Skip to content

Commit a2efcbd

Browse files
authored
Merge pull request #6456 from Countly/improvements-for-ai
Improvements for AI Assistants
2 parents a33f060 + 77515f0 commit a2efcbd

File tree

15 files changed

+445
-433
lines changed

15 files changed

+445
-433
lines changed

frontend/express/public/javascripts/countly/vue/components/drawer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
saveButtonLabel: {type: String, required: false, default: ""},
2121
cancelButtonLabel: {type: String, required: false, default: CV.i18n("common.cancel")},
2222
closeFn: {type: Function},
23-
hasRightSidecar: { type: Boolean, required: false, default: false },
2423
hasCancelButton: {type: Boolean, required: false, default: true},
2524
hasBackLink: {
2625
type: [Object, Boolean],
@@ -62,7 +61,6 @@
6261
'is-mounted': this.isMounted,
6362
'is-open': this.isOpened,
6463
'has-sidecars': this.hasSidecars,
65-
'has-right-sidecar': this.hasRightSidecar,
6664
};
6765
// NOTE: currentScreenMode variable seems to be not defined it should be defined or removed
6866
classes["cly-vue-drawer--" + this.currentScreenMode + "-screen"] = true;

frontend/express/public/javascripts/countly/vue/components/sidebar.js

Lines changed: 69 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global app, jQuery, CV, Vue, countlyGlobal, _, Backbone, store, moment, countlyCommon, CountlyHelpers, countlyCMS */
1+
/* global app, jQuery, CV, Vue, Vuex, countlyGlobal, _, Backbone, store, moment, countlyCommon, CountlyHelpers, countlyCMS */
22

33
(function(countlyVue, $) {
44

@@ -157,6 +157,32 @@
157157
errorMessage: CV.i18n("common.copy-error-message")
158158
};
159159
},
160+
computed: {
161+
member: function() {
162+
//We should fetch the user from vuex
163+
//So that updates are reactive
164+
165+
var userImage = {};
166+
var member = countlyGlobal.member;
167+
if (member.member_image) {
168+
userImage.url = member.member_image;
169+
userImage.found = true;
170+
}
171+
else {
172+
var defaultAvatarSelector = (member.created_at || Date.now()) % 10 * -60;
173+
var name = member.full_name.split(" ");
174+
175+
userImage.found = false;
176+
userImage.url = "images/avatar-sprite.png?v2";
177+
userImage.position = defaultAvatarSelector;
178+
userImage.initials = name[0][0] + name[name.length - 1][0];
179+
}
180+
181+
member.image = userImage;
182+
183+
return member;
184+
},
185+
},
160186
methods: {
161187
logout: function() {
162188
this.$store.dispatch("countlyCommon/removeActiveApp");
@@ -555,12 +581,42 @@
555581
}
556582
});
557583

