Skip to content

Commit 219a368

Browse files
committed
bulk status
1 parent 2f39ff0 commit 219a368

File tree

6 files changed

+142
-4
lines changed

6 files changed

+142
-4
lines changed

app/lang/en.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
'admin.feeds.add_new' => 'Add New Feed',
130130
'admin.feeds.filter_status' => 'Filter by Status',
131131
'admin.feeds.all_status' => 'All Statuses',
132+
'admin.feeds.bulk_status' => 'Change Status',
132133
'admin.feeds.bulk_categories' => 'Edit Categories',
133134
'admin.feeds.bulk_tags' => 'Edit Tags',
134135
'admin.feeds.selected' => 'selected',

app/lang/es.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
'admin.feeds.add_new' => 'Añadir Nuevo Feed',
130130
'admin.feeds.filter_status' => 'Filtrar por Estado',
131131
'admin.feeds.all_status' => 'Todos los Estados',
132+
'admin.feeds.bulk_status' => 'Cambiar Estado',
132133
'admin.feeds.bulk_categories' => 'Editar Categorías',
133134
'admin.feeds.bulk_tags' => 'Editar Etiquetas',
134135
'admin.feeds.selected' => 'seleccionado(s)',

app/lang/pt-BR.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
'admin.feeds.add_new' => 'Adicionar Novo Feed',
130130
'admin.feeds.filter_status' => 'Filtrar por Status',
131131
'admin.feeds.all_status' => 'Todos os Status',
132+
'admin.feeds.bulk_status' => 'Alterar Status',
132133
'admin.feeds.bulk_categories' => 'Editar Categorias',
133134
'admin.feeds.bulk_tags' => 'Editar Tags',
134135
'admin.feeds.selected' => 'selecionado(s)',

app/public/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
$router->map('DELETE', '/feeds/{id:number}', [AdminController::class, 'deleteFeed']);
6666
$router->map('POST', '/feeds/bulk/categories', [AdminController::class, 'bulkUpdateFeedCategories']);
6767
$router->map('POST', '/feeds/bulk/tags', [AdminController::class, 'bulkUpdateFeedTags']);
68+
$router->map('POST', '/feeds/bulk/status', [AdminController::class, 'bulkUpdateFeedStatus']);
6869
$router->map('PUT', '/items/{id:number}', [AdminController::class, 'updateItem']);
6970

7071
// Categories management

app/src/Controllers/AdminController.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,48 @@ public function bulkUpdateFeedTags(ServerRequestInterface $request): ResponseInt
13601360
}
13611361
}
13621362

