Skip to content

Commit d2d9e17

Browse files
committed
twig work
1 parent a85d655 commit d2d9e17

8 files changed

+63
-36
lines changed

pages/dashboard.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
$total_feat = array_sum($stats[PATCH_FEATURE] ?? array());
105105
$bugs = $stats[PATCH_BUGFIX][1] ?? 0;
106106
$feat = $stats[PATCH_FEATURE][1] ?? 0;
107-
$fields['table'][] = [
107+
$fields['all_projects'][] = [
108108
'id' => $id++,
109109
'name' => $name,
110110
'total_bugs' => $total_bugs,

pages/features.php

-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@
6262
$file->move(__DIR__ . '/../uploads', $hash);
6363
$success_message = "File uploaded successfully!";
6464

65-
if ($group->hash_proposal_file && $group->hash_proposal_file !== $hash) {
66-
unlink(__DIR__ . "/../uploads/{$group->hash_proposal_file}");
67-
}
6865
$group->hash_proposal_file = $hash;
6966
$group->url_proposal = check_url($form->get('url')->getData());
7067
}

pages/patches.php

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
'Files' => $patch->files_modified,
9292
'Submitter' => $patch->getSubmitterName(),
9393
'Authors' => implode(', ', $authors),
94+
'_large_table' => true,
9495
];
9596
}
9697
}

