From d182202fc6001983541504ed323d68479086317e Mon Sep 17 00:00:00 2001 From: WuKong Date: Sat, 22 Apr 2017 13:25:07 +0200 Subject: add moonv4 Change-Id: I247af788d0b0fb961fbc85416486b241eb1d807c Signed-off-by: WuKong --- .../static/app/pdp/action/pdp-add.tpl.html | 88 +++++++ .../static/app/pdp/action/pdp-delete.tpl.html | 35 +++ .../static/app/pdp/action/pdp.controller.add.js | 108 ++++++++ .../static/app/pdp/action/pdp.controller.delete.js | 66 +++++ .../static/app/pdp/edit/pdp-edit-basic.tpl.html | 65 +++++ .../moon_gui/static/app/pdp/edit/pdp-edit.tpl.html | 56 ++++ .../static/app/pdp/edit/pdp.controller.edit.js | 50 ++++ .../static/app/pdp/edit/pdp.edit.basic.dir.js | 97 +++++++ moonv4/moon_gui/static/app/pdp/pdp-list.tpl.html | 133 ++++++++++ .../moon_gui/static/app/pdp/pdp.controller.list.js | 287 +++++++++++++++++++++ 10 files changed, 985 insertions(+) create mode 100644 moonv4/moon_gui/static/app/pdp/action/pdp-add.tpl.html create mode 100644 moonv4/moon_gui/static/app/pdp/action/pdp-delete.tpl.html create mode 100644 moonv4/moon_gui/static/app/pdp/action/pdp.controller.add.js create mode 100644 moonv4/moon_gui/static/app/pdp/action/pdp.controller.delete.js create mode 100644 moonv4/moon_gui/static/app/pdp/edit/pdp-edit-basic.tpl.html create mode 100644 moonv4/moon_gui/static/app/pdp/edit/pdp-edit.tpl.html create mode 100644 moonv4/moon_gui/static/app/pdp/edit/pdp.controller.edit.js create mode 100644 moonv4/moon_gui/static/app/pdp/edit/pdp.edit.basic.dir.js create mode 100644 moonv4/moon_gui/static/app/pdp/pdp-list.tpl.html create mode 100644 moonv4/moon_gui/static/app/pdp/pdp.controller.list.js (limited to 'moonv4/moon_gui/static/app/pdp') diff --git a/moonv4/moon_gui/static/app/pdp/action/pdp-add.tpl.html b/moonv4/moon_gui/static/app/pdp/action/pdp-add.tpl.html new file mode 100644 index 00000000..f83fb85c --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/action/pdp-add.tpl.html @@ -0,0 +1,88 @@ + diff --git a/moonv4/moon_gui/static/app/pdp/action/pdp-delete.tpl.html b/moonv4/moon_gui/static/app/pdp/action/pdp-delete.tpl.html new file mode 100644 index 00000000..167ba417 --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/action/pdp-delete.tpl.html @@ -0,0 +1,35 @@ + diff --git a/moonv4/moon_gui/static/app/pdp/action/pdp.controller.add.js b/moonv4/moon_gui/static/app/pdp/action/pdp.controller.add.js new file mode 100644 index 00000000..d1c34c79 --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/action/pdp.controller.add.js @@ -0,0 +1,108 @@ +/** + * @author arnaud marhin + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PDPAddController', PDPAddController); + + PDPAddController.$inject = ['$scope', '$translate', 'alertService', 'formService', 'pdpService', 'policyService', 'utilService']; + + function PDPAddController($scope, $translate, alertService, formService, pdpService, policyService, utilService) { + + var add = this; + + /* + * + */ + + add.form = {}; + + add.pdp = {}; + + add.policies = []; + + add.selectedPolicy = null; + + add.loading = false; + add.loadingPolicies = true; + + add.create = createPDP; + + resolvePolicies(); + + /* + * + */ + + /** + * This function return an array of all policies/template ids + */ + function resolvePolicies() { + + policyService.findAllWithCallback(function(policies){ + + add.policies = policies; + add.loadingPolicies = false; + }); + + } + + function createPDP(pdp) { + + if(formService.isInvalid(add.form)) { + + formService.checkFieldsValidity(add.form); + + } else { + + add.loading = true; + + pdpService.data.pdp.create({}, { + + name: add.pdp.name, + description: add.pdp.description, + security_pipeline: [add.selectedPolicy.id], + keystone_project_id: null + + }, createSuccess, createError); + + } + + function createSuccess(data) { + + $translate('moon.pdp.add.success', { pdpName: pdp.name }) + .then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + var createdPdp = utilService.transformOne(data, 'pdps'); + + add.loading = false; + + $scope.$emit('event:pdpCreatedSuccess', createdPdp); + + } + + function createError(reason) { + + $translate('moon.pdp.add.error', { pdpName: pdp.name }) + .then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + add.loading = false; + + $scope.$emit('event:pdpCreatedError'); + + } + + } + + } + +})(); diff --git a/moonv4/moon_gui/static/app/pdp/action/pdp.controller.delete.js b/moonv4/moon_gui/static/app/pdp/action/pdp.controller.delete.js new file mode 100644 index 00000000..62557864 --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/action/pdp.controller.delete.js @@ -0,0 +1,66 @@ +/** + * @author arnaud marhin + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PDPDeleteController', PDPDeleteController); + + PDPDeleteController.$inject = ['$scope', '$translate', 'alertService', 'pdpService']; + + function PDPDeleteController($scope, $translate, alertService, pdpService) { + + var del = this; + + /* + * + */ + + del.pdp = $scope.pdp; + del.loading = false; + del.remove = deletePDP; + + /* + * + */ + + function deletePDP() { + del.loading = true; + + pdpService.data.pdp.remove({pdp_id: del.pdp.id}, deleteSuccess, deleteError); + + function deleteSuccess(data) { + + $translate('moon.pdp.remove.success', { pdpName: del.pdp.name }) + .then(function (translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + del.loading = false; + + $scope.$emit('event:pdpDeletedSuccess', del.pdp); + + } + + function deleteError(reason) { + + $translate('moon.pdp.remove.error', { pdpName: del.pdp.name }) + .then(function (translatedValue) { + alertService.alertError(translatedValue); + }); + + del.loading = false; + + $scope.$emit('event:pdpDeletedError', del.pdp); + + } + + } + + } + +})(); diff --git a/moonv4/moon_gui/static/app/pdp/edit/pdp-edit-basic.tpl.html b/moonv4/moon_gui/static/app/pdp/edit/pdp-edit-basic.tpl.html new file mode 100644 index 00000000..887d81ca --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/edit/pdp-edit-basic.tpl.html @@ -0,0 +1,65 @@ +
+ +
+ +
+ + + +
+ + + +
+ +
+ +
+ + + +
+ + + +
+ Name is required +
+ +
+ +
+ +
+ + +
+ +
+ +
+ +
+ + + +
+ + + + Update + + + +
+ +
+ +
+ +
\ No newline at end of file diff --git a/moonv4/moon_gui/static/app/pdp/edit/pdp-edit.tpl.html b/moonv4/moon_gui/static/app/pdp/edit/pdp-edit.tpl.html new file mode 100644 index 00000000..bc4582ce --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/edit/pdp-edit.tpl.html @@ -0,0 +1,56 @@ +
+ +
+

