-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
182 lines (175 loc) · 6.6 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
<!DOCTYPE HTML>
<html xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Course</title>
<meta name="twitter:card" content="summary">
<meta property="og:title" content="Course">
<meta property="og:type" content="website">
<meta name="application-name" content="Course">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/css/bootstrap.min.css"
integrity="sha384-2hfp1SzUoho7/TsGGGDaFdsuuDL0LX2hnUp6VkX3CUQ2K4K+xjboZdsXyp4oUHZj" crossorigin="anonymous">
<style>
th, td {
text-align: center;
white-space: nowrap;
}
td.breakTime {
background: #f0f0f0;
}
</style>
</head>
<body>
<div class="container-fluid text-md-center">
<h1>Course</h1>
<div class="table-responsive">
<div id="courseDiv">
<table class="table table-bordered table-hover" id="courseTable">
<thead class="thead-inverse">
<tr>
<th></th>
<th scope="col" v-for="(weekday, index) in weekdays">
{{ weekday }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="period in 14">
<td scope="row">
{{ period }}<br/>
{{ periodTime(period)}}
</td>
<template v-for="(weekday, index) in weekdays">
<td-course :period="period" :course="findCourse(index, period)"></td-course>
</template>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<template id="td-course">
<td :class="classObject">
<template v-if="course">
<template v-if="course.code">({{ course.code }})</template>
{{ course.course }}<br/>
{{ course.classroom }}<br/>
{{ course.teacher }}
</template>
</td>
</template>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"
integrity="sha384-THPy051/pYDQGanwU6poAc/hOdQxjnOEXzbT+OuUAFqNqFjL+4IGLBgCJC3ZOShY"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.2.0/js/tether.min.js"
integrity="sha384-Plbmg8JY28KFelvJVai01l8WyZzrYWG825m+cZ0eDDS1f7d/js6ikvy1+X+guPIB"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/js/bootstrap.min.js"
integrity="sha384-VjEeINv9OSwtWFLAtmc4JCtEJXXBub00gtSnszmspDLCtC0I4z4nqz7rEFbIZLLU"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/vue/2.0.1/vue.js"></script>
<script src="https://cdn.jsdelivr.net/vue.resource/1.0.1/vue-resource.min.js"></script>
<script>
var type = {
"course": "info",
"meeting": "warning",
"club": "success"
};
var pad = function (str, size) {
var s = String(str);
while (s.length < (size || 2)) {
s = "0" + s;
}
return s;
};
Vue.component('td-course', {
props: ['period', 'course'],
template: '#td-course',
computed: {
isBreakTime: function () {
return this.period == 5 || this.period == 10;
},
classObject: function () {
if (this.course) {
if (this.course.type) {
return ['table-' + this.course.type];
} else {
return [];
}
} else if (this.isBreakTime) {
return ['breakTime'];
}
}
}
});
var vue = new Vue({
el: '#courseDiv',
data: {
course: {},
weekdays: {
0: '星期日',
1: '星期一',
2: '星期二',
3: '星期三',
4: '星期四',
5: '星期五',
6: '星期六'
}
},
mounted: function () {
this.$nextTick(function () {
this.fetchCourse();
});
},
methods: {
fetchCourse: function () {
this.$http.get('./data.json').then(function (response) {
var json = response.data;
var course = {};
//課程類型
$.each(json, function (courseType, courseList) {
//單一類型課程清單
$.each(courseList, function (key, value) {
//單一課程
$.each(value["time"], function (timeKey, timeValue) {
//上課時間
course[timeValue.weekday] = course[timeValue.weekday] !== undefined ? course[timeValue.weekday] : {};
//課程資料
var courseData = {
code: value.code,
course: value.course,
teacher: value.teacher,
classroom: timeValue.classroom,
type: type[courseType]
};
//持續節數
var length = timeValue.length || 1;
for (var i = 0; i < length; i++) {
course[timeValue.weekday][timeValue.period + i] = courseData;
}
});
});
});
this.course = course;
});
},
periodTime: function (period) {
var hour = period - 1 + 8;
return pad(hour, 2) + ':10~' + pad(hour + 1, 2) + ':00';
},
findCourse: function (weekday, period) {
if (this.course && this.course[weekday] && this.course[weekday][period]) {
return this.course[weekday][period];
}
return null;
}
}
});
</script>
</body>
</html>