Skip to content

Commit

Permalink
#53 Add support to report template delete
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Dec 15, 2016
1 parent 0de4ccb commit 8f71cdb
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 25 deletions.
41 changes: 37 additions & 4 deletions ui/app/scripts/controllers/admin/AdminReportTemplatesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
angular.module('theHiveControllers')
.controller('AdminReportTemplatesCtrl', AdminReportTemplatesCtrl)
.controller('AdminReportTemplateDialogCtrl', AdminReportTemplateDialogCtrl)
.controller('AdminReportTemplateImportCtrl', AdminReportTemplateImportCtrl);
.controller('AdminReportTemplateImportCtrl', AdminReportTemplateImportCtrl)
.controller('AdminReportTemplateDeleteCtrl', AdminReportTemplateDeleteCtrl);


function AdminReportTemplatesCtrl($q, $modal, AnalyzerSrv, ReportTemplateSrv) {
Expand Down Expand Up @@ -63,6 +64,24 @@
});
};

this.deleteTemplate = function(template) {
var modalInstance = $modal.open({
templateUrl: 'views/partials/admin/report-template-delete.html',
controller: 'AdminReportTemplateDeleteCtrl',
controllerAs: 'vm',
size: '',
resolve: {
template: function() {
return template;
}
}
});

modalInstance.result.then(function() {
self.load();
});
};

this.import = function (analyzer, dataType) {
var modalInstance = $modal.open({
animation: true,
Expand Down Expand Up @@ -105,11 +124,25 @@
}, function(response) {
AlertSrv.error('AdminReportTemplateDialogCtrl', response.data, response.status);
});
};


};
}

function AdminReportTemplateDeleteCtrl($modalInstance, ReportTemplateSrv, AlertSrv, template) {
this.template = template;

this.ok = function () {
ReportTemplateSrv.delete(template.id)
.then(function() {
$modalInstance.close();
}, function(response) {
AlertSrv.error('AdminReportTemplateDeleteCtrl', response.data, response.status);
});
};
this.cancel = function () {
$modalInstance.dismiss('cancel');
};
};

function AdminReportTemplateImportCtrl($modalInstance, ReportTemplateSrv, AlertSrv) {
this.formData = {};

Expand Down
4 changes: 4 additions & 0 deletions ui/app/scripts/services/ReportTemplateSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
}
},

delete: function(tplId) {
return $http.delete(baseUrl + '/' + tplId);
},

import: function(post) {
var postData = {
templates: post.attachment
Expand Down
4 changes: 3 additions & 1 deletion ui/app/scripts/services/VersionSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
try {
var service = cache.connectors.cortex;

return service.enabled && service.servers.length;
// TODO check how to verify if cortex is enabled
//return service.enabled && service.servers.length;
return service.enabled;
} catch (err) {
return false;
}
Expand Down
15 changes: 15 additions & 0 deletions ui/app/views/partials/admin/report-template-delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="modal-header bg-primary">
<h3 class="modal-title">Remove report template</h3>
</div>
<div class="modal-body">
<p>
Are you sure you want to delete the {{vm.template.flavor}} report template for analyzer <strong>{{vm.template.analyzers}}</strong>.
</p>
<p>
This action cannot be undone.
</p>
</div>
<div class="modal-footer text-left">
<button class="btn btn-default" ng-click="vm.cancel()" type="button">Cancel</button>
<button class="btn btn-danger pull-right" ng-click="vm.ok()">Yes, Delete the report template</button>
</div>
38 changes: 18 additions & 20 deletions ui/app/views/partials/admin/report-templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ <h2>Report template management</h2>
<div class="btn-group">
<button type="button" class="btn btn-primary" ng-click="vm.import()">
<span class="fa fa-upload"></span> Import templates
</button>
</button>
</div>
</div>
</div>
</div>
</div>

<div class="row mv-s" ng-show="vm.analyzerCount === 0">
<div class="col-md-12">
<div class="empty-message">No report templates found.</div>
</div>
</div>

<div class="row" ng-show="vm.analyzerCount > 0">
<div class="col-md-12">
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Name</th>
<th width="200px">Short template</th>
<th width="200px">Long template</th>
</tr>
Expand All @@ -34,24 +32,24 @@ <h2>Report template management</h2>
<td>
{{::analyzer.id}}<br>
<small class="text-muted">{{::analyzer.description}}</small>
</td>
</td>
<td class="vmiddle">
<span class="clickable label label-lg label-success"
ng-if="analyzer.shortReport"
ng-click="vm.showTemplate(analyzer.shortReport, analyzer)">View Template</span>

<span class="clickable label label-lg label-default"
ng-if="!analyzer.shortReport",
ng-click="vm.showTemplate({flavor: 'short'}, analyzer)"><em>Default template</em></span>
<div class="btn-group btn-group-sm" ng-if="analyzer.shortReport">
<button type="button" class="btn btn-default" ng-click="vm.showTemplate(analyzer.shortReport, analyzer)">View Template</button>
<button type="button" class="btn btn-danger" ng-click="vm.deleteTemplate(analyzer.shortReport)"><i class="fa fa-times"></i></button>
</div>
<div class="btn-group btn-group-sm" ng-if="!analyzer.shortReport">
<button type="button" class="btn btn-dark" ng-click="vm.showTemplate({flavor: 'short'}, analyzer)">Default template</button>
</div>
</td>
<td class="vmiddle">
<span class="clickable label label-lg label-success"
ng-if="analyzer.longReport"
ng-click="vm.showTemplate(analyzer.longReport, analyzer)">View Template</span>

<span class="clickable label label-lg label-default"
ng-if="!analyzer.longReport"
ng-click="vm.showTemplate({flavor: 'long'}, analyzer)"><em>Default template</em></span>
<div class="btn-group btn-group-sm" ng-if="analyzer.longReport">
<button type="button" class="btn btn-default" ng-click="vm.showTemplate(analyzer.longReport, analyzer)">View Template</button>
<button type="button" class="btn btn-danger" ng-click="vm.deleteTemplate(analyzer.longReport)"><i class="fa fa-times"></i></button>
</div>
<div class="btn-group btn-group-sm" ng-if="!analyzer.longReport">
<button type="button" class="btn btn-dark" ng-click="vm.showTemplate({flavor: 'long'}, analyzer)">Default template</button>
</div>
</td>
</tr>
</tbody>
Expand Down

0 comments on commit 8f71cdb

Please sign in to comment.