Add a label input control
This commit is contained in:
parent
94c41cc7e3
commit
46d1532f0e
6 changed files with 99 additions and 1 deletions
43
static/js/directives/ui/label-input.js
Normal file
43
static/js/directives/ui/label-input.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* An element which allows for editing labels.
|
||||
*/
|
||||
angular.module('quay').directive('labelInput', function () {
|
||||
return {
|
||||
templateUrl: '/static/directives/label-input.html',
|
||||
restrict: 'C',
|
||||
replace: true,
|
||||
scope: {
|
||||
'labels': '=labels',
|
||||
'updatedLabels': '=?updatedLabels',
|
||||
},
|
||||
controller: function($scope) {
|
||||
$scope.tags = [];
|
||||
|
||||
$scope.$watch('tags', function(tags) {
|
||||
if (!tags) { return; }
|
||||
$scope.updatedLabels = tags.filter(function(tag) {
|
||||
parts = tag['keyValue'].split('=', 2);
|
||||
return tag['label'] ? tag['label'] : {
|
||||
'key': parts[0],
|
||||
'value': parts[1],
|
||||
'is_new': true
|
||||
};
|
||||
});
|
||||
}, true);
|
||||
|
||||
$scope.$watch('labels', function(labels) {
|
||||
$scope.filteredLabels = labels.filter(function(label) {
|
||||
return label['source_type'] == 'api';
|
||||
});
|
||||
|
||||
$scope.tags = $scope.filteredLabels.map(function(label) {
|
||||
return {
|
||||
'id': label['id'],
|
||||
'keyValue': label['key'] + '=' + label['value'],
|
||||
'label': label
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -45,4 +45,4 @@ angular
|
|||
.constant('NAME_PATTERNS', NAME_PATTERNS)
|
||||
.constant('INJECTED_CONFIG', INJECTED_CONFIG)
|
||||
.constant('INJECTED_FEATURES', INJECTED_FEATURES)
|
||||
.constant('INJECTED_ENDPOINTS', INJECTED_ENDPOINTS);
|
||||
.constant('INJECTED_ENDPOINTS', INJECTED_ENDPOINTS);
|
Reference in a new issue