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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-03-23 15:37:24 +0300
committerPhil Hughes <me@iamphill.com>2017-03-23 15:37:24 +0300
commit0ef85857268f2622a3c248e39cc359ffc9193849 (patch)
tree3172e81c918a6e96ff7d3c36a12350cf90f41cda /app/assets/javascripts/blob
parente8949a1ee48b5589c1f82d4b8a6b4e20d43d51a3 (diff)
Added tests
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r--app/assets/javascripts/blob/notebook/index.js80
-rw-r--r--app/assets/javascripts/blob/notebook_viewer.js76
2 files changed, 82 insertions, 74 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..c910ed5b76b
--- /dev/null
+++ b/app/assets/javascripts/blob/notebook/index.js
@@ -0,0 +1,80 @@
+/* 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" />
+ <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
index 45b838c700f..b7a0a195a92 100644
--- a/app/assets/javascripts/blob/notebook_viewer.js
+++ b/app/assets/javascripts/blob/notebook_viewer.js
@@ -1,75 +1,3 @@
-import Vue from 'vue';
-import VueResource from 'vue-resource';
-import NotebookLab from 'vendor/notebooklab';
+import renderNotebook from './notebook';
-Vue.use(VueResource);
-Vue.use(NotebookLab);
-
-document.addEventListener('DOMContentLoaded', () => {
- 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" />
- <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');
-
- $.getScript(gon.katex_js_url, () => {
- this.loadFile();
- });
- },
- });
-});
+document.addEventListener('DOMContentLoaded', renderNotebook);