From a5db8628e2e13dbc00202a0ae4c91c2646102373 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Sun, 5 Jan 2014 18:03:47 -0700 Subject: [PATCH] hall: start moving admin stuff to hall-of-heroes / hall-of-patrons, so everyone can see contribs / backers --- public/js/app.js | 26 ++++++-- public/js/controllers/adminCtrl.js | 20 ------ public/js/controllers/hallCtrl.js | 25 +++++++ public/manifest.json | 2 +- src/controllers/{admin.js => hall.js} | 38 +++++++---- src/routes/apiv2.coffee | 31 +++++---- views/options/admin.jade | 65 ------------------ views/options/index.jade | 5 -- views/options/social/hall.jade | 96 +++++++++++++++++++++++++++ views/options/social/index.jade | 6 ++ 10 files changed, 189 insertions(+), 125 deletions(-) delete mode 100644 public/js/controllers/adminCtrl.js create mode 100644 public/js/controllers/hallCtrl.js rename src/controllers/{admin.js => hall.js} (75%) delete mode 100644 views/options/admin.jade create mode 100644 views/options/social/hall.jade diff --git a/public/js/app.js b/public/js/app.js index fb2bfca9a9..63374c4c5b 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -39,6 +39,7 @@ window.habitrpg = angular.module('habitrpg', .when('/options/profile', '/options/profile/avatar') .when('/options/groups', '/options/groups/tavern') .when('/options/groups/guilds', '/options/groups/guilds/public') + .when('/options/groups/hall', '/options/groups/hall/heroes') .when('/options/inventory', '/options/inventory/drops') .when('/options/settings', '/options/settings/settings') @@ -84,16 +85,34 @@ window.habitrpg = angular.module('habitrpg', url: "/groups", templateUrl: "partials/options.social.html" }) + .state('options.social.tavern', { url: "/tavern", templateUrl: "partials/options.social.tavern.html", controller: 'TavernCtrl' }) + .state('options.social.party', { url: '/party', templateUrl: "partials/options.social.party.html", controller: 'PartyCtrl' }) + + .state('options.social.hall', { + url: '/hall', + templateUrl: "partials/options.social.hall.html" + }) + .state('options.social.hall.heroes', { + url: '/heroes', + templateUrl: "partials/options.social.hall.heroes.html", + controller: 'HallHeroesCtrl' + }) + .state('options.social.hall.patrons', { + url: '/patrons', + templateUrl: "partials/options.social.hall.patrons.html", + controller: 'HallPatronsCtrl' + }) + .state('options.social.guilds', { url: '/guilds', templateUrl: "partials/options.social.guilds.html", @@ -184,13 +203,6 @@ window.habitrpg = angular.module('habitrpg', templateUrl: "partials/options.settings.export.html" }) - // Options > Settings - .state('options.admin', { - url: "/admin", - controller: 'AdminCtrl', - templateUrl: "partials/options.admin.html" - }) - var settings = JSON.parse(localStorage.getItem(STORAGE_SETTINGS_ID)); if (settings && settings.auth) { $httpProvider.defaults.headers.common['Content-Type'] = 'application/json;charset=utf-8'; diff --git a/public/js/controllers/adminCtrl.js b/public/js/controllers/adminCtrl.js deleted file mode 100644 index af29e301f5..0000000000 --- a/public/js/controllers/adminCtrl.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; - -habitrpg.controller("AdminCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'API_URL', '$resource', - function($scope, $rootScope, User, Notification, API_URL, $resource) { - var Contributor = $resource(API_URL + '/api/v2/admin/members/:uid', {uid:'@_id'}); - - $scope.profile = undefined; - $scope.loadUser = function(uuid){ - $scope.profile = Contributor.get({uid:uuid}); - } - $scope.save = function(profile) { - profile.$save(function(){ - Notification.text("User updated"); - $scope.profile = undefined; - $scope._uuid = undefined; - $scope.contributors = Contributor.query(); - }) - } - $scope.contributors = Contributor.query(); - }]) \ No newline at end of file diff --git a/public/js/controllers/hallCtrl.js b/public/js/controllers/hallCtrl.js new file mode 100644 index 0000000000..f047d0bcb3 --- /dev/null +++ b/public/js/controllers/hallCtrl.js @@ -0,0 +1,25 @@ +"use strict"; + +habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'API_URL', '$resource', + function($scope, $rootScope, User, Notification, API_URL, $resource) { + var Hero = $resource(API_URL + '/api/v2/hall/heroes/:uid', {uid:'@_id'}); + $scope.hero = undefined; + $scope.loadHero = function(uuid){ + $scope.hero = Hero.get({uid:uuid}); + } + $scope.saveHero = function(hero) { + hero.$save(function(){ + Notification.text("User updated"); + $scope.hero = undefined; + $scope._heroID = undefined; + $scope.heroes = Hero.query(); + }) + } + $scope.heroes = Hero.query(); + }]); + +habitrpg.controller("HallPatronsCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'API_URL', '$resource', + function($scope, $rootScope, User, Notification, API_URL, $resource) { + var Patron = $resource(API_URL + '/api/v2/hall/patrons/:uid', {uid:'@_id'}); + $scope.patrons = Patron.query(); + }]); diff --git a/public/manifest.json b/public/manifest.json index 6fc51a7f19..186150cf9f 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -55,7 +55,7 @@ "js/controllers/inventoryCtrl.js", "js/controllers/footerCtrl.js", "js/controllers/challengesCtrl.js", - "js/controllers/adminCtrl.js" + "js/controllers/hallCtrl.js" ], "css": [ "bower_components/bootstrap/docs/assets/css/bootstrap.css", diff --git a/src/controllers/admin.js b/src/controllers/hall.js similarity index 75% rename from src/controllers/admin.js rename to src/controllers/hall.js index e39c966767..1b14a2fada 100644 --- a/src/controllers/admin.js +++ b/src/controllers/hall.js @@ -12,27 +12,37 @@ api.ensureAdmin = function(req, res, next) { next(); } -api.getMember = function(req, res) { +api.getHeroes = function(req,res,next) { + User.find({'contributor.level':{$ne:null}})// {$exists:true} causes terrible performance http://goo.gl/GCxzC9 + .select('contributor backer balance profile.name') + .sort('contributor.text') + .exec(function(err, users){ + if (err) return next(err); + res.json(users); + }); +} + +api.getPatrons = function(req,res,next){ + User.find({'backer.tier':{$ne:null}}) + .select('contributor backer profile.name') + .sort('-backer.tier') + .exec(function(err, users){ + if (err) return next(err); + res.json(users); + }); +} + +api.getHero = function(req,res,next) { User.findById(req.params.uid) .select('contributor balance profile.name purchased') .exec(function(err, user){ - if (err) return res.json(500,{err:err}); + if (err) return next(err) if (!user) return res.json(400,{err:'User not found'}); res.json(user); }); } -api.listMembers = function(req, res) { - User.find({'contributor.level':{$ne:null}})// {$exists:true} causes terrible performance http://goo.gl/GCxzC9 - .select('contributor balance profile.name') - .sort('contributor.text') - .exec(function(err, users){ - if (err) return res.json(500,{err:err}); - res.json(users); - }); -} - -api.updateMember = function(req, res) { +api.updateHero = function(req,res,next) { async.waterfall([ function(cb){ User.findById(req.params.uid, cb); @@ -50,7 +60,7 @@ api.updateMember = function(req, res) { member.save(cb); } ], function(err, saved){ - if (err) return res.json(500,{err:err}); + if (err) return next(err); res.json(204); }) } \ No newline at end of file diff --git a/src/routes/apiv2.coffee b/src/routes/apiv2.coffee index 539d6cc62c..958430bc10 100644 --- a/src/routes/apiv2.coffee +++ b/src/routes/apiv2.coffee @@ -11,7 +11,7 @@ $ mocha test/user.mocha.coffee user = require("../controllers/user") groups = require("../controllers/groups") auth = require("../controllers/auth") -admin = require("../controllers/admin") +hall = require("../controllers/hall") challenges = require("../controllers/challenges") dataexport = require("../controllers/dataexport") nconf = require("nconf") @@ -491,24 +491,29 @@ module.exports = (swagger, v2) -> action: groups.getMember # --------------------------------- - # Admin + # Hall of Heroes / Patrons # --------------------------------- - "/admin/members": + "/hall/heroes": spec: {} - middleware:[auth.auth, admin.ensureAdmin] - action: admin.listMembers + middleware:[auth.auth] + action: hall.getHeroes - "/admin/members/{uid}:GET": - spec: path: "/admin/members/{uid}" - middleware:[auth.auth, admin.ensureAdmin] - action: admin.getMember + "/hall/heroes/{uid}:GET": + spec: path: "/hall/heroes/{uid}" + middleware:[auth.auth, hall.ensureAdmin] + action: hall.getHero - "/admin/members/{uid}:POST": + "/hall/heroes/{uid}:POST": spec: method: 'POST' - path: "/admin/members/{uid}" - middleware: [auth.auth, admin.ensureAdmin] - action: admin.updateMember + path: "/hall/heroes/{uid}" + middleware: [auth.auth, hall.ensureAdmin] + action: hall.updateHero + + "/hall/patrons": + spec: {} + middleware:[auth.auth] + action: hall.getPatrons # --------------------------------- diff --git a/views/options/admin.jade b/views/options/admin.jade deleted file mode 100644 index f255bb50a0..0000000000 --- a/views/options/admin.jade +++ /dev/null @@ -1,65 +0,0 @@ -script(id='partials/options.admin.html', type="text/ng-template") - h2 Reward User - form.form-horizontal(ng-submit='loadUser(_uuid)') - .-options - .option-group.option-large - input.option-content(type='text', ng-model='_uuid', placeholder='UUID') - button.btn(type='submit') Load User - form.form-horizontal(ng-show='profile', ng-submit='save(profile)') - h3 {{profile.profile.name}} - .-options - .control-group.option-large - input.option-content(type='text', ng-model='profile.contributor.text', placeholder='Contributor Title (eg, "Blacksmith")') - .control-group.option-medium - input.option-content(type='number', step="any", ng-model='profile.contributor.level') - span.input-suffix Contrib Level - br - small [1-7] this determines which items, pets, and mounts are available. Also determines name-tag coloring.  - a(target='_blank', href='https://trello.com/c/wkFzONhE/277-contributor-gear') More details. - .control-group.option-large - textarea.option-content(style='height:15em;', placeholder='Contributions', ng-model='profile.contributor.contributions') - include ../shared/formatting-help - .control-group.option-medium - label.checkbox - input(type='checkbox', ng-model='profile.contributor.admin') - | Admin - - hr - - .control-group.option-medium - input.option-content(type='number', step="any", ng-model='profile.balance') - span.input-suffix Balance - p - small `user.balance` is in USD, not in Gems. Aka, if this number is 1, it means 4 gems. Only use this option when manually granting gems to players, don't use it when granting contributor levels. Contrib levels will automatically add 2G/lvl. - - .control-group.option-medium - label.checkbox - input(type='checkbox', ng-model='profile.purchased.ads') - | Hide Ads - - // h4 Backer Status - // Add backer stuff like tier, disable adds, etcs - button.btn-primary(type='submit') Save - - br - br - br - h2 Current Contributors - table.table.table-striped - tr - thead - tr - th Name - th UUID - th Contrib Level - th Title - th Admin - th Contributions - tr(ng-repeat='contrib in contributors') - td - a.label(class='label-contributor-{{contrib.contributor.level}}', ng-click='clickMember(contrib._id, true)') {{contrib.profile.name}} - td {{contrib._id}} - td {{contrib.contributor.level}} - td {{contrib.contributor.text}} - td {{contrib.contributor.admin}} - td {{contrib.contributor.contributions}} \ No newline at end of file diff --git a/views/options/index.jade b/views/options/index.jade index 7b987ce013..e5a10f7865 100644 --- a/views/options/index.jade +++ b/views/options/index.jade @@ -2,7 +2,6 @@ include ./profile include ./social/index include ./inventory/index include ./settings -include ./admin script(id='partials/options.html', type="text/ng-template") .grid @@ -27,10 +26,6 @@ script(id='partials/options.html', type="text/ng-template") a(ui-sref='options.settings') i.icon-wrench | Settings - li(ng-class="{ active: $state.includes('options.admin') }", ng-if='user.contributor.admin') - a(ui-sref='options.admin') - i.icon-cog - | Admin .tab-content .tab-pane.active diff --git a/views/options/social/hall.jade b/views/options/social/hall.jade new file mode 100644 index 0000000000..aae5ccb1ec --- /dev/null +++ b/views/options/social/hall.jade @@ -0,0 +1,96 @@ +script(type='text/ng-template', id='partials/options.social.hall.html') + ul.nav.nav-tabs + li(ng-class="{ active: $state.includes('options.social.hall.heroes') }") + a(ui-sref='options.social.hall.heroes') + i.icon-eye-close + | Hall of Heroes + li(ng-class="{ active: $state.includes('options.social.hall.patrons') }") + a(ui-sref='options.social.hall.patrons') + | Hall of Patrons + + .tab-content + .tab-pane.active + div(ui-view) + +script(type='text/ng-template', id='partials/options.social.hall.heroes.html') + div.well(ng-if='user.contributor.admin') + h2 Reward User + form.form-horizontal(ng-submit='loadHero(_heroID)') + .-options + .option-group.option-large + input.option-content(type='text', ng-model='_heroID', placeholder='UUID') + button.btn(type='submit') Load User + form.form-horizontal(ng-show='hero', ng-submit='saveHero(hero)') + h3 {{hero.profile.name}} + .-options + .control-group.option-large + input.option-content(type='text', ng-model='hero.contributor.text', placeholder='Contributor Title (eg, "Blacksmith")') + .control-group.option-medium + input.option-content(type='number', step="any", ng-model='hero.contributor.level') + span.input-suffix Contrib Level + br + small [1-7] this determines which items, pets, and mounts are available. Also determines name-tag coloring.  + a(target='_blank', href='https://trello.com/c/wkFzONhE/277-contributor-gear') More details. + .control-group.option-large + textarea.option-content(style='height:15em;', placeholder='Contributions', ng-model='hero.contributor.contributions') + //-include ../../shared/formatting-help + .control-group.option-medium + label.checkbox + input(type='checkbox', ng-model='hero.contributor.admin') + | Admin + + hr + + .control-group.option-medium + input.option-content(type='number', step="any", ng-model='hero.balance') + span.input-suffix Balance + p + small `user.balance` is in USD, not in Gems. Aka, if this number is 1, it means 4 gems. Only use this option when manually granting gems to players, don't use it when granting contributor levels. Contrib levels will automatically add 2G/lvl. + + .control-group.option-medium + label.checkbox + input(type='checkbox', ng-model='hero.purchased.ads') + | Hide Ads + + // h4 Backer Status + // Add backer stuff like tier, disable adds, etcs + button.btn-primary(type='submit') Save + + + table.table.table-striped + tr + thead + tr + th Name + th(ng-if='user.contributor.admin') UUID + th Contrib Level + th Title + th Contributions + tr(ng-repeat='hero in heroes') + td + span(ng-if='hero.contributor.admin',popover='Game Master',popover-trigger='mouseenter',popover-placement='right') + a.label(class='label-contributor-{{hero.contributor.level}}', ng-class='{"label-npc": hero.backer.npc}', ng-click='clickMember(hero._id, true)') + i.icon-star  + | {{hero.profile.name}} + i.icon-star  + span(ng-if='!hero.contributor.admin') + a.label(class='label-contributor-{{hero.contributor.level}}', ng-class='{"label-npc": hero.backer.npc}', ng-click='clickMember(hero._id, true)') {{hero.profile.name}} + td(ng-if='user.contributor.admin') {{hero._id}} + td {{hero.contributor.level}} + td {{hero.contributor.text}} + td + markdown(ng-model='hero.contributor.contributions', target='_blank') + +script(type='text/ng-template', id='partials/options.social.hall.patrons.html') + table.table.table-striped + tr + thead + tr + th Name + th(ng-if='user.contributor.admin') UUID + th Backer Tier + tr(ng-repeat='patron in patrons') + td + a.label(class='label-contributor-{{patron.contributor.level}}', ng-class='{"label-npc": patron.backer.npc}', ng-click='clickMember(patron._id, true)') {{patron.profile.name}} + td(ng-if='user.contributor.admin') {{patron._id}} + td {{patron.backer.tier}} \ No newline at end of file diff --git a/views/options/social/index.jade b/views/options/social/index.jade index 51d1742dff..17dfb94f49 100644 --- a/views/options/social/index.jade +++ b/views/options/social/index.jade @@ -2,10 +2,12 @@ // Subscribe to that ticket & change this when they fix include ./challenges.jade +include ./hall.jade script(type='text/ng-template', id='partials/options.social.tavern.html') include ./tavern + script(type='text/ng-template', id='partials/options.social.party.html') div(ng-show='group._id') include ./group @@ -84,6 +86,10 @@ script(type='text/ng-template', id='partials/options.social.html') a(ui-sref='options.social.challenges') i.icon-bullhorn | Challenges + li(ng-class="{ active: $state.includes('options.social.hall') }") + a(ui-sref='options.social.hall') + i.icon-flag + | Hall .tab-content .tab-pane.active