Skip to content

Commit

Permalink
#1816 Add custom tag management tag under organisation details page
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Mar 5, 2021
1 parent 32df782 commit 64b66dc
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 12 deletions.
1 change: 1 addition & 0 deletions frontend/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
<script src="scripts/components/organisation/OrgCaseTemplateListCmp.js"></script>
<script src="scripts/components/organisation/OrgCaseTemplateModalCtrl.js"></script>
<script src="scripts/components/organisation/OrgConfigListCmp.js"></script>
<script src="scripts/components/organisation/OrgCustomTagsListCmp.js"></script>
<script src="scripts/components/organisation/OrgSwitchCtrl.js"></script>
<script src="scripts/components/organisation/OrgUserListCmp.js"></script>
<script src="scripts/components/search/filters-preview.component.js"></script>
Expand Down
233 changes: 233 additions & 0 deletions frontend/app/scripts/components/organisation/OrgCustomTagsListCmp.js
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: '&'
}
});
})();
30 changes: 19 additions & 11 deletions frontend/app/views/components/org/case-template/case-templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,20 @@ <h4>
Custom Fields
</th>
<th style="width: 60px;">By</th>
<th style="width: 120px">
<a href class="text-default" ng-click="$vm.sortByField('_createdAt')">
Creation Date
<i ng-show="$vm.filtering.context.sort.indexOf('+_createdAt') === -1 && $vm.filtering.context.sort.indexOf('-_createdAt') === -1" class="fa fa-sort"></i>
<i ng-show="$vm.filtering.context.sort.indexOf('+_createdAt') !== -1" class="fa fa-caret-up"></i>
<i ng-show="$vm.filtering.context.sort.indexOf('-_createdAt') !== -1" class="fa fa-caret-down"></i>
</a>
<th style="width: 150px">
Dates
<a href class="text-default ml-xxxs" ng-click="$vm.sortByField('_createdAt')" uib-tooltip="Sort by creation date">
C.
<i ng-show="$vm.filtering.context.sort.indexOf('+_createdAt') === -1 && $vm.filtering.context.sort.indexOf('-_createdAt') === -1" class="fa fa-sort"></i>
<i ng-show="$vm.filtering.context.sort.indexOf('+_createdAt') !== -1" class="fa fa-caret-up"></i>
<i ng-show="$vm.filtering.context.sort.indexOf('-_createdAt') !== -1" class="fa fa-caret-down"></i>
</a>
<a href class="text-default ml-xxxs" ng-click="$vm.sortByField('_updatedAt')" uib-tooltip="Sort by last update date">
U.
<i ng-show="$vm.filtering.context.sort.indexOf('+_updatedAt') === -1 && $vm.filtering.context.sort.indexOf('-_updatedAt') === -1" class="fa fa-sort"></i>
<i ng-show="$vm.filtering.context.sort.indexOf('+_updatedAt') !== -1" class="fa fa-caret-up"></i>
<i ng-show="$vm.filtering.context.sort.indexOf('-_updatedAt') !== -1" class="fa fa-caret-down"></i>
</a>
</th>
<th style="width: 120px">Actions</th>
</tr>
Expand Down Expand Up @@ -108,10 +115,11 @@ <h4>
<user user-id="template._createdBy" icon-only="true" icon-size="m"></user>
</td>
<td>
<div>
<a href ng-click="$vm.addFilterValue('_createdAt', template._createdAt)">
<span uib-tooltip="{{template._createdAt | shortDate}}" tooltip-popup-delay="500" tooltip-placement="bottom">{{template._createdAt | shortDate}}</span>
</a>
<div ng-class="{'text-bold': $vm.filtering.context.sort.indexOf('+_createdAt') !== -1 || $vm.filtering.context.sort.indexOf('-_createdAt') !== -1}">
C. <a href ng-click="$vm.addFilterValue('_createdAt', template._createdAt)">{{template._createdAt | shortDate}}</a>
</div>
<div ng-if="template._updatedAt > 0" ng-class="{'text-bold': $vm.filtering.context.sort.indexOf('+_updatedAt') !== -1 || $vm.filtering.context.sort.indexOf('-_updatedAt') !== -1}">
U. <a href ng-click="$vm.addFilterValue('_updatedAt', template._updatedAt)">{{template._updatedAt | shortDate}}</a>
</div>
</td>
<td class="text-center">
Expand Down
39 changes: 39 additions & 0 deletions frontend/app/views/components/org/custom-tags/filters.html
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>
Loading

0 comments on commit 64b66dc

Please sign in to comment.