diff options
| author | root <root@kabir-PC> | 2016-02-23 20:34:59 +0100 |
|---|---|---|
| committer | root <root@kabir-PC> | 2016-02-23 20:34:59 +0100 |
| commit | d2f5ae5c83ef5bc41cf430ace79769459b4acbf8 (patch) | |
| tree | b48882db52687bdd64a398c7d1844d05dbc01343 /client | |
| parent | 1eff9ee90bf26127463cae0ae2cb2e1951527591 (diff) | |
| parent | ff1832adcfe10fadb6cbf738c874611f77f6dd43 (diff) | |
Merge branch 'develop' of https://github.com/manzerbredes/istic-openstack into othmane
Diffstat (limited to 'client')
| -rw-r--r-- | client/index.html | 16 | ||||
| -rw-r--r-- | client/js/app.js | 23 | ||||
| -rw-r--r-- | client/js/controllers/home/main.js | 18 | ||||
| -rw-r--r-- | client/js/controllers/login.js | 75 | ||||
| -rw-r--r-- | client/js/controllers/network/main.js | 9 | ||||
| -rw-r--r-- | client/js/controllers/status.js | 38 | ||||
| -rw-r--r-- | client/js/requests/identity.js | 42 | ||||
| -rw-r--r-- | client/js/services/Compute.js | 40 | ||||
| -rw-r--r-- | client/js/services/Identity.js | 111 | ||||
| -rw-r--r-- | client/js/services/Image.js | 28 | ||||
| -rw-r--r-- | client/partials/login.html | 20 | ||||
| -rw-r--r-- | client/partials/nav.html | 9 | ||||
| -rw-r--r-- | client/vendors/angularjs/angular-cookies.min.js | 9 |
13 files changed, 311 insertions, 127 deletions
diff --git a/client/index.html b/client/index.html index a4845e8..ba183df 100644 --- a/client/index.html +++ b/client/index.html @@ -61,7 +61,7 @@ <!-- Include JQuery --> <script src="./vendors/jquery/jquery-2.2.0.min.js"></script> - + <!-- Include Bootstrap --> <script src="./vendors/bootstrap/js/bootstrap.min.js"></script> @@ -69,18 +69,22 @@ <script src="./vendors/angularjs/angular.min.js"></script> <script src="./vendors/angularjs/angular-route.min.js"></script> <script src="./vendors/angularjs/angular-sanitize.min.js"></script> + <script src="./vendors/angularjs/angular-cookies.min.js"></script> <script src="./js/app.js"></script> - <!-- Include resquest dependencies --> - <script src="./js/requests/identity.js"></script> - + <!-- Include services --> + <script src="./js/services/Identity.js"></script> + <script src="./js/services/Image.js"></script> + <script src="./js/services/Compute.js"></script> + <!-- Include controller --> <script src="./js/controllers/login.js"></script> <script src="./js/controllers/status.js"></script> <script src="./js/controllers/home/main.js"></script> <script src="./js/controllers/network/main.js"></script> + + - -</html>
\ No newline at end of file +</html> diff --git a/client/js/app.js b/client/js/app.js index 0e9c423..e2d5b9b 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -1,9 +1,16 @@ -// Declare main app -var mainApp=angular.module("mainApp",['ngRoute', 'ngSanitize']); - +/** + * The main app module instance + * @type angular.module.angular-1_3_6_L1749.moduleInstance + */ +var mainApp=angular.module("mainApp",['ngRoute', 'ngSanitize', 'ngCookies']); +/** + * Configure routeProvider + */ mainApp.config(['$routeProvider', function($routeProvider){ + + $routeProvider. when('/home',{ templateUrl: 'partials/home/main.html', @@ -15,4 +22,12 @@ mainApp.config(['$routeProvider', function($routeProvider){ }).otherwise({ redirectTo: '/home' }); -}]);
\ No newline at end of file +}]); + +/** + * Configure httpProvider + */ +mainApp.config(['$httpProvider', function($httpProvider){ + $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; +}]); + diff --git a/client/js/controllers/home/main.js b/client/js/controllers/home/main.js index 2898de2..d25bfad 100644 --- a/client/js/controllers/home/main.js +++ b/client/js/controllers/home/main.js @@ -1,11 +1,17 @@ -/* - * home Controller +/** + * The home controller + * + * @param {$scope} $scope The $scope service from angular */ +mainApp.controller('homeCtrl', [ '$scope', 'Compute', function ($scope, Compute) +{ + var updatePage=function(){ + // TODO Update graph etc... + } -mainApp.controller('homeCtrl', function ($scope) -{ - + // Retrieve all Data + Compute.pullData(updatePage); -});
\ No newline at end of file +}]); diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 2f74414..829fc1d 100644 --- a/client/js/controllers/login.js +++ b/client/js/controllers/login.js @@ -1,39 +1,60 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ /** - * Represents a book. - * @constructor + * The login controler + * @param {$scope} $scope The $scope angular service + * @param {$sce} $sce The $sce angular service + * @param {$http} $http The $http angular service + * @param {Identity} The Identity service + */ -mainApp.controller('loginCtrl', function ($scope,$interval,$sce) +mainApp.controller('loginCtrl', ['$scope','$sce','Identity', function ($scope,$sce, Identity) { - // Define default states - $('#loginModal').modal({backdrop: 'static', keyboard: false}); - $('#loadingLoginButton').hide(); - $('#failedToLoginAlert').hide(); - + // Check for login and define default states + if(!Identity.isAlreadyLogin()){ + $('#loginModal').modal({backdrop: 'static', keyboard: false}); + } + $scope.$on('logoutEvent', function(){ + $('#loginModal').modal({backdrop: 'static', keyboard: false}); + }); + + $('#loadingLoginButton').hide(); + $('#failedToLoginAlert').hide(); + - $('#loginButton').click(function(){ + $scope.loginAction=function(){ + + // Begin login state for template $('#loginButton').hide(); $('#loadingLoginButton').show(); $('#failedToLoginAlert').hide(); - + // Get data from templates + var username=$("#loginFormUsername").val(); + var password=$("#loginFormPassword").val(); + var projectname=$("#loginFormProjectname").val(); + + // Function to call to handle result + var responseCallback=function(response){ + + if(response.status!==0){ + // Set reason of fail + $scope.failReason=response.failReason; - $interval( - function() - { - $('#failedToLoginAlert').show(); + // Display the error + $('#failedToLoginAlert').show(); + } + else { + // Else the user is online ! + $('#loginModal').modal('hide'); + } + // Reset button state $('#loginButton').show(); - $('#loadingLoginButton').hide(); - - }, 2000,1); - - - - }); -}) + $('#loadingLoginButton').hide(); + } + + // Try to login + Identity.login(username, password, projectname, responseCallback); + }; + +}]); diff --git a/client/js/controllers/network/main.js b/client/js/controllers/network/main.js index 6c916ae..7264aec 100644 --- a/client/js/controllers/network/main.js +++ b/client/js/controllers/network/main.js @@ -1,9 +1,8 @@ -/* - * network Controller +/** + * The network controller + * + * @param {$scope} $scope The $scope service from angular */ - - - mainApp.controller('networkCtrl', function ($scope) { });
\ No newline at end of file diff --git a/client/js/controllers/status.js b/client/js/controllers/status.js index 42a54d4..e01df34 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -1,28 +1,22 @@ -/* - * mainApp Controller - */ - -mainApp.controller('statusCtrl', function ($scope,$interval,$sce) +/** + * The status controller + * + * @param {$scope} $scope The $scope service from angular + * @param {Identity} The Identity service + */ +mainApp.controller('statusCtrl', ['$scope','Identity', '$rootScope', function ($scope, Identity, $rootScope) { - $scope.username="John Doe"; - $scope.projectname="Web Server"; - // Update status every 2 seconds - /*$interval(function(){ - var status=identity.fetchStatus(); - $scope.username=status[1]; - $scope.lastconnection=status[2]; - if(status[0] == "1"){ - $scope.connection=$sce.trustAsHtml("<span style=\"color:green;\">Online</span>"); - } - else{ - $scope.connection=$sce.trustAsHtml("<span style=\"color:red;\">Offline</span>"); - } - }, 2000);*/ + // Give profile to model + $scope.profile=Identity.profile; + + // Function to logout + $scope.logout=function(){ + Identity.logout(); + $rootScope.$broadcast('logoutEvent'); + }; - - -});
\ No newline at end of file +}]); diff --git a/client/js/requests/identity.js b/client/js/requests/identity.js deleted file mode 100644 index cad1261..0000000 --- a/client/js/requests/identity.js +++ /dev/null @@ -1,42 +0,0 @@ - -// Make Namespace -var identity = {} ; - - - - - - -/* -mainApp.controller('identityCtrl', function($scope, $http) { - - $scope.identityFormData = {}; - - $scope.processForm = function() { - - $http({ - method : 'POST', - url : 'http://148.60.11.31/', - data : $.param($scope.identityFormData), - headers : { 'Content-Type': 'application/x-www-form-urlencoded' } - }) - .success(function(data) { - console.log(data); - - if (!data.success) { - // if not successful, bind errors to error variables - //$scope.errorName = data.errors.name; - //$scope.errorSuperhero = data.errors.superheroAlias; - } else { - // if successful, bind success message to message - //$scope.message = data.message; - } - }); - }; - - - -});*/ - - - diff --git a/client/js/services/Compute.js b/client/js/services/Compute.js new file mode 100644 index 0000000..c5c8da9 --- /dev/null +++ b/client/js/services/Compute.js @@ -0,0 +1,40 @@ + +mainApp.factory('Compute',[ '$http', 'Identity', function($http, Identity){ + + + + var data={}; + data.machines={}; + + + // Parser + var parseGetMachinesAnswer=function(response, failedToSendRequest){ + + }; + + + // Get Machine + var getMachines=function(callback){ + + var result=$http.post('../server/index.php', + $.param({"token" : Identity.profile.token, "task" : "Compute"})); + + + }; + + + + var pullData=function(callback){ + // TODO call getMachines etc... + } + + + // Return services objects + return { + getMachines: getMachines + pullData: pullData + data:data + }; + + +}]); diff --git a/client/js/services/Identity.js b/client/js/services/Identity.js new file mode 100644 index 0000000..8ee664c --- /dev/null +++ b/client/js/services/Identity.js @@ -0,0 +1,111 @@ + +mainApp.factory('Identity',[ '$http', '$cookies', function($http, $cookies){ + + /* Create profile structure to store informations + * about current session + */ + var profile={}; + profile.username=null; + profile.projectname=null; + profile.token=null; + + + /** + * Save profile in cookies + */ + var saveCookieForSession=function(){ + $cookies.putObject('profile', 5); + }; + + + /* + * @returns {boolean} Return true if a cookie is found (and load it in profile) false else + */ + var isAlreadyLogin=function(){ + var profileInCookie=$cookies.getObject('profile'); + console.log(profileInCookie); + + if(typeof profileInCookie !== 'undefined'){ + angular.extend(profile, profileInCookie); + return true; + } + + return false; + } + + /* + * Destroy profile cookies + */ + var logout=function(){ + $cookies.remove('profile'); + } + + + /** + * + * @param {string} response The response to parse + * @param {boolean} to check if the request is send or not + * @returns {requestParserResult} Formated data + */ + var parseLoginAnswer=function(response, failedToSendRequest){ + + + var requestParserResult={}; + requestParserResult.status=1; + requestParserResult.failReason=null; + + if (typeof response.data.token !== 'undefined') { + requestParserResult.status=0; + profile.token=response.data.token; + saveCookieForSession(); + } + else if(failedToSendRequest){ + requestParserResult.failReason="Failed to send request"; + } + else{ + requestParserResult.failReason="Please check your username, password and project name !"; + } + + return requestParserResult; + }; + + + + /** + * Function to connect to OpenStack + * + * @param {object} $http Angular $http service + * @param {string} username The user name + * @param {string} password The user password + * @param {string} projectname The user project name + * @param {function} function to call when data is avalaible + */ + var login=function(username, password,projectname, callback){ + + // Set profile information (early) + profile.username=username; + profile.projectname=projectname; + + var result=$http.post('../server/index.php', + $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname})); + + // Wait and handle the response + result.then(function (response){ + callback(parseLoginAnswer(response), false); + },function(response){ + callback(parseLoginAnswer(response), true) + }); + }; + + + + // Return services objects + return { + login: login, + profile: profile, + isAlreadyLogin: isAlreadyLogin, + logout:logout + }; + + +}]); diff --git a/client/js/services/Image.js b/client/js/services/Image.js new file mode 100644 index 0000000..23b33a8 --- /dev/null +++ b/client/js/services/Image.js @@ -0,0 +1,28 @@ + +mainApp.factory('Image',[ '$http', 'Identity', function($http, Identity){ + + + + var parseUploadImageAnswer=function(response, failedToSendRequest){ + + }; + + + var getImages=function(callback){ + + var result=$http.post('../server/index.php', + $.param({"token" : Identity.profile.token, "task" : "Image"})); + + + + }; + + + + // Return services objects + return { + uploadImage: uploadImage + }; + + +}]); diff --git a/client/partials/login.html b/client/partials/login.html index 387b075..7519a83 100644 --- a/client/partials/login.html +++ b/client/partials/login.html @@ -12,18 +12,18 @@ <div class="modal-body"> <div class="form-group"> - <label label-default="" for="inputUser">User</label> - <input class="form-control" id="inputUser" + <label label-default="" for="loginFormUsername">User</label> + <input class="form-control" id="loginFormUsername" placeholder="Email" type="text" ng-model="identityFormData.user"> </div> <div class="form-group"> - <label label-default="" for="inputProject">Project</label> - <input class="form-control" id="inputProject" - placeholder="Project Name" type="password" ng-model="identityFormData.project"> + <label label-default="" for="loginFormProjectname">Project</label> + <input class="form-control" id="loginFormProjectname" + placeholder="Project Name" type="text" ng-model="identityFormData.project"> </div> <div class="form-group"> - <label label-default="" for="inputPassword">Password</label> - <input class="form-control" id="inputPassword" + <label label-default="" for="loginFormPassword">Password</label> + <input class="form-control" id="loginFormPassword" placeholder="Password" type="password" ng-model="identityFormData.password"> </div> @@ -33,9 +33,9 @@ <div class="modal-footer"> <!--<a href="#" data-dismiss="modal" class="btn btn-default">Close</a>--> <button class="btn btn-lg btn-warning btn-block" id="loadingLoginButton"><span class="glyphicon glyphicon-refresh glyphicon-refresh-animate"></span> Loading...</button> - <div class="alert alert-danger text-center" role="alert" id="failedToLoginAlert">Failed to login</div> - <a href="#" class="btn btn-lg btn-primary btn-block" id="loginButton" ng-click="processForm()">Login</a> + <div class="alert alert-danger text-center" role="alert" id="failedToLoginAlert"><b>Failed to login</b></b><br />{{ failReason }}</div> + <a href="#" class="btn btn-lg btn-primary btn-block" id="loginButton" ng-click="loginAction()">Login</a> </div> </div> </div> -</div>
\ No newline at end of file +</div> diff --git a/client/partials/nav.html b/client/partials/nav.html index f412597..3c72844 100644 --- a/client/partials/nav.html +++ b/client/partials/nav.html @@ -18,8 +18,8 @@ <ul class="nav navbar-nav"> <li class="nav-divider"></li> - <li><a href="#">User : {{ username }}</a></li> - <li><a href="#">Project Name : {{ projectname }}</a></li> + <li><a href="#">User : {{ profile.username }}</a></li> + <li><a href="#">Project Name : {{ profile.projectname }}</a></li> <!--<li><a href="#" >Connection : <span ng-bind-html="connection"></span></a></li>--> @@ -32,11 +32,10 @@ <li><a href="#">Informations</a></li> <li><a href="#">Settings</a></li> <li role="separator" class="divider"></li> - <li><a href="#myModal" data-toggle="modal">Logout</a> - </li> + <li><a href="#" ng-click="logout()">Logout</a></li> </ul> </li> </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> -</nav>
\ No newline at end of file +</nav> diff --git a/client/vendors/angularjs/angular-cookies.min.js b/client/vendors/angularjs/angular-cookies.min.js new file mode 100644 index 0000000..d0f126a --- /dev/null +++ b/client/vendors/angularjs/angular-cookies.min.js @@ -0,0 +1,9 @@ +/* + AngularJS v1.5.0 + (c) 2010-2016 Google, Inc. http://angularjs.org + License: MIT +*/ +(function(p,c,n){'use strict';function l(b,a,g){var d=g.baseHref(),k=b[0];return function(b,e,f){var g,h;f=f||{};h=f.expires;g=c.isDefined(f.path)?f.path:d;c.isUndefined(e)&&(h="Thu, 01 Jan 1970 00:00:00 GMT",e="");c.isString(h)&&(h=new Date(h));e=encodeURIComponent(b)+"="+encodeURIComponent(e);e=e+(g?";path="+g:"")+(f.domain?";domain="+f.domain:"");e+=h?";expires="+h.toUTCString():"";e+=f.secure?";secure":"";f=e.length+1;4096<f&&a.warn("Cookie '"+b+"' possibly not set or overflowed because it was too large ("+ +f+" > 4096 bytes)!");k.cookie=e}}c.module("ngCookies",["ng"]).provider("$cookies",[function(){var b=this.defaults={};this.$get=["$$cookieReader","$$cookieWriter",function(a,g){return{get:function(d){return a()[d]},getObject:function(d){return(d=this.get(d))?c.fromJson(d):d},getAll:function(){return a()},put:function(d,a,m){g(d,a,m?c.extend({},b,m):b)},putObject:function(d,b,a){this.put(d,c.toJson(b),a)},remove:function(a,k){g(a,n,k?c.extend({},b,k):b)}}}]}]);c.module("ngCookies").factory("$cookieStore", +["$cookies",function(b){return{get:function(a){return b.getObject(a)},put:function(a,c){b.putObject(a,c)},remove:function(a){b.remove(a)}}}]);l.$inject=["$document","$log","$browser"];c.module("ngCookies").provider("$$cookieWriter",function(){this.$get=l})})(window,window.angular); +//# sourceMappingURL=angular-cookies.min.js.map |
