harbor/static/resources/js/components/repository/popup-details.directive.js

111 lines
5.3 KiB
JavaScript
Raw Normal View History

/*
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2016-05-05 12:35:52 +02:00
(function() {
'use strict';
angular
.module('harbor.repository')
.directive('popupDetails', popupDetails);
PopupDetailsController.$inject = ['ListManifestService', '$filter', 'dateLFilter'];
function PopupDetailsController(ListManifestService, $filter, dateLFilter) {
var vm = this;
2016-05-05 12:35:52 +02:00
vm.retrieve = retrieve;
2016-05-05 12:35:52 +02:00
function retrieve() {
ListManifestService(vm.repoName, vm.tag)
.success(getManifestSuccess)
.error(getManifestFailed);
}
function getManifestSuccess(data, status) {
2016-08-02 07:43:35 +02:00
console.log('Successful get manifest:' + data);
vm.manifest = angular.fromJson(data.manifest.history[0].v1Compatibility);
vm.manifest['created'] = $filter('dateL')(vm.manifest['created'], 'YYYY-MM-DD HH:mm:ss');
2016-05-05 12:35:52 +02:00
}
function getManifestFailed(data, status) {
console.log('Failed to get manifest:' + data);
2016-05-05 12:35:52 +02:00
}
}
function popupDetails() {
var directive = {
'restrict': 'E',
'templateUrl': '/static/resources/js/components/repository/popup-details.directive.html',
2016-05-05 12:35:52 +02:00
'scope': {
'repoName': '@',
'tag': '@',
'index': '@'
2016-05-05 12:35:52 +02:00
},
'replace': true,
2016-05-05 12:35:52 +02:00
'link': link,
'controller': PopupDetailsController,
'controllerAs': 'vm',
'bindToController': true
};
return directive;
function link(scope, element, attrs, ctrl) {
ctrl.retrieve();
scope.$watch('vm.manifest', function(current) {
2016-05-05 12:35:52 +02:00
if(current) {
element
.popover({
'template': '<div class="popover" role="tooltip"><div class="arrow"></div><div class="popover-title"></div><div class="popover-content"></div></div>',
'title': '<div class="pull-right clearfix"><a href="javascript:void(0);"><span class="glyphicon glyphicon-remove-circle"></span></a></div>',
'content': generateContent,
'html': true
})
.on('shown.bs.popover', function(e){
var self = jQuery(this);
$('[type="text"]:input', self.parent())
.on('click', function() {
$(this).select();
});
self.parent().find('.glyphicon.glyphicon-remove-circle').on('click', function() {
element.trigger('click');
});
});
2016-05-05 12:35:52 +02:00
}
});
function generateContent() {
2016-06-28 01:58:38 +02:00
var content = '<form class="form-horizontal" width="100%">' +
2016-05-05 12:35:52 +02:00
'<div class="form-group">' +
'<label class="col-sm-3 control-label">Id</label>' +
2016-08-02 07:43:35 +02:00
'<div class="col-sm-9"><p class="form-control-static long-line long-line-margin-right"><input type="text" id="txtImageId" value="' + ctrl.manifest['id'] + '" readonly size="32"></p></div></div>' +
2016-05-05 12:35:52 +02:00
'<div class="form-group"><label class="col-sm-3 control-label">Parent</label>' +
2016-08-02 07:43:35 +02:00
'<div class="col-sm-9"><p class="form-control-static long-line long-line-margin-right"><input type="text" id="txtImageId" value="' + ctrl.manifest['parent'] + '" readonly size="32"></p></div></div>' +
2016-05-05 12:35:52 +02:00
'<div class="form-group"><label class="col-sm-3 control-label">Created</label>' +
2016-08-02 07:43:35 +02:00
'<div class="col-sm-9"><p class="form-control-static long-line-margin-right">' + ctrl.manifest['created'] + '</p></div></div>' +
2016-05-05 12:35:52 +02:00
'<div class="form-group"><label class="col-sm-3 control-label">Author</label>' +
2016-08-02 07:43:35 +02:00
'<div class="col-sm-9"><p class="form-control-static long-line-margin-right">' + ((!angular.isDefined(ctrl.manifest['author']) || ctrl.manifest['author'] === '') ? 'N/A' : ctrl.manifest['author']) + '</p></div></div>' +
2016-05-05 12:35:52 +02:00
'<div class="form-group"><label class="col-sm-3 control-label">Architecture</label>' +
2016-08-02 07:43:35 +02:00
'<div class="col-sm-9"><p class="form-control-static long-line-margin-right">' + ((!angular.isDefined(ctrl.manifest['architecture']) || ctrl.manifest['architecture'] === '') ? 'N/A' : ctrl.manifest['architecture']) + '</p></div></div>' +
2016-05-05 12:35:52 +02:00
'<div class="form-group"><label class="col-sm-3 control-label">Docker Version</label>' +
2016-08-02 07:43:35 +02:00
'<div class="col-sm-9"><p class="form-control-static long-line-margin-right">' + ((!angular.isDefined(ctrl.manifest['docker_version']) || ctrl.manifest['docker_version'] === '') ? 'N/A' : ctrl.manifest['docker_version']) + '</p></div></div>' +
2016-05-05 12:35:52 +02:00
'<div class="form-group"><label class="col-sm-3 control-label">OS</label>' +
2016-08-02 07:43:35 +02:00
'<div class="col-sm-9"><p class="form-control-static long-line-margin-right">' + ((!angular.isDefined(ctrl.manifest['os']) || ctrl.manifest['os'] === '') ? 'N/A' : ctrl.manifest['os']) + '</p></div></div>' +
2016-05-05 12:35:52 +02:00
'</form>';
return content;
}
}
}
})();