Skip to content

Commit

Permalink
support renaming files for #394
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrachan committed Jul 16, 2013
1 parent 7c194bd commit a06fc19
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
12 changes: 12 additions & 0 deletions hawtio-web/src/main/webapp/app/git/js/git.ts
Expand Up @@ -21,6 +21,11 @@ module Git {
*/
revertTo(objectId:string, blobPath:string, commitMessage:string, fn): void;

/**
* Renames a file or moves a file to a new location
*/
rename(branch:string, oldPath:string, newPath:string, commitMessage:string, fn): void;

/**
* Removes a file if it exists
*/
Expand Down Expand Up @@ -84,6 +89,13 @@ module Git {
this.jolokia.execute(this.mbean, "revertTo", this.branch, objectId, blobPath, commitMessage, authorName, authorEmail, onSuccess(fn));
}

public rename(branch:string, oldPath: string, newPath:string, commitMessage:string, fn) {
var authorName = this.getUserName();
var authorEmail = this.getUserEmail();

this.jolokia.execute(this.mbean, "rename", branch, oldPath, newPath, commitMessage, authorName, authorEmail, onSuccess(fn));
}

public remove(branch:string, path:string, commitMessage:string, fn) {
var authorName = this.getUserName();
var authorEmail = this.getUserEmail();
Expand Down
57 changes: 54 additions & 3 deletions hawtio-web/src/main/webapp/app/wiki/html/viewPage.html
Expand Up @@ -22,6 +22,21 @@
<i class="icon-comments-alt"></i> History</a>
</li>
<li class="divider">
</li>
<li>
<a ng-click="openRenameDialog()" ng-disabled="gridOptions.selectedItems.length !== 1"
title="Rename the selected document"
data-placement="bottom">
<i class="icon-adjust"></i> Rename</a>
</li>
<li>
<a ng-click="openMoveDialog()" ng-disabled="!gridOptions.selectedItems.length"
title="move the selected documents to a new folder"
data-placement="bottom">
<i class="icon-move"></i> Move</a>
</li>
<li class="divider">
</li>
<li>
<a ng-click="openDeleteDialog()" ng-disabled="!gridOptions.selectedItems.length"
title="Delete the selected document(s)"
Expand Down Expand Up @@ -104,10 +119,46 @@
</ng-pluralize>
</p>
<div ng-bind-html-unsafe="selectedFileHtml"></div>
<!--
<p>This operation cannot be undone so please be careful.</p>
-->
</div>
</div>

<div modal="moveDialog.show" close="moveDialog.close()" ng-options="moveDialog.options">
<div class="modal-header"><h4>Move Document</h4></div>
<div class="modal-body">
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="moveFolder">Folder</label>
<div class="controls">
<input type="text" id="moveFolder" ng-model="moveFolder">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<input class="btn btn-primary" type="submit" ng-click="moveAndCloseDialog()"
ng-disabled="!moveFolder"
value="Move">
<button class="btn btn-warning cancel" type="button" ng-click="moveDialog.close()">Cancel</button>
</div>
</div>

<div modal="renameDialog.show" close="renameDialog.close()" ng-options="renameDialog.options">
<div class="modal-header"><h4>Rename Document</h4></div>
<div class="modal-body">
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="renameFileName">Name</label>
<div class="controls">
<input type="text" id="renameFileName" ng-model="fileName">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<input class="btn btn-primary" type="submit" ng-click="renameAndCloseDialog()"
ng-disabled="!fileName"
value="Rename">
<button class="btn btn-warning cancel" type="button" ng-click="renameDialog.close()">Cancel</button>
</div>
</div>
</div>
37 changes: 37 additions & 0 deletions hawtio-web/src/main/webapp/app/wiki/js/view.ts
Expand Up @@ -4,6 +4,8 @@ module Wiki {
Wiki.initScope($scope, $routeParams, $location);

$scope.addDialog = new Core.Dialog();
$scope.renameDialog = new Core.Dialog();
$scope.moveDialog = new Core.Dialog();
$scope.deleteDialog = false;
$scope.isFile = false;
$scope.createDocumentTree = Wiki.createWizardTree();
Expand Down Expand Up @@ -237,6 +239,41 @@ module Wiki {
$scope.deleteDialog = false;
};

$scope.openRenameDialog = () => {
var name = null;
if ($scope.gridOptions.selectedItems.length) {
var selected = $scope.gridOptions.selectedItems[0];
name = selected.name;
}
if (name) {
$scope.fileName = name;
$scope.renameDialog.open();
} else {
console.log("No items selected right now! " + $scope.gridOptions.selectedItems);
}
};

$scope.renameAndCloseDialog = () => {
if ($scope.gridOptions.selectedItems.length) {
var selected = $scope.gridOptions.selectedItems[0];
var newName = $scope.fileName;
if (selected && newName) {
var oldName = selected.name;
var oldPath = $scope.pageId + "/" + oldName;
var newPath = $scope.pageId + "/" + newName;
console.log("About to rename file " + oldPath + " to " + newPath);
$scope.git = wikiRepository.rename($scope.branch, oldPath, newPath, null, (result) => {
notification("success", "Renamed file to " + newName);
$scope.renameDialog.close();
Core.$apply($scope);
updateView();
});
}
}
$scope.renameDialog.close();
};


updateView();

function updateView() {
Expand Down
9 changes: 9 additions & 0 deletions hawtio-web/src/main/webapp/app/wiki/js/wikiRepository.ts
Expand Up @@ -78,6 +78,15 @@ module Wiki {
this.git().revertTo(objectId, fullPath, commitMessage, fn);
}

public rename(branch:string, oldPath:string, newPath:string, commitMessage:string, fn) {
var fullOldPath = this.getPath(oldPath);
var fullNewPath = this.getPath(newPath);
if (!commitMessage) {
commitMessage = "Renaming page " + oldPath + " to " + newPath;
}
this.git().rename(branch, fullOldPath, fullNewPath, commitMessage, fn);
}

public removePage(branch:string, path:string, commitMessage:string, fn) {
var fullPath = this.getPath(path);
if (!commitMessage) {
Expand Down

0 comments on commit a06fc19

Please sign in to comment.