Skip to content

Commit 522ed30

Browse files
committed
[frontend] add API for category
1 parent 6a12a10 commit 522ed30

File tree

2 files changed

+94
-52
lines changed

2 files changed

+94
-52
lines changed

frontend/express/public/javascripts/countly/countly.template.js

+93-35
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,60 @@ var AppRouter = Backbone.Router.extend({
712712
_subMenuForAllTypes: [],
713713
_subMenuForCodes: {},
714714
_subMenus: {},
715-
_internalMenuCategories: ["understand", "explore", "reach", "improve", "utilities", "management", "user"],
715+
_internalMenuCategories: ["management", "user"],
716+
/**
717+
* Add menu category. Categories will be copied for all app types and its visibility should be controled from the app type plugin
718+
* @param {string} category - new menu category
719+
* @param {Object} node - object defining category lement
720+
* @param {string} node.text - key for localization string which to use as text
721+
* @param {number} node.priority - priority order number, the less it is, the more on top category will be
722+
* @param {string} node.classes - string with css classes to add to category element
723+
* @param {string} node.style - string with css styling to add to category element
724+
* @param {string} node.html - additional HTML to append after text
725+
* @param {function} node.callback - called when and each time category is added passing same parameters as to this method plus added jquery category element as 3th param
726+
**/
727+
addMenuCategory: function(category, node) {
728+
if (this._internalMenuCategories.indexOf(category) !== -1) {
729+
throw "Category already exists with name: " + category;
730+
}
731+
if (typeof node.priority === "undefined") {
732+
throw "Provide priority property for category element";
733+
}
734+
var menu = $("<div></div>");
735+
menu.addClass("menu-category");
736+
menu.addClass(category + "-category");
737+
menu.attr("data-priority", node.priority);
738+
if (node.classes) {
739+
menu.addClass(node.classes);
740+
}
741+
if (node.style) {
742+
menu.attr("style", node.style);
743+
}
744+
menu.append('<span class="menu-category-title" data-localize="' + (node.text || "sidebar.category." + category) + '"></span>');
745+
if (node.html) {
746+
menu.append(node.html);
747+
}
748+
this._internalMenuCategories.push(category);
749+
var added = false;
750+
var selector = "#sidebar-menu .sidebar-menu";
751+
//try adding before first greater priority
752+
$(selector + " > div.menu-category").each(function() {
753+
var cur = parseInt($(this).attr("data-priority"));
754+
if (node.priority < cur) {
755+
added = true;
756+
$(this).before(menu);
757+
return false;
758+
}
759+
});
760+
761+
//if not added, maybe we are first or last, so just add it
762+
if (!added) {
763+
$(selector).append(menu);
764+
}
765+
if (typeof node.callback === "function") {
766+
node.callback(category, node, menu);
767+
}
768+
},
716769
/**
717770
* Add first level menu element for specific app type under specified category. You can only add app type specific menu to categories "understand", "explore", "reach", "improve", "utilities"
718771
* @param {string} app_type - type of the app for which to add menu
@@ -1233,44 +1286,50 @@ var AppRouter = Backbone.Router.extend({
12331286
this.refreshScripts = {};
12341287
this.appSettings = {};
12351288
this.widgetCallbacks = {};
1236-
1237-
/**
1238-
* Add menus
1239-
**/
1240-
1241-
this.addMenu("understand", {code: "overview", url: "#/", text: "sidebar.dashboard", icon: '<div class="logo dashboard ion-speedometer"></div>', priority: 10});
1242-
this.addMenu("understand", {code: "analytics", text: "sidebar.analytics", icon: '<div class="logo analytics ion-ios-pulse-strong"></div>', priority: 20});
1243-
this.addMenu("understand", {code: "engagement", text: "sidebar.engagement", icon: '<div class="logo ion-happy-outline"></div>', priority: 30});
1244-
this.addMenu("understand", {code: "events", text: "sidebar.events", icon: '<div class="logo events"><i class="material-icons">bubble_chart</i></div>', priority: 40});
1245-
this.addSubMenu("events", {code: "events-overview", url: "#/analytics/events/overview", text: "sidebar.events.overview", priority: 10});
1246-
this.addSubMenu("events", {code: "all-events", url: "#/analytics/events", text: "sidebar.events.all-events", priority: 20});
1247-
if (countlyGlobal.member.global_admin) {
1248-
this.addSubMenu("events", {code: "all-events", url: "#/analytics/events/blueprint", text: "sidebar.events.blueprint", priority: 100});
1249-
}
1250-
this.addMenu("utilities", {
1251-
code: "management",
1252-
text: "sidebar.utilities",
1253-
icon: '<div class="logo management ion-wrench"></div>',
1254-
priority: 10000000,
1255-
callback: function(type, category, node, menu) {
1256-
//for backwards compatability of old plugins adding menu to management
1257-
menu.filter("#management-submenu").append("<span class='help-toggle'></span>");
1289+
var self = this;
1290+
$(document).ready(function() {
1291+
/**
1292+
* Add menus
1293+
**/
1294+
self.addMenuCategory("understand", {priority: 1});
1295+
self.addMenuCategory("explore", {priority: 2});
1296+
self.addMenuCategory("reach", {priority: 3});
1297+
self.addMenuCategory("improve", {priority: 4});
1298+
self.addMenuCategory("utilities", {priority: 5});
1299+
self.addMenu("understand", {code: "overview", url: "#/", text: "sidebar.dashboard", icon: '<div class="logo dashboard ion-speedometer"></div>', priority: 10});
1300+
self.addMenu("understand", {code: "analytics", text: "sidebar.analytics", icon: '<div class="logo analytics ion-ios-pulse-strong"></div>', priority: 20});
1301+
self.addMenu("understand", {code: "engagement", text: "sidebar.engagement", icon: '<div class="logo ion-happy-outline"></div>', priority: 30});
1302+
self.addMenu("understand", {code: "events", text: "sidebar.events", icon: '<div class="logo events"><i class="material-icons">bubble_chart</i></div>', priority: 40});
1303+
self.addSubMenu("events", {code: "events-overview", url: "#/analytics/events/overview", text: "sidebar.events.overview", priority: 10});
1304+
self.addSubMenu("events", {code: "all-events", url: "#/analytics/events", text: "sidebar.events.all-events", priority: 20});
1305+
if (countlyGlobal.member.global_admin) {
1306+
self.addSubMenu("events", {code: "all-events", url: "#/analytics/events/blueprint", text: "sidebar.events.blueprint", priority: 100});
12581307
}
1259-
});
1308+
self.addMenu("utilities", {
1309+
code: "management",
1310+
text: "sidebar.utilities",
1311+
icon: '<div class="logo management ion-wrench"></div>',
1312+
priority: 10000000,
1313+
callback: function(type, category, node, menu) {
1314+
//for backwards compatability of old plugins adding menu to management
1315+
menu.filter("#management-submenu").append("<span class='help-toggle'></span>");
1316+
}
1317+
});
12601318

1261-
this.addSubMenu("management", {code: "longtasks", url: "#/manage/tasks", text: "sidebar.management.longtasks", priority: 10});
1319+
self.addSubMenu("management", {code: "longtasks", url: "#/manage/tasks", text: "sidebar.management.longtasks", priority: 10});
12621320

1263-
if (countlyGlobal.member.global_admin || (countlyGlobal.admin_apps && Object.keys(countlyGlobal.admin_apps).length)) {
1264-
this.addMenu("management", {code: "applications", url: "#/manage/apps", text: "sidebar.management.applications", icon: '<div class="logo-icon ion-ios-albums"></div>', priority: 10});
1265-
}
1266-
if (countlyGlobal.member.global_admin) {
1267-
this.addMenu("management", {code: "users", url: "#/manage/users", text: "sidebar.management.users", icon: '<div class="logo-icon fa fa-user-friends"></div>', priority: 20});
1268-
}
1321+
if (countlyGlobal.member.global_admin || (countlyGlobal.admin_apps && Object.keys(countlyGlobal.admin_apps).length)) {
1322+
self.addMenu("management", {code: "applications", url: "#/manage/apps", text: "sidebar.management.applications", icon: '<div class="logo-icon ion-ios-albums"></div>', priority: 10});
1323+
}
1324+
if (countlyGlobal.member.global_admin) {
1325+
self.addMenu("management", {code: "users", url: "#/manage/users", text: "sidebar.management.users", icon: '<div class="logo-icon fa fa-user-friends"></div>', priority: 20});
1326+
}
12691327

1270-
this.addMenu("management", {code: "help", text: "sidebar.management.help", icon: '<div class="logo-icon ion-help help"></div>', classes: "help-toggle", html: '<div class="on-off-switch" id="help-toggle"><input type="checkbox" class="on-off-switch-checkbox" id="help-toggle-cbox"><label class="on-off-switch-label" for="help-toggle-cbox"></label></div>', priority: 10000000});
1328+
self.addMenu("management", {code: "help", text: "sidebar.management.help", icon: '<div class="logo-icon ion-help help"></div>', classes: "help-toggle", html: '<div class="on-off-switch" id="help-toggle"><input type="checkbox" class="on-off-switch-checkbox" id="help-toggle-cbox"><label class="on-off-switch-label" for="help-toggle-cbox"></label></div>', priority: 10000000});
12711329

1272-
this.addMenu("explore", {code: "users", text: "sidebar.analytics.users", icon: '<div class="logo ion-person-stalker"></div>', priority: 10});
1273-
this.addMenu("explore", {code: "behavior", text: "sidebar.behavior", icon: '<div class="logo ion-funnel"></div>', priority: 20});
1330+
self.addMenu("explore", {code: "users", text: "sidebar.analytics.users", icon: '<div class="logo ion-person-stalker"></div>', priority: 10});
1331+
self.addMenu("explore", {code: "behavior", text: "sidebar.behavior", icon: '<div class="logo ion-funnel"></div>', priority: 20});
1332+
});
12741333

12751334
this.routesHit = 0; //keep count of number of routes handled by your application
12761335
/**
@@ -1588,7 +1647,6 @@ var AppRouter = Backbone.Router.extend({
15881647
return options.fn(object[options.hash.key]);
15891648
});
15901649

1591-
var self = this;
15921650
$("body").addClass("lang-" + countlyCommon.BROWSER_LANG_SHORT);
15931651
jQuery.i18n.properties({
15941652
name: 'locale',

frontend/express/views/dashboard.html

+1-17
Original file line numberDiff line numberDiff line change
@@ -273,23 +273,7 @@
273273
<div id="sidebar">
274274
<div id="new-install-overlay"></div>
275275
<div id="sidebar-menu">
276-
<div id="default-type" class="sidebar-menu" style="display: none;">
277-
<div class="understand-category menu-category">
278-
<span data-localize="sidebar.category.understand" class="menu-category-title"></span>
279-
</div>
280-
<div class="explore-category menu-category">
281-
<span data-localize="sidebar.category.explore" class="menu-category-title"></span>
282-
</div>
283-
<div class="reach-category menu-category">
284-
<span data-localize="sidebar.category.reach" class="menu-category-title"></span>
285-
</div>
286-
<div class="improve-category menu-category">
287-
<span data-localize="sidebar.category.improve" class="menu-category-title"></span>
288-
</div>
289-
<div class="utilities-category menu-category">
290-
<span class="menu-category-title"></span>
291-
</div>
292-
</div>
276+
<div id="default-type" class="sidebar-menu" style="display: none;"></div>
293277
</div>
294278
<div id="version-info"><%= countlyTypeName %></div>
295279
</div>

0 commit comments

Comments
 (0)