Skip to content

Commit fc8ef10

Browse files
committed
[qa]: mdu telegram
1 parent 2366d25 commit fc8ef10

File tree

6 files changed

+135
-172
lines changed

6 files changed

+135
-172
lines changed

app/src/Controllers/AdminController.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,13 @@ public function createFeed(ServerRequestInterface $request): ResponseInterface
389389
public function updateFeed(ServerRequestInterface $request, array $args): ResponseInterface
390390
{
391391
$id = (int)$args['id'];
392-
$params = (array)$request->getParsedBody();
392+
393+
$body = $request->getBody()->getContents();
394+
$params = !empty($body) ? json_decode($body, true) : [];
395+
396+
if ($params === null) {
397+
$params = (array)$request->getParsedBody();
398+
}
393399

394400
$feed = DB::queryFirstRow("SELECT * FROM feeds WHERE id = %i", $id);
395401
if (!$feed) {
@@ -435,7 +441,12 @@ public function updateFeed(ServerRequestInterface $request, array $args): Respon
435441
}
436442

437443
if (isset($params['status'])) {
438-
$updateData['status'] = $params['status'];
444+
$validStatuses = ['online', 'offline', 'paused'];
445+
if (!in_array($params['status'], $validStatuses)) {
446+
$errors['status'] = 'Status inválido. Valores permitidos: online, offline, paused';
447+
} else {
448+
$updateData['status'] = $params['status'];
449+
}
439450
}
440451

441452
if (!empty($errors)) {

app/templates/admin/feeds.php

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<?php $this->start('active') ?>admin-feeds<?php $this->stop() ?>
44

55
<div class="card shadow-sm">
6-
<div class="card-header d-flex justify-content-between align-items-center">
6+
<div class="card-header d-md-flex justify-content-between align-items-center">
77
<div>
88
<h3 class="fs-5 fw-medium mb-0 mt-1">
99
<i class="bi bi-grid me-1"></i>
1010
Gerenciar Feeds
1111
</h3>
1212
</div>
13-
<div>
13+
<div class="pt-2 pb-1 pt-md-0 pb-md-0">
1414
<a href="/admin/feeds/new" class="btn btn-primary d-inline-flex align-items-center">
1515
<i class="bi bi-plus-lg me-1"></i>
1616
Adicionar Novo Feed
@@ -35,8 +35,8 @@
3535
<th scope="col" class="small text-uppercase">Tipo</th>
3636
<th scope="col" class="small text-uppercase">Idioma</th>
3737
<th scope="col" class="small text-uppercase">Status</th>
38-
<th scope="col" class="small text-uppercase">Última Verificação</th>
39-
<th scope="col" class="small text-uppercase">Última Atualização</th>
38+
<th scope="col" class="small text-uppercase text-truncate">Última Verificação</th>
39+
<th scope="col" class="small text-uppercase text-truncate">Última Atualização</th>
4040
<th scope="col" class="small text-uppercase">Itens</th>
4141
<th scope="col"></th>
4242
</tr>
@@ -79,21 +79,22 @@
7979
</select>
8080
</td>
8181
<td class="align-middle small text-secondary">
82-
<?= $feed['last_checked'] ? date('j M Y H:i', strtotime($feed['last_checked'])) : 'Nunca' ?>
82+
<?= $feed['last_checked'] ? date('d/m/Y \à\s H:i', strtotime($feed['last_checked'])) : 'Nunca' ?>
8383
</td>
8484
<td class="align-middle small text-secondary">
85-
<?= $feed['last_updated'] ? date('j M Y H:i', strtotime($feed['last_updated'])) : 'Nunca' ?>
85+
<?= $feed['last_updated'] ? date('d/m/Y \à\s H:i', strtotime($feed['last_updated'])) : 'Nunca' ?>
8686
</td>
8787
<td class="align-middle small text-secondary">
8888
<?= $feed['item_count'] ?? 0 ?>
8989
</td>
9090
<td class="align-middle text-end">
91-
<a href="/admin/feeds/<?= $feed['id'] ?>/edit" class="d-inline-block btn btn-sm btn-outline-primary">
91+
<div class="text-truncate">
92+
<a href="/admin/feeds/<?= $feed['id'] ?>/edit" class="d-inline-block btn btn-sm btn-outline-primary me-2">
9293
<i class="bi bi-pencil"></i>
93-
</a>
94-
<button class="d-inline-block btn btn-sm btn-outline-danger delete-feed" data-feed-id="<?= $feed['id'] ?>">
94+
</a><button class="d-inline-block btn btn-sm btn-outline-danger delete-feed" data-feed-id="<?= $feed['id'] ?>">
9595
<i class="bi bi-trash"></i>
9696
</button>
97+
</div>
9798
</td>
9899
</tr>
99100
<?php endforeach; ?>
@@ -104,7 +105,6 @@
104105
<?php endif; ?>
105106
</div>
106107

107-
<!-- Delete Confirmation Modal -->
108108
<div class="modal fade" id="delete-modal" tabindex="-1" aria-labelledby="modal-title" aria-hidden="true">
109109
<div class="modal-dialog">
110110
<div class="modal-content">
@@ -115,9 +115,7 @@
115115
<div class="modal-body">
116116
<div class="d-flex">
117117
<div class="me-3">
118-
<div class="bg-danger bg-opacity-10 p-2 rounded-circle">
119-
<i class="bi bi-exclamation-triangle text-danger fs-4"></i>
120-
</div>
118+
<i class="bi bi-exclamation-triangle text-danger fs-4"></i>
121119
</div>
122120
<div>
123121
<p class="mb-0">
@@ -143,16 +141,13 @@
143141
<?php $this->start('scripts') ?>
144142
<script>
145143
document.addEventListener('DOMContentLoaded', function() {
146-
// Modal elements
147144
const deleteModal = new bootstrap.Modal(document.getElementById('delete-modal'));
148145

149-
// Buttons
150146
const cancelDeleteButton = document.getElementById('cancel-delete');
151147
const confirmDeleteButton = document.getElementById('confirm-delete');
152148
const deleteFeedButtons = document.querySelectorAll('.delete-feed');
153149
const statusSelects = document.querySelectorAll('.status-select');
154150

155-
// Delete feed
156151
deleteFeedButtons.forEach(button => {
157152
button.addEventListener('click', function() {
158153
const feedId = this.dataset.feedId;
@@ -161,7 +156,6 @@
161156
});
162157
});
163158

164-
// Confirm delete
165159
confirmDeleteButton.addEventListener('click', function() {
166160
const feedId = this.dataset.feedId;
167161

@@ -171,14 +165,11 @@
171165
.then(response => response.json())
172166
.then(data => {
173167
if (data.success) {
174-
// Remove the row from the table
175168
const row = document.querySelector(`tr[data-feed-id="${feedId}"]`);
176169
row.remove();
177170

178-
// Hide the modal
179171
deleteModal.hide();
180172

181-
// If no feeds left, refresh the page to show the empty state
182173
if (document.querySelectorAll('tbody tr').length === 0) {
183174
window.location.reload();
184175
}
@@ -192,7 +183,6 @@
192183
});
193184
});
194185

195-
// Update feed status
196186
statusSelects.forEach(select => {
197187
select.addEventListener('change', function() {
198188
const feedId = this.dataset.feedId;
@@ -211,16 +201,14 @@
211201
.then(response => response.json())
212202
.then(data => {
213203
if (data.success) {
214-
// Update the data attribute
215204
this.dataset.originalValue = newStatus;
205+
alert('Status do feed atualizado com sucesso para: ' + newStatus);
216206
} else {
217-
// Revert to original value
218207
this.value = originalValue;
219208
alert('Erro ao atualizar status do feed: ' + data.message);
220209
}
221210
})
222211
.catch(error => {
223-
// Revert to original value
224212
this.value = originalValue;
225213
console.error('Error:', error);
226214
alert('Ocorreu um erro ao atualizar o status do feed.');

app/templates/admin/items.php

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,35 @@
33
<?php $this->start('active') ?>admin<?php $this->stop() ?>
44

55
<div class="card shadow-sm">
6-
<div class="card-header d-flex justify-content-between align-items-center">
7-
<div>
8-
<h3 class="fs-5 fw-medium mb-0 mt-1">
9-
<i class="bi bi-collection me-1"></i>
10-
Gerenciar artigos de feeds
11-
</h3>
12-
</div>
13-
<div>
14-
<form action="/admin" method="GET" class="d-flex gap-2">
15-
<div>
16-
<select name="feed" class="form-select">
17-
<option value="">Feeds</option>
18-
<?php foreach ($feeds as $feed): ?>
19-
<option value="<?= $feed['id'] ?>" <?= $selectedFeed == $feed['id'] ? 'selected' : '' ?>>
20-
<?= $this->e($feed['title']) ?>
21-
</option>
22-
<?php endforeach; ?>
23-
</select>
24-
</div>
25-
<div class="input-group">
26-
<input type="text" name="search" value="<?= $this->e($search) ?>" class="form-control" placeholder="Pesquisar...">
27-
<button type="submit" class="btn btn-primary d-flex align-items-center">
28-
<i class="bi bi-search me-1"></i>
29-
Pesquisar
30-
</button>
31-
</div>
32-
</form>
6+
<div class="card-header">
7+
<div class="row">
8+
<div class="col-12 col-md-6">
9+
<h3 class="fs-5 fw-medium mb-0 mt-1 mt-md-2">
10+
<i class="bi bi-collection me-1"></i>
11+
Gerenciar artigos de feeds
12+
</h3>
13+
</div>
14+
<div class="col-12 col-md-6 pb-1 pb-md-0 pt-3 pt-md-0">
15+
<form action="/admin" method="GET" class="d-flex gap-2">
16+
<div>
17+
<select name="feed" class="form-select">
18+
<option value="">Feeds</option>
19+
<?php foreach ($feeds as $feed): ?>
20+
<option value="<?= $feed['id'] ?>" <?= $selectedFeed == $feed['id'] ? 'selected' : '' ?>>
21+
<?= $this->e($feed['title']) ?>
22+
</option>
23+
<?php endforeach; ?>
24+
</select>
25+
</div>
26+
<div class="input-group">
27+
<input type="text" name="search" value="<?= $this->e($search) ?>" class="form-control" placeholder="...">
28+
<button type="submit" class="btn btn-primary d-flex align-items-center">
29+
<i class="bi bi-search me-1"></i>
30+
Pesquisar
31+
</button>
32+
</div>
33+
</form>
34+
</div>
3335
</div>
3436
</div>
3537

@@ -89,7 +91,7 @@
8991
<?= $this->e($item['author'] ?? 'Desconhecido') ?>
9092
</td>
9193
<td class="small text-secondary align-middle">
92-
<?= date('j M Y', strtotime($item['published_at'])) ?>
94+
<?= $item['published_at'] ? date('d/m/Y \à\s H:i', strtotime($item['published_at'])) : 'Nunca' ?>
9395
</td>
9496
<td class="align-middle text-end">
9597
<button
@@ -112,28 +114,10 @@ class="d-inline-block btn btn-sm btn-outline-primary toggle-visibility">
112114

113115
<?php if ($pagination['total'] > 1): ?>
114116
<div class="card-footer d-flex justify-content-between align-items-center">
115-
<div class="d-flex d-sm-none w-100 justify-content-between">
116-
<?php if ($pagination['current'] > 1): ?>
117-
<a href="<?= $pagination['baseUrl'] ?>&page=<?= $pagination['current'] - 1 ?>" class="btn btn-outline-secondary btn-sm d-flex align-items-center">
118-
<i class="bi bi-chevron-left me-1"></i>
119-
Anterior
120-
</a>
121-
<?php else: ?>
122-
<div></div>
123-
<?php endif; ?>
124-
<?php if ($pagination['current'] < $pagination['total']): ?>
125-
<a href="<?= $pagination['baseUrl'] ?>&page=<?= $pagination['current'] + 1 ?>" class="btn btn-outline-secondary btn-sm d-flex align-items-center">
126-
Próximo
127-
<i class="bi bi-chevron-right ms-1"></i>
128-
</a>
129-
<?php else: ?>
130-
<div></div>
131-
<?php endif; ?>
132-
</div>
133-
<div class="d-none d-sm-flex justify-content-between align-items-center w-100">
117+
<div class="d-flex justify-content-between align-items-center w-100">
134118
<div>
135119
<p class="small text-secondary mb-0">
136-
Mostrando página <span class="fw-medium"><?= $pagination['current'] ?></span> de <span class="fw-medium"><?= $pagination['total'] ?></span>
120+
Página <span class="fw-medium"><?= $pagination['current'] ?></span> de <span class="fw-medium"><?= $pagination['total'] ?></span>
137121
</p>
138122
</div>
139123
<div>
@@ -207,15 +191,13 @@ class="d-inline-block btn btn-sm btn-outline-primary toggle-visibility">
207191
.then(response => response.json())
208192
.then(data => {
209193
if (data.success) {
210-
// Update button text and icon
211194
if (newVisible) {
212195
this.innerHTML = '<i class="bi bi-eye-slash me-1"></i> Ocultar';
213196
} else {
214197
this.innerHTML = '<i class="bi bi-eye me-1"></i> Mostrar';
215198
}
216199
this.dataset.visible = newVisible ? '1' : '0';
217200

218-
// Update visibility badge
219201
const row = this.closest('tr');
220202
const badge = row.querySelector('td:nth-child(5) span');
221203

app/templates/feeds.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<div class="card shadow-sm">
66
<div class="card-header">
7-
<h3 class="fs-5 fw-medium mb-0 mt-1">
7+
<h3 class="fs-5 fw-medium mb-1 mb-md-0 mt-1">
88
<i class="bi bi-journal-text me-1"></i>
99
Feeds
1010
</h3>
@@ -26,34 +26,28 @@
2626
Feed
2727
</div>
2828
</th>
29-
<th scope="col" class="small text-uppercase">
30-
<div class="d-flex align-items-center">
31-
<i class="bi bi-book me-1"></i>
32-
Tipo
33-
</div>
34-
</th>
3529
<th scope="col" class="small text-uppercase">
3630
<div class="d-flex align-items-center">
3731
<i class="bi bi-clock me-1"></i>
3832
Status
3933
</div>
4034
</th>
4135
<th scope="col" class="small text-uppercase">
42-
<div class="d-flex align-items-center">
36+
<div class="d-flex align-items-center text-truncate">
4337
<i class="bi bi-clock-history me-1"></i>
4438
Última Verificação
4539
</div>
4640
</th>
4741
<th scope="col" class="small text-uppercase">
48-
<div class="d-flex align-items-center">
42+
<div class="d-flex align-items-center text-truncate">
4943
<i class="bi bi-arrow-repeat me-1"></i>
5044
Última Atualização
5145
</div>
5246
</th>
5347
<th scope="col" class="small text-uppercase">
5448
<div class="d-flex align-items-center">
5549
<i class="bi bi-collection me-1"></i>
56-
Itens
50+
Artigos
5751
</div>
5852
</th>
5953
</tr>
@@ -79,9 +73,6 @@
7973
</div>
8074
</div>
8175
</td>
82-
<td class="align-middle fw-medium">
83-
<?= $this->e(strtoupper($feed['feed_type'])) ?>
84-
</td>
8576
<td class="align-middle">
8677
<?php if ($feed['status'] === 'online'): ?>
8778
<span class="badge bg-success">
@@ -101,10 +92,10 @@
10192
<?php endif; ?>
10293
</td>
10394
<td class="align-middle small text-secondary">
104-
<?= $feed['last_checked'] ? date('M j, Y H:i', strtotime($feed['last_checked'])) : 'Nunca' ?>
95+
<?= $feed['last_checked'] ? date('d/m/Y \à\s H:i', strtotime($feed['last_checked'])) : 'Nunca' ?>
10596
</td>
10697
<td class="align-middle small text-secondary">
107-
<?= $feed['last_updated'] ? date('M j, Y H:i', strtotime($feed['last_updated'])) : 'Nunca' ?>
98+
<?= $feed['last_updated'] ? date('d/m/Y \à\s H:i', strtotime($feed['last_updated'])) : 'Nunca' ?>
10899
</td>
109100
<td class="align-middle small text-secondary">
110101
<?= $feed['item_count'] ?? 0 ?>

0 commit comments

Comments
 (0)