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:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-04 21:05:41 +03:00
1 parent d251ec73d0
commit dcc3d7f2d5
12 files changed
+315 -92

No files matched your search

+4
View File
@@ -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();
+152 -25
View File
@@ -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 */
+33
View File
@@ -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>
+64
View File
@@ -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 };
}
+3 -13
View File
@@ -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';
+3 -20
View File
@@ -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
+3 -19
View File
@@ -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 {
+3 -15
View File
@@ -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);
@@ -0,0 +1,28 @@
# Toast notifications (2026-10-04)
Goal: pop-up notifications in the bottom-right corner of the screen, readable in the light and the dark theme. Plan: [Toast_Notifications_PLAN](2026-10-04_Toast_Notifications_PLAN.md). UI only.
## Changes
| Area | Change |
|---|---|
| `composables/useToast.js` | Shared state: `show(text, type, timeout)`, `dismiss`, `pause`, `resume`; types `success`, `warning`, `error`, `info`; 5 s (errors 8 s); at most 4 on screen |
| `components/ToastContainer.vue` | Mounted once in `App.vue` (also on the Login page): icon, text, close button, progress bar; slide-in from the right; hover pauses the timer; `role="alert"` for errors, `role="status"` otherwise |
| `assets/main.css` | Fixed bottom-right stack above modals; surface from the theme variables, coloured stripe/icon/progress bar per type; separate colour tokens for the light and the dark theme; full width on phones; reduced motion supported. Old `.toast-message` styles removed |
| Views | `PKIConfig.vue`, `VPNConfig.vue`, `ServerManagement.vue`, `Certificates.vue` use the shared toast; their `showMessage` / `showToast` helpers are one-line wrappers, call sites unchanged; inline markup and local timers removed |
Not changed: SweetAlert2 dialogs in `Account.vue` and inline alerts on the Login page.
## Verification
`app-ui` image builds (Vite), the toast styles are in the bundle and the old ones are gone; appearance and behaviour (both themes, several toasts, hover pause, narrow window, toast over a modal) are checked manually.
## Notes
- Durations are unified: 5 s, errors 8 s (was 3 to 5 s).
- Toasts are global, so a message raised right before a route change stays visible after it.
- Touch devices have no hover: toasts there simply time out.
## Existing installations
Rebuild the UI image (`app-ui`); no configuration or data changes.
@@ -0,0 +1,20 @@
# Toast notifications: implementation plan (2026-10-04)
Goal: pop-up notifications appear in the bottom-right corner of the screen, are not lost, and look good in the light and dark themes. UI only.
## Current state
- Four views implement their own notification: `PKIConfig.vue`, `VPNConfig.vue`, `ServerManagement.vue` render `.toast-message` inside the page card (top of the page, scrolls away, one message at a time); `Certificates.vue` has its own fixed bottom-right copy with inline styles.
- Styles (`assets/main.css`, `.toast-message`, `.toast-success|warning|error`) use fixed light colours, no dark theme.
- `Account.vue` uses SweetAlert2 dialogs and `Login.vue` inline alerts: these are dialogs, not toasts, and stay as they are.
## Steps
1. `src/composables/useToast.js`: shared reactive list of toasts; `show(text, type = 'success', timeout)` with types `success | warning | error | info`; `dismiss(id)`. Default timeout 5 s (errors 8 s); max 4 on screen (oldest dropped).
2. `src/components/ToastContainer.vue`, mounted once in `App.vue`: fixed bottom-right (`z-index` above modals), stacked column, `TransitionGroup` slide-in from the right and fade-out; each toast has an icon, text, close button, thin progress bar; the timer pauses on hover; `role="status"` (`role="alert"` for errors) with `aria-live`; on phones full width at the bottom.
3. Design (`main.css`): card surface from existing variables (`--bg-card`, `--border-color`, `--text-main`), a coloured accent stripe and icon per type, soft shadow; separate colour tokens for the light and the dark theme (`[data-theme="dark"]`) so contrast stays readable in both. Old `.toast-message` styles are removed.
4. Views: `PKIConfig.vue`, `VPNConfig.vue`, `ServerManagement.vue`, `Certificates.vue` call `useToast().show(...)` (their `showMessage` / `showToast` helpers stay as thin wrappers, call sites are not changed); inline toast markup and local timers are removed.
5. Tests: none (no UI test infrastructure; no logic on the server side).
6. Verification: rebuild `app-ui` on the stand (port 8089) and check manually: all four pages, success / warning / error, several toasts at once, hover pause, close button, light and dark theme, narrow window, toast above an open modal (Certificates note save).
7. Documentation: summary `DOCS/Changes/2026-10-04_Toast_Notifications.md`, row in `README.md`, link in `DOCS/General/Index.md`.
## Out of scope
SweetAlert2 dialogs in `Account.vue`, inline login alerts, sound, persistent notification history.
+1
View File
@@ -21,6 +21,7 @@ Welcome to the documentation for the OpenVPN Monitor suite.
- [Egress via Hysteria2 (2026-09-30)](../Changes/2026-09-30_Egress_via_Hysteria2.md)
- [Profile notes (2026-10-04)](../Changes/2026-10-04_Profile_Notes.md)
- [Async PKI init (2026-10-04)](../Changes/2026-10-04_Async_PKI_Init.md)
- [Toast notifications (2026-10-04)](../Changes/2026-10-04_Toast_Notifications.md)
## 🔍 Core Monitoring (`APP_CORE`)
The core module responsible for log parsing, real-time statistics, and the primary API.
+1
View File
@@ -63,6 +63,7 @@ No default user is created. Seed the initial admin with `OVPMON_INITIAL_ADMIN_US
| 2026-09-30 | Route OpenVPN clients through a Hysteria2 tunnel to an exit node | [Egress via Hysteria2](DOCS/Changes/2026-09-30_Egress_via_Hysteria2.md) |
| 2026-10-04 | Certificates page: clickable rows, profile details modal with a saved note (`PUT /profiles/{id}/note`) | [Profile notes](DOCS/Changes/2026-10-04_Profile_Notes.md) (includes the compact modal and the note tooltip on the client name) |
| 2026-10-04 | PKI initialization runs in the background: status endpoint, progress on the PKI page, protection against a second start | [Async PKI init](DOCS/Changes/2026-10-04_Async_PKI_Init.md) |
| 2026-10-04 | Toast notifications moved to the bottom-right corner, shared component, light/dark themes | [Toast notifications](DOCS/Changes/2026-10-04_Toast_Notifications.md) |
## Notes