-
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.
#1816 Add custom tag management tag under organisation details page
- Loading branch information
Showing
7 changed files
with
418 additions
and
12 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
233 changes: 233 additions & 0 deletions
233
frontend/app/scripts/components/organisation/OrgCustomTagsListCmp.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,233 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
angular.module('theHiveComponents') | ||
.component('orgCustomTagsList', { | ||
controller: function($uibModal, $scope, PaginatedQuerySrv, FilteringSrv, UserSrv, NotificationSrv, ModalUtilsSrv) { | ||
var self = this; | ||
|
||
self.tags = []; | ||
self.getUserInfo = UserSrv.getCache; | ||
|
||
this.$onInit = function() { | ||
// TODO: FIXME | ||
self.filtering = new FilteringSrv('taxonomy', 'custom-tags.list', { | ||
version: 'v1', | ||
defaults: { | ||
showFilters: true, | ||
showStats: false, | ||
pageSize: 15, | ||
sort: ['+predicate'] | ||
}, | ||
defaultFilter: [] | ||
}); | ||
|
||
self.filtering.initContext(self.organisation.name) | ||
.then(function() { | ||
self.load(); | ||
|
||
$scope.$watch('$vm.list.pageSize', function (newValue) { | ||
self.filtering.setPageSize(newValue); | ||
}); | ||
}); | ||
}; | ||
|
||
this.load = function() { | ||
|
||
self.list = new PaginatedQuerySrv({ | ||
name: 'organisation-custom-tags', | ||
version: 'v1', | ||
skipStream: true, | ||
sort: self.filtering.context.sort, | ||
loadAll: false, | ||
pageSize: self.filtering.context.pageSize, | ||
filter: this.filtering.buildQuery(), | ||
operations: [ | ||
{ | ||
'_name': 'listTag' | ||
}, | ||
{ | ||
'_name': 'freetags' | ||
} | ||
], | ||
onFailure: function(err) { | ||
if(err && err.status === 400) { | ||
self.filtering.resetContext(); | ||
self.load(); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
// Filtering | ||
this.toggleFilters = function () { | ||
this.filtering.toggleFilters(); | ||
}; | ||
|
||
this.filter = function () { | ||
self.filtering.filter().then(this.applyFilters); | ||
}; | ||
|
||
this.clearFilters = function () { | ||
this.filtering.clearFilters() | ||
.then(self.search); | ||
}; | ||
|
||
this.removeFilter = function (index) { | ||
self.filtering.removeFilter(index) | ||
.then(self.search); | ||
}; | ||
|
||
this.search = function () { | ||
self.load(); | ||
self.filtering.storeContext(); | ||
}; | ||
this.addFilterValue = function (field, value) { | ||
this.filtering.addFilterValue(field, value); | ||
this.search(); | ||
}; | ||
|
||
this.filterBy = function(field, value) { | ||
self.filtering.clearFilters() | ||
.then(function(){ | ||
self.addFilterValue(field, value); | ||
}); | ||
}; | ||
|
||
this.sortBy = function(sort) { | ||
self.list.sort = sort; | ||
self.list.update(); | ||
self.filtering.setSort(sort); | ||
}; | ||
|
||
this.sortByField = function(field) { | ||
var context = this.filtering.context; | ||
var currentSort = Array.isArray(context.sort) ? context.sort[0] : context.sort; | ||
var sort = null; | ||
|
||
if(currentSort.substr(1) !== field) { | ||
sort = ['+' + field]; | ||
} else { | ||
sort = [(currentSort === '+' + field) ? '-'+field : '+'+field]; | ||
} | ||
|
||
self.list.sort = sort; | ||
self.list.update(); | ||
self.filtering.setSort(sort); | ||
}; | ||
|
||
|
||
// this.showTemplate = function(template) { | ||
|
||
// var promise = template._id ? CaseTemplateSrv.get(template._id) : $q.resolve(template); | ||
|
||
// promise | ||
// .then(function(response) { | ||
// var modalInstance = $uibModal.open({ | ||
// animation: true, | ||
// keyboard: false, | ||
// backdrop: 'static', | ||
// templateUrl: 'views/components/org/case-template/details.modal.html', | ||
// controller: 'OrgCaseTemplateModalCtrl', | ||
// controllerAs: '$vm', | ||
// size: 'max', | ||
// resolve: { | ||
// template: function() { | ||
// return response; | ||
// }, | ||
// fields: function() { | ||
// return self.fields; | ||
// } | ||
// } | ||
// }); | ||
|
||
// return modalInstance.result; | ||
// }) | ||
// .then(function() { | ||
// self.load(); | ||
// }) | ||
// .catch(function(err) { | ||
// if(err && !_.isString(err)) { | ||
// NotificationSrv.error('Case Template Admin', err.data, err.status); | ||
// } | ||
// }) | ||
// } | ||
|
||
// self.createTemplate = function(template) { | ||
// return CaseTemplateSrv.create(template).then( | ||
// function(/*response*/) { | ||
// self.load(); | ||
|
||
// $scope.$emit('templates:refresh'); | ||
|
||
// NotificationSrv.log('The template [' + template.name + '] has been successfully created', 'success'); | ||
// }, | ||
// function(response) { | ||
// NotificationSrv.error('TemplateCtrl', response.data, response.status); | ||
// } | ||
// ); | ||
// }; | ||
|
||
// self.importTemplate = function() { | ||
// var modalInstance = $uibModal.open({ | ||
// animation: true, | ||
// templateUrl: 'views/components/org/case-template/import.html', | ||
// controller: 'AdminCaseTemplateImportCtrl', | ||
// controllerAs: 'vm', | ||
// size: 'lg' | ||
// }); | ||
|
||
// modalInstance.result | ||
// .then(function(template) { | ||
// return self.createTemplate(template); | ||
// }) | ||
// .catch(function(err) { | ||
// if (err && err.status) { | ||
// NotificationSrv.error('TemplateCtrl', err.data, err.status); | ||
// } | ||
// }); | ||
// }; | ||
|
||
// self.deleteTemplate = function (template) { | ||
// ModalUtilsSrv.confirm('Remove case template', 'Are you sure you want to delete this case template?', { | ||
// okText: 'Yes, remove it', | ||
// flavor: 'danger' | ||
// }) | ||
// .then(function () { | ||
// return CaseTemplateSrv.delete(template._id); | ||
// }) | ||
// .then(function () { | ||
// self.load(); | ||
|
||
// $scope.$emit('templates:refresh'); | ||
// }); | ||
// }; | ||
|
||
// self.exportTemplate = function (template) { | ||
// CaseTemplateSrv.get(template._id) | ||
// .then(function(response) { | ||
// var fileName = 'Case-Template__' + response.name.replace(/\s/gi, '_') + '.json'; | ||
|
||
// // Create a blob of the data | ||
// var fileToSave = new Blob([angular.toJson(_.omit(response, 'id'))], { | ||
// type: 'application/json', | ||
// name: fileName | ||
// }); | ||
|
||
// // Save the file | ||
// saveAs(fileToSave, fileName); | ||
// }) | ||
|
||
// }; | ||
}, | ||
controllerAs: '$vm', | ||
templateUrl: 'views/components/org/custom-tags/tag-list.html', | ||
bindings: { | ||
organisation: '<', | ||
templates: '=', | ||
fields: '<', | ||
onReload: '&', | ||
onEdit: '&' | ||
} | ||
}); | ||
})(); |
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
39 changes: 39 additions & 0 deletions
39
frontend/app/views/components/org/custom-tags/filters.html
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 @@ | ||
<div class="row"> | ||
<div class="col-md-12 active-filters"> | ||
<h4>Filters</h4> | ||
|
||
<form ng-submit="$vm.search()"> | ||
<div class="row mb-xxxs" ng-repeat="filter in $vm.filtering.context.filters track by $index"> | ||
<div class="col-sm-4 col-md-4 col-lg-2"> | ||
<div class="input-group"> | ||
<span class="input-group-btn"> | ||
<button class="btn btn-default" type="button" ng-click="$vm.removeFilter($index)"> | ||
<i class="fa fa-times text-danger"></i> | ||
</button> | ||
</span> | ||
<select class="form-control" ng-model="filter.field" | ||
ng-options="item for item in $vm.filtering.attributeKeys" | ||
ng-change="$vm.filtering.setFilterField(filter, config.entity)"></select> | ||
</div> | ||
</div> | ||
<div class="col-sm-8 col-md-8 col-lg-6"> | ||
<filter-editor metadata="$vm.filtering.metadata" filter="filter" entity="$vm.filtering.entity"></filter-editor> | ||
</div> | ||
</div> | ||
<div class="mv-xs row"> | ||
<div class="col-sm-12 col-md-12 col-lg-8"> | ||
<a href class="btn btn-sm btn-link btn-clear" ng-click="$vm.filtering.addFilter()"> | ||
<i class="fa fa-plus"></i> Add a filter | ||
</a> | ||
<a href class="btn btn-sm btn-danger" ng-click="$vm.clearFilters()" ng-if="$vm.filtering.context.filters.length > 0"> | ||
<i class="fa fa-times"></i> Clear | ||
</a> | ||
<button href class="btn btn-sm btn-primary pull-right" type="submit" ng-if="$vm.filtering.context.filters.length > 0"> | ||
<i class="fa fa-search"></i> Search | ||
</button> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
</div> | ||
</div> |
Oops, something went wrong.