Skip to content

Commit

Permalink
#1336 Create a reusable component for custome field editing and refac…
Browse files Browse the repository at this point in the history
…tor the case and alert custom fields sections
  • Loading branch information
nadouani committed May 22, 2020
1 parent b63a15e commit 0b102e3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 111 deletions.
1 change: 1 addition & 0 deletions frontend/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
<!-- injector:js -->
<script src="scripts/app.js"></script>
<script src="scripts/components/app-container.component.js"></script>
<script src="scripts/components/common/custom-field-input.component.js"></script>
<script src="scripts/components/control-sidebar.component.js"></script>
<script src="scripts/components/header.component.js"></script>
<script src="scripts/components/main-sidebar.component.js"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function() {
'use strict';

angular.module('theHiveComponents')
.component('customFieldInput', {
controller: function() {
this.updateField = function(newValue) {
this.onUpdate({
fieldName: ['customFields', this.field.reference, this.field.type].join('.'),
value: newValue
});
};
},
controllerAs: '$ctrl',
templateUrl: 'views/components/common/custom-field-input.component.html',
bindings: {
field: '<',
value: '=',
onUpdate: '&',
editable: '<'
}
});
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<dl class="dl-horizontal">
<dt class="pull-left" uib-tooltip="{{$ctrl.field.description}}">{{$ctrl.field.name}}</dt>
<dd ng-if="$ctrl.editable && $ctrl.field.options.length > 0">
<updatable-select
options="$ctrl.field.options"
on-update="$ctrl.updateField(newValue)"
value="$ctrl.value"></updatable-select>
</dd>
<dd ng-if="$ctrl.editable && $ctrl.field.options.length === 0" ng-switch="$ctrl.field.type">
<updatable-simple-text ng-switch-when="string"
input-type="text" on-update="$ctrl.updateField(newValue)" value="$ctrl.value"></updatable-simple-text>

<updatable-date ng-switch-when="date" on-update="$ctrl.updateField(newValue)" value="$ctrl.value"></updatable-date>

<updatable-simple-text ng-switch-when="integer"
input-type="integer"
on-update="$ctrl.updateField(newValue)"
value="$ctrl.value"></updatable-simple-text>

<updatable-simple-text ng-switch-when="float"
input-type="float"
on-update="$ctrl.updateField(newValue)"
value="$ctrl.value"></updatable-simple-text>

<updatable-boolean ng-switch-when="boolean"
input-type="number"
on-update="$ctrl.updateField(newValue)"
value="$ctrl.value"></updatable-boolean>

<span ng-switch-default>Not Editable</span>
</dd>
<dd ng-if="!$ctrl.editable" ng-switch="$ctrl.field.type">
<span ng-switch-when="date">{{$ctrl.value | shortDate}}</span>
<span ng-switch-default>
{{$ctrl.value}}
<em class="text-warning" ng-if="!$ctrl.value">Not Specified</em>
</span>
</dd>
</dl>
64 changes: 6 additions & 58 deletions frontend/app/views/partials/alert/custom.fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,68 +3,16 @@
<em>No aditional information have been specified</em>
</div>

<div ng-if="dialog.canEdit">
<div class="row">
<div ng-repeat="k in dialog.orderedFields track by $index" ng-init="fieldDef = dialog.customFieldsCache.getCache(k);">
<div class="clearfix" ng-if="$index % 2 == 0"></div>
<div class="col-xs-6">
<dl class="dl-horizontal clear">
<dt class="pull-left" uib-tooltip="{{fieldDef.description}}">{{fieldDef.name}}</dt>
<dd ng-if="fieldDef.options.length > 0">
<updatable-select
options="fieldDef.options"
on-update="dialog.updateField(dialog.getCustomFieldName(fieldDef), newValue)"
value="dialog.event.customFields[fieldDef.reference][fieldDef.type]"></updatable-select>
</dd>

<dd ng-if="fieldDef.options.length === 0" ng-switch="fieldDef.type">
<updatable-simple-text ng-switch-when="string"
input-type="text"
on-update="dialog.updateField(dialog.getCustomFieldName(fieldDef), newValue)"
value="dialog.event.customFields[fieldDef.reference][fieldDef.type]"></updatable-simple-text>

<updatable-date ng-switch-when="date"
on-update="dialog.updateField(dialog.getCustomFieldName(fieldDef), newValue)"
value="dialog.event.customFields[fieldDef.reference][fieldDef.type]"></updatable-date>

<updatable-simple-text ng-switch-when="integer"
input-type="integer"
on-update="dialog.updateField(dialog.getCustomFieldName(fieldDef), newValue)"
value="dialog.event.customFields[fieldDef.reference][fieldDef.type]"></updatable-simple-text>

<updatable-simple-text ng-switch-when="float"
input-type="float"
on-update="dialog.updateField(dialog.getCustomFieldName(fieldDef), newValue)"
value="dialog.event.customFields[fieldDef.reference][fieldDef.type]"></updatable-simple-text>

<updatable-boolean ng-switch-when="boolean"
input-type="number"
on-update="dialog.updateField(dialog.getCustomFieldName(fieldDef), newValue)"
value="dialog.event.customFields[fieldDef.reference][fieldDef.type]"></updatable-boolean>

<span ng-switch-default>Not Editable</span>
</dd>
</dl>
<custom-field-input
editable="dialog.canEdit"
field="fieldDef"
on-update="dialog.updateField(fieldName, value)"
value="dialog.event.customFields[fieldDef.reference][fieldDef.type]"></custom-field-input>
</div>
</div>
</div>

<div ng-if="!dialog.canEdit">
<div ng-repeat="k in dialog.orderedFields track by $index" ng-init="fieldDef = dialog.customFieldsCache.getCache(k);">
<div class="clearfix" ng-if="$index % 2 == 0"></div>
<div class="col-xs-6">
<dl class="dl-horizontal clear">
<dt class="pull-left" uib-tooltip="{{fieldDef.description}}">{{fieldDef.name}}</dt>
<dd ng-switch="fieldDef.type">
<span ng-switch-when="date">{{dialog.event.customFields[fieldDef.reference][fieldDef.type] | shortDate}}</span>
<span ng-switch-default>
{{dialog.event.customFields[fieldDef.reference][fieldDef.type]}}
<em class="text-warning" ng-if="!dialog.event.customFields[fieldDef.reference][fieldDef.type]">Not Specified</em>
</span>
</dd>
</dl>
</div>
</div>
</div>


</div>
58 changes: 5 additions & 53 deletions frontend/app/views/partials/case/details/custom.fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,14 @@ <h4 class="vpad10 text-primary">
<em>No additional information have been specified</em>
</div>

<div ng-if="canEdit" class="row">
<div ng-repeat="k in orderedFields track by $index" ng-init="fieldDef = customFieldsCache[k];">
<div class="row">
<div ng-repeat="k in orderedFields track by $index">
<div class="clearfix" ng-if="$index % 3 == 0"></div>
<div class="col-xs-4">
<dl class="dl-horizontal">
<dt class="pull-left" uib-tooltip="{{fieldDef.description}}">{{fieldDef.name}}</dt>
<dd ng-if="fieldDef.options.length > 0">
<updatable-select
options="fieldDef.options"
on-update="updateField(getCustomFieldName(fieldDef), newValue)"
value="caze.customFields[fieldDef.reference][fieldDef.type]"></updatable-select>
</dd>
<dd ng-if="fieldDef.options.length === 0" ng-switch="fieldDef.type">
<updatable-simple-text ng-switch-when="string"
input-type="text"
on-update="updateField(getCustomFieldName(fieldDef), newValue)"
value="caze.customFields[fieldDef.reference][fieldDef.type]"></updatable-simple-text>
<updatable-date ng-switch-when="date"
on-update="updateField(getCustomFieldName(fieldDef), newValue)"
value="caze.customFields[fieldDef.reference][fieldDef.type]"></updatable-date>
<updatable-simple-text ng-switch-when="integer"
input-type="integer"
on-update="updateField(getCustomFieldName(fieldDef), newValue)"
value="caze.customFields[fieldDef.reference][fieldDef.type]"></updatable-simple-text>
<updatable-simple-text ng-switch-when="float"
input-type="float"
on-update="updateField(getCustomFieldName(fieldDef), newValue)"
value="caze.customFields[fieldDef.reference][fieldDef.type]"></updatable-simple-text>
<updatable-boolean ng-switch-when="boolean"
input-type="number"
on-update="updateField(getCustomFieldName(fieldDef), newValue)"
value="caze.customFields[fieldDef.reference][fieldDef.type]"></updatable-boolean>
<span ng-switch-default>Not Editable</span>
</dd>
</dl>
<custom-field-input
field="customFieldsCache[k]" on-update="updateField(fieldName, value)" editable="canEdit"
value="caze.customFields[customFieldsCache[k].reference][customFieldsCache[k].type]"></custom-field-input>
</div>
</div>
</div>

<div ng-if="!canEdit">
<div ng-repeat="k in orderedFields track by $index" ng-init="fieldDef = customFieldsCache[k];">
<div class="clearfix" ng-if="$index % 3 == 0"></div>
<div class="col-xs-4">
<dl class="dl-horizontal clear">
<dt class="pull-left" uib-tooltip="{{fieldDef.description}}">{{fieldDef.name}}</dt>
<dd ng-switch="fieldDef.type">
<span ng-switch-when="date">{{caze.customFields[fieldDef.reference][fieldDef.type] | shortDate}}</span>
<span ng-switch-default>
{{caze.customFields[fieldDef.reference][fieldDef.type]}}
<em class="text-warning" ng-if="!caze.customFields[fieldDef.reference][fieldDef.type]">Not Specified</em>
</span>
</dd>
</dl>
</div>
</div>

</div>

</div>

0 comments on commit 0b102e3

Please sign in to comment.