generated from edrys-org/module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
231 lines (198 loc) · 10.1 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
225
226
227
228
229
230
231
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Automaticaly assigns students to stations" />
<meta name="show-in" content="station" />
<title>Auto Assign</title>
<script src="https://edrys-org.github.io/edrys/module/edrys.js"></script>
<script defer src="https://edrys-org.github.io/edrys/module/vendor/alpine.min.js"></script>
<link rel="stylesheet" href="https://edrys-org.github.io/edrys/module/vendor/water.min.css" />
<link rel="stylesheet" href="https://edrys-org.github.io/edrys/module/vendor/open-iconic/css/open-iconic.min.css" />
</head>
<body>
<template x-if="!!edrys" x-data="{ edrys: undefined, candidates: [] }" x-init="Edrys.onUpdate((e) => {
edrys = {...e}
candidates = Object.entries(edrys.liveClass.users)
.map(([name, user]) => ({ name, ...user}))
.filter(u => u.room == 'Lobby' && u.role == 'student')
.sort((a,b) => {
if (a.dateJoined > b.dateJoined) return 1
if (a.dateJoined < b.dateJoined) return -1
return 0
})
})">
<div>
<h1>Auto Assign</h1>
<hr />
<form x-data="{ state: { running: false, duration: 5, count: 1, strategy: 'roundrobin', lastAssignment: 0 },
interval: {}, timeSinceLastAssignment: 0, onStateUpdate: ()=>{} }"
x-init="() => { Edrys.onReady(() => {
onStateUpdate = (s) => {
state = s
function assign() {
state.lastAssignment = new Date().getTime()
Edrys.setItem('state', JSON.stringify(s))
edrys.sendMessage('response:state', JSON.stringify(s))
// Remove existing students, if there are more candidates to consider
if (candidates.length)
Object.entries(edrys.liveClass.users)
.filter(([name, user]) => user.room == edrys.liveUser.room && user.role == 'student')
.forEach(([name, user]) => {
candidates.push({ name, ...user})
edrys.liveClass.users[name].room = 'Lobby'
})
// Move next candidate(s) into station
for (let i = 0; i < state.count && i < candidates.length; i++) {
edrys.liveClass.users[candidates[i].name].room = edrys.liveUser.room
}
}
if (s.running)
{
assign()
interval = setInterval(() => {
assign()
}, s.duration * 60 * 1000 )
}
else
{
clearInterval(interval)
}
edrys.sendMessage('response:state', JSON.stringify(state))
}
setInterval(() => {
const ms = (state.lastAssignment + (state.duration * 60 * 1000)) - new Date().getTime()
const s = Math.floor(ms / 1000)
const mm = Math.floor(s / 60)
const ss = s - (mm * 60)
timeSinceLastAssignment = `${mm}:${ss}`
}, 1000)
// If station load settings from localstorage,
// else if not station load by request-broadcast
if (edrys.role == 'station')
{
try {
state = { ...state, ...JSON.parse(Edrys.getItem('state'))}
} catch (error) {}
state.lastAssignment = 0
onStateUpdate(state)
edrys.onMessage((m) => {
if (m.subject == 'request:state')
{
if (m.body == '')
{
// Read
edrys.sendMessage('response:state', JSON.stringify(state))
}
else
{
// Write (only teachers can)
if (Object.entries(edrys.liveClass.users).find(([name, user]) => name == m.from && user.role == 'teacher'))
onStateUpdate(JSON.parse(m.body))
}
}
})
}
else
{
edrys.sendMessage('request:state', '')
edrys.onMessage((m) => {
if (m.subject == 'response:state')
{
state = JSON.parse(m.body)
}
})
}
})}" x-on:submit.prevent="() => {
state.running = !state.running
if (edrys.role == 'station')
{
onStateUpdate(state)
}
else
{
edrys.sendMessage('request:state', JSON.stringify(state))
}
}">
<template x-if="edrys.role != 'student'">
<div>
<label for="commands">Duration per student (mins):</label>
<input id="duration" type="number" required minlength="1"
placeholder="Duration per student (mins)" min="1" step="1" x-model="state.duration"
:disabled="state.running" />
<label for="commands">Max number of students to assign to this station at the same time:</label>
<input id="count" type="number" required minlength="1" placeholder="Students per station"
min="1" step="1" x-model="state.count" :disabled="state.running" />
<label for="strategy">Assignment strategy:</label>
<select name="strategy" id="strategy" x-model="state.strategy" :disabled="state.running">
<option value="roundrobin">Longest wait first</option>
<option value="alphabetic" disabled>Alphabetic Round Robin</option>
<option value="random" disabled>Random</option>
</select>
<button type="submit">
<template x-if="!state.running">
<span>
<span class="oi" data-glyph="media-play" aria-hidden="true"></span>
Start Auto-Assign for this station
</span>
</template>
<template x-if="state.running">
<span>
<span class="oi" data-glyph="media-stop" aria-hidden="true"></span>
Stop Auto-Assign for this station
</span>
</template>
</button>
<hr />
</div>
</template>
<template x-if="edrys.role == 'student'">
<div>
<template x-if="state.running">
<span>
Auto-Assign is running on this station...
</span>
</template>
<template x-if="!state.running">
<span>
Auto-Assign is currently disabled in this station.
</span>
</template>
</div>
</template>
<div x-show="state.running" x-transition>
<br />
<span class="oi" data-glyph="clock" aria-hidden="true"></span>
Time to next assignment:
<span x-text="timeSinceLastAssignment"></span> mins
<br />
<br />
<template x-if="candidates.length">
<div>
<span class="oi" data-glyph="people" aria-hidden="true"></span>
Students next to be assigned:
<ol>
<template x-for="u in candidates">
<li>
<span x-text="u.displayName"></span>
</li>
</template>
</ol>
</div>
</template>
<template x-if="!candidates.length">
<div>
<span class="oi" data-glyph="people" aria-hidden="true"></span>
No more students waiting in the Lobby...
</div>
</template>
<br />
<br />
</div>
</form>
</div>
</template>
</body>
</html>