Skip to content

Commit

Permalink
#1264 Add possibility to remove custom field from case.
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Mar 17, 2021
1 parent 768eaca commit bb5e263
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
value: newValue
});
};
this.removeCustomField = function(fieldId) {
this.onRemove({
fieldId: fieldId
})
}
},
controllerAs: '$ctrl',
templateUrl: 'views/components/common/custom-field-input.component.html',
Expand All @@ -18,7 +23,9 @@
field: '<',
value: '=',
onUpdate: '&',
editable: '<'
onRemove: '&',
editable: '<',
removable: '<'
}
});
})();
17 changes: 16 additions & 1 deletion frontend/app/scripts/controllers/case/CaseDetailsCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
};
});

angular.module('theHiveControllers').controller('CaseCustomFieldsCtrl', function($scope, $uibModal, CustomFieldsSrv) {
angular.module('theHiveControllers').controller('CaseCustomFieldsCtrl', function($scope, $uibModal, NotificationSrv, ModalUtilsSrv, CustomFieldsSrv, CaseSrv) {

$scope.getCustomFieldName = function(fieldDef) {
return 'customFields.' + fieldDef.reference + '.' + fieldDef.type;
Expand Down Expand Up @@ -103,6 +103,21 @@
});
};

$scope.removeField = function(fieldId) {
ModalUtilsSrv.confirm('Remove custom field value', 'Are you sure you want to delete this case custom field value?', {
okText: 'Yes, remove it',
flavor: 'danger'
})
.then(function () {
return CaseSrv.removeCustomField(fieldId);
})
.catch(function(err) {
if(err && !_.isString(err)) {
NotificationSrv.error('Remove custom field', err.data, err.status);
}
});
}

$scope.keys = function(obj) {
return _.keys(obj);
};
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/scripts/services/api/CaseSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@
}
});
};

this.removeCustomField = function(customfFieldValueId) {
return $http.delete('./api/v1/case/customField/' + customfFieldValueId)
}
});

})();
10 changes: 9 additions & 1 deletion frontend/app/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ ul.observable-reports-summary li {

.case-details dd,
.case-custom-fields dd {
margin-left: 200px !important;
margin-left: 205px !important;
}

.case-custom-fields dt {
Expand All @@ -359,6 +359,14 @@ ul.observable-reports-summary li {
border-left: 2px solid #337ab7;
}

.case-custom-fields dt a {
display: none;
}

.case-custom-fields dt:hover a {
display: block;
}

.case-custom-fields dd {
margin-left: 205px;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<dl class="dl-horizontal custom-field-input">
<dt class="pull-left" uib-tooltip="{{$ctrl.field.description}}">{{$ctrl.field.name}}</dt>
<dt class="pull-left">
<span uib-tooltip="{{$ctrl.field.description}}">{{$ctrl.field.name}}</span>
<a ng-if="$ctrl.removable" class="pull-right mr-xxxs" href ng-click="$ctrl.removeCustomField($ctrl.field.id)" uib-tooltip="Delete">
<i class="fa fa-trash text-danger"></i>
</a>
</dt>
<dd ng-if="$ctrl.editable && $ctrl.field.options.length > 0">
<updatable-select
options="$ctrl.field.options"
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/views/partials/case/details/custom.fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ <h4 class="vpad10 text-primary">
<custom-field-input
index="$index"
editable="canEdit"
removable="canEdit"
field="customFieldsCache[customField.name]"
on-update="updateField(fieldName, value)"
on-remove="removeField(fieldId)"
value="customField.value"></custom-field-input>
</div>
</div>
Expand Down

0 comments on commit bb5e263

Please sign in to comment.