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/services/gui/alert.service.js | 39 +++++++++++++ .../static/app/services/gui/browser.service.js | 47 +++++++++++++++ .../static/app/services/gui/form.service.js | 47 +++++++++++++++ .../static/app/services/gui/menu.service.js | 49 ++++++++++++++++ .../app/services/gui/security.pipeline.service.js | 29 ++++++++++ .../static/app/services/gui/util.service.js | 66 ++++++++++++++++++++++ .../static/app/services/gui/version.service.js | 27 +++++++++ 7 files changed, 304 insertions(+) create mode 100644 moonv4/moon_gui/static/app/services/gui/alert.service.js create mode 100644 moonv4/moon_gui/static/app/services/gui/browser.service.js create mode 100644 moonv4/moon_gui/static/app/services/gui/form.service.js create mode 100644 moonv4/moon_gui/static/app/services/gui/menu.service.js create mode 100644 moonv4/moon_gui/static/app/services/gui/security.pipeline.service.js create mode 100644 moonv4/moon_gui/static/app/services/gui/util.service.js create mode 100644 moonv4/moon_gui/static/app/services/gui/version.service.js (limited to 'moonv4/moon_gui/static/app/services/gui') diff --git a/moonv4/moon_gui/static/app/services/gui/alert.service.js b/moonv4/moon_gui/static/app/services/gui/alert.service.js new file mode 100644 index 00000000..8435eab1 --- /dev/null +++ b/moonv4/moon_gui/static/app/services/gui/alert.service.js @@ -0,0 +1,39 @@ +/** + * @author arnaud marhin + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .factory('alertService', alertService); + + alertService.$inject = [ 'toaster']; + + function alertService( toaster) { + + var service = {}; + + service.alertError = alertError; + service.alertSuccess = alertSuccess; + service.alertInfo = alertInfo; + + return service; + + function alertError(msg){ + toaster.pop('error', null, msg, 5000); + } + + function alertSuccess(msg){ + toaster.pop('success', null, msg, 5000); + } + + function alertInfo(msg){ + toaster.pop('note', null, msg, 5000); + } + + } + +})(); diff --git a/moonv4/moon_gui/static/app/services/gui/browser.service.js b/moonv4/moon_gui/static/app/services/gui/browser.service.js new file mode 100644 index 00000000..88c693a8 --- /dev/null +++ b/moonv4/moon_gui/static/app/services/gui/browser.service.js @@ -0,0 +1,47 @@ +/** + * @author arnaud marhin + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .factory('browserService', browserService); + + function browserService() { + + var service = {}; + + service.sayWho = sayWho; + + return service; + + function sayWho() { + + var ua= navigator.userAgent, tem, + + M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; + + if(/trident/i.test(M[1])){ + tem= /\brv[ :]+(\d+)/g.exec(ua) || []; + return 'IE '+(tem[1] || ''); + } + + if(M[1]=== 'Chrome'){ + tem= ua.match(/\bOPR\/(\d+)/); + if(tem!= null){ return 'Opera '+tem[1];} + } + + M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?']; + + if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1]); + + return M.join(' '); + + }; + + }; + +})(); diff --git a/moonv4/moon_gui/static/app/services/gui/form.service.js b/moonv4/moon_gui/static/app/services/gui/form.service.js new file mode 100644 index 00000000..bc137943 --- /dev/null +++ b/moonv4/moon_gui/static/app/services/gui/form.service.js @@ -0,0 +1,47 @@ +/** + * @author arnaud marhin + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .factory('formService', formService); + + function formService() { + + var service = {}; + + service.isInvalid = isInvalid; + service.checkFieldsValidity = checkFieldsValidity; + + return service; + + function isInvalid(form) { + return form.$invalid; + } + + function checkFieldsValidity(form) { + + var validationErrorKeys = _.keys(form.$error); + + _(validationErrorKeys).each(function(anErrorKey) { + + var formFields = _.values(form.$error[anErrorKey]); + + _(formFields).each(function(aFormField) { + + aFormField.$dirty = true; + aFormField.$setValidity(anErrorKey, false); + + }); + + }); + + } + + } + +})(); diff --git a/moonv4/moon_gui/static/app/services/gui/menu.service.js b/moonv4/moon_gui/static/app/services/gui/menu.service.js new file mode 100644 index 00000000..fd90a2fa --- /dev/null +++ b/moonv4/moon_gui/static/app/services/gui/menu.service.js @@ -0,0 +1,49 @@ +/** + * @author arnaud marhin + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .factory('menuService', menuService); + + menuService.$inject = ['$state']; + + function menuService($state) { + + var service = {}; + + service.isProjectTabActive = isProjectTabActive; + service.isPDPTabActive = isPDPTabActive; + service.isPolicyTabActive = isPolicyTabActive; + service.isLogsTabActive = isLogsTabActive; + service.isModelTabActive = isModelTabActive; + + return service; + + function isProjectTabActive() { + return $state.includes('moon.project'); + } + + function isPDPTabActive() { + return $state.includes('moon.pdp'); + } + + function isPolicyTabActive(){ + return $state.includes('moon.policy'); + } + + function isLogsTabActive(){ + return $state.includes('moon.logs'); + } + + function isModelTabActive(){ + return $state.includes('moon.model'); + } + + } + +})(); diff --git a/moonv4/moon_gui/static/app/services/gui/security.pipeline.service.js b/moonv4/moon_gui/static/app/services/gui/security.pipeline.service.js new file mode 100644 index 00000000..3831e487 --- /dev/null +++ b/moonv4/moon_gui/static/app/services/gui/security.pipeline.service.js @@ -0,0 +1,29 @@ +(function() { + + 'use strict'; + + angular + .module('moon') + .factory('securityPipelineService', securityPipelineService); + + securityPipelineService.$inject = ['SECURITY_PIPELINE_CST','policyService']; + + function securityPipelineService(SECURITY_PIPELINE_CST, policyService) { + var service = {}; + + service.findAll = findAll; + + return service; + + function findAll(type){ + switch(type){ + case SECURITY_PIPELINE_CST.TYPE.POLICY : + return policyService.findAll(); + default : + return policyService.findAll(); + } + + } + } + +})(); diff --git a/moonv4/moon_gui/static/app/services/gui/util.service.js b/moonv4/moon_gui/static/app/services/gui/util.service.js new file mode 100644 index 00000000..7274244a --- /dev/null +++ b/moonv4/moon_gui/static/app/services/gui/util.service.js @@ -0,0 +1,66 @@ +/** + * @author arnaud marhin + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .factory('utilService', utilService); + + utilService.$inject = []; + + function utilService() { + + return { + + + /** + * Transforms an answer from server and return an array of objects instead the @param data + + * @param data object : { + * 'typeOfTheRreturnedObject' : { + * 'idObject1' : {....}, + * 'idObject2' : {....} + * } + * } + * @param typeOfObject + * @returns {Array} + */ + transform : function(data, typeOfObject){ + + var result = []; + + _.each(data[typeOfObject],function(item, key){ + item.id = key; + result.push(item); + }); + + return result; + }, + + /** + * same as transform but with only one object + * @param data + * @param typeOfObject the first elem of the dictonnary + */ + transformOne : function(data, typeOfObject){ + + var result = []; + + _.each(data[typeOfObject], function (item, key) { + item.id = key; + result.push(item); + }); + + return result[0]; + + } + + }; + + } + +})(); diff --git a/moonv4/moon_gui/static/app/services/gui/version.service.js b/moonv4/moon_gui/static/app/services/gui/version.service.js new file mode 100644 index 00000000..5f9f2786 --- /dev/null +++ b/moonv4/moon_gui/static/app/services/gui/version.service.js @@ -0,0 +1,27 @@ +/** + * @author arnaud marhin + */ + +(function() { + + 'use strict'; + + angular + .module('moon') + .factory('versionService', versionService); + + versionService.$inject = ['$resource']; + + function versionService($resource) { + + return { + + version: $resource('version.json', {}, { + get: {method: 'GET', isArray: false} + }) + + }; + + } + +})(); -- cgit 1.2.3-korg