debian-mirror-gitlab/app/assets/javascripts/header.js

105 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2018-12-05 23:21:45 +05:30
import Vue from 'vue';
import Translate from '~/vue_shared/translate';
2018-03-17 18:26:18 +05:30
import { highCountTrim } from '~/lib/utils/text_utility';
2018-12-05 23:21:45 +05:30
import SetStatusModalTrigger from './set_status_modal/set_status_modal_trigger.vue';
import SetStatusModalWrapper from './set_status_modal/set_status_modal_wrapper.vue';
2019-02-15 15:39:39 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
2020-04-22 19:07:51 +05:30
import Tracking from '~/tracking';
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
/**
* Updates todo counter when todos are toggled.
* When count is 0, we hide the badge.
*
* @param {jQuery.Event} e
* @param {String} count
*/
export default function initTodoToggle() {
$(document).on('todo:toggle', (e, count) => {
const $todoPendingCount = $('.todos-count');
2019-12-21 20:55:43 +05:30
$todoPendingCount.text(highCountTrim(count));
$todoPendingCount.toggleClass('hidden', count === 0);
2018-03-17 18:26:18 +05:30
});
}
2018-12-05 23:21:45 +05:30
2019-03-02 22:35:43 +05:30
function initStatusTriggers() {
2018-12-05 23:21:45 +05:30
const setStatusModalTriggerEl = document.querySelector('.js-set-status-modal-trigger');
const setStatusModalWrapperEl = document.querySelector('.js-set-status-modal-wrapper');
if (setStatusModalTriggerEl || setStatusModalWrapperEl) {
Vue.use(Translate);
// eslint-disable-next-line no-new
new Vue({
el: setStatusModalTriggerEl,
data() {
const { hasStatus } = this.$options.el.dataset;
return {
2019-02-15 15:39:39 +05:30
hasStatus: parseBoolean(hasStatus),
2018-12-05 23:21:45 +05:30
};
},
render(createElement) {
return createElement(SetStatusModalTrigger, {
props: {
hasStatus: this.hasStatus,
},
});
},
});
// eslint-disable-next-line no-new
new Vue({
el: setStatusModalWrapperEl,
data() {
const { currentEmoji, currentMessage } = this.$options.el.dataset;
return {
currentEmoji,
currentMessage,
};
},
render(createElement) {
const { currentEmoji, currentMessage } = this;
return createElement(SetStatusModalWrapper, {
props: {
currentEmoji,
currentMessage,
},
});
},
});
}
2019-03-02 22:35:43 +05:30
}
2020-05-24 23:13:21 +05:30
function trackShowUserDropdownLink(trackEvent, elToTrack, el) {
const { trackLabel, trackProperty } = elToTrack.dataset;
$(el).on('shown.bs.dropdown', () => {
Tracking.event(document.body.dataset.page, trackEvent, {
label: trackLabel,
property: trackProperty,
});
});
}
2020-04-22 19:07:51 +05:30
export function initNavUserDropdownTracking() {
const el = document.querySelector('.js-nav-user-dropdown');
const buyEl = document.querySelector('.js-buy-ci-minutes-link');
2020-05-24 23:13:21 +05:30
const upgradeEl = document.querySelector('.js-upgrade-plan-link');
2020-04-22 19:07:51 +05:30
if (el && buyEl) {
2020-05-24 23:13:21 +05:30
trackShowUserDropdownLink('show_buy_ci_minutes', buyEl, el);
}
2020-04-22 19:07:51 +05:30
2020-05-24 23:13:21 +05:30
if (el && upgradeEl) {
trackShowUserDropdownLink('show_upgrade_link', upgradeEl, el);
2020-04-22 19:07:51 +05:30
}
}
2019-03-02 22:35:43 +05:30
document.addEventListener('DOMContentLoaded', () => {
requestIdleCallback(initStatusTriggers);
2020-04-22 19:07:51 +05:30
initNavUserDropdownTracking();
2018-12-05 23:21:45 +05:30
});