X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=afb-client%2Fapp%2FFrontend%2Fpages%2FHome%2FHomeModule.js;h=174365404ebffa5fa3ca0398b31005882af1ea6c;hb=6d06a2a9a02906ce4c848540d74c3c5798688664;hp=6a73bdff2f9868e6b68ad4d447c2417d02df0e35;hpb=07bbb1900acc411da012291f6c0530230a1110e0;p=src%2Fapp-framework-demo.git diff --git a/afb-client/app/Frontend/pages/Home/HomeModule.js b/afb-client/app/Frontend/pages/Home/HomeModule.js index 6a73bdf..1743654 100644 --- a/afb-client/app/Frontend/pages/Home/HomeModule.js +++ b/afb-client/app/Frontend/pages/Home/HomeModule.js @@ -1,12 +1,12 @@ (function() { 'use strict'; -// WARNING: make sure than app/frontend/services/ConfigApp.js match your server +// WARNING: make sure than app/frontend/services/AppConfig.js match your server // list all rependencies within the page + controler if needed -angular.module('HomeModule', ['SubmitButton', 'TokenRefresh']) +angular.module('HomeModule', ['SubmitButton', 'TokenRefresh','ModalNotification']) - .controller('HomeController', function ($http, ConfigApp) { + .controller('HomeController', function (AppCall, Notification) { var scope = this; // I hate JavaScript scope.uuid ="none"; scope.token ="none"; @@ -15,80 +15,74 @@ angular.module('HomeModule', ['SubmitButton', 'TokenRefresh']) console.log ("Home Controller"); - scope.ProcessResponse= function(data, errcode, headers, config) { - var apiname= 'API'+ data.request.api.replace('-','_'); - scope.status = "err-ok"; - scope.errcode= errcode; - scope.request = data.request; - scope.response = data.response; + scope.OnResponse= function(jresp, errcode) { - // if token was refresh let's update ConfigApp - if (data.request.token) ConfigApp.session.token = data.request.token; - if (data.request.uuid) ConfigApp.session.uuid = data.request.uuid; - if (data.request.timeout) ConfigApp.session.timeout = data.request.timeout; - - // Make sure we clean everything when Open/Close is called - if (apiname === "APIcreate" || apiname === "APIreset") { - scope.APIreset =''; - scope.APIcreate =''; - scope.APIrefresh=''; - scope.APIcheck =''; - } - scope[apiname]="success"; + // Update UI response global display zone + scope.status = jresp.request.status; + scope.errcode = errcode; + scope.request = jresp.request; + scope.response = jresp.response; - // If we have a new token let's update it - if (data.request.token) scope.token=data.request.token; + if (jresp.request.status !== "success") { + Notification.error ({message: "Invalid API call:" + jresp.request.info , delay: 5000}); + scope.class [jresp.request.reqid]="fail"; + return; + } - console.log ("OK: "+ JSON.stringify(data)); + switch (jresp.request.reqid) { + case 'login': + case 'logout': + scope.class={}; + break; + + case 'refresh': + case 'check': + break; + + default: + Notification.error ({message: "Invalid RequestID:" + jresp.request.reqid , delay: 5000}); + return; + } + + // update button classes within home.html + scope.class [jresp.request.reqid]="success"; + console.log ("OK: "+ JSON.stringify(jresp)); }; - scope.ProcessError= function(data, errcode, headers, config) { - var apiname= 'API'+data.request.api.replace('-','_'); + scope.ProcessError= function(response, errcode, config) { + Notification.error ({message: "Invalid API:" + response.request.reqid , delay: 5000}); scope.status = "err-fx"; scope.errcode = errcode; - scope.request = data.request; - scope.response = ""; - scope[apiname]="fail"; - - console.log ("FX: "+ JSON.stringify(data)); + scope.request = response.request; + scope.response = ""; + console.log ("FX: "+ JSON.stringify(response)); }; - scope.OpenSession = function() { - console.log ("OpenSession"); - var postdata= {/* any json your application may need */}; - var handler = $http.post(ConfigApp.session.create + '?token='+ConfigApp.session.initial, postdata); - - handler.success(scope.ProcessResponse); - handler.error(scope.ProcessError); + scope.LoginClient = function() { + console.log ("LoginClient"); + AppCall.get ("auth", "login", {/*query*/}, scope.OnResponse, scope.InvalidApiCall); }; scope.CheckSession = function() { - console.log ("CloseSession"); - var postdata= {/* any json your application may need */}; - var handler = $http.post(ConfigApp.session.check + '?token='+ConfigApp.session.token, postdata); - - handler.success(scope.ProcessResponse); - handler.error(scope.ProcessError); + console.log ("CheckSession"); + AppCall.get ("auth", "check", {/*query*/}, scope.OnResponse, scope.InvalidApiCall); + }; scope.RefreshSession = function() { console.log ("RefreshSession"); - var postdata= {/* any json your application may need */}; - var handler = $http.post(ConfigApp.session.refresh + '?token='+ConfigApp.session.token, postdata); - - handler.success(scope.ProcessResponse); - handler.error(scope.ProcessError); + AppCall.get ("auth", "refresh", {/*query*/}, scope.OnResponse, scope.InvalidApiCall); }; - scope.ResetSession = function() { - console.log ("ResetSession"); - var postdata= {/* any json your application may need */}; - var handler = $http.post(ConfigApp.session.reset + '?token='+ConfigApp.session.token, postdata); - - handler.success(scope.ProcessResponse); - handler.error(scope.ProcessError); + scope.LogoutClient = function() { + console.log ("LogoutClient"); + AppCall.get ("auth", "logout", {/*query*/}, scope.OnResponse, scope.InvalidApiCall); }; + scope.Initialised = function () { + scope.class = {login: "success"}; + } + }); console.log ("SampleControler Loaded");