584+
// we need to register the sidebar menu items here so that they are available in the
585+
// sidebar in the order they are registered otherwise the order registered from other
586+
// plugins will not be respected:
587+
CV.container.registerData("/sidebar/menu/other", {
588+
name: CountlyHelpers.isPluginEnabled('guides') ? "countly-guides" : "help-center",
589+
icon: CountlyHelpers.isPluginEnabled('guides') ? "cly-icon-sidebar-countly-guides" : "cly-icon-sidebar-help-center",
590+
noSelect: true,
591+
tooltip: CountlyHelpers.isPluginEnabled('guides') ? "Countly Guides" : "Help Center",
592+
priority: 10,
593+
});
594+
CV.container.registerData("/sidebar/menu/other", {
595+
name: "user",
596+
noSelect: true,
597+
tooltip: CV.i18n("sidebar.my-profile"),
598+
priority: 20,
599+
});
600+
CV.container.registerData("/sidebar/menu/other", {
601+
name: "language",
602+
noSelect: true,
603+
tooltip: "Language",
604+
priority: 30,
605+
});
606+
CV.container.registerData("/sidebar/menu/other", {
607+
name: "toggle",
608+
icon: "cly-icon-sidebar-toggle-left",
609+
noSelect: true,
610+
priority: 40,
611+
});
612+
558613
var SidebarView = countlyVue.views.create({
559614
template: CV.T('/javascripts/countly/vue/templates/sidebar/sidebar.html'),
560615
mixins: [
561616
countlyVue.container.dataMixin({
562617
"externalMainMenuOptions": "/sidebar/menu/main",
563-
"externalOtherMenuOptions": "/sidebar/menu/other"
618+
"otherMenuOptions": "/sidebar/menu/other",
619+
"customSidebarComponents": "/sidebar/custom",
564620
})
565621
],
566622
components: {
@@ -574,7 +630,6 @@
574630
selectedMenuOptionLocal: null,
575631
versionInfo: countlyGlobal.countlyTypeName,
576632
countlySidebarVersionPath: '/dashboard#/' + countlyCommon.ACTIVE_APP_ID + '/versions',
577-
showMainMenu: true,
578633
redirectHomePage: 'dashboard#/' + countlyCommon.ACTIVE_APP_ID,
579634
onOptionsMenu: false,
580635
onMainMenu: false,
@@ -611,18 +666,19 @@
611666
};
612667
},
613668
computed: {
669+
...Vuex.mapState("countlySidebar", ["showMainMenu"]),
614670
components: function() {
615671
var menuOptions = [];
616672

617673
var externalMainMenuOptions = this.externalMainMenuOptions;
618-
var externalOtherMenuOptions = this.externalOtherMenuOptions;
674+
var otherMenuOptions = this.otherMenuOptions;
619675

620676
if (externalMainMenuOptions && externalMainMenuOptions.length) {
621677
menuOptions = menuOptions.concat(externalMainMenuOptions);
622678
}
623679

624-
if (externalOtherMenuOptions && externalOtherMenuOptions.length) {
625-
menuOptions = menuOptions.concat(externalOtherMenuOptions);
680+
if (otherMenuOptions && otherMenuOptions.length) {
681+
menuOptions = menuOptions.concat(otherMenuOptions);
626682
}
627683

628684
return menuOptions;
@@ -640,66 +696,6 @@
640696

641697
return menuOptions;
642698
},
643-
otherMenuOptions: function() {
644-
var menuOptions = [
645-
{
646-
name: this.enableGuides ? "countly-guides" : "help-center",
647-
icon: this.enableGuides ? "cly-icon-sidebar-countly-guides" : "cly-icon-sidebar-help-center",
648-
noSelect: true,
649-
tooltip: this.enableGuides ? "Countly Guides" : "Help Center"
650-
},
651-
{
652-
name: "user",
653-
noSelect: true,
654-
member: this.member,
655-
tooltip: CV.i18n("sidebar.my-profile")
656-
},
657-
{
658-
name: "language",
659-
noSelect: true,
660-
tooltip: "Language"
661-
},
662-
{
663-
name: "toggle",
664-
icon: "cly-icon-sidebar-toggle-left",
665-
noSelect: true
666-
}
667-
];
668-
669-
var externalOtherMenuOptions = this.externalOtherMenuOptions;
670-
671-
if (externalOtherMenuOptions && externalOtherMenuOptions.length) {
672-
for (var i = 0; i < externalOtherMenuOptions.length; i++) {
673-
menuOptions.splice(3, 0, externalOtherMenuOptions[i]);
674-
}
675-
}
676-
677-
return menuOptions;
678-
},
679-
member: function() {
680-
//We should fetch the user from vuex
681-
//So that updates are reactive
682-
683-
var userImage = {};
684-
var member = countlyGlobal.member;
685-
if (member.member_image) {
686-
userImage.url = member.member_image;
687-
userImage.found = true;
688-
}
689-
else {
690-
var defaultAvatarSelector = (member.created_at || Date.now()) % 10 * -60;
691-
var name = member.full_name.split(" ");
692-
693-
userImage.found = false;
694-
userImage.url = "images/avatar-sprite.png?v2";
695-
userImage.position = defaultAvatarSelector;
696-
userImage.initials = name[0][0] + name[name.length - 1][0];
697-
}
698-
699-
member.image = userImage;
700-
701-
return member;
702-
},
703699
pseudoSelectedMenuOption: function() {
704700
var selected = this.$store.getters["countlySidebar/getSelectedMenuItem"];
705701

@@ -748,6 +744,7 @@
748744
}
749745
},
750746
methods: {
747+
...Vuex.mapMutations("countlySidebar", ["toggleMainMenu"]),
751748
guidesMouseOver: function() {
752749
var state = this.$store.getters["countlySidebar/getGuidesButton"];
753750
if (state !== 'selected' && state !== 'highlighted') {
@@ -763,20 +760,17 @@
763760
onClick: function(option) {
764761
if (!option.noSelect) {
765762
this.selectedMenuOptionLocal = option.name;
766-
this.showMainMenu = true;
763+
this.toggleMainMenu(true);
767764
this.$store.dispatch("countlySidebar/deselectGuidesButton");
768765
}
769766

770767
if (option.name === "toggle") {
771-
this.onToggleClick();
768+
this.toggleMainMenu();
772769
}
773770
else if (option.name === "countly-guides") {
774771
this.$store.dispatch("countlySidebar/selectGuidesButton");
775772
}
776773
},
777-
onToggleClick: function() {
778-
this.showMainMenu = !this.showMainMenu;
779-
},
780774
identifySelected: function() {
781775
for (var ref in this.$refs) {
782776
if (Array.isArray(this.$refs[ref])) {
@@ -804,7 +798,7 @@
804798
/**
805799
* If the selected menu in vuex is dashboards, the sidebar should be floating.
806800
*/
807-
this.showMainMenu = false;
801+
this.toggleMainMenu(false);
808802
}
809803
},
810804
onOptionsMenuMouseOver: function() {
@@ -813,7 +807,7 @@
813807
var selectedOption = this.$store.getters["countlySidebar/getSelectedMenuItem"];
814808

815809
if (selectedOption && selectedOption.menu === "dashboards" && !this.showMainMenu) {
816-
this.showMainMenu = true;
810+
this.toggleMainMenu(true);
817811
}
818812
},
819813
onOptionsMenuMouseLeave: function() {
@@ -845,7 +839,7 @@
845839
/**
846840
* If not on the main menu, hide the main menu.
847841
*/
848-
self.showMainMenu = false;
842+
self.toggleMainMenu(false);
849843
}
850844
}
851845
}, 0);
@@ -877,7 +871,7 @@
877871
/**
878872
* If not on the options menu, hide the main menu.
879873
*/
880-
self.showMainMenu = false;
874+
self.toggleMainMenu(false);
881875
}
882876
}
883877
}, 0);

