Files
OpenVPN-Monitoring-Simple/APP_UI/src/components/ProfileDetailsModal.vue
T

86 lines
3.1 KiB
Vue
Raw Normal View History

<template>
<BaseModal id="profileDetailsModal" title="Profile Details" ref="modal">
<template #header>
<div class="d-flex align-items-center gap-2 flex-wrap">
<h5 class="modal-title fw-bold mb-0" style="color: var(--text-heading);">{{ profile?.username }}</h5>
<span v-if="profile" class="status-badge" :class="status.cls">{{ status.label }}</span>
</div>
</template>
<template #body>
<div v-if="profile">
<dl class="profile-meta">
<dt>Created</dt>
<dd>{{ formatDate(profile.created_at) }}</dd>
<dt>Expires</dt>
<dd>{{ formatDate(profile.expiration_date) }}<span v-if="daysLabel" class="text-muted"> ({{ daysLabel }})</span></dd>
<template v-if="profile.revoked_at">
<dt>Revoked</dt>
<dd>{{ formatDate(profile.revoked_at) }}</dd>
</template>
<dt>File</dt>
<dd class="certificate-file text-muted small text-break mt-0">{{ profile.file_path || 'N/A' }}</dd>
</dl>
<label for="profileNote" class="form-label small text-muted text-uppercase fw-bold">Note</label>
<textarea class="form-control" id="profileNote" rows="3" maxlength="1000" v-model="note" placeholder="Add a note about this profile..."></textarea>
<div class="form-text text-end">{{ note.length }} / 1000</div>
</div>
</template>
<template #footer>
<button type="button" class="btn-action btn-action-secondary" @click="close">Close</button>
<button type="button" class="btn-action btn-action-save" @click="save" :disabled="!dirty">Save</button>
</template>
</BaseModal>
</template>
<script setup>
import { ref, computed } from 'vue';
import BaseModal from './BaseModal.vue';
const emit = defineEmits(['save']);
const modal = ref(null);
const profile = ref(null);
const note = ref('');
const dirty = computed(() => note.value !== (profile.value?.note || ''));
const status = computed(() => {
const p = profile.value;
if (p?.is_revoked) return { label: 'Revoked', cls: 'status-expired' };
if (p?.is_expired) return { label: 'Expired', cls: 'status-expired' };
if (p?.days_remaining != null && p.days_remaining <= 30) return { label: 'Expiring Soon', cls: 'status-warning' };
return { label: 'Active', cls: 'status-valid' };
});
const daysLabel = computed(() => {
const days = profile.value?.days_remaining;
if (days == null) return '';
return days > 0 ? `${days} d` : 'expired';
});
// YYYY-MM-DD HH:mm (local time)
const formatDate = (dateStr) => {
if (!dateStr) return 'N/A';
const d = new Date(dateStr);
if (isNaN(d)) return dateStr;
const pad = (n) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
};
const open = (p) => {
profile.value = p;
note.value = p.note || '';
modal.value.show();
};
const close = () => {
modal.value.hide();
};
const save = () => {
emit('save', { id: profile.value.id, note: note.value });
close();
};
defineExpose({ open, close });
</script>