aboutsummaryrefslogtreecommitdiffstats
path: root/templates/staff/jams/teams/view.html
blob: 909c4c94fc84d02cd563eff14aba5ddf8dd5413b (plain) (blame)
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
{% extends "main/base.html" %}
{% block title %}Staff | Jams | Teams{% endblock %}
{% block og_title %}Staff | Jams | Teams{% endblock %}
{% block og_description %}Manage Teams{% endblock %}
{% block content %}
    <div class="uk-flex">
        <div class="uk-flex-column uk-padding-small uk-background-muted" id="member-answers-sidebar">
            <h3 class="uk-text-center" id="user-info-hint">Hover a user to show their information here</h3>

            <div id="visible-user-info">

            </div>
            <div id="hidden-user-info" hidden>
                {% for participant in jam.participants %}
                    <div class="user-info" id="user-info-{{ participant.user_id }}">
                        <img src="{{ participant.avatar }}" class="uk-border-circle avatar" />
                        <div class="uk-text-center">
                            <strong>{{ participant.username }}#{{ participant.discriminator }}</strong>
                        </div>
                        <div class="uk-text-center">
                            <span class="uk-text-muted">{{ participant.user_id }}</span>
                        </div>
                        <div class="uk-text-center">
                            <i class="uk-icon far fa-fw fa-clock"></i> {{ participant.profile.timezone }} |
                            <a href="https://gitlab.com/{{ participant.profile.gitlab_username }}">
                                <i class="uk-icon fab fa-fw fa-gitlab"></i> {{ participant.profile.gitlab_username }}
                            </a>
                        </div>
                        <hr class="uk-divider-icon" />

                        {% for answer in participant.answers %}
                            <strong>{{ questions[answer.question].title }}</strong>
                            <br/>
                            <span class="fira-code">{{ answer.value }}</span>
                            <br/>
                            <br/>
                        {% endfor %}
                    </div>
                {% endfor %}
            </div>
        </div>
        <div class="uk-section uk-flex-column uk-flex-stretch">
            <h1>Code Jam {{ jam.number }}: Teams</h1>

            <a class="uk-button uk-button-default" href="{{ url_for("staff.jams.index") }}"><i class="uk-icon fa-fw far fa-arrow-left"></i> &nbsp;Back</a>

            {% if teams %}
                <button class="uk-button uk-button-primary" id="init-button" disabled><i class="uk-icon fa-fw far fa-play"></i> &nbsp;Generate Teams</button>
            {% else %}
                <button class="uk-button uk-button-primary" id="init-button"><i class="uk-icon fa-fw far fa-play"></i> &nbsp;Generate Teams</button>
            {% endif %}

            <button class="uk-button uk-button-secondary" id="add-button"><i class="uk-icon fa-fw far fa-plus"></i> &nbsp;Add Team</button>
            <br />
            <br />
            <div class="uk-hidden hidden-participants" hidden>
                {% for participant in jam.participants %}
                    {% if participant.user_id not in assigned %}
                        <div class="uk-margin-small-bottom uk-margin-small-right uk-margin-small-top uk-margin-small-left" id="participant-line-{{ participant.user_id }}" title="{{ participant.user_id }}">
                            <span class="participant-handle" draggable="true" data-user-id="{{ participant.user_id }}">
                                <img class="uk-icon-image uk-border-circle" draggable="false" src="{{ participant.avatar }}" />
                                {{ participant.username }}#{{ participant.discriminator }} ({{ participant.profile.timezone }})
                            </span>
                        </div>
                    {% endif %}
                {% endfor %}
            </div>
            <div class="uk-flex uk-flex-row uk-flex-wrap" id="participant-handles">
                {% for participant in jam.participants %}
                    {% if participant.user_id not in assigned %}
                        <div class="participant-handle uk-margin-small-bottom uk-margin-small-right uk-margin-small-top uk-margin-small-left" id="participant-{{ participant.user_id }}" title="{{ participant.profile.timezone }} - {{ participant.user_id }}" draggable="true" data-user-id="{{ participant.user_id }}">
                            <div class="uk-card uk-card-primary uk-card-small" id="participant-{{ participant.user_id }}-card">
                                <div class="uk-card-body">
                                    <img class="uk-icon-image uk-border-circle" draggable="false" src="{{ participant.avatar }}" />
                                    {{ participant.username }}#{{ participant.discriminator }}
                                </div>
                            </div>
                        </div>
                    {% else %}
                        <div class="participant-handle uk-margin-small-bottom uk-margin-small-right uk-margin-small-top uk-margin-small-left" id="participant-{{ participant.user_id }}" title="{{ participant.profile.timezone }} - {{ participant.user_id }}" draggable="true" data-user-id="{{ participant.user_id }}">
                            <div class="uk-card uk-card-secondary uk-card-small" id="participant-{{ participant.user_id }}-card">
                                <div class="uk-card-body">
                                    <img class="uk-icon-image uk-border-circle" draggable="false" src="{{ participant.avatar }}" />
                                    {{ participant.username }}#{{ participant.discriminator }}
                                </div>
                            </div>
                        </div>
                    {% endif %}
                {% endfor %}
            </div>

            {% if not teams %}
                <p id="no-teams-paragraph">No teams found.</p>

                <div class="uk-flex uk-flex-row uk-flex-stretch uk-flex-wrap uk-flex-center" id="team-targets">
                </div>
            {% else %}
                <p id="no-teams-paragraph" hidden="hidden">No teams found.</p>

                <div class="uk-flex uk-flex-row uk-flex-stretch uk-flex-wrap uk-flex-center" id="team-targets">
                    {% for id, team in teams.items() %}
                        <div class="team-handle uk-margin-small-bottom uk-margin-small-right uk-margin-small-top uk-margin-small-left" id="team-{{ team.id }}" data-team-id="{{ team.id }}">
                            <div class="uk-card uk-card-default uk-card-small">
                                <div class="uk-card-header">
                                    <h3 class="uk-card-title">{{ team.name }}</h3>
                                </div>
                                <div class="uk-card-body team-target" data-team-id="{{ team.id }}">
                                    <p>Drop users here to assign them</p>

                                    {% for user_id in team.members %}
                                        <div class="uk-margin-small-bottom uk-margin-small-right uk-margin-small-top uk-margin-small-left" id="participant-line-{{ user_id }}" title="{{ participants[user_id].user_id }}">
                                            <span class="participant-handle" draggable="true" data-user-id="{{ participants[user_id].user_id }}">
                                                <img class="uk-icon-image uk-border-circle" draggable="false" src="{{ participants[user_id].avatar }}" />
                                                {{ participants[user_id].username }}#{{ participants[user_id].discriminator }} ({{ participants[user_id].profile.timezone }})
                                            </span>
                                        </div>
                                    {% endfor %}
                                </div>
                                <div class="uk-card-footer uk-text-right">
                                    <button class="team-reroll-button uk-button uk-button-primary uk-button-small" data-team-id="{{ team.id }}">
                                        <i class="uk-icon fa-fw far fa-dice"></i>
                                    </button>
                                    <button class="team-delete-button uk-button uk-button-danger uk-button-small" data-team-id="{{ team.id }}">
                                        <i class="uk-icon fa-fw far fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    {% endfor %}
                </div>
            {% endif %}
        </div>
    </div>

    <script type="application/javascript">
        "use strict";
        const jam = parseInt("{{ jam.number }}");
        const actions = new JamActions("{{ url_for("staff.jams.action") }}", "{{ csrf_token() }}");

        $("#init-button").on(
            "click",
            () => actions.generate_teams(jam, (result, data) => {
                if (result) {
                    data.teams.forEach( (team) => {
                        let elem = `
                            <div class="team-handle uk-margin-small-bottom uk-margin-small-right uk-margin-small-top uk-margin-small-left" id="team-${team.id}" data-team-id="${team.id}">
                                <div class="uk-card uk-card-default uk-card-small">
                                    <div class="uk-card-header">
                                        <h3 class="uk-card-title">${team.name}</h3>
                                    </div>
                                    <div class="uk-card-body team-target" data-team-id="${team.id}">
                                        <p>Drop users here to assign them</p>
                                    </div>
                                    <div class="uk-card-footer uk-text-right">
                                        <button class="team-reroll-button uk-button uk-button-primary uk-button-small" data-team-id="${team.id}">
                                            <i class="uk-icon fa-fw far fa-dice"></i>
                                        </button>
                                        <button class="team-delete-button uk-button uk-button-danger uk-button-small" data-team-id="${team.id}">
                                            <i class="uk-icon fa-fw far fa-trash"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>`;

                        $("#team-targets").append(elem);
                        assign_handlers();
                    });

                    $("#init-button").prop('disabled', true);

                    UIkit.notification({
                        "message": `Generated ${data.teams.length} teams`,
                        "status": "success",
                        "pos": "bottom-center",
                        "timeout": 5000
                    });
                } else {
                    console.log(data);

                    UIkit.notification({
                        "message": "Failed to generate teams",
                        "status": "danger",
                        "pos": "bottom-center",
                        "timeout": 5000
                    });
                }
            })
        );

        $("#add-button").on(
            "click",
            () => actions.create_team(jam, (result, data) => {
                if (result) {
                    let team = data.team;
                    let elem = `
                        <div class="team-handle uk-margin-small-bottom uk-margin-small-right uk-margin-small-top uk-margin-small-left" id="team-${team.id}" data-team-id="${team.id}">
                            <div class="uk-card uk-card-default uk-card-small">
                                <div class="uk-card-header">
                                    <h3 class="uk-card-title">${team.name}</h3>
                                </div>
                                <div class="uk-card-body team-target" data-team-id="${team.id}">
                                    <p>Drop users here to assign them</p>
                                </div>
                                <div class="uk-card-footer uk-text-right">
                                    <button class="team-reroll-button uk-button uk-button-primary uk-button-small" data-team-id="${team.id}">
                                        <i class="uk-icon fa-fw far fa-dice"></i>
                                    </button>
                                    <button class="team-delete-button uk-button uk-button-danger uk-button-small" data-team-id="${team.id}">
                                        <i class="uk-icon fa-fw far fa-trash"></i>
                                    </button>
                                </div>
                            </div>
                        </div>`;

                    $("#team-targets").append(elem);
                    assign_handlers();

                    UIkit.notification({
                        "message": `Created team: ${team.name}`,
                        "status": "success",
                        "pos": "bottom-center",
                        "timeout": 5000
                    });
                } else {
                    console.log(data);

                    UIkit.notification({
                        "message": "Failed to create team",
                        "status": "danger",
                        "pos": "bottom-center",
                        "timeout": 5000
                    });
                }
            })
        );

        $(".participant-handle").on(
            "dragstart",
            (e) => {
                e.originalEvent.dataTransfer.setData(
                    "pydis/member",
                    e.target.getAttribute("data-user-id")
                );
            }
        ).on(
            "mouseenter",
            (e) => {
                $("#user-info-hint").prop("hidden", true);
                $(".user-info").appendTo("#hidden-user-info");

                console.log(e.target);
                let target = e.target;
                let member = target.getAttribute("data-user-id");

                if (member === null) {
                    target = e.target.parentNode.parentNode;
                    member = target.getAttribute("data-user-id");
                }

                console.log(member);

                $(`#user-info-${member}`).appendTo("#visible-user-info");
            }
        );

        function drag_over(e) {
            e.preventDefault();
            e.stopPropagation();

            e.originalEvent.dropEffect = "move";
        }

        function drop(e) {
            e.preventDefault();
            e.stopPropagation();

            let member = e.originalEvent.dataTransfer.getData("pydis/member");

            if (!member) {
                return;
            }

            let target = e.target;

            if (target.tagName === "p" || target.tagName === "P") {
                target = target.parentNode;
            }

            let team = target.getAttribute("data-team-id");

            $(`#participant-line-${member}`).appendTo(target);
            actions.set_team_member(jam, member, team, (result, data) => {
                if (result) {
                    UIkit.notification({
                        "message": `Team assigned successfully`,
                        "status": "success",
                        "pos": "bottom-center",
                        "timeout": 5000
                    });

                    $(`#participant-${member}-card`).removeClass("uk-card-primary").addClass("uk-card-secondary");
                } else {
                    console.log(data);

                    UIkit.notification({
                        "message": "Failed to assign user to team",
                        "status": "danger",
                        "pos": "bottom-center",
                        "timeout": 5000
                    });
                }
            });
        }

        function reroll_team(e) {
            let team = this.getAttribute("data-team-id");

            actions.reroll_team(team, (result, data) => {
                if (result) {
                    $(`#team-${team}`).find("h3").text(data.name);

                    UIkit.notification({
                        "message": `Team rerolled: ${data.name}`,
                        "status": "success",
                        "pos": "bottom-center",
                        "timeout": 5000
                    });
                } else {
                    console.log(data);

                    UIkit.notification({
                        "message": "Failed to reroll team",
                        "status": "danger",
                        "pos": "bottom-center",
                        "timeout": 5000
                    });
                }
            })
        }

        function delete_team(e) {
            let team = this.getAttribute("data-team-id");

            actions.delete_team(team, (result, data) => {
                if (result) {
                    let target = $(`#team-${team}`);

                    target.find(".team-target").children("div").appendTo(".hidden-participants");
                    target.remove();
                } else {
                    console.log(data);

                    UIkit.notification({
                        "message": "Failed to delete team",
                        "status": "danger",
                        "pos": "bottom-center",
                        "timeout": 5000
                    });
                }
            })
        }

        function assign_handlers() {
            $(".team-target").off("dragover").off("drop").on("dragover", drag_over).on("drop", drop);
            $(".team-reroll-button").off("click").on("click", reroll_team);
            $(".team-delete-button").off("click").on("click", delete_team);
        }

        assign_handlers();
    </script>
{% endblock %}