chartboard/app/Views/query/index.php
2026-03-30 09:51:33 +05:30

72 lines
3.2 KiB
PHP

<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>
<header class="cb-page-header cb-page-header--center">
<div>
<h1 class="cb-page-title">Saved Queries</h1>
<p class="cb-page-subtitle">Start building reusable queries for charts and dashboards.</p>
</div>
<a href="<?= base_url('query/create') ?>" class="btn cb-page-primary-btn">+ New Query</a>
</header>
<div class="cb-page-body">
<?php if (session()->getFlashdata('success')): ?>
<div class="alert alert-success"><?= esc(session()->getFlashdata('success')) ?></div>
<?php endif; ?>
<?php if (session()->getFlashdata('error')): ?>
<div class="alert alert-danger"><?= esc(session()->getFlashdata('error')) ?></div>
<?php endif; ?>
<div class="cb-table-shell">
<div class="table-responsive">
<table class="table cb-data-table align-middle">
<thead>
<tr>
<th>Name</th>
<th>Data Source</th>
<th>Type</th>
<th>Updated</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
<?php if ($queries === []): ?>
<tr>
<td colspan="5" class="text-center text-muted py-5">No queries saved yet. Create your first query.</td>
</tr>
<?php endif; ?>
<?php foreach ($queries as $query): ?>
<?php
$qType = strtoupper((string) $query['query_type']);
$typeClass = match ($qType) {
'API' => 'cb-badge-type--api',
'VISUAL' => 'cb-badge-type--visual',
default => 'cb-badge-type--sql',
};
?>
<tr>
<td>
<div class="cb-cell-name"><?= esc($query['name']) ?></div>
<div class="cb-cell-sub"><?= esc($query['description'] ?: 'No description') ?></div>
</td>
<td><?= esc($query['data_source_name'] ?: '-') ?></td>
<td><span class="cb-badge-type <?= esc($typeClass, 'attr') ?>"><?= esc($qType) ?></span></td>
<td class="text-muted small"><?= esc($query['updated_at'] ?? '-') ?></td>
<td class="text-end">
<div class="cb-table-actions">
<a href="<?= base_url('query/view/' . (int) $query['id']) ?>" class="cb-action-btn cb-action-btn--ghost">View</a>
<a href="<?= base_url('query/edit/' . (int) $query['id']) ?>" class="cb-action-btn cb-action-btn--edit">Edit</a>
<a href="<?= base_url('query/edit/' . (int) $query['id']) ?>#test" class="cb-action-btn cb-action-btn--test" title="Test with variables">Test</a>
<a href="<?= base_url('chart/create?query=' . (int) $query['id']) ?>" class="cb-action-btn cb-action-btn--chart" title="Build chart from this query">Chart</a>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?= $this->endSection() ?>