nitweb/angular: add user controller
authorAlexandre Terrasa <alexandre@moz-code.org>
Tue, 2 Aug 2016 17:43:05 +0000 (13:43 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Mon, 15 Aug 2016 04:59:32 +0000 (00:59 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

share/nitweb/index.html
share/nitweb/javascripts/model.js
share/nitweb/javascripts/nitweb.js
share/nitweb/javascripts/users.js [new file with mode: 0644]
share/nitweb/views/user.html [new file with mode: 0644]

index b936f1d..7454ce5 100644 (file)
@@ -74,5 +74,6 @@
                <script src='/javascripts/index.js'></script>
                <script src='/javascripts/docdown.js'></script>
                <script src='/javascripts/metrics.js'></script>
+               <script src='/javascripts/users.js'></script>
        </body>
 </html>
index cd127ed..8ec516c 100644 (file)
                                }
                        }
                }])
+
+               .factory('User', [ '$http', function($http) {
+                       return {
+                               loadUser: function(cb, cbErr) {
+                                       $http.get(apiUrl + '/user')
+                                               .success(cb)
+                                               .error(cbErr);
+                               }
+                       }
+               }])
 })();
index 9dac463..21df4bf 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 (function() {
-       angular.module('nitweb', ['ngRoute', 'ngSanitize', 'angular-loading-bar', 'entities', 'docdown', 'index', 'metrics'])
+       angular.module('nitweb', ['ngRoute', 'ngSanitize', 'angular-loading-bar', 'entities', 'docdown', 'index', 'metrics', 'users'])
        .config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
                cfpLoadingBarProvider.includeSpinner = false;
        }])
                                controller: 'IndexCtrl',
                                controllerAs: 'indexCtrl'
                        })
+                       .when('/user', {
+                               templateUrl: 'views/user.html',
+                               controller: 'UserCtrl',
+                               controllerAs: 'userCtrl'
+                       })
                        .when('/docdown', {
                                templateUrl: 'views/docdown.html',
                                controller: 'DocdownCtrl',
                                controllerAs: 'docdownCtrl'
                        })
+                       .when('/login', {
+                               controller : function(){
+                                       window.location.replace('/login');
+                               },
+                           template : "<div></div>"
+                       })
+                       .when('/logout', {
+                               controller : function(){
+                                       window.location.replace('/logout');
+                               },
+                           template : "<div></div>"
+                       })
                        .when('/doc/:id', {
                                templateUrl: 'views/doc.html',
                                controller: 'EntityCtrl',
diff --git a/share/nitweb/javascripts/users.js b/share/nitweb/javascripts/users.js
new file mode 100644 (file)
index 0000000..42e7d6f
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+(function() {
+       angular
+               .module('users', ['ngSanitize', 'model'])
+
+               .controller('UserCtrl', ['User', '$routeParams', '$scope', function(User, $routeParams, $scope) {
+                       this.loadUser = function() {
+                               User.loadUser(
+                                       function(data) {
+                                               $scope.user = data;
+                                       }, function(err) {
+                                               $scope.error = err;
+                                       });
+                       };
+
+                       this.loadUser();
+               }])
+
+               .directive('userMenu', ['User', function(User) {
+                       return {
+                               restrict: 'E',
+                               templateUrl: '/directives/user/user-menu.html',
+                               link: function ($scope, element, attrs) {
+                                       $scope.loadUser = function() {
+                                               User.loadUser(
+                                                       function(data) {
+                                                               $scope.user = data;
+                                                       }, function(err) {
+                                                               //$scope.error = err;
+                                                       });
+                                       }
+                                       $scope.loadUser();
+                               }
+                       };
+               }])
+})();
diff --git a/share/nitweb/views/user.html b/share/nitweb/views/user.html
new file mode 100644 (file)
index 0000000..b044c9c
--- /dev/null
@@ -0,0 +1,20 @@
+<div class='container'>
+       <div class='col-xs-4'>
+               <img class='avatar' width='100%' src='{{user.avatar_url}}' />
+               <h1>{{user.login}}</h1>
+               <h3>{{user.name}}</h3>
+               <ul class='list-unstyled'>
+                       <li>
+                               <span class='glyphicon glyphicon-envelope' />
+                               <a href='mailto:{{user.email}}'>{{user.email}}</a>
+                       </li>
+                       <li>
+                               <span class='glyphicon glyphicon-link' />
+                               <a href='{{user.blog}}'>{{user.blog}}</a>
+                       </li>
+               </ul>
+       </div>
+       <div class='col-xs-8'>
+               Nothing to display yet.
+       </div>
+<div>