This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/directives/ui/label-input.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-11-12 16:09:47 +00:00
/**
* 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
};
});
});
}
};
});