diff options
author | Jacob Schatz <jschatz@gitlab.com> | 2017-03-28 19:29:02 +0000 |
---|---|---|
committer | Jacob Schatz <jschatz@gitlab.com> | 2017-03-28 19:29:02 +0000 |
commit | 47aeacd7f5b214d24dcb02bf0a42774415f5083d (patch) | |
tree | 130f356d8177ab6688a5e9236f77cc92887e2867 /app/assets/javascripts/blob | |
parent | 5f6c32e1452cc25d47db9d5e66d3a5b1b453ceb3 (diff) | |
parent | 0f790dbccc506d59feeae2799163e3f00198dee2 (diff) | |
download | gitlab-ce-47aeacd7f5b214d24dcb02bf0a42774415f5083d.tar.gz |
Merge branch 'ipython-notebook-viewer' into 'master'
iPython notebook viewer
See merge request !10017
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r-- | app/assets/javascripts/blob/notebook/index.js | 81 | ||||
-rw-r--r-- | app/assets/javascripts/blob/notebook_viewer.js | 3 |
2 files changed, 84 insertions, 0 deletions
diff --git a/app/assets/javascripts/blob/notebook/index.js b/app/assets/javascripts/blob/notebook/index.js new file mode 100644 index 00000000000..6e07105471c --- /dev/null +++ b/app/assets/javascripts/blob/notebook/index.js @@ -0,0 +1,81 @@ +/* eslint-disable no-new */ +import Vue from 'vue'; +import VueResource from 'vue-resource'; +import NotebookLab from 'vendor/notebooklab'; + +Vue.use(VueResource); +Vue.use(NotebookLab); + +export default () => { + const el = document.getElementById('js-notebook-viewer'); + + new Vue({ + el, + data() { + return { + error: false, + loadError: false, + loading: true, + json: {}, + }; + }, + template: ` + <div class="container-fluid md prepend-top-default append-bottom-default"> + <div + class="text-center loading" + v-if="loading && !error"> + <i + class="fa fa-spinner fa-spin" + aria-hidden="true" + aria-label="iPython notebook loading"> + </i> + </div> + <notebook-lab + v-if="!loading && !error" + :notebook="json" + code-css-class="code white" /> + <p + class="text-center" + v-if="error"> + <span v-if="loadError"> + An error occured whilst loading the file. Please try again later. + </span> + <span v-else> + An error occured whilst parsing the file. + </span> + </p> + </div> + `, + methods: { + loadFile() { + this.$http.get(el.dataset.endpoint) + .then((res) => { + this.json = res.json(); + this.loading = false; + }) + .catch((e) => { + if (e.status) { + this.loadError = true; + } + + this.error = true; + }); + }, + }, + mounted() { + $('<link>', { + rel: 'stylesheet', + type: 'text/css', + href: gon.katex_css_url, + }).appendTo('head'); + + if (gon.katex_js_url) { + $.getScript(gon.katex_js_url, () => { + this.loadFile(); + }); + } else { + this.loadFile(); + } + }, + }); +}; diff --git a/app/assets/javascripts/blob/notebook_viewer.js b/app/assets/javascripts/blob/notebook_viewer.js new file mode 100644 index 00000000000..b7a0a195a92 --- /dev/null +++ b/app/assets/javascripts/blob/notebook_viewer.js @@ -0,0 +1,3 @@ +import renderNotebook from './notebook'; + +document.addEventListener('DOMContentLoaded', renderNotebook); |