2023-03-22 16:42:54 +08:00
|
|
|
<template>
|
|
|
|
<div class="sci--navigation--top-menu-container">
|
2023-06-15 08:59:34 +08:00
|
|
|
<div v-if="user" class="sci--navigation--top-menu-search left-icon sci-input-container-v2" :class="{'disabled' : !currentTeam}" :title="i18n.t('nav.search')">
|
2023-06-13 18:38:55 +08:00
|
|
|
<input type="text" :placeholder="i18n.t('nav.search')" @change="searchValue"/>
|
|
|
|
<i class="sn-icon sn-icon-search"></i>
|
|
|
|
</div>
|
2023-08-03 21:14:44 +08:00
|
|
|
<div v-if="currentTeam" class="w-64">
|
2023-06-13 17:51:00 +08:00
|
|
|
<Select
|
|
|
|
:value="currentTeam"
|
2023-03-22 16:42:54 +08:00
|
|
|
:options="teams"
|
2023-06-13 17:51:00 +08:00
|
|
|
:placeholder="'test'"
|
|
|
|
:noOptionsPlaceholder="'test'"
|
|
|
|
v-bind:disabled="false"
|
|
|
|
@change="switchTeam"
|
|
|
|
></Select>
|
2023-03-22 16:42:54 +08:00
|
|
|
</div>
|
2023-09-22 17:59:39 +08:00
|
|
|
<MenuDropdown
|
|
|
|
class="ml-auto"
|
2023-10-02 20:31:28 +08:00
|
|
|
v-if="settingsMenu && settingsMenu.length > 0"
|
|
|
|
:listItems="settingsMenuItems"
|
2023-10-16 15:52:06 +08:00
|
|
|
:title="i18n.t('nav.settings')"
|
2023-09-22 17:59:39 +08:00
|
|
|
:btnClasses="'btn btn-light icon-btn btn-black'"
|
|
|
|
:position="'right'"
|
|
|
|
:btnIcon="'sn-icon sn-icon-settings'"
|
|
|
|
></MenuDropdown>
|
2023-06-22 17:55:23 +08:00
|
|
|
<div v-if="user" class="sci--navigation--notificaitons-flyout-container" >
|
2023-06-14 20:40:26 +08:00
|
|
|
<button class="btn btn-light icon-btn btn-black"
|
2023-06-22 17:55:23 +08:00
|
|
|
:title="i18n.t('nav.notifications.title')"
|
2023-04-12 17:14:53 +08:00
|
|
|
:class="{ 'has-unseen': unseenNotificationsCount > 0 }"
|
|
|
|
:data-unseen="unseenNotificationsCount"
|
|
|
|
data-toggle="dropdown"
|
|
|
|
@click="notificationsOpened = !notificationsOpened">
|
2023-06-08 14:33:37 +08:00
|
|
|
<i class="sn-icon sn-icon-notifications"></i>
|
2023-03-24 17:42:37 +08:00
|
|
|
</button>
|
2023-04-13 20:54:03 +08:00
|
|
|
<div v-if="notificationsOpened" class="sci--navigation--notificaitons-flyout-backdrop" @click="notificationsOpened = false"></div>
|
2023-04-12 17:14:53 +08:00
|
|
|
<NotificationsFlyout
|
|
|
|
v-if="notificationsOpened"
|
|
|
|
:notificationsUrl="notificationsUrl"
|
|
|
|
:unseenNotificationsCount="unseenNotificationsCount"
|
2023-04-17 21:23:52 +08:00
|
|
|
@update:unseenNotificationsCount="checkUnseenNotifications()"
|
2023-04-12 17:14:53 +08:00
|
|
|
@close="notificationsOpened = false" />
|
2023-03-24 17:42:37 +08:00
|
|
|
</div>
|
2023-06-15 08:59:34 +08:00
|
|
|
<div v-if="user" class="dropdown" :title="i18n.t('nav.user_profile')">
|
2023-06-14 20:40:26 +08:00
|
|
|
<div class="sci--navigation--top-menu-user btn btn-light icon-btn btn-black" data-toggle="dropdown">
|
2023-06-13 18:38:55 +08:00
|
|
|
<img class="avatar w-6 h-6" :src="user.avatar_url">
|
2023-03-22 16:42:54 +08:00
|
|
|
</div>
|
2023-09-22 17:59:39 +08:00
|
|
|
<div class="dropdown-menu dropdown-menu-right rounded !p-2.5 sn-shadow-menu-sm">
|
2023-05-08 20:44:50 +08:00
|
|
|
<li v-for="(item, i) in userMenu" :key="i">
|
2023-09-22 17:59:39 +08:00
|
|
|
<a :href="item.url" class="!px-3 !py-2.5 rounded hover:!bg-sn-super-light-grey !text-sn-blue block">
|
2023-03-22 16:42:54 +08:00
|
|
|
{{ item.name }}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
2023-09-22 17:59:39 +08:00
|
|
|
<a rel="nofollow" data-method="delete" :href="user.sign_out_url" class="!px-3 !py-2.5 rounded hover:!bg-sn-super-light-grey !text-sn-blue block">
|
2023-03-22 16:42:54 +08:00
|
|
|
{{ i18n.t('nav.user.logout') }}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-09-22 17:59:39 +08:00
|
|
|
import NotificationsFlyout from './notifications/notifications_flyout.vue';
|
|
|
|
import DropdownSelector from '../shared/dropdown_selector.vue';
|
2023-06-13 17:51:00 +08:00
|
|
|
import Select from "../shared/select.vue";
|
2023-09-22 17:59:39 +08:00
|
|
|
import MenuDropdown from '../shared/menu_dropdown.vue';
|
2023-03-22 16:42:54 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'TopMenuContainer',
|
|
|
|
components: {
|
2023-03-24 17:42:37 +08:00
|
|
|
DropdownSelector,
|
2023-06-13 17:51:00 +08:00
|
|
|
NotificationsFlyout,
|
2023-09-22 17:59:39 +08:00
|
|
|
Select,
|
|
|
|
MenuDropdown
|
2023-03-22 16:42:54 +08:00
|
|
|
},
|
|
|
|
props: {
|
2023-04-06 20:57:00 +08:00
|
|
|
url: String,
|
2023-04-12 17:14:53 +08:00
|
|
|
notificationsUrl: String,
|
|
|
|
unseenNotificationsUrl: String
|
2023-03-22 16:42:54 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
rootUrl: null,
|
2023-06-13 17:51:00 +08:00
|
|
|
teamSwitchUrl: null,
|
2023-05-09 21:21:07 +08:00
|
|
|
currentTeam: null,
|
2023-03-22 16:42:54 +08:00
|
|
|
teams: null,
|
|
|
|
searchUrl: null,
|
|
|
|
user: null,
|
|
|
|
helpMenu: null,
|
|
|
|
settingsMenu: null,
|
|
|
|
userMenu: null,
|
2023-04-12 17:14:53 +08:00
|
|
|
notificationsOpened: false,
|
|
|
|
unseenNotificationsCount: 0
|
2023-03-22 16:42:54 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
2023-05-09 21:21:07 +08:00
|
|
|
this.fetchData();
|
2023-04-12 17:14:53 +08:00
|
|
|
this.checkUnseenNotifications();
|
|
|
|
|
|
|
|
$(document).on('turbolinks:load', () => {
|
|
|
|
this.notificationsOpened = false;
|
|
|
|
this.checkUnseenNotifications();
|
2023-04-21 18:25:42 +08:00
|
|
|
this.refreshCurrentTeam();
|
2023-04-12 17:14:53 +08:00
|
|
|
})
|
2023-05-09 21:21:07 +08:00
|
|
|
|
|
|
|
// Track name update in user profile settings
|
|
|
|
$(document).on('inlineEditing::updated', '.inline-editing-container[data-field-to-update="full_name"]', this.fetchData);
|
2023-03-22 16:42:54 +08:00
|
|
|
},
|
2023-11-09 02:32:43 +08:00
|
|
|
beforeUnmount: function(){
|
2023-07-11 22:05:34 +08:00
|
|
|
clearTimeout(this.unseenNotificationsTimeout);
|
|
|
|
},
|
2023-10-02 20:31:28 +08:00
|
|
|
computed: {
|
|
|
|
settingsMenuItems() {
|
|
|
|
return this.settingsMenu.map((item) => {
|
|
|
|
return { text: item.name, url: item.url } }
|
|
|
|
).concat(
|
|
|
|
{
|
|
|
|
text: this.i18n.t('left_menu_bar.support_links.core_version'),
|
|
|
|
modalTarget: '#aboutModal', url: ''
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
2023-11-24 22:32:32 +08:00
|
|
|
watch: {
|
|
|
|
notificationsOpened(newVal) {
|
|
|
|
if (newVal === true) {
|
|
|
|
document.body.style.overflow = 'hidden';
|
|
|
|
} else if (newVal === false) {
|
|
|
|
document.body.style.overflow = 'scroll';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-03-22 16:42:54 +08:00
|
|
|
methods: {
|
2023-05-09 21:21:07 +08:00
|
|
|
fetchData() {
|
|
|
|
$.get(this.url, (result) => {
|
|
|
|
this.rootUrl = result.root_url;
|
2023-06-13 17:51:00 +08:00
|
|
|
this.teamSwitchUrl = result.team_switch_url;
|
2023-05-09 21:21:07 +08:00
|
|
|
this.currentTeam = result.current_team;
|
|
|
|
this.teams = result.teams;
|
|
|
|
this.searchUrl = result.search_url;
|
|
|
|
this.helpMenu = result.help_menu;
|
|
|
|
this.settingsMenu = result.settings_menu;
|
|
|
|
this.userMenu = result.user_menu;
|
|
|
|
this.user = result.user;
|
|
|
|
})
|
|
|
|
},
|
2023-03-22 16:42:54 +08:00
|
|
|
switchTeam(team) {
|
2023-05-09 21:21:07 +08:00
|
|
|
if (this.currentTeam == team) return;
|
2023-03-22 16:42:54 +08:00
|
|
|
|
2023-06-13 17:51:00 +08:00
|
|
|
let newTeam = this.teams.find(e => e[0] == team);
|
2023-04-21 18:25:42 +08:00
|
|
|
|
|
|
|
if (!newTeam) return;
|
|
|
|
|
2023-06-13 17:51:00 +08:00
|
|
|
$.post(this.teamSwitchUrl, {team_id: team}, (result) => {
|
2023-06-16 18:38:09 +08:00
|
|
|
this.currentTeam = result.current_team
|
2023-05-09 21:21:07 +08:00
|
|
|
dropdownSelector.selectValues('#sciNavigationTeamSelector', this.currentTeam);
|
2023-04-21 18:25:42 +08:00
|
|
|
$('body').attr('data-current-team-id', this.currentTeam);
|
2023-03-22 16:42:54 +08:00
|
|
|
window.open(this.rootUrl, '_self')
|
2023-08-09 16:33:58 +08:00
|
|
|
}).fail((msg) => {
|
2023-03-22 16:42:54 +08:00
|
|
|
HelperModule.flashAlertMsg(msg.responseJSON.message, 'danger');
|
|
|
|
});
|
|
|
|
},
|
2023-04-12 17:14:53 +08:00
|
|
|
searchValue(e) {
|
2023-03-22 16:42:54 +08:00
|
|
|
window.open(`${this.searchUrl}?q=${e.target.value}`, '_self')
|
2023-04-12 17:14:53 +08:00
|
|
|
},
|
|
|
|
checkUnseenNotifications() {
|
2023-07-11 22:05:34 +08:00
|
|
|
clearTimeout(this.unseenNotificationsTimeout);
|
2023-04-12 17:14:53 +08:00
|
|
|
$.get(this.unseenNotificationsUrl, (result) => {
|
|
|
|
this.unseenNotificationsCount = result.unseen;
|
2023-07-11 22:05:34 +08:00
|
|
|
this.unseenNotificationsTimeout = setTimeout(this.checkUnseenNotifications, 30000);
|
2023-04-12 17:14:53 +08:00
|
|
|
})
|
2023-04-21 18:25:42 +08:00
|
|
|
},
|
|
|
|
refreshCurrentTeam() {
|
|
|
|
let newTeam = parseInt($('body').attr('data-current-team-id'));
|
|
|
|
if (newTeam !== this.currentTeam) {
|
|
|
|
this.currentTeam = newTeam;
|
|
|
|
dropdownSelector.selectValues('#sciNavigationTeamSelector', this.currentTeam);
|
|
|
|
}
|
2023-03-22 16:42:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|