Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « gitlab_version_check « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b3180c2d1ba06a8edb5cc905b70b8bed166d5543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import Vue from 'vue';
import { parseBoolean } from '~/lib/utils/common_utils';
import GitlabVersionCheckBadge from './components/gitlab_version_check_badge.vue';
import SecurityPatchUpgradeAlert from './components/security_patch_upgrade_alert.vue';

const mountGitlabVersionCheckBadge = (el) => {
  const { size, version } = el.dataset;
  const actionable = parseBoolean(el.dataset.actionable);

  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;
  }
};

const mountSecurityPatchUpgradeAlert = (el) => {
  const { currentVersion } = el.dataset;

  try {
    return new Vue({
      el,
      render(createElement) {
        return createElement(SecurityPatchUpgradeAlert, {
          props: {
            currentVersion,
          },
        });
      },
    });
  } catch {
    return null;
  }
};

export default () => {
  const renderedApps = [];

  const securityPatchUpgradeAlert = document.getElementById('js-security-patch-upgrade-alert');
  const versionCheckBadges = [...document.querySelectorAll('.js-gitlab-version-check-badge')];

  if (securityPatchUpgradeAlert) {
    renderedApps.push(mountSecurityPatchUpgradeAlert(securityPatchUpgradeAlert));
  }

  renderedApps.push(...versionCheckBadges.map((el) => mountGitlabVersionCheckBadge(el)));

  return renderedApps;
};