Skip to content

Commit

Permalink
#1591 Fix the report template modal
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Oct 22, 2020
1 parent f8959cf commit fbc707f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 43 deletions.
60 changes: 28 additions & 32 deletions ui/app/scripts/controllers/admin/AdminReportTemplatesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
angular.module('theHiveControllers')
.controller('AdminReportTemplatesCtrl', AdminReportTemplatesCtrl)
.controller('AdminReportTemplateDialogCtrl', AdminReportTemplateDialogCtrl)
.controller('AdminReportTemplateImportCtrl', AdminReportTemplateImportCtrl)
.controller('AdminReportTemplateDeleteCtrl', AdminReportTemplateDeleteCtrl);
.controller('AdminReportTemplateImportCtrl', AdminReportTemplateImportCtrl);


function AdminReportTemplatesCtrl($q, $uibModal, AnalyzerSrv, ReportTemplateSrv, NotificationSrv) {
function AdminReportTemplatesCtrl($q, $uibModal, ModalUtilsSrv, AnalyzerSrv, ReportTemplateSrv, NotificationSrv) {
var self = this;

this.templates = [];
Expand Down Expand Up @@ -75,25 +74,32 @@
});

modalInstance.result.then(function() {
NotificationSrv.log('Report template has been saved successfully', 'success');

self.load();
}).catch(function(err) {
if(err && !_.isString(err)) {
NotificationSrv.error('AdminReportTemplateDialogCtrl', err.data, err.status);
}
});
};

this.deleteTemplate = function(template) {
var modalInstance = $uibModal.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();
ModalUtilsSrv.confirm('Remove report template', 'Are you sure you want to delete the ' + template.reportType + ' report template for analyzer ' + template.analyzerId + '?', {
okText: 'Yes, remove it',
flavor: 'danger'
}).then(function() {
ReportTemplateSrv.delete(template.id)
.then(function() {
self.load();
NotificationSrv.log('Report template has been permanently deleted', 'success');
})
.catch(function(err) {
if(err && !_.isString(err)) {
NotificationSrv.error('AdminReportTemplateDialogCtrl', err.data, err.status);
}
});
});
};

Expand All @@ -107,7 +113,13 @@
});

modalInstance.result.then(function() {
NotificationSrv.log('Report templates have been imported successfully', 'success');

self.load();
}).catch(function(err) {
if(err && !_.isString(err)) {
NotificationSrv.error('AdminReportTemplateDialogCtrl', err.data, err.status);
}
});
};

Expand Down Expand Up @@ -142,22 +154,6 @@
};
}

function AdminReportTemplateDeleteCtrl($uibModalInstance, ReportTemplateSrv, NotificationSrv, template) {
this.template = template;

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

function AdminReportTemplateImportCtrl($uibModalInstance, ReportTemplateSrv, NotificationSrv) {
this.formData = {};

Expand Down
2 changes: 1 addition & 1 deletion ui/app/views/partials/admin/report-template-dialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h3 class="modal-title">{{vm.reportTemplate.id ? 'Update' : 'Add'}} report templ
<i class="fa fa-asterisk text-danger"></i>
</label>
<div class="col-sm-4">
<select class="form-control" ng-model="vm.formData.reportType" ng-options="t for t in vm.reportTypes" required>
<select class="form-control" ng-model="vm.formData.reportType" ng-options="t for t in vm.reportTypes" required disabled>
<option value="">-- choose report type --</option>
</select>
</div>
Expand Down
20 changes: 10 additions & 10 deletions ui/app/views/partials/admin/report-templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ <h3 class="box-title">Report template management</h3>
<tbody>
<tr ng-repeat="analyzerId in vm.analyzerIds | orderBy:'toString()'" ng-init="analyzer=vm.analyzers[analyzerId]">
<td>
{{::analyzer.name || analyzer.id}}<br>
<small class="text-muted">{{::analyzer.description}}</small>
{{::vm.analyzers[analyzerId].name || vm.analyzers[analyzerId].id}}<br>
<small class="text-muted">{{::vm.analyzers[analyzerId].description}}</small>
</td>
<td class="vmiddle">
<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 class="btn-group btn-group-sm" ng-if="vm.analyzers[analyzerId].shortReport">
<button type="button" class="btn btn-default" ng-click="vm.showTemplate(vm.analyzers[analyzerId].shortReport, analyzer)">View Template</button>
<button type="button" class="btn btn-danger" ng-click="vm.deleteTemplate(vm.analyzers[analyzerId].shortReport)"><i class="fa fa-times"></i></button>
</div>
<div class="btn-group btn-group-sm" ng-if="!analyzer.shortReport">
<div class="btn-group btn-group-sm" ng-if="!vm.analyzers[analyzerId].shortReport">
<button type="button" class="btn btn-default" ng-click="vm.showTemplate({reportType: 'short'}, analyzer)">Default template</button>
</div>
</td>
<td class="vmiddle">
<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 class="btn-group btn-group-sm" ng-if="vm.analyzers[analyzerId].longReport">
<button type="button" class="btn btn-default" ng-click="vm.showTemplate(vm.analyzers[analyzerId].longReport, analyzer)">View Template</button>
<button type="button" class="btn btn-danger" ng-click="vm.deleteTemplate(vm.analyzers[analyzerId].longReport)"><i class="fa fa-times"></i></button>
</div>
<div class="btn-group btn-group-sm" ng-if="!analyzer.longReport">
<div class="btn-group btn-group-sm" ng-if="!vm.analyzers[analyzerId].longReport">
<button type="button" class="btn btn-default" ng-click="vm.showTemplate({reportType: 'long'}, analyzer)">Default template</button>
</div>
</td>
Expand Down

0 comments on commit fbc707f

Please sign in to comment.