Implemented systems for editing training reports.
This commit is contained in:
@@ -34,16 +34,19 @@ import {
|
||||
} from '@/components/ui/pagination'
|
||||
import Tooltip from '@/components/tooltip/Tooltip.vue';
|
||||
import { CopyLink } from '@/lib/copyLink';
|
||||
import { useUserStore } from '@/stores/user';
|
||||
|
||||
enum sidePanelState { view, create, closed };
|
||||
enum sidePanelState { view, create, edit, closed };
|
||||
|
||||
const trainingReports = ref<CourseEventSummary[] | null>(null);
|
||||
const loaded = ref(false);
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const user = useUserStore();
|
||||
|
||||
const sidePanel = computed<sidePanelState>(() => {
|
||||
if (route.path.endsWith('/edit')) return sidePanelState.edit;
|
||||
if (route.path.endsWith('/new')) return sidePanelState.create;
|
||||
if (route.params.id) return sidePanelState.view;
|
||||
return sidePanelState.closed;
|
||||
@@ -110,6 +113,17 @@ async function openTrainingReport(id: number) {
|
||||
router.push(`/trainingReport/${id}`);
|
||||
}
|
||||
|
||||
async function openEditPanel() {
|
||||
if (!focusedTrainingReport.value) return;
|
||||
|
||||
if (isMobile.value) {
|
||||
mobilePanel.value = sidePanelState.edit;
|
||||
return;
|
||||
}
|
||||
|
||||
router.push(`/trainingReport/${focusedTrainingReport.value.id}/edit`);
|
||||
}
|
||||
|
||||
function openCreatePanel() {
|
||||
if (isMobile.value) {
|
||||
mobilePanel.value = sidePanelState.create;
|
||||
@@ -132,6 +146,17 @@ async function closePanel() {
|
||||
await closeTrainingReport();
|
||||
}
|
||||
|
||||
const canEditFocusedReport = computed<boolean>(() => {
|
||||
const report = focusedTrainingReport.value;
|
||||
if (!report) return false;
|
||||
|
||||
const actorId = user.user?.member?.member_id;
|
||||
const isAuthor = !!actorId && report.created_by === actorId;
|
||||
const isAdmin = user.hasRole('17th Administrator');
|
||||
|
||||
return isAuthor || isAdmin;
|
||||
});
|
||||
|
||||
const sortMode = ref<string>("descending");
|
||||
const searchString = ref<string>("");
|
||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
@@ -328,6 +353,9 @@ const expanded = ref<number>(null);
|
||||
<div class="flex justify-between items-center">
|
||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Training Report Details</p>
|
||||
<div class="flex items-center gap-2">
|
||||
<Button v-if="canEditFocusedReport" @click="openEditPanel" class="cursor-pointer" variant="outline" size="sm">
|
||||
Edit
|
||||
</Button>
|
||||
<Button v-if="isMobile" @click="closePanel" class="cursor-pointer" variant="outline" size="sm">
|
||||
<ChevronLeft class="size-4"></ChevronLeft> Back
|
||||
</Button>
|
||||
@@ -705,5 +733,33 @@ const expanded = ref<number>(null);
|
||||
</TrainingReportForm>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="focusedTrainingReport != null && effectivePanel == sidePanelState.edit" :class="isMobile ? 'fixed inset-0 z-[60] overflow-y-auto bg-background px-3 py-3' : 'mt-2 w-full max-w-5xl lg:mt-0 lg:w-3/5 lg:border-l lg:pl-7'"
|
||||
:style="isMobile ? { top: 'var(--app-header-height, 60px)' } : {}">
|
||||
<div class="flex justify-between items-center my-3">
|
||||
<div class="flex gap-5 lg:pl-2">
|
||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Edit Training Report</p>
|
||||
</div>
|
||||
<Button v-if="isMobile" @click="mobilePanel = sidePanelState.view" class="cursor-pointer" variant="outline" size="sm">
|
||||
<ChevronLeft class="size-4"></ChevronLeft> Back
|
||||
</Button>
|
||||
<Button v-else @click="router.push(`/trainingReport/${focusedTrainingReport.id}`)" class="cursor-pointer" variant="ghost" size="icon">
|
||||
<X class="size-6"></X>
|
||||
</Button>
|
||||
</div>
|
||||
<div :class="isMobile ? 'mt-3 pb-8' : 'overflow-y-auto max-h-[70vh] mt-5 scrollbar-themed'">
|
||||
<TrainingReportForm class="w-full lg:pl-2" mode="edit" :report-id="focusedTrainingReport.id"
|
||||
:report="focusedTrainingReport"
|
||||
@submit="async (id) => {
|
||||
await loadTrainingReports();
|
||||
await viewTrainingReport(id);
|
||||
|
||||
if (isMobile) {
|
||||
mobilePanel = sidePanelState.view;
|
||||
} else {
|
||||
router.push(`/trainingReport/${id}`);
|
||||
}
|
||||
}" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user