frontend/express/public/javascripts/countly/vue/container.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
else {
3737
var found = false,
3838
i = 0;
39-
4039
while (!found && i < _items.length) {
4140
if (!Object.prototype.hasOwnProperty.call(_items[i], 'priority') || _items[i].priority > value.priority) {
4241
found = true;

frontend/express/public/javascripts/countly/vue/core.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@
542542
state: {
543543
selectedMenuItem: {},
544544
guidesButton: '',
545+
showMainMenu: window.localStorage.getItem('countlySidebarMenuVisible') === "false" ? false : true,
545546
},
546547
getters: {
547548
getSelectedMenuItem: function(state) {
@@ -557,6 +558,13 @@
557558
},
558559
setGuidesButton: function(state, payload) {
559560
state.guidesButton = payload;
561+
},
562+
toggleMainMenu(state, show) {
563+
if (typeof show !== "boolean") {
564+
show = !state.showMainMenu;
565+
}
566+
state.showMainMenu = show;
567+
window.localStorage.setItem('countlySidebarMenuVisible', show);
560568
}
561569
},
562570
actions: {
@@ -881,7 +889,7 @@
881889
/*
882890
Some 3rd party components such as echarts, use Composition API.
883891
It is not clear why, but when a view with those components destroyed,
884-
they leave some memory leaks. Instantiating DummyCompAPI triggers memory cleanups.
892+
they leave some memory leaks. Instantiating DummyCompAPI triggers memory cleanups.
885893
*/
886894
self.vm = new Vue({
887895
el: el,

frontend/express/public/javascripts/countly/vue/templates/drawer.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,5 @@ <h3>{{title}}</h3>
108108
</div>
109109
</div>
110110
</div>
111-
<div class="cly-vue-drawer__right-sidecar" v-show="hasRightSidecar">
112-
<slot name="right-sidecar" v-bind="passedScope">
113-
</slot>
114-
</div>
115111
</div>
116112
</transition>

frontend/express/public/javascripts/countly/vue/templates/sidebar/sidebar.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
}]" data-test-id="sidebar-menuoptions-toogleleft"></i>
3333
<a v-else-if="item.name === 'help-center'" :href="helpCenterLink" :target="helpCenterTarget"><i :class="['cly-icon-btn', item.icon]" data-test-id="sidebar-menu-helpcenter"></i></a>
3434
<a v-else-if="item.name === 'countly-guides'" @click="onClick(item)" :href="helpCenterLink" :target="helpCenterTarget"><i class="cly-io-16 cly-is cly-is-book-open" :style="guidesButtonDynamicClass" @mouseover='guidesMouseOver' @mouseleave='guidesMouseLeave' data-test-id="sidebar-menu-countlyguides"></i></a>
35+
<component v-else-if="item.component" :is="item.component"></component>
3536
<i v-else :class="['cly-icon-btn', item.icon, {'cly-vue-sidebar__menu-option--selected': item.name === pseudoSelectedMenuOption}]"></i>
3637
</li>
3738
</ul>
3839
</div>
39-
4040
<transition name="cly-vue-sidebar__slide-transition">
4141
<div
4242
:class="[
@@ -67,4 +67,10 @@
6767
</a>
6868
</div>
6969
</transition>
70+
71+
<component
72+
v-if="customSidebarComponents"
73+
v-for="customComponent in customSidebarComponents"
74+
:key="customComponent.name"
75+
:is="customComponent.component" />
7076
</div>

0 commit comments

Comments
 (0)