mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 08:57:03 -05:00
Web editor: improve delete file process
This commit is contained in:
parent
dad5c15520
commit
0114fdcba4
19 changed files with 217 additions and 174 deletions
|
@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
|
|||
|
||||
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
|
||||
|
||||
##### Current tip version: 0.9.90 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
|
||||
##### Current tip version: 0.9.91 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
|
||||
|
||||
| Web | UI | Preview |
|
||||
|:-------------:|:-------:|:-------:|
|
||||
|
|
|
@ -506,7 +506,8 @@ func runWeb(ctx *cli.Context) error {
|
|||
m.Post("/_preview/*", bindIgnErr(auth.EditPreviewDiffForm{}), repo.DiffPreviewPost)
|
||||
m.Combo("/_upload/*").Get(repo.UploadFile).
|
||||
Post(bindIgnErr(auth.UploadRepoFileForm{}), repo.UploadFilePost)
|
||||
m.Post("/_delete/*", bindIgnErr(auth.DeleteRepoFileForm{}), repo.DeleteFilePost)
|
||||
m.Combo("/_delete/*").Get(repo.DeleteFile).
|
||||
Post(bindIgnErr(auth.DeleteRepoFileForm{}), repo.DeleteFilePost)
|
||||
// m.Post("/upload-file", repo.UploadFileToServer)
|
||||
// m.Post("/upload-remove", bindIgnErr(auth.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer)
|
||||
}, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) {
|
||||
|
|
|
@ -426,30 +426,31 @@ file_view_raw = View Raw
|
|||
file_permalink = Permalink
|
||||
file_too_large = This file is too large to be shown
|
||||
|
||||
cancel = Cancel
|
||||
cancel_lower = cancel
|
||||
or = or
|
||||
new_file = New file
|
||||
upload_files = Upload files
|
||||
find_file = Find file
|
||||
commit_changes = Commit Changes
|
||||
default_commit_message = Add an optional extended description...
|
||||
last_commit_info = %s edited this file %s
|
||||
delete_this_file = Delete this file
|
||||
edit_file = Edit file
|
||||
delete_confirm_message = Are you sure you want to delete this file?
|
||||
delete_commit_message = Write a note about this delete (optional)
|
||||
unable_to_update_file = Unable to update this file, error occurred
|
||||
must_be_writer = You must have write access to make or propose changes to this file
|
||||
filename_help = To add directory, just type it and press /. To remove a directory, go to the beginning of the field and press backspace.
|
||||
new_branch = new branch
|
||||
editor.new_file = New file
|
||||
editor.cannot_edit_non_text_files = Cannot edit non-text files
|
||||
editor.edit_this_file = Edit this file
|
||||
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file
|
||||
editor.fork_before_edit = You must fork this repository before editing the file
|
||||
editor.delete_this_file = Delete this file
|
||||
editor.must_have_write_access = You must have write access to make or propose changes to this file
|
||||
editor.file_delete_success = File '%s' has been deleted successfully!
|
||||
editor.commit_changes = Commit Changes
|
||||
editor.add_tmpl = Add '%s/<filename>'
|
||||
editor.add = Add '%s'
|
||||
editor.update = Update '%s'
|
||||
editor.delete = Delete '%s'
|
||||
editor.commit_message_desc = Add an optional extended description...
|
||||
editor.commit_directly_to_this_branch = Commit directly to the <strong class="branch-name">%s</strong> branch.
|
||||
editor.create_new_branch = Create a <strong>new branch</strong> for this commit and start a pull request.
|
||||
editor.new_branch_name_desc = New branch name...
|
||||
editor.cancel = Cancel
|
||||
editor.filename_cannot_be_empty = Filename cannot be empty.
|
||||
editor.branch_already_exists = Branch '%s' already exists in this repository.
|
||||
editor.directory_is_a_file = Entry '%s' in the parent path is a file not a directory in this repository.
|
||||
|
@ -457,12 +458,8 @@ editor.filename_is_a_directory = The filename '%s' is an existing directory in t
|
|||
editor.file_editing_no_longer_exists = The file '%s' you are editing no longer exists in the repository.
|
||||
editor.file_changed_while_editing = File content has been changed since you started editing. <a target="_blank" href="%s">Click here</a> to see what have been changed or <strong>press commit again</strong> to overwrite those changes.
|
||||
editor.file_already_exists = A file with name '%s' already exists in this repository.
|
||||
editor.add = Add '%s'
|
||||
editor.update = Update '%s'
|
||||
editor.failed_to_upload_files = An error occurred while updating file: %v
|
||||
editor.no_changes_to_show = There are no changes to show.
|
||||
create_branch = Create branch
|
||||
from = from
|
||||
upload_file = Upload file
|
||||
add_files_to_dir = Add files to %s
|
||||
add_subdir = Add subdirectory...
|
||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const APP_VER = "0.9.90.0828"
|
||||
const APP_VER = "0.9.91.0828"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
|
|
@ -95,14 +95,6 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
|
|||
}
|
||||
}
|
||||
|
||||
if len(opts.Message) == 0 {
|
||||
if opts.IsNewFile {
|
||||
opts.Message = "Add '" + opts.NewTreeName + "'"
|
||||
} else {
|
||||
opts.Message = "Update '" + opts.NewTreeName + "'"
|
||||
}
|
||||
}
|
||||
|
||||
localPath := repo.LocalCopyPath()
|
||||
filePath := path.Join(localPath, opts.NewTreeName)
|
||||
os.MkdirAll(path.Dir(filePath), os.ModePerm)
|
||||
|
@ -228,7 +220,8 @@ func (repo *Repository) GetDiffPreview(branch, treePath, content string) (diff *
|
|||
|
||||
type DeleteRepoFileOptions struct {
|
||||
LastCommitID string
|
||||
Branch string
|
||||
OldBranch string
|
||||
NewBranch string
|
||||
TreePath string
|
||||
Message string
|
||||
}
|
||||
|
@ -237,21 +230,23 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
|
|||
repoWorkingPool.CheckIn(com.ToStr(repo.ID))
|
||||
defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
|
||||
|
||||
localPath := repo.LocalCopyPath()
|
||||
if err = discardLocalRepoBranchChanges(localPath, opts.Branch); err != nil {
|
||||
return fmt.Errorf("discardLocalRepoBranchChanges [branch: %s]: %v", opts.Branch, err)
|
||||
} else if err = repo.UpdateLocalCopyBranch(opts.Branch); err != nil {
|
||||
return fmt.Errorf("UpdateLocalCopyBranch [branch: %s]: %v", opts.Branch, err)
|
||||
if err = repo.DiscardLocalRepoBranchChanges(opts.OldBranch); err != nil {
|
||||
return fmt.Errorf("DiscardLocalRepoBranchChanges [branch: %s]: %v", opts.OldBranch, err)
|
||||
} else if err = repo.UpdateLocalCopyBranch(opts.OldBranch); err != nil {
|
||||
return fmt.Errorf("UpdateLocalCopyBranch [branch: %s]: %v", opts.OldBranch, err)
|
||||
}
|
||||
|
||||
if opts.OldBranch != opts.NewBranch {
|
||||
if err := repo.CheckoutNewBranch(opts.OldBranch, opts.NewBranch); err != nil {
|
||||
return fmt.Errorf("CheckoutNewBranch [old_branch: %s, new_branch: %s]: %v", opts.OldBranch, opts.NewBranch, err)
|
||||
}
|
||||
}
|
||||
|
||||
localPath := repo.LocalCopyPath()
|
||||
if err = os.Remove(path.Join(localPath, opts.TreePath)); err != nil {
|
||||
return fmt.Errorf("Remove: %v", err)
|
||||
}
|
||||
|
||||
if len(opts.Message) == 0 {
|
||||
opts.Message = "Delete file '" + opts.TreePath + "'"
|
||||
}
|
||||
|
||||
if err = git.AddChanges(localPath, true); err != nil {
|
||||
return fmt.Errorf("git add --all: %v", err)
|
||||
} else if err = git.CommitChanges(localPath, git.CommitChangesOptions{
|
||||
|
@ -259,8 +254,8 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
|
|||
Message: opts.Message,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("CommitChanges: %v", err)
|
||||
} else if err = git.Push(localPath, "origin", opts.Branch); err != nil {
|
||||
return fmt.Errorf("git push origin %s: %v", opts.Branch, err)
|
||||
} else if err = git.Push(localPath, "origin", opts.NewBranch); err != nil {
|
||||
return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
|
||||
}
|
||||
|
||||
gitRepo, err := git.OpenRepository(repo.RepoPath())
|
||||
|
@ -268,9 +263,9 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
|
|||
log.Error(4, "OpenRepository: %v", err)
|
||||
return nil
|
||||
}
|
||||
commit, err := gitRepo.GetBranchCommit(opts.Branch)
|
||||
commit, err := gitRepo.GetBranchCommit(opts.NewBranch)
|
||||
if err != nil {
|
||||
log.Error(4, "GetBranchCommit [branch: %s]: %v", opts.Branch, err)
|
||||
log.Error(4, "GetBranchCommit [branch: %s]: %v", opts.NewBranch, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -283,7 +278,7 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
|
|||
PusherName: doer.Name,
|
||||
RepoOwnerID: repo.MustOwner().ID,
|
||||
RepoName: repo.Name,
|
||||
RefFullName: git.BRANCH_PREFIX + opts.Branch,
|
||||
RefFullName: git.BRANCH_PREFIX + opts.NewBranch,
|
||||
OldCommitID: opts.LastCommitID,
|
||||
NewCommitID: commit.ID.String(),
|
||||
Commits: pushCommits,
|
||||
|
|
|
@ -337,6 +337,9 @@ func (f *RemoveUploadFileForm) Validate(ctx *macaron.Context, errs binding.Error
|
|||
|
||||
type DeleteRepoFileForm struct {
|
||||
CommitSummary string `binding:"MaxSize(100)`
|
||||
CommitMessage string
|
||||
CommitChoice string `binding:"Required;MaxSize(50)"`
|
||||
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
|
||||
}
|
||||
|
||||
func (f *DeleteRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -737,6 +737,16 @@ function setCodeMirror($editArea) {
|
|||
}
|
||||
|
||||
function initEditor() {
|
||||
$('.js-quick-pull-choice-option').change(function () {
|
||||
if ($(this).val() == 'commit-to-new-branch') {
|
||||
$('.quick-pull-branch-name').show();
|
||||
$('.quick-pull-branch-name input').prop('required',true);
|
||||
} else {
|
||||
$('.quick-pull-branch-name').hide();
|
||||
$('.quick-pull-branch-name input').prop('required',false);
|
||||
}
|
||||
});
|
||||
|
||||
var $editFilename = $("#file-name");
|
||||
$editFilename.keyup(function (e) {
|
||||
var $section = $('.breadcrumb span.section');
|
||||
|
@ -841,16 +851,6 @@ function initEditor() {
|
|||
codeMirrorEditor.setOption("lineWrapping", false);
|
||||
}
|
||||
}).trigger('keyup');
|
||||
|
||||
|
||||
$('.js-quick-pull-choice-option').change(function () {
|
||||
if ($(this).val() == 'commit-to-new-branch') {
|
||||
$('.quick-pull-branch-name').show();
|
||||
} else {
|
||||
$('.quick-pull-branch-name').hide();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function initOrganization() {
|
||||
|
|
|
@ -20,9 +20,10 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
EDIT base.TplName = "repo/editor/edit"
|
||||
DIFF_PREVIEW base.TplName = "repo/editor/diff_preview"
|
||||
DIFF_PREVIEW_NEW base.TplName = "repo/editor/diff_preview_new"
|
||||
EDIT_FILE base.TplName = "repo/editor/edit"
|
||||
EDIT_DIFF_PREVIEW base.TplName = "repo/editor/diff_preview"
|
||||
NEW_DIFF_PREVIEW base.TplName = "repo/editor/diff_preview_new"
|
||||
DELETE_FILE base.TplName = "repo/editor/delete"
|
||||
)
|
||||
|
||||
func editFile(ctx *context.Context, isNewFile bool) {
|
||||
|
@ -104,7 +105,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
|
|||
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
|
||||
ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
|
||||
|
||||
ctx.HTML(200, EDIT)
|
||||
ctx.HTML(200, EDIT_FILE)
|
||||
}
|
||||
|
||||
func EditFile(ctx *context.Context) {
|
||||
|
@ -125,12 +126,10 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
|||
branchName := oldBranchName
|
||||
branchLink := ctx.Repo.RepoLink + "/src/" + branchName
|
||||
oldTreePath := ctx.Repo.TreePath
|
||||
content := form.Content
|
||||
commitChoice := form.CommitChoice
|
||||
lastCommit := form.LastCommit
|
||||
form.LastCommit = ctx.Repo.Commit.ID.String()
|
||||
|
||||
if commitChoice == "commit-to-new-branch" {
|
||||
if form.CommitChoice == "commit-to-new-branch" {
|
||||
branchName = form.NewBranchName
|
||||
}
|
||||
|
||||
|
@ -144,10 +143,10 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
|||
ctx.Data["TreePath"] = form.TreePath
|
||||
ctx.Data["TreeNames"] = treeNames
|
||||
ctx.Data["BranchLink"] = branchLink
|
||||
ctx.Data["FileContent"] = content
|
||||
ctx.Data["FileContent"] = form.Content
|
||||
ctx.Data["commit_summary"] = form.CommitSummary
|
||||
ctx.Data["commit_message"] = form.CommitMessage
|
||||
ctx.Data["commit_choice"] = commitChoice
|
||||
ctx.Data["commit_choice"] = form.CommitChoice
|
||||
ctx.Data["new_branch_name"] = branchName
|
||||
ctx.Data["last_commit"] = form.LastCommit
|
||||
ctx.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
|
||||
|
@ -155,20 +154,20 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
|||
ctx.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, EDIT)
|
||||
ctx.HTML(200, EDIT_FILE)
|
||||
return
|
||||
}
|
||||
|
||||
if len(form.TreePath) == 0 {
|
||||
ctx.Data["Err_TreePath"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.filename_cannot_be_empty"), EDIT, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.filename_cannot_be_empty"), EDIT_FILE, &form)
|
||||
return
|
||||
}
|
||||
|
||||
if oldBranchName != branchName {
|
||||
if _, err := ctx.Repo.Repository.GetBranch(branchName); err == nil {
|
||||
ctx.Data["Err_NewBranchName"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), EDIT, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), EDIT_FILE, &form)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -189,13 +188,13 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
|||
if index != len(treeNames)-1 {
|
||||
if !entry.IsDir() {
|
||||
ctx.Data["Err_TreePath"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.directory_is_a_file", part), EDIT, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.directory_is_a_file", part), EDIT_FILE, &form)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if entry.IsDir() {
|
||||
ctx.Data["Err_TreePath"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_a_directory", part), EDIT, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.filename_is_a_directory", part), EDIT_FILE, &form)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +205,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
|||
if err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.Data["Err_TreePath"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), EDIT, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.file_editing_no_longer_exists", oldTreePath), EDIT_FILE, &form)
|
||||
} else {
|
||||
ctx.Handle(500, "GetTreeEntryByPath", err)
|
||||
}
|
||||
|
@ -221,7 +220,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
|||
|
||||
for _, file := range files {
|
||||
if file == form.TreePath {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.file_changed_while_editing", ctx.Repo.RepoLink+"/compare/"+lastCommit+"..."+ctx.Repo.CommitID), EDIT, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.file_changed_while_editing", ctx.Repo.RepoLink+"/compare/"+lastCommit+"..."+ctx.Repo.CommitID), EDIT_FILE, &form)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -239,15 +238,13 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
|||
}
|
||||
if entry != nil {
|
||||
ctx.Data["Err_TreePath"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.file_already_exists", form.TreePath), EDIT, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.file_already_exists", form.TreePath), EDIT_FILE, &form)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var message string
|
||||
if len(form.CommitSummary) > 0 {
|
||||
message = strings.TrimSpace(form.CommitSummary)
|
||||
} else {
|
||||
message := strings.TrimSpace(form.CommitSummary)
|
||||
if len(message) == 0 {
|
||||
if isNewFile {
|
||||
message = ctx.Tr("repo.editor.add", form.TreePath)
|
||||
} else {
|
||||
|
@ -267,11 +264,11 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
|
|||
OldTreeName: oldTreePath,
|
||||
NewTreeName: form.TreePath,
|
||||
Message: message,
|
||||
Content: content,
|
||||
Content: form.Content,
|
||||
IsNewFile: isNewFile,
|
||||
}); err != nil {
|
||||
ctx.Data["Err_TreePath"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.failed_to_update_file", err), EDIT, &form)
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.failed_to_update_file", err), EDIT_FILE, &form)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -287,14 +284,14 @@ func NewFilePost(ctx *context.Context, form auth.EditRepoFileForm) {
|
|||
}
|
||||
|
||||
func DiffPreviewPost(ctx *context.Context, form auth.EditPreviewDiffForm) {
|
||||
treeName := ctx.Repo.TreePath
|
||||
treePath := ctx.Repo.TreePath
|
||||
content := form.Content
|
||||
|
||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treeName)
|
||||
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treePath)
|
||||
if err != nil {
|
||||
if git.IsErrNotExist(err) {
|
||||
ctx.Data["FileContent"] = content
|
||||
ctx.HTML(200, DIFF_PREVIEW_NEW)
|
||||
ctx.HTML(200, NEW_DIFF_PREVIEW)
|
||||
} else {
|
||||
ctx.Error(500, "GetTreeEntryByPath: "+err.Error())
|
||||
}
|
||||
|
@ -305,7 +302,7 @@ func DiffPreviewPost(ctx *context.Context, form auth.EditPreviewDiffForm) {
|
|||
return
|
||||
}
|
||||
|
||||
diff, err := ctx.Repo.Repository.GetDiffPreview(ctx.Repo.BranchName, treeName, content)
|
||||
diff, err := ctx.Repo.Repository.GetDiffPreview(ctx.Repo.BranchName, treePath, content)
|
||||
if err != nil {
|
||||
ctx.Error(500, "GetDiffPreview: "+err.Error())
|
||||
return
|
||||
|
@ -317,28 +314,71 @@ func DiffPreviewPost(ctx *context.Context, form auth.EditPreviewDiffForm) {
|
|||
}
|
||||
ctx.Data["File"] = diff.Files[0]
|
||||
|
||||
ctx.HTML(200, DIFF_PREVIEW)
|
||||
ctx.HTML(200, EDIT_DIFF_PREVIEW)
|
||||
}
|
||||
|
||||
func DeleteFile(ctx *context.Context) {
|
||||
ctx.Data["PageIsDelete"] = true
|
||||
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName
|
||||
ctx.Data["TreePath"] = ctx.Repo.TreePath
|
||||
ctx.Data["commit_summary"] = ""
|
||||
ctx.Data["commit_message"] = ""
|
||||
ctx.Data["commit_choice"] = "direct"
|
||||
ctx.Data["new_branch_name"] = ""
|
||||
ctx.HTML(200, DELETE_FILE)
|
||||
}
|
||||
|
||||
func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
|
||||
branchName := ctx.Repo.BranchName
|
||||
treeName := ctx.Repo.TreePath
|
||||
ctx.Data["PageIsDelete"] = true
|
||||
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchName
|
||||
ctx.Data["TreePath"] = ctx.Repo.TreePath
|
||||
|
||||
oldBranchName := ctx.Repo.BranchName
|
||||
branchName := oldBranchName
|
||||
treePath := ctx.Repo.TreePath
|
||||
|
||||
if form.CommitChoice == "commit-to-new-branch" {
|
||||
branchName = form.NewBranchName
|
||||
}
|
||||
ctx.Data["commit_summary"] = form.CommitSummary
|
||||
ctx.Data["commit_message"] = form.CommitMessage
|
||||
ctx.Data["commit_choice"] = form.CommitChoice
|
||||
ctx.Data["new_branch_name"] = branchName
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + treeName)
|
||||
ctx.HTML(200, DELETE_FILE)
|
||||
return
|
||||
}
|
||||
|
||||
if oldBranchName != branchName {
|
||||
if _, err := ctx.Repo.Repository.GetBranch(branchName); err == nil {
|
||||
ctx.Data["Err_NewBranchName"] = true
|
||||
ctx.RenderWithErr(ctx.Tr("repo.editor.branch_already_exists", branchName), DELETE_FILE, &form)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
message := strings.TrimSpace(form.CommitSummary)
|
||||
if len(message) == 0 {
|
||||
message = ctx.Tr("repo.editor.delete", treePath)
|
||||
}
|
||||
|
||||
form.CommitMessage = strings.TrimSpace(form.CommitMessage)
|
||||
if len(form.CommitMessage) > 0 {
|
||||
message += "\n\n" + form.CommitMessage
|
||||
}
|
||||
|
||||
if err := ctx.Repo.Repository.DeleteRepoFile(ctx.User, models.DeleteRepoFileOptions{
|
||||
LastCommitID: ctx.Repo.CommitID,
|
||||
Branch: branchName,
|
||||
TreePath: treeName,
|
||||
Message: form.CommitSummary,
|
||||
OldBranch: oldBranchName,
|
||||
NewBranch: branchName,
|
||||
TreePath: treePath,
|
||||
Message: message,
|
||||
}); err != nil {
|
||||
ctx.Handle(500, "DeleteRepoFile", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", treeName))
|
||||
ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", treePath))
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName)
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ func Home(ctx *context.Context) {
|
|||
branchLink := ctx.Repo.RepoLink + "/src/" + branchName
|
||||
treeLink := branchLink
|
||||
rawLink := ctx.Repo.RepoLink + "/raw/" + branchName
|
||||
// newFileLink := ctx.Repo.RepoLink + "/_new/" + branchName
|
||||
// uploadFileLink := ctx.Repo.RepoLink + "/upload/" + branchName
|
||||
|
||||
treePath := ctx.Repo.TreePath
|
||||
|
@ -155,13 +154,11 @@ func Home(ctx *context.Context) {
|
|||
|
||||
if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
|
||||
ctx.Data["CanDeleteFile"] = true
|
||||
ctx.Data["FileDeleteLinkTooltip"] = ctx.Tr("repo.delete_this_file")
|
||||
} else {
|
||||
if !ctx.Repo.IsViewBranch {
|
||||
ctx.Data["FileDeleteLinkTooltip"] = ctx.Tr("repo.must_be_on_branch")
|
||||
} else if !ctx.Repo.IsWriter() {
|
||||
ctx.Data["FileDeleteLinkTooltip"] = ctx.Tr("repo.must_be_writer")
|
||||
}
|
||||
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.delete_this_file")
|
||||
} else if !ctx.Repo.IsViewBranch {
|
||||
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
|
||||
} else if !ctx.Repo.IsWriter() {
|
||||
ctx.Data["DeleteFileTooltip"] = ctx.Tr("repo.editor.must_have_write_access")
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -240,12 +237,13 @@ func Home(ctx *context.Context) {
|
|||
}
|
||||
ctx.Data["LastCommit"] = lastCommit
|
||||
ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit)
|
||||
// if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
|
||||
// ctx.Data["NewFileLink"] = newFileLink + "/" + treePath
|
||||
// if setting.Repository.Upload.Enabled {
|
||||
// ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treePath
|
||||
// }
|
||||
// }
|
||||
|
||||
if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
|
||||
ctx.Data["CanAddFile"] = true
|
||||
// if setting.Repository.Upload.Enabled {
|
||||
// ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treePath
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["Username"] = userName
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.9.90.0828
|
||||
0.9.91.0828
|
|
@ -10,6 +10,6 @@
|
|||
{{end}}
|
||||
{{if .Flash.InfoMsg}}
|
||||
<div class="ui info message">
|
||||
<p>{{.Flash.InfoMsg| Safe}}</p>
|
||||
<p>{{.Flash.InfoMsg | Safe}}</p>
|
||||
</div>
|
||||
{{end}}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="fitted item choose reference">
|
||||
<div id="branch-dropdown" class="ui floating filter dropdown" data-no-results="{{.i18n.Tr "repo.pulls.no_results"}}">
|
||||
<div class="ui floating filter dropdown" data-no-results="{{.i18n.Tr "repo.pulls.no_results"}}">
|
||||
<div class="ui basic small button">
|
||||
<span class="text">
|
||||
<i class="octicon octicon-git-branch"></i>
|
||||
|
@ -31,12 +31,12 @@
|
|||
</div>
|
||||
<div id="branch-list" class="scrolling menu" {{if .IsViewTag}}style="display: none"{{end}}>
|
||||
{{range .Branches}}
|
||||
<div class="item {{if eq $.BranchName .}}selected{{end}}" data-url="{{$.RepoLink}}/{{if $.PageIsCommits}}commits{{else}}src{{end}}/{{EscapePound .}}{{if $.TreeName}}/{{EscapePound $.TreeName}}{{end}}">{{.}}</div>
|
||||
<div class="item {{if eq $.BranchName .}}selected{{end}}" data-url="{{$.RepoLink}}/{{if $.PageIsCommits}}commits{{else}}src{{end}}/{{EscapePound .}}{{if $.TreePath}}/{{EscapePound $.TreePath}}{{end}}">{{.}}</div>
|
||||
{{end}}
|
||||
</div>
|
||||
<div id="tag-list" class="scrolling menu" {{if not .IsViewTag}}style="display: none"{{end}}>
|
||||
{{range .Tags}}
|
||||
<div class="item {{if eq $.BranchName .}}selected{{end}}" data-url="{{$.RepoLink}}/{{if $.PageIsCommits}}commits{{else}}src{{end}}/{{EscapePound .}}{{if $.TreeName}}/{{EscapePound $.TreeName}}{{end}}">{{.}}</div>
|
||||
<div class="item {{if eq $.BranchName .}}selected{{end}}" data-url="{{$.RepoLink}}/{{if $.PageIsCommits}}commits{{else}}src{{end}}/{{EscapePound .}}{{if $.TreePath}}/{{EscapePound $.TreePath}}{{end}}">{{.}}</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -152,21 +152,21 @@
|
|||
|
||||
{{if .IsSplitStyle}}
|
||||
<script>
|
||||
(function() {
|
||||
$('.add-code').each(function() {
|
||||
var prev = $(this).prev();
|
||||
if(prev.is('.del-code') && prev.children().eq(3).text().trim() === '') {
|
||||
while(prev.prev().is('.del-code') && prev.prev().children().eq(3).text().trim() === '') {
|
||||
prev = prev.prev();
|
||||
(function() {
|
||||
$('.add-code').each(function() {
|
||||
var prev = $(this).prev();
|
||||
if(prev.is('.del-code') && prev.children().eq(3).text().trim() === '') {
|
||||
while(prev.prev().is('.del-code') && prev.prev().children().eq(3).text().trim() === '') {
|
||||
prev = prev.prev();
|
||||
}
|
||||
prev.children().eq(3).html($(this).children().eq(3).html());
|
||||
prev.children().eq(2).html($(this).children().eq(2).html());
|
||||
prev.children().eq(3).addClass('add-code');
|
||||
prev.children().eq(2).addClass('add-code');
|
||||
$(this).remove();
|
||||
}
|
||||
prev.children().eq(3).html($(this).children().eq(3).html());
|
||||
prev.children().eq(2).html($(this).children().eq(2).html());
|
||||
prev.children().eq(3).addClass('add-code');
|
||||
prev.children().eq(2).addClass('add-code');
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
}());
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
|
43
templates/repo/editor/commit_form.tmpl
Normal file
43
templates/repo/editor/commit_form.tmpl
Normal file
|
@ -0,0 +1,43 @@
|
|||
<div class="commit-form-wrapper">
|
||||
<img width="48" height="48" class="ui image commit-avatar" src="{{.SignedUser.AvatarLink}}">
|
||||
<div class="commit-form">
|
||||
<h3>{{.i18n.Tr "repo.editor.commit_changes"}}</h3>
|
||||
<div class="field">
|
||||
<input name="commit_summary" placeholder="{{if .PageIsDelete}}{{.i18n.Tr "repo.editor.delete" .TreePath}}{{else if .IsNewFile}}{{.i18n.Tr "repo.editor.add_tmpl" .TreePath}}{{else}}{{.i18n.Tr "repo.editor.update" .TreePath}}{{end}}" value="{{.commit_summary}}" autofocus>
|
||||
</div>
|
||||
<div class="field">
|
||||
<textarea name="commit_message" placeholder="{{.i18n.Tr "repo.editor.commit_message_desc"}}" rows="5">{{.commit_message}}</textarea>
|
||||
</div>
|
||||
<div class="quick-pull-choice js-quick-pull-choice">
|
||||
<div class="field">
|
||||
<div class="ui radio checkbox">
|
||||
<input type="radio" class="js-quick-pull-choice-option" name="commit_choice" value="direct" {{if eq .commit_choice "direct"}}checked{{end}}>
|
||||
<label>
|
||||
<i class="octicon octicon-git-commit" height="16" width="14"></i>
|
||||
{{.i18n.Tr "repo.editor.commit_directly_to_this_branch" .BranchName | Safe}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="ui radio checkbox">
|
||||
<input type="radio" class="js-quick-pull-choice-option" name="commit_choice" value="commit-to-new-branch" {{if eq .commit_choice "commit-to-new-branch"}}checked{{end}}>
|
||||
<label>
|
||||
<i class="octicon octicon-git-pull-request" height="16" width="12"></i>
|
||||
{{.i18n.Tr "repo.editor.create_new_branch" | Safe}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="quick-pull-branch-name {{if not (eq .commit_choice "commit-to-new-branch")}}hide{{end}}">
|
||||
<div class="new-branch-name-input field {{if .Err_NewBranchName}}error{{end}}">
|
||||
<i class="octicon octicon-git-branch" height="16" width="10"></i>
|
||||
<input type="text" name="new_branch_name" value="{{.new_branch_name}}" class="input-contrast mr-2 js-quick-pull-new-branch-name" placeholder="{{.i18n.Tr "repo.editor.new_branch_name_desc"}}" {{if eq .commit_choice "commit-to-new-branch"}}required{{end}}>
|
||||
<span class="text-muted js-quick-pull-normalization-info"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="ui green button">
|
||||
{{.i18n.Tr "repo.editor.commit_changes"}}
|
||||
</button>
|
||||
<a class="ui button red" href="{{EscapePound $.BranchLink}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.editor.cancel"}}</a>
|
||||
</div>
|
12
templates/repo/editor/delete.tmpl
Normal file
12
templates/repo/editor/delete.tmpl
Normal file
|
@ -0,0 +1,12 @@
|
|||
{{template "base/head" .}}
|
||||
<div class="repository file editor delete">
|
||||
{{template "repo/header" .}}
|
||||
<div class="ui container">
|
||||
{{template "base/alert" .}}
|
||||
<form class="ui form" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
{{template "repo/editor/commit_form" .}}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{template "base/footer" .}}
|
|
@ -50,49 +50,7 @@
|
|||
{{.i18n.Tr "repo.release.loading"}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="commit-form-wrapper">
|
||||
<img width="48" height="48" class="ui image commit-avatar" src="{{.SignedUser.AvatarLink}}">
|
||||
<div class="commit-form">
|
||||
<h3>{{.i18n.Tr "repo.commit_changes"}}</h3>
|
||||
<div class="field">
|
||||
<input name="commit_summary" placeholder="{{if .IsNewFile}}{{.i18n.Tr "repo.add"}} '{{.TreePath}}/<filename>'{{else}}{{.i18n.Tr "repo.update"}} '{{.TreePath}}'{{end}}" value="{{.commit_summary}}">
|
||||
</div>
|
||||
<div class="field">
|
||||
<textarea name="commit_message" placeholder="{{.i18n.Tr "repo.default_commit_message"}}" rows="5">{{.commit_message}}</textarea>
|
||||
</div>
|
||||
<div class="quick-pull-choice js-quick-pull-choice">
|
||||
<div class="field">
|
||||
<div class="ui radio checkbox">
|
||||
<input type="radio" class="js-quick-pull-choice-option" name="commit_choice" value="direct" {{if eq .commit_choice "direct"}}checked{{end}}>
|
||||
<label>
|
||||
<i class="octicon octicon-git-commit" height="16" width="14"></i>
|
||||
{{.i18n.Tr "repo.editor.commit_directly_to_this_branch" .BranchName | Safe}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="ui radio checkbox">
|
||||
<input type="radio" class="js-quick-pull-choice-option" name="commit_choice" value="commit-to-new-branch" {{if eq .commit_choice "commit-to-new-branch"}}checked{{end}}>
|
||||
<label>
|
||||
<i class="octicon octicon-git-pull-request" height="16" width="12"></i>
|
||||
{{.i18n.Tr "repo.editor.create_new_branch" | Safe}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="quick-pull-branch-name {{if not (eq .commit_choice "commit-to-new-branch")}}hide{{end}}">
|
||||
<div class="new-branch-name-input{{if .Err_NewBranchName}} error{{end}}">
|
||||
<i class="octicon octicon-git-branch" height="16" width="10"></i>
|
||||
<input type="text" name="new_branch_name" value="{{.new_branch_name}}" class="form-control input-contrast mr-2 js-quick-pull-new-branch-name" placeholder="New branch name…">
|
||||
<span class="text-muted js-quick-pull-normalization-info"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="ui green button">
|
||||
{{.i18n.Tr "repo.commit_changes"}}
|
||||
</button>
|
||||
<a class="ui button red" href="{{EscapePound $.BranchLink}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.cancel"}}</a>
|
||||
</div>
|
||||
{{template "repo/editor/commit_form" .}}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -34,9 +34,9 @@
|
|||
</div>
|
||||
<div class="right fitted item">
|
||||
<div id="file-buttons" class="ui tiny buttons">
|
||||
{{if .NewFileLink}}
|
||||
<a href="{{EscapePound .NewFileLink}}" class="ui button">
|
||||
{{.i18n.Tr "repo.new_file"}}
|
||||
{{if .CanAddFile}}
|
||||
<a href="{{.RepoLink}}/_new/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}" class="ui button">
|
||||
{{.i18n.Tr "repo.editor.new_file"}}
|
||||
</a>
|
||||
{{end}}
|
||||
{{if .UploadFileLink}}
|
||||
|
|
|
@ -21,18 +21,14 @@
|
|||
<a class="ui button" href="{{EscapePound .FileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
|
||||
</div>
|
||||
{{if .CanEditFile}}
|
||||
<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="poping up octicon octicon-pencil btn-octicon" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
|
||||
<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-pencil btn-octicon poping up" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
|
||||
{{else}}
|
||||
<i class="octicon btn-octicon octicon-pencil poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
|
||||
<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
|
||||
{{end}}
|
||||
{{if .CanDeleteFile}}
|
||||
<form id="delete-file-form" class="ui form inline-form" action="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{.TreePath}}" method="post">
|
||||
{{.CsrfTokenHtml}}
|
||||
<button onclick="submitDeleteForm()" class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up" type="button" data-content="{{.FileDeleteLinkTooltip}}" data-position="bottom center" data-variation="tiny inverted"></button>
|
||||
<input type="hidden" id="delete-message" name="commit_message" value="">
|
||||
</form>
|
||||
<a href="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
|
||||
{{else}}
|
||||
<i class="octicon btn-octicon octicon-trashcan poping up disabled" data-content="{{.FileDeleteLinkTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
|
||||
<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
|
||||
{{end}}
|
||||
</div>
|
||||
{{end}}
|
||||
|
|
Loading…
Reference in a new issue