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

notebook_viewer.vue « notebook « blob « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02f93e142196e3986d6c86de9e678673be31ea95 (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
68
69
70
71
72
73
74
75
76
77
78
79
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import axios from '~/lib/utils/axios_utils';
import notebookLab from '~/notebook/index.vue';

export default {
  components: {
    notebookLab,
    GlLoadingIcon,
  },
  props: {
    endpoint: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      error: false,
      loadError: false,
      loading: true,
      json: {},
    };
  },
  mounted() {
    if (gon.katex_css_url) {
      const katexStyles = document.createElement('link');
      katexStyles.setAttribute('rel', 'stylesheet');
      katexStyles.setAttribute('href', gon.katex_css_url);
      document.head.appendChild(katexStyles);
    }

    if (gon.katex_js_url) {
      const katexScript = document.createElement('script');
      katexScript.addEventListener('load', () => {
        this.loadFile();
      });
      katexScript.setAttribute('src', gon.katex_js_url);
      document.head.appendChild(katexScript);
    } else {
      this.loadFile();
    }
  },
  methods: {
    loadFile() {
      axios
        .get(this.endpoint)
        .then((res) => res.data)
        .then((data) => {
          this.json = data;
          this.loading = false;
        })
        .catch((e) => {
          if (e.status !== 200) {
            this.loadError = true;
          }
          this.error = true;
        });
    },
  },
};
</script>

<template>
  <div class="js-notebook-viewer-mounted container-fluid md gl-mt-3 gl-mb-3">
    <div v-if="loading && !error" class="text-center loading">
      <gl-loading-icon class="mt-5" size="lg" />
    </div>
    <notebook-lab v-if="!loading && !error" :notebook="json" code-css-class="code white" />
    <p v-if="error" class="text-center">
      <span v-if="loadError" ref="loadErrorMessage">{{
        __('An error occurred while loading the file. Please try again later.')
      }}</span>
      <span v-else ref="parsingErrorMessage">{{
        __('An error occurred while parsing the file.')
      }}</span>
    </p>
  </div>
</template>