mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Moved menu stuff to own controller
This commit is contained in:
@@ -71,6 +71,7 @@ module.exports = function(config) {
|
|||||||
"website/public/js/directives/when-scrolled.directive.js",
|
"website/public/js/directives/when-scrolled.directive.js",
|
||||||
|
|
||||||
"website/public/js/controllers/authCtrl.js",
|
"website/public/js/controllers/authCtrl.js",
|
||||||
|
"website/public/js/controllers/menuCtrl.js",
|
||||||
"website/public/js/controllers/notificationCtrl.js",
|
"website/public/js/controllers/notificationCtrl.js",
|
||||||
"website/public/js/controllers/rootCtrl.js",
|
"website/public/js/controllers/rootCtrl.js",
|
||||||
"website/public/js/controllers/settingsCtrl.js",
|
"website/public/js/controllers/settingsCtrl.js",
|
||||||
|
|||||||
@@ -41,11 +41,5 @@ describe('Auth Controller', function() {
|
|||||||
expect($window.alert).to.be.calledOnce;
|
expect($window.alert).to.be.calledOnce;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('clearMessage', function() {
|
|
||||||
it('is Chat.seenMessage', inject(function(Chat) {
|
|
||||||
expect(scope.clearMessages).to.eql(Chat.seenMessage);
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
26
test/spec/controllers/menuCtrlSpec.js
Normal file
26
test/spec/controllers/menuCtrlSpec.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Menu Controller', function() {
|
||||||
|
|
||||||
|
describe('MenuCtrl', function(){
|
||||||
|
var scope, ctrl, user, $httpBackend, $window;
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
module(function($provide) {
|
||||||
|
$provide.value('Chat', { seenMessage: function() {} });
|
||||||
|
});
|
||||||
|
|
||||||
|
inject(function(_$httpBackend_, $rootScope, $controller) {
|
||||||
|
scope = $rootScope.$new();
|
||||||
|
|
||||||
|
ctrl = $controller('MenuCtrl', {$scope: scope, $window: $window, User: user});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('clearMessage', function() {
|
||||||
|
it('is Chat.seenMessage', inject(function(Chat) {
|
||||||
|
expect(scope.clearMessages).to.eql(Chat.seenMessage);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -5,8 +5,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
angular.module('habitrpg')
|
angular.module('habitrpg')
|
||||||
.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','ApiUrl', '$modal', 'Analytics', 'Chat',
|
.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','ApiUrl', '$modal', 'Analytics',
|
||||||
function($scope, $rootScope, User, $http, $location, $window, ApiUrl, $modal, Analytics, Chat) {
|
function($scope, $rootScope, User, $http, $location, $window, ApiUrl, $modal, Analytics) {
|
||||||
$scope.Analytics = Analytics;
|
$scope.Analytics = Analytics;
|
||||||
|
|
||||||
$scope.logout = function() {
|
$scope.logout = function() {
|
||||||
@@ -102,41 +102,6 @@ angular.module('habitrpg')
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// @TODO: Pull out menu stuff into separate menu controller
|
|
||||||
$scope.expandMenu = function(menu) {
|
|
||||||
$scope._expandedMenu = ($scope._expandedMenu == menu) ? null : menu;
|
|
||||||
};
|
|
||||||
|
|
||||||
function selectNotificationValue(mysteryValue, invitationValue, unallocatedValue, messageValue, noneValue) {
|
|
||||||
var user = $scope.user;
|
|
||||||
if (user.purchased && user.purchased.plan && user.purchased.plan.mysteryItems && user.purchased.plan.mysteryItems.length) {
|
|
||||||
return mysteryValue;
|
|
||||||
} else if ((user.invitations.party && user.invitations.party.id) || (user.invitations.guilds && user.invitations.guilds.length > 0)) {
|
|
||||||
return invitationValue;
|
|
||||||
} else if (user.flags.classSelected && !(user.preferences && user.preferences.disableClasses) && user.stats.points) {
|
|
||||||
return unallocatedValue;
|
|
||||||
} else if (!(_.isEmpty(user.newMessages))) {
|
|
||||||
return messageValue;
|
|
||||||
} else {
|
|
||||||
return noneValue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.clearMessages = Chat.seenMessage;
|
|
||||||
|
|
||||||
$scope.iconClasses = function() {
|
|
||||||
return selectNotificationValue(
|
|
||||||
"glyphicon-gift",
|
|
||||||
"glyphicon-user",
|
|
||||||
"glyphicon-plus-sign",
|
|
||||||
"glyphicon-comment",
|
|
||||||
"glyphicon-comment inactive");
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.hasNoNotifications = function() {
|
|
||||||
return selectNotificationValue(false, false, false, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ------ Social ----------
|
// ------ Social ----------
|
||||||
|
|
||||||
hello.init({
|
hello.init({
|
||||||
|
|||||||
47
website/public/js/controllers/menuCtrl.js
Normal file
47
website/public/js/controllers/menuCtrl.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('habitrpg')
|
||||||
|
.controller('MenuCtrl', ['$scope', '$rootScope', '$http', 'Chat',
|
||||||
|
function($scope, $rootScope, $http, Chat) {
|
||||||
|
|
||||||
|
$scope.logout = function() {
|
||||||
|
localStorage.clear();
|
||||||
|
window.location.href = '/logout';
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.expandMenu = function(menu) {
|
||||||
|
$scope._expandedMenu = ($scope._expandedMenu == menu) ? null : menu;
|
||||||
|
};
|
||||||
|
|
||||||
|
function selectNotificationValue(mysteryValue, invitationValue, unallocatedValue, messageValue, noneValue) {
|
||||||
|
var user = $scope.user;
|
||||||
|
if (user.purchased && user.purchased.plan && user.purchased.plan.mysteryItems && user.purchased.plan.mysteryItems.length) {
|
||||||
|
return mysteryValue;
|
||||||
|
} else if ((user.invitations.party && user.invitations.party.id) || (user.invitations.guilds && user.invitations.guilds.length > 0)) {
|
||||||
|
return invitationValue;
|
||||||
|
} else if (user.flags.classSelected && !(user.preferences && user.preferences.disableClasses) && user.stats.points) {
|
||||||
|
return unallocatedValue;
|
||||||
|
} else if (!(_.isEmpty(user.newMessages))) {
|
||||||
|
return messageValue;
|
||||||
|
} else {
|
||||||
|
return noneValue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.clearMessages = Chat.seenMessage;
|
||||||
|
|
||||||
|
$scope.iconClasses = function() {
|
||||||
|
return selectNotificationValue(
|
||||||
|
'glyphicon-gift',
|
||||||
|
'glyphicon-user',
|
||||||
|
'glyphicon-plus-sign',
|
||||||
|
'glyphicon-comment',
|
||||||
|
'glyphicon-comment inactive'
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
$scope.hasNoNotifications = function() {
|
||||||
|
return selectNotificationValue(false, false, false, false, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]);
|
||||||
@@ -68,6 +68,7 @@
|
|||||||
"js/directives/when-scrolled.directive.js",
|
"js/directives/when-scrolled.directive.js",
|
||||||
|
|
||||||
"js/controllers/authCtrl.js",
|
"js/controllers/authCtrl.js",
|
||||||
|
"js/controllers/menuCtrl.js",
|
||||||
"js/controllers/notificationCtrl.js",
|
"js/controllers/notificationCtrl.js",
|
||||||
"js/controllers/rootCtrl.js",
|
"js/controllers/rootCtrl.js",
|
||||||
"js/controllers/settingsCtrl.js",
|
"js/controllers/settingsCtrl.js",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
nav.toolbar(ng-controller='AuthCtrl', ng-class='{active: isToolbarHidden}')
|
nav.toolbar(ng-controller='MenuCtrl', ng-class='{active: isToolbarHidden}')
|
||||||
button.toolbar-toggle(ng-click='isToolbarHidden = !isToolbarHidden', ng-class='{active: isToolbarHidden}')
|
button.toolbar-toggle(ng-click='isToolbarHidden = !isToolbarHidden', ng-class='{active: isToolbarHidden}')
|
||||||
span.glyphicon.glyphicon-remove-circle
|
span.glyphicon.glyphicon-remove-circle
|
||||||
span.toggle-text.toggle-close=env.t('close')
|
span.toggle-text.toggle-close=env.t('close')
|
||||||
|
|||||||
Reference in New Issue
Block a user