1363+
public function bulkUpdateFeedStatus(ServerRequestInterface $request): ResponseInterface
1364+
{
1365+
$params = json_decode($request->getBody()->getContents(), true) ?: (array)$request->getParsedBody();
1366+
1367+
$feedIds = $params['feed_ids'] ?? [];
1368+
$status = $params['status'] ?? '';
1369+
1370+
if (empty($feedIds) || !is_array($feedIds)) {
1371+
return new JsonResponse([
1372+
'success' => false,
1373+
'message' => 'Nenhum feed selecionado'
1374+
], 400);
1375+
}
1376+
1377+
$validStatuses = ['online', 'offline', 'paused', 'pending', 'rejected'];
1378+
if (!in_array($status, $validStatuses)) {
1379+
return new JsonResponse([
1380+
'success' => false,
1381+
'message' => 'Status inválido. Valores permitidos: online, offline, paused, pending, rejected'
1382+
], 400);
1383+
}
1384+
1385+
try {
1386+
// Update status for all selected feeds
1387+
foreach ($feedIds as $feedId) {
1388+
DB::update('feeds', [
1389+
'status' => $status
1390+
], 'id=%i', (int)$feedId);
1391+
}
1392+
1393+
return new JsonResponse([
1394+
'success' => true,
1395+
'message' => 'Status atualizado com sucesso para ' . count($feedIds) . ' feed(s)'
1396+
]);
1397+
} catch (\Exception $e) {
1398+
return new JsonResponse([
1399+
'success' => false,
1400+
'message' => 'Erro ao atualizar status: ' . $e->getMessage()
1401+
], 500);
1402+
}
1403+
}
1404+
13631405
/**
13641406
* Recalculate item counts for specified categories
13651407
*

app/templates/admin/feeds.php

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div class="card-body border-bottom">
2323
<div class="row g-3 align-items-end">
2424
<!-- Search -->
25-
<div class="col-md-4">
25+
<div class="col-md-3">
2626
<label for="search-input" class="form-label small fw-medium"><?= __('common.search') ?></label>
2727
<div class="input-group">
2828
<input type="text" id="search-input" class="form-control" placeholder="Buscar feeds..." value="<?= $this->e($searchQuery ?? '') ?>">
@@ -38,7 +38,7 @@
3838
</div>
3939

4040
<!-- Status Filter -->
41-
<div class="col-md-4">
41+
<div class="col-md-3">
4242
<label for="status-filter" class="form-label small fw-medium"><?= __('admin.feeds.filter_status') ?></label>
4343
<select id="status-filter" class="form-select">
4444
<option value=""><?= __('admin.feeds.all_status') ?></option>
@@ -51,8 +51,12 @@
5151
</div>
5252

5353
<!-- Bulk Actions -->
54-
<div class="col-md-4">
54+
<div class="col-md-6">
5555
<div class="d-flex gap-2 flex-wrap">
56+
<button id="bulk-status-btn" class="btn btn-outline-primary" disabled>
57+
<i class="bi bi-toggle-on me-1"></i>
58+
<?= __('admin.feeds.bulk_status') ?>
59+
</button>
5660
<button id="bulk-categories-btn" class="btn btn-outline-primary" disabled>
5761
<i class="bi bi-folder me-1"></i>
5862
<?= __('admin.feeds.bulk_categories') ?>
@@ -351,6 +355,44 @@
351355
</div>
352356
</div>
353357

358+
<!-- Bulk Status Modal -->
359+
<div class="modal fade" id="bulk-status-modal" tabindex="-1" aria-labelledby="bulk-status-title" aria-hidden="true">
360+
<div class="modal-dialog">
361+
<div class="modal-content">
362+
<div class="modal-header">
363+
<h5 class="modal-title" id="bulk-status-title">Alterar Status em Lote</h5>
364+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
365+
</div>
366+
<div class="modal-body">
367+
<p class="text-secondary mb-3">
368+
Selecione o novo status para <span id="bulk-status-count">0</span> feed(s) selecionado(s):
369+
</p>
370+
<div class="form-group">
371+
<label for="bulk-status-select" class="form-label fw-medium">Novo Status</label>
372+
<select id="bulk-status-select" class="form-select">
373+
<option value="">Selecione um status...</option>
374+
<option value="online"><?= __('status.online') ?></option>
375+
<option value="offline"><?= __('status.offline') ?></option>
376+
<option value="paused"><?= __('status.paused') ?></option>
377+
<option value="pending"><?= __('status.pending') ?></option>
378+
<option value="rejected"><?= __('status.rejected') ?></option>
379+
</select>
380+
</div>
381+
</div>
382+
<div class="modal-footer">
383+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
384+
<i class="bi bi-x-lg me-1"></i>
385+
<?= __('common.cancel') ?>
386+
</button>
387+
<button type="button" class="btn btn-primary" id="confirm-bulk-status">
388+
<i class="bi bi-check-lg me-1"></i>
389+
Aplicar Status
390+
</button>
391+
</div>
392+
</div>
393+
</div>
394+
</div>
395+
354396
<?php $this->start('scripts') ?>
355397
<script>
356398
document.addEventListener('DOMContentLoaded', function() {
@@ -444,6 +486,7 @@ function hideModal(modalElement) {
444486
// Bulk selection
445487
const selectAllCheckbox = document.getElementById('select-all');
446488
const feedCheckboxes = document.querySelectorAll('.feed-checkbox');
489+
const bulkStatusBtn = document.getElementById('bulk-status-btn');
447490
const bulkCategoriesBtn = document.getElementById('bulk-categories-btn');
448491
const bulkTagsBtn = document.getElementById('bulk-tags-btn');
449492
const selectionCount = document.getElementById('selection-count');
@@ -462,6 +505,8 @@ function hideModal(modalElement) {
462505
checkbox.addEventListener('change', updateBulkButtons);
463506
});
464507

508+
const bulkStatusModalElement = document.getElementById('bulk-status-modal');
509+
465510
document.querySelectorAll('[data-bs-dismiss="modal"]').forEach(button => {
466511
button.addEventListener('click', function() {
467512
const modal = this.closest('.modal');
@@ -471,7 +516,7 @@ function hideModal(modalElement) {
471516
});
472517
});
473518

474-
[deleteModalElement, bulkCategoriesModalElement, bulkTagsModalElement].forEach(modal => {
519+
[deleteModalElement, bulkCategoriesModalElement, bulkTagsModalElement, bulkStatusModalElement].forEach(modal => {
475520
modal.addEventListener('click', function(e) {
476521
if (e.target === this) {
477522
hideModal(this);
@@ -483,6 +528,7 @@ function updateBulkButtons() {
483528
const selectedCount = Array.from(feedCheckboxes).filter(cb => cb.checked).length;
484529
const hasSelection = selectedCount > 0;
485530

531+
bulkStatusBtn.disabled = !hasSelection;
486532
bulkCategoriesBtn.disabled = !hasSelection;
487533
bulkTagsBtn.disabled = !hasSelection;
488534

@@ -498,6 +544,52 @@ function updateBulkButtons() {
498544
selectAllCheckbox.indeterminate = selectedCount > 0 && selectedCount < feedCheckboxes.length;
499545
}
500546

547+
// Bulk status
548+
bulkStatusBtn.addEventListener('click', function() {
549+
const selectedCount = Array.from(feedCheckboxes).filter(cb => cb.checked).length;
550+
document.getElementById('bulk-status-count').textContent = selectedCount;
551+
document.getElementById('bulk-status-select').value = '';
552+
showModal(bulkStatusModalElement);
553+
});
554+
555+
document.getElementById('confirm-bulk-status').addEventListener('click', function() {
556+
const selectedFeeds = Array.from(feedCheckboxes)
557+
.filter(cb => cb.checked)
558+
.map(cb => parseInt(cb.value));
559+
560+
const newStatus = document.getElementById('bulk-status-select').value;
561+
562+
if (!newStatus) {
563+
alert('Selecione um status');
564+
return;
565+
}
566+
567+
fetch('/admin/feeds/bulk/status', {
568+
method: 'POST',
569+
headers: {
570+
'Content-Type': 'application/json',
571+
},
572+
body: JSON.stringify({
573+
feed_ids: selectedFeeds,
574+
status: newStatus
575+
})
576+
})
577+
.then(response => response.json())
578+
.then(data => {
579+
if (data.success) {
580+
hideModal(bulkStatusModalElement);
581+
alert(data.message);
582+
window.location.reload();
583+
} else {
584+
alert('Erro: ' + data.message);
585+
}
586+
})
587+
.catch(error => {
588+
console.error('Error:', error);
589+
alert('Ocorreu um erro ao atualizar o status.');
590+
});
591+
});
592+
501593
// Bulk categories
502594
bulkCategoriesBtn.addEventListener('click', function() {
503595
const selectedCount = Array.from(feedCheckboxes).filter(cb => cb.checked).length;

0 commit comments

Comments
 (0)