aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/moon_gui/static/app/services/gui
diff options
context:
space:
mode:
authorWuKong <rebirthmonkey@gmail.com>2017-04-22 13:25:07 +0200
committerWuKong <rebirthmonkey@gmail.com>2017-04-22 13:25:07 +0200
commitd182202fc6001983541504ed323d68479086317e (patch)
tree11d4c10cdd3e995f519c3e0e324968fdaf175114 /moonv4/moon_gui/static/app/services/gui
parent83c1c966baf73329fab8ddcfad19ad7fe0c41c2a (diff)
add moonv4
Change-Id: I247af788d0b0fb961fbc85416486b241eb1d807c Signed-off-by: WuKong <rebirthmonkey@gmail.com>
Diffstat (limited to 'moonv4/moon_gui/static/app/services/gui')
-rw-r--r--moonv4/moon_gui/static/app/services/gui/alert.service.js39
-rw-r--r--moonv4/moon_gui/static/app/services/gui/browser.service.js47
-rw-r--r--moonv4/moon_gui/static/app/services/gui/form.service.js47
-rw-r--r--moonv4/moon_gui/static/app/services/gui/menu.service.js49
-rw-r--r--moonv4/moon_gui/static/app/services/gui/security.pipeline.service.js29
-rw-r--r--moonv4/moon_gui/static/app/services/gui/util.service.js66
-rw-r--r--moonv4/moon_gui/static/app/services/gui/version.service.js27
7 files changed, 304 insertions, 0 deletions
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<arnaud.marhin@orange.com>
+ */
+
+(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<arnaud.marhin@orange.com>
+ */
+
+(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<arnaud.marhin@orange.com>
+ */
+
+(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<arnaud.marhin@orange.com>
+ */
+
+(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<arnaud.marhin@orange.com>
+ */
+
+(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<arnaud.marhin@orange.com>
+ */
+
+(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}
+ })
+
+ };
+
+ }
+
+})();