-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#53 Add a report template management section
- Loading branch information
Showing
14 changed files
with
266 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
ui/app/scripts/controllers/admin/AdminReportTemplatesCtrl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
angular.module('theHiveControllers') | ||
.controller('AdminReportTemplatesCtrl', AdminReportTemplatesCtrl) | ||
.controller('AdminReportTemplateDialogCtrl', AdminReportTemplateDialogCtrl); | ||
|
||
|
||
function AdminReportTemplatesCtrl($q, $modal, AnalyzerSrv, ReportTemplateSrv) { | ||
var self = this; | ||
|
||
this.templates = []; | ||
this.analyzers = []; | ||
|
||
|
||
this.load = function() { | ||
$q.all([ | ||
ReportTemplateSrv.list(), | ||
AnalyzerSrv.query({ | ||
range: 'all' | ||
}).$promise | ||
]).then(function (response) { | ||
self.templates = response[0].data; | ||
self.analyzers = response[1]; | ||
|
||
var map = _.indexBy(self.analyzers, 'id'); | ||
|
||
return $q.resolve(map); | ||
}).then(function (analyzersMap) { | ||
_.each(self.templates, function (tpl) { | ||
_.each(tpl.analyzers, function (analyzerId) { | ||
analyzersMap[analyzerId][tpl.flavor + 'Report'] = tpl; | ||
}); | ||
}); | ||
|
||
console.log(self.analyzers); | ||
}); | ||
}; | ||
|
||
this.showTemplate = function (reportTemplate, analyzer) { | ||
var modalInstance = $modal.open({ | ||
//scope: $scope, | ||
templateUrl: 'views/partials/admin/report-template-dialog.html', | ||
controller: 'AdminReportTemplateDialogCtrl', | ||
controllerAs: 'vm', | ||
size: 'max', | ||
resolve: { | ||
reportTemplate: function () { | ||
return reportTemplate; | ||
}, | ||
analyzer: function () { | ||
return analyzer; | ||
} | ||
} | ||
}); | ||
|
||
modalInstance.result.then(function() { | ||
self.load(); | ||
}); | ||
}; | ||
|
||
this.load(); | ||
}; | ||
|
||
function AdminReportTemplateDialogCtrl($modalInstance, reportTemplate, ReportTemplateSrv, analyzer) { | ||
this.reportTemplate = reportTemplate; | ||
this.analyzer = analyzer; | ||
this.reportTypes = ['short', 'long']; | ||
this.editorOptions = { | ||
useWrapMode: true, | ||
showGutter: true, | ||
theme: 'default', | ||
mode: 'xml' | ||
}; | ||
|
||
this.formData = _.pick(reportTemplate, 'id', 'flavor', 'content'); | ||
this.formData.analyzers = [this.analyzer.id]; | ||
|
||
this.cancel = function () { | ||
$modalInstance.dismiss(); | ||
}; | ||
|
||
this.saveTemplate = function() { | ||
ReportTemplateSrv.save(this.formData) | ||
.then(function() { | ||
$modalInstance.close(); | ||
}, function(response) { | ||
AlertSrv.error('AdminReportTemplateDialogCtrl', response.data, response.status); | ||
}); | ||
}; | ||
|
||
|
||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(function() { | ||
'use strict'; | ||
angular.module('theHiveServices') | ||
.factory('ReportTemplateSrv', function($resource, $http) { | ||
var baseUrl = '/api/report/template'; | ||
var resource = $resource(baseUrl, {}, { | ||
query: { | ||
method: 'POST', | ||
url: baseUrl + '/_search', | ||
isArray: true | ||
}, | ||
update: { | ||
method: 'PATCH' | ||
}, | ||
create: { | ||
method: 'POST' | ||
}, | ||
save: { | ||
method: 'PUT' | ||
} | ||
}); | ||
|
||
return { | ||
get: function() { | ||
return resource; | ||
}, | ||
|
||
list: function() { | ||
return $http.post(baseUrl + '/_search', { | ||
range: 'all' | ||
}); | ||
}, | ||
|
||
save: function(tpl) { | ||
if(tpl.id) { | ||
return $http.put(baseUrl + '/' + tpl.id, tpl, {}); | ||
} else { | ||
return $http.post(baseUrl, tpl, {}); | ||
} | ||
} | ||
} | ||
|
||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<form class="form-horizontal" name="tplForm" ng-submit="vm.saveTemplate()" novalidate> | ||
<div class="modal-header bg-primary"> | ||
<h3 class="modal-title">{{vm.reportTemplate.id ? 'Update' : 'Add'}} report template</h3> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label"> | ||
Report Type | ||
<i class="fa fa-asterisk text-danger"></i> | ||
</label> | ||
<div class="col-sm-4"> | ||
<select class="form-control" ng-model="vm.formData.flavor" ng-options="t for t in vm.reportTypes" required> | ||
<option value="">-- choose report type --</option> | ||
</select> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label">Analyzer</label> | ||
<div class="col-sm-10"> | ||
<p class="form-control-static">{{vm.formData.analyzers[0]}}</p> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label class="col-sm-2 control-label"> | ||
Template | ||
<i class="fa fa-asterisk text-danger"></i> | ||
</label> | ||
<div class="col-sm-10"> | ||
<div ui-ace="vm.editorOptions" | ||
ng-model="vm.formData.content" style="height: 400px;"></div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
<div class="modal-footer text-left"> | ||
<button class="btn btn-default" ng-click="vm.cancel()" type="button">Cancel</button> | ||
<button class="btn btn-primary pull-right" ng-disabled="taskForm.$invalid" type="submit">Save template</button> | ||
</div> | ||
</form> |
Oops, something went wrong.