-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_ui_vue.html
341 lines (312 loc) · 15 KB
/
main_ui_vue.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link href='https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css'
rel='stylesheet'>
<!-- Vue 3 -->
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.global.js'></script>
<!-- Vue 3: production version, optimized for size and speed -->
<!-- <script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.global.prod.js'></script> -->
</head>
<body>
<!-- <p>test</p> -->
<div id="app" class="container my-3">
<h1>BOSS Finder</h1>
<div v-if="!isValidStudent">
<div class="row w-50 my-5 mx-auto border border-secondary-subtle p-3">
<p class="fw-bold">Enter your Student ID:
<input type="text" placeholder="Insert StudentID" class="w-75 my-2" v-model="student_id"/>
<button @click="checkStudent()" type="button" class="ms-3 btn btn-sm btn-primary">
Submit
</button>
</p>
<p v-show="hasError">{{ message }}</p>
</div>
</div>
<div v-else>
<div class="row">
<div class="col align-middle">
<button @click="displayAll()" type="button" class="btn btn-sm btn-primary" v-show="!isSearching">
Display All Jobs
</button>
<button @click="matchJobs()" type="button" class="ms-3 btn btn-sm btn-primary" v-show="!isSearching">
Search for Matching Jobs
</button>
<button @click="logOut()" type="button" class="ms-3 btn btn-sm btn-secondary" v-show="!isSearching">
Log out
</button>
<button type="button" class="btn btn-sm btn-primary" disabled v-show="isSearching">
Searching
</button><br>
</div>
</div>
<div class="row" v-if="!hasSearched && !isSearching && !hasError">
<div class="row mt-3">
<job-component
:role="job['job_role']"
:company="job['job_company']"
:description="job['job_description']"
:link="temp_link"
:id="job['job_id']"
@apply ="applyJobs"
v-for="job in jobs"
>
</job-component>
</div>
</div>
<div class="row mt-3" v-else-if="isSearching && !hasError">
<div class="card w-100 p-2 my-2" aria-hidden="true">
<div class="card-body">
<h5 class="card-title placeholder-glow">
<span class="placeholder col-6"></span>
</h5>
<p class="card-text placeholder-glow">
<span class="placeholder col-7"></span>
<span class="placeholder col-4"></span>
<span class="placeholder col-4"></span>
</p>
<a class="btn btn-primary disabled placeholder col-6"></a>
</div>
</div>
<div class="card w-100 p-2 my-2" aria-hidden="true">
<div class="card-body">
<h5 class="card-title placeholder-glow">
<span class="placeholder col-6"></span>
</h5>
<p class="card-text placeholder-glow">
<span class="placeholder col-7"></span>
<span class="placeholder col-4"></span>
<span class="placeholder col-4"></span>
</p>
<a class="btn btn-primary disabled placeholder col-6"></a>
</div>
</div>
<div class="card w-100 p-2 my-2" aria-hidden="true">
<div class="card-body">
<h5 class="card-title placeholder-glow">
<span class="placeholder col-6"></span>
</h5>
<p class="card-text placeholder-glow">
<span class="placeholder col-7"></span>
<span class="placeholder col-4"></span>
<span class="placeholder col-4"></span>
</p>
<a class="btn btn-primary disabled placeholder col-6"></a>
</div>
</div>
</div>
<div class="row w-50 my-5 mx-auto border border-secondary-subtle p-3" v-else-if="hasError">
<h4 class="text-danger fw-bold">Error:</h4>
<p class="text-center col">{{ message }}</p>
</div>
<div class="row" v-else>
<h4 class="mt-3">Search Results</h4>
<div class="row mt-1">
<job-component
:role="job['job_role']"
:company="job['job_company']"
:description="job['job_description']"
:link="temp_link"
:id="job['job_id']"
@apply="applyJobs"
v-for="job in matched_jobs"
>
</job-component>
</div>
</div>
</div>
</div>
<script>
const match_job_URL = "http://localhost:5005";
const job_URL = "http://localhost:5002";
const apply_job_URL = "http://localhost:5006"
student_id = sessionStorage.getItem("apply_studentID")
isValidStudent = sessionStorage.getItem("isValidStudent")
console.log(student_id)
const app = Vue.createApp({
data() {
return {
student_id: student_id,
job_id: "",
jobs: [],
matched_jobs: [],
courses: [],
modules: [],
lack_skills: [],
temp_link: 'https://google.com',
hasSearched: false,
isSearching: false,
hasError: false,
hasproceed: false,
uploadText: false,
isValidStudent: isValidStudent,
message: "There is a problem retrieving data, please try again later.",
};
},
methods: {
getAllJobs () {
// on Vue instance created, load the book list
const response =
fetch(job_URL + '/jobs')
.then(response => response.json())
.then(data => {
console.log(data);
if (data.code !== 200) {
// no job in db
this.message = data.message;
} else {
this.jobs = data.data;
console.log(this.jobs)
}
})
.catch(error => {
// Errors when calling the service; such as network error,
// service offline, etc
console.log(this.message + error);
});
},
matchJobs () {
console.log(this.student_id);
this.isSearching = true
this.hasError = false
const response =
fetch(`${match_job_URL}/match/${this.student_id}`)
.then(response => response.json())
.then(data => {
console.log(data);
if (data.code !== 200) {
// no book in db
this.message = data.message;
this.matched_jobs = [];
this.hasError = true
} else {
this.matched_jobs = data.data;
this.hasSearched = true;
console.log(data.data)
this.hasError = false
}
this.isSearching = false
})
.catch(error => {
// Errors when calling the service; such as network error,
// service offline, etc
console.log(this.message + error);
this.hasError = true
this.isSearching = false
});
},
applyJobs(id) {
// console.log(this.jobs)
// console.log(this.job_id)
this.job_id = id
console.log(this.job_id)
const response =
fetch(`${apply_job_URL}/apply/${this.student_id}/${this.job_id}`)
.then(response => response.json())
.then(data => {
console.log(data);
if (data.code !== 200) {
this.message = data.message;
this.hasError = true
}
else{
this.isSuitable = data.message
}
if (this.isSuitable) {
// is suitable
this.hasproceed = true
}
else {
// is not suitable
this.lack_skills = data.data.lack_skills
this.courses = data.data.courses
this.modules = data.data.modules
}
sessionStorage.setItem("apply_studentID", this.student_id);
sessionStorage.setItem("apply_jobID", this.job_id);
sessionStorage.setItem("apply_courses", JSON.stringify(this.courses));
sessionStorage.setItem("apply_lack_skills", this.lack_skills);
sessionStorage.setItem("apply_modules", JSON.stringify(this.modules));
sessionStorage.setItem('isValidStudent', this.isValidStudent)
location.replace("./apply_ui_vue.html")
})
.catch(error => {
// Errors when calling the service; such as network error,
// service offline, etc
console.log(this.message + error);
this.hasError = true
});
},
checkStudent() {
const response =
fetch(`${match_job_URL}/${this.student_id}`)
.then(response => response.json())
.then(data => {
console.log(data);
if (data.code !== 200) {
this.message = data.message;
this.isValidStudent = false
this.hasError = true
} else {
this.matched_jobs = data.data;
this.hasError = false
this.isValidStudent = true
}
sessionStorage.setItem("apply_studentID", this.student_id);
sessionStorage.setItem("isValidStudent", this.isValidStudent);
})
.catch(error => {
// Errors when calling the service; such as network error,
// service offline, etc
console.log(this.message + error);
this.hasError = true
})
},
logOut() {
this.isValidStudent = false
this.hasError = false
sessionStorage.clear()
},
displayAll() {
this.hasSearched = false
this.hasError = false
}
},
created () {
// on Vue instance created, load the job list
this.getAllJobs();
},
});
app.component('job-component', {
props: [ 'role', 'company', 'description', 'link', 'id' ],
emits: [ 'apply' ],
template: `
<div class="card w-100 p-2 my-2">
<div class="card-body">
<div class="row">
<div class="col-10">
<h5 class="card-title">{{ role }}</h5>
<h6 class="card-subtitle mb-2 text-body-secondary">{{ company }}</h6>
<p class="card-text">{{ description }}</p>
<a :href="link" class="card-link">Visit Company Page</a>
</div>
<div class="col">
<button type="button" class="btn btn-primary" @click="$emit('apply', id)">Apply</button>
<p display="none">{{ id }}</p>
</div>
</div>
</div>
</div>
`
})
const vm = app.mount('#app');
</script>
<!-- Bootstrap Javascript -->
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js'></script>
</body>
</html>