-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.vue
211 lines (180 loc) · 4.38 KB
/
App.vue
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
<template>
<div id="appContainer">
<div id="Header">
<h1 id="title">Menelmacar</h1>
<img src="./src/assets/logo.png" alt="Logo" id="logo">
</div>
<div id="chooseModel">
<div id="model_input">
<input type="text" v-model="path" placeholder="Enter the model name" @keydown="clearModel(false)" @keydown.enter="loadModel" @keydown.delete="clearModel(false)" >
<button v-if="!model_loaded" @click="loadModel" id="loadModel">Load model</button>
<button v-if="model_loaded" @click="clearModel(true)" id="clearModel">Clear model</button>
<div id="exampleModels">
<text>Example models:</text>
<button class="exampleModel" @click="path = 'BIOMD0000000982'; loadModel()">BIOMD0000000982</button>
<button class="exampleModel" @click="path = 'BIOMD0000000012'; loadModel()">BIOMD0000000012</button>
</div>
</div>
<!-- Load the model only if its ID is in the public folder -->
<div v-if="model_loaded && file_names.includes(path)" >
<h2 style="font-size: 12pt;">Model: {{ path }}</h2>
</div>
<div v-else-if="no_model">
<h2>No model is loaded</h2>
</div>
<div v-else>
<h2>Model not found</h2>
</div>
</div>
<div id="model_viewer" v-if="model_loaded && file_names.includes(path)">
<ModelViewer :path="path" :key="path"/>
</div>
</div>
</template>
<script>
import { ref } from 'vue'
import ModelViewer from './src/components/ModelViewer.vue';
export default {
name: 'App',
components: {
ModelViewer
},
data() {
return {
file_names: [],
}
},
mounted() {
this.extractFileNames().then(() => {
let url = window.location.href
let model = url.split("id?")[1]
if (model != undefined && model != "") {
model = model.split("/")[0]
this.path = model
this.loadModel()
}
})
},
setup() {
let path = ref("")
let model_loaded = ref(false)
let no_model = ref(true)
return {
path,
model_loaded,
no_model
}
},
methods: {
loadModel() {
if (this.file_names.includes(this.path)) {
window.history.pushState({}, null, window.location.origin + "/id?" + this.path)
this.model_loaded = true
this.no_model = true
}
else {
this.no_model = false
}
},
clearModel(clear_path) {
this.model_loaded = false
if (clear_path) {
this.path = ""
}
window.history.pushState({}, null, window.location.origin + "/")
},
// Open the file containing the names of the models and extract them into a list
async extractFileNames() {
console.log("Extracting file names")
try {
const response = await fetch('./models/file_names.txt');
if (response.ok) {
let fileContent = await response.text();
let file_names = fileContent.split("\n").slice(0, -1)
for (let i = 0; i < file_names.length; i++) {
file_names[i] = file_names[i].split("\r")[0]
}
this.file_names = file_names
} else {
console.error('Failed to load file');
}
} catch (error) {
console.error('Error fetching file:', error);
}
}
},
}
</script>
<style>
#appContainer {
display: flex;
flex-direction: column;
height: 90vh;
box-sizing: border-box;
min-height: 500px;
min-width: 500px;
}
#Header {
display: flex;
align-items: center;
justify-content: center;
}
#logo {
position: absolute;
left: 5px;
top: 5px;
height: 100px;
width: fit-content;
}
#title {
text-align: center;
font-size: 50px;
margin: 0;
}
h1 {
text-align: center;
font-size: 50px;
}
#loadModel {
background-color: lightblue;
border-width: 1px;
height: 20.86px;
}
#loadModel:hover {
background-color: lightcyan;
cursor: pointer;
}
#clearModel {
background-color: lightcoral;
border-width: 1px;
height: 20.86px;
}
#clearModel:hover {
background-color: lightpink;
cursor: pointer;
}
.exampleModel {
margin: 0 2px;
background-color: #f5f5f5;
border: 0;
font-size: 8pt;
}
.exampleModel:hover {
background-color: #e5e5e5;
cursor: pointer;
}
#chooseModel {
display: flex;
align-items: center;
justify-content: center;
}
h2 {
margin-left: 20px;
}
#model_viewer {
width: 100%;
flex-grow: 1;
padding: 0 20px;
box-sizing: border-box;
}
</style>