/
index.html
224 lines (215 loc) · 6.01 KB
/
index.html
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.materialdesignicons.com/2.5.94/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify@1.x/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
<style>
body, html {
width: 100%;
height: 100%;
overflow: hidden;
}
#inspire > div > main > div > div {
padding: 0;
}
iframe {
width: 100%;
height: 100%;
border: none;
}
</style>
</head>
<body>
<div id="app">
<v-app id="inspire">
<v-navigation-drawer fixed v-model="drawer" app >
<v-treeview ref="mytreeview" activatable :items="items" :active.sync="active">
<template v-slot:prepend="{item}">
<v-icon v-if="!item.file">
mdi-folder
</v-icon>
<v-icon v-else>
{{ files[item.file] }}
</v-icon>
</template>
<template v-slot:label="{item}">
{{item.name}}
</template>
</v-treeview>
</v-navigation-drawer>
<v-toolbar color="indigo" dark fixed app>
<v-toolbar-side-icon @click.stop="drawer = !drawer"></v-toolbar-side-icon>
<v-toolbar-title> {{title}}</v-toolbar-title>
</v-toolbar>
<v-content>
<v-container fluid fill-height fill-width>
<v-layout justify-center align-center >
<iframe id="theIframe" :key="key" :src="page"></iframe>
</v-layout>
</v-container>
</v-content>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/socket.io-client@2.2.0/dist/socket.io.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify@1.x/dist/vuetify.js"></script>
<script>
let vm = new Vue({
el: '#app',
created: function () {
console.log("preparing socket io");
var self = this;
var socket = io();
socket.on("load-event", function (filename) {
console.log("got the load event: " + filename);
Vue.set(self.active, 0, filename)
//self.key = Date.now();
window.scrollTo(0, document.body.scrollHeight);
location.reload();
});
console.log("loading json items data");
fetch('./data.json')
.then(response => {
return response.json()
})
.then(data => {
// Work with JSON data here
console.log(data)
self.items = data;
})
.catch(err => {
console.log("there was an error reading items json");
})
},
methods: {
isLocalhost: function() {
if( location.hostname === '' ||
location.hostname === 'localhost' ||
location.hostname === '127.0.0.1')
return true;
else
return false;
},
localhostUrl: function() {
let url = null;
if(location.hostname === '') {
url = "";
}
else if(location.hostname === 'localhost') {
url = "http://localhost:3000/"
}
else if(location.hostname === "127.0.0.1") {
url = "http://127.0.0.1:3000/"
}
return url;
},
findItemById: function(id, children){
for(let i=0; i<children.length; i++) {
let item = children[i];
if(item.id === id)
return item;
else {
if(item.hasOwnProperty("children")){
let found = this.findItemById(id, item.children)
if(found)
return found;
}
}
}
return null;
}
},
computed: {
title: function() {
if(this.page === "opensInOtherWindow.html")
return "";
else
return this.page;
},
page: function() {
console.log("updating page !!!");
if(this.active.length ===1) {
console.log("updating url: this.active[0] is: "+this.active[0]);
let id = this.active[0];
console.log("this.active[0] is: " + this.active[0]);
let item = this.findItemById(id, this.items);
let filename = item.name;
const ext = item.file;
//const ext = filename.substring(filename.lastIndexOf('.')+1, filename.length)
console.log("hostname is " + location.hostname);
//Try to determine if we are running in development mode
let productionUrl = "https://calvinw.gitlab.io/mathplosion-rmarkdown/"
if(ext === "docx") {
if(this.isLocalhost()) {
let localhostUrl = this.localhostUrl();
return localhostUrl + filename;
}
else {
let wordViewer = "https://view.officeapps.live.com/op/embed.aspx?src="
return wordViewer + productionUrl + filename;
}
}
else if (ext === "Rmd" ||
ext === "html" ||
ext === "webtex" ||
ext === "pdf" ||
ext === "ipynb")
{
if(this.isLocalhost()) {
let localhostUrl = this.localhostUrl();
return localhostUrl + filename;
}
else {
return productionUrl + filename;
}
}
else if(ext === "colab") {
let baseUrl = "https://colab.research.google.com/github/calvinw/mathplosion-rmarkdown/blob/master/";
let url = baseUrl + item.name + ".ipynb";
window.open(url, "_blank")
return "opensInOtherWindow.html";
}
else if(ext === "jupyter") {
let baseUrl = "https://nbviewer.jupyter.org/github/calvinw/mathplosion-rmarkdown/blob/master/"
let url = baseUrl + item.name + ".ipynb";
window.open(url, "_blank")
return "opensInOtherWindow.html";
}
}
else {
console.log("updating page to null string");
return "";
}
}
},
watch: {
items: function(val) {
// this.$nextTick(() => {
// this.$refs.mytreeview.updateAll(true);
// });
}
},
data: () => ({
ipythonMode: "colab",
drawer: null,
key: null,
active: [],
files: {
html: 'mdi-file-xml',
webtex: 'mdi-file-xml',
Rmd: 'mdi-markdown',
pdf: 'mdi-file-pdf',
ipynb: 'mdi-file',
docx: 'mdi-file-word',
colab: 'mdi-open-in-new',
jupyter: 'mdi-open-in-new',
googledoc: 'mdi-open-in-new'
},
items: []
})
})
</script>
</body>
</html>