|
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 */ |
2 | 2 |
|
3 | 3 | (function(countlyVue, $) { |
4 | 4 |
|
|
157 | 157 | errorMessage: CV.i18n("common.copy-error-message") |
158 | 158 | }; |
159 | 159 | }, |
| 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 | + }, |
160 | 186 | methods: { |
161 | 187 | logout: function() { |
162 | 188 | this.$store.dispatch("countlyCommon/removeActiveApp"); |
|
555 | 581 | } |
556 | 582 | }); |
557 | 583 |
|
| 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 | + |
558 | 613 | var SidebarView = countlyVue.views.create({ |
559 | 614 | template: CV.T('/javascripts/countly/vue/templates/sidebar/sidebar.html'), |
560 | 615 | mixins: [ |
561 | 616 | countlyVue.container.dataMixin({ |
562 | 617 | "externalMainMenuOptions": "/sidebar/menu/main", |
563 | | - "externalOtherMenuOptions": "/sidebar/menu/other" |
| 618 | + "otherMenuOptions": "/sidebar/menu/other", |
| 619 | + "customSidebarComponents": "/sidebar/custom", |
564 | 620 | }) |
565 | 621 | ], |
566 | 622 | components: { |
|
574 | 630 | selectedMenuOptionLocal: null, |
575 | 631 | versionInfo: countlyGlobal.countlyTypeName, |
576 | 632 | countlySidebarVersionPath: '/dashboard#/' + countlyCommon.ACTIVE_APP_ID + '/versions', |
577 | | - showMainMenu: true, |
578 | 633 | redirectHomePage: 'dashboard#/' + countlyCommon.ACTIVE_APP_ID, |
579 | 634 | onOptionsMenu: false, |
580 | 635 | onMainMenu: false, |
|
611 | 666 | }; |
612 | 667 | }, |
613 | 668 | computed: { |
| 669 | + ...Vuex.mapState("countlySidebar", ["showMainMenu"]), |
614 | 670 | components: function() { |
615 | 671 | var menuOptions = []; |
616 | 672 |
|
617 | 673 | var externalMainMenuOptions = this.externalMainMenuOptions; |
618 | | - var externalOtherMenuOptions = this.externalOtherMenuOptions; |
| 674 | + var otherMenuOptions = this.otherMenuOptions; |
619 | 675 |
|
620 | 676 | if (externalMainMenuOptions && externalMainMenuOptions.length) { |
621 | 677 | menuOptions = menuOptions.concat(externalMainMenuOptions); |
622 | 678 | } |
623 | 679 |
|
624 | | - if (externalOtherMenuOptions && externalOtherMenuOptions.length) { |
625 | | - menuOptions = menuOptions.concat(externalOtherMenuOptions); |
| 680 | + if (otherMenuOptions && otherMenuOptions.length) { |
| 681 | + menuOptions = menuOptions.concat(otherMenuOptions); |
626 | 682 | } |
627 | 683 |
|
628 | 684 | return menuOptions; |
|
640 | 696 |
|
641 | 697 | return menuOptions; |
642 | 698 | }, |
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 | | - }, |
703 | 699 | pseudoSelectedMenuOption: function() { |
704 | 700 | var selected = this.$store.getters["countlySidebar/getSelectedMenuItem"]; |
705 | 701 |
|
|
748 | 744 | } |
749 | 745 | }, |
750 | 746 | methods: { |
| 747 | + ...Vuex.mapMutations("countlySidebar", ["toggleMainMenu"]), |
751 | 748 | guidesMouseOver: function() { |
752 | 749 | var state = this.$store.getters["countlySidebar/getGuidesButton"]; |
753 | 750 | if (state !== 'selected' && state !== 'highlighted') { |
|
763 | 760 | onClick: function(option) { |
764 | 761 | if (!option.noSelect) { |
765 | 762 | this.selectedMenuOptionLocal = option.name; |
766 | | - this.showMainMenu = true; |
| 763 | + this.toggleMainMenu(true); |
767 | 764 | this.$store.dispatch("countlySidebar/deselectGuidesButton"); |
768 | 765 | } |
769 | 766 |
|
770 | 767 | if (option.name === "toggle") { |
771 | | - this.onToggleClick(); |
| 768 | + this.toggleMainMenu(); |
772 | 769 | } |
773 | 770 | else if (option.name === "countly-guides") { |
774 | 771 | this.$store.dispatch("countlySidebar/selectGuidesButton"); |
775 | 772 | } |
776 | 773 | }, |
777 | | - onToggleClick: function() { |
778 | | - this.showMainMenu = !this.showMainMenu; |
779 | | - }, |
780 | 774 | identifySelected: function() { |
781 | 775 | for (var ref in this.$refs) { |
782 | 776 | if (Array.isArray(this.$refs[ref])) { |
|
804 | 798 | /** |
805 | 799 | * If the selected menu in vuex is dashboards, the sidebar should be floating. |
806 | 800 | */ |
807 | | - this.showMainMenu = false; |
| 801 | + this.toggleMainMenu(false); |
808 | 802 | } |
809 | 803 | }, |
810 | 804 | onOptionsMenuMouseOver: function() { |
|
813 | 807 | var selectedOption = this.$store.getters["countlySidebar/getSelectedMenuItem"]; |
814 | 808 |
|
815 | 809 | if (selectedOption && selectedOption.menu === "dashboards" && !this.showMainMenu) { |
816 | | - this.showMainMenu = true; |
| 810 | + this.toggleMainMenu(true); |
817 | 811 | } |
818 | 812 | }, |
819 | 813 | onOptionsMenuMouseLeave: function() { |
|
845 | 839 | /** |
846 | 840 | * If not on the main menu, hide the main menu. |
847 | 841 | */ |
848 | | - self.showMainMenu = false; |
| 842 | + self.toggleMainMenu(false); |
849 | 843 | } |
850 | 844 | } |
851 | 845 | }, 0); |
|
877 | 871 | /** |
878 | 872 | * If not on the options menu, hide the main menu. |
879 | 873 | */ |
880 | | - self.showMainMenu = false; |
| 874 | + self.toggleMainMenu(false); |
881 | 875 | } |
882 | 876 | } |
883 | 877 | }, 0); |
|
0 commit comments