Skip to content

Commit a85d655

Browse files
committed
more twig porting
1 parent 0f51a05 commit a85d655

File tree

5 files changed

+126
-100
lines changed

5 files changed

+126
-100
lines changed

index.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,11 @@ function terminate($error_message = null, $template = 'main.html.twig',
132132
'deadline' => $deadline ? $deadline->format('c') : null,
133133
'bottom_links' => $bottom_links,
134134
'refresh_url' => $refresh_url,
135+
'form' => $form === null ? null : $form->createView(),
136+
'select_form' => $select_form === null
137+
? null : $select_form->createView(),
135138
];
136139

137-
if ($form)
138-
$content['form'] = $form->createView();
139-
if ($select_form)
140-
$content['select_form'] = $select_form->createView();
141-
142140
if (!$error_message) {
143141
db_flush();
144142
}

pages/bugs.php

+32-27
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,10 @@
1919
$groups = $user->groups;
2020
}
2121

22-
$table = [];
23-
foreach ($groups as $group) {
24-
foreach (db_fetch_bugs_group($group) as $bug) {
25-
$video = $bug->getVideoHTML();
26-
if ($video) {
27-
$video = <<<HTML
28-
<button class="btn btn-primary" onclick="toggleVideo(this)">Show Video</button>
29-
<div style="display: none; margin-top: 10px">$video</div>
30-
HTML;
31-
}
32-
$repo = $group->getRepository();
33-
$table[] = [
34-
'id' => $bug->id,
35-
'Group' => dolink_group($group, $group),
36-
'Project' => $repo ? dolink_ext($repo, $repo->name()) : '',
37-
'Student' => $bug->user->shortName(),
38-
'Issue' => dolink_ext($bug->issue_url, 'link'),
39-
'Description' => $bug->description,
40-
'Video' => ['html' => $video],
41-
];
42-
}
43-
}
44-
4522
if ($user->role == ROLE_STUDENT && $deadlines->isBugSelectionActive()) {
23+
$info_message = "You can submit this form multiple times until the deadline.".
24+
" Only the last submission will be considered.";
25+
4626
if ($bug = db_fetch_bug_user($year, $user)) {
4727
$issue_url = $bug->issue_url;
4828
$repro_url = $bug->repro_url;
@@ -54,11 +34,12 @@
5434
$form = $formFactory->createBuilder(FormType::class)
5535
->add('issue_url', UrlType::class, [
5636
'label' => 'Issue URL',
57-
'data' => $issue_url,
37+
'data' => $issue_url,
5838
])
5939
->add('repro_url', UrlType::class, [
60-
'label' => 'URL of video reproducing the issue',
61-
'data' => $repro_url,
40+
'label' => 'URL of video reproducing the issue',
41+
'data' => $repro_url,
42+
'required' => false,
6243
])
6344
->add('description', TextareaType::class, [
6445
'label' => 'Description',
@@ -76,7 +57,7 @@
7657
if ($bug = db_fetch_bug_user($year, $user)) {
7758
$bug->description = $form->get('description')->getData();
7859
$bug->set_issue_url($form->get('issue_url')->getData());
79-
$bug->set_repro_url($form->get('repro_url')->getData());
60+
$bug->set_repro_url($form->get('repro_url')->getData() ?? '');
8061
} else {
8162
$bug = SelectedBug::factory(
8263
$group, $user, $form->get('description')->getData(),
@@ -86,3 +67,27 @@
8667
}
8768
}
8869
}
70+
71+
$table = [];
72+
foreach ($groups as $group) {
73+
foreach (db_fetch_bugs_group($group) as $bug) {
74+
$video = $bug->getVideoHTML();
75+
if ($video) {
76+
$video = <<<HTML
77+
<button class="btn btn-primary" onclick="toggleVideo(this)">Show Video</button>
78+
<div style="display: none; margin-top: 10px">$video</div>
79+
HTML;
80+
}
81+
$repo = $group->getRepository();
82+
$table[] = [
83+
'id' => $bug->id,
84+
'Group' => dolink_group($group, $group),
85+
'Project' => $repo ? dolink_ext($repo, $repo->name()) : '',
86+
'Student' => $bug->user->shortName(),
87+
'Issue' => dolink_ext($bug->issue_url, 'link'),
88+
'Description' => $bug->description,
89+
'Video' => ['html' => $video, 'width' => 100],
90+
'_large_table' => true,
91+
];
92+
}
93+
}

pages/listproject.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
if (!$group || !has_group_permissions($group))
1212
die('Permission error');
1313

14-
$top_box['title'] = 'Students';
1514
foreach ($group->students as $s) {
1615
$data = [
1716
['type' => 'photo', 'data' => $s->getPhoto()],
@@ -25,12 +24,15 @@
2524
$repou->platform().':'.$repou->username());
2625
$data[] = $repou->description();
2726
}
28-
$top_box['rows'][] = $data;
27+
$top_box['Students'][] = $data;
2928
}
3029

3130
if ($prof = $group->shift->prof) {
32-
echo "<p>Professor: <a href=\"mailto:$prof->email\">",
33-
$prof->shortName(), "</a></p>\n";
31+
$top_box['Professor'][] = [
32+
['type' => 'photo', 'data' => $prof->getPhoto()],
33+
$prof->shortName(),
34+
['type' => 'email', 'data' => $prof->email],
35+
];
3436
}
3537

3638
$readonly = ['group_number', 'year', 'shift'];

templates/header.html.twig

+36-32
Original file line numberDiff line numberDiff line change
@@ -61,42 +61,46 @@
6161
</script>
6262
{% endif %}
6363

64-
65-
6664
{% if top_box is defined and top_box %}
67-
<div class="card mb-3">
68-
<div class="card-header">
69-
<h5 class="mb-0">{{ top_box.title }}</h5>
70-
</div>
71-
<div class="card-body">
72-
<div class="row g-3">
73-
{% for row in top_box.rows %}
74-
<div class="col-md-6 col-lg-4">
75-
<div class="d-flex align-items-center p-2 border rounded">
76-
<ul class="list-unstyled mb-0">
77-
{% for item in row %}
78-
<li>
79-
{% if item is iterable %}
80-
{% if item.url is defined %}
81-
<a href="{{ item.url }}" class="text-decoration-none">{{ item.label }}</a>
82-
{% elseif item.type == 'photo' %}
83-
<img src="{{ item.data }}" class="rounded-circle me-2" width="100" height="100">
84-
{% elseif item.type == 'email' %}
85-
<i class="bi bi-envelope"></i>
86-
<a href="mailto:{{ item.data }}" class="text-decoration-none">{{ item.data }}</a>
87-
{% endif %}
88-
{% else %}
89-
{{ item }}
90-
{% endif %}
91-
</li>
92-
{% endfor %}
93-
</ul>
94-
</div>
65+
<div class="row g-3">
66+
{% for title, cols in top_box %}
67+
<div class="col-12 col-md-6">
68+
<div class="card h-100">
69+
<div class="card-header">
70+
<h5 class="mb-0">{{ title }}</h5>
71+
</div>
72+
<div class="card-body">
73+
<div class="row g-3">
74+
{% for col in cols %}
75+
<div class="col-md-6">
76+
<div class="p-2 border rounded">
77+
<ul class="list-unstyled mb-0">
78+
{% for item in col %}
79+
<li>
80+
{% if item is iterable %}
81+
{% if item.url is defined %}
82+
<a href="{{ item.url }}" class="text-decoration-none">{{ item.label }}</a>
83+
{% elseif item.type == 'photo' %}
84+
<img src="{{ item.data }}" class="rounded-circle me-2" width="100" height="100">
85+
{% elseif item.type == 'email' %}
86+
<i class="bi bi-envelope"></i>
87+
<a href="mailto:{{ item.data }}" class="text-decoration-none">{{ item.data }}</a>
88+
{% endif %}
89+
{% else %}
90+
{{ item }}
91+
{% endif %}
92+
</li>
93+
{% endfor %}
94+
</ul>
95+
</div>
96+
</div>
97+
{% endfor %}
9598
</div>
96-
{% endfor %}
99+
</div>
97100
</div>
98101
</div>
99-
</div>
102+
{% endfor %}
103+
</div>
100104
{% endif %}
101105

102106
<div class="container mt-4 row">

templates/main.html.twig

+49-32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% include 'header.html.twig' %}
22

3-
{% if select_form is defined %}
3+
{% if select_form %}
44
<form method="GET">
55
<div class="card mb-3">
66
<div class="card-body">
@@ -21,8 +21,8 @@
2121
</form>
2222
{% endif %}
2323

24-
{% if deadline is defined and deadline %}
25-
<div class="position-fixed top-50 end-0 translate-middle-y p-3 bg-primary text-white shadow rounded me-4">
24+
{% if deadline %}
25+
<div class="position-fixed top-50 end-0 translate-middle-y p-3 bg-primary text-white shadow rounded me-4" style="z-index: 2000">
2626
<h5 class="text-center">Deadline</h5>
2727
<p id="deadline" class="text-center fs-5">Loading...</p>
2828
</div>
@@ -52,7 +52,7 @@
5252
</script>
5353
{% endif %}
5454

55-
{% if embed_file is defined and embed_file %}
55+
{% if embed_file %}
5656
<div class="card my-3">
5757
<div class="card-header">
5858
<h5 class="mb-0">File Preview</h5>
@@ -63,7 +63,7 @@
6363
</div>
6464
{% endif %}
6565

66-
{% if monospace is defined and monospace %}
66+
{% if monospace %}
6767
<div class="container mt-4">
6868
<h4>Log Output</h4>
6969
<div class="bg-dark text-light p-3 rounded overflow-auto" style="max-height: 400px">
@@ -72,36 +72,53 @@
7272
</div>
7373
{% endif %}
7474

75-
{% if table is defined and table %}
76-
<table class="table table-striped table-bordered table-hover w-auto">
77-
<thead class="table-primary sticky-top">
78-
<tr>
79-
{% for key in table|first|keys %}
80-
<th>{{ key }}</th>
81-
{% endfor %}
82-
</tr>
83-
</thead>
84-
<tbody>
85-
{% for row in table %}
75+
{% if table %}
76+
{% if (table|first)._large_table is defined %}
77+
</div>
78+
<div class="col-md-12">
79+
{% endif %}
80+
<div class="container-fluid my-4">
81+
<table class="table table-striped table-bordered table-hover w-auto">
82+
<thead class="table-primary sticky-top">
8683
<tr>
87-
{% for value in row %}
88-
<td>
89-
{% if value is iterable and value.url is defined %}
90-
<a href="{{ value.url }}">{{ value.label }}</a>
91-
{% elseif value is iterable and value.html is defined %}
92-
{{ value.html|raw }}
93-
{% else %}
94-
{{ value|nl2br }}
84+
{% for key in table|first|keys %}
85+
{% if key != '_large_table' %}
86+
<th>{{ key }}</th>
9587
{% endif %}
96-
</td>
9788
{% endfor %}
98-
</tr>
99-
{% endfor %}
100-
</tbody>
101-
</table>
89+
</tr>
90+
</thead>
91+
<tbody>
92+
{% for row in table %}
93+
<tr>
94+
{% for key, value in row %}
95+
{% if key != '_large_table' %}
96+
<td style="
97+
{% if value is iterable and value.width is defined %}
98+
min-width: {{ value.width }}px;
99+
{% endif %}
100+
word-break: break-word">
101+
{% if value is iterable and value.url is defined %}
102+
<a href="{{ value.url }}">{{ value.label }}</a>
103+
{% elseif value is iterable and value.html is defined %}
104+
{{ value.html|raw }}
105+
{% else %}
106+
{{ value|nl2br }}
107+
{% endif %}
108+
</td>
109+
{% endif %}
110+
{% endfor %}
111+
</tr>
112+
{% endfor %}
113+
</tbody>
114+
</table>
115+
</div>
116+
{% if (table|first)._large_table is defined %}
117+
</div><div class="col-md-7">
118+
{% endif %}
102119
{% endif %}
103120

104-
{% if lists is defined and lists %}
121+
{% if lists %}
105122
<div class="container mt-4">
106123
{% for label, items in lists %}
107124
<div class="card mb-3">
@@ -124,7 +141,7 @@
124141
</div>
125142
{% endif %}
126143

127-
{% if form is defined %}
144+
{% if form %}
128145
<div class="card mb-4" style="max-width: 600px; margin: 0 auto">
129146
<div class="card-body">
130147
{{ form_start(form) }}
@@ -146,7 +163,7 @@
146163
</div>
147164
{% endif %}
148165

149-
{% if bottom_links is defined and bottom_links %}
166+
{% if bottom_links %}
150167
<div class="mt-3 mb-3 bg-light py-3 container">
151168
{% for line in bottom_links %}
152169
<a href="{{ line.url }}" class="d-block text-decoration-none">{{line.label}}</a>

0 commit comments

Comments
 (0)