SHARE
TWEET
Untitled
a guest
Nov 30th, 2014
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- //(...)
- .factory('utils', function () {
- return {
- // Util for finding an object by its 'id' property among an array
- findById: function findById(a, id) {
- for (var i = 0; i < a.length; i++) {
- if (a[i].id == id) return a[i];
- }
- return null;
- },
- // Util for returning a random key from a collection that also isn't the current key
- newRandomKey: function newRandomKey(coll, key, currentKey){
- var randKey;
- do {
- randKey = coll[Math.floor(coll.length * Math.random())][key];
- } while (randKey == currentKey);
- return randKey;
- }
- };
- })
- .factory('userData', ['$http', 'utils', 'Restangular', function ($http, utils, Restangular) {
- var userData = Restangular.all('users').getList().then(function(resp) {
- return resp.data;
- });
- var factory = {};
- factory.all = function () {
- return userData;
- };
- factory.get = function (id) {
- return userData.then(function(){
- return utils.findById(userData, id);
- })
- };
- return factory;
- }]);
- //(...)
- .state('user.admin', {
- title: 'Panel wolontariusza',
- abstract: false,
- url: '/admin',
- views: {
- 'navbar@': {
- templateUrl: 'partials/admin/navbar.html'
- },
- 'sidebar@': {
- templateUrl: 'partials/admin/sidebar.html'
- },
- 'content@': {
- templateUrl: 'partials/admin/dashboard.html',
- controller: 'UsersController'
- },
- },
- data: {
- permissions: {
- only: ['admin']
- }
- },
- resolve: {
- userData: ['userData',
- function(userData){
- return userData.all();
- }]
- }
- })
- //(...)
- Users.controller('UsersController', function($scope, $state, $stateParams, Restangular, $filter, ngTableParams, userData) {
- 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.

