From 80323120b61cab3abad1ca3dcfea3358d92e027e Mon Sep 17 00:00:00 2001 From: Keith Holliday Date: Mon, 23 May 2016 21:32:43 +0100 Subject: [PATCH] Updated hall service and updated hall controller --- website/client/js/controllers/hallCtrl.js | 60 ++++++++++++---------- website/client/js/services/hallServices.js | 41 +++++++++++++++ website/client/manifest.json | 1 + website/views/options/social/hall.jade | 2 +- 4 files changed, 76 insertions(+), 28 deletions(-) create mode 100644 website/client/js/services/hallServices.js diff --git a/website/client/js/controllers/hallCtrl.js b/website/client/js/controllers/hallCtrl.js index 3aad20a782..8d9d385546 100644 --- a/website/client/js/controllers/hallCtrl.js +++ b/website/client/js/controllers/hallCtrl.js @@ -1,47 +1,53 @@ "use strict"; -habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrl', '$resource', - function($scope, $rootScope, User, Notification, ApiUrl, $resource) { - var Hero = $resource(ApiUrl.get() + '/api/v3/hall/heroes/:uid', {uid:'@_id'}); +habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrl', 'Hall', + function($scope, $rootScope, User, Notification, ApiUrl, Hall) { $scope.hero = undefined; - $scope.loadHero = function(uuid){ - Hero.query({uid:uuid}, function (heroData) { - $scope.hero = heroData.data; + $scope.currentHeroIndex = undefined; + $scope.heroes = []; + + Hall.getHeroes() + .then(function (response) { + $scope.heroes = response.data.data; }); + + $scope.loadHero = function(uuid, heroIndex) { + $scope.currentHeroIndex = heroIndex; + Hall.getHero(uuid) + .then(function (response) { + $scope.hero = response.data.data; + }); } + $scope.saveHero = function(hero) { $scope.hero.contributor.admin = ($scope.hero.contributor.level > 7) ? true : false; - hero.$save(function(){ - Notification.text("User updated"); - $scope.hero = undefined; - $scope._heroID = undefined; - Hero.query({}, function (heroesData) { - $scope.heroes = heroesData.data; + Hall.updateHero($scope.hero) + .then(function (response) { + Notification.text("User updated"); + $scope.hero = undefined; + $scope._heroID = undefined; + $scope.heroes[$scope.currentHeroIndex] = response.data.data; + $scope.currentHeroIndex = undefined; }); - }) } - Hero.query({}, function (heroesData) { - $scope.heroes = heroesData.data; - }); - $scope.populateContributorInput = function(id) { + $scope.populateContributorInput = function(id, index) { $scope._heroID = id; - window.scrollTo(0,200); - $scope.loadHero(id); + window.scrollTo(0, 200); + $scope.loadHero(id, index); }; }]); -habitrpg.controller("HallPatronsCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrl', '$resource', - function($scope, $rootScope, User, Notification, ApiUrl, $resource) { - var Patron = $resource(ApiUrl.get() + '/api/v3/hall/patrons/:uid', {uid:'@_id'}); - +habitrpg.controller("HallPatronsCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrl', 'Hall', + function($scope, $rootScope, User, Notification, ApiUrl, Hall) { var page = 0; $scope.patrons = []; - $scope.loadMore = function(){ - Patron.query({page: page++}, function(patronsData){ - $scope.patrons = $scope.patrons.concat(patronsData.data); - }) + $scope.loadMore = function() { + Hall.getPatrons(page++) + .then(function (response) { + $scope.patrons = $scope.patrons.concat(response.data.data); + }); } $scope.loadMore(); diff --git a/website/client/js/services/hallServices.js b/website/client/js/services/hallServices.js new file mode 100644 index 0000000000..a3b7e49751 --- /dev/null +++ b/website/client/js/services/hallServices.js @@ -0,0 +1,41 @@ +'use strict'; + +angular.module('habitrpg') +.factory('Hall', [ '$rootScope', 'ApiUrl', '$http', + function($rootScope, ApiUrl, $http) { + var apiV3Prefix = '/api/v3'; + var Hall = {}; + + Hall.getHeroes = function () { + return $http({ + method: 'GET', + url: apiV3Prefix + '/hall/heroes', + }); + } + + Hall.getHero = function (uuid) { + return $http({ + method: 'GET', + url: apiV3Prefix + '/hall/heroes/' + uuid, + }); + } + + Hall.updateHero = function (heroDetails) { + return $http({ + method: 'PUT', + url: apiV3Prefix + '/hall/heroes/' + heroDetails._id, + data: heroDetails, + }); + } + + Hall.getPatrons = function (page) { + if (!page) page = 0; + + return $http({ + method: 'GET', + url: apiV3Prefix + '/hall/patrons?page=' + page, + }); + } + + return Hall; + }]); diff --git a/website/client/manifest.json b/website/client/manifest.json index 2c770893f1..fb59224a34 100644 --- a/website/client/manifest.json +++ b/website/client/manifest.json @@ -56,6 +56,7 @@ "js/services/socialServices.js", "js/services/statServices.js", "js/services/userServices.js", + "js/services/hallServices.js", "js/filters/money.js", "js/filters/roundLargeNumbers.js", diff --git a/website/views/options/social/hall.jade b/website/views/options/social/hall.jade index 381e5ec8fd..c5d0201666 100644 --- a/website/views/options/social/hall.jade +++ b/website/views/options/social/hall.jade @@ -88,7 +88,7 @@ script(type='text/ng-template', id='partials/options.social.hall.heroes.html') span(ng-class='userAdminGlyphiconStyle(hero)') span(ng-if='!hero.contributor.admin') a.label.label-default(ng-class='userLevelStyle(hero)', ng-click='clickMember(hero._id, true)') {{hero.profile.name}} - td(ng-if='user.contributor.admin', ng-click='populateContributorInput(hero._id)').btn-link {{hero._id}} + td(ng-if='user.contributor.admin', ng-click='populateContributorInput(hero._id, $index)').btn-link {{hero._id}} td {{hero.contributor.level}} td {{hero.contributor.text}} td