소스 검색

repo: update repository description field to contain more than 256 symbols (#5219)

* Update repository description field to contain more than 256 symbols

- update repository model - description field now is `TEXT` and limited by 4000 symbols
- new migration
- add description to html forms - repo creation and repo settings
- add translation for description

* Update for description field, new features

- add autosize (height) for description textarea, new plugin
- set max description length to 512 symbols
- update locales

* Fix migration - typo in var

* Update repo description behaviour

- add textarea autosize for /repo/create
- add symbols counter under description testarea (create/edit)

* Fix function definition - it a var

* Revert ru-RU locale

* Update by review

- Use type `varchar(512)` in migration
- Remove unused files from autosize plugin

* Fix migration - new project paths

* Fixes after review 2

- copyright year
- format includes
- use switch instead of multi-if

* Remove unused `default:` option.
Sergey Dryabzhinsky 6 년 전
부모
커밋
57897cc8c2

+ 4 - 0
conf/locale/locale_en-US.ini

@@ -421,6 +421,8 @@ mirror_last_synced = Last Synced
 watchers = Watchers
 stargazers = Stargazers
 forks = Forks
+repo_description_helper = Description of repository. Maximum 512 characters length.
+repo_description_length = Available characters
 
 form.reach_limit_of_creation = The owner has reached maximum creation limit of %d repositories.
 form.name_reserved = Repository name '%s' is reserved.
@@ -856,6 +858,8 @@ settings.add_key_success = New deploy key '%s' has been added successfully!
 settings.deploy_key_deletion = Delete Deploy Key
 settings.deploy_key_deletion_desc = Deleting this deploy key will remove all related accesses for this repository. Do you want to continue?
 settings.deploy_key_deletion_success = Deploy key has been deleted successfully!
+settings.description_desc = Description of repository. Maximum 512 characters length.
+settings.description_length = Available characters
 
 diff.browse_source = Browse Source
 diff.parent = parent

+ 2 - 0
models/migrations/migrations.go

@@ -64,6 +64,8 @@ var migrations = []Migration{
 	NewMigration("update repository sizes", updateRepositorySizes),
 	// v16 -> v17:v0.10.31
 	NewMigration("remove invalid protect branch whitelist", removeInvalidProtectBranchWhitelist),
+	// v17 -> v18:v0.11.48
+	NewMigration("store long text in repository description field", updateRepositoryDescriptionField),
 }
 
 // Migrate database to current version

+ 34 - 0
models/migrations/v18.go

@@ -0,0 +1,34 @@
+// Copyright 2018 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+	"fmt"
+
+	"github.com/go-xorm/xorm"
+
+	"github.com/gogs/gogs/pkg/setting"
+)
+
+func updateRepositoryDescriptionField(x *xorm.Engine) error {
+	exist, err := x.IsTableExist("repository")
+	if err != nil {
+		return fmt.Errorf("IsTableExist: %v", err)
+	} else if !exist {
+		return nil
+	}
+	switch {
+		case setting.UseMySQL:
+			_, err = x.Exec("ALTER TABLE `repository` MODIFY `description` VARCHAR(512);")
+		case setting.UseMSSQL:
+			_, err = x.Exec("ALTER TABLE `repository` ALTER COLUMN `description` VARCHAR(512);")
+		case setting.UsePostgreSQL:
+			_, err = x.Exec("ALTER TABLE `repository` ALTER COLUMN `description` TYPE VARCHAR(512);")
+		case setting.UseSQLite3:
+			// Sqlite3 uses TEXT type by default for any string type field.
+			// Keep this comment to mention that we don't missed any option.
+	}
+	return err
+}

+ 3 - 3
models/repo.go

