Skip to content

Commit

Permalink
#1816 Allow free tag delete + add tag usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Mar 5, 2021
1 parent 4b4909b commit 6b9d6d5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 116 deletions.
124 changes: 19 additions & 105 deletions frontend/app/scripts/components/organisation/OrgCustomTagsListCmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

angular.module('theHiveComponents')
.component('orgCustomTagsList', {
controller: function($scope, PaginatedQuerySrv, FilteringSrv, TagSrv, UserSrv, NotificationSrv) {
controller: function($scope, PaginatedQuerySrv, FilteringSrv, TagSrv, UserSrv, ModalUtilsSrv, NotificationSrv) {
var self = this;

self.tags = [];
Expand Down Expand Up @@ -50,6 +50,7 @@
'_name': 'freetags'
}
],
extraData: ['usage'],
onFailure: function(err) {
if(err && err.status === 400) {
self.filtering.resetContext();
Expand All @@ -59,6 +60,23 @@
});
};

self.deleteTag = function (tag) {
ModalUtilsSrv.confirm('Remove free tag', 'Are you sure you want to delete this tag?', {
okText: 'Yes, remove it',
flavor: 'danger'
})
.then(function () {
return TagSrv.removeTag(tag._id);
})
.then(function () {
NotificationSrv.success('Tag list', 'Tag removed successfully');

self.load();

$scope.$emit('freetags:refresh');
});
};

self.updateColour = function(id, colour) {
TagSrv.updateTag(id, {colour: colour})
.then(function(/*response*/) {
Expand Down Expand Up @@ -125,110 +143,6 @@
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',
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/scripts/directives/tag-colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
return;
}

scope.bgColour = TaxonomyCacheSrv.getColour(scope.tag) || '#3c8dbc';
scope.bgColour = TaxonomyCacheSrv.getColour(scope.tag) || TaxonomyCacheSrv.getColour('_freetags_:' + scope.tag) || '#3c8dbc';

$timeout(function() {
angular.element(element[0]).attr('style', 'background-color:' + scope.bgColour);
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/scripts/services/api/TagSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
return $http.patch('./api/v1/tag/' + id, patch);
}

this.removeTag = function(id) {
return $http.delete('./api/v1/tag/' + id);
}

this.autoComplete = function(term) {
var defer = $q.defer();

Expand Down
2 changes: 0 additions & 2 deletions frontend/app/scripts/services/api/TaxonomyCacheSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@
.then(function(freeTags) {
self.cacheTagColors(freeTags);

console.log(self.cache);

deferred.resolve(self.cache);
});
} else {
Expand Down
17 changes: 10 additions & 7 deletions frontend/app/views/components/org/custom-tags/tag-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ <h4>
<table class="table table-striped">
<thead>
<tr>
<th width="100">ID</th>
<th>
<a href class="text-default" ng-click="$vm.sortByField('predicate')">
Name
Expand All @@ -41,6 +40,9 @@ <h4>
<th width="250px">
Colour
</th>
<th width="100px">Cases</th>
<th width="100px">Alerts</th>
<th width="100px">Observables</th>
<th style="width: 60px;">By</th>
<th style="width: 150px">
Dates
Expand All @@ -58,20 +60,21 @@ <h4>
<i ng-show="$vm.filtering.context.sort.indexOf('-_updatedAt') !== -1" class="fa fa-caret-down"></i>
</a>
</th>
<th style="width: 120px">Actions</th>
<th style="width: 60px">Actions</th>
</tr>
</thead>

<tbody>
<tr ng-repeat="tag in $vm.list.values">
<td>{{tag._id}}</td>
<td>
<tag-item class="label-lg" value="tag.predicate" colour="tag.colour"></tag-item>
</td>
<td>
<updatable-colour value="tag.colour" on-update="$vm.updateColour(tag._id, newValue)"></updatable-colour>
</td>

<td>{{tag.extraData.usage.case}}</td>
<td>{{tag.extraData.usage.alert}}</td>
<td>{{tag.extraData.usage.observable}}</td>
<td class="nowrap">
<user user-id="tag._createdBy" icon-only="true" icon-size="m"></user>
</td>
Expand All @@ -84,10 +87,10 @@ <h4>
</div>
</td>
<td class="text-center">
<a href class="btn btn-icon btn-clear" ng-click="$vm.showTemplate(template)">
<!-- <a href class="btn btn-icon btn-clear" ng-click="$vm.showTemplate(template)">
<i class="text-info fa fa-edit"></i>
</a>
<a href class="btn btn-icon btn-clear" ng-click="$vm.deleteTemplate(template)">
</a> -->
<a href class="btn btn-icon btn-clear" ng-click="$vm.deleteTag(tag)">
<i class="text-info fa fa-trash text-danger"></i>
</a>
</td>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/views/partials/case/case.links.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<div class="case-tags flexwrap mt-xxs">
<span class="mr-xxxs text-muted"><i class="fa fa-tags"></i></span>
<strong class="text-muted mr-xxxs" ng-if="!item.tags || item.tags.length === 0">None</strong>
<span ng-repeat="tag in item.tags track by $index" class="label label-primary mb-xxxs mr-xxxs pointer">{{tag}}</span>
<tag-item ng-repeat="tag in item.tags track by $index" value="tag"></tag-item>
</div>
<div class="text-success" ng-show="item.status !== 'Open'">
<small>
Expand Down

0 comments on commit 6b9d6d5

Please sign in to comment.