Skip to content

Commit

Permalink
#1410 Update case close dialog to rely on API v1 objects
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Jul 10, 2020
1 parent fa4441c commit cbd7eab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 48 deletions.
56 changes: 21 additions & 35 deletions frontend/app/scripts/controllers/case/CaseCloseModalCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$scope.tasksValid = false;
$scope.tasks = [];
$scope.formData = {};
$scope.customFieldsSrv = CustomFieldsSrv;

SearchSrv(function(data) {
$scope.initialize();
Expand All @@ -30,37 +31,17 @@
}]
}, 'case_task', 'all');

var getTemplateCustomFields = function(customFields) {
var result = [];

result = _.pluck(_.sortBy(_.map(customFields, function(definition, name){
return {
name: name,
order: definition.order
};
}), 'order'), 'name');

return result;
};

$scope.initialize = function() {
CustomFieldsSrv.all().then(function(fields) {
$scope.orderedFields = getTemplateCustomFields($scope.caze.customFields);
$scope.allCustomFields = fields;

$scope.mandatoryFields = _.without(_.map($scope.orderedFields, function(cf) {
var fieldDef = fields[cf];
CustomFieldsSrv.all().then(function() {
$scope.mandatoryFields = _.sortBy(_.filter($scope.caze.customFields, function(cf) {
var fieldDef = $scope.customFieldsSrv.getCache(cf.name);

if(!fieldDef) {
return;
}

var fieldValue = $scope.caze.customFields[cf][cf.type];

if((fieldValue === undefined || fieldValue === null) && fieldDef.mandatory === true) {
return cf;
}
}), undefined);
return ((cf.value === undefined || cf.value === null) && fieldDef.mandatory === true);
}), 'order');

});

Expand All @@ -83,23 +64,28 @@
$scope.tasksValid = true;
};

$scope.getCustomFieldsForUpdate = function() {
var customFields = {};

_.each($scope.caze.customFields, function(cf) {
customFields[cf.name] = {
order: cf.order
};

customFields[cf.name][cf.type] = cf.type === 'date' ? moment(cf.value).valueOf() : cf.value;
});

return customFields;
};

$scope.closeCase = function() {
var data = $scope.formData;

if (data.impactStatus === null) {
data.impactStatus = 'NotApplicable';
}

data.customFields = $scope.caze.customFields;

_.each($scope.mandatoryFields, function(cf) {
var field = data.customFields[cf];
var fieldDef = $scope.allCustomFields[cf];

if(fieldDef.type === 'date') {
field[fieldDef.type] = field[fieldDef.type] ? moment(field[fieldDef.type]).valueOf() : field[fieldDef.type];
}
});
data.customFields = $scope.getCustomFieldsForUpdate();

var promise = $scope.updateField(data);

Expand Down
28 changes: 15 additions & 13 deletions frontend/app/views/partials/case/case.close.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<form class="form-horizontal" name="caseCloseForm" ng-submit="closeCase(caseCloseForm.$valid);" novalidate>
<div class="modal-header bg-primary">
<h3 class="modal-title">Close Case #{{caze.caseId}}</h3>
<h3 class="modal-title">Close Case #{{caze.number}}</h3>
</div>
<div class="modal-body">
<div ng-show="!tasksValid">
Expand Down Expand Up @@ -47,7 +47,7 @@ <h3 class="modal-title">Close Case #{{caze.caseId}}</h3>
<div ng-show="tasksValid === true">
<div align="center" class="alert alert-danger">
<i class="glyphicon glyphicon-exclamation-sign"></i>
You are about to close Case #{{caze.caseId}}. Are you sure you want to continue ?
You are about to close Case #{{caze.number}}. Are you sure you want to continue ?
</div>

<div class="row">
Expand Down Expand Up @@ -121,25 +121,27 @@ <h2 class="background"><span>Incident</span></h2>
</div>
</div>
<!-- Custom Fields -->
<div class="form-group" ng-repeat="k in mandatoryFields" ng-init="fieldDef = allCustomFields[k];" ng-class="{ 'has-error' : caseCloseForm['customFields.' + k].$invalid && !caseCloseForm['customFields.' + k].$pristine }">
<label class="col-sm-3 control-label" uib-tooltip="{{allCustomFields[k].description}}">{{fieldDef.name}}
<div class="form-group" ng-repeat="cf in mandatoryFields" ng-init="fieldDef = customFieldsSrv.getCache(cf.name);"
ng-class="{ 'has-error' : caseCloseForm['customFields.' + cf.name].$invalid && !caseCloseForm['customFields.' + cf.name].$pristine }">
<label class="col-sm-3 control-label" uib-tooltip="{{fieldDef.description}}">{{fieldDef.name}}
<i class="fa fa-asterisk text-danger"></i>
</label>

<div class="col-sm-3" ng-if="allCustomFields[k].options.length > 0">
<select class="form-control" name="{{'customFields.' + k}}" ng-model="caze.customFields[k][fieldDef.type]" ng-options="v for v in allCustomFields[k].options" required>
<div class="col-sm-3" ng-if="fieldDef.options.length > 0">
<select class="form-control" name="{{'customFields.' + cf.name}}" ng-model="cf.value" ng-options="v for v in fieldDef.options" required>
<option value=""></option>
</select>
<p class="help-block" ng-show="caseCloseForm['customFields.' + k].$invalid && !caseCloseForm['customFields.' + k].$pristine">This field is required.</p>
<p class="help-block" ng-show="caseCloseForm['customFields.' + cf.name].$invalid && !caseCloseForm['customFields.' + cf.name].$pristine">This field is required.</p>
</div>
<div class="col-sm-3" ng-if="allCustomFields[k].options.length === 0" ng-switch="allCustomFields[k].type">
<input ng-switch-when="string" name="{{'customFields.' + k}}" type="text" class="form-control" ng-model="caze.customFields[k][fieldDef.type]" required>
<input ng-switch-when="number" name="{{'customFields.' + k}}" type="number" class="form-control" ng-model="caze.customFields[k][fieldDef.type]" required>
<select ng-switch-when="boolean" name="{{'customFields.' + k}}" class="form-control" ng-model="caze.customFields[k][fieldDef.type]" ng-options="v for v in [true, false]" required>
<div class="col-sm-3" ng-if="fieldDef.options.length === 0" ng-switch="cf.type">
<input ng-switch-when="string" name="{{'customFields.' + cf.name}}" type="text" class="form-control" ng-model="cf.value" required>
<input ng-switch-when="integer" name="{{'customFields.' + cf.name}}" type="number" step="1" class="form-control" ng-model="cf.value" required>
<input ng-switch-when="float" name="{{'customFields.' + cf.name}}" type="number" step=".01" class="form-control" ng-model="cf.value" required>
<select ng-switch-when="boolean" name="{{'customFields.' + cf.name}}" class="form-control" ng-model="cf.value" ng-options="v for v in [true, false]" required>
<option value=""></option>
</select>
<dt-picker ng-switch-when="date" name="{{'customFields.' + k}}" date="caze.customFields[k][fieldDef.type]" required="true"></dt-picker>
<p class="help-block" ng-show="caseCloseForm['customFields.' + k].$invalid && !caseCloseForm['customFields.' + k].$pristine">This field is required.</p>
<dt-picker ng-switch-when="date" name="{{'customFields.' + cf.name}}" date="cf.value" required="true"></dt-picker>
<p class="help-block" ng-show="caseCloseForm['customFields.' + cf.name].$invalid && !caseCloseForm['customFields.' + cf.name].$pristine">This field is required.</p>
</div>

</div>
Expand Down

0 comments on commit cbd7eab

Please # to comment.