debian-mirror-gitlab/app/assets/javascripts/blob/notebook/notebook_viewer.vue

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

86 lines
2.1 KiB
Vue
Raw Normal View History

2020-04-08 14:13:33 +05:30
<script>
2020-10-24 23:57:45 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2020-04-08 14:13:33 +05:30
import axios from '~/lib/utils/axios_utils';
2022-10-11 01:57:18 +05:30
import NotebookLab from '~/notebook/index.vue';
2020-04-08 14:13:33 +05:30
export default {
components: {
2022-10-11 01:57:18 +05:30
NotebookLab,
2020-04-08 14:13:33 +05:30
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)
2021-03-08 18:12:59 +05:30
.then((res) => res.data)
.then((data) => {
2020-04-08 14:13:33 +05:30
this.json = data;
this.loading = false;
})
2021-03-08 18:12:59 +05:30
.catch((e) => {
2020-04-08 14:13:33 +05:30
if (e.status !== 200) {
this.loadError = true;
}
this.error = true;
});
},
},
};
</script>
<template>
2020-07-28 23:09:34 +05:30
<div class="js-notebook-viewer-mounted container-fluid md gl-mt-3 gl-mb-3">
2020-04-08 14:13:33 +05:30
<div v-if="loading && !error" class="text-center loading">
<gl-loading-icon class="mt-5" size="lg" />
</div>
2022-10-11 01:57:18 +05:30
<notebook-lab v-if="!loading && !error" :notebook="json" />
2020-04-08 14:13:33 +05:30
<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>
2021-11-11 11:23:49 +05:30
<style>
.output img {
min-width: 0; /* https://www.w3.org/TR/css-flexbox-1/#min-size-auto */
}
</style>