UI: shared toast notifications in the bottom-right corner
- useToast composable and ToastContainer (mounted once in App.vue): stacked toasts with icon, close button and progress bar, hover pause, slide-in animation, aria roles, full width on phones. - Light and dark theme colour tokens; old .toast-message styles removed. - PKIConfig, VPNConfig, ServerManagement and Certificates use the shared toast through thin showMessage/showToast wrappers. - Docs: plan and summary in DOCS/Changes, README, Index. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d251ec73d0
commit
dcc3d7f2d5
12 files changed
+316
-93
No files matched your search
@@ -118,6 +118,9 @@
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<!-- Shared toasts: outside the v-if/v-else pair so they also work on the Login page -->
|
||||
<ToastContainer />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -125,6 +128,7 @@ import { ref, onMounted, watch, computed } from 'vue';
|
||||
import { useAppConfig } from './composables/useAppConfig';
|
||||
import { useApi } from './composables/useApi';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import ToastContainer from './components/ToastContainer.vue';
|
||||
|
||||
const { loadConfig, isLoaded } = useAppConfig();
|
||||
const { apiClient } = useApi();
|
||||
|
||||
+153
-26
@@ -1616,42 +1616,169 @@ input[type="number"].config-input {
|
||||
appearance: textfield;
|
||||
}
|
||||
|
||||
/* Messages / Toast */
|
||||
.toast-message {
|
||||
padding: 14px 22px;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin-bottom: 20px;
|
||||
/* Toast notifications (ToastContainer.vue) */
|
||||
:root {
|
||||
--toast-success: #1a7f37;
|
||||
--toast-warning: #9a6700;
|
||||
--toast-error: #cf222e;
|
||||
--toast-info: #0969da;
|
||||
--toast-shadow: 0 8px 24px rgba(31, 35, 40, 0.14), 0 1px 3px rgba(31, 35, 40, 0.08);
|
||||
}
|
||||
|
||||
[data-theme="dark"] {
|
||||
--toast-success: #3fb950;
|
||||
--toast-warning: #d29922;
|
||||
--toast-error: #f85149;
|
||||
--toast-info: #58a6ff;
|
||||
--toast-shadow: 0 8px 24px rgba(1, 4, 9, 0.6), 0 0 0 1px rgba(240, 246, 252, 0.04);
|
||||
}
|
||||
|
||||
.toast-stack {
|
||||
position: fixed;
|
||||
right: 20px;
|
||||
bottom: 20px;
|
||||
z-index: 2000; /* above Bootstrap modals (1055) and backdrop (1050) */
|
||||
width: 380px;
|
||||
max-width: calc(100vw - 32px);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.toast-stack-list {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.app-toast {
|
||||
--toast-color: var(--toast-info);
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
width: 100%;
|
||||
padding: 12px 10px 14px 14px;
|
||||
overflow: hidden;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border-color);
|
||||
border-left: 4px solid var(--toast-color);
|
||||
border-radius: 8px;
|
||||
box-shadow: var(--toast-shadow);
|
||||
color: var(--text-main);
|
||||
font-size: 14px;
|
||||
line-height: 1.45;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.app-toast-success { --toast-color: var(--toast-success); }
|
||||
.app-toast-warning { --toast-color: var(--toast-warning); }
|
||||
.app-toast-error { --toast-color: var(--toast-error); }
|
||||
.app-toast-info { --toast-color: var(--toast-info); }
|
||||
|
||||
.app-toast-icon {
|
||||
flex: 0 0 auto;
|
||||
margin-top: 2px;
|
||||
font-size: 16px;
|
||||
color: var(--toast-color);
|
||||
}
|
||||
|
||||
.app-toast-text {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
color: var(--text-heading);
|
||||
font-weight: 500;
|
||||
overflow-wrap: anywhere;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.app-toast-close {
|
||||
flex: 0 0 auto;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
padding: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
border-radius: 4px;
|
||||
color: var(--text-muted);
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.15s ease, color 0.15s ease;
|
||||
}
|
||||
|
||||
.app-toast-close:hover,
|
||||
.app-toast-close:focus-visible {
|
||||
background: var(--bg-element-hover);
|
||||
color: var(--text-heading);
|
||||
}
|
||||
|
||||
.app-toast-progress {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
height: 3px;
|
||||
background: var(--toast-color);
|
||||
opacity: 0.55;
|
||||
transform-origin: left center;
|
||||
animation: toast-progress linear forwards;
|
||||
}
|
||||
|
||||
.app-toast:hover .app-toast-progress {
|
||||
animation-play-state: paused;
|
||||
}
|
||||
|
||||
@keyframes toast-progress {
|
||||
from { transform: scaleX(1); }
|
||||
to { transform: scaleX(0); }
|
||||
}
|
||||
|
||||
.toast-enter-active,
|
||||
.toast-leave-active {
|
||||
transition: transform 0.28s ease, opacity 0.28s ease;
|
||||
}
|
||||
|
||||
.toast-leave-active {
|
||||
position: absolute; /* keeps its place while siblings slide into the gap */
|
||||
}
|
||||
|
||||
.toast-move {
|
||||
transition: transform 0.28s ease;
|
||||
}
|
||||
|
||||
.toast-enter-from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
transition: all 0.3s ease;
|
||||
transform: translateX(40px);
|
||||
}
|
||||
|
||||
.toast-message.show {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
.toast-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateX(20px);
|
||||
}
|
||||
|
||||
.toast-success {
|
||||
background-color: #d1fae5;
|
||||
color: #065f46;
|
||||
border-left: 4px solid #10b981;
|
||||
@media (max-width: 576px) {
|
||||
.toast-stack {
|
||||
right: 16px;
|
||||
left: 16px;
|
||||
bottom: 16px;
|
||||
width: auto;
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
.toast-warning {
|
||||
background-color: #fef3c7;
|
||||
color: #92400e;
|
||||
border-left: 4px solid #f59e0b;
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.toast-enter-active,
|
||||
.toast-leave-active,
|
||||
.toast-move {
|
||||
transition: opacity 0.15s ease;
|
||||
}
|
||||
|
||||
.toast-error {
|
||||
background-color: #fee2e2;
|
||||
color: #991b1b;
|
||||
border-left: 4px solid #ef4444;
|
||||
.toast-enter-from,
|
||||
.toast-leave-to {
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Animations */
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<template>
|
||||
<div class="toast-stack">
|
||||
<TransitionGroup name="toast" tag="div" class="toast-stack-list">
|
||||
<div v-for="t in toasts" :key="t.id" class="app-toast" :class="'app-toast-' + t.type"
|
||||
:role="t.type === 'error' ? 'alert' : 'status'"
|
||||
:aria-live="t.type === 'error' ? 'assertive' : 'polite'" aria-atomic="true"
|
||||
@mouseenter="pause(t.id)" @mouseleave="resume(t.id)">
|
||||
<i class="fas app-toast-icon" :class="ICONS[t.type]" aria-hidden="true"></i>
|
||||
<div class="app-toast-text">{{ t.text }}</div>
|
||||
<button type="button" class="app-toast-close" aria-label="Close notification" @click="dismiss(t.id)">
|
||||
<i class="fas fa-times" aria-hidden="true"></i>
|
||||
</button>
|
||||
<div v-if="t.timeout > 0" class="app-toast-progress" :style="{ animationDuration: t.timeout + 'ms' }"></div>
|
||||
</div>
|
||||
</TransitionGroup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onBeforeUnmount } from 'vue';
|
||||
import { useToast } from '../composables/useToast';
|
||||
|
||||
const { toasts, dismiss, pause, resume, clear } = useToast();
|
||||
|
||||
const ICONS = {
|
||||
success: 'fa-check-circle',
|
||||
warning: 'fa-exclamation-triangle',
|
||||
error: 'fa-exclamation-circle',
|
||||
info: 'fa-info-circle'
|
||||
};
|
||||
|
||||
onBeforeUnmount(clear);
|
||||
</script>
|
||||
@@ -0,0 +1,64 @@
|
||||
import { reactive } from 'vue';
|
||||
|
||||
const MAX_VISIBLE = 4;
|
||||
const DEFAULT_TIMEOUT = 5000;
|
||||
const ERROR_TIMEOUT = 8000;
|
||||
|
||||
// Module-level state: every caller (views, ToastContainer) shares the same list
|
||||
const toasts = reactive([]);
|
||||
const timers = new Map(); // id -> { handle, startedAt, remaining }
|
||||
let nextId = 1;
|
||||
|
||||
const clearTimer = (id) => {
|
||||
const t = timers.get(id);
|
||||
if (t) clearTimeout(t.handle);
|
||||
timers.delete(id);
|
||||
};
|
||||
|
||||
const dismiss = (id) => {
|
||||
clearTimer(id);
|
||||
const idx = toasts.findIndex((t) => t.id === id);
|
||||
if (idx !== -1) toasts.splice(idx, 1);
|
||||
};
|
||||
|
||||
const startTimer = (id, ms) => {
|
||||
clearTimer(id);
|
||||
timers.set(id, { handle: setTimeout(() => dismiss(id), ms), startedAt: Date.now(), remaining: ms });
|
||||
};
|
||||
|
||||
// Stop the countdown (mouse over the toast); the progress bar is paused by CSS
|
||||
const pause = (id) => {
|
||||
const t = timers.get(id);
|
||||
if (!t) return;
|
||||
clearTimeout(t.handle);
|
||||
t.remaining = Math.max(0, t.remaining - (Date.now() - t.startedAt));
|
||||
t.handle = null;
|
||||
};
|
||||
|
||||
const resume = (id) => {
|
||||
const t = timers.get(id);
|
||||
if (!t || t.handle !== null) return;
|
||||
startTimer(id, t.remaining);
|
||||
};
|
||||
|
||||
const show = (text, type = 'success', timeout) => {
|
||||
const kind = ['success', 'warning', 'error', 'info'].includes(type) ? type : 'info';
|
||||
const duration = timeout ?? (kind === 'error' ? ERROR_TIMEOUT : DEFAULT_TIMEOUT);
|
||||
const id = nextId++;
|
||||
|
||||
toasts.push({ id, text: String(text ?? ''), type: kind, timeout: duration });
|
||||
while (toasts.length > MAX_VISIBLE) dismiss(toasts[0].id);
|
||||
if (duration > 0) startTimer(id, duration);
|
||||
return id;
|
||||
};
|
||||
|
||||
// Drop everything and release all timers (container unmount)
|
||||
const clear = () => {
|
||||
timers.forEach((t) => clearTimeout(t.handle));
|
||||
timers.clear();
|
||||
toasts.splice(0, toasts.length);
|
||||
};
|
||||
|
||||
export function useToast() {
|
||||
return { toasts, show, dismiss, pause, resume, clear };
|
||||
}
|
||||
@@ -147,11 +147,6 @@
|
||||
<NewClientModal ref="newClientModal" @create="createClient" />
|
||||
<ConfirmModal ref="confirmModal" @confirm="confirmRevoke" />
|
||||
<ProfileDetailsModal ref="detailsModal" @save="saveNote" />
|
||||
|
||||
<div v-if="toastMessage" class="toast-message show" :class="'toast-' + toastType" style="position: fixed; bottom: 20px; right: 20px; z-index: 9999;">
|
||||
<i class="fas" :class="toastType === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle'"></i>
|
||||
{{ toastMessage }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -161,8 +156,10 @@ import NewClientModal from '../components/NewClientModal.vue';
|
||||
import ConfirmModal from '../components/ConfirmModal.vue';
|
||||
import ProfileDetailsModal from '../components/ProfileDetailsModal.vue';
|
||||
import vNoteTooltip from '../directives/noteTooltip';
|
||||
import { useToast } from '../composables/useToast';
|
||||
|
||||
const { profilesApiClient } = useApi();
|
||||
const toast = useToast();
|
||||
|
||||
const loading = ref(true);
|
||||
const allProfiles = ref([]);
|
||||
@@ -172,14 +169,7 @@ const hideExpired = ref(false);
|
||||
const newClientModal = ref(null);
|
||||
const confirmModal = ref(null);
|
||||
const detailsModal = ref(null);
|
||||
const toastMessage = ref('');
|
||||
const toastType = ref('success');
|
||||
|
||||
const showToast = (msg, type = 'success') => {
|
||||
toastMessage.value = msg;
|
||||
toastType.value = type;
|
||||
setTimeout(() => toastMessage.value = '', 3000);
|
||||
};
|
||||
const showToast = (msg, type = 'success') => toast.show(msg, type);
|
||||
|
||||
const formatDate = (dateStr) => {
|
||||
if (!dateStr) return 'N/A';
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
<h1>PKI Infrastructure Configuration</h1>
|
||||
</div>
|
||||
|
||||
<div v-if="message.text" :class="['toast-message', 'toast-' + message.type, 'show']">
|
||||
<i :class="['fas', message.icon]"></i> {{ message.text }}
|
||||
</div>
|
||||
|
||||
<form @submit.prevent="handleSave">
|
||||
<div class="config-row">
|
||||
<div class="config-col">
|
||||
@@ -176,8 +172,10 @@
|
||||
import { ref, computed, onMounted, onUnmounted, reactive } from 'vue';
|
||||
|
||||
import { useApi } from '../composables/useApi';
|
||||
import { useToast } from '../composables/useToast';
|
||||
|
||||
const { profilesApiClient } = useApi();
|
||||
const toast = useToast();
|
||||
|
||||
// State
|
||||
const form = reactive({
|
||||
@@ -198,12 +196,6 @@ const form = reactive({
|
||||
easyrsa_batch: true
|
||||
});
|
||||
|
||||
const message = reactive({
|
||||
text: '',
|
||||
type: 'success', // success, warning, error (mapped to css classes)
|
||||
icon: 'fa-check-circle'
|
||||
});
|
||||
|
||||
const isLoading = ref(false);
|
||||
const action = ref(''); // 'save', 'init', 'clear'
|
||||
|
||||
@@ -225,16 +217,7 @@ const stepText = computed(() => STEP_TEXTS[initStatus.step] || 'Initializing PKI
|
||||
let pollTimer = null;
|
||||
|
||||
// Methods
|
||||
const showMessage = (text, type = 'success') => {
|
||||
message.text = text;
|
||||
message.type = type;
|
||||
message.icon = type === 'success' ? 'fa-check-circle' : type === 'warning' ? 'fa-exclamation-triangle' : 'fa-exclamation-circle';
|
||||
|
||||
// Auto hide
|
||||
setTimeout(() => {
|
||||
message.text = '';
|
||||
}, 4000);
|
||||
};
|
||||
const showMessage = (text, type = 'success') => toast.show(text, type);
|
||||
|
||||
// API Fetch Wrapper
|
||||
// API Wrapper removed, using profilesApiClient directly
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
<h1>Server Process Management</h1>
|
||||
</div>
|
||||
|
||||
<div v-if="message.text" :class="['toast-message', 'toast-' + message.type, 'show']">
|
||||
<i :class="['fas', message.icon]"></i> {{ message.text }}
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Stats Grid -->
|
||||
<!-- User requested specific order: CPU (full), Status, PID, Memory, Uptime -->
|
||||
@@ -92,8 +88,10 @@
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted, onUnmounted } from 'vue';
|
||||
import { useApi } from '../composables/useApi';
|
||||
import { useToast } from '../composables/useToast';
|
||||
|
||||
const { profilesApiClient } = useApi();
|
||||
const toast = useToast();
|
||||
|
||||
// State
|
||||
const stats = reactive({
|
||||
@@ -104,26 +102,12 @@ const stats = reactive({
|
||||
uptime: null
|
||||
});
|
||||
|
||||
const message = reactive({
|
||||
text: '',
|
||||
type: 'success',
|
||||
icon: 'fa-check-circle'
|
||||
});
|
||||
|
||||
const isLoading = ref(false);
|
||||
const action = ref(''); // 'start', 'stop', 'restart'
|
||||
let pollInterval = null;
|
||||
|
||||
// Methods
|
||||
const showMessage = (text, type = 'success') => {
|
||||
message.text = text;
|
||||
message.type = type;
|
||||
message.icon = type === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle';
|
||||
|
||||
setTimeout(() => {
|
||||
message.text = '';
|
||||
}, 4000);
|
||||
};
|
||||
const showMessage = (text, type = 'success') => toast.show(text, type);
|
||||
|
||||
const fetchStats = async () => {
|
||||
try {
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
<h1>Server Infrastructure Configuration</h1>
|
||||
</div>
|
||||
|
||||
<div v-if="message.text" :class="['toast-message', 'toast-' + message.type, 'show']">
|
||||
<i :class="['fas', message.icon]"></i> {{ message.text }}
|
||||
</div>
|
||||
|
||||
<form @submit.prevent="handleSave">
|
||||
<!-- Basic Network -->
|
||||
<div class="config-row">
|
||||
@@ -257,8 +253,10 @@
|
||||
<script setup>
|
||||
import { ref, onMounted, reactive, watch } from 'vue';
|
||||
import { useApi } from '../composables/useApi';
|
||||
import { useToast } from '../composables/useToast';
|
||||
|
||||
const { profilesApiClient } = useApi();
|
||||
const toast = useToast();
|
||||
|
||||
// State
|
||||
const form = reactive({
|
||||
@@ -285,11 +283,6 @@ const form = reactive({
|
||||
|
||||
const isSplitTunnel = ref(false);
|
||||
|
||||
const message = reactive({
|
||||
text: '',
|
||||
type: 'success',
|
||||
icon: 'fa-check-circle'
|
||||
});
|
||||
const isLoading = ref(false);
|
||||
const action = ref('');
|
||||
|
||||
@@ -309,12 +302,7 @@ function maskToCidr(mask) {
|
||||
}
|
||||
|
||||
// Methods
|
||||
const showMessage = (text, type = 'success') => {
|
||||
message.text = text;
|
||||
message.type = type;
|
||||
message.icon = type === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle';
|
||||
setTimeout(() => message.text = '', 5000);
|
||||
};
|
||||
const showMessage = (text, type = 'success') => toast.show(text, type);
|
||||
|
||||
const addRoute = () => form.split_routes.push('');
|
||||
const removeRoute = (idx) => form.split_routes.splice(idx, 1);
|
||||
|
||||
Reference in new issue
Block a user