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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-03-13 15:44:24 +05:30
import Vue from 'vue';
2022-04-04 11:22:00 +05:30
import { setCookie, parseBoolean } from '~/lib/utils/common_utils';
2020-03-13 15:44:24 +05:30
import DismissibleAlert from '~/vue_shared/components/dismissible_alert.vue';
2022-01-26 12:08:38 +05:30
const getCookieExpirationPeriod = (expirationPeriod) => {
const defaultExpirationPeriod = 30;
const alertExpirationPeriod = Number(expirationPeriod);
return !expirationPeriod || Number.isNaN(alertExpirationPeriod)
? defaultExpirationPeriod
: alertExpirationPeriod;
};
2021-03-08 18:12:59 +05:30
const mountVueAlert = (el) => {
2020-03-13 15:44:24 +05:30
const props = {
html: el.innerHTML,
};
const attrs = {
...el.dataset,
dismissible: parseBoolean(el.dataset.dismissible),
};
2022-01-26 12:08:38 +05:30
const { dismissCookieName, dismissCookieExpire } = el.dataset;
2020-03-13 15:44:24 +05:30
return new Vue({
el,
2022-01-26 12:08:38 +05:30
render(createElement) {
return createElement(DismissibleAlert, {
props,
attrs,
on: {
alertDismissed() {
if (!dismissCookieName) {
return;
}
2022-04-04 11:22:00 +05:30
setCookie(dismissCookieName, true, {
2022-01-26 12:08:38 +05:30
expires: getCookieExpirationPeriod(dismissCookieExpire),
});
},
},
});
2020-03-13 15:44:24 +05:30
},
});
};
export default () => [...document.querySelectorAll('.js-vue-alert')].map(mountVueAlert);