@@ -146,7 +146,7 @@ type Repository struct {
 	Owner         *User  `xorm:"-" json:"-"`
 	LowerName     string `xorm:"UNIQUE(s) INDEX NOT NULL"`
 	Name          string `xorm:"INDEX NOT NULL"`
-	Description   string
+	Description   string `xorm:"VARCHAR(512)"`
 	Website       string
 	DefaultBranch string
 	Size          int64 `xorm:"NOT NULL DEFAULT 0"`
@@ -1331,8 +1331,8 @@ func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) {
 func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) {
 	repo.LowerName = strings.ToLower(repo.Name)
 
-	if len(repo.Description) > 255 {
-		repo.Description = repo.Description[:255]
+	if len(repo.Description) > 512 {
+		repo.Description = repo.Description[:512]
 	}
 	if len(repo.Website) > 255 {
 		repo.Website = repo.Website[:255]

+ 3 - 3
pkg/form/repo.go

@@ -26,7 +26,7 @@ type CreateRepo struct {
 	UserID      int64  `binding:"Required"`
 	RepoName    string `binding:"Required;AlphaDashDot;MaxSize(100)"`
 	Private     bool
-	Description string `binding:"MaxSize(255)"`
+	Description string `binding:"MaxSize(512)"`
 	AutoInit    bool
 	Gitignores  string
 	License     string
@@ -45,7 +45,7 @@ type MigrateRepo struct {
 	RepoName     string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
 	Mirror       bool   `json:"mirror"`
 	Private      bool   `json:"private"`
-	Description  string `json:"description" binding:"MaxSize(255)"`
+	Description  string `json:"description" binding:"MaxSize(512)"`
 }
 
 func (f *MigrateRepo) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
@@ -82,7 +82,7 @@ func (f MigrateRepo) ParseRemoteAddr(user *models.User) (string, error) {
 
 type RepoSetting struct {
 	RepoName      string `binding:"Required;AlphaDashDot;MaxSize(100)"`
-	Description   string `binding:"MaxSize(255)"`
+	Description   string `binding:"MaxSize(512)"`
 	Website       string `binding:"Url;MaxSize(100)"`
 	Branch        string
 	Interval      int

+ 21 - 0
public/js/gogs.js

@@ -1443,3 +1443,24 @@ $(function () {
     if ($('.user.signin').length > 0) return;
     $('form').areYouSure();
 });
+
+function showMessageMaxLength(maxLen, textElemId, counterId) {
+    var $msg = $('#'+textElemId);                      //text message
+    $('#'+counterId).html(maxLen - $msg.val().length); //symbols count
+
+    var onMessageKey = function (e) {
+        var $msg = $(this);
+        var text = $msg.val();
+        var len = text.length;
+        var remainder = maxLen - len;
+
+        if (len >= maxLen) {
+            $msg.val($msg.val().substr(0, maxLen));
+            remainder = 0;
+        }
+
+        $('#'+counterId).html(remainder);
+    };
+
+    $msg.keyup(onMessageKey).keydown(onMessageKey);
+}

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 5 - 0
public/plugins/autosize-4.0.2/dist/autosize.min.js


+ 1 - 0
routes/repo/repo.go

@@ -75,6 +75,7 @@ func Create(c *context.Context) {
 	c.Data["readme"] = "Default"
 	c.Data["private"] = c.User.LastRepoVisibility
 	c.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
+	c.Data["RequireAutosize"] = true
 
 	ctxUser := checkContextUser(c, c.QueryInt64("org"))
 	if c.Written() {

+ 1 - 0
routes/repo/setting.go

@@ -34,6 +34,7 @@ const (
 func Settings(c *context.Context) {
 	c.Title("repo.settings")
 	c.PageIs("SettingsOptions")
+	c.Data["RequireAutosize"] = true
 	c.Success(SETTINGS_OPTIONS)
 }
 

+ 3 - 1
templates/base/head.tmpl

@@ -41,7 +41,9 @@
 	<script src="{{AppSubURL}}/js/libs/jquery.are-you-sure.js"></script>
 	<link rel="stylesheet" href="{{AppSubURL}}/assets/font-awesome-4.6.3/css/font-awesome.min.css">
 	<link rel="stylesheet" href="{{AppSubURL}}/assets/octicons-4.3.0/octicons.min.css">
-
+	{{if .RequireAutosize}}
+		<script src="{{AppSubURL}}/plugins/autosize-4.0.2/dist/autosize.min.js"></script>
+	{{end}}
 	<!-- notebook.js for rendering ipython notebooks and marked.js for rendering markdown in notebooks -->
 	{{if .IsIPythonNotebook}}
 		<script src="{{AppSubURL}}/plugins/notebookjs-0.3.0/notebook.min.js"></script>

+ 13 - 1
templates/repo/create.tmpl

@@ -52,7 +52,9 @@
 					</div>
 					<div class="inline field {{if .Err_Description}}error{{end}}">
 						<label for="description">{{.i18n.Tr "repo.repo_desc"}}</label>
-						<textarea id="description" name="description">{{.description}}</textarea>
+						<textarea id="description" name="description" rows="3">{{.description}}</textarea>
+						<span class="help">{{.i18n.Tr "repo.repo_description_helper" | Safe}}</span>
+						<span class="help">{{.i18n.Tr "repo.repo_description_length"}}: <span id="descLength"></span></span>
 					</div>
 
 					<div class="ui divider"></div>
@@ -113,4 +115,14 @@
 		</div>
 	</div>
 </div>
+
+<script type="text/javascript">
+$(document).ready(function(){
+	if (typeof window.autosize !== "undefined") {
+		autosize($('#description'));
+	}
+	showMessageMaxLength(512, 'description', 'descLength');
+});
+</script>
+
 {{template "base/footer" .}}

+ 12 - 1
templates/repo/settings/options.tmpl

@@ -19,7 +19,9 @@
 						</div>
 						<div class="field {{if .Err_Description}}error{{end}}">
 							<label for="description">{{$.i18n.Tr "repo.repo_desc"}}</label>
-							<textarea id="description" name="description" rows="2">{{.Repository.Description}}</textarea>
+							<textarea id="description" name="description" rows="3">{{.Repository.Description}}</textarea>
+							<p class="help">{{.i18n.Tr "repo.settings.description_desc"}}</p>
+							<p class="help">{{.i18n.Tr "repo.settings.description_length"}}: <span id="descLength"></span></p>
 						</div>
 						<div class="field {{if .Err_Website}}error{{end}}">
 							<label for="website">{{.i18n.Tr "repo.settings.site"}}</label>
@@ -415,4 +417,13 @@
 	{{end}}
 {{end}}
 
+<script type="text/javascript">
+$(document).ready(function(){
+	if (typeof window.autosize !== "undefined") {
+		autosize($('#description'));
+	}
+	showMessageMaxLength(512, 'description', 'descLength');
+});
+</script>
+
 {{template "base/footer" .}}

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.