pages/rmpatch.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
if (!empty($_GET['sure'])) {
1717
db_delete($patch);
18-
echo "<p>Patch deleted</p>";
18+
$success_message = "Patch deleted";
1919
} else {
2020
$name = $patch->getSubmitter()->shortName();
2121
$link = dolink('rmpatch', "Yes, I'm sure",

pages/shifts.php

+27-23
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,41 @@
22
// Copyright (c) 2022-present Instituto Superior Técnico.
33
// Distributed under the MIT license that can be found in the LICENSE file.
44

5+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
6+
use Symfony\Component\Form\Extension\Core\Type\FormType;
7+
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
8+
59
auth_require_at_least(ROLE_PROF);
610

711
$year = get_current_year();
812
$shifts = db_fetch_shifts($year);
9-
$profs = db_get_all_profs(true);
1013

11-
if (isset($_POST['submit'])) {
12-
foreach ($shifts as $shift) {
13-
$var = "shift_$shift->id";
14-
if (!empty($_POST[$var])) {
15-
$user = db_fetch_user($_POST[$var]);
16-
if (!$user || !$user->roleAtLeast(ROLE_TA))
17-
die("Unknown user");
18-
$shift->prof = $user;
19-
}
20-
}
21-
db_flush();
22-
echo "<p>Saved!</p>";
23-
}
14+
$form = $formFactory->createBuilder(FormType::class);
2415

25-
foreach ($profs as $prof) {
26-
echo "<td>{$prof->shortName()}</td>";
16+
foreach (db_get_all_profs(true) as $prof) {
17+
$profs[$prof->shortName()] = $prof->id;
2718
}
2819

2920
foreach ($shifts as $shift) {
30-
echo "<tr><td>", htmlspecialchars($shift->name), "</td>";
31-
foreach ($profs as $prof) {
32-
$selected = '';
33-
if ($shift->prof == $prof)
34-
$selected = ' checked';
35-
echo "<td><input type=\"radio\" name=\"shift_$shift->id\" value=\"",
36-
htmlspecialchars($prof->id), "\"$selected></td>";
21+
$form->add("shift_$shift->id", ChoiceType::class, [
22+
'label' => $shift->name,
23+
'choices' => $profs,
24+
'data' => $shift->prof ? $shift->prof->id : null,
25+
]);
26+
}
27+
28+
$form->add('submit', SubmitType::class);
29+
$form = $form->getForm();
30+
31+
$form->handleRequest($request);
32+
33+
if ($form->isSubmitted() && $form->isValid()) {
34+
foreach ($shifts as $shift) {
35+
$var = "shift_$shift->id";
36+
$user = db_fetch_user($form->get($var)->getData());
37+
if (!$user || !$user->roleAtLeast(ROLE_TA))
38+
die("Unknown user");
39+
$shift->prof = $user;
3740
}
41+
$success_message = 'Saved!';
3842
}

templates.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ function handle_form(&$obj, $hide_fields, $readonly, $only_fields = null,
156156
}
157157
}
158158

159-
if ($not_all_readonly)
160-
$form->add('submit', SubmitType::class, ['label' => 'Save changes']);
159+
$form->add('submit', SubmitType::class, [
160+
'label' => 'Save changes',
161+
'disabled' => !$not_all_readonly,
162+
]);
161163

162164
if ($extra_buttons) {
163165
foreach ($extra_buttons as $name => $args) {

templates/dashboard.html.twig

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
{% include 'header.html.twig' %}
22

3+
</div>
4+
<div class="col-md-12">
5+
36
<script src="https://cdn.plot.ly/plotly-3.0.0.min.js"></script>
47
<link href="https://unpkg.com/tabulator-tables/dist/css/tabulator.min.css" rel="stylesheet">
58
<script type="text/javascript" src="https://unpkg.com/tabulator-tables/dist/js/tabulator.js"></script>
69

10+
<form method="GET">
11+
<div class="card mb-3">
12+
<div class="card-body">
13+
<div class="row g-3">
14+
{% for field in select_form %}
15+
{% if 'hidden' in field.vars.block_prefixes %}
16+
{{ form_widget(field) }}
17+
{% else %}
18+
<div class="col-md-2">
19+
{{ form_row(field, {'attr': {'class': 'form-control',
20+
'onchange': 'this.form.submit()'}}) }}
21+
</div>
22+
{% endif %}
23+
{% endfor %}
24+
</div>
25+
</div>
26+
</div>
27+
</form>
28+
729
<div class="container justify-content-center">
830
<div class="row">
931
<div class="col">
@@ -27,8 +49,8 @@
2749
</div>
2850
</div>
2951

30-
<div class="container mt-4 mb-4">
31-
<div class="card shadow">
52+
<div class="container mt-4 mb-4 d-flex justify-content-center">
53+
<div class="card shadow w-auto">
3254
<div class="card-header bg-primary text-white">
3355
<h5 class="mb-0">All projects</h5>
3456
</div>
@@ -173,7 +195,7 @@ Plotly.newPlot('projsplot', data, layout, config);
173195
174196
// the table
175197
var tabledata = [
176-
{% for row in table %}
198+
{% for row in all_projects %}
177199
{ id: {{ row.id }},
178200
name: "{{ row.name|e('js') }}",
179201
url: "{{ row.url|e('js') }}",
@@ -185,7 +207,7 @@ var tabledata = [
185207
{% endfor %}
186208
];
187209
var table = new Tabulator("#projects-table", {
188-
height: 250,
210+
height: 350,
189211
data: tabledata,
190212
layout: "fitColumns",
191213
columns: [

templates/header.html.twig

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
style="max-width: 350px; border-radius: 10px;">
2525
<div class="card-body">
2626
<img src="{{ photo }}" class="rounded-circle mb-3" alt="User Photo"
27-
style="width: 100px; height: 100px; object-fit: cover; border: 4px solid #ddd;">
27+
style="width: 100px; height: 100px; object-fit: cover; border: 4px solid #ddd">
2828
<h5 class="card-title mb-1">{{ name }}</h5>
2929
<p class="text-muted small mb-0">User ID: {{ user_id }}</p>
3030
<p class="mb-0">Role: {{ role }}</p>
@@ -81,7 +81,8 @@
8181
{% if item.url is defined %}
8282
<a href="{{ item.url }}" class="text-decoration-none">{{ item.label }}</a>
8383
{% elseif item.type == 'photo' %}
84-
<img src="{{ item.data }}" class="rounded-circle me-2" width="100" height="100">
84+
<img src="{{ item.data }}" class="rounded-circle mb-3"
85+
style="width: 100px; height: 100px; object-fit: cover; border: 4px solid #ddd">
8586
{% elseif item.type == 'email' %}
8687
<i class="bi bi-envelope"></i>
8788
<a href="mailto:{{ item.data }}" class="text-decoration-none">{{ item.data }}</a>

0 commit comments

Comments
 (0)