Navigation Menu

Skip to content

Commit

Permalink
fixes #390 so that the wiki can delete one or more files easily
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrachan committed Jul 15, 2013
1 parent 0dc5f01 commit 042a6d6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 9 deletions.
Expand Up @@ -137,7 +137,7 @@ module Dashboard {
angular.forEach(array, (dash) => {
var path = this.getDashboardPath(dash);
var commitMessage = "Removing dashboard " + path;
this.git.remove(path, commitMessage, fn);
this.git.remove(this.branch, path, commitMessage, fn);
});
}

Expand Down
6 changes: 3 additions & 3 deletions hawtio-web/src/main/webapp/app/git/js/git.ts
Expand Up @@ -24,7 +24,7 @@ module Git {
/**
* Removes a file if it exists
*/
remove(path:string, commitMessage:string, fn): void;
remove(branch:string, path:string, commitMessage:string, fn): void;


/**
Expand Down Expand Up @@ -84,11 +84,11 @@ module Git {
this.jolokia.execute(this.mbean, "revertTo", this.branch, objectId, blobPath, commitMessage, authorName, authorEmail, onSuccess(fn));
}

public remove(path:string, commitMessage:string, fn) {
public remove(branch:string, path:string, commitMessage:string, fn) {
var authorName = this.getUserName();
var authorEmail = this.getUserEmail();

this.jolokia.execute(this.mbean, "remove", this.branch, path, commitMessage, authorName, authorEmail, onSuccess(fn));
this.jolokia.execute(this.mbean, "remove", branch, path, commitMessage, authorName, authorEmail, onSuccess(fn));
}

/**
Expand Down
23 changes: 23 additions & 0 deletions hawtio-web/src/main/webapp/app/wiki/html/viewPage.html
Expand Up @@ -6,6 +6,12 @@
<a ng-href="{{link.href}}{{hash}}">{{link.name}}</a>
</li>

<li class="pull-right">
<a ng-click="openDeleteDialog()" ng-disabled="!gridOptions.selectedItems.length"
title="Delete the selected document(s)"
data-placement="bottom">
<i class="icon-remove"></i> Delete</a>
</li>
<li class="pull-right">
<a ng-href="{{editLink()}}{{hash}}" ng-hide="!editLink()" title="Edit this page"
data-placement="bottom">
Expand Down Expand Up @@ -79,4 +85,21 @@
</div>
</div>
</div>

<div hawtio-confirm-dialog="deleteDialog"
ok-button-text="Delete"
on-ok="deleteAndCloseDialog()">
<div class="dialog-body">
<p>You are about to delete
<ng-pluralize count="gridOptions.selectedItems.length"
when="{'1': 'this document!', 'other': 'these {} documents!'}">
</ng-pluralize>
</p>
<div ng-bind-html-unsafe="selectedFileHtml"></div>
<!--
<p>This operation cannot be undone so please be careful.</p>
-->
</div>
</div>

</div>
37 changes: 36 additions & 1 deletion hawtio-web/src/main/webapp/app/wiki/js/view.ts
Expand Up @@ -4,16 +4,19 @@ module Wiki {
Wiki.initScope($scope, $routeParams, $location);

$scope.addDialog = new Core.Dialog();
$scope.deleteDialog = false;
$scope.createDocumentTree = Wiki.createWizardTree();
$scope.createDocumentTreeActivations = ["camel-spring.xml", "ReadMe.md"];

$scope.gridOptions = {
data: 'children',
displayFooter: false,
selectedItems: [],
showSelectionCheckbox: true,
columnDefs: [
{
field: 'name',
displayName: 'Page Name',
displayName: 'Name',
cellTemplate: '<div class="ngCellText"><a href="{{childLink(row.entity)}}"><i class="{{row | fileIconClass}}"></i> {{row.getProperty(col.field)}}</a></div>',
cellFilter: ""
},
Expand Down Expand Up @@ -119,6 +122,7 @@ module Wiki {
$scope.addDialog.open();
};


$scope.addAndCloseDialog = () => {
var template = $scope.selectedCreateDocumentTemplate;
if (!template) {
Expand Down Expand Up @@ -188,6 +192,37 @@ module Wiki {
$scope.addDialog.close();
};


$scope.openDeleteDialog = () => {
if ($scope.gridOptions.selectedItems.length) {
$scope.selectedFileHtml = "<ul>" + $scope.gridOptions.selectedItems.map(file => "<li>" + file.name + "</li>").sort().join("") + "</ul>";
$scope.deleteDialog = true;
} else {
console.log("No items selected right now! " + $scope.gridOptions.selectedItems);
}
};

$scope.deleteAndCloseDialog = () => {
var files = $scope.gridOptions.selectedItems;
console.log("Deleting selection: " + files);
var removed = 0;
angular.forEach(files, (file, idx) => {
var path = $scope.pageId + "/" + file.name;
console.log("About to delete " + path);
$scope.git = wikiRepository.removePage($scope.branch, path, null, (result) => {
removed += 1;
if (idx + 1 === files.length) {
$scope.gridOptions.selectedItems.splice(0, files.length);
var message = Core.maybePlural(removed, "document");
notification("success", "Deleted " + message);
Core.$apply($scope);
updateView();
}
});
});
$scope.deleteDialog = false;
};

updateView();

function updateView() {
Expand Down
10 changes: 6 additions & 4 deletions hawtio-web/src/main/webapp/app/wiki/js/wikiRepository.ts
Expand Up @@ -3,7 +3,7 @@ module Wiki {
export interface WikiRepository {
putPage(branch:string, path:string, contents:string, commitMessage:string, fn): void;

deletePage(path:string, fn): void;
removePage(branch:string, path:string, commitMessage:string, fn): void;
}

export class GitWikiRepository implements WikiRepository {
Expand Down Expand Up @@ -78,10 +78,12 @@ module Wiki {
this.git().revertTo(objectId, fullPath, commitMessage, fn);
}

public deletePage(path:string, fn) {
public removePage(branch:string, path:string, commitMessage:string, fn) {
var fullPath = this.getPath(path);
var commitMessage = "Removing wiki page " + path;
this.git().remove(fullPath, commitMessage, fn);
if (!commitMessage) {
commitMessage = "Removing page " + path;
}
this.git().remove(branch, fullPath, commitMessage, fn);
}

/**
Expand Down

0 comments on commit 042a6d6

Please sign in to comment.