Skip to content

The Unified and Autonomous Development Platform

Draft version of file editing.

robin shine146cd8f7bf3c
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobNameChangeCallback.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobNameChangeCallback.java
index 12e59136c8..8af93fa2cd 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobNameChangeCallback.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobNameChangeCallback.java
@@ -1,7 +1,11 @@
package com.pmease.gitplex.web.component.blobview;
+import java.io.Serializable;
+
import org.apache.wicket.ajax.AjaxRequestTarget;
-public interface BlobNameChangeCallback {
+public interface BlobNameChangeCallback extends Serializable {
+
void onChange(AjaxRequestTarget target, String blobName);
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewPanel.java
index 0da0076cc3..870aea0a3e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/BlobViewPanel.java
@@ -5,6 +5,7 @@ import java.util.concurrent.atomic.AtomicReference;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
@@ -46,6 +47,8 @@ public abstract class BlobViewPanel extends Panel {
protected final BlobViewContext context;
+ private Component editPanel;
+
public BlobViewPanel(String id, BlobViewContext context) {
super(id);
@@ -202,21 +205,8 @@ public abstract class BlobViewPanel extends Panel {
String refName = Git.REFS_HEADS + file.revision;
final AtomicReference<String> newPathRef = new AtomicReference<>();
- final BlobNameChangeCallback callback = new BlobNameChangeCallback() {
-
- @Override
- public void onChange(AjaxRequestTarget target, String blobName) {
- String newPath;
- if (file.path.contains("/"))
- newPath = StringUtils.substringBeforeLast(file.path, "/") + "/" + blobName;
- else
- newPath = blobName;
- newPathRef.set(GitUtils.normalizePath(newPath));
- }
-
- };
- context.onEdit(target, callback);
- FileEditPanel fileEditPanel = new FileEditPanel(panelId, repoModel, refName,
+
+ editPanel = new FileEditPanel(panelId, repoModel, refName,
file.path, context.getBlob().getText().getContent(), commitId) {
@Override
@@ -226,7 +216,7 @@ public abstract class BlobViewPanel extends Panel {
String newPath = newPathRef.get();
if (file.path.equals(newPath)) {
- viewBlob(target);
+ restoreViewPanel(target);
context.onEditDone(target);
} else {
context.onSelect(target, new BlobIdent(file.revision, newPath, file.mode), null);
@@ -235,13 +225,28 @@ public abstract class BlobViewPanel extends Panel {
@Override
protected void onCancel(AjaxRequestTarget target) {
- viewBlob(target);
+ restoreViewPanel(target);
context.onEditDone(target);
}
};
- blobViewPanel.replaceWith(fileEditPanel);
- target.add(fileEditPanel);
+ final BlobNameChangeCallback callback = new BlobNameChangeCallback() {
+
+ @Override
+ public void onChange(AjaxRequestTarget target, String blobName) {
+ String newPath;
+ if (file.path.contains("/"))
+ newPath = StringUtils.substringBeforeLast(file.path, "/") + "/" + blobName;
+ else
+ newPath = blobName;
+ newPathRef.set(GitUtils.normalizePath(newPath));
+ ((FileEditPanel)editPanel).onNewPathChange(target, newPathRef.get());
+ }
+
+ };
+ context.onEdit(target, callback);
+ blobViewPanel.replaceWith(editPanel);
+ target.add(editPanel);
}
});
@@ -279,12 +284,12 @@ public abstract class BlobViewPanel extends Panel {
@Override
public void onCancel(AjaxRequestTarget target) {
- viewBlob(target);
+ restoreViewPanel(target);
}
};
- EditSavePanel saveChangePanel = new EditSavePanel(panelId, repoModel, refName,
- file.path, null, commitId, cancelListener) {
+ editPanel = new EditSavePanel(panelId, repoModel, refName, file.path,
+ null, commitId, cancelListener) {
@Override
protected void onCommitted(AjaxRequestTarget target, ObjectId newCommitId) {
@@ -310,8 +315,8 @@ public abstract class BlobViewPanel extends Panel {
}
};
- blobViewPanel.replaceWith(saveChangePanel);
- target.add(saveChangePanel);
+ blobViewPanel.replaceWith(editPanel);
+ target.add(editPanel);
}
});
@@ -319,11 +324,14 @@ public abstract class BlobViewPanel extends Panel {
setOutputMarkupId(true);
}
- private void viewBlob(AjaxRequestTarget target) {
- BlobViewPanel blobViewPanel = context.render(getId());
- replaceWith(blobViewPanel);
- target.add(blobViewPanel);
- target.appendJavaScript("$(window).resize();");
+ private void restoreViewPanel(AjaxRequestTarget target) {
+ if (editPanel != null) {
+ BlobViewPanel blobViewPanel = context.render(getId());
+ editPanel.replaceWith(blobViewPanel);
+ target.add(blobViewPanel);
+ target.appendJavaScript("$(window).resize();");
+ editPanel = null;
+ }
}
protected WebMarkupContainer newCustomActions(String id) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.html
index 6f4783ff2f..bf4977e1dd 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.html
@@ -11,11 +11,11 @@
<form wicket:id="form">
<div class="form-group">
<label>Summary Commit Message</label>
- <input wicket:id="summaryCommitMessage" class="form-control"></input>
+ <input wicket:id="summaryCommitMessage" class="summary-commit-message form-control"></input>
</div>
<div class="form-group">
<label>Detail Commit Message</label>
- <textarea wicket:id="detailCommitMessage" class="form-control" rows="10"></textarea>
+ <textarea wicket:id="detailCommitMessage" class="detail-commit-message form-control" rows="10"></textarea>
</div>
<div class="actions">
<input wicket:id="save" type="submit" class="btn btn-primary" value="Commit"></input>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.java
index 90226bcb85..840f77d16b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/EditSavePanel.java
@@ -4,6 +4,7 @@ import java.io.IOException;
import javax.annotation.Nullable;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
@@ -304,6 +305,11 @@ public abstract class EditSavePanel extends Panel {
protected abstract void onCommitted(AjaxRequestTarget target, ObjectId newCommitId);
+ public void onNewPathChange(AjaxRequestTarget target) {
+ target.appendJavaScript(String.format("gitplex.editSave.updateDefaultCommitMessage('%s', '%s');",
+ getMarkupId(), StringEscapeUtils.escapeEcmaScript(getDefaultCommitMessage())));
+ }
+
@Override
protected void onDetach() {
repoModel.detach();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/edit-save.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/edit-save.js
index c94c4919df..6201064a1a 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/edit-save.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/editsave/edit-save.js
@@ -2,7 +2,7 @@ gitplex.editSave = {
init: function(containerId) {
var $editSave = $("#" + containerId + ">.edit-save");
$editSave.scroll(function() {
- pmease.commons.history.setScrollPos({left: $body.scrollLeft(), top: $body.scrollTop()});
+ pmease.commons.history.setScrollPos({left: $editSave.scrollLeft(), top: $editSave.scrollTop()});
});
gitplex.expandable.getScrollTop = function() {
@@ -25,5 +25,8 @@ gitplex.editSave = {
});
$(window).resize();
+ },
+ updateDefaultCommitMessage: function(containerId, placeholder) {
+ $("#" + containerId + " .summary-commit-message").attr("placeholder", placeholder);
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.java
index de6fbfcd59..6a42dc47fe 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/FileEditPanel.java
@@ -5,6 +5,8 @@ import javax.annotation.Nullable;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;
import org.apache.wicket.ajax.attributes.CallbackParameter;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.head.CssHeaderItem;
@@ -45,6 +47,8 @@ public abstract class FileEditPanel extends Panel {
private AbstractDefaultAjaxBehavior saveBehavior;
+ private EditSavePanel editSavePanel;
+
public FileEditPanel(String id, IModel<Repository> repoModel, String refName,
@Nullable String oldPath, String content, ObjectId prevCommitId) {
super(id);
@@ -63,6 +67,12 @@ public abstract class FileEditPanel extends Panel {
previewBehavior = new AbstractDefaultAjaxBehavior() {
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.setMethod(Method.POST);
+ }
+
@Override
protected void respond(AjaxRequestTarget target) {
IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();
@@ -75,6 +85,12 @@ public abstract class FileEditPanel extends Panel {
saveBehavior = new AbstractDefaultAjaxBehavior() {
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.setMethod(Method.POST);
+ }
+
@Override
protected void respond(AjaxRequestTarget target) {
IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();
@@ -104,7 +120,7 @@ public abstract class FileEditPanel extends Panel {
}
};
- add(new EditSavePanel("save", repoModel, refName, oldPath, newFileModel, prevCommitId, null) {
+ add(editSavePanel = new EditSavePanel("save", repoModel, refName, oldPath, newFileModel, prevCommitId, null) {
@Override
protected void onCommitted(AjaxRequestTarget target, ObjectId newCommitId) {
@@ -149,6 +165,7 @@ public abstract class FileEditPanel extends Panel {
public void onNewPathChange(AjaxRequestTarget target, String newPath) {
this.newPath = newPath;
+ editSavePanel.onNewPathChange(target);
target.appendJavaScript(String.format("gitplex.fileEdit.setMode('%s', '%s');",
getMarkupId(), getNewPathParam()));
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js
index 287c5b1bd1..a5f3ba0942 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js
@@ -1,7 +1,7 @@
gitplex.fileEdit = {
init: function(containerId, filePath, fileContent, previewCallback, saveCallback) {
var $container = $("#" + containerId);
- var $code = $container.find(">file-edit>.body>.edit");
+ var $code = $container.find(">.file-edit>.body>.edit");
var cm = CodeMirror($code[0], {
value: fileContent,
theme: "eclipse",
@@ -15,18 +15,18 @@ gitplex.fileEdit = {
highlightIdentifiers: {delay: 500}
});
- setMode(cm, filePath);
+ gitplex.fileEdit.setMode(cm, filePath);
- $container.find(">file-edit>.head>.edit").click(function() {
+ $container.find(">.file-edit>.head>.edit").click(function() {
$container.find(">.file-edit>.body>.preview").hide();
$container.find(">.file-edit>.body>.save").hide();
$container.find(">.file-edit>.body>.edit").show();
});
$container.find(">.file-edit>.head>.preview").click(function() {
- previewCallback($cm.getValue());
+ previewCallback(cm.getValue());
});
$container.find(">.file-edit>.head>.save").click(function() {
- saveCallback($cm.getValue());
+ saveCallback(cm.getValue());
});
},
save: function(containerId) {
@@ -42,6 +42,7 @@ gitplex.fileEdit = {
$container.find(">.file-edit>.body>.preview").show();
},
setMode: function(cm, filePath) {
+ console.log(filePath);
if (typeof cm === "string")
cm = $("#"+ cm + ">.file-edit>.body>.edit>.CodeMirror")[0].CodeMirror;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.html
index ecdb435491..d8ba6d36df 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.html
@@ -13,7 +13,7 @@
<span wicket:id="label"></span>
</wicket:fragment>
<wicket:fragment wicket:id="nameEditFrag">
- <input wicket:id="path" type="text" class="form-control input-sm"></input>
+ <input wicket:id="name" type="text" class="form-control input-sm"></input>
</wicket:fragment>
<wicket:fragment wicket:id="addFileFrag">
<a wicket:id="addFile"><i class="fa fa-plus"></i></a>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.java
index 97aa672957..b209308fdd 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/filenavigator/FileNavigator.java
@@ -87,7 +87,9 @@ public abstract class FileNavigator extends Panel {
BlobIdent parent = treeSegments.get(treeSegments.size()-1);
int treeMode = FileMode.TREE.getBits();
if (i<segments.size()-1 || file.mode == treeMode) {
- String treePath = parent.path + "/" + segments.get(i);
+ String treePath = segments.get(i);
+ if (parent.path != null)
+ treePath = parent.path + "/" + treePath;
treeSegments.add(new BlobIdent(file.revision, treePath, treeMode));
}
}
@@ -116,7 +118,7 @@ public abstract class FileNavigator extends Panel {
}
};
- link.setEnabled(item.getIndex() != getViewSize()-1);
+ link.setEnabled(!file.isTree() || item.getIndex() != getViewSize()-1);
if (blobIdent.path != null) {
if (blobIdent.path.indexOf('/') != -1)
@@ -257,7 +259,16 @@ public abstract class FileNavigator extends Panel {
WebMarkupContainer lastSegment;
if (callback != null) {
lastSegment = new Fragment(LAST_SEGMENT_ID, "nameEditFrag", this);
- final TextField<String> nameInput = new TextField<String>("name");
+
+ String name;
+ if (file.isTree())
+ name = null;
+ else if (file.path.contains("/"))
+ name = StringUtils.substringAfterLast(file.path, "/");
+ else
+ name = file.path;
+
+ final TextField<String> nameInput = new TextField<String>("name", Model.of(name));
lastSegment.add(nameInput);
nameInput.add(new OnChangeAjaxBehavior() {
@@ -282,22 +293,25 @@ public abstract class FileNavigator extends Panel {
lastSegment.add(new AjaxLink<Void>("addFile") {
@Override
- public void onClick(AjaxRequestTarget target) {
+ protected void onConfigure() {
+ super.onConfigure();
+ setEnabled(repoModel.getObject().getRefs(Git.REFS_HEADS).containsKey(file.revision));
}
-
+
@Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
+ public void onClick(AjaxRequestTarget target) {
- if (!repoModel.getObject().getRefs(Git.REFS_HEADS).containsKey(file.revision))
- tag.put("disabled", "disabled");
}
});
} else {
lastSegment = new Fragment(LAST_SEGMENT_ID, "blobNameFrag", this);
- lastSegment.add(new Label("label", StringUtils.substringAfterLast(file.path, "/")));
+
+ String blobName = file.path;
+ if (blobName.contains("/"))
+ blobName = StringUtils.substringAfterLast(blobName, "/");
+ lastSegment.add(new Label("label", blobName));
}
add(lastSegment);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
index df23d823db..aa790957fe 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java
@@ -73,8 +73,6 @@ public class RepoFilePage extends RepositoryPage {
private static final String PARAM_BLAME = "blame";
- private static final String PARAM_ACTION = "action";
-
private static final String REVISION_SELECTOR_ID = "revisionSelector";
private static final String FILE_NAVIGATOR_ID = "fileNavigator";
@@ -125,13 +123,11 @@ public class RepoFilePage extends RepositoryPage {
} catch (IOException e) {
throw new RuntimeException(e);
}
+ } else {
+ state.file.mode = FileMode.TREE.getBits();
}
state.blame = params.get(PARAM_BLAME).toBoolean(false);
-
- String actionName = params.get(PARAM_ACTION).toString();
- if (actionName != null) {
- }
}
private ObjectId getCommitId() {