Skip to content

Commit 57cbb3d

Browse files
committed
#12 Add support to custom fields with enumerated list of possible values
1 parent e42c3e9 commit 57cbb3d

12 files changed

+80
-15
lines changed

ui/app/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
<script src="scripts/directives/updatableBoolean.js"></script>
191191
<script src="scripts/directives/updatableDataDropdown.js"></script>
192192
<script src="scripts/directives/updatableDate.js"></script>
193+
<script src="scripts/directives/updatableSelect.js"></script>
193194
<script src="scripts/directives/updatableSimpleText.js"></script>
194195
<script src="scripts/directives/updatableTags.js"></script>
195196
<script src="scripts/directives/updatableText.js"></script>

ui/app/scripts/controllers/admin/AdminCustomFieldDialogCtrl.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,27 @@
1919
NotificationSrv.error('AdminCustomFieldDialogCtrl', response.data, response.status);
2020
};
2121

22+
var buildOptionsCollection = function(options) {
23+
if(!options || options === '') {
24+
return [];
25+
}
26+
27+
var type = self.customField.type;
28+
//var values = _.isArray(self.customField.options) ? self.customField.options : self.customField.options.split('\n');
29+
var values = self.customField.options.split('\n');
30+
31+
if(type === 'number') {
32+
return _.without(values.map(function(item) {
33+
return Number(item);
34+
}), NaN);
35+
}
36+
37+
return values;
38+
};
39+
2240
self.saveField = function() {
2341
var postData = _.pick(self.customField, 'name', 'title', 'label', 'description', 'type');
24-
postData.options = _.isArray(self.customField.options) ? self.customField.options : self.customField.options.split('\n');
42+
postData.options = buildOptionsCollection(self.customField.options);
2543

2644
if(self.customField.id) {
2745
ListSrv.update(

ui/app/scripts/directives/updatableBoolean.js

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
'link': UtilsSrv.updatableLink,
88
'templateUrl': 'views/directives/updatable-boolean.html',
99
'scope': {
10-
'inputType': '@',
1110
'value': '=?',
1211
'onUpdate': '&',
1312
'active': '=?',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(function() {
2+
'use strict';
3+
angular.module('theHiveDirectives')
4+
.directive('updatableSelect', function(UtilsSrv) {
5+
return {
6+
'restrict': 'E',
7+
'link': UtilsSrv.updatableLink,
8+
'templateUrl': 'views/directives/updatable-select.html',
9+
'scope': {
10+
'options': '=?',
11+
'value': '=?',
12+
'onUpdate': '&',
13+
'active': '=?',
14+
'placeholder': '@'
15+
}
16+
};
17+
});
18+
})();

ui/app/views/directives/updatable-boolean.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<i class="glyphicon glyphicon-pencil" ng-click="edit()"></i>
77
</a>
88
</small>
9-
<span ng-hide="active">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
9+
<small ng-hide="active">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>
1010
</span>
1111
<span ng-show="updatable.updating" ng-init="updatable.dropdownOpen=false">
1212
<form ng-submit="update()">

ui/app/views/directives/updatable-date.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<i class="glyphicon glyphicon-pencil" ng-click="edit()"></i>
77
</a>
88
</small>
9-
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
9+
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>
1010
</span>
1111
<span ng-init="updatable.dropdownOpen=false" ng-show="updatable.updating">
1212

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<span ng-hide="updatable.updating" ng-init="active = false" ng-mouseenter="active = true" ng-mouseleave="active = false">
2+
<span ng-if="value!==null && value !==''" style="vertical-align: top; white-space: pre-wrap" class="updatable-value">{{value}}</span>
3+
<span ng-if="value === null || value === undefined" style="vertical-align: top;" class="updatable-value text-warning"><em>Not Specified</em></span>
4+
<small ng-show="active">
5+
<a href class="clickable" tooltip-popup-delay='500' uib-tooltip="edit">
6+
<i class="glyphicon glyphicon-pencil" ng-click="edit()"></i>
7+
</a>
8+
</small>
9+
<small ng-hide="active">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>
10+
</span>
11+
<span ng-show="updatable.updating" ng-init="updatable.dropdownOpen=false">
12+
<form ng-submit="update()">
13+
<div class="input-group input-group-sm">
14+
<select class="form-control input-sm" ng-model="value" ng-options="v for v in options" ng-change="update()"></select>
15+
<span class="input-group-btn">
16+
<button class="btn btn-sm btn-default" type="submit">
17+
<i class="text-success glyphicon glyphicon-ok"></i>
18+
</button>
19+
<button class="btn btn-sm btn-default" type="button" ng-click="cancel()">
20+
<i class="text-danger glyphicon glyphicon-remove"></i>
21+
</button>
22+
</span>
23+
</div>
24+
</form>
25+
</span>

ui/app/views/directives/updatable-simple-text.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<i class="glyphicon glyphicon-pencil" ng-click="edit()"></i>
77
</a>
88
</small>
9-
<span ng-hide="active">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
9+
<small ng-hide="active">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>
1010
</span>
1111
<span ng-show="updatable.updating" ng-init="updatable.dropdownOpen=false">
1212
<form ng-submit="update()">

ui/app/views/directives/updatable-tags.html

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<span ng-hide="updatable.updating" ng-init="active = false" ng-mouseenter="active = true" ng-mouseleave="active = false">
22
<span class="updatable-value" ng-show="!value || value.length === 0" style="vertical-align:top; white-space: pre-wrap"><span class="text-warning"><em>Not Specified</em></span></span>
3-
<span ng-repeat="tag in value">
4-
<span class="label label-primary mr-xxxs"><span ng-bind="tag.text"></span>
5-
</span>
6-
</span>
3+
<small ng-repeat="tag in value">
4+
<span class="label label-primary mr-xxxs" ng-bind="tag.text"></span>
5+
</small>
76

87
<small ng-show="active">
9-
<a style="cursor: pointer;" target="_self" tooltip-popup-delay='500' uib-tooltip="edit">
8+
<a href class="clickable" tooltip-popup-delay='500' uib-tooltip="edit">
109
<i class="glyphicon glyphicon-pencil" ng-click="edit()"></i>
1110
</a>
1211
</small>

ui/app/views/directives/updatable-text.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<em>Not specified</em>
1414
</span>
1515
<small ng-show="active">
16-
<a style="cursor: pointer;" uib-tooltip="edit">
16+
<a href class="clickable" uib-tooltip="edit">
1717
<i class="glyphicon glyphicon-pencil" ng-click="edit()"></i>
1818
</a>
1919
</small>

ui/app/views/directives/updatable-user.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<i class="glyphicon glyphicon-pencil" ng-click="edit()"></i>
66
</a>
77
</small>
8-
<span ng-hide="active">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
8+
<small ng-hide="active">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>
99

1010
</span>
1111
<span ng-init="updatable.dropdownOpen=false" ng-show="updatable.updating">

ui/app/views/partials/case/details/custom.fields.html

+8-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ <h4 class="vpad10 text-primary">
2121
ng-repeat="k in orderedFields"
2222
ng-init="fieldDef = customFieldsCache[k]; customFieldValue=caze.customFields[fieldDef.name][fieldDef.type];">
2323
<dt class="pull-left" uib-tooltip="{{fieldDef.description}}">{{fieldDef.label}}</dt>
24-
<dd ng-switch="fieldDef.type">
24+
<dd ng-if="fieldDef.options.length > 0">
25+
<updatable-select
26+
options="fieldDef.options"
27+
on-update="updateField(getCustomFieldName(fieldDef), newValue)"
28+
value="customFieldValue"></updatable-select>
29+
</dd>
30+
31+
<dd ng-if="fieldDef.options.length === 0" ng-switch="fieldDef.type">
2532
<updatable-simple-text ng-switch-when="string"
2633
input-type="text"
2734
on-update="updateField(getCustomFieldName(fieldDef), newValue)"
@@ -41,8 +48,6 @@ <h4 class="vpad10 text-primary">
4148
on-update="updateField(getCustomFieldName(fieldDef), newValue)"
4249
value="customFieldValue"></updatable-boolean>
4350

44-
45-
4651
<span ng-switch-default>Not Editable</span>
4752
</dd>
4853
</dl>

0 commit comments

Comments
 (0)