diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/index.html | 6 | ||||
| -rw-r--r-- | client/js/app.js | 22 | ||||
| -rw-r--r-- | client/js/controllers/home/main.js | 9 | ||||
| -rw-r--r-- | client/js/controllers/login.js | 67 | ||||
| -rw-r--r-- | client/js/controllers/network/main.js | 9 | ||||
| -rw-r--r-- | client/js/controllers/status.js | 34 | ||||
| -rw-r--r-- | client/js/requests/identity.js | 86 | ||||
| -rw-r--r-- | client/js/services/sharedProfile.js | 13 | ||||
| -rw-r--r-- | client/partials/login.html | 14 | ||||
| -rw-r--r-- | client/partials/nav.html | 4 |
10 files changed, 156 insertions, 108 deletions
diff --git a/client/index.html b/client/index.html index a4845e8..013b1b4 100644 --- a/client/index.html +++ b/client/index.html @@ -71,6 +71,9 @@ <script src="./vendors/angularjs/angular-sanitize.min.js"></script> <script src="./js/app.js"></script> + <!-- Include services --> + <script src="./js/services/sharedProfile.js"></script> + <!-- Include resquest dependencies --> <script src="./js/requests/identity.js"></script> @@ -79,7 +82,8 @@ <script src="./js/controllers/status.js"></script> <script src="./js/controllers/home/main.js"></script> <script src="./js/controllers/network/main.js"></script> - + + diff --git a/client/js/app.js b/client/js/app.js index 0e9c423..90fae89 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -1,9 +1,16 @@ -// Declare main app +/** + * The main app module instance + * @type angular.module.angular-1_3_6_L1749.moduleInstance + */ var mainApp=angular.module("mainApp",['ngRoute', 'ngSanitize']); - +/** + * Configure routeProvider + */ mainApp.config(['$routeProvider', function($routeProvider){ + + $routeProvider. when('/home',{ templateUrl: 'partials/home/main.html', @@ -15,4 +22,13 @@ 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..e629779 100644 --- a/client/js/controllers/home/main.js +++ b/client/js/controllers/home/main.js @@ -1,9 +1,8 @@ -/* - * home Controller +/** + * The home controller + * + * @param {$scope} $scope The $scope service from angular */ - - - mainApp.controller('homeCtrl', function ($scope) { diff --git a/client/js/controllers/login.js b/client/js/controllers/login.js index 2f74414..751bd09 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 {sharedProfile} sharedProfile The sharedProfile service + */ -mainApp.controller('loginCtrl', function ($scope,$interval,$sce) +mainApp.controller('loginCtrl', ['$scope','$sce','$http', 'sharedProfile', function ($scope,$sce, $http, sharedProfile) { - // Define default states - $('#loginModal').modal({backdrop: 'static', keyboard: false}); - $('#loadingLoginButton').hide(); - $('#failedToLoginAlert').hide(); - + // Define default states + $('#loginModal').modal({backdrop: 'static', keyboard: false}); + $('#loadingLoginButton').hide(); + $('#failedToLoginAlert').hide(); + - $('#loginButton').click(function(){ + $('#loginButton').click(function(){ $('#loginButton').hide(); $('#loadingLoginButton').show(); $('#failedToLoginAlert').hide(); + var username=$("#loginFormUsername").val(); + var password=$("#loginFormPassword").val(); + var projectname=$("#loginFormProjectname").val(); + + var result=identity.request.login($http,username, password, projectname); + + result.then(function (response){ + // Parser result + var requestResultObject=identity.requestParser.parseLoginAnswer(response); + + // Check for error + if(requestResultObject.status!==0){ + //alert(result.data) + $('#failedToLoginAlert').show(); + } + else { + $('#loginModal').modal('hide'); + sharedProfile.username=username; + sharedProfile.projectname=projectname; - $interval( - function() - { - $('#failedToLoginAlert').show(); + } + // Reset button state $('#loginButton').show(); - $('#loadingLoginButton').hide(); - - }, 2000,1); - + $('#loadingLoginButton').hide(); + },function(response){ + $('#failedToLoginAlert').show(); + + // Reset button state + $('#loginButton').show(); + $('#loadingLoginButton').hide(); + }); + }); -}) +}]); 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..ce6882e 100644 --- a/client/js/controllers/status.js +++ b/client/js/controllers/status.js @@ -1,28 +1,14 @@ -/* - * mainApp Controller - */ - -mainApp.controller('statusCtrl', function ($scope,$interval,$sce) +/** + * The status controller + * + * @param {$scope} $scope The $scope service from angular + * @param {sharedProfile} sharedProfile The sharedProfile build by ourself + */ +mainApp.controller('statusCtrl', ['$scope','sharedProfile', function ($scope, sharedProfile) { - $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);*/ - - - - + $scope.profile=sharedProfile; + -});
\ No newline at end of file +}]);
\ No newline at end of file diff --git a/client/js/requests/identity.js b/client/js/requests/identity.js index cad1261..be3f4f8 100644 --- a/client/js/requests/identity.js +++ b/client/js/requests/identity.js @@ -1,42 +1,52 @@ -// 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; - } - }); - }; - - +/** + * Client Identity Module + * @namespace identity + */ +var identity = {}; + +/** + * Contain all request who can be send with http request + * @namespace request + */ +identity.request = {}; + +/** + * Contain parser for result of request made by {@link identity.request} + * @namespace request + */ +identity.requestParser = {}; + + +/** + * + * @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 + * @returns {promise} The result of the request + */ +identity.request.login=function($http,username, password,projectname){ + return $http.post('../server/index.php', + $.param({"task" : "Authenticate", "user" : username, "password" : password, "project" : projectname})); +}; + + +/** + * + * @param {string} response The response to parse + * @returns {requestParserResult} Formated data + */ +identity.requestParser.parseLoginAnswer=function(response){ + var requestParserResult={}; + + requestParserResult.status=0; + requestParserResult.data=response.data; -});*/ - + // TODO + + + return requestParserResult; +}; diff --git a/client/js/services/sharedProfile.js b/client/js/services/sharedProfile.js new file mode 100644 index 0000000..6e78cf6 --- /dev/null +++ b/client/js/services/sharedProfile.js @@ -0,0 +1,13 @@ + +/** + * The sharedProfile service + * It's used to shared the profile between controller + */ +mainApp.factory('sharedProfile',[function(){ + var profile={}; + + profile.username="None"; + profile.projectname="None"; + + return profile; +}]);
\ No newline at end of file diff --git a/client/partials/login.html b/client/partials/login.html index 387b075..e0ce876 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> diff --git a/client/partials/nav.html b/client/partials/nav.html index f412597..786c53b 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>--> |
