Commits

ont  committed 60ea132

(+) adding viewing of cards for another user

  • Participants
  • Parent commits 22708e6

Comments (0)

Files changed (4)

 from beaker.middleware import SessionMiddleware
 
 
-@bottle.get('/users/info')
+@bottle.get('/users/<id>')
 @auth
-def login():
-    s = bottle.request.environ.get('beaker.session')
-    return {'id' : s['id'], 'login' : s['login']}  ## hand-made User instance
+def login( id ):
+    if id == 'current':
+        s = bottle.request.environ.get('beaker.session')
+        id = s['id']
+
+    user = User.select().where(User.id == id).get()
+    return user and {'id' : user.id, 'login' : user.login}  ## hand-made User instance
+
 
 @bottle.post('/users/login')
 def login():

File js/controllers.js

-function CardsListCtrl($scope, $http, Restangular, mtg) {
+function CardsListCtrl($scope, $http, Restangular, mtg, authService, user) {
     var prs = null;
     var cards = Restangular.all('cards');
 
     $scope.dmode = 'thumb';
     $scope.dlg_login = false;
 
-    /// container for user (login) information
-    $scope.u = {
-        'user' : null,  // restangular instance
-    };
-
     /// container for filtering and sorting params
     $scope.m = {
         'sort' : [null, null, null],
         prs = PEG.buildParser(res.data);
     });
 
+    /*
+     * MAIN PART.
+     * Download original non-sorted "owns" for * selected user (injected by route).
+     */
+    user.getList('owns').then(function(data){
+        $scope.owns = data;
+        $scope.owns_process();  // do default sorting and grouping
+    });
+
     $scope.cmd_line = function( cmd ) {
         console.log(cmd, prs.parse(cmd));
         res = prs.parse(cmd);
         if( res[0] == 'add' ) {
 
-            $scope.u.user.all('owns').post({
+            /// use restangular instance
+            authService.user.all('owns').post({
                 'cnt' : res[1],
                 'name': res[2][0],
                 'cset': res[2][1]}
     }
 
     /*
-     * Fillup $scope with basic non-sorted and non-filtered
-     * list of owns for particular user.
-     */
-    $scope.owns_reload = function( user ){
-        /// download original non-sorted "owns"
-        user.getList('owns').then(function(data){
-            $scope.owns = data;
-            $scope.owns_process();  // do default sorting and grouping
-        });
-    }
-
-    /*
      * Login form hooks.
      */
     $scope.$on('event:auth-loginRequired',  function(){ $scope.dlg_login = true; });
     $scope.$on('event:auth-loginCancelled', function(){ $scope.dlg_login = false; });
-    $scope.$on('event:auth-loginConfirmed', function(){
-        $scope.dlg_login = false;
-    });
+    $scope.$on('event:auth-loginConfirmed', function(){ $scope.dlg_login = false; });
 
     /*
      * Login form global functions
 
     $scope.bootstrap = function(){
         /// trying to get ourself and storing in global box "$scope.u"
-        users.get('info').then(function( user ){
-            $scope.u.user = user;
-            $scope.owns_reload(user);  /// now load our "owns"
+        users.get('current').then(function( user ){
+            authService.user = user;           /// store restangular user obj in service singleton
+            $scope.$emit('event:userLogged');  /// send notification
         });
     }
 

File js/modules.js

     $routeProvider.
         when('/main', {
             templateUrl: 'tpl/cards_my.html',
-            controller: 'CardsListCtrl'
+            controller: 'CardsListCtrl',
+            resolve: {
+                'user' : function(Restangular){
+                    return Restangular.all('users').get('current');  // inject current user
+                }
+            }
+        }).
+        when('/user/:user_id/cards/all', {
+            templateUrl: 'tpl/cards_user.html',
+            controller: 'CardsListCtrl',
+            resolve: {
+                'user' : function(Restangular, $route){
+                    /// Inject selected user to CardsListCtrl
+                    /// NOTE: we can't use $routeParams here (it will be updated after resolve)
+                    return Restangular.all('users').get($route.current.params.user_id);
+                }
+            }
         }).
         /*
-        when('/user/:user_id/cards/all', {
-            templateUrl: 'tpl/cards_user.html',
-            controller: 'CardsListCtrl'
-        }).
         when('/user/:user_id/cards/exchange', {
             templateUrl: 'tpl/cards_user.html',
             controller: 'CardsListCtrl'

File tpl/cards_user.html

+<div>
+    <div ng-include="'tpl/_popup_login.html'"></div>
+    <div ng-include="'tpl/_topbar.html'"></div>
+
+    <hr/>
+
+    <div ng-include="'tpl/_cards_numpad.html'"></div>
+    <div ng-include="'tpl/_cards_list.html'"></div>
+</div>