Edit

+
+ +
+
+ +
+ +

+ Basic Information + + Update + + +

+ +
+ +
+ +
+ +
+ +
+
+
Id
+
+
Name
+
+
Description
+
+
+
+ +
+ +
+ +
+ +
+ +

Policies

+ +
+ + + +
+
+ +
diff --git a/moonv4/moon_gui/static/app/pdp/edit/pdp.controller.edit.js b/moonv4/moon_gui/static/app/pdp/edit/pdp.controller.edit.js new file mode 100644 index 00000000..41b73098 --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/edit/pdp.controller.edit.js @@ -0,0 +1,50 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PDPEditController', PDPEditController); + + PDPEditController.$inject = ['$scope', '$rootScope', 'pdp', '$stateParams']; + + function PDPEditController($scope, $rootScope, pdp, $stateParams) { + + var edit = this; + + edit.pdp = pdp; + + edit.editBasic = false; + + activate(); + + function activate(){ + + } + + /* + * ---- events + */ + var rootListeners = { + + 'event:pdpUpdatedSuccess': $rootScope.$on('event:pdpUpdatedSuccess', pdpUpdatedSuccess) + + }; + + for (var unbind in rootListeners) { + $scope.$on('$destroy', rootListeners[unbind]); + } + + /** + * When the model is updated, this function refresh the current model with the new changes + * @param event + * @param pdp + */ + function pdpUpdatedSuccess(event, pdp){ + + edit.pdp = pdp; + + } + } + +})(); diff --git a/moonv4/moon_gui/static/app/pdp/edit/pdp.edit.basic.dir.js b/moonv4/moon_gui/static/app/pdp/edit/pdp.edit.basic.dir.js new file mode 100644 index 00000000..402422b6 --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/edit/pdp.edit.basic.dir.js @@ -0,0 +1,97 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .directive('moonPDPEditBasic', moonPDPEditBasic); + + moonPDPEditBasic.$inject = []; + + function moonPDPEditBasic() { + + return { + templateUrl : 'html/pdp/edit/pdp-edit-basic.tpl.html', + bindToController : true, + controller : moonPDPEditBasicController, + controllerAs : 'edit', + scope : { + pdp : '=' + }, + restrict : 'E', + replace : true + }; + } + + angular + .module('moon') + .controller('moonPDPEditBasicController', moonPDPEditBasicController); + + moonPDPEditBasicController.$inject = ['$scope', 'pdpService', 'formService', 'alertService', '$translate', 'utilService']; + + function moonPDPEditBasicController($scope, pdpService, formService, alertService, $translate, utilService){ + + var edit = this; + + edit.editPdp = editPdp; + edit.init = init; + + edit.form = {}; + + activate(); + + function activate(){ + + edit.pdp = $scope.edit.pdp; + + edit.pdpToEdit = angular.copy(edit.pdp); + + } + + function editPdp(){ + + if(formService.isInvalid(edit.form)) { + + formService.checkFieldsValidity(edit.form); + + }else{ + + edit.loading = true; + + pdpService.update(edit.pdpToEdit, updateSuccess, updateError); + + } + + function updateSuccess(data) { + + var updatedPdp = utilService.transformOne(data, 'pdps'); + + $translate('moon.pdp.edit.basic.success', { pdpName: updatedPdp.name }).then( function(translatedValue) { + alertService.alertSuccess(translatedValue); + }); + + edit.loading = false; + + $scope.$emit('event:pdpUpdatedSuccess', updatedPdp); + + } + + function updateError(reason) { + + $translate('moon.pdp.edit.basic.error', { pdpName: edit.pdp.name }).then( function(translatedValue) { + alertService.alertError(translatedValue); + }); + + edit.loading = false; + + } + } + + function init(){ + + edit.pdpToEdit = angular.copy(edit.pdp); + + } + } + +})(); diff --git a/moonv4/moon_gui/static/app/pdp/pdp-list.tpl.html b/moonv4/moon_gui/static/app/pdp/pdp-list.tpl.html new file mode 100644 index 00000000..6716ebba --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/pdp-list.tpl.html @@ -0,0 +1,133 @@ + +
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
 
