Updated hall service and updated hall controller

This commit is contained in:
Keith Holliday
2016-05-23 21:32:43 +01:00
parent 51254c26dc
commit 80323120b6
4 changed files with 76 additions and 28 deletions

View File

@@ -1,47 +1,53 @@
"use strict"; "use strict";
habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrl', '$resource', habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrl', 'Hall',
function($scope, $rootScope, User, Notification, ApiUrl, $resource) { function($scope, $rootScope, User, Notification, ApiUrl, Hall) {
var Hero = $resource(ApiUrl.get() + '/api/v3/hall/heroes/:uid', {uid:'@_id'});
$scope.hero = undefined; $scope.hero = undefined;
$scope.loadHero = function(uuid){ $scope.currentHeroIndex = undefined;
Hero.query({uid:uuid}, function (heroData) { $scope.heroes = [];
$scope.hero = heroData.data;
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.saveHero = function(hero) {
$scope.hero.contributor.admin = ($scope.hero.contributor.level > 7) ? true : false; $scope.hero.contributor.admin = ($scope.hero.contributor.level > 7) ? true : false;
hero.$save(function(){ Hall.updateHero($scope.hero)
Notification.text("User updated"); .then(function (response) {
$scope.hero = undefined; Notification.text("User updated");
$scope._heroID = undefined; $scope.hero = undefined;
Hero.query({}, function (heroesData) { $scope._heroID = undefined;
$scope.heroes = heroesData.data; $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; $scope._heroID = id;
window.scrollTo(0,200); window.scrollTo(0, 200);
$scope.loadHero(id); $scope.loadHero(id, index);
}; };
}]); }]);
habitrpg.controller("HallPatronsCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrl', '$resource', habitrpg.controller("HallPatronsCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrl', 'Hall',
function($scope, $rootScope, User, Notification, ApiUrl, $resource) { function($scope, $rootScope, User, Notification, ApiUrl, Hall) {
var Patron = $resource(ApiUrl.get() + '/api/v3/hall/patrons/:uid', {uid:'@_id'});
var page = 0; var page = 0;
$scope.patrons = []; $scope.patrons = [];
$scope.loadMore = function(){ $scope.loadMore = function() {
Patron.query({page: page++}, function(patronsData){ Hall.getPatrons(page++)
$scope.patrons = $scope.patrons.concat(patronsData.data); .then(function (response) {
}) $scope.patrons = $scope.patrons.concat(response.data.data);
});
} }
$scope.loadMore(); $scope.loadMore();

View File

@@ -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;
}]);

View File

@@ -56,6 +56,7 @@
"js/services/socialServices.js", "js/services/socialServices.js",
"js/services/statServices.js", "js/services/statServices.js",
"js/services/userServices.js", "js/services/userServices.js",
"js/services/hallServices.js",
"js/filters/money.js", "js/filters/money.js",
"js/filters/roundLargeNumbers.js", "js/filters/roundLargeNumbers.js",

View File

@@ -88,7 +88,7 @@ script(type='text/ng-template', id='partials/options.social.hall.heroes.html')
span(ng-class='userAdminGlyphiconStyle(hero)') span(ng-class='userAdminGlyphiconStyle(hero)')
span(ng-if='!hero.contributor.admin') span(ng-if='!hero.contributor.admin')
a.label.label-default(ng-class='userLevelStyle(hero)', ng-click='clickMember(hero._id, true)') {{hero.profile.name}} 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.level}}
td {{hero.contributor.text}} td {{hero.contributor.text}}
td td