debian-mirror-gitlab/app/assets/javascripts/gitlab_version_check/index.js

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

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-01-13 00:05:48 +05:30
import Vue from 'vue';
2023-03-04 22:38:38 +05:30
import { parseBoolean, convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
2023-01-13 00:05:48 +05:30
import GitlabVersionCheckBadge from './components/gitlab_version_check_badge.vue';
2023-03-04 22:38:38 +05:30
import SecurityPatchUpgradeAlertModal from './components/security_patch_upgrade_alert_modal.vue';
2023-01-13 00:05:48 +05:30
2023-03-04 22:38:38 +05:30
const mountGitlabVersionCheckBadge = (el) => {
const { size, version } = el.dataset;
2023-01-13 00:05:48 +05:30
const actionable = parseBoolean(el.dataset.actionable);
2023-03-04 22:38:38 +05:30
try {
const { severity } = JSON.parse(version);
// If no severity (status) data don't worry about rendering
if (!severity) {
return null;
}
return new Vue({
el,
render(createElement) {
return createElement(GitlabVersionCheckBadge, {
props: {
size,
actionable,
status: severity,
},
});
},
});
} catch {
return null;
}
2023-01-13 00:05:48 +05:30
};
2023-03-04 22:38:38 +05:30
const mountSecurityPatchUpgradeAlertModal = (el) => {
const { currentVersion, version } = el.dataset;
try {
const { details, latestStableVersions } = convertObjectPropsToCamelCase(JSON.parse(version));
return new Vue({
el,
render(createElement) {
return createElement(SecurityPatchUpgradeAlertModal, {
props: {
currentVersion,
details,
latestStableVersions,
},
});
},
2023-01-13 00:05:48 +05:30
});
2023-03-04 22:38:38 +05:30
} catch {
return null;
}
};
export default () => {
const renderedApps = [];
2023-01-13 00:05:48 +05:30
2023-03-04 22:38:38 +05:30
const securityPatchUpgradeAlertModal = document.getElementById(
'js-security-patch-upgrade-alert-modal',
);
const versionCheckBadges = [...document.querySelectorAll('.js-gitlab-version-check-badge')];
if (securityPatchUpgradeAlertModal) {
renderedApps.push(mountSecurityPatchUpgradeAlertModal(securityPatchUpgradeAlertModal));
}
renderedApps.push(...versionCheckBadges.map((el) => mountGitlabVersionCheckBadge(el)));
return renderedApps;
2023-01-13 00:05:48 +05:30
};