Compare commits
22 Commits
1.2.1
...
Qualificat
| Author | SHA1 | Date | |
|---|---|---|---|
| 7532436b9a | |||
| 0deb2ac316 | |||
| e672159c51 | |||
| cfbab75132 | |||
| b167135038 | |||
| 2db22f9955 | |||
| 93c8f3a35c | |||
| b64891c2a2 | |||
| a05b48cd4c | |||
| 191bc6f428 | |||
| 87bdd30a19 | |||
| bae5578afb | |||
| 676e09aef5 | |||
| b40e4f3ec7 | |||
| b4ff7d4686 | |||
| 171e3b3137 | |||
| dd2ac19e4a | |||
| 18ba9b576c | |||
| 6c85677e1b | |||
| 0e37a8bc9c | |||
| 045de2fe98 | |||
| a1ca07e6fd |
45
api/migrations/20260330120000-qualification-sync.js
Normal file
45
api/migrations/20260330120000-qualification-sync.js
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var dbm;
|
||||||
|
var type;
|
||||||
|
var seed;
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var Promise;
|
||||||
|
|
||||||
|
exports.setup = function(options, seedLink) {
|
||||||
|
dbm = options.dbmigrate;
|
||||||
|
type = dbm.dataType;
|
||||||
|
seed = seedLink;
|
||||||
|
Promise = options.Promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.up = function(db) {
|
||||||
|
var filePath = path.join(__dirname, 'sqls', '20260330120000-qualification-sync-up.sql');
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
fs.readFile(filePath, { encoding: 'utf-8' }, function(err, data) {
|
||||||
|
if (err) return reject(err);
|
||||||
|
console.log('received data: ' + data);
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
}).then(function(data) {
|
||||||
|
return db.runSql(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.down = function(db) {
|
||||||
|
var filePath = path.join(__dirname, 'sqls', '20260330120000-qualification-sync-down.sql');
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
fs.readFile(filePath, { encoding: 'utf-8' }, function(err, data) {
|
||||||
|
if (err) return reject(err);
|
||||||
|
console.log('received data: ' + data);
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
}).then(function(data) {
|
||||||
|
return db.runSql(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports._meta = {
|
||||||
|
version: 1,
|
||||||
|
};
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
ALTER TABLE members_qualifications
|
||||||
|
DROP FOREIGN KEY fk_members_qualifications_course_id,
|
||||||
|
DROP FOREIGN KEY fk_members_qualifications_awarded_by,
|
||||||
|
DROP FOREIGN KEY fk_members_qualifications_revoked_by,
|
||||||
|
DROP FOREIGN KEY fk_members_qualifications_source_event,
|
||||||
|
DROP KEY uq_members_qualifications_member_course,
|
||||||
|
DROP KEY idx_members_qualifications_active,
|
||||||
|
DROP KEY idx_members_qualifications_source_event,
|
||||||
|
DROP COLUMN course_id,
|
||||||
|
DROP COLUMN active,
|
||||||
|
DROP COLUMN awarded_by_id,
|
||||||
|
DROP COLUMN revoked_by_id,
|
||||||
|
DROP COLUMN revoked_reason,
|
||||||
|
DROP COLUMN revoked_at,
|
||||||
|
DROP COLUMN source_course_event_id,
|
||||||
|
ADD COLUMN qualification_id INT(11) DEFAULT 0,
|
||||||
|
ADD KEY fk_members_qualifications_qualifications_id (qualification_id),
|
||||||
|
ADD CONSTRAINT fk_members_qualifications_qualifications_id FOREIGN KEY (qualification_id) REFERENCES qualifications(id) ON UPDATE CASCADE;
|
||||||
18
api/migrations/sqls/20260330120000-qualification-sync-up.sql
Normal file
18
api/migrations/sqls/20260330120000-qualification-sync-up.sql
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
ALTER TABLE members_qualifications
|
||||||
|
DROP FOREIGN KEY fk_members_qualifications_qualifications_id,
|
||||||
|
DROP KEY fk_members_qualifications_qualifications_id,
|
||||||
|
DROP COLUMN qualification_id,
|
||||||
|
ADD COLUMN course_id INT(11) NOT NULL AFTER member_id,
|
||||||
|
ADD COLUMN active TINYINT(1) NOT NULL DEFAULT 1,
|
||||||
|
ADD COLUMN awarded_by_id INT(11) DEFAULT NULL,
|
||||||
|
ADD COLUMN revoked_by_id INT(11) DEFAULT NULL,
|
||||||
|
ADD COLUMN revoked_reason TEXT DEFAULT NULL,
|
||||||
|
ADD COLUMN revoked_at DATETIME DEFAULT NULL,
|
||||||
|
ADD COLUMN source_course_event_id INT(11) DEFAULT NULL,
|
||||||
|
ADD UNIQUE KEY uq_members_qualifications_member_course (member_id, course_id),
|
||||||
|
ADD KEY idx_members_qualifications_active (member_id, course_id, active),
|
||||||
|
ADD KEY idx_members_qualifications_source_event (source_course_event_id),
|
||||||
|
ADD CONSTRAINT fk_members_qualifications_course_id FOREIGN KEY (course_id) REFERENCES courses(id) ON UPDATE CASCADE,
|
||||||
|
ADD CONSTRAINT fk_members_qualifications_awarded_by FOREIGN KEY (awarded_by_id) REFERENCES members(id) ON UPDATE CASCADE,
|
||||||
|
ADD CONSTRAINT fk_members_qualifications_revoked_by FOREIGN KEY (revoked_by_id) REFERENCES members(id) ON UPDATE CASCADE,
|
||||||
|
ADD CONSTRAINT fk_members_qualifications_source_event FOREIGN KEY (source_course_event_id) REFERENCES course_events(id) ON UPDATE CASCADE;
|
||||||
@@ -11,7 +11,9 @@
|
|||||||
"dev": "tsc && tsc-alias && node ./built/api/src/index.js",
|
"dev": "tsc && tsc-alias && node ./built/api/src/index.js",
|
||||||
"prod": "tsc && tsc-alias && node ./built/api/src/index.js",
|
"prod": "tsc && tsc-alias && node ./built/api/src/index.js",
|
||||||
"build": "tsc && tsc-alias",
|
"build": "tsc && tsc-alias",
|
||||||
"seed": "node ./scripts/seed.js"
|
"seed": "node ./scripts/seed.js",
|
||||||
|
"backfill:qualifications:dry": "node ./scripts/backfillQualifications.js --dry-run",
|
||||||
|
"backfill:qualifications": "node ./scripts/backfillQualifications.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rsol/hashmig": "^1.0.7",
|
"@rsol/hashmig": "^1.0.7",
|
||||||
|
|||||||
237
api/scripts/backfillQualifications.js
Normal file
237
api/scripts/backfillQualifications.js
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
const dotenv = require("dotenv");
|
||||||
|
const path = require("path");
|
||||||
|
const mariadb = require("mariadb");
|
||||||
|
|
||||||
|
dotenv.config({ path: path.resolve(process.cwd(), ".env") });
|
||||||
|
|
||||||
|
const {
|
||||||
|
DB_HOST,
|
||||||
|
DB_PORT,
|
||||||
|
DB_USERNAME,
|
||||||
|
DB_PASSWORD,
|
||||||
|
DB_DATABASE,
|
||||||
|
} = process.env;
|
||||||
|
|
||||||
|
function parseArgs(argv) {
|
||||||
|
const args = {
|
||||||
|
dryRun: false,
|
||||||
|
actorId: null,
|
||||||
|
courseId: null,
|
||||||
|
memberId: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (let i = 2; i < argv.length; i++) {
|
||||||
|
const token = argv[i];
|
||||||
|
if (token === "--dry-run") {
|
||||||
|
args.dryRun = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token.startsWith("--actor=")) {
|
||||||
|
args.actorId = Number(token.split("=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token.startsWith("--course=")) {
|
||||||
|
args.courseId = Number(token.split("=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (token.startsWith("--member=")) {
|
||||||
|
args.memberId = Number(token.split("=")[1]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.actorId !== null && Number.isNaN(args.actorId)) {
|
||||||
|
throw new Error("--actor must be a number");
|
||||||
|
}
|
||||||
|
if (args.courseId !== null && Number.isNaN(args.courseId)) {
|
||||||
|
throw new Error("--course must be a number");
|
||||||
|
}
|
||||||
|
if (args.memberId !== null && Number.isNaN(args.memberId)) {
|
||||||
|
throw new Error("--member must be a number");
|
||||||
|
}
|
||||||
|
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildScopeClause(args, tableAlias = "") {
|
||||||
|
const prefix = tableAlias ? `${tableAlias}.` : "";
|
||||||
|
const clauses = [];
|
||||||
|
const params = [];
|
||||||
|
|
||||||
|
if (args.courseId !== null) {
|
||||||
|
clauses.push(`${prefix}course_id = ?`);
|
||||||
|
params.push(args.courseId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.memberId !== null) {
|
||||||
|
clauses.push(`${prefix}member_id = ?`);
|
||||||
|
params.push(args.memberId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!clauses.length) {
|
||||||
|
return { sql: "", params };
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
sql: ` AND ${clauses.join(" AND ")}`,
|
||||||
|
params,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function key(memberId, courseId) {
|
||||||
|
return `${memberId}:${courseId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
const args = parseArgs(process.argv);
|
||||||
|
|
||||||
|
const conn = await mariadb.createConnection({
|
||||||
|
host: DB_HOST,
|
||||||
|
port: Number(DB_PORT),
|
||||||
|
user: DB_USERNAME,
|
||||||
|
password: DB_PASSWORD,
|
||||||
|
database: DB_DATABASE,
|
||||||
|
multipleStatements: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const schemaCheck = await conn.query("SHOW COLUMNS FROM members_qualifications LIKE 'course_id';");
|
||||||
|
if (!schemaCheck.length) {
|
||||||
|
throw new Error("members_qualifications.course_id does not exist. Run qualification migration first.");
|
||||||
|
}
|
||||||
|
|
||||||
|
const scoped = buildScopeClause(args);
|
||||||
|
|
||||||
|
const passRows = await conn.query(
|
||||||
|
`SELECT
|
||||||
|
ca.attendee_id AS member_id,
|
||||||
|
e.course_id,
|
||||||
|
e.id AS course_event_id,
|
||||||
|
e.event_date
|
||||||
|
FROM course_events e
|
||||||
|
INNER JOIN course_attendees ca ON ca.course_event_id = e.id
|
||||||
|
WHERE ca.attendee_role_id = 2
|
||||||
|
AND (e.deleted IS NULL OR e.deleted = 0)
|
||||||
|
AND (
|
||||||
|
(e.hasBookwork = 1 AND e.hasQual = 1 AND ca.passed_bookwork = 1 AND ca.passed_qual = 1)
|
||||||
|
OR (e.hasBookwork = 1 AND IFNULL(e.hasQual, 0) = 0 AND ca.passed_bookwork = 1)
|
||||||
|
OR (IFNULL(e.hasBookwork, 0) = 0 AND e.hasQual = 1 AND ca.passed_qual = 1)
|
||||||
|
)
|
||||||
|
${scoped.sql}
|
||||||
|
ORDER BY ca.attendee_id ASC, e.course_id ASC, e.event_date DESC, e.id DESC;`,
|
||||||
|
scoped.params
|
||||||
|
);
|
||||||
|
|
||||||
|
const latestByPair = new Map();
|
||||||
|
for (const row of passRows) {
|
||||||
|
const mapKey = key(Number(row.member_id), Number(row.course_id));
|
||||||
|
if (!latestByPair.has(mapKey)) {
|
||||||
|
latestByPair.set(mapKey, {
|
||||||
|
memberId: Number(row.member_id),
|
||||||
|
courseId: Number(row.course_id),
|
||||||
|
courseEventId: Number(row.course_event_id),
|
||||||
|
eventDate: row.event_date,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentRows = await conn.query(
|
||||||
|
`SELECT member_id, course_id
|
||||||
|
FROM members_qualifications
|
||||||
|
WHERE active = 1
|
||||||
|
AND (deleted IS NULL OR deleted = 0)
|
||||||
|
${scoped.sql};`,
|
||||||
|
scoped.params
|
||||||
|
);
|
||||||
|
|
||||||
|
const currentKeys = new Set(currentRows.map((r) => key(Number(r.member_id), Number(r.course_id))));
|
||||||
|
const nextKeys = new Set(Array.from(latestByPair.keys()));
|
||||||
|
|
||||||
|
let wouldDeactivate = 0;
|
||||||
|
currentKeys.forEach((k) => {
|
||||||
|
if (!nextKeys.has(k)) {
|
||||||
|
wouldDeactivate++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const summary = {
|
||||||
|
dryRun: args.dryRun,
|
||||||
|
scope: {
|
||||||
|
memberId: args.memberId,
|
||||||
|
courseId: args.courseId,
|
||||||
|
},
|
||||||
|
actorId: args.actorId,
|
||||||
|
historicalPassingRows: passRows.length,
|
||||||
|
activePairsComputed: latestByPair.size,
|
||||||
|
currentlyActivePairs: currentRows.length,
|
||||||
|
wouldDeactivate,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (args.dryRun) {
|
||||||
|
console.log("Qualification backfill dry run summary:");
|
||||||
|
console.log(JSON.stringify(summary, null, 2));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await conn.beginTransaction();
|
||||||
|
|
||||||
|
const deactivateReason = "Backfill recompute from historical training reports";
|
||||||
|
|
||||||
|
const deactivateResult = await conn.query(
|
||||||
|
`UPDATE members_qualifications mq
|
||||||
|
SET mq.active = 0,
|
||||||
|
mq.revoked_by_id = ?,
|
||||||
|
mq.revoked_reason = ?,
|
||||||
|
mq.revoked_at = UTC_TIMESTAMP(),
|
||||||
|
mq.updated_at = current_timestamp()
|
||||||
|
WHERE mq.active = 1
|
||||||
|
AND (mq.deleted IS NULL OR mq.deleted = 0)
|
||||||
|
${buildScopeClause(args, "mq").sql};`,
|
||||||
|
[args.actorId, deactivateReason].concat(buildScopeClause(args, "mq").params)
|
||||||
|
);
|
||||||
|
|
||||||
|
let upserts = 0;
|
||||||
|
for (const item of latestByPair.values()) {
|
||||||
|
await conn.query(
|
||||||
|
`INSERT INTO members_qualifications
|
||||||
|
(member_id, course_id, event_date, active, awarded_by_id, revoked_by_id, revoked_reason, revoked_at, source_course_event_id, deleted)
|
||||||
|
VALUES (?, ?, ?, 1, ?, NULL, NULL, NULL, ?, 0)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
event_date = VALUES(event_date),
|
||||||
|
active = 1,
|
||||||
|
awarded_by_id = VALUES(awarded_by_id),
|
||||||
|
revoked_by_id = NULL,
|
||||||
|
revoked_reason = NULL,
|
||||||
|
revoked_at = NULL,
|
||||||
|
source_course_event_id = VALUES(source_course_event_id),
|
||||||
|
deleted = 0,
|
||||||
|
updated_at = current_timestamp();`,
|
||||||
|
[item.memberId, item.courseId, item.eventDate, args.actorId, item.courseEventId]
|
||||||
|
);
|
||||||
|
upserts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
await conn.commit();
|
||||||
|
|
||||||
|
console.log("Qualification backfill complete:");
|
||||||
|
console.log(JSON.stringify({
|
||||||
|
...summary,
|
||||||
|
deactivatedRows: deactivateResult.affectedRows,
|
||||||
|
upserts,
|
||||||
|
}, null, 2));
|
||||||
|
} catch (error) {
|
||||||
|
try {
|
||||||
|
await conn.rollback();
|
||||||
|
} catch (_ignored) {
|
||||||
|
// No-op rollback failure.
|
||||||
|
}
|
||||||
|
console.error("Qualification backfill failed:");
|
||||||
|
console.error(error);
|
||||||
|
process.exitCode = 1;
|
||||||
|
} finally {
|
||||||
|
await conn.end();
|
||||||
|
}
|
||||||
|
})();
|
||||||
@@ -396,11 +396,11 @@ VALUES(?, ?, ?, 1);`
|
|||||||
INNER JOIN members AS member ON member.id = app.poster_id
|
INNER JOIN members AS member ON member.id = app.poster_id
|
||||||
WHERE app.id = ?; `;
|
WHERE app.id = ?; `;
|
||||||
const comment = await conn.query(getSQL, [result.insertId])
|
const comment = await conn.query(getSQL, [result.insertId])
|
||||||
audit.record('application', 'comment_added', { actorId: user.id, targetId: appID }, { commentId: result.insertId });
|
audit.record('application', 'comment_added', { actorId: user.id, targetId: appID }, { commentId: Number(result.insertId) });
|
||||||
logger.info('app', "Admin application comment posted", {
|
logger.info('app', "Admin application comment posted", {
|
||||||
application: appID,
|
application: appID,
|
||||||
poster: user.id,
|
poster: user.id,
|
||||||
comment: result.insertId,
|
comment: Number(result.insertId),
|
||||||
})
|
})
|
||||||
|
|
||||||
res.status(201).json(comment[0]);
|
res.status(201).json(comment[0]);
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { CourseAttendee, CourseEventDetails } from "@app/shared/types/course";
|
import { CourseAttendee, CourseEventDetails } from "@app/shared/types/course";
|
||||||
import { getAllCourses, getCourseEventAttendees, getCourseEventDetails, getCourseEventRoles, getCourseEvents, insertCourseEvent } from "../services/db/CourseSerivce";
|
import { getAllCourses, getCourseEventAttendees, getCourseEventDetails, getCourseEventRoles, getCourseEvents, insertCourseEvent, updateCourseEvent } from "../services/db/CourseSerivce";
|
||||||
import { Request, Response, Router } from "express";
|
import { Request, Response, Router } from "express";
|
||||||
import { requireLogin, requireMemberState } from "../middleware/auth";
|
import { requireLogin, requireMemberState, requireRole } from "../middleware/auth";
|
||||||
import { MemberState } from "@app/shared/types/member";
|
import { MemberState } from "@app/shared/types/member";
|
||||||
import { logger } from "../services/logging/logger";
|
import { logger } from "../services/logging/logger";
|
||||||
import { audit } from "../services/logging/auditLog";
|
import { audit } from "../services/logging/auditLog";
|
||||||
|
import { syncQualificationsForCourseEvent } from "../services/db/qualificationService";
|
||||||
|
|
||||||
const cr = Router();
|
const cr = Router();
|
||||||
const er = Router();
|
const er = Router();
|
||||||
@@ -125,9 +126,10 @@ er.post('/', async (req: Request, res: Response) => {
|
|||||||
data.created_by = posterID;
|
data.created_by = posterID;
|
||||||
data.event_date = new Date(data.event_date);
|
data.event_date = new Date(data.event_date);
|
||||||
const id = await insertCourseEvent(data);
|
const id = await insertCourseEvent(data);
|
||||||
|
const syncOutcome = await syncQualificationsForCourseEvent(id, posterID);
|
||||||
|
|
||||||
audit.course('report_created', { actorId: posterID, targetId: id });
|
audit.course('report_created', { actorId: posterID, targetId: id }, { qualificationSync: syncOutcome });
|
||||||
logger.info('app', 'Training report posted', { user: posterID, report: id })
|
logger.info('app', 'Training report posted', { user: posterID, report: id, qualificationSync: syncOutcome })
|
||||||
res.status(201).json(id);
|
res.status(201).json(id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
@@ -143,5 +145,34 @@ er.post('/', async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
er.put('/:id', [requireLogin, requireMemberState(MemberState.Member), requireRole("dev")], async (req: Request, res: Response) => {
|
||||||
|
const editorID: number = req.user.id;
|
||||||
|
const reportId = Number(req.params.id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
let data: CourseEventDetails = req.body;
|
||||||
|
data.event_date = new Date(data.event_date);
|
||||||
|
|
||||||
|
await updateCourseEvent(reportId, data);
|
||||||
|
const syncOutcome = await syncQualificationsForCourseEvent(reportId, editorID);
|
||||||
|
|
||||||
|
audit.course('report_edited', { actorId: editorID, targetId: reportId }, { qualificationSync: syncOutcome });
|
||||||
|
logger.info('app', 'Training report edited', { user: editorID, report: reportId, qualificationSync: syncOutcome })
|
||||||
|
res.sendStatus(200);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(
|
||||||
|
'app',
|
||||||
|
'Failed to edit training report',
|
||||||
|
{
|
||||||
|
user: editorID,
|
||||||
|
report: reportId,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
res.status(500).json("failed to edit training\n" + error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
export const courseRouter = cr;
|
export const courseRouter = cr;
|
||||||
export const eventRouter = er;
|
export const eventRouter = er;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { memberCache } from './auth';
|
|||||||
import { cancelLatestRank } from '../services/db/rankService';
|
import { cancelLatestRank } from '../services/db/rankService';
|
||||||
import { cancelLatestUnit } from '../services/db/unitService';
|
import { cancelLatestUnit } from '../services/db/unitService';
|
||||||
import { audit } from '../services/logging/auditLog';
|
import { audit } from '../services/logging/auditLog';
|
||||||
|
import { getMemberActiveQualifications } from '../services/db/qualificationService';
|
||||||
|
|
||||||
//get all users
|
//get all users
|
||||||
router.get('/', [requireLogin, requireMemberState(MemberState.Member)], async (req, res) => {
|
router.get('/', [requireLogin, requireMemberState(MemberState.Member)], async (req, res) => {
|
||||||
@@ -211,6 +212,27 @@ router.post('/full/bulk', async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.get('/:id/qualifications', [requireLogin, requireMemberState(MemberState.Member)], async (req: Request, res: Response) => {
|
||||||
|
const memberId = Number(req.params.id);
|
||||||
|
if (Number.isNaN(memberId) || memberId <= 0) {
|
||||||
|
return res.status(400).json({ error: 'Invalid member id' });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const qualifications = await getMemberActiveQualifications(memberId);
|
||||||
|
return res.status(200).json(qualifications);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('app', 'Failed to fetch member qualifications', {
|
||||||
|
memberId,
|
||||||
|
caller: req.user?.id,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(500).json({ error: 'Failed to fetch member qualifications' });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
router.post('/cache/user/bust', [requireLogin, requireMemberState(MemberState.Member), requireRole('dev')], async (req: Request, res: Response) => {
|
router.post('/cache/user/bust', [requireLogin, requireMemberState(MemberState.Member), requireRole('dev')], async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
const clearedEntries = memberCache.Clear();
|
const clearedEntries = memberCache.Clear();
|
||||||
|
|||||||
@@ -161,3 +161,48 @@ export async function getCourseEventRoles(): Promise<CourseAttendeeRole[]> {
|
|||||||
const roles: CourseAttendeeRole[] = await pool.query(sql);
|
const roles: CourseAttendeeRole[] = await pool.query(sql);
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateCourseEvent(eventId: number, event: CourseEventDetails): Promise<void> {
|
||||||
|
try {
|
||||||
|
var con = await pool.getConnection();
|
||||||
|
|
||||||
|
let course: Course = await getCourseByID(event.course_id);
|
||||||
|
|
||||||
|
await con.beginTransaction();
|
||||||
|
|
||||||
|
await con.query(
|
||||||
|
`UPDATE course_events
|
||||||
|
SET course_id = ?,
|
||||||
|
event_date = ?,
|
||||||
|
remarks = ?,
|
||||||
|
hasBookwork = ?,
|
||||||
|
hasQual = ?
|
||||||
|
WHERE id = ?;`,
|
||||||
|
[event.course_id, toDateTime(event.event_date), event.remarks, course.hasBookwork, course.hasQual, eventId]
|
||||||
|
);
|
||||||
|
|
||||||
|
await con.query(`DELETE FROM course_attendees WHERE course_event_id = ?;`, [eventId]);
|
||||||
|
|
||||||
|
for (const attendee of event.attendees) {
|
||||||
|
await con.query(
|
||||||
|
`INSERT INTO course_attendees (
|
||||||
|
attendee_id,
|
||||||
|
course_event_id,
|
||||||
|
attendee_role_id,
|
||||||
|
passed_bookwork,
|
||||||
|
passed_qual,
|
||||||
|
remarks
|
||||||
|
)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?);`,
|
||||||
|
[attendee.attendee_id, eventId, attendee.attendee_role_id, attendee.passed_bookwork, attendee.passed_qual, attendee.remarks]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await con.commit();
|
||||||
|
} catch (error) {
|
||||||
|
if (con) await con.rollback();
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
if (con) await con.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
283
api/src/services/db/qualificationService.ts
Normal file
283
api/src/services/db/qualificationService.ts
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
import pool from "../../db";
|
||||||
|
import { CourseAttendee } from "@app/shared/types/course";
|
||||||
|
import { MemberQualificationView } from "@app/shared/types/qualification";
|
||||||
|
|
||||||
|
interface EventQualificationContext {
|
||||||
|
courseId: number;
|
||||||
|
eventDate: Date;
|
||||||
|
hasBookwork: boolean;
|
||||||
|
hasQual: boolean;
|
||||||
|
attendees: CourseAttendee[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SyncOutcome {
|
||||||
|
courseId: number | null;
|
||||||
|
awarded: number;
|
||||||
|
deactivated: number;
|
||||||
|
impactedMembers: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getEventQualificationContext(con: any, courseEventId: number): Promise<EventQualificationContext | null> {
|
||||||
|
const eventRows = await con.query(
|
||||||
|
`SELECT e.event_date, e.hasBookwork, e.hasQual, c.id AS course_id
|
||||||
|
FROM course_events e
|
||||||
|
INNER JOIN courses c ON c.id = e.course_id
|
||||||
|
WHERE e.id = ?;`,
|
||||||
|
[courseEventId]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!eventRows.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const attendeeRows = await con.query(
|
||||||
|
`SELECT
|
||||||
|
ca.passed_bookwork,
|
||||||
|
ca.passed_qual,
|
||||||
|
ca.attendee_id,
|
||||||
|
ca.course_event_id,
|
||||||
|
ca.attendee_role_id,
|
||||||
|
ca.created_at,
|
||||||
|
ca.updated_at,
|
||||||
|
ca.remarks,
|
||||||
|
mem.name AS attendee_name,
|
||||||
|
ar.id AS role_id,
|
||||||
|
ar.name AS role_name,
|
||||||
|
ar.description AS role_description,
|
||||||
|
ar.deleted AS role_deleted,
|
||||||
|
ar.created_at AS role_created_at,
|
||||||
|
ar.updated_at AS role_updated_at
|
||||||
|
FROM course_attendees ca
|
||||||
|
LEFT JOIN members mem ON ca.attendee_id = mem.id
|
||||||
|
LEFT JOIN course_attendee_roles ar ON ca.attendee_role_id = ar.id
|
||||||
|
WHERE ca.course_event_id = ?;`,
|
||||||
|
[courseEventId]
|
||||||
|
);
|
||||||
|
|
||||||
|
const attendees: CourseAttendee[] = attendeeRows.map((row: any) => ({
|
||||||
|
passed_bookwork: !!row.passed_bookwork,
|
||||||
|
passed_qual: !!row.passed_qual,
|
||||||
|
attendee_id: row.attendee_id,
|
||||||
|
course_event_id: row.course_event_id,
|
||||||
|
attendee_role_id: row.attendee_role_id,
|
||||||
|
created_at: new Date(row.created_at),
|
||||||
|
updated_at: new Date(row.updated_at),
|
||||||
|
remarks: row.remarks,
|
||||||
|
attendee_name: row.attendee_name,
|
||||||
|
role: row.role_id
|
||||||
|
? {
|
||||||
|
id: row.role_id,
|
||||||
|
name: row.role_name,
|
||||||
|
description: row.role_description,
|
||||||
|
deleted: !!row.role_deleted,
|
||||||
|
created_at: row.role_created_at ? new Date(row.role_created_at) : null,
|
||||||
|
updated_at: row.role_updated_at ? new Date(row.role_updated_at) : null,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
}));
|
||||||
|
|
||||||
|
return {
|
||||||
|
courseId: Number(eventRows[0].course_id),
|
||||||
|
eventDate: new Date(eventRows[0].event_date),
|
||||||
|
hasBookwork: !!eventRows[0].hasBookwork,
|
||||||
|
hasQual: !!eventRows[0].hasQual,
|
||||||
|
attendees,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function attendeePassed(attendee: CourseAttendee, hasBookwork: boolean, hasQual: boolean): boolean {
|
||||||
|
if (attendee.attendee_role_id !== 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasBookwork && hasQual) {
|
||||||
|
return attendee.passed_bookwork && attendee.passed_qual;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasBookwork && !hasQual) {
|
||||||
|
return attendee.passed_bookwork;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasBookwork && hasQual) {
|
||||||
|
return attendee.passed_qual;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getLatestPassingCourseEvent(con: any, memberId: number, courseId: number): Promise<{ course_event_id: number, event_date: Date } | null> {
|
||||||
|
const rows = await con.query(
|
||||||
|
`SELECT e.id AS course_event_id, e.event_date
|
||||||
|
FROM course_events e
|
||||||
|
INNER JOIN course_attendees ca ON ca.course_event_id = e.id
|
||||||
|
WHERE e.course_id = ?
|
||||||
|
AND ca.attendee_id = ?
|
||||||
|
AND ca.attendee_role_id = 2
|
||||||
|
AND (e.deleted IS NULL OR e.deleted = 0)
|
||||||
|
AND (
|
||||||
|
(e.hasBookwork = 1 AND e.hasQual = 1 AND ca.passed_bookwork = 1 AND ca.passed_qual = 1)
|
||||||
|
OR (e.hasBookwork = 1 AND IFNULL(e.hasQual, 0) = 0 AND ca.passed_bookwork = 1)
|
||||||
|
OR (IFNULL(e.hasBookwork, 0) = 0 AND e.hasQual = 1 AND ca.passed_qual = 1)
|
||||||
|
)
|
||||||
|
ORDER BY e.event_date DESC, e.id DESC
|
||||||
|
LIMIT 1;`,
|
||||||
|
[courseId, memberId]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!rows.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
course_event_id: Number(rows[0].course_event_id),
|
||||||
|
event_date: new Date(rows[0].event_date),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function syncQualificationsForCourseEvent(courseEventId: number, actorId: number, existingConnection: any | null = null): Promise<SyncOutcome> {
|
||||||
|
let con = existingConnection;
|
||||||
|
let ownConnection = false;
|
||||||
|
|
||||||
|
if (!con) {
|
||||||
|
con = await pool.getConnection();
|
||||||
|
ownConnection = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (ownConnection) {
|
||||||
|
await con.beginTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
const context = await getEventQualificationContext(con, courseEventId);
|
||||||
|
if (!context) {
|
||||||
|
if (ownConnection) {
|
||||||
|
await con.commit();
|
||||||
|
}
|
||||||
|
return { courseId: null, awarded: 0, deactivated: 0, impactedMembers: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!context.hasBookwork && !context.hasQual) {
|
||||||
|
if (ownConnection) {
|
||||||
|
await con.commit();
|
||||||
|
}
|
||||||
|
return { courseId: context.courseId, awarded: 0, deactivated: 0, impactedMembers: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
const expectedMembers = new Set<number>();
|
||||||
|
for (const attendee of context.attendees) {
|
||||||
|
if (attendeePassed(attendee, context.hasBookwork, context.hasQual)) {
|
||||||
|
expectedMembers.add(attendee.attendee_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const existingAwardedByThisEvent = await con.query(
|
||||||
|
`SELECT member_id
|
||||||
|
FROM members_qualifications
|
||||||
|
WHERE course_id = ?
|
||||||
|
AND source_course_event_id = ?
|
||||||
|
AND active = 1
|
||||||
|
AND (deleted IS NULL OR deleted = 0);`,
|
||||||
|
[context.courseId, courseEventId]
|
||||||
|
);
|
||||||
|
|
||||||
|
const existingMembers = new Set<number>(existingAwardedByThisEvent.map((row: any) => Number(row.member_id)));
|
||||||
|
|
||||||
|
const expectedMemberList = Array.from(expectedMembers);
|
||||||
|
const impactedMembers = new Set<number>(expectedMemberList.concat(Array.from(existingMembers)));
|
||||||
|
const impactedList = Array.from(impactedMembers);
|
||||||
|
|
||||||
|
let awarded = 0;
|
||||||
|
let deactivated = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < impactedList.length; i++) {
|
||||||
|
const memberId = impactedList[i];
|
||||||
|
const latestPass = await getLatestPassingCourseEvent(con, memberId, context.courseId);
|
||||||
|
|
||||||
|
if (latestPass) {
|
||||||
|
await con.query(
|
||||||
|
`INSERT INTO members_qualifications
|
||||||
|
(member_id, course_id, event_date, active, awarded_by_id, revoked_by_id, revoked_reason, revoked_at, source_course_event_id, deleted)
|
||||||
|
VALUES (?, ?, ?, 1, ?, NULL, NULL, NULL, ?, 0)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
event_date = VALUES(event_date),
|
||||||
|
active = 1,
|
||||||
|
awarded_by_id = VALUES(awarded_by_id),
|
||||||
|
revoked_by_id = NULL,
|
||||||
|
revoked_reason = NULL,
|
||||||
|
revoked_at = NULL,
|
||||||
|
source_course_event_id = VALUES(source_course_event_id),
|
||||||
|
deleted = 0,
|
||||||
|
updated_at = current_timestamp();`,
|
||||||
|
[memberId, context.courseId, latestPass.event_date, actorId, latestPass.course_event_id]
|
||||||
|
);
|
||||||
|
awarded++;
|
||||||
|
} else {
|
||||||
|
const result = await con.query(
|
||||||
|
`UPDATE members_qualifications
|
||||||
|
SET active = 0,
|
||||||
|
revoked_by_id = ?,
|
||||||
|
revoked_reason = ?,
|
||||||
|
revoked_at = UTC_TIMESTAMP(),
|
||||||
|
updated_at = current_timestamp()
|
||||||
|
WHERE member_id = ?
|
||||||
|
AND course_id = ?
|
||||||
|
AND active = 1;`,
|
||||||
|
[actorId, 'No passing record remains for this course after report reconciliation', memberId, context.courseId]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.affectedRows > 0) {
|
||||||
|
deactivated++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ownConnection) {
|
||||||
|
await con.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
courseId: context.courseId,
|
||||||
|
awarded,
|
||||||
|
deactivated,
|
||||||
|
impactedMembers: impactedMembers.size,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
if (ownConnection) {
|
||||||
|
await con.rollback();
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
if (ownConnection && con) {
|
||||||
|
await con.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMemberActiveQualifications(memberId: number): Promise<MemberQualificationView[]> {
|
||||||
|
const rows = await pool.query(
|
||||||
|
`SELECT
|
||||||
|
mq.course_id,
|
||||||
|
c.name AS course_name,
|
||||||
|
c.short_name AS course_short_name,
|
||||||
|
mq.event_date AS awarded_on,
|
||||||
|
mq.source_course_event_id,
|
||||||
|
mq.active
|
||||||
|
FROM members_qualifications mq
|
||||||
|
INNER JOIN courses c ON c.id = mq.course_id
|
||||||
|
WHERE mq.member_id = ?
|
||||||
|
AND mq.active = 1
|
||||||
|
AND (mq.deleted IS NULL OR mq.deleted = 0)
|
||||||
|
AND (c.deleted IS NULL OR c.deleted = 0)
|
||||||
|
ORDER BY mq.event_date DESC, c.name ASC;`,
|
||||||
|
[memberId]
|
||||||
|
);
|
||||||
|
|
||||||
|
return rows.map((row: any) => ({
|
||||||
|
course_id: row.course_id,
|
||||||
|
course_name: row.course_name,
|
||||||
|
course_short_name: row.course_short_name,
|
||||||
|
awarded_on: row.awarded_on ? new Date(row.awarded_on) : null,
|
||||||
|
active: !!row.active,
|
||||||
|
source_course_event_id: row.source_course_event_id,
|
||||||
|
}));
|
||||||
|
}
|
||||||
23
shared/types/qualification.ts
Normal file
23
shared/types/qualification.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
export interface MemberQualification {
|
||||||
|
id: number;
|
||||||
|
member_id: number;
|
||||||
|
course_id: number;
|
||||||
|
event_date: Date | null;
|
||||||
|
active: boolean;
|
||||||
|
awarded_by_id: number | null;
|
||||||
|
revoked_by_id: number | null;
|
||||||
|
revoked_reason: string | null;
|
||||||
|
revoked_at: Date | null;
|
||||||
|
source_course_event_id: number | null;
|
||||||
|
created_at: Date;
|
||||||
|
updated_at: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MemberQualificationView {
|
||||||
|
course_id: number;
|
||||||
|
course_name: string;
|
||||||
|
course_short_name: string;
|
||||||
|
awarded_on: Date | null;
|
||||||
|
active: boolean;
|
||||||
|
source_course_event_id: number | null;
|
||||||
|
}
|
||||||
@@ -6,8 +6,11 @@
|
|||||||
import AlertDescription from './components/ui/alert/AlertDescription.vue';
|
import AlertDescription from './components/ui/alert/AlertDescription.vue';
|
||||||
import Navbar from './components/Navigation/Navbar.vue';
|
import Navbar from './components/Navigation/Navbar.vue';
|
||||||
import { cancelLOA } from './api/loa';
|
import { cancelLOA } from './api/loa';
|
||||||
|
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
const headerRef = ref<HTMLDivElement | null>(null);
|
||||||
|
let resizeObserver: ResizeObserver | null = null;
|
||||||
|
|
||||||
function formatDate(dateStr) {
|
function formatDate(dateStr) {
|
||||||
if (!dateStr) return "";
|
if (!dateStr) return "";
|
||||||
@@ -22,6 +25,27 @@
|
|||||||
const environment = import.meta.env.VITE_ENVIRONMENT;
|
const environment = import.meta.env.VITE_ENVIRONMENT;
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
const version = import.meta.env.VITE_APPLICATION_VERSION;
|
const version = import.meta.env.VITE_APPLICATION_VERSION;
|
||||||
|
|
||||||
|
function updateHeaderHeight() {
|
||||||
|
if (!headerRef.value) return;
|
||||||
|
const height = headerRef.value.offsetHeight;
|
||||||
|
document.documentElement.style.setProperty('--app-header-height', `${height}px`);
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
updateHeaderHeight();
|
||||||
|
|
||||||
|
// Gracefully skip observer setup for environments that do not support ResizeObserver.
|
||||||
|
if (typeof ResizeObserver === 'undefined' || !headerRef.value) return;
|
||||||
|
|
||||||
|
resizeObserver = new ResizeObserver(updateHeaderHeight);
|
||||||
|
resizeObserver.observe(headerRef.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
resizeObserver?.disconnect();
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -29,7 +53,7 @@
|
|||||||
background-size: contain;
|
background-size: contain;
|
||||||
background-attachment: fixed;
|
background-attachment: fixed;
|
||||||
background-position: center;">
|
background-position: center;">
|
||||||
<div class="sticky top-0 bg-background z-50">
|
<div class="sticky top-0 bg-background z-50" ref="headerRef">
|
||||||
<Navbar class="flex"></Navbar>
|
<Navbar class="flex"></Navbar>
|
||||||
<Alert v-if="environment == 'dev'" class="m-2 mx-auto max-w-5xl" variant="info">
|
<Alert v-if="environment == 'dev'" class="m-2 mx-auto max-w-5xl" variant="info">
|
||||||
<AlertDescription class="flex flex-row items-center text-wrap gap-5 mx-auto">
|
<AlertDescription class="flex flex-row items-center text-wrap gap-5 mx-auto">
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Discharge } from "@shared/schemas/dischargeSchema";
|
import { Discharge } from "@shared/schemas/dischargeSchema";
|
||||||
import { memberSettings, Member, MemberLight, MemberCardDetails, PaginatedMembers, MemberState, UserCacheBustResult } from "@shared/types/member";
|
import { memberSettings, Member, MemberLight, MemberCardDetails, PaginatedMembers, MemberState, UserCacheBustResult } from "@shared/types/member";
|
||||||
|
import { MemberQualificationView } from "@shared/types/qualification";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const addr = import.meta.env.VITE_APIHOST;
|
const addr = import.meta.env.VITE_APIHOST;
|
||||||
@@ -117,6 +118,18 @@ export async function getFullMembers(ids: number[]): Promise<MemberCardDetails[]
|
|||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getMemberQualifications(memberID: number): Promise<MemberQualificationView[]> {
|
||||||
|
const response = await fetch(`${addr}/members/${memberID}/qualifications`, {
|
||||||
|
credentials: 'include',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch member qualifications");
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests for the given member to be discharged
|
* Requests for the given member to be discharged
|
||||||
* @param data discharge packet
|
* @param data discharge packet
|
||||||
|
|||||||
@@ -91,3 +91,19 @@ export async function postTrainingReport(report: CourseEventDetails) {
|
|||||||
|
|
||||||
return res.json(); // expected to return the inserted report or new ID
|
return res.json(); // expected to return the inserted report or new ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function putTrainingReport(reportId: number, report: CourseEventDetails): Promise<void> {
|
||||||
|
const res = await fetch(`${addr}/courseEvent/${reportId}`, {
|
||||||
|
method: "PUT",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(report),
|
||||||
|
credentials: 'include',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
const errorText = await res.text();
|
||||||
|
throw new Error(`Failed to update training report: ${res.status} ${errorText}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { RouterLink } from 'vue-router';
|
import { RouterLink, useRouter } from 'vue-router';
|
||||||
import Separator from '../ui/separator/Separator.vue';
|
import Separator from '../ui/separator/Separator.vue';
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
|
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover';
|
||||||
import {
|
import {
|
||||||
@@ -18,10 +18,11 @@ import NavigationMenuTrigger from '../ui/navigation-menu/NavigationMenuTrigger.v
|
|||||||
import NavigationMenuContent from '../ui/navigation-menu/NavigationMenuContent.vue';
|
import NavigationMenuContent from '../ui/navigation-menu/NavigationMenuContent.vue';
|
||||||
import { navigationMenuTriggerStyle } from '../ui/navigation-menu/'
|
import { navigationMenuTriggerStyle } from '../ui/navigation-menu/'
|
||||||
import { useAuth } from '@/composables/useAuth';
|
import { useAuth } from '@/composables/useAuth';
|
||||||
import { ArrowUpRight, CircleArrowOutUpRight } from 'lucide-vue-next';
|
import { ArrowUpRight, ChevronDown, ChevronUp, CircleArrowOutUpRight, LogIn, LogOut, Menu, Settings, X } from 'lucide-vue-next';
|
||||||
import DropdownMenuGroup from '../ui/dropdown-menu/DropdownMenuGroup.vue';
|
import DropdownMenuGroup from '../ui/dropdown-menu/DropdownMenuGroup.vue';
|
||||||
import DropdownMenuSeparator from '../ui/dropdown-menu/DropdownMenuSeparator.vue';
|
import DropdownMenuSeparator from '../ui/dropdown-menu/DropdownMenuSeparator.vue';
|
||||||
import { MemberState } from '@shared/types/member';
|
import { MemberState } from '@shared/types/member';
|
||||||
|
import { computed, onBeforeUnmount, ref, watch } from 'vue';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
@@ -41,18 +42,181 @@ function blurAfter() {
|
|||||||
(document.activeElement as HTMLElement)?.blur();
|
(document.activeElement as HTMLElement)?.blur();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NavItem = {
|
||||||
|
title: string;
|
||||||
|
to?: string;
|
||||||
|
href?: string;
|
||||||
|
status?: 'member' | 'guest';
|
||||||
|
isExternal?: boolean;
|
||||||
|
roles?: string[];
|
||||||
|
items?: NavItem[];
|
||||||
|
};
|
||||||
|
|
||||||
|
const navConfig: NavItem[] = [
|
||||||
|
{
|
||||||
|
title: 'Calendar',
|
||||||
|
to: '/calendar',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Documents',
|
||||||
|
href: 'https://docs.iceberg-gaming.com',
|
||||||
|
status: 'member',
|
||||||
|
isExternal: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Forms',
|
||||||
|
status: 'member',
|
||||||
|
items: [
|
||||||
|
{ title: 'Leave of Absence', to: '/loa' },
|
||||||
|
{ title: 'Training Report', to: '/trainingReport' },
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Administration',
|
||||||
|
status: 'member',
|
||||||
|
roles: ['17th Administrator', '17th HQ', '17th Command', 'Recruiter'],
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
title: 'Leave of Absence',
|
||||||
|
to: '/administration/loa',
|
||||||
|
roles: ['17th Administrator', '17th HQ', '17th Command']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Promotions',
|
||||||
|
to: '/administration/rankChange',
|
||||||
|
roles: ['17th Administrator', '17th HQ', '17th Command']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Recruitment',
|
||||||
|
to: '/administration/applications',
|
||||||
|
roles: ['Recruiter']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Member Management',
|
||||||
|
to: '/administration/members',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Role Management',
|
||||||
|
to: '/administration/roles',
|
||||||
|
roles: ['17th Administrator']
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Developer',
|
||||||
|
to: '/developer',
|
||||||
|
roles: ['Dev']
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Join',
|
||||||
|
to: '/join',
|
||||||
|
status: 'guest',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const filteredNav = computed(() => {
|
||||||
|
return navConfig.flatMap(item => {
|
||||||
|
const filtered: NavItem[] = [];
|
||||||
|
|
||||||
|
// 1. Check Login Requirements
|
||||||
|
const isLoggedIn = userStore.isLoggedIn;
|
||||||
|
|
||||||
|
// 2. Determine visibility based on status
|
||||||
|
let shouldShow = false;
|
||||||
|
|
||||||
|
if (!item.status) {
|
||||||
|
// Public items - always show
|
||||||
|
shouldShow = true;
|
||||||
|
} else if (item.status === 'guest') {
|
||||||
|
// Show if NOT logged in OR logged in as guest (but NOT a member)
|
||||||
|
shouldShow = !isLoggedIn || auth.accountStatus.value === MemberState.Guest;
|
||||||
|
} else if (item.status === 'member') {
|
||||||
|
// Show ONLY if logged in as member
|
||||||
|
shouldShow = isLoggedIn && auth.accountStatus.value === MemberState.Member;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Check Role Requirements (if status check passed)
|
||||||
|
if (shouldShow && item.roles) {
|
||||||
|
shouldShow = auth.hasAnyRole(item.roles);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldShow) {
|
||||||
|
if (item.items) {
|
||||||
|
const filteredItems = item.items.filter(subItem =>
|
||||||
|
!subItem.roles || auth.hasAnyRole(subItem.roles)
|
||||||
|
);
|
||||||
|
filtered.push({ ...item, items: filteredItems });
|
||||||
|
} else {
|
||||||
|
filtered.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filtered;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
const isMobileMenuOpen = ref(false);
|
||||||
|
const expandedMenu = ref(null);
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
function openMobileMenu() {
|
||||||
|
expandedMenu.value = null;
|
||||||
|
isMobileMenuOpen.value = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeMobileMenu() {
|
||||||
|
isMobileMenuOpen.value = false;
|
||||||
|
expandedMenu.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mobileNavigateTo(to: string) {
|
||||||
|
closeMobileMenu();
|
||||||
|
router.push(to);
|
||||||
|
}
|
||||||
|
|
||||||
|
function lockDocumentScroll() {
|
||||||
|
document.documentElement.style.overflow = 'hidden';
|
||||||
|
document.documentElement.style.overscrollBehavior = 'none';
|
||||||
|
document.body.style.overflow = 'hidden';
|
||||||
|
document.body.style.overscrollBehavior = 'none';
|
||||||
|
document.body.style.touchAction = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
function unlockDocumentScroll() {
|
||||||
|
document.documentElement.style.overflow = '';
|
||||||
|
document.documentElement.style.overscrollBehavior = '';
|
||||||
|
document.body.style.overflow = '';
|
||||||
|
document.body.style.overscrollBehavior = '';
|
||||||
|
document.body.style.touchAction = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(isMobileMenuOpen, (isOpen) => {
|
||||||
|
if (isOpen) {
|
||||||
|
lockDocumentScroll();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
unlockDocumentScroll();
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
unlockDocumentScroll();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="w-full border-b">
|
<div class="w-full border-b">
|
||||||
<div class="max-w-screen-3xl w-full mx-auto flex items-center justify-between pr-10 pl-7">
|
<div class="hidden lg:flex max-w-screen-3xl w-full mx-auto items-center justify-between pr-10 pl-7">
|
||||||
<!-- left side -->
|
<!-- left side -->
|
||||||
<div class="flex items-center gap-7">
|
<div class="flex items-center gap-7">
|
||||||
<RouterLink to="/">
|
<RouterLink to="/">
|
||||||
<img src="/17RBN_Logo.png" class="w-10 h-10 object-contain"></img>
|
<img src="/17RBN_Logo.png" class="w-10 h-10 object-contain"></img>
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
<!-- Member navigation -->
|
<!-- Member navigation -->
|
||||||
<div v-if="auth.accountStatus.value == MemberState.Member" class="h-15 flex items-center justify-center">
|
<div v-if="auth.accountStatus.value == MemberState.Member"
|
||||||
|
class="h-15 flex items-center justify-center">
|
||||||
<NavigationMenu>
|
<NavigationMenu>
|
||||||
<NavigationMenuList class="gap-3">
|
<NavigationMenuList class="gap-3">
|
||||||
|
|
||||||
@@ -202,6 +366,119 @@ function blurAfter() {
|
|||||||
<a v-else :href="APIHOST + '/login'">Login</a>
|
<a v-else :href="APIHOST + '/login'">Login</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- <Separator></Separator> -->
|
|
||||||
|
<!-- mobile navigation -->
|
||||||
|
<div class="flex flex-col lg:hidden w-full">
|
||||||
|
<div class="flex items-center justify-between w-full p-2">
|
||||||
|
<!-- <RouterLink to="/">
|
||||||
|
<img src="/17RBN_Logo.png" class="w-10 h-10 object-contain"></img>
|
||||||
|
</RouterLink> -->
|
||||||
|
<button @click="mobileNavigateTo('/')">
|
||||||
|
<img src="/17RBN_Logo.png" class="w-10 h-10 object-contain"></img>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<Button v-if="!isMobileMenuOpen" variant="ghost" size="icon" @click="openMobileMenu()">
|
||||||
|
<Menu class="size-7" />
|
||||||
|
</Button>
|
||||||
|
<Button v-else variant="ghost" size="icon" @click="closeMobileMenu()">
|
||||||
|
<X class="size-7" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div v-if="isMobileMenuOpen" class="fixed inset-0 z-[70] flex flex-col overflow-hidden bg-background"
|
||||||
|
:style="{ paddingBottom: 'env(safe-area-inset-bottom)' }">
|
||||||
|
<div class="flex items-center justify-between w-full border-b bg-background p-2">
|
||||||
|
<button @click="mobileNavigateTo('/')">
|
||||||
|
<img src="/17RBN_Logo.png" class="w-10 h-10 object-contain"></img>
|
||||||
|
</button>
|
||||||
|
<Button variant="ghost" size="icon" @click="closeMobileMenu()">
|
||||||
|
<X class="size-7" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex-1 overflow-y-auto overscroll-contain px-2 py-3 space-y-0.5">
|
||||||
|
<div v-for="navItem in filteredNav" :key="navItem.title" class="group">
|
||||||
|
|
||||||
|
<template v-if="!navItem.items">
|
||||||
|
<a v-if="navItem.isExternal" :href="navItem.href" target="_blank"
|
||||||
|
class="flex items-center justify-between w-full px-4 py-2.5 text-base font-medium rounded-md hover:bg-accent active:bg-accent transition-colors">
|
||||||
|
<span class="flex items-center gap-2">
|
||||||
|
{{ navItem.title }}
|
||||||
|
<ArrowUpRight class="h-3.5 w-3.5 opacity-50" />
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
<button v-else @click="mobileNavigateTo(navItem.to)"
|
||||||
|
class="w-full text-left px-4 py-2.5 text-base font-medium rounded-md hover:bg-accent active:bg-accent transition-colors">
|
||||||
|
{{ navItem.title }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div v-else class="space-y-0.5">
|
||||||
|
<button @click="expandedMenu = expandedMenu === navItem.title ? null : navItem.title"
|
||||||
|
class="flex items-center justify-between w-full px-4 py-2.5 text-base font-medium rounded-md transition-colors"
|
||||||
|
:class="expandedMenu === navItem.title ? 'bg-accent/50 text-primary' : 'hover:bg-accent'">
|
||||||
|
{{ navItem.title }}
|
||||||
|
<ChevronDown class="h-4 w-4 transition-transform duration-200"
|
||||||
|
:class="expandedMenu === navItem.title ? 'rotate-180' : ''" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<div v-if="expandedMenu === navItem.title"
|
||||||
|
class="ml-4 mr-2 border-l border-border space-y-0.5">
|
||||||
|
<button v-for="subNavItem in navItem.items" :key="subNavItem.title"
|
||||||
|
@click="mobileNavigateTo(subNavItem.to)"
|
||||||
|
class="w-full text-left px-6 py-2 text-sm text-muted-foreground hover:text-foreground active:text-primary transition-colors">
|
||||||
|
{{ subNavItem.title }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="p-3 border-t bg-background mt-auto" :style="{ paddingBottom: 'max(0.75rem, env(safe-area-inset-bottom))' }">
|
||||||
|
<div v-if="userStore.isLoggedIn" class="space-y-3">
|
||||||
|
<div class="flex items-center justify-between px-2">
|
||||||
|
<div class="flex gap-3">
|
||||||
|
<!-- <div
|
||||||
|
class="size-8 rounded-full bg-primary/10 flex items-center justify-center text-xs font-bold text-primary">
|
||||||
|
{{ userStore.displayName?.charAt(0) }}
|
||||||
|
</div> -->
|
||||||
|
<div class="flex flex-col leading-tight">
|
||||||
|
<span class="text-sm font-semibold">
|
||||||
|
{{ userStore.displayName || userStore.user.member.member_name }}
|
||||||
|
</span>
|
||||||
|
<span v-if="userStore.displayName"
|
||||||
|
class="text-[10px] uppercase tracking-wider text-muted-foreground">
|
||||||
|
{{ userStore.user.member.member_name }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<Button variant="ghost" size="icon" @click="mobileNavigateTo('/profile')">
|
||||||
|
<Settings class="size-6"></Settings>
|
||||||
|
</Button>
|
||||||
|
<Button variant="ghost" size="icon" @click="logout()">
|
||||||
|
<LogOut class="size-6 text-destructive"></LogOut>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<!-- <Button variant="outline" size="xs" class="flex-1 h-8 text-xs"
|
||||||
|
@click="mobileNavigateTo('/profile')">Profile</Button> -->
|
||||||
|
<Button variant="secondary" size="xs" class="flex-1 h-8 text-xs"
|
||||||
|
@click="mobileNavigateTo('/join')">My
|
||||||
|
Application</Button>
|
||||||
|
<Button variant="secondary" size="xs" class="flex-1 h-8 text-xs"
|
||||||
|
@click="mobileNavigateTo('/applications')">Application History</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a v-else :href="APIHOST + '/login'" class="block">
|
||||||
|
<Button class="w-full text-sm h-10">
|
||||||
|
<LogIn></LogIn> Login
|
||||||
|
</Button>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -169,16 +169,16 @@ const filteredMembers = computed(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-row-reverse gap-6 mx-auto w-full" :class="!adminMode ? 'max-w-5xl' : 'max-w-5xl'">
|
<div class="mx-auto flex w-full max-w-5xl flex-col gap-4 lg:flex-row-reverse lg:gap-6">
|
||||||
<div v-if="!adminMode" class="flex-1 flex flex-col space-x-4 rounded-md border p-4">
|
<div v-if="!adminMode" class="order-2 flex flex-1 flex-col rounded-md border p-4 lg:order-1">
|
||||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">LOA Policy</p>
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">LOA Policy</p>
|
||||||
<div ref="policyRef" class="bookstack-container">
|
<div ref="policyRef" class="bookstack-container">
|
||||||
<!-- LOA policy gets loaded here -->
|
<!-- LOA policy gets loaded here -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-1 flex flex-col gap-5">
|
<div class="order-1 flex flex-1 flex-col gap-5 lg:order-2">
|
||||||
<form v-if="!formSubmitted" @submit="onSubmit" class="flex flex-col gap-2">
|
<form v-if="!formSubmitted" @submit="onSubmit" class="flex flex-col gap-2">
|
||||||
<div class="flex w-full gap-5">
|
<div class="grid w-full grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-5">
|
||||||
<VeeField v-slot="{ field, errors }" name="member_id">
|
<VeeField v-slot="{ field, errors }" name="member_id">
|
||||||
<Field>
|
<Field>
|
||||||
<FieldContent>
|
<FieldContent>
|
||||||
@@ -237,13 +237,13 @@ const filteredMembers = computed(() => {
|
|||||||
</Field>
|
</Field>
|
||||||
</VeeField>
|
</VeeField>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex gap-5">
|
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 sm:gap-5">
|
||||||
<VeeField v-slot="{ field, errors }" name="start_date">
|
<VeeField v-slot="{ field, errors }" name="start_date">
|
||||||
<Field>
|
<Field class="w-full">
|
||||||
<FieldContent>
|
<FieldContent>
|
||||||
<FieldLabel>Start Date</FieldLabel>
|
<FieldLabel>Start Date</FieldLabel>
|
||||||
<Popover>
|
<Popover>
|
||||||
<div class="relative inline-flex items-center group">
|
<div class="group relative flex w-full items-center">
|
||||||
<PopoverTrigger as-child>
|
<PopoverTrigger as-child>
|
||||||
<Button :disabled="!values.type" variant="outline" :class="cn(
|
<Button :disabled="!values.type" variant="outline" :class="cn(
|
||||||
'w-full justify-start text-left font-normal',
|
'w-full justify-start text-left font-normal',
|
||||||
@@ -259,7 +259,7 @@ const filteredMembers = computed(() => {
|
|||||||
text-popover-foreground shadow-md border border-border
|
text-popover-foreground shadow-md border border-border
|
||||||
opacity-0 translate-y-1
|
opacity-0 translate-y-1
|
||||||
group-hover:opacity-100 group-hover:translate-y-0
|
group-hover:opacity-100 group-hover:translate-y-0
|
||||||
transition-opacity transition-transform duration-150">
|
transition-all duration-150">
|
||||||
Select an LOA type first
|
Select an LOA type first
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -277,11 +277,11 @@ const filteredMembers = computed(() => {
|
|||||||
</Field>
|
</Field>
|
||||||
</VeeField>
|
</VeeField>
|
||||||
<VeeField v-slot="{ field, errors }" name="end_date">
|
<VeeField v-slot="{ field, errors }" name="end_date">
|
||||||
<Field>
|
<Field class="w-full">
|
||||||
<FieldContent>
|
<FieldContent>
|
||||||
<FieldLabel>End Date</FieldLabel>
|
<FieldLabel>End Date</FieldLabel>
|
||||||
<Popover>
|
<Popover>
|
||||||
<div class="relative inline-flex items-center group">
|
<div class="group relative flex w-full items-center">
|
||||||
<PopoverTrigger as-child>
|
<PopoverTrigger as-child>
|
||||||
<Button :disabled="!values.type" variant="outline" :class="cn(
|
<Button :disabled="!values.type" variant="outline" :class="cn(
|
||||||
'w-full justify-start text-left font-normal',
|
'w-full justify-start text-left font-normal',
|
||||||
@@ -297,7 +297,7 @@ const filteredMembers = computed(() => {
|
|||||||
text-popover-foreground shadow-md border border-border
|
text-popover-foreground shadow-md border border-border
|
||||||
opacity-0 translate-y-1
|
opacity-0 translate-y-1
|
||||||
group-hover:opacity-100 group-hover:translate-y-0
|
group-hover:opacity-100 group-hover:translate-y-0
|
||||||
transition-opacity transition-transform duration-150">
|
transition-all duration-150">
|
||||||
Select an LOA type first
|
Select an LOA type first
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -330,8 +330,8 @@ const filteredMembers = computed(() => {
|
|||||||
</Field>
|
</Field>
|
||||||
</VeeField>
|
</VeeField>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-end">
|
<div class="flex justify-stretch sm:justify-end">
|
||||||
<Button type="submit" :disabled="submitting" class="w-35">
|
<Button type="submit" :disabled="submitting" class="w-full sm:w-35">
|
||||||
<span class="flex items-center gap-2" v-if="submitting">
|
<span class="flex items-center gap-2" v-if="submitting">
|
||||||
<Spinner></Spinner> Submitting…
|
<Spinner></Spinner> Submitting…
|
||||||
</span>
|
</span>
|
||||||
@@ -352,7 +352,7 @@ const filteredMembers = computed(() => {
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
<div class="flex gap-3 mt-4">
|
<div class="mt-4 flex flex-col gap-3 sm:flex-row">
|
||||||
<Button variant="secondary" @click="formSubmitted = false">
|
<Button variant="secondary" @click="formSubmitted = false">
|
||||||
Submit another request
|
Submit another request
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -141,29 +141,125 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<Dialog :open="isExtending" @update:open="(val) => isExtending = val">
|
<Dialog :open="isExtending" @update:open="(val) => isExtending = val">
|
||||||
<DialogContent>
|
<DialogContent class="w-[95vw] max-w-[95vw] p-4 sm:max-w-fit sm:p-6">
|
||||||
<DialogHeader>
|
<DialogHeader class="gap-1 pr-12 text-left">
|
||||||
<DialogTitle>Extend {{ targetLOA.name }}'s Leave of Absence </DialogTitle>
|
<DialogTitle class="text-base leading-tight sm:text-lg">Extend Leave of Absence</DialogTitle>
|
||||||
|
<DialogDescription class="truncate text-xs text-muted-foreground sm:text-sm">
|
||||||
|
{{ targetLOA?.name }}
|
||||||
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<div class="flex gap-5">
|
<div class="flex flex-col gap-4 sm:flex-row sm:items-start sm:gap-5">
|
||||||
<Calendar v-model="extendTo" class="rounded-md border shadow-sm w-min" layout="month-and-year"
|
<Calendar v-model="extendTo"
|
||||||
|
class="mx-auto w-min rounded-md border shadow-sm sm:mx-0"
|
||||||
|
layout="month-and-year"
|
||||||
:min-value="toCalendarDate(targetEnd)"
|
:min-value="toCalendarDate(targetEnd)"
|
||||||
:max-value="props.adminMode ? toCalendarDate(targetEnd).add({ years: 1 }) : toCalendarDate(targetEnd).add({ months: 1 })" />
|
:max-value="props.adminMode ? toCalendarDate(targetEnd).add({ years: 1 }) : toCalendarDate(targetEnd).add({ months: 1 })" />
|
||||||
<div class="flex flex-col w-full gap-3 px-2">
|
<div class="flex w-full flex-col gap-2 sm:gap-3">
|
||||||
<p>Quick Options</p>
|
<p class="text-sm font-medium text-muted-foreground">Quick Options</p>
|
||||||
<Button variant="outline" @click="extendTo = toCalendarDate(targetEnd).add({ days: 7 })">1
|
<Button class="w-full" variant="outline" @click="extendTo = toCalendarDate(targetEnd).add({ days: 7 })">1
|
||||||
Week</Button>
|
Week</Button>
|
||||||
<Button variant="outline" @click="extendTo = toCalendarDate(targetEnd).add({ months: 1 })">1
|
<Button class="w-full" variant="outline" @click="extendTo = toCalendarDate(targetEnd).add({ months: 1 })">1
|
||||||
Month</Button>
|
Month</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-end gap-4">
|
<div class="flex flex-row justify-end gap-2 pt-2 sm:gap-4 sm:pt-0">
|
||||||
<Button variant="outline" @click="isExtending = false">Cancel</Button>
|
<Button class="flex-1 sm:flex-none" variant="outline" @click="isExtending = false">Cancel</Button>
|
||||||
<Button @click="commitExtend">Extend</Button>
|
<Button class="flex-1 sm:flex-none" @click="commitExtend">Extend</Button>
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
<div class="max-w-7xl w-full mx-auto">
|
<div class="max-w-7xl w-full mx-auto">
|
||||||
|
<div class="space-y-3 md:hidden">
|
||||||
|
<template v-for="post in LOAList" :key="`mobile-${post.id}`">
|
||||||
|
<div class="rounded-lg border bg-card p-2.5 shadow-sm">
|
||||||
|
<div class="grid grid-cols-[minmax(0,1fr)_auto] items-center gap-2">
|
||||||
|
<div class="min-w-0 overflow-hidden">
|
||||||
|
<div class="max-w-[70vw] overflow-hidden whitespace-nowrap">
|
||||||
|
<MemberCard :member-id="post.member_id"></MemberCard>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Badge v-if="loaStatus(post) === 'Upcoming'" class="shrink-0 bg-blue-400">Upcoming</Badge>
|
||||||
|
<Badge v-else-if="loaStatus(post) === 'Active'" class="shrink-0 bg-green-500">Active</Badge>
|
||||||
|
<Badge v-else-if="loaStatus(post) === 'Extended'" class="shrink-0 bg-green-500">Extended</Badge>
|
||||||
|
<Badge v-else-if="loaStatus(post) === 'Overdue'" class="shrink-0 bg-yellow-400">Overdue</Badge>
|
||||||
|
<Badge v-else class="shrink-0 bg-gray-400">Ended</Badge>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-1 grid grid-cols-2 gap-x-4 gap-y-1">
|
||||||
|
<div>
|
||||||
|
<p class="text-[11px] uppercase tracking-wide text-muted-foreground/90">Start</p>
|
||||||
|
<p class="text-sm font-semibold text-foreground">{{ formatDate(post.start_date) }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="text-right">
|
||||||
|
<p class="text-[11px] uppercase tracking-wide text-muted-foreground/90">End</p>
|
||||||
|
<p class="text-sm font-semibold text-foreground">{{ post.extended_till ? formatDate(post.extended_till) : formatDate(post.end_date) }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-1 flex items-center justify-end gap-1">
|
||||||
|
<Button variant="ghost" class="h-8 px-2 text-xs text-muted-foreground" @click="expanded = expanded === post.id ? null : post.id">
|
||||||
|
<span class="mr-1">Details</span>
|
||||||
|
<ChevronUp v-if="expanded === post.id" class="size-4" />
|
||||||
|
<ChevronDown v-else class="size-4" />
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger class="cursor-pointer">
|
||||||
|
<Button variant="ghost" size="icon" class="size-8 text-muted-foreground">
|
||||||
|
<Ellipsis class="size-5"></Ellipsis>
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent>
|
||||||
|
<DropdownMenuItem v-if="!post.closed"
|
||||||
|
:disabled="post.extended_till !== null && !props.adminMode"
|
||||||
|
@click="isExtending = true; targetLOA = post">
|
||||||
|
{{ (post.extended_till !== null && !props.adminMode) ? 'Extend (Already Extended)' : 'Extend' }}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem v-if="!post.closed" :variant="'destructive'"
|
||||||
|
@click="cancelAndReload(post.id)">{{ loaStatus(post) === 'Upcoming' ?
|
||||||
|
'Cancel' :
|
||||||
|
'End' }}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<p v-if="post.closed || (!props.adminMode && post.closed)"
|
||||||
|
class="p-2 text-center text-sm">
|
||||||
|
No actions
|
||||||
|
</p>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="expanded === post.id" class="mt-2 space-y-2.5 border-t pt-2 text-sm">
|
||||||
|
<div class="space-y-1.5">
|
||||||
|
<div class="flex items-center justify-between gap-3">
|
||||||
|
<span class="text-muted-foreground/90">Type</span>
|
||||||
|
<span class="text-right font-semibold text-foreground">{{ post.type_name }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-between gap-3">
|
||||||
|
<span class="text-muted-foreground/90">Posted on</span>
|
||||||
|
<span class="text-right font-semibold text-foreground">{{ formatDate(post.filed_date) }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-between gap-3">
|
||||||
|
<span class="text-muted-foreground/90">Original end</span>
|
||||||
|
<span class="text-right font-semibold text-foreground">{{ formatDate(post.end_date) }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center justify-between gap-3">
|
||||||
|
<span class="text-muted-foreground/90">Extended to</span>
|
||||||
|
<span class="text-right font-semibold text-foreground">{{ post.extended_till ? formatDate(post.extended_till) : 'N/A' }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h4 class="text-[11px] font-semibold uppercase tracking-wide text-muted-foreground/90">Reason</h4>
|
||||||
|
<p class="mt-1 whitespace-pre-wrap text-sm leading-relaxed text-foreground/90">
|
||||||
|
{{ post.reason || 'No reason provided.' }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="hidden overflow-x-auto md:block">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
@@ -242,7 +338,7 @@
|
|||||||
<div class="w-full p-4 mb-6 space-y-4">
|
<div class="w-full p-4 mb-6 space-y-4">
|
||||||
|
|
||||||
<!-- Dates -->
|
<!-- Dates -->
|
||||||
<div class="grid grid-cols-3 gap-4 text-sm">
|
<div class="grid grid-cols-1 gap-4 text-sm lg:grid-cols-3">
|
||||||
<div>
|
<div>
|
||||||
<p class="text-muted-foreground">Start</p>
|
<p class="text-muted-foreground">Start</p>
|
||||||
<p class="font-medium">
|
<p class="font-medium">
|
||||||
@@ -266,16 +362,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Reason -->
|
<!-- Reason -->
|
||||||
<div class="space-y-2">
|
<div class="space-y-2 border-t pt-3">
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<h4 class="text-sm font-semibold text-foreground">
|
<h4 class="text-sm font-semibold text-foreground">
|
||||||
Reason
|
Reason
|
||||||
</h4>
|
</h4>
|
||||||
<Separator class="flex-1" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
<div class="text-sm leading-relaxed whitespace-pre-wrap text-muted-foreground">
|
||||||
class="rounded-lg border bg-muted/40 px-4 py-3 text-sm leading-relaxed whitespace-pre-wrap text-muted-foreground">
|
|
||||||
{{ post.reason || 'No reason provided.' }}
|
{{ post.reason || 'No reason provided.' }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -287,8 +379,9 @@
|
|||||||
</template>
|
</template>
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
<div class="mt-5 flex justify-between">
|
</div>
|
||||||
<div></div>
|
<div class="mt-5 flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
||||||
|
<div class="hidden md:block"></div>
|
||||||
<Pagination v-slot="{ page }" :items-per-page="pageData?.pageSize || 10" :total="pageData?.total || 10"
|
<Pagination v-slot="{ page }" :items-per-page="pageData?.pageSize || 10" :total="pageData?.total || 10"
|
||||||
:default-page="2" :page="pageNum" @update:page="setPage">
|
:default-page="2" :page="pageNum" @update:page="setPage">
|
||||||
<PaginationContent v-slot="{ items }">
|
<PaginationContent v-slot="{ items }">
|
||||||
@@ -303,7 +396,7 @@
|
|||||||
<PaginationNext />
|
<PaginationNext />
|
||||||
</PaginationContent>
|
</PaginationContent>
|
||||||
</Pagination>
|
</Pagination>
|
||||||
<div class="flex items-center gap-3 text-sm">
|
<div class="flex items-center justify-end gap-3 text-sm">
|
||||||
<p class="text-muted-foreground text-nowrap">Per page:</p>
|
<p class="text-muted-foreground text-nowrap">Per page:</p>
|
||||||
|
|
||||||
<button v-for="size in pageSizeOptions" :key="size" @click="setPageSize(size)"
|
<button v-for="size in pageSizeOptions" :key="size" @click="setPageSize(size)"
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ const reasonOptions = [
|
|||||||
{ label: 'Leadership Vote', value: 'leadership_vote' },
|
{ label: 'Leadership Vote', value: 'leadership_vote' },
|
||||||
{ label: 'Appointment', value: 'appointment' },
|
{ label: 'Appointment', value: 'appointment' },
|
||||||
{ label: 'Step Down', value: 'step_down' },
|
{ label: 'Step Down', value: 'step_down' },
|
||||||
|
{ label: 'Completed Basic', value: 'completed_basic' },
|
||||||
{ label: 'Custom', value: 'custom' },
|
{ label: 'Custom', value: 'custom' },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -135,11 +135,7 @@ function setAllToday() {
|
|||||||
<div class="w-xl">
|
<div class="w-xl">
|
||||||
<form v-if="!formSubmitted" id="trainingForm" @submit.prevent="submitForm"
|
<form v-if="!formSubmitted" id="trainingForm" @submit.prevent="submitForm"
|
||||||
class="w-full min-w-0 flex flex-col gap-4">
|
class="w-full min-w-0 flex flex-col gap-4">
|
||||||
<div>
|
|
||||||
<FieldLegend class="scroll-m-20 text-2xl font-semibold tracking-tight">
|
|
||||||
Promotion Form
|
|
||||||
</FieldLegend>
|
|
||||||
</div>
|
|
||||||
<VeeFieldArray name="promotions" v-slot="{ fields, push, remove }">
|
<VeeFieldArray name="promotions" v-slot="{ fields, push, remove }">
|
||||||
<FieldSet class="w-full min-w-0">
|
<FieldSet class="w-full min-w-0">
|
||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|||||||
<slot />
|
<slot />
|
||||||
|
|
||||||
<DialogClose
|
<DialogClose
|
||||||
class="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
class="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-3.5 right-3.5 inline-flex h-9 w-9 items-center justify-center rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none sm:top-4 sm:right-4 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-5"
|
||||||
>
|
>
|
||||||
<X />
|
<X />
|
||||||
<span class="sr-only">Close</span>
|
<span class="sr-only">Close</span>
|
||||||
|
|||||||
@@ -19,17 +19,20 @@ const showLOADialog = ref(false);
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<Dialog v-model:open="showLOADialog" v-on:update:open="showLOADialog = false">
|
<Dialog v-model:open="showLOADialog" v-on:update:open="showLOADialog = false">
|
||||||
<DialogContent class="sm:max-w-fit">
|
<DialogContent class="w-[95vw] max-w-[95vw] max-h-[90dvh] overflow-y-auto p-4 sm:max-w-fit sm:p-6">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Post LOA</DialogTitle>
|
<DialogTitle>Post LOA</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
Post an LOA on behalf of a member.
|
Post an LOA on behalf of a member.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<LoaForm :admin-mode="true" class="my-3"></LoaForm>
|
<LoaForm :admin-mode="true"></LoaForm>
|
||||||
|
<DialogFooter>
|
||||||
|
<Button variant="outline" @click="showLOADialog = false">Cancel</Button>
|
||||||
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
<div class="max-w-5xl mx-auto pt-10">
|
<div class="mx-auto max-w-5xl px-3 pt-10 sm:px-4 lg:px-0">
|
||||||
<div class="flex justify-between mb-4">
|
<div class="flex justify-between mb-4">
|
||||||
<h1 class="scroll-m-20 text-2xl font-semibold tracking-tight">LOA Log</h1>
|
<h1 class="scroll-m-20 text-2xl font-semibold tracking-tight">LOA Log</h1>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -1,29 +1,48 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { Plus, PlusIcon, X } from 'lucide-vue-next'
|
||||||
|
import PromotionForm from '@/components/promotions/promotionForm.vue'
|
||||||
|
import PromotionList from '@/components/promotions/promotionList.vue'
|
||||||
|
import DialogContent from '@/components/ui/dialog/DialogContent.vue'
|
||||||
|
import Dialog from '@/components/ui/dialog/Dialog.vue'
|
||||||
|
import DialogTrigger from '@/components/ui/dialog/DialogTrigger.vue'
|
||||||
|
import DialogHeader from '@/components/ui/dialog/DialogHeader.vue'
|
||||||
|
import DialogTitle from '@/components/ui/dialog/DialogTitle.vue'
|
||||||
|
import Button from '@/components/ui/button/Button.vue'
|
||||||
|
|
||||||
|
const isFormOpen = ref(false)
|
||||||
|
const listRef = ref(null)
|
||||||
|
|
||||||
|
const isMobileFormOpen = ref(false);
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="mx-auto mt-6 lg:mt-10 px-4 lg:px-8">
|
<div class="mx-auto mt-6 lg:mt-10 px-4 lg:px-8">
|
||||||
|
|
||||||
<div class="flex items-center justify-between mb-6 lg:hidden">
|
<div class="flex flex-col items-center justify-between mb-6 lg:hidden">
|
||||||
<h1 class="text-2xl font-semibold tracking-tight">Promotion History</h1>
|
<div v-if="isMobileFormOpen">
|
||||||
|
<div class="mb-4 flex justify-between items-center">
|
||||||
<Dialog v-model:open="isFormOpen">
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">
|
||||||
<DialogTrigger as-child>
|
Promotion Form
|
||||||
<Button size="sm" class="gap-2">
|
</p>
|
||||||
<Plus class="size-4" />
|
<Button variant="ghost" size="icon" @click="isMobileFormOpen = false">
|
||||||
Promote
|
<X v-if="isMobileFormOpen" class="size-6"></X>
|
||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
|
||||||
<DialogContent class="w-full h-full max-w-none m-0 rounded-none flex flex-col">
|
|
||||||
<DialogHeader class="flex-row items-center justify-between border-b pb-4">
|
|
||||||
<DialogTitle>New Promotion</DialogTitle>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<div class="flex-1 overflow-y-auto pt-6">
|
|
||||||
<PromotionForm @submitted="handleMobileSubmit" />
|
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
<PromotionForm @submitted="listRef?.refresh" />
|
||||||
</Dialog>
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<div class="flex justify-between w-full">
|
||||||
|
<h1 class="text-2xl font-semibold tracking-tight">Promotion History</h1>
|
||||||
|
<Button @click="isMobileFormOpen = true">
|
||||||
|
<PlusIcon />Submit
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<PromotionList></PromotionList>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col lg:flex-row lg:max-h-[70vh] gap-8">
|
<div class="hidden lg:flex flex-row lg:max-h-[70vh] gap-8">
|
||||||
<div class="flex-1 lg:border-r lg:pr-8 w-full lg:min-w-2xl">
|
<div class="flex-1 lg:border-r lg:pr-8 w-full lg:min-w-2xl">
|
||||||
<p class="hidden lg:block scroll-m-20 text-2xl font-semibold tracking-tight mb-3">
|
<p class="hidden lg:block scroll-m-20 text-2xl font-semibold tracking-tight mb-3">
|
||||||
Promotion History
|
Promotion History
|
||||||
@@ -42,24 +61,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { ref } from 'vue'
|
|
||||||
import { Plus } from 'lucide-vue-next'
|
|
||||||
import PromotionForm from '@/components/promotions/promotionForm.vue'
|
|
||||||
import PromotionList from '@/components/promotions/promotionList.vue'
|
|
||||||
import DialogContent from '@/components/ui/dialog/DialogContent.vue'
|
|
||||||
import Dialog from '@/components/ui/dialog/Dialog.vue'
|
|
||||||
import DialogTrigger from '@/components/ui/dialog/DialogTrigger.vue'
|
|
||||||
import DialogHeader from '@/components/ui/dialog/DialogHeader.vue'
|
|
||||||
import DialogTitle from '@/components/ui/dialog/DialogTitle.vue'
|
|
||||||
import Button from '@/components/ui/button/Button.vue'
|
|
||||||
|
|
||||||
const isFormOpen = ref(false)
|
|
||||||
const listRef = ref(null)
|
|
||||||
|
|
||||||
const handleMobileSubmit = () => {
|
|
||||||
isFormOpen.value = false // Close the "Whole page" modal
|
|
||||||
listRef.value?.refresh() // Refresh the list behind it
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -11,7 +11,7 @@ const mode = ref<'submit' | 'view'>('submit')
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="max-w-5xl mx-auto flex w-full flex-col mt-4 mb-10">
|
<div class="mx-auto mt-4 mb-10 flex w-full max-w-5xl flex-col px-3 sm:px-4 lg:px-0">
|
||||||
<div class="mb-8">
|
<div class="mb-8">
|
||||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Leave of Absence</p>
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Leave of Absence</p>
|
||||||
<div class="pt-3">
|
<div class="pt-3">
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getTrainingReport, getTrainingReports } from '@/api/trainingReport';
|
import { getTrainingReport, getTrainingReports } from '@/api/trainingReport';
|
||||||
import { CourseAttendee, CourseEventDetails, CourseEventSummary } from '@shared/types/course';
|
import { CourseAttendee, CourseEventDetails, CourseEventSummary } from '@shared/types/course';
|
||||||
import { computed, onMounted, ref, watch } from 'vue';
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from '@/components/ui/table'
|
} from '@/components/ui/table'
|
||||||
import { ArrowUpDown, ChevronDown, ChevronUp, Funnel, Link, Plus, Search, X } from 'lucide-vue-next';
|
import { ArrowUpDown, ChevronDown, ChevronLeft, ChevronUp, Funnel, Link, Plus, Search, X } from 'lucide-vue-next';
|
||||||
import Button from '@/components/ui/button/Button.vue';
|
import Button from '@/components/ui/button/Button.vue';
|
||||||
import TrainingReportForm from '@/components/trainingReport/trainingReportForm.vue';
|
import TrainingReportForm from '@/components/trainingReport/trainingReportForm.vue';
|
||||||
import Checkbox from '@/components/ui/checkbox/Checkbox.vue';
|
import Checkbox from '@/components/ui/checkbox/Checkbox.vue';
|
||||||
@@ -49,6 +49,21 @@ const sidePanel = computed<sidePanelState>(() => {
|
|||||||
return sidePanelState.closed;
|
return sidePanelState.closed;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const isMobile = ref(false);
|
||||||
|
const mobilePanel = ref<sidePanelState>(sidePanelState.closed);
|
||||||
|
let mobileMediaQuery: MediaQueryList | null = null;
|
||||||
|
|
||||||
|
function syncMobileMode() {
|
||||||
|
isMobile.value = mobileMediaQuery?.matches ?? window.innerWidth < 1024;
|
||||||
|
if (!isMobile.value) {
|
||||||
|
mobilePanel.value = sidePanelState.closed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const effectivePanel = computed<sidePanelState>(() => {
|
||||||
|
return isMobile.value ? mobilePanel.value : sidePanel.value;
|
||||||
|
})
|
||||||
|
|
||||||
watch(() => route.params.id, async (newID) => {
|
watch(() => route.params.id, async (newID) => {
|
||||||
if (!newID) {
|
if (!newID) {
|
||||||
focusedTrainingReport.value = null;
|
focusedTrainingReport.value = null;
|
||||||
@@ -82,6 +97,41 @@ async function closeTrainingReport() {
|
|||||||
focusedTrainingReport.value = null;
|
focusedTrainingReport.value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function openTrainingReport(id: number) {
|
||||||
|
if (isMobile.value) {
|
||||||
|
focusedTrainingReport.value = null;
|
||||||
|
TRLoaded.value = false;
|
||||||
|
expanded.value = null;
|
||||||
|
mobilePanel.value = sidePanelState.view;
|
||||||
|
await viewTrainingReport(id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.push(`/trainingReport/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openCreatePanel() {
|
||||||
|
if (isMobile.value) {
|
||||||
|
mobilePanel.value = sidePanelState.create;
|
||||||
|
focusedTrainingReport.value = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
router.push('/trainingReport/new');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function closePanel() {
|
||||||
|
if (isMobile.value) {
|
||||||
|
mobilePanel.value = sidePanelState.closed;
|
||||||
|
focusedTrainingReport.value = null;
|
||||||
|
TRLoaded.value = false;
|
||||||
|
expanded.value = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await closeTrainingReport();
|
||||||
|
}
|
||||||
|
|
||||||
const sortMode = ref<string>("descending");
|
const sortMode = ref<string>("descending");
|
||||||
const searchString = ref<string>("");
|
const searchString = ref<string>("");
|
||||||
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
@@ -105,12 +155,20 @@ async function loadTrainingReports() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
mobileMediaQuery = window.matchMedia('(max-width: 1023px)');
|
||||||
|
syncMobileMode();
|
||||||
|
mobileMediaQuery.addEventListener('change', syncMobileMode);
|
||||||
|
|
||||||
await loadTrainingReports();
|
await loadTrainingReports();
|
||||||
if (route.params.id)
|
if (route.params.id)
|
||||||
viewTrainingReport(Number(route.params.id))
|
viewTrainingReport(Number(route.params.id))
|
||||||
loaded.value = true;
|
loaded.value = true;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
mobileMediaQuery?.removeEventListener('change', syncMobileMode);
|
||||||
|
})
|
||||||
|
|
||||||
const TRLoaded = ref(false);
|
const TRLoaded = ref(false);
|
||||||
|
|
||||||
const pageNum = ref<number>(1);
|
const pageNum = ref<number>(1);
|
||||||
@@ -119,6 +177,16 @@ const pageData = ref<pagination>();
|
|||||||
const pageSize = ref<number>(15)
|
const pageSize = ref<number>(15)
|
||||||
const pageSizeOptions = [10, 15, 30]
|
const pageSizeOptions = [10, 15, 30]
|
||||||
|
|
||||||
|
function formatDate(date: Date | string): string {
|
||||||
|
if (!date) return '';
|
||||||
|
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
||||||
|
return dateObj.toLocaleDateString('en-US', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function setPageSize(size: number) {
|
function setPageSize(size: number) {
|
||||||
pageSize.value = size
|
pageSize.value = size
|
||||||
pageNum.value = 1;
|
pageNum.value = 1;
|
||||||
@@ -134,21 +202,22 @@ const expanded = ref<number>(null);
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="px-20 mx-auto max-w-[100rem] w-full flex mt-5">
|
<div class="mx-auto mt-5 flex w-full max-w-[100rem] flex-col px-3 sm:px-4 lg:flex-row lg:px-8 xl:px-20">
|
||||||
<!-- training report list -->
|
<!-- training report list -->
|
||||||
<div class="px-4 my-3" :class="sidePanel == sidePanelState.closed ? 'w-full' : 'w-2/5'">
|
<div v-show="!isMobile || effectivePanel === sidePanelState.closed" class="my-3 px-0 lg:px-4"
|
||||||
|
:class="effectivePanel == sidePanelState.closed ? 'w-full' : 'w-full lg:flex-[0_0_26rem] xl:flex-[0_0_30rem]'">
|
||||||
<div class="flex justify-between mb-4">
|
<div class="flex justify-between mb-4">
|
||||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Training Reports</p>
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Training Reports</p>
|
||||||
<Button @click="router.push('/trainingReport/new')">
|
<Button @click="openCreatePanel()">
|
||||||
<Plus></Plus> New Training Report
|
<Plus></Plus> New Training Report
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<!-- search/filter -->
|
<!-- search/filter -->
|
||||||
<div class="flex justify-between">
|
<div class="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
|
||||||
<!-- <Search></Search>
|
<!-- <Search></Search>
|
||||||
<Funnel></Funnel> -->
|
<Funnel></Funnel> -->
|
||||||
<div></div>
|
<div></div>
|
||||||
<div class="flex flex-row gap-5">
|
<div class="flex flex-col gap-3 sm:flex-row sm:gap-5">
|
||||||
<div>
|
<div>
|
||||||
<label class="text-muted-foreground">Search</label>
|
<label class="text-muted-foreground">Search</label>
|
||||||
<Input v-model="searchString" placeholder="Search..."></Input>
|
<Input v-model="searchString" placeholder="Search..."></Input>
|
||||||
@@ -172,7 +241,24 @@ const expanded = ref<number>(null);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="overflow-y-auto max-h-[70vh] mt-5 scrollbar-themed">
|
<div class="mt-5">
|
||||||
|
<div class="space-y-2 md:hidden">
|
||||||
|
<button v-for="report in trainingReports" :key="`mobile-report-${report.event_id}`"
|
||||||
|
class="w-full rounded-lg border bg-card px-3 py-2 text-left transition-colors hover:bg-muted/40"
|
||||||
|
@click="openTrainingReport(report.event_id)">
|
||||||
|
<p class="font-semibold text-foreground">
|
||||||
|
{{ report.course_name.length > 35 ? report.course_shortname : report.course_name }}
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-sm text-muted-foreground">{{ formatDate(report.date) }}</p>
|
||||||
|
<div class="mt-2 flex items-center gap-2 text-xs text-muted-foreground">
|
||||||
|
<span class="font-medium">Posted by:</span>
|
||||||
|
<MemberCard v-if="report.created_by" :member-id="report.created_by"></MemberCard>
|
||||||
|
<span v-else>Unknown User</span>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="hidden md:block">
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader class="">
|
<TableHeader class="">
|
||||||
<TableRow>
|
<TableRow>
|
||||||
@@ -187,12 +273,12 @@ const expanded = ref<number>(null);
|
|||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody v-if="loaded">
|
<TableBody v-if="loaded">
|
||||||
<TableRow class="cursor-pointer" v-for="report in trainingReports" :key="report.event_id"
|
<TableRow class="cursor-pointer" v-for="report in trainingReports" :key="report.event_id"
|
||||||
@click="router.push(`/trainingReport/${report.event_id}`)">
|
@click="openTrainingReport(report.event_id)">
|
||||||
<TableCell class="font-medium">{{ report.course_name.length > 30 ? report.course_shortname :
|
<TableCell class="font-medium">{{ report.course_name.length > 30 ? report.course_shortname :
|
||||||
report.course_name }}</TableCell>
|
report.course_name }}</TableCell>
|
||||||
<TableCell>{{ report.date.split('T')[0] }}</TableCell>
|
<TableCell>{{ report.date.split('T')[0] }}</TableCell>
|
||||||
<TableCell class="text-right">
|
<TableCell class="text-right">
|
||||||
<MemberCard v-if="report.created_by_name" :member-id="report.created_by"></MemberCard>
|
<MemberCard v-if="report.created_by" :member-id="report.created_by"></MemberCard>
|
||||||
<span v-else>Unknown User</span>
|
<span v-else>Unknown User</span>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<!-- <TableCell class="text-right">{{ report.created_by_name === null ? "Unknown User" :
|
<!-- <TableCell class="text-right">{{ report.created_by_name === null ? "Unknown User" :
|
||||||
@@ -202,9 +288,10 @@ const expanded = ref<number>(null);
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-5 flex justify-between"
|
</div>
|
||||||
:class="sidePanel !== sidePanelState.closed ? 'flex-col items-center' : 'items-center justify-between'">
|
<div class="mt-5 flex flex-col gap-3 md:flex-row md:items-center md:justify-between"
|
||||||
<div></div>
|
:class="effectivePanel !== sidePanelState.closed ? 'items-center' : ''">
|
||||||
|
<div class="hidden md:block"></div>
|
||||||
<Pagination v-slot="{ page }" :items-per-page="pageData?.pageSize || 10" :total="pageData?.total || 10"
|
<Pagination v-slot="{ page }" :items-per-page="pageData?.pageSize || 10" :total="pageData?.total || 10"
|
||||||
:default-page="2" :page="pageNum" @update:page="setPage">
|
:default-page="2" :page="pageNum" @update:page="setPage">
|
||||||
<PaginationContent v-slot="{ items }">
|
<PaginationContent v-slot="{ items }">
|
||||||
@@ -219,8 +306,9 @@ const expanded = ref<number>(null);
|
|||||||
<PaginationNext />
|
<PaginationNext />
|
||||||
</PaginationContent>
|
</PaginationContent>
|
||||||
</Pagination>
|
</Pagination>
|
||||||
<div class="flex items-center gap-3 text-sm" :class="sidePanel !== sidePanelState.closed ? 'mt-3' : ''">
|
<div class="flex flex-wrap items-center justify-end gap-2 text-sm"
|
||||||
<p class="text-muted-foreground text-nowrap">Per page:</p>
|
:class="effectivePanel !== sidePanelState.closed ? 'w-full justify-center md:w-auto md:justify-end' : ''">
|
||||||
|
<p class="text-muted-foreground">Per page:</p>
|
||||||
|
|
||||||
<button v-for="size in pageSizeOptions" :key="size" @click="setPageSize(size)"
|
<button v-for="size in pageSizeOptions" :key="size" @click="setPageSize(size)"
|
||||||
class="px-2 py-1 rounded transition-colors" :class="{
|
class="px-2 py-1 rounded transition-colors" :class="{
|
||||||
@@ -234,53 +322,95 @@ const expanded = ref<number>(null);
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- view training report section -->
|
<!-- view training report section -->
|
||||||
<div v-if="focusedTrainingReport != null && sidePanel == sidePanelState.view" class="pl-9 my-3 border-l w-3/5">
|
<div v-if="focusedTrainingReport != null && effectivePanel == sidePanelState.view"
|
||||||
|
:class="isMobile ? 'fixed inset-0 z-[60] overflow-y-auto px-3 py-3' : 'my-3 mt-2 w-full min-w-0 lg:mt-0 lg:flex-1 lg:border-l lg:pl-9'"
|
||||||
|
:style="isMobile ? { top: 'var(--app-header-height, 60px)' } : {}">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Training Report Details</p>
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Training Report Details</p>
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<Button class="cursor-pointer" variant="ghost" size="icon" @click="CopyLink()">
|
<Button v-if="isMobile" @click="closePanel" class="cursor-pointer" variant="outline" size="sm">
|
||||||
|
<ChevronLeft class="size-4"></ChevronLeft> Back
|
||||||
|
</Button>
|
||||||
|
<Button v-else class="cursor-pointer" variant="ghost" size="icon" @click="CopyLink()">
|
||||||
<Link class="size-4" />
|
<Link class="size-4" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button @click="closeTrainingReport" class="cursor-pointer" variant="ghost" size="icon">
|
<Button v-if="!isMobile" @click="closePanel" class="cursor-pointer" variant="ghost" size="icon">
|
||||||
<X class="size-6"></X>
|
<X class="size-6"></X>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="TRLoaded" class="max-h-[70vh] overflow-auto scrollbar-themed my-5">
|
<div v-if="TRLoaded" :class="isMobile ? 'my-3 pb-8' : 'my-5 max-h-[70vh] overflow-y-auto overflow-x-hidden scrollbar-themed'">
|
||||||
<div class="flex flex-col mb-5 border rounded-lg bg-muted/70 p-2 py-3 px-4">
|
<div class="flex flex-col mb-5 border rounded-lg bg-muted/70 p-2 py-3 px-4">
|
||||||
<p class="scroll-m-20 text-xl font-semibold tracking-tight">{{ focusedTrainingReport.course_name }}
|
<p class="scroll-m-20 text-xl font-semibold tracking-tight">{{ focusedTrainingReport.course_name }}
|
||||||
</p>
|
</p>
|
||||||
<div class="flex gap-10 items-center">
|
<div class="mt-2 flex flex-col gap-2 text-sm sm:flex-row sm:items-center sm:gap-10">
|
||||||
<p class="text-muted-foreground">{{ focusedTrainingReport.event_date.split('T')[0] }}</p>
|
<p class="text-muted-foreground">{{ formatDate(focusedTrainingReport.event_date) }}</p>
|
||||||
<p class="flex gap-2 items-center">Created by:
|
<div class="flex gap-2 items-center">Created by:
|
||||||
<MemberCard v-if="focusedTrainingReport.created_by"
|
<MemberCard v-if="focusedTrainingReport.created_by"
|
||||||
:member-id="focusedTrainingReport.created_by" />
|
:member-id="focusedTrainingReport.created_by" />
|
||||||
<p v-else>{{ focusedTrainingReport.created_by_name === null ? "Unknown User" :
|
<span v-else>Unknown User</span>
|
||||||
focusedTrainingReport.created_by_name
|
</div>
|
||||||
}}</p>
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col gap-8 ">
|
<div class="flex flex-col gap-8 ">
|
||||||
<!-- Trainers -->
|
<!-- Trainers -->
|
||||||
<div>
|
<div>
|
||||||
<label class="scroll-m-20 text-xl font-semibold tracking-tight">Trainers</label>
|
<label class="scroll-m-20 text-xl font-semibold tracking-tight">Trainers</label>
|
||||||
|
<div class="mt-3 space-y-2 md:hidden">
|
||||||
|
<article v-for="person in focusedTrainingTrainers" :key="person.attendee_id ?? person.attendee_name"
|
||||||
|
class="rounded-xl border bg-card p-3 shadow-sm" :class="expanded === person.attendee_id && 'ring-1 ring-primary/30'">
|
||||||
|
<div class="flex items-start justify-between gap-2">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
||||||
|
class="max-w-full whitespace-nowrap overflow-hidden text-ellipsis"></MemberCard>
|
||||||
|
<p v-else class="font-medium whitespace-nowrap overflow-hidden text-ellipsis">{{ person.attendee_name }}</p>
|
||||||
|
</div>
|
||||||
|
<Button @click.stop="expanded === person.attendee_id ? expanded = null : expanded = person.attendee_id"
|
||||||
|
variant="ghost" size="icon" class="shrink-0">
|
||||||
|
<ChevronDown v-if="expanded !== person.attendee_id" class="size-5" />
|
||||||
|
<ChevronUp v-else class="size-5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 grid grid-cols-1 gap-2 text-xs">
|
||||||
|
<div class="rounded-lg bg-muted px-3 py-2">
|
||||||
|
<p class="text-muted-foreground">Role</p>
|
||||||
|
<p class="font-medium text-foreground">{{ person.role.name }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="rounded-lg bg-muted px-3 py-2">
|
||||||
|
<p class="text-muted-foreground">Remarks</p>
|
||||||
|
<p class="font-medium text-foreground truncate">{{ person.remarks || '--' }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="expanded === person.attendee_id" class="mt-3 rounded-lg border bg-background px-3 py-2">
|
||||||
|
<p class="text-sm font-medium text-foreground">Full Remarks</p>
|
||||||
|
<p v-if="person.remarks"
|
||||||
|
class="mt-1 text-sm text-muted-foreground leading-relaxed whitespace-pre-wrap max-h-72 overflow-y-auto">
|
||||||
|
{{ person.remarks }}
|
||||||
|
</p>
|
||||||
|
<p v-else class="mt-1 text-sm text-muted-foreground italic">
|
||||||
|
None provided
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
<div class="mt-2 hidden md:block">
|
||||||
<div
|
<div
|
||||||
class="grid grid-cols-[1fr_1fr_2fr_3rem] py-2 text-sm font-medium text-muted-foreground border-b">
|
class="grid grid-cols-[minmax(0,1.6fr)_minmax(0,1fr)_minmax(0,1.4fr)_2.5rem] py-2 text-sm font-medium text-muted-foreground border-b gap-x-2">
|
||||||
<span>Name</span>
|
<span>Name</span>
|
||||||
<span class="">Role</span>
|
<span>Role</span>
|
||||||
<span class="text-right">Remarks</span>
|
<span class="text-right">Remarks</span>
|
||||||
<span></span>
|
<span></span>
|
||||||
</div>
|
</div>
|
||||||
<div v-for="person in focusedTrainingTrainers" class=" items-center border-b last:border-none"
|
<div v-for="person in focusedTrainingTrainers" :key="person.attendee_id ?? person.attendee_name"
|
||||||
|
class="items-center border-b last:border-none"
|
||||||
:class="expanded === person.attendee_id && 'bg-muted/20'">
|
:class="expanded === person.attendee_id && 'bg-muted/20'">
|
||||||
<div class="grid grid-cols-[1fr_1fr_2fr_3rem] items-center py-2">
|
<div class="grid grid-cols-[minmax(0,1.6fr)_minmax(0,1fr)_minmax(0,1.4fr)_2.5rem] items-center py-2 gap-x-2">
|
||||||
<div>
|
<div class="min-w-0">
|
||||||
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
||||||
class="justify-self-start"></MemberCard>
|
class="justify-self-start max-w-full whitespace-nowrap overflow-hidden text-ellipsis"></MemberCard>
|
||||||
<p v-else>{{ person.attendee_name }}</p>
|
<p v-else class="whitespace-nowrap overflow-hidden text-ellipsis">{{ person.attendee_name }}</p>
|
||||||
</div>
|
</div>
|
||||||
<p class="">{{ person.role.name }}</p>
|
<p class="truncate">{{ person.role.name }}</p>
|
||||||
<p class="text-right px-2 truncate"
|
<p class="text-right px-2 truncate"
|
||||||
:class="person.remarks == '' ? 'text-muted-foreground' : ''">
|
:class="person.remarks == '' ? 'text-muted-foreground' : ''">
|
||||||
{{ person.remarks == "" ?
|
{{ person.remarks == "" ?
|
||||||
@@ -313,39 +443,85 @@ const expanded = ref<number>(null);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<!-- trainees -->
|
<!-- trainees -->
|
||||||
<div>
|
<div>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<label class="scroll-m-20 text-xl font-semibold tracking-tight">Trainees</label>
|
<label class="scroll-m-20 text-xl font-semibold tracking-tight">Trainees</label>
|
||||||
|
<div class="mt-3 space-y-2 md:hidden">
|
||||||
|
<article v-for="person in focusedTrainingTrainees" :key="person.attendee_id ?? person.attendee_name"
|
||||||
|
class="rounded-xl border bg-card p-3 shadow-sm" :class="expanded === person.attendee_id && 'ring-1 ring-primary/30'">
|
||||||
|
<div class="flex items-start justify-between gap-2">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
||||||
|
class="max-w-full whitespace-nowrap overflow-hidden text-ellipsis"></MemberCard>
|
||||||
|
<p v-else class="font-medium whitespace-nowrap overflow-hidden text-ellipsis">{{ person.attendee_name }}</p>
|
||||||
|
</div>
|
||||||
|
<Button @click.stop="expanded === person.attendee_id ? expanded = null : expanded = person.attendee_id"
|
||||||
|
variant="ghost" size="icon" class="shrink-0">
|
||||||
|
<ChevronDown v-if="expanded !== person.attendee_id" class="size-5" />
|
||||||
|
<ChevronUp v-else class="size-5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 grid grid-cols-2 gap-2 text-xs">
|
||||||
|
<div class="rounded-lg bg-muted px-3 py-2 text-center">
|
||||||
|
<p class="text-muted-foreground">Bookwork</p>
|
||||||
|
<p class="font-semibold text-foreground">{{ !focusedTrainingReport.course.hasBookwork ? 'N/A' : (person.passed_bookwork ? 'Pass' : 'Fail') }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="rounded-lg bg-muted px-3 py-2 text-center">
|
||||||
|
<p class="text-muted-foreground">Qual</p>
|
||||||
|
<p class="font-semibold text-foreground">{{ !focusedTrainingReport.course.hasQual ? 'N/A' : (person.passed_qual ? 'Pass' : 'Fail') }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-span-2 rounded-lg bg-muted px-3 py-2">
|
||||||
|
<p class="text-muted-foreground">Remarks</p>
|
||||||
|
<p class="font-medium text-foreground truncate">{{ person.remarks || '--' }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-if="expanded === person.attendee_id" class="mt-3 rounded-lg border bg-background px-3 py-2">
|
||||||
|
<p class="text-sm font-medium text-foreground">Full Remarks</p>
|
||||||
|
<p v-if="person.remarks"
|
||||||
|
class="mt-1 text-sm text-muted-foreground leading-relaxed whitespace-pre-wrap max-h-72 overflow-y-auto">
|
||||||
|
{{ person.remarks }}
|
||||||
|
</p>
|
||||||
|
<p v-else class="mt-1 text-sm text-muted-foreground italic">
|
||||||
|
None provided
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
<div class="hidden md:block">
|
||||||
<div
|
<div
|
||||||
class="grid grid-cols-[1fr_5rem_5rem_2fr_3rem] py-2 text-sm font-medium text-muted-foreground border-b px-2">
|
class="grid grid-cols-[minmax(0,1.6fr)_4.25rem_4.25rem_minmax(0,1.4fr)_2.5rem] py-2 text-sm font-medium text-muted-foreground border-b px-2 gap-x-2">
|
||||||
<span>Name</span>
|
<span>Name</span>
|
||||||
<span class="text-center">Bookwork</span>
|
<span class="text-center">Bookwork</span>
|
||||||
<span class="text-center">Qual</span>
|
<span class="text-center">Qual</span>
|
||||||
<span class="text-right">Remarks</span>
|
<span class="text-right">Remarks</span>
|
||||||
<span class="w-15"></span>
|
<span class="w-15"></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div v-for="person in focusedTrainingTrainees" :key="person.attendee_id ?? person.attendee_name" class="border-b last:border-none"
|
||||||
<div v-for="person in focusedTrainingTrainees" class="border-b last:border-none"
|
|
||||||
:class="expanded === person.attendee_id && 'bg-muted/20'">
|
:class="expanded === person.attendee_id && 'bg-muted/20'">
|
||||||
<div class="grid grid-cols-[1fr_5rem_5rem_2fr_3rem] py-2 items-center mx-2">
|
<div class="grid grid-cols-[minmax(0,1.6fr)_4.25rem_4.25rem_minmax(0,1.4fr)_2.5rem] py-2 items-center px-2 gap-x-2">
|
||||||
<div>
|
<div class="min-w-0">
|
||||||
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
||||||
class="justify-self-start"></MemberCard>
|
class="justify-self-start max-w-full whitespace-nowrap overflow-hidden text-ellipsis"></MemberCard>
|
||||||
<p v-else>{{ person.attendee_name }}</p>
|
<p v-else class="whitespace-nowrap overflow-hidden text-ellipsis">{{ person.attendee_name }}</p>
|
||||||
</div>
|
</div>
|
||||||
<Tooltip :open="!focusedTrainingReport.course.hasBookwork" class="mx-auto"
|
<div class="flex justify-center">
|
||||||
|
<Tooltip :open="!focusedTrainingReport.course.hasBookwork"
|
||||||
message="This course does not have bookwork">
|
message="This course does not have bookwork">
|
||||||
<Checkbox :disabled="!focusedTrainingReport.course.hasBookwork"
|
<Checkbox :disabled="!focusedTrainingReport.course.hasBookwork"
|
||||||
:model-value="person.passed_bookwork" class="pointer-events-none">
|
:model-value="person.passed_bookwork" class="pointer-events-none">
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip :open="!focusedTrainingReport.course.hasQual" class="mx-auto"
|
</div>
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<Tooltip :open="!focusedTrainingReport.course.hasQual"
|
||||||
message="This course does not have a qualification">
|
message="This course does not have a qualification">
|
||||||
<Checkbox :disabled="!focusedTrainingReport.course.hasQual"
|
<Checkbox :disabled="!focusedTrainingReport.course.hasQual"
|
||||||
:model-value="person.passed_qual" class="pointer-events-none ml-1">
|
:model-value="person.passed_qual" class="pointer-events-none">
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
</div>
|
||||||
<p class="text-right truncate"
|
<p class="text-right truncate"
|
||||||
:class="person.remarks == '' ? 'text-muted-foreground' : ''">
|
:class="person.remarks == '' ? 'text-muted-foreground' : ''">
|
||||||
{{ person.remarks == "" ?
|
{{ person.remarks == "" ?
|
||||||
@@ -378,6 +554,8 @@ const expanded = ref<number>(null);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<!-- No Shows -->
|
<!-- No Shows -->
|
||||||
<div v-if="focusedNoShows.length != 0">
|
<div v-if="focusedNoShows.length != 0">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
@@ -385,29 +563,76 @@ const expanded = ref<number>(null);
|
|||||||
No Shows
|
No Shows
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<div class="mt-3 space-y-2 md:hidden">
|
||||||
|
<article v-for="person in focusedNoShows" :key="person.attendee_id ?? person.attendee_name"
|
||||||
|
class="rounded-xl border bg-card p-3 shadow-sm" :class="expanded === person.attendee_id && 'ring-1 ring-primary/30'">
|
||||||
|
<div class="flex items-start justify-between gap-2">
|
||||||
|
<div class="min-w-0">
|
||||||
|
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
||||||
|
class="max-w-full whitespace-nowrap overflow-hidden text-ellipsis" />
|
||||||
|
<p v-else class="font-medium whitespace-nowrap overflow-hidden text-ellipsis">{{ person.attendee_name }}</p>
|
||||||
|
</div>
|
||||||
|
<Button variant="ghost" size="icon" class="shrink-0" @click.stop="expanded === person.attendee_id
|
||||||
|
? expanded = null
|
||||||
|
: expanded = person.attendee_id">
|
||||||
|
<ChevronDown v-if="expanded !== person.attendee_id" class="size-5" />
|
||||||
|
<ChevronUp v-else class="size-5" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3 grid grid-cols-2 gap-2 text-xs">
|
||||||
|
<div class="rounded-lg bg-muted px-3 py-2 text-center">
|
||||||
|
<p class="text-muted-foreground">Bookwork</p>
|
||||||
|
<p class="font-semibold text-foreground">N/A</p>
|
||||||
|
</div>
|
||||||
|
<div class="rounded-lg bg-muted px-3 py-2 text-center">
|
||||||
|
<p class="text-muted-foreground">Qual</p>
|
||||||
|
<p class="font-semibold text-foreground">N/A</p>
|
||||||
|
</div>
|
||||||
|
<div class="col-span-2 rounded-lg bg-muted px-3 py-2">
|
||||||
|
<p class="text-muted-foreground">Remarks</p>
|
||||||
|
<p class="font-medium text-foreground truncate">{{ person.remarks || '--' }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="expanded === person.attendee_id" class="mt-3 rounded-lg border bg-background px-3 py-2">
|
||||||
|
<p class="text-sm font-medium text-foreground">
|
||||||
|
Full Remarks
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p v-if="person.remarks"
|
||||||
|
class="mt-1 text-sm text-muted-foreground leading-relaxed whitespace-pre-wrap max-h-72 overflow-y-auto">
|
||||||
|
{{ person.remarks }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p v-else class="mt-1 text-sm text-muted-foreground italic">
|
||||||
|
None provided
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</article>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="hidden md:block">
|
||||||
<div
|
<div
|
||||||
class="grid grid-cols-[1fr_5rem_5rem_2fr_3rem] py-2 text-sm font-medium text-muted-foreground border-b">
|
class="grid grid-cols-[minmax(0,1.6fr)_4.25rem_4.25rem_minmax(0,1.4fr)_2.5rem] py-2 text-sm font-medium text-muted-foreground border-b gap-x-2">
|
||||||
<span>Name</span>
|
<span>Name</span>
|
||||||
<span></span>
|
<span class="text-center">Bookwork</span>
|
||||||
<span></span>
|
<span class="text-center">Qual</span>
|
||||||
<span class="text-right">Remarks</span>
|
<span class="text-right">Remarks</span>
|
||||||
<span></span>
|
<span></span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-for="person in focusedNoShows" :key="person.attendee_id ?? person.attendee_name"
|
<div v-for="person in focusedNoShows" :key="person.attendee_id ?? person.attendee_name"
|
||||||
class="border-b last:border-none transition-colors"
|
class="border-b last:border-none transition-colors"
|
||||||
:class="expanded === person.attendee_id && 'bg-muted/20'">
|
:class="expanded === person.attendee_id && 'bg-muted/20'">
|
||||||
<!-- Row -->
|
<div class="grid grid-cols-[minmax(0,1.6fr)_4.25rem_4.25rem_minmax(0,1.4fr)_2.5rem] py-2 items-center gap-x-2">
|
||||||
<div class="grid grid-cols-[1fr_5rem_5rem_2fr_3rem] py-2 items-center">
|
<div class="min-w-0">
|
||||||
<!-- Name -->
|
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id"
|
||||||
<div>
|
class="max-w-full whitespace-nowrap overflow-hidden text-ellipsis" />
|
||||||
<MemberCard v-if="person.attendee_id" :member-id="person.attendee_id" />
|
<p v-else class="whitespace-nowrap overflow-hidden text-ellipsis">{{ person.attendee_name }}</p>
|
||||||
<p v-else>{{ person.attendee_name }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div></div>
|
<p class="text-center text-muted-foreground">-</p>
|
||||||
<div></div>
|
<p class="text-center text-muted-foreground">-</p>
|
||||||
|
|
||||||
<p class="text-right px-2 truncate" :class="!person.remarks && 'text-muted-foreground'">
|
<p class="text-right px-2 truncate" :class="!person.remarks && 'text-muted-foreground'">
|
||||||
{{ person.remarks || '--' }}
|
{{ person.remarks || '--' }}
|
||||||
@@ -438,7 +663,8 @@ const expanded = ref<number>(null);
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label class="scroll-m-20 text-xl font-semibold tracking-tight">Remarks</label>
|
<label class="scroll-m-20 text-xl font-semibold tracking-tight">Remarks</label>
|
||||||
@@ -452,18 +678,30 @@ const expanded = ref<number>(null);
|
|||||||
<Spinner class="size-8"></Spinner>
|
<Spinner class="size-8"></Spinner>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="sidePanel == sidePanelState.create" class="pl-7 border-l w-3/5 max-w-5xl">
|
<div v-if="effectivePanel == sidePanelState.create" :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 justify-between items-center my-3">
|
||||||
<div class="flex pl-2 gap-5">
|
<div class="flex gap-5 lg:pl-2">
|
||||||
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">New Training Report</p>
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">New Training Report</p>
|
||||||
</div>
|
</div>
|
||||||
<Button @click="closeTrainingReport" class="cursor-pointer" variant="ghost" size="icon">
|
<Button v-if="isMobile" @click="closePanel" class="cursor-pointer" variant="outline" size="sm">
|
||||||
|
<ChevronLeft class="size-4"></ChevronLeft> Back
|
||||||
|
</Button>
|
||||||
|
<Button v-else @click="closePanel" class="cursor-pointer" variant="ghost" size="icon">
|
||||||
<X class="size-6"></X>
|
<X class="size-6"></X>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div class="overflow-y-auto max-h-[70vh] mt-5 scrollbar-themed">
|
<div :class="isMobile ? 'mt-3 pb-8' : 'overflow-y-auto max-h-[70vh] mt-5 scrollbar-themed'">
|
||||||
<TrainingReportForm class="w-full pl-2"
|
<TrainingReportForm class="w-full lg:pl-2"
|
||||||
@submit="(newID) => { router.push(`/trainingReport/${newID}`); loadTrainingReports() }">
|
@submit="async (newID) => {
|
||||||
|
if (isMobile) {
|
||||||
|
await viewTrainingReport(newID);
|
||||||
|
mobilePanel = sidePanelState.view;
|
||||||
|
} else {
|
||||||
|
router.push(`/trainingReport/${newID}`);
|
||||||
|
}
|
||||||
|
loadTrainingReports()
|
||||||
|
}">
|
||||||
</TrainingReportForm>
|
</TrainingReportForm>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const router = createRouter({
|
|||||||
// ADMIN / STAFF ROUTES
|
// ADMIN / STAFF ROUTES
|
||||||
{
|
{
|
||||||
path: '/administration',
|
path: '/administration',
|
||||||
meta: { requiresAuth: true, memberOnly: true, roles: ['17th Administrator', '17th HQ', '17th Command'] },
|
meta: { requiresAuth: true, memberOnly: true, roles: ['17th Administrator', '17th HQ', '17th Command', '17th Recruiter'] },
|
||||||
children: [
|
children: [
|
||||||
{ path: 'applications', component: () => import('@/pages/ManageApplications.vue') },
|
{ path: 'applications', component: () => import('@/pages/ManageApplications.vue') },
|
||||||
{ path: 'applications/:id', component: () => import('@/pages/ManageApplications.vue') },
|
{ path: 'applications/:id', component: () => import('@/pages/ManageApplications.vue') },
|
||||||
|
|||||||
Reference in New Issue
Block a user