2017-03-16 13:04:58 -04:00
|
|
|
import Vue from 'vue';
|
2017-03-17 13:00:55 -04:00
|
|
|
import VueResource from 'vue-resource';
|
2017-03-16 13:04:58 -04:00
|
|
|
import NotebookLab from 'vendor/notebooklab';
|
|
|
|
|
2017-03-17 13:00:55 -04:00
|
|
|
Vue.use(VueResource);
|
2017-03-16 13:04:58 -04:00
|
|
|
Vue.use(NotebookLab);
|
|
|
|
|
2017-03-22 10:08:51 -04:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2017-03-17 13:00:55 -04:00
|
|
|
const el = document.getElementById('js-notebook-viewer');
|
|
|
|
|
2017-03-16 13:04:58 -04:00
|
|
|
new Vue({
|
2017-03-17 13:00:55 -04:00
|
|
|
el,
|
2017-03-16 13:04:58 -04:00
|
|
|
data() {
|
|
|
|
return {
|
2017-03-20 10:44:07 -04:00
|
|
|
error: false,
|
2017-03-22 10:08:51 -04:00
|
|
|
loadError: false,
|
2017-03-17 13:00:55 -04:00
|
|
|
loading: true,
|
2017-03-16 13:04:58 -04:00
|
|
|
json: {},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
template: `
|
2017-03-22 10:08:51 -04:00
|
|
|
<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>
|
2017-03-17 13:00:55 -04:00
|
|
|
<notebook-lab
|
2017-03-22 10:08:51 -04:00
|
|
|
v-if="!loading && !error"
|
2017-03-17 13:00:55 -04:00
|
|
|
:notebook="json" />
|
2017-03-22 10:08:51 -04:00
|
|
|
<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>
|
2017-03-16 13:04:58 -04:00
|
|
|
</div>
|
|
|
|
`,
|
2017-03-22 10:08:51 -04:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2017-03-17 13:00:55 -04:00
|
|
|
mounted() {
|
2017-03-20 10:44:07 -04:00
|
|
|
$('<link>', {
|
|
|
|
rel: 'stylesheet',
|
|
|
|
type: 'text/css',
|
|
|
|
href: gon.katex_css_url,
|
|
|
|
}).appendTo('head');
|
2017-03-17 13:00:55 -04:00
|
|
|
|
|
|
|
$.getScript(gon.katex_js_url, () => {
|
2017-03-22 10:08:51 -04:00
|
|
|
this.loadFile();
|
2017-03-17 13:00:55 -04:00
|
|
|
});
|
|
|
|
},
|
2017-03-16 13:04:58 -04:00
|
|
|
});
|
|
|
|
});
|