Skip to content

Commit

Permalink
#1926 Fix case template task edition
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jun 10, 2021
1 parent 4ffea3c commit 9eb14bc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(function() {
(function () {
'use strict';

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

self.task = '';
Expand All @@ -13,7 +13,7 @@
self.getUserInfo = UserSrv.getCache;


this.$onInit = function() {
this.$onInit = function () {
self.filtering = new FilteringSrv('caseTemplate', 'caseTemplate.list', {
version: 'v1',
defaults: {
Expand All @@ -26,7 +26,7 @@
});

self.filtering.initContext(self.organisation.name)
.then(function() {
.then(function () {
self.load();

$scope.$watch('$vm.list.pageSize', function (newValue) {
Expand All @@ -35,7 +35,7 @@
});
};

this.load = function() {
this.load = function () {

self.list = new PaginatedQuerySrv({
name: 'organisation-case-templates',
Expand All @@ -46,15 +46,15 @@
pageSize: self.filtering.context.pageSize,
filter: this.filtering.buildQuery(),
operations: [{
'_name': 'getOrganisation',
'idOrName': self.organisation.name
},
{
'_name': 'caseTemplates'
}
'_name': 'getOrganisation',
'idOrName': self.organisation.name
},
{
'_name': 'caseTemplates'
}
],
onFailure: function(err) {
if(err && err.status === 400) {
onFailure: function (err) {
if (err && err.status === 400) {
self.filtering.resetContext();
self.load();
}
Expand Down Expand Up @@ -90,36 +90,36 @@
this.search();
};

this.filterBy = function(field, value) {
this.filterBy = function (field, value) {
self.filtering.clearFilters()
.then(function(){
.then(function () {
self.addFilterValue(field, value);
});
};

this.sortBy = function(sort) {
this.sortBy = function (sort) {
self.list.sort = sort;
self.list.update();
self.filtering.setSort(sort);
};

this.sortByField = function(field) {
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) {
if (currentSort.substr(1) !== field) {
sort = ['+' + field];
} else {
sort = [(currentSort === '+' + field) ? '-'+field : '+'+field];
sort = [(currentSort === '+' + field) ? '-' + field : '+' + field];
}

self.list.sort = sort;
self.list.update();
self.filtering.setSort(sort);
};

this.newTemplate = function() {
this.newTemplate = function () {
self.showTemplate({
name: '',
titlePrefix: '',
Expand All @@ -133,12 +133,12 @@
});
};

this.showTemplate = function(template) {
this.showTemplate = function (template) {

var promise = template._id ? CaseTemplateSrv.get(template._id) : $q.resolve(template);

promise
.then(function(response) {
.then(function (response) {
var modalInstance = $uibModal.open({
animation: true,
keyboard: false,
Expand All @@ -148,43 +148,49 @@
controllerAs: '$vm',
size: 'max',
resolve: {
template: function() {
return response;
template: function () {
var tmpl = angular.copy(response);

if (tmpl.tasks && tmpl.tasks.length > 0) {
tmpl.tasks = _.sortBy(tmpl.tasks, 'order');
}

return tmpl;
},
fields: function() {
fields: function () {
return self.fields;
}
}
});

return modalInstance.result;
})
.then(function() {
.then(function () {
self.load();
})
.catch(function(err) {
if(err && !_.isString(err)) {
.catch(function (err) {
if (err && !_.isString(err)) {
NotificationSrv.error('Case Template Admin', err.data, err.status);
}
})
}

self.createTemplate = function(template) {
self.createTemplate = function (template) {
return CaseTemplateSrv.create(template).then(
function(/*response*/) {
function (/*response*/) {
self.load();

$scope.$emit('templates:refresh');

NotificationSrv.log('The template [' + template.name + '] has been successfully created', 'success');
},
function(response) {
function (response) {
NotificationSrv.error('TemplateCtrl', response.data, response.status);
}
);
};

self.importTemplate = function() {
self.importTemplate = function () {
var modalInstance = $uibModal.open({
animation: true,
templateUrl: 'views/components/org/case-template/import.html',
Expand All @@ -194,10 +200,10 @@
});

modalInstance.result
.then(function(template) {
.then(function (template) {
return self.createTemplate(template);
})
.catch(function(err) {
.catch(function (err) {
if (err && err.status) {
NotificationSrv.error('TemplateCtrl', err.data, err.status);
}
Expand All @@ -221,7 +227,7 @@

self.exportTemplate = function (template) {
CaseTemplateSrv.get(template._id)
.then(function(response) {
.then(function (response) {
var fileName = 'Case-Template__' + response.name.replace(/\s/gi, '_') + '.json';

// Create a blob of the data
Expand Down
11 changes: 7 additions & 4 deletions frontend/app/views/components/org/case-template/tasks.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
No tasks have been specified. <a href class="mr-xxxs" ng-click="$vm.addTask()">Add a task</a>
</div>
<div ng-if="$vm.template.tasks.length !== 0" ui-sortable="$vm.sortableOptions" ng-model="$vm.template.tasks">
<div class="task-item" ng-init="isCollapsed=true" ng-repeat="t in $vm.template.tasks | orderBy:'order' track by $index">
<div class="task-item" ng-init="isCollapsed=true"
ng-repeat="t in $vm.template.tasks | orderBy:'order' track by $index">
<div class="panel-heading">
<span class="drag-handle text-primary clickable mr-xxs">
<i class="fa fa-bars"></i>
Expand All @@ -22,14 +23,16 @@
</a>
</span>
<span class="hpad5">[{{t.group || 'default'}}] {{t.title}}</span>
<span class="mr-xxs" ng-if="t.owner">(Assigned to <em><user-info value="t.owner" field="name"></user-info></em>)</span>
<span class="mr-xxs" ng-if="t.owner">(Assigned to <em>
<user-info value="t.owner" field="name"></user-info>
</em>)</span>

<span class="pull-right">
<a class="text-default" href ng-click="$vm.editTask(t)">
<i class="fa fa-pencil"></i>&nbsp;Edit</a>
<span class="hpad5"></span>
<a class="text-danger" href ng-click="$vm.removeTask(t)">
<i class="fa fa-trash"></i>&nbsp;Delete</a>
<a class="text-danger" href ng-click="$vm.removeTask(t)">
<i class="fa fa-trash"></i>&nbsp;Delete</a>
</span>
</div>
<div class="panel-body" ng-hide="isCollapsed">
Expand Down

0 comments on commit 9eb14bc

Please sign in to comment.