Files
Solis/internal/server/templates/shortener.html
T
2026-05-21 02:11:11 -07:00

144 lines
8.5 KiB
HTML

{{define "title"}}Solis | URL Shortener{{end}}
{{define "content"}}
<div class="page-header">
<div class="page-title">
<h1>URL Shortener</h1>
<p>Manage custom manual redirects (e.g. warranties, external manuals) or review auto-generated asset short URLs.</p>
</div>
</div>
<div class="detail-grid">
<!-- Left Column: Links List -->
<div class="detail-main">
<div class="card" style="padding: 0;">
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th>Slug</th>
<th>Target URL</th>
<th>Link Type</th>
<th style="width: 80px; text-align: center;">Clicks</th>
<th style="width: 120px; text-align: right;">Actions</th>
</tr>
</thead>
<tbody>
{{if .Links}}
{{range .Links}}
<tr>
<td>
<div style="display: flex; flex-direction: column; gap: 0.15rem;">
<a href="/s/{{.Slug}}" target="_blank" style="font-weight: 700; color: var(--color-brand-primary); text-decoration: none;">
/s/{{.Slug}}
</a>
<!-- QR code link quick view in printer sheet -->
<a href="/admin/qr/{{.Slug}}" target="_blank" style="font-size: 0.75rem; color: var(--color-text-light); text-decoration: underline;">
View QR Code
</a>
</div>
</td>
<td>
<div style="max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: monospace; font-size: 0.85rem;" title="{{.URL}}">
{{.URL}}
</div>
</td>
<td>
{{if .ItemID.Valid}}
<span style="font-size: 0.8rem; font-weight: 600; color:#065f46; background-color:#d1fae5; padding: 0.2rem 0.5rem; border-radius: 4px;">
Asset #{{.ItemID.Int64}} Link
</span>
{{else}}
<span style="font-size: 0.8rem; font-weight: 600; color:#1e40af; background-color:#dbeafe; padding: 0.2rem 0.5rem; border-radius: 4px;">
Manual Redirect
</span>
{{end}}
</td>
<td style="text-align: center; font-weight: 600; font-size: 0.95rem; color: var(--color-text-muted);">
{{.Clicks}}
</td>
<td style="text-align: right;">
{{if .ItemID.Valid}}
<!-- Asset link modifications are handled through items CRUD -->
<span style="color: var(--color-text-light); font-size: 0.85rem; font-style: italic;">Managed by Asset</span>
{{else}}
<div style="display: inline-flex; gap: 0.5rem;">
<a href="/admin/shortener?edit={{.ID}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
Edit
</a>
<form action="/admin/shortener/delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to delete this custom redirect?')" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
Delete
</button>
</form>
</div>
{{end}}
</td>
</tr>
{{end}}
{{else}}
<tr>
<td colspan="5" style="text-align: center; color: var(--color-text-light); padding: 3rem 1rem;">
No short links recorded. Create a custom redirect on the right!
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
</div>
<!-- Right Column: Add/Edit Form -->
<div class="detail-sidebar">
<div class="card">
{{if .EditingLink}}
<h3 style="font-weight: 700; margin-bottom: 1.25rem;">Edit Redirect</h3>
<form action="/admin/shortener/edit/{{.EditingLink.ID}}" method="POST">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<div class="form-group">
<label for="slug" class="form-label">Short Slug</label>
<input type="text" id="slug" name="slug" class="form-control" value="{{.EditingLink.Slug}}" required>
</div>
<div class="form-group" style="margin-bottom: 1.75rem;">
<label for="url" class="form-label">Target Destination URL</label>
<input type="url" id="url" name="url" class="form-control" value="{{.EditingLink.URL}}" placeholder="e.g. https://brand.com/manual.pdf" required>
</div>
<div style="display: flex; gap: 0.5rem;">
<button type="submit" class="btn btn-primary" style="flex-grow: 1;">Save Changes</button>
<a href="/admin/shortener" class="btn btn-secondary">Cancel</a>
</div>
</form>
{{else}}
<h3 style="font-weight: 700; margin-bottom: 1.25rem;">Create Redirect</h3>
<form action="/admin/shortener/new" method="POST">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<div class="form-group">
<label for="slug" class="form-label">Custom Slug (Optional)</label>
<div style="display: flex; gap: 0.5rem;">
<input type="text" id="slug" name="slug" class="form-control" placeholder="e.g. warranty1" style="flex-grow:1;">
<button type="button" class="btn btn-secondary" style="padding: 0 0.75rem;" onclick="document.getElementById('slug').value = Math.random().toString(36).substring(2, 6)">
Auto
</button>
</div>
<span style="font-size: 0.75rem; color: var(--color-text-light); margin-top: 0.25rem; display: block;">Leave blank to generate a random 4-character slug.</span>
</div>
<div class="form-group" style="margin-bottom: 1.75rem;">
<label for="url" class="form-label">Destination URL</label>
<input type="url" id="url" name="url" class="form-control" placeholder="e.g. https://support.brand.com/warranty" required>
</div>
<button type="submit" class="btn btn-primary" style="width: 100%;">Add Redirect</button>
</form>
{{end}}
</div>
</div>
</div>
{{end}}