SHARE
TWEET

Untitled

a guest Nov 30th, 2014 149 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //(...)
  3.  
  4. .factory('utils', function () {
  5.   return {
  6.     // Util for finding an object by its 'id' property among an array
  7.     findById: function findById(a, id) {
  8.       for (var i = 0; i < a.length; i++) {
  9.         if (a[i].id == id) return a[i];
  10.       }
  11.       return null;
  12.     },
  13.  
  14.     // Util for returning a random key from a collection that also isn't the current key
  15.     newRandomKey: function newRandomKey(coll, key, currentKey){
  16.       var randKey;
  17.       do {
  18.         randKey = coll[Math.floor(coll.length * Math.random())][key];
  19.       } while (randKey == currentKey);
  20.       return randKey;
  21.     }
  22.   };
  23. })
  24.        
  25. .factory('userData', ['$http', 'utils', 'Restangular', function ($http, utils, Restangular) {
  26.  
  27.   var userData = Restangular.all('users').getList().then(function(resp) {
  28.     return resp.data;
  29.   });
  30.  
  31.   var factory = {};
  32.   factory.all = function () {
  33.     return userData;
  34.   };
  35.   factory.get = function (id) {
  36.     return userData.then(function(){
  37.       return utils.findById(userData, id);
  38.     })
  39.   };
  40.   return factory;
  41. }]);
  42.  
  43. //(...)
  44.  
  45.    .state('user.admin', {
  46.      title: 'Panel wolontariusza',
  47.      abstract: false,
  48.      url: '/admin',
  49.      views: {
  50.          'navbar@': {
  51.           templateUrl: 'partials/admin/navbar.html'
  52.          },
  53.          'sidebar@': {
  54.           templateUrl: 'partials/admin/sidebar.html'
  55.          },
  56.          'content@': {
  57.           templateUrl: 'partials/admin/dashboard.html',
  58.           controller: 'UsersController'
  59.          },
  60.        },
  61.        data: {
  62.            permissions: {
  63.              only: ['admin']
  64.            }
  65.        },
  66.        resolve: {
  67.          userData: ['userData',
  68.                       function(userData){
  69.                         return userData.all();
  70.           }]
  71.        }
  72.    })
  73.  
  74. //(...)
  75.  
  76. Users.controller('UsersController', function($scope, $state, $stateParams, Restangular, $filter, ngTableParams, userData) {
  77.        
  78.         var data = userData; // angular says that this is undefined
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top