+
 
+
 
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
Name
+
+
Number of Securities
+
+
Project
+
+
Actions
+
There is no PDP
+
+ +
+ + Loading Project +
+ +
+ +
+ +
+ +
+ Is not mapped +
+
+ +
+ +
+ + + +
+
\ No newline at end of file diff --git a/moonv4/moon_gui/static/app/pdp/pdp.controller.list.js b/moonv4/moon_gui/static/app/pdp/pdp.controller.list.js new file mode 100644 index 00000000..07c9aa2a --- /dev/null +++ b/moonv4/moon_gui/static/app/pdp/pdp.controller.list.js @@ -0,0 +1,287 @@ +/** + * @author arnaud marhin + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .controller('PDPListController', PDPListController); + + PDPListController.$inject = [ + '$rootScope', + '$scope', + '$filter', + '$modal', + 'ngTableParams', + 'pdps', + 'projectService']; + + function PDPListController($rootScope, + $scope, + $filter, + $modal, + ngTableParams, + pdps, + projectService) { + + var list = this; + + list.pdps = pdps; + list.mappings = []; + + + list.getPDPs = getPDPs; + list.hasPDPs = hasPDPs; + list.getPDPName = getPDPName; + list.isMapped = isMapped; + list.getProjectFromPDP = getProjectFromPDP; + list.getidFromPDP = getidFromPDP; + + list.table = {}; + + list.addPDP = addPDP; + list.deletePDP = deletePDP; + list.refreshPDPs = refreshPDPs; + list.updatePDPs = updatePDPs; + + list.getMappedProjectName = getMappedProjectName; + list.getSecPipelineFromPdp = getSecPipelineFromPdp; + + list.search = { query: '', + find: searchPDP, + reset: searchReset }; + + list.add = { modal: $modal({ template: 'html/pdp/action/pdp-add.tpl.html', show: false }), + showModal: showAddModal }; + + list.del = { modal: $modal({ template: 'html/pdp/action/pdp-delete.tpl.html', show: false }), + showModal: showDeleteModal }; + + activate(); + + function activate(){ + newPDPsTable(); + } + + /* + * ---- events + */ + + var rootListeners = { + + 'event:pdpCreatedSuccess': $rootScope.$on('event:pdpCreatedSuccess', pdpCreatedSuccess), + 'event:pdpCreatedError': $rootScope.$on('event:pdpCreatedError', pdpCreatedError), + + 'event:pdpDeletedSuccess': $rootScope.$on('event:pdpDeletedSuccess', pdpDeletedSuccess), + 'event:pdpDeletedError': $rootScope.$on('event:pdpDeletedError', pdpDeletedError), + + }; + + for (var unbind in rootListeners) { + $scope.$on('$destroy', rootListeners[unbind]); + } + + /* + * + */ + + /** + * Function getting an array of PDP JSON + * @return An array of valid pdp. + */ + function getPDPs() { + return (list.pdps) ? list.pdps : []; + } + + function hasPDPs() { + return list.getPDPs().length > 0; + } + + function addPDP(pdp) { + list.pdps.push(pdp); + } + + function deletePDP(pdp) { + + list.pdps = _.chain(list.pdps).reject({id: pdp.id}).value(); + + } + + function refreshPDPs() { + + list.table.total(list.pdps.length); + list.table.reload(); + + } + + function updatePDPs(pdp) { + + _(_.values(list.getPDPs())).each(function(anPDP) { + if(anPDP.id === pdp.id) { + //@todo: Determine what this code should have been designed to do + anPDP = _.clone(pdp); + } + }); + + return list.pdps; + + } + + /** + * Get the id from an PDP + * @param pdp The inspected pdp + * @returns {*} Its UUID + */ + function getidFromPDP(pdp) { + return pdp.id; + } + + function getMappedProjectName(pdp) { + return pdp.tenant.name; + } + + /** + * Get the name of the PDP + * @param pdp The PDP to inspect + * @returns {*} Its name. + */ + function getPDPName(pdp) { + return (pdp) ? pdp.name : ''; + } + + function isMapped(pdp) { + return !_.isNull(pdp.keystone_project_id); + } + + /** + * Prerequisite : before calling this method, isMapped should return true before + * @param pdp + * @returns false or {*}, false if the project is currently loading + */ + function getProjectFromPDP(pdp) { + + if(_.has(pdp, 'project')){ + return pdp.project; + } + + // if the call has not been made + if(!_.has(pdp, 'callPdpInProgress')){ + + pdp.callPdpInProgress = true; + + projectService.findOne(pdp.keystone_project_id, function(project){ + pdp.callPdpInProgress = false; + pdp.project = project; + return pdp.project; + }); + } + + // if the call is in progress return false + return false; + } + + /** + * Generate a table item, directly usable by the rendering engine + * @returns {{}|*} the table + */ + function newPDPsTable() { + + list.table = new ngTableParams({ + + page: 1, // show first page + count: 10, // count per page + sorting: { + name: 'asc' // initial sorting + } + + }, { + + total: function () { return list.getPDPs().length; }, // length of data + getData: function($defer, params) { + + var orderedData = params.sorting() ? $filter('orderBy')(list.getPDPs(), params.orderBy()) : list.getPDPs(); + $defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count())); + + }, + $scope: { $data: {} } + + }); + + return list.table; + + } + + + /* + * --- search + */ + + /** + * Indicate if an pdp having a specified name exists + * @param pdp Searched name + * @returns {boolean} True if a corresponding pdp is found, false otherwise + */ + function searchPDP(pdp){ + return list.getPDPName(pdp).indexOf(list.search.query) !== -1 || list.getSecPipelineFromPdp(pdp).indexOf(list.search.query) !== -1 ; + } + + function getSecPipelineFromPdp(pdp){ + return (pdp.security_pipeline) ? pdp.security_pipeline : []; + } + + /** + * Blank the search field + */ + function searchReset() { + list.search.query = ''; + } + + /* + * ---- add + */ + + function showAddModal() { + list.add.modal.$promise.then(list.add.modal.show); + } + + function pdpCreatedSuccess(event, pdp) { + + list.addPDP(pdp); + list.refreshPDPs(); + + list.add.modal.hide(); + + } + + function pdpCreatedError(event, pdp) { + list.add.modal.hide(); + } + + /* + * ---- delete + */ + + function showDeleteModal(pdp) { + list.del.modal.$scope.pdp = pdp; + list.del.modal.$promise.then(list.del.modal.show); + } + + function pdpDeletedSuccess(event, pdp) { + + list.deletePDP(pdp); + list.refreshPDPs(); + + list.del.modal.hide(); + + } + + function pdpDeletedError() { + list.del.modal.hide(); + } + + } + +})(); -- cgit 1.2.3-korg