Merge commit '0919997e0f90ec5463f63f470213acd7e39493af' into #54-Application-tweaks
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
name: Continuous Deployment
|
name: Continuous Deployment
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Deploy:
|
Deploy:
|
||||||
@@ -8,20 +10,29 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
container:
|
container:
|
||||||
volumes:
|
volumes:
|
||||||
- /var/www/html/milsim-site-v4:/var/www/html/milsim-site-v4:rw
|
- /var/www/html/milsim-site-v4:/var/www/html/milsim-site-v4:z
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Local Environment
|
- name: Setup Local Environment
|
||||||
run: |
|
run: |
|
||||||
groupadd -g 989 nginx || true
|
groupadd -g 989 nginx || true
|
||||||
useradd nginx -u 990 -g nginx -m || true
|
useradd nginx -u 990 -g nginx -m || true
|
||||||
|
|
||||||
- name: Verify Node Environment
|
- name: Update Node Environment
|
||||||
|
uses: actions/setup-node@v6
|
||||||
|
with:
|
||||||
|
node-version: 20.19
|
||||||
|
|
||||||
|
- name: Verify Local Environment
|
||||||
run: |
|
run: |
|
||||||
|
which npm
|
||||||
npm -v
|
npm -v
|
||||||
|
which node
|
||||||
node -v
|
node -v
|
||||||
|
which sed
|
||||||
|
sed --version
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
ref: 'main'
|
ref: 'main'
|
||||||
@@ -32,31 +43,53 @@ jobs:
|
|||||||
cp /workspace/17th-Ranger-Battalion-ORG/milsim-site-v4/.git/config .git/config
|
cp /workspace/17th-Ranger-Battalion-ORG/milsim-site-v4/.git/config .git/config
|
||||||
chown nginx:nginx .git/config
|
chown nginx:nginx .git/config
|
||||||
|
|
||||||
- name: Fix File Permissions
|
|
||||||
run: |
|
|
||||||
sudo chown -R nginx:nginx /var/www/html/milsim-site-v4
|
|
||||||
sudo chmod -R u+w /var/www/html/milsim-site-v4
|
|
||||||
|
|
||||||
- name: Update Application Code
|
- name: Update Application Code
|
||||||
run: |
|
run: |
|
||||||
sudo -u nginx bash -c "cd /var/www/html/milsim-site-v4 && git reset --hard && git pull origin main"
|
cd /var/www/html/milsim-site-v4
|
||||||
|
version=`git log -1 --format=%H`
|
||||||
|
echo "Current Revision: $version"
|
||||||
|
echo "Updating to: ${{ github.sha }}
|
||||||
|
sudo -u nginx git reset --hard
|
||||||
|
sudo -u nginx git pull origin main
|
||||||
|
sudo -u nginx git pull origin main
|
||||||
|
new_version=`git log -1 --format=%H`
|
||||||
|
echo "Sucessfully updated to: $new_version
|
||||||
|
|
||||||
- name: Update Shared Dependencies
|
- name: Update Shared Dependencies and Fix Permissions
|
||||||
run: |
|
run: |
|
||||||
sudo -u nginx bash -c "cd /var/www/html/milsim-site-v4/shared && npm install"
|
cd /var/www/html/milsim-site-v4/shared
|
||||||
|
npm install
|
||||||
|
chown -R nginx:nginx .
|
||||||
|
|
||||||
- name: Update UI Dependencies
|
- name: Update UI Dependencies and Fix Permissions
|
||||||
run: |
|
run: |
|
||||||
sudo -u nginx bash -c "cd /var/www/html/milsim-site-v4/ui && npm install"
|
cd /var/www/html/milsim-site-v4/ui
|
||||||
|
npm install
|
||||||
|
chown -R nginx:nginx .
|
||||||
|
|
||||||
- name: Update API Dependencies
|
- name: Update API Dependencies and Fix Permissions
|
||||||
run: |
|
run: |
|
||||||
sudo -u nginx bash -c "cd /var/www/html/milsim-site-v4/api && npm install"
|
cd /var/www/html/milsim-site-v4/api
|
||||||
|
npm install
|
||||||
|
chown -R nginx:nginx .
|
||||||
|
|
||||||
- name: Build UI
|
- name: Build UI / Update Version / Fix Permissions
|
||||||
run: |
|
run: |
|
||||||
sudo -u nginx bash -c "cd /var/www/html/milsim-site-v4/ui && npm run build"
|
cd /var/www/html/milsim-site-v4/ui
|
||||||
|
npm run build
|
||||||
|
version=`git describe --abbrev=0 --tags`
|
||||||
|
sed -i "s/VITE_APPLICATION_VERSION=.*/VITE_APPLICATION_VERSION=$version/" .env
|
||||||
|
chown -R nginx:nginx .
|
||||||
|
|
||||||
- name: Build API
|
- name: Build API / Update Version / Fix Permissions
|
||||||
run: |
|
run: |
|
||||||
sudo -u nginx bash -c "cd /var/www/html/milsim-site-v4/api && npm run build"
|
cd /var/www/html/milsim-site-v4/api
|
||||||
|
npm run build
|
||||||
|
version=`git describe --abbrev=0 --tags`
|
||||||
|
sed -i "s/APPLICATION_VERSION=.*/APPLICATION_VERSION=$version/" .env
|
||||||
|
chown -R nginx:nginx .
|
||||||
|
|
||||||
|
- name: Reset File Permissions
|
||||||
|
run: |
|
||||||
|
sudo chown -R nginx:nginx /var/www/html/milsim-site-v4
|
||||||
|
sudo chmod -R u+w /var/www/html/milsim-site-v4
|
||||||
89
.gitea/workflows/ci-deploy.yaml
Normal file
89
.gitea/workflows/ci-deploy.yaml
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
name: Continuous Integration
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
Deploy:
|
||||||
|
name: Update Development
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
volumes:
|
||||||
|
- /var/www/html/milsim-site-v4-dev:/var/www/html/milsim-site-v4:z
|
||||||
|
steps:
|
||||||
|
- name: Setup Local Environment
|
||||||
|
run: |
|
||||||
|
groupadd -g 989 nginx || true
|
||||||
|
useradd nginx -u 990 -g nginx -m || true
|
||||||
|
|
||||||
|
- name: Update Node Environment
|
||||||
|
uses: actions/setup-node@v6
|
||||||
|
with:
|
||||||
|
node-version: 20.19
|
||||||
|
|
||||||
|
- name: Verify Local Environment
|
||||||
|
run: |
|
||||||
|
which npm
|
||||||
|
npm -v
|
||||||
|
which node
|
||||||
|
node -v
|
||||||
|
which sed
|
||||||
|
sed --version
|
||||||
|
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
ref: 'main'
|
||||||
|
|
||||||
|
- name: Token Copy
|
||||||
|
run: |
|
||||||
|
cd /var/www/html/milsim-site-v4
|
||||||
|
cp /workspace/17th-Ranger-Battalion-ORG/milsim-site-v4/.git/config .git/config
|
||||||
|
chown nginx:nginx .git/config
|
||||||
|
|
||||||
|
- name: Update Application Code
|
||||||
|
run: |
|
||||||
|
cd /var/www/html/milsim-site-v4
|
||||||
|
sudo -u nginx git reset --hard
|
||||||
|
sudo -u nginx git pull origin main
|
||||||
|
|
||||||
|
- name: Update Shared Dependencies and Fix Permissions
|
||||||
|
run: |
|
||||||
|
cd /var/www/html/milsim-site-v4/shared
|
||||||
|
npm install
|
||||||
|
chown -R nginx:nginx .
|
||||||
|
|
||||||
|
- name: Update UI Dependencies and Fix Permissions
|
||||||
|
run: |
|
||||||
|
cd /var/www/html/milsim-site-v4/ui
|
||||||
|
npm install
|
||||||
|
chown -R nginx:nginx .
|
||||||
|
|
||||||
|
- name: Update API Dependencies and Fix Permissions
|
||||||
|
run: |
|
||||||
|
cd /var/www/html/milsim-site-v4/api
|
||||||
|
npm install
|
||||||
|
chown -R nginx:nginx .
|
||||||
|
|
||||||
|
- name: Build UI / Update Version / Fix Permissions
|
||||||
|
run: |
|
||||||
|
cd /var/www/html/milsim-site-v4/ui
|
||||||
|
npm run build
|
||||||
|
version=`git rev-parse --short=10 HEAD`
|
||||||
|
sed -i "s/VITE_APPLICATION_VERSION=.*/VITE_APPLICATION_VERSION=$version/" .env
|
||||||
|
chown -R nginx:nginx .
|
||||||
|
|
||||||
|
- name: Build API / Update Version / Fix Permissions
|
||||||
|
run: |
|
||||||
|
cd /var/www/html/milsim-site-v4/api
|
||||||
|
npm run build
|
||||||
|
version=`git rev-parse --short=10 HEAD`
|
||||||
|
sed -i "s/APPLICATION_VERSION=.*/APPLICATION_VERSION=$version/" .env
|
||||||
|
chown -R nginx:nginx .
|
||||||
|
|
||||||
|
- name: Reset File Permissions
|
||||||
|
run: |
|
||||||
|
sudo chown -R nginx:nginx /var/www/html/milsim-site-v4
|
||||||
|
sudo chmod -R u+w /var/www/html/milsim-site-v4
|
||||||
@@ -19,7 +19,14 @@ AUTH_END_SESSION_URI=
|
|||||||
SERVER_PORT=3000
|
SERVER_PORT=3000
|
||||||
CLIENT_URL= # This is whatever URL the client web app is served on
|
CLIENT_URL= # This is whatever URL the client web app is served on
|
||||||
CLIENT_DOMAIN= #whatever.com
|
CLIENT_DOMAIN= #whatever.com
|
||||||
|
APPLICATION_VERSION= # Should match release tag
|
||||||
|
APPLICATION_ENVIRONMENT= # dev / prod
|
||||||
|
|
||||||
# Glitchtip
|
# Glitchtip
|
||||||
GLITCHTIP_DSN=
|
GLITCHTIP_DSN=
|
||||||
DISABLE_GLITCHTIP= # true/false
|
DISABLE_GLITCHTIP= # true/false
|
||||||
|
|
||||||
|
# Bookstack
|
||||||
|
DOC_HOST= # https://bookstack.whatever.com/
|
||||||
|
DOC_TOKEN_SECRET=
|
||||||
|
DOC_TOKEN_ID=
|
||||||
@@ -20,11 +20,14 @@ const port = process.env.SERVER_PORT;
|
|||||||
|
|
||||||
//glitchtip setup
|
//glitchtip setup
|
||||||
const sentry = require('@sentry/node');
|
const sentry = require('@sentry/node');
|
||||||
if (process.env.DISABLE_GLITCHTIP) {
|
if (process.env.DISABLE_GLITCHTIP === "true") {
|
||||||
console.log("Glitchtip disabled")
|
console.log("Glitchtip disabled")
|
||||||
} else {
|
} else {
|
||||||
let dsn = process.env.GLITCHTIP_DSN;
|
let dsn = process.env.GLITCHTIP_DSN;
|
||||||
sentry.init({ dsn: dsn });
|
let release = process.env.APPLICATION_VERSION;
|
||||||
|
let environment = process.env.APPLICATION_ENVIRONMENT;
|
||||||
|
console.log(release, environment)
|
||||||
|
sentry.init({ dsn: dsn, release: release, environment: environment });
|
||||||
console.log("Glitchtip initialized");
|
console.log("Glitchtip initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +61,7 @@ const { roles, memberRoles } = require('./routes/roles');
|
|||||||
const { courseRouter, eventRouter } = require('./routes/course');
|
const { courseRouter, eventRouter } = require('./routes/course');
|
||||||
const { calendarRouter } = require('./routes/calendar')
|
const { calendarRouter } = require('./routes/calendar')
|
||||||
const morgan = require('morgan');
|
const morgan = require('morgan');
|
||||||
|
const { env } = require('process');
|
||||||
|
|
||||||
app.use('/application', applicationsRouter);
|
app.use('/application', applicationsRouter);
|
||||||
app.use('/ranks', ranks);
|
app.use('/ranks', ranks);
|
||||||
|
|||||||
@@ -21,12 +21,13 @@ passport.use(new OpenIDConnectStrategy({
|
|||||||
scope: ['openid', 'profile']
|
scope: ['openid', 'profile']
|
||||||
}, async function verify(issuer, sub, profile, jwtClaims, accessToken, refreshToken, params, cb) {
|
}, async function verify(issuer, sub, profile, jwtClaims, accessToken, refreshToken, params, cb) {
|
||||||
|
|
||||||
// console.log('--- OIDC verify() called ---');
|
console.log('--- OIDC verify() called ---');
|
||||||
// console.log('issuer:', issuer);
|
console.log('issuer:', issuer);
|
||||||
// console.log('sub:', sub);
|
console.log('sub:', sub);
|
||||||
// console.log('profile:', JSON.stringify(profile, null, 2));
|
// console.log('profile:', JSON.stringify(profile, null, 2));
|
||||||
// console.log('id_token claims:', JSON.stringify(jwtClaims, null, 2));
|
console.log('profile:', profile);
|
||||||
// console.log('preferred_username:', jwtClaims?.preferred_username);
|
console.log('id_token claims:', JSON.stringify(jwtClaims, null, 2));
|
||||||
|
console.log('preferred_username:', jwtClaims?.preferred_username);
|
||||||
|
|
||||||
const con = await pool.getConnection();
|
const con = await pool.getConnection();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
const express = require('express');
|
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
import pool from '../db';
|
|
||||||
|
|
||||||
//post a new LOA
|
|
||||||
router.post("/", async (req, res) => {
|
|
||||||
const { member_id, filed_date, start_date, end_date, reason } = req.body;
|
|
||||||
|
|
||||||
if (!member_id || !filed_date || !start_date || !end_date) {
|
|
||||||
return res.status(400).json({ error: "Missing required fields" });
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await pool.query(
|
|
||||||
`INSERT INTO leave_of_absences
|
|
||||||
(member_id, filed_date, start_date, end_date, reason)
|
|
||||||
VALUES (?, ?, ?, ?, ?)`,
|
|
||||||
[member_id, filed_date, start_date, end_date, reason]
|
|
||||||
);
|
|
||||||
res.sendStatus(201);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
res.status(500).send('Something went wrong', error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//get my current LOA
|
|
||||||
router.get("/me", async (req, res) => {
|
|
||||||
//TODO: implement current user getter
|
|
||||||
const user = 89;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await pool.query("SELECT * FROM leave_of_absences WHERE member_id = ?", [user])
|
|
||||||
res.status(200).json(result)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
res.status(500).send(error);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
router.get('/all', async (req, res) => {
|
|
||||||
try {
|
|
||||||
const result = await pool.query(
|
|
||||||
`SELECT loa.*, members.name
|
|
||||||
FROM leave_of_absences AS loa
|
|
||||||
INNER JOIN members ON loa.member_id = members.id;
|
|
||||||
`);
|
|
||||||
res.status(200).json(result)
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error);
|
|
||||||
res.status(500).send(error);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = router;
|
|
||||||
148
api/src/routes/loa.ts
Normal file
148
api/src/routes/loa.ts
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
import { Request, Response } from 'express';
|
||||||
|
import pool from '../db';
|
||||||
|
import { closeLOA, createNewLOA, getAllLOA, getLOAbyID, getLoaTypes, getUserLOA, setLOAExtension } from '../services/loaService';
|
||||||
|
import { LOARequest } from '@app/shared/types/loa';
|
||||||
|
|
||||||
|
//member posts LOA
|
||||||
|
router.post("/", async (req: Request, res: Response) => {
|
||||||
|
let LOARequest = req.body as LOARequest;
|
||||||
|
LOARequest.member_id = req.user.id;
|
||||||
|
LOARequest.created_by = req.user.id;
|
||||||
|
LOARequest.filed_date = new Date();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await createNewLOA(LOARequest);
|
||||||
|
res.sendStatus(201);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//admin posts LOA
|
||||||
|
router.post("/admin", async (req: Request, res: Response) => {
|
||||||
|
let LOARequest = req.body as LOARequest;
|
||||||
|
LOARequest.created_by = req.user.id;
|
||||||
|
LOARequest.filed_date = new Date();
|
||||||
|
|
||||||
|
console.log(LOARequest);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await createNewLOA(LOARequest);
|
||||||
|
res.sendStatus(201);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//get my current LOA
|
||||||
|
router.get("/me", async (req: Request, res: Response) => {
|
||||||
|
const user = req.user.id;
|
||||||
|
try {
|
||||||
|
const result = await getUserLOA(user);
|
||||||
|
res.status(200).json(result)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
//get my LOA history
|
||||||
|
router.get("/history", async (req: Request, res: Response) => {
|
||||||
|
const user = req.user.id;
|
||||||
|
try {
|
||||||
|
const result = await getUserLOA(user);
|
||||||
|
res.status(200).json(result)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/all', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const result = await getAllLOA();
|
||||||
|
res.status(200).json(result)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).send(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/types', async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
let out = await getLoaTypes();
|
||||||
|
res.status(200).json(out);
|
||||||
|
} catch (error) {
|
||||||
|
res.status(500).json(error);
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.post('/cancel/:id', async (req: Request, res: Response) => {
|
||||||
|
let closer = req.user.id;
|
||||||
|
let id = Number(req.params.id);
|
||||||
|
try {
|
||||||
|
let loa = await getLOAbyID(id);
|
||||||
|
if (loa.member_id != closer) {
|
||||||
|
return res.sendStatus(403);
|
||||||
|
}
|
||||||
|
|
||||||
|
await closeLOA(Number(req.params.id), closer);
|
||||||
|
res.sendStatus(200);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
//TODO: enforce admin only
|
||||||
|
router.post('/adminCancel/:id', async (req: Request, res: Response) => {
|
||||||
|
let closer = req.user.id;
|
||||||
|
try {
|
||||||
|
await closeLOA(Number(req.params.id), closer);
|
||||||
|
res.sendStatus(200);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO: Enforce admin only
|
||||||
|
router.post('/extend/:id', async (req: Request, res: Response) => {
|
||||||
|
const to: Date = req.body.to;
|
||||||
|
|
||||||
|
if (!to) {
|
||||||
|
res.status(400).send("Extension length is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await setLOAExtension(Number(req.params.id), to);
|
||||||
|
res.sendStatus(200);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
res.status(500).json(error);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/policy', async (req: Request, res: Response) => {
|
||||||
|
const output = await fetch(`${process.env.DOC_HOST}/api/pages/42`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Token ${process.env.DOC_TOKEN_ID}:${process.env.DOC_TOKEN_SECRET}`,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (output.ok) {
|
||||||
|
const out = await output.json();
|
||||||
|
res.status(200).json(out.html);
|
||||||
|
} else {
|
||||||
|
console.error("Failed to fetch LOA policy from bookstack");
|
||||||
|
res.sendStatus(500);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
@@ -2,6 +2,7 @@ const express = require('express');
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
import pool from '../db';
|
import pool from '../db';
|
||||||
|
import { getUserActiveLOA } from '../services/loaService';
|
||||||
import { getUserData } from '../services/memberService';
|
import { getUserData } from '../services/memberService';
|
||||||
import { getUserRoles } from '../services/rolesService';
|
import { getUserRoles } from '../services/rolesService';
|
||||||
|
|
||||||
@@ -40,12 +41,13 @@ router.get('/me', async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { id, name, state } = await getUserData(req.user.id);
|
const { id, name, state } = await getUserData(req.user.id);
|
||||||
const LOAData = await pool.query(
|
// const LOAData = await pool.query(
|
||||||
`SELECT *
|
// `SELECT *
|
||||||
FROM leave_of_absences
|
// FROM leave_of_absences
|
||||||
WHERE member_id = ?
|
// WHERE member_id = ?
|
||||||
AND deleted = 0
|
// AND deleted = 0
|
||||||
AND UTC_TIMESTAMP() BETWEEN start_date AND end_date;`, req.user.id);
|
// AND UTC_TIMESTAMP() BETWEEN start_date AND end_date;`, req.user.id);
|
||||||
|
const LOAData = await getUserActiveLOA(req.user.id);
|
||||||
|
|
||||||
const roleData = await getUserRoles(req.user.id);
|
const roleData = await getUserRoles(req.user.id);
|
||||||
|
|
||||||
|
|||||||
@@ -123,15 +123,9 @@ export async function setAttendanceStatus(memberID: number, eventID: number, sta
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getEventAttendance(eventID: number): Promise<CalendarSignup[]> {
|
export async function getEventAttendance(eventID: number): Promise<CalendarSignup[]> {
|
||||||
const sql = `
|
|
||||||
SELECT
|
|
||||||
s.member_id,
|
|
||||||
s.status,
|
|
||||||
m.name AS member_name
|
|
||||||
FROM calendar_events_signups s
|
|
||||||
LEFT JOIN members m ON s.member_id = m.id
|
|
||||||
WHERE s.event_id = ?
|
|
||||||
`;
|
|
||||||
|
|
||||||
return await pool.query(sql, [eventID]);
|
const sql = "CALL `sp_GetCalendarEventSignups`(?)"
|
||||||
|
const res = await pool.query(sql, [eventID]);
|
||||||
|
console.log(res[0]);
|
||||||
|
return res[0];
|
||||||
}
|
}
|
||||||
98
api/src/services/loaService.ts
Normal file
98
api/src/services/loaService.ts
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import { toDateTime } from "@app/shared/utils/time";
|
||||||
|
import pool from "../db";
|
||||||
|
import { LOARequest, LOAType } from '@app/shared/types/loa'
|
||||||
|
|
||||||
|
export async function getLoaTypes(): Promise<LOAType[]> {
|
||||||
|
return await pool.query('SELECT * FROM leave_of_absences_types;');
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getAllLOA(page = 1, pageSize = 20): Promise<LOARequest[]> {
|
||||||
|
const offset = (page - 1) * pageSize;
|
||||||
|
|
||||||
|
const sql = `
|
||||||
|
SELECT loa.*, members.name, t.name AS type_name
|
||||||
|
FROM leave_of_absences AS loa
|
||||||
|
LEFT JOIN members ON loa.member_id = members.id
|
||||||
|
LEFT JOIN leave_of_absences_types AS t ON loa.type_id = t.id
|
||||||
|
ORDER BY
|
||||||
|
CASE
|
||||||
|
WHEN loa.closed IS NULL
|
||||||
|
AND NOW() > COALESCE(loa.extended_till, loa.end_date) THEN 1
|
||||||
|
WHEN loa.closed IS NULL
|
||||||
|
AND NOW() BETWEEN loa.start_date AND COALESCE(loa.extended_till, loa.end_date) THEN 2
|
||||||
|
WHEN loa.closed IS NULL AND NOW() < loa.start_date THEN 3
|
||||||
|
WHEN loa.closed IS NOT NULL THEN 4
|
||||||
|
END,
|
||||||
|
loa.start_date DESC
|
||||||
|
LIMIT ? OFFSET ?;
|
||||||
|
`;
|
||||||
|
|
||||||
|
let res: LOARequest[] = await pool.query(sql, [pageSize, offset]) as LOARequest[];
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getUserLOA(userId: number): Promise<LOARequest[]> {
|
||||||
|
const result: LOARequest[] = await pool.query(`
|
||||||
|
SELECT loa.*, members.name, t.name AS type_name
|
||||||
|
FROM leave_of_absences AS loa
|
||||||
|
LEFT JOIN members ON loa.member_id = members.id
|
||||||
|
LEFT JOIN leave_of_absences_types AS t ON loa.type_id = t.id
|
||||||
|
WHERE member_id = ?
|
||||||
|
ORDER BY
|
||||||
|
CASE
|
||||||
|
WHEN loa.closed IS NULL
|
||||||
|
AND NOW() > COALESCE(loa.extended_till, loa.end_date) THEN 1
|
||||||
|
WHEN loa.closed IS NULL
|
||||||
|
AND NOW() BETWEEN loa.start_date AND COALESCE(loa.extended_till, loa.end_date) THEN 2
|
||||||
|
WHEN loa.closed IS NULL AND NOW() < loa.start_date THEN 3
|
||||||
|
WHEN loa.closed IS NOT NULL THEN 4
|
||||||
|
END,
|
||||||
|
loa.start_date DESC
|
||||||
|
`, [userId])
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getUserActiveLOA(userId: number): Promise<LOARequest[]> {
|
||||||
|
const sql = `SELECT *
|
||||||
|
FROM leave_of_absences
|
||||||
|
WHERE member_id = ?
|
||||||
|
AND closed IS NULL
|
||||||
|
AND UTC_TIMESTAMP() BETWEEN start_date AND end_date;`
|
||||||
|
const LOAData = await pool.query(sql, [userId]);
|
||||||
|
return LOAData;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function createNewLOA(data: LOARequest) {
|
||||||
|
const sql = `INSERT INTO leave_of_absences
|
||||||
|
(member_id, filed_date, start_date, end_date, type_id, reason)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)`;
|
||||||
|
await pool.query(sql, [data.member_id, toDateTime(data.filed_date), toDateTime(data.start_date), toDateTime(data.end_date), data.type_id, data.reason])
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function closeLOA(id: number, closer: number) {
|
||||||
|
const sql = `UPDATE leave_of_absences
|
||||||
|
SET closed = 1,
|
||||||
|
closed_by = ?
|
||||||
|
WHERE leave_of_absences.id = ?`;
|
||||||
|
let out = await pool.query(sql, [closer, id]);
|
||||||
|
console.log(out);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getLOAbyID(id: number): Promise<LOARequest> {
|
||||||
|
let res = await pool.query(`SELECT * FROM leave_of_absences WHERE id = ?`, [id]);
|
||||||
|
console.log(res);
|
||||||
|
if (res.length != 1)
|
||||||
|
throw new Error(`LOA with id ${id} not found`);
|
||||||
|
return res[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function setLOAExtension(id: number, extendTo: Date) {
|
||||||
|
let res = await pool.query(`UPDATE leave_of_absences
|
||||||
|
SET extended_till = ?
|
||||||
|
WHERE leave_of_absences.id = ? `, [toDateTime(extendTo), id]);
|
||||||
|
if (res.affectedRows != 1)
|
||||||
|
throw new Error(`Could not extend LOA`);
|
||||||
|
return res[0];
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ module.exports = {
|
|||||||
script: 'built/api/src/index.js',
|
script: 'built/api/src/index.js',
|
||||||
watch: ['.env', 'built'],
|
watch: ['.env', 'built'],
|
||||||
ignore_watch: ['.gitignore', '\.json', 'src', '\.db', 'node_modules'],
|
ignore_watch: ['.gitignore', '\.json', 'src', '\.db', 'node_modules'],
|
||||||
|
appendEnvToName: true,
|
||||||
watch_options: {
|
watch_options: {
|
||||||
usePolling: true,
|
usePolling: true,
|
||||||
interval: 10000
|
interval: 10000
|
||||||
|
|||||||
51
shared/schemas/loaSchema.ts
Normal file
51
shared/schemas/loaSchema.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import * as z from "zod";
|
||||||
|
import { LOAType } from "../types/loa";
|
||||||
|
|
||||||
|
export const loaTypeSchema = z.object({
|
||||||
|
id: z.number(),
|
||||||
|
name: z.string(),
|
||||||
|
max_length_days: z.number(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const loaSchema = z.object({
|
||||||
|
member_id: z.number(),
|
||||||
|
start_date: z.date(),
|
||||||
|
end_date: z.date(),
|
||||||
|
type: loaTypeSchema,
|
||||||
|
reason: z.string(),
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
const { start_date, end_date, type } = data;
|
||||||
|
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
if (start_date < today) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
path: ["start_date"],
|
||||||
|
message: "Start date cannot be in the past.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. end > start
|
||||||
|
if (end_date <= start_date) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
path: ["end_date"],
|
||||||
|
message: "End date must be after start date.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. calculate max
|
||||||
|
const maxEnd = new Date(start_date);
|
||||||
|
maxEnd.setDate(maxEnd.getDate() + type.max_length_days);
|
||||||
|
|
||||||
|
if (end_date > maxEnd) {
|
||||||
|
ctx.addIssue({
|
||||||
|
code: z.ZodIssueCode.custom,
|
||||||
|
path: ["end_date"],
|
||||||
|
message: `This LOA type allows a maximum of ${type.max_length_days} days.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -26,6 +26,7 @@ export interface CalendarSignup {
|
|||||||
eventID: number;
|
eventID: number;
|
||||||
status: CalendarAttendance;
|
status: CalendarAttendance;
|
||||||
member_name?: string;
|
member_name?: string;
|
||||||
|
member_unit?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CalendarEventShort {
|
export interface CalendarEventShort {
|
||||||
|
|||||||
24
shared/types/loa.ts
Normal file
24
shared/types/loa.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
export interface LOARequest {
|
||||||
|
id?: number;
|
||||||
|
member_id?: number;
|
||||||
|
filed_date?: Date; // ISO 8601 string
|
||||||
|
start_date: Date; // ISO 8601 string
|
||||||
|
end_date: Date; // ISO 8601 string
|
||||||
|
extended_till?: Date;
|
||||||
|
type_id?: number;
|
||||||
|
reason?: string;
|
||||||
|
expired?: boolean;
|
||||||
|
closed?: boolean;
|
||||||
|
closed_by?: number;
|
||||||
|
created_by?: number;
|
||||||
|
|
||||||
|
name?: string; //member name
|
||||||
|
type_name?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface LOAType {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
max_length_days: number;
|
||||||
|
extendable: boolean;
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
export function toDateTime(date: Date): string {
|
export function toDateTime(date: Date): string {
|
||||||
console.log(date);
|
console.log(date);
|
||||||
|
if (typeof date === 'string') {
|
||||||
|
date = new Date(date);
|
||||||
|
}
|
||||||
// This produces a CST-local time because server runs in CST
|
// This produces a CST-local time because server runs in CST
|
||||||
const year = date.getFullYear();
|
const year = date.getFullYear();
|
||||||
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
# SITE SETTINGS
|
# SITE SETTINGS
|
||||||
VITE_APIHOST=
|
VITE_APIHOST=
|
||||||
|
VITE_DOCHOST= # https://bookstack.whatever.com/api
|
||||||
VITE_ENVIRONMENT= # dev / prod
|
VITE_ENVIRONMENT= # dev / prod
|
||||||
|
VITE_APPLICATION_VERSION= # Should match release tag
|
||||||
|
|
||||||
|
|
||||||
# Glitchtip
|
# Glitchtip
|
||||||
VITE_GLITCHTIP_DSN=
|
VITE_GLITCHTIP_DSN=
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { useUserStore } from './stores/user';
|
|||||||
import Alert from './components/ui/alert/Alert.vue';
|
import Alert from './components/ui/alert/Alert.vue';
|
||||||
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';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|
||||||
@@ -29,10 +30,11 @@ const environment = import.meta.env.VITE_ENVIRONMENT;
|
|||||||
<p>This is a development build of the application. Some features will be unavailable or unstable.</p>
|
<p>This is a development build of the application. Some features will be unavailable or unstable.</p>
|
||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
<Alert v-if="userStore.user?.loa?.[0]" class="m-2 mx-auto w-5xl" variant="info">
|
<Alert v-if="userStore.user?.LOAData?.[0]" class="m-2 mx-auto w-5xl" variant="info">
|
||||||
<AlertDescription class="flex flex-row items-center text-nowrap gap-5 mx-auto">
|
<AlertDescription class="flex flex-row items-center text-nowrap gap-5 mx-auto">
|
||||||
<p>You are on LOA until <strong>{{ formatDate(userStore.user?.loa?.[0].end_date) }}</strong></p>
|
<p>You are on LOA until <strong>{{ formatDate(userStore.user?.LOAData?.[0].end_date) }}</strong></p>
|
||||||
<Button variant="secondary">End LOA</Button>
|
<Button variant="secondary" @click="async () => { await cancelLOA(userStore.user?.LOAData?.[0].id); userStore.loadUser(); }">End
|
||||||
|
LOA</Button>
|
||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
</Alert>
|
</Alert>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,12 +1,4 @@
|
|||||||
export type LOARequest = {
|
import { LOARequest, LOAType } from '@shared/types/loa'
|
||||||
id?: number;
|
|
||||||
name?: string;
|
|
||||||
member_id: number;
|
|
||||||
filed_date: string; // ISO 8601 string
|
|
||||||
start_date: string; // ISO 8601 string
|
|
||||||
end_date: string; // ISO 8601 string
|
|
||||||
reason?: string;
|
|
||||||
};
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const addr = import.meta.env.VITE_APIHOST;
|
const addr = import.meta.env.VITE_APIHOST;
|
||||||
|
|
||||||
@@ -17,6 +9,24 @@ export async function submitLOA(request: LOARequest): Promise<{ id?: number; err
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(request),
|
body: JSON.stringify(request),
|
||||||
|
credentials: 'include',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw new Error("Failed to submit LOA");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function adminSubmitLOA(request: LOARequest): Promise<{ id?: number; error?: string }> {
|
||||||
|
const res = await fetch(`${addr}/loa/admin`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(request),
|
||||||
|
credentials: 'include',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
@@ -26,6 +36,7 @@ export async function submitLOA(request: LOARequest): Promise<{ id?: number; err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function getMyLOA(): Promise<LOARequest | null> {
|
export async function getMyLOA(): Promise<LOARequest | null> {
|
||||||
const res = await fetch(`${addr}/loa/me`, {
|
const res = await fetch(`${addr}/loa/me`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@@ -60,3 +71,84 @@ export function getAllLOAs(): Promise<LOARequest[]> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getMyLOAs(): Promise<LOARequest[]> {
|
||||||
|
return fetch(`${addr}/loa/history`, {
|
||||||
|
method: "GET",
|
||||||
|
credentials: 'include',
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}).then((res) => {
|
||||||
|
if (res.ok) {
|
||||||
|
return res.json();
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getLoaTypes(): Promise<LOAType[]> {
|
||||||
|
const res = await fetch(`${addr}/loa/types`, {
|
||||||
|
method: "GET",
|
||||||
|
credentials: 'include',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
const out = res.json();
|
||||||
|
if (!out) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getLoaPolicy(): Promise<string> {
|
||||||
|
const res = await fetch(`${addr}/loa/policy`, {
|
||||||
|
method: "GET",
|
||||||
|
credentials: 'include',
|
||||||
|
});
|
||||||
|
if (res.ok) {
|
||||||
|
const out = res.json();
|
||||||
|
if (!out) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function cancelLOA(id: number, admin: boolean = false) {
|
||||||
|
let route = admin ? 'adminCancel' : 'cancel';
|
||||||
|
const res = await fetch(`${addr}/loa/${route}/${id}`, {
|
||||||
|
method: "POST",
|
||||||
|
credentials: 'include',
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
throw new Error("Could not cancel LOA");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function extendLOA(id: number, to: Date) {
|
||||||
|
const res = await fetch(`${addr}/loa/extend/${id}`, {
|
||||||
|
method: "POST",
|
||||||
|
credentials: 'include',
|
||||||
|
body: JSON.stringify({ to }),
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
throw new Error("Could not extend LOA");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -165,4 +165,76 @@
|
|||||||
body {
|
body {
|
||||||
@apply bg-background text-foreground;
|
@apply bg-background text-foreground;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Root container */
|
||||||
|
.ListRendererV2-container {
|
||||||
|
font-family: var(--font-sans, system-ui), sans-serif;
|
||||||
|
color: var(--foreground);
|
||||||
|
line-height: 1.45;
|
||||||
|
max-width: 760px;
|
||||||
|
margin: 0 auto;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Headers */
|
||||||
|
.ListRendererV2-container h4 {
|
||||||
|
margin: 0.9rem 0 0.4rem 0;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.35;
|
||||||
|
font-size: 1.05rem;
|
||||||
|
color: var(--foreground);
|
||||||
|
/* PURE WHITE */
|
||||||
|
}
|
||||||
|
|
||||||
|
.ListRendererV2-container h5 {
|
||||||
|
margin: 0.9rem 0 0.4rem 0;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.35;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
color: var(--foreground);
|
||||||
|
/* Still white (change to muted if desired) */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Lists */
|
||||||
|
.ListRendererV2-container ul {
|
||||||
|
list-style-type: disc;
|
||||||
|
margin-left: 1.1rem;
|
||||||
|
margin-bottom: 0.6rem;
|
||||||
|
padding-left: 0.6rem;
|
||||||
|
color: var(--muted-foreground);
|
||||||
|
/* dim text */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Nested lists */
|
||||||
|
.ListRendererV2-container ul ul {
|
||||||
|
list-style-type: circle;
|
||||||
|
margin-left: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* List items */
|
||||||
|
.ListRendererV2-container li {
|
||||||
|
margin: 0.15rem 0;
|
||||||
|
padding-left: 0.1rem;
|
||||||
|
color: var(--muted-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bullet color */
|
||||||
|
.ListRendererV2-container li::marker {
|
||||||
|
color: var(--muted-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Inline elements */
|
||||||
|
.ListRendererV2-container li p,
|
||||||
|
.ListRendererV2-container li span,
|
||||||
|
.ListRendererV2-container p {
|
||||||
|
display: inline;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
color: var(--muted-foreground);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Top-level spacing */
|
||||||
|
.ListRendererV2-container>ul>li {
|
||||||
|
margin-top: 0.3rem;
|
||||||
}
|
}
|
||||||
@@ -156,6 +156,12 @@ function blurAfter() {
|
|||||||
<RouterLink to="/join" @click="blurAfter">Join</RouterLink>
|
<RouterLink to="/join" @click="blurAfter">Join</RouterLink>
|
||||||
</NavigationMenuLink>
|
</NavigationMenuLink>
|
||||||
</NavigationMenuItem>
|
</NavigationMenuItem>
|
||||||
|
<!-- Calendar -->
|
||||||
|
<NavigationMenuItem>
|
||||||
|
<NavigationMenuLink as-child :class="navigationMenuTriggerStyle()">
|
||||||
|
<RouterLink to="/calendar" @click="blurAfter">Calendar</RouterLink>
|
||||||
|
</NavigationMenuLink>
|
||||||
|
</NavigationMenuItem>
|
||||||
</NavigationMenuList>
|
</NavigationMenuList>
|
||||||
</NavigationMenu>
|
</NavigationMenu>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { CalendarEvent, CalendarSignup } from '@shared/types/calendar'
|
import type { CalendarEvent, CalendarSignup } from '@shared/types/calendar'
|
||||||
import { CircleAlert, Clock, EllipsisVertical, MapPin, User, X } from 'lucide-vue-next';
|
import { CircleAlert, Clock4, EllipsisVertical, MapPin, User, X } from 'lucide-vue-next';
|
||||||
import { computed, onMounted, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import ButtonGroup from '../ui/button-group/ButtonGroup.vue';
|
import ButtonGroup from '../ui/button-group/ButtonGroup.vue';
|
||||||
import Button from '../ui/button/Button.vue';
|
import Button from '../ui/button/Button.vue';
|
||||||
import { CalendarAttendance, getCalendarEvent, setCalendarEventAttendance, setCancelCalendarEvent } from '@/api/calendar';
|
import { CalendarAttendance, getCalendarEvent, setCalendarEventAttendance, setCancelCalendarEvent } from '@/api/calendar';
|
||||||
@@ -11,24 +11,13 @@ import DropdownMenu from '../ui/dropdown-menu/DropdownMenu.vue';
|
|||||||
import DropdownMenuTrigger from '../ui/dropdown-menu/DropdownMenuTrigger.vue';
|
import DropdownMenuTrigger from '../ui/dropdown-menu/DropdownMenuTrigger.vue';
|
||||||
import DropdownMenuContent from '../ui/dropdown-menu/DropdownMenuContent.vue';
|
import DropdownMenuContent from '../ui/dropdown-menu/DropdownMenuContent.vue';
|
||||||
import DropdownMenuItem from '../ui/dropdown-menu/DropdownMenuItem.vue';
|
import DropdownMenuItem from '../ui/dropdown-menu/DropdownMenuItem.vue';
|
||||||
|
import { Calendar } from 'lucide-vue-next';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
// const eventID = computed(() => {
|
|
||||||
// const id = route.params.id;
|
|
||||||
// if (typeof id === 'string') return id;
|
|
||||||
// return undefined;
|
|
||||||
// });
|
|
||||||
|
|
||||||
const loaded = ref<boolean>(false);
|
const loaded = ref<boolean>(false);
|
||||||
const activeEvent = ref<CalendarEvent | null>(null);
|
const activeEvent = ref<CalendarEvent | null>(null);
|
||||||
|
|
||||||
// onMounted(async () => {
|
|
||||||
// let eventID = route.params.id;
|
|
||||||
// console.log(eventID);
|
|
||||||
// activeEvent.value = await getCalendarEvent(Number(eventID));
|
|
||||||
// loaded.value = true;
|
|
||||||
// });
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => route.params.id,
|
() => route.params.id,
|
||||||
async (id) => {
|
async (id) => {
|
||||||
@@ -45,23 +34,27 @@ const emit = defineEmits<{
|
|||||||
(e: 'edit', event: CalendarEvent): void
|
(e: 'edit', event: CalendarEvent): void
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
// const activeEvent = computed(() => props.event)
|
const dateFmt = new Intl.DateTimeFormat(undefined, {
|
||||||
|
weekday: 'long', month: 'short', day: 'numeric',
|
||||||
const startFmt = new Intl.DateTimeFormat(undefined, {
|
|
||||||
weekday: 'short', year: 'numeric', month: 'short', day: 'numeric',
|
|
||||||
hour: 'numeric', minute: '2-digit'
|
|
||||||
})
|
})
|
||||||
const endFmt = new Intl.DateTimeFormat(undefined, {
|
|
||||||
|
const timeFmt = new Intl.DateTimeFormat(undefined, {
|
||||||
hour: 'numeric', minute: '2-digit'
|
hour: 'numeric', minute: '2-digit'
|
||||||
})
|
})
|
||||||
|
|
||||||
const whenText = computed(() => {
|
const dateText = computed(() => {
|
||||||
if (!activeEvent.value?.start) return ''
|
let start = dateFmt.format(new Date(activeEvent.value.start));
|
||||||
const s = new Date(activeEvent.value.start)
|
let end = dateFmt.format(new Date(activeEvent.value.end));
|
||||||
const e = activeEvent.value?.end ? new Date(activeEvent.value.end) : null
|
if (start === end)
|
||||||
return e
|
return start;
|
||||||
? `${startFmt.format(s)} – ${endFmt.format(e)}`
|
else
|
||||||
: `${startFmt.format(s)}`
|
return `${start} - ${end}`;
|
||||||
|
})
|
||||||
|
|
||||||
|
const timeText = computed(() => {
|
||||||
|
let startTime = timeFmt.format(new Date(activeEvent.value.start))
|
||||||
|
let endTime = timeFmt.format(new Date(activeEvent.value.end))
|
||||||
|
return [startTime, endTime]
|
||||||
})
|
})
|
||||||
|
|
||||||
const attending = computed<CalendarSignup[]>(() => { return activeEvent.value.eventSignups.filter((s) => s.status == CalendarAttendance.Attending) })
|
const attending = computed<CalendarSignup[]>(() => { return activeEvent.value.eventSignups.filter((s) => s.status == CalendarAttendance.Attending) })
|
||||||
@@ -71,6 +64,7 @@ const viewedState = ref<CalendarAttendance>(CalendarAttendance.Attending);
|
|||||||
|
|
||||||
let user = useUserStore();
|
let user = useUserStore();
|
||||||
const myAttendance = computed<CalendarSignup | null>(() => {
|
const myAttendance = computed<CalendarSignup | null>(() => {
|
||||||
|
if (!user.isLoggedIn) return null;
|
||||||
return activeEvent.value.eventSignups.find(
|
return activeEvent.value.eventSignups.find(
|
||||||
(s) => s.member_id === user.user.id
|
(s) => s.member_id === user.user.id
|
||||||
) || null;
|
) || null;
|
||||||
@@ -83,6 +77,7 @@ async function setAttendance(state: CalendarAttendance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const canEditEvent = computed(() => {
|
const canEditEvent = computed(() => {
|
||||||
|
if (!user.isLoggedIn) return false;
|
||||||
if (user.user.id == activeEvent.value.creator_id)
|
if (user.user.id == activeEvent.value.creator_id)
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@@ -97,17 +92,94 @@ async function forceReload() {
|
|||||||
activeEvent.value = await getCalendarEvent(activeEvent.value.id);
|
activeEvent.value = await getCalendarEvent(activeEvent.value.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
defineExpose({forceReload})
|
const isPast = computed(() => {
|
||||||
|
const end = new Date(activeEvent.value.end)
|
||||||
|
// is current date later than end date
|
||||||
|
return new Date() < end;
|
||||||
|
})
|
||||||
|
|
||||||
|
const attendanceTab = ref<"Alpha" | "Echo" | "Other">("Alpha");
|
||||||
|
const attendanceList = computed<CalendarSignup[]>(() => {
|
||||||
|
let out: CalendarSignup[] = [];
|
||||||
|
if (attendanceTab.value === 'Alpha') {
|
||||||
|
out = activeEvent.value.eventSignups?.filter((s) => s.member_unit === 'Alpha Company');
|
||||||
|
} else if (attendanceTab.value === 'Echo') {
|
||||||
|
out = activeEvent.value.eventSignups?.filter((s) => s.member_unit === 'Echo Company')
|
||||||
|
} else {
|
||||||
|
out = activeEvent.value.eventSignups?.filter((s) => s.member_unit != 'Alpha Company' && s.member_unit != 'Echo Company')
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusOrder: Record<CalendarAttendance, number> = {
|
||||||
|
[CalendarAttendance.Attending]: 1,
|
||||||
|
[CalendarAttendance.Maybe]: 2,
|
||||||
|
[CalendarAttendance.NotAttending]: 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
out.sort((a, b) => statusOrder[a.status] - statusOrder[b.status]);
|
||||||
|
|
||||||
|
return out;
|
||||||
|
})
|
||||||
|
|
||||||
|
const attendanceCountsByGroup = computed(() => {
|
||||||
|
const signups = activeEvent.value.eventSignups ?? [];
|
||||||
|
|
||||||
|
return {
|
||||||
|
Alpha: signups.filter(s => s.member_unit === "Alpha Company").length,
|
||||||
|
Echo: signups.filter(s => s.member_unit === "Echo Company").length,
|
||||||
|
Other: signups.filter(s =>
|
||||||
|
s.member_unit !== "Alpha Company" &&
|
||||||
|
s.member_unit !== "Echo Company"
|
||||||
|
).length,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const attendanceStatusSummary = computed(() => {
|
||||||
|
const signups = activeEvent.value.eventSignups ?? [];
|
||||||
|
|
||||||
|
return {
|
||||||
|
attending: signups.filter(s => s.status === CalendarAttendance.Attending).length,
|
||||||
|
maybe: signups.filter(s => s.status === CalendarAttendance.Maybe).length,
|
||||||
|
notAttending: signups.filter(s => s.status === CalendarAttendance.NotAttending).length,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const statusColor = (status: CalendarAttendance) => {
|
||||||
|
switch (status) {
|
||||||
|
case CalendarAttendance.Attending:
|
||||||
|
return "text-success";
|
||||||
|
case CalendarAttendance.Maybe:
|
||||||
|
return "text-yellow-600";
|
||||||
|
case CalendarAttendance.NotAttending:
|
||||||
|
return "text-destructive";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const displayStatus = (status: CalendarAttendance) => {
|
||||||
|
switch (status) {
|
||||||
|
case CalendarAttendance.Attending:
|
||||||
|
return "Attending";
|
||||||
|
case CalendarAttendance.Maybe:
|
||||||
|
return "Maybe";
|
||||||
|
case CalendarAttendance.NotAttending:
|
||||||
|
return "Declined";
|
||||||
|
default:
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
defineExpose({ forceReload })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="loaded">
|
<div v-if="loaded">
|
||||||
<!-- Header -->
|
<!-- Header -->
|
||||||
<div class="flex items-center justify-between gap-3 border-b px-4 py-3">
|
<div class="flex items-center justify-between gap-3 border-b px-4 py-3 h-14">
|
||||||
<h2 class="text-lg font-semibold break-all">
|
<h2 class="text-lg font-semibold break-all">
|
||||||
{{ activeEvent?.name || 'Event' }}
|
{{ activeEvent?.name || 'Event' }}
|
||||||
</h2>
|
</h2>
|
||||||
<div class="flex gap-4">
|
<div class="flex gap-4 items-center">
|
||||||
<DropdownMenu v-if="canEditEvent">
|
<DropdownMenu v-if="canEditEvent">
|
||||||
<DropdownMenuTrigger>
|
<DropdownMenuTrigger>
|
||||||
<button
|
<button
|
||||||
@@ -119,8 +191,7 @@ defineExpose({forceReload})
|
|||||||
<DropdownMenuItem @click="emit('edit', activeEvent)">
|
<DropdownMenuItem @click="emit('edit', activeEvent)">
|
||||||
Edit
|
Edit
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem v-if="activeEvent.cancelled"
|
<DropdownMenuItem v-if="activeEvent.cancelled" @click="setCancel(false)">
|
||||||
@click="setCancel(false)">
|
|
||||||
Un-Cancel
|
Un-Cancel
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem v-else @click="setCancel(true)">
|
<DropdownMenuItem v-else @click="setCancel(true)">
|
||||||
@@ -142,7 +213,7 @@ defineExpose({forceReload})
|
|||||||
<CircleAlert></CircleAlert> This event has been cancelled
|
<CircleAlert></CircleAlert> This event has been cancelled
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section class="w-full">
|
<section v-if="isPast && user.isLoggedIn" class="w-full">
|
||||||
<ButtonGroup class="flex w-full">
|
<ButtonGroup class="flex w-full">
|
||||||
<Button variant="outline"
|
<Button variant="outline"
|
||||||
:class="myAttendance?.status === CalendarAttendance.Attending ? 'border-2 border-primary text-primary' : ''"
|
:class="myAttendance?.status === CalendarAttendance.Attending ? 'border-2 border-primary text-primary' : ''"
|
||||||
@@ -155,24 +226,21 @@ defineExpose({forceReload})
|
|||||||
@click="setAttendance(CalendarAttendance.NotAttending)">Declined</Button>
|
@click="setAttendance(CalendarAttendance.NotAttending)">Declined</Button>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</section>
|
</section>
|
||||||
<!-- When -->
|
<!-- Meta -->
|
||||||
<section v-if="whenText" class="space-y-2 w-full">
|
<section class="space-y-3 w-full">
|
||||||
<div class="inline-flex items-center gap-2 rounded-md border px-2.5 py-1.5 text-sm">
|
<p class="text-lg font-semibold">Details</p>
|
||||||
<Clock class="size-4 opacity-80" />
|
<div class="text-foreground/80 flex gap-3 items-center">
|
||||||
<span class="font-medium">{{ whenText }}</span>
|
<Calendar :size="20"></Calendar> {{ dateText }}
|
||||||
|
</div>
|
||||||
|
<div class="text-foreground/80 flex gap-3 items-center">
|
||||||
|
<Clock4 :size="20"></Clock4> {{ timeText[0] }} - {{ timeText[1] }}
|
||||||
|
</div>
|
||||||
|
<div class="text-foreground/80 flex gap-3 items-center">
|
||||||
|
<MapPin :size="20"></MapPin> {{ activeEvent.location || "Unknown" }}
|
||||||
|
</div>
|
||||||
|
<div class="text-foreground/80 flex gap-3 items-center">
|
||||||
|
<User :size="20"></User> {{ activeEvent.creator_name || "Unknown User" }}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
|
||||||
<!-- Quick meta chips -->
|
|
||||||
<section class="flex flex-wrap gap-2 w-full">
|
|
||||||
<span class="inline-flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs">
|
|
||||||
<MapPin class="size-3.5 opacity-80" />
|
|
||||||
<span class="font-medium">{{ activeEvent.location || "Unknown" }}</span>
|
|
||||||
</span>
|
|
||||||
<span class="inline-flex items-center gap-1.5 rounded-md border px-2 py-1 text-xs">
|
|
||||||
<User class="size-3.5 opacity-80" />
|
|
||||||
<span class="font-medium">Created by: {{ activeEvent.creator_name || "Unknown User"
|
|
||||||
}}</span>
|
|
||||||
</span>
|
|
||||||
</section>
|
</section>
|
||||||
<!-- Description -->
|
<!-- Description -->
|
||||||
<section class="space-y-2 w-full">
|
<section class="space-y-2 w-full">
|
||||||
@@ -181,46 +249,41 @@ defineExpose({forceReload})
|
|||||||
{{ activeEvent.description }}
|
{{ activeEvent.description }}
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
<!-- Attendance -->
|
<!-- attendance -->
|
||||||
<section class="space-y-2 w-full">
|
<section class="space-y-2 w-full">
|
||||||
<p class="text-lg font-semibold">Attendance</p>
|
<div class="flex items-center gap-5">
|
||||||
|
<p class="text-lg font-semibold">Attendance</p>
|
||||||
|
<!-- <div class="text-muted-foreground flex gap-6">
|
||||||
|
<p>Going <span class="ml-1">{{ attendanceStatusSummary.attending }}</span></p>
|
||||||
|
<p>Maybe <span class="ml-1">{{ attendanceStatusSummary.maybe }}</span></p>
|
||||||
|
<p>Declined <span class="ml-1">{{ attendanceStatusSummary.notAttending }}</span></p>
|
||||||
|
</div> -->
|
||||||
|
</div>
|
||||||
<div class="flex flex-col border bg-muted/50 rounded-lg min-h-24 my-2">
|
<div class="flex flex-col border bg-muted/50 rounded-lg min-h-24 my-2">
|
||||||
<div class="flex w-full pt-2 border-b *:w-full *:text-center *:pb-1 *:cursor-pointer">
|
<div class="flex w-full pt-2 border-b *:w-full *:text-center *:pb-1 *:cursor-pointer">
|
||||||
<label
|
<label :class="attendanceTab === 'Alpha' ? 'border-b-3 border-foreground' : 'mb-[2px]'"
|
||||||
:class="viewedState === CalendarAttendance.Attending ? 'border-b-3 border-foreground' : 'mb-[2px]'"
|
@click="attendanceTab = 'Alpha'">Alpha {{ attendanceCountsByGroup.Alpha }}</label>
|
||||||
@click="viewedState = CalendarAttendance.Attending">Going {{ attending.length }}</label>
|
<label :class="attendanceTab === 'Echo' ? 'border-b-3 border-foreground' : 'mb-[2px]'"
|
||||||
<label
|
@click="attendanceTab = 'Echo'">Echo {{ attendanceCountsByGroup.Echo }}</label>
|
||||||
:class="viewedState === CalendarAttendance.Maybe ? 'border-b-3 border-foreground' : 'mb-[2px]'"
|
<label :class="attendanceTab === 'Other' ? 'border-b-3 border-foreground' : 'mb-[2px]'"
|
||||||
@click="viewedState = CalendarAttendance.Maybe">Maybe {{ maybe.length }}</label>
|
@click="attendanceTab = 'Other'">Other {{ attendanceCountsByGroup.Other }}</label>
|
||||||
<label
|
|
||||||
:class="viewedState === CalendarAttendance.NotAttending ? 'border-b-3 border-foreground' : 'mb-[2px]'"
|
|
||||||
@click="viewedState = CalendarAttendance.NotAttending">Declined {{ declined.length
|
|
||||||
}}</label>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="px-5 py-4 min-h-28">
|
<div class="pb-1 min-h-48">
|
||||||
<div v-if="viewedState === CalendarAttendance.Attending" v-for="person in attending">
|
<div class="grid grid-cols-2 font-semibold text-muted-foreground border-b py-1 px-3 mb-2">
|
||||||
<p>{{ person.member_name }}</p>
|
<p>Name</p>
|
||||||
|
<p class="text-right">Status</p>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="viewedState === CalendarAttendance.Maybe" v-for="person in maybe">
|
|
||||||
<p>{{ person.member_name }}</p>
|
<div v-for="person in attendanceList" :key="person.member_id"
|
||||||
</div>
|
class="grid grid-cols-2 py-1 *:px-3 hover:bg-muted">
|
||||||
<div v-if="viewedState === CalendarAttendance.NotAttending" v-for="person in declined">
|
|
||||||
<p>{{ person.member_name }}</p>
|
<p>{{ person.member_name }}</p>
|
||||||
|
<p :class="statusColor(person.status)" class="text-right">
|
||||||
|
{{ displayStatus(person.status) }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
<!-- Footer (optional actions) -->
|
|
||||||
<!-- <div class="border-t px-4 py-3 flex items-center justify-end gap-2">
|
|
||||||
<button class="rounded-md border px-3 py-1.5 text-sm hover:bg-muted/40 transition">
|
|
||||||
Edit
|
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
class="rounded-md bg-primary text-primary-foreground px-3 py-1.5 text-sm hover:opacity-90 transition">
|
|
||||||
Open details
|
|
||||||
</button>
|
|
||||||
</div> -->
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,26 +1,47 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Check, Search } from "lucide-vue-next"
|
import { Check, Search } from "lucide-vue-next"
|
||||||
import { Combobox, ComboboxAnchor, ComboboxEmpty, ComboboxGroup, ComboboxInput, ComboboxItem, ComboboxItemIndicator, ComboboxList } from "@/components/ui/combobox"
|
import { ComboboxAnchor, ComboboxEmpty, ComboboxGroup, ComboboxInput, ComboboxItem, ComboboxItemIndicator, ComboboxList } from "@/components/ui/combobox"
|
||||||
import { onMounted, ref } from "vue";
|
import { computed, onMounted, ref, watch } from "vue";
|
||||||
import { Member, getMembers } from "@/api/member";
|
import { Member, getMembers } from "@/api/member";
|
||||||
import Button from "@/components/ui/button/Button.vue";
|
import Button from "@/components/ui/button/Button.vue";
|
||||||
import {
|
import {
|
||||||
CalendarDate,
|
CalendarDate,
|
||||||
DateFormatter,
|
DateFormatter,
|
||||||
|
fromDate,
|
||||||
getLocalTimeZone,
|
getLocalTimeZone,
|
||||||
|
parseDate,
|
||||||
|
today,
|
||||||
} from "@internationalized/date"
|
} from "@internationalized/date"
|
||||||
import type { DateRange } from "reka-ui"
|
import type { DateRange, DateValue } from "reka-ui"
|
||||||
import type { Ref } from "vue"
|
import type { Ref } from "vue"
|
||||||
import Popover from "@/components/ui/popover/Popover.vue";
|
import Popover from "@/components/ui/popover/Popover.vue";
|
||||||
import PopoverTrigger from "@/components/ui/popover/PopoverTrigger.vue";
|
import PopoverTrigger from "@/components/ui/popover/PopoverTrigger.vue";
|
||||||
import PopoverContent from "@/components/ui/popover/PopoverContent.vue";
|
import PopoverContent from "@/components/ui/popover/PopoverContent.vue";
|
||||||
import { RangeCalendar } from "@/components/ui/range-calendar"
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { CalendarIcon } from "lucide-vue-next"
|
import { CalendarIcon } from "lucide-vue-next"
|
||||||
import Textarea from "@/components/ui/textarea/Textarea.vue";
|
import Textarea from "@/components/ui/textarea/Textarea.vue";
|
||||||
import { LOARequest, submitLOA } from "@/api/loa"; // <-- import the submit function
|
import { adminSubmitLOA, getLoaPolicy, getLoaTypes, submitLOA } from "@/api/loa"; // <-- import the submit function
|
||||||
|
import { LOARequest, LOAType } from "@shared/types/loa";
|
||||||
|
import { useForm, Field as VeeField } from "vee-validate";
|
||||||
|
import {
|
||||||
|
Field,
|
||||||
|
FieldContent,
|
||||||
|
FieldDescription,
|
||||||
|
FieldGroup,
|
||||||
|
FieldLabel,
|
||||||
|
} from '@/components/ui/field'
|
||||||
|
import Combobox from "../ui/combobox/Combobox.vue";
|
||||||
|
import Select from "../ui/select/Select.vue";
|
||||||
|
import SelectTrigger from "../ui/select/SelectTrigger.vue";
|
||||||
|
import SelectValue from "../ui/select/SelectValue.vue";
|
||||||
|
import SelectContent from "../ui/select/SelectContent.vue";
|
||||||
|
import SelectItem from "../ui/select/SelectItem.vue";
|
||||||
|
import FieldError from "../ui/field/FieldError.vue";
|
||||||
|
|
||||||
const members = ref<Member[]>([])
|
const members = ref<Member[]>([])
|
||||||
|
const loaTypes = ref<LOAType[]>();
|
||||||
|
const policyString = ref<string | null>(null);
|
||||||
|
|
||||||
const currentMember = ref<Member | null>(null);
|
const currentMember = ref<Member | null>(null);
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
@@ -31,142 +52,226 @@ const props = withDefaults(defineProps<{
|
|||||||
member: null,
|
member: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const df = new Intl.DateTimeFormat('en-US', {
|
||||||
|
year: 'numeric',
|
||||||
|
month: 'long',
|
||||||
|
day: 'numeric'
|
||||||
|
});
|
||||||
|
|
||||||
const df = new DateFormatter("en-US", {
|
const userStore = useUserStore()
|
||||||
dateStyle: "medium",
|
|
||||||
|
//form stuff
|
||||||
|
import { loaSchema } from '@shared/schemas/loaSchema'
|
||||||
|
import { toTypedSchema } from "@vee-validate/zod";
|
||||||
|
import Calendar from "../ui/calendar/Calendar.vue";
|
||||||
|
import { useUserStore } from "@/stores/user";
|
||||||
|
|
||||||
|
const { handleSubmit, values, resetForm } = useForm({
|
||||||
|
validationSchema: toTypedSchema(loaSchema),
|
||||||
})
|
})
|
||||||
|
|
||||||
const value = ref({
|
const onSubmit = handleSubmit(async (values) => {
|
||||||
// start: new CalendarDate(2022, 1, 20),
|
console.log(values);
|
||||||
// end: new CalendarDate(2022, 1, 20).add({ days: 20 }),
|
const out: LOARequest = {
|
||||||
}) as Ref<DateRange>
|
member_id: values.member_id,
|
||||||
|
start_date: values.start_date,
|
||||||
const reason = ref(""); // <-- reason for LOA
|
end_date: values.end_date,
|
||||||
const submitting = ref(false);
|
type_id: values.type.id,
|
||||||
const submitError = ref<string | null>(null);
|
reason: values.reason
|
||||||
const submitSuccess = ref(false);
|
};
|
||||||
|
if (props.adminMode) {
|
||||||
|
await adminSubmitLOA(out);
|
||||||
|
} else {
|
||||||
|
await submitLOA(out);
|
||||||
|
userStore.loadUser();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (props.member) {
|
if (props.member) {
|
||||||
currentMember.value = props.member;
|
currentMember.value = props.member;
|
||||||
}
|
}
|
||||||
if (props.adminMode) {
|
try {
|
||||||
members.value = await getMembers();
|
if (!props.adminMode) {
|
||||||
|
let policy = await getLoaPolicy() as any;
|
||||||
|
policyString.value = policy;
|
||||||
|
policyRef.value.innerHTML = policyString.value;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
members.value = await getMembers();
|
members.value = await getMembers();
|
||||||
|
loaTypes.value = await getLoaTypes();
|
||||||
|
resetForm({ values: { member_id: currentMember.value?.member_id } });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Submit handler
|
const policyRef = ref<HTMLElement>(null);
|
||||||
async function handleSubmit() {
|
|
||||||
submitError.value = null;
|
|
||||||
submitSuccess.value = false;
|
|
||||||
submitting.value = true;
|
|
||||||
|
|
||||||
// Use currentMember if adminMode, otherwise use your own member id (stubbed as 89 here)
|
const defaultPlaceholder = today(getLocalTimeZone())
|
||||||
const member_id = currentMember.value?.member_id ?? 89;
|
|
||||||
|
|
||||||
// Format dates as ISO strings
|
const minEndDate = computed(() => {
|
||||||
const filed_date = toMariaDBDatetime(new Date());
|
if (values.start_date) {
|
||||||
const start_date = toMariaDBDatetime(value.value.start?.toDate(getLocalTimeZone()));
|
return new CalendarDate(values.start_date.getFullYear(), values.start_date.getMonth() + 1, values.start_date.getDate())
|
||||||
const end_date = toMariaDBDatetime(value.value.end?.toDate(getLocalTimeZone()));
|
|
||||||
|
|
||||||
if (!member_id || !filed_date || !start_date || !end_date) {
|
|
||||||
submitError.value = "Missing required fields";
|
|
||||||
submitting.value = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const req: LOARequest = {
|
|
||||||
filed_date,
|
|
||||||
start_date,
|
|
||||||
end_date,
|
|
||||||
reason: reason.value,
|
|
||||||
member_id
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await submitLOA(req);
|
|
||||||
submitting.value = false;
|
|
||||||
|
|
||||||
if (result.id) {
|
|
||||||
submitSuccess.value = true;
|
|
||||||
reason.value = "";
|
|
||||||
} else {
|
} else {
|
||||||
submitError.value = result.error || "Failed to submit LOA";
|
return null;
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
function toMariaDBDatetime(date: Date): string {
|
const maxEndDate = computed(() => {
|
||||||
return date.toISOString().slice(0, 19).replace('T', ' ');
|
if (values.type && values.start_date) {
|
||||||
}
|
let endDateObj = new Date(values.start_date.getTime() + values.type.max_length_days * 24 * 60 * 60 * 1000);
|
||||||
|
return new CalendarDate(endDateObj.getFullYear(), endDateObj.getMonth() + 1, endDateObj.getDate())
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})
|
||||||
</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="flex flex-row-reverse gap-6 mx-auto w-full" :class="!adminMode ? 'max-w-5xl' : 'max-w-5xl'">
|
||||||
<div v-if="!adminMode" class="flex-1 flex space-x-4 rounded-md border p-4">
|
<div v-if="!adminMode" class="flex-1 flex flex-col space-x-4 rounded-md border p-4">
|
||||||
<div class="flex-2 space-y-1">
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">LOA Policy</p>
|
||||||
<p class="text-sm font-medium leading-none">
|
<div ref="policyRef">
|
||||||
LOA Policy
|
<!-- LOA policy gets loaded here -->
|
||||||
</p>
|
|
||||||
<p class="text-sm text-muted-foreground">
|
|
||||||
Policy goes here.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-1 flex flex-col gap-5">
|
<div class="flex-1 flex flex-col gap-5">
|
||||||
<div class="flex w-full gap-5 ">
|
<form @submit="onSubmit" class="flex flex-col gap-2">
|
||||||
<Combobox class="w-1/2" v-model="currentMember" :disabled="!adminMode">
|
<div class="flex w-full gap-5">
|
||||||
<ComboboxAnchor class="w-full">
|
<VeeField v-slot="{ field, errors }" name="member_id">
|
||||||
<ComboboxInput placeholder="Search members..." class="w-full pl-9"
|
<Field>
|
||||||
:display-value="(v) => v ? v.member_name : ''" />
|
<FieldContent>
|
||||||
</ComboboxAnchor>
|
<FieldLabel>Member</FieldLabel>
|
||||||
<ComboboxList class="w-full">
|
<Combobox :model-value="field.value" @update:model-value="field.onChange"
|
||||||
<ComboboxEmpty class="text-muted-foreground">No results</ComboboxEmpty>
|
:disabled="!adminMode">
|
||||||
<ComboboxGroup>
|
<ComboboxAnchor class="w-full">
|
||||||
<template v-for="member in members" :key="member.member_id">
|
<ComboboxInput placeholder="Search members..." class="w-full pl-3"
|
||||||
<ComboboxItem :value="member"
|
:display-value="(id) => {
|
||||||
class="data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground relative cursor-pointer select-none px-2 py-1.5">
|
const m = members.find(mem => mem.member_id === id)
|
||||||
{{ member.member_name }}
|
return m ? m.member_name : ''
|
||||||
<ComboboxItemIndicator class="absolute left-2 inline-flex items-center">
|
}" />
|
||||||
<Check class="h-4 w-4" />
|
</ComboboxAnchor>
|
||||||
</ComboboxItemIndicator>
|
<ComboboxList class="*:w-64">
|
||||||
</ComboboxItem>
|
<ComboboxEmpty class="text-muted-foreground w-full">No results</ComboboxEmpty>
|
||||||
</template>
|
<ComboboxGroup>
|
||||||
</ComboboxGroup>
|
<template v-for="member in members" :key="member.member_id">
|
||||||
</ComboboxList>
|
<ComboboxItem :value="member.member_id"
|
||||||
</Combobox>
|
class="data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground relative cursor-pointer select-none px-2 py-1.5 w-full">
|
||||||
<Popover>
|
{{ member.member_name }}
|
||||||
<PopoverTrigger as-child>
|
<ComboboxItemIndicator
|
||||||
<Button variant="outline" :class="cn(
|
class="absolute left-2 inline-flex items-center">
|
||||||
'w-1/2 justify-start text-left font-normal',
|
<Check class="h-4 w-4" />
|
||||||
!value && 'text-muted-foreground',
|
</ComboboxItemIndicator>
|
||||||
)">
|
</ComboboxItem>
|
||||||
<CalendarIcon class="mr-2 h-4 w-4" />
|
</template>
|
||||||
<template v-if="value.start">
|
</ComboboxGroup>
|
||||||
<template v-if="value.end">
|
</ComboboxList>
|
||||||
{{ df.format(value.start.toDate(getLocalTimeZone())) }} - {{
|
</Combobox>
|
||||||
df.format(value.end.toDate(getLocalTimeZone())) }}
|
<div class="h-4">
|
||||||
</template>
|
<FieldError v-if="errors.length" :errors="errors"></FieldError>
|
||||||
<template v-else>
|
</div>
|
||||||
{{ df.format(value.start.toDate(getLocalTimeZone())) }}
|
</FieldContent>
|
||||||
</template>
|
</Field>
|
||||||
</template>
|
</VeeField>
|
||||||
<template v-else>
|
<VeeField v-slot="{ field, errors }" name="type">
|
||||||
Pick a date
|
<Field class="w-full">
|
||||||
</template>
|
<FieldContent>
|
||||||
</Button>
|
<FieldLabel>Type</FieldLabel>
|
||||||
</PopoverTrigger>
|
<Select :model-value="field.value" @update:model-value="field.onChange">
|
||||||
<PopoverContent class="w-auto p-0">
|
<SelectTrigger class="w-full">
|
||||||
<RangeCalendar v-model="value" initial-focus :number-of-months="2"
|
<SelectValue placeholder="Select type"></SelectValue>
|
||||||
@update:start-value="(startDate) => value.start = startDate" />
|
</SelectTrigger>
|
||||||
</PopoverContent>
|
<SelectContent>
|
||||||
</Popover>
|
<SelectItem v-for="type in loaTypes" :value="type">
|
||||||
</div>
|
{{ type.name }}
|
||||||
<Textarea v-model="reason" placeholder="Reason for LOA" class="w-full resize-none" />
|
</SelectItem>
|
||||||
<div class="flex justify-end">
|
</SelectContent>
|
||||||
<Button :onClick="handleSubmit" :disabled="submitting" class="w-min">Submit</Button>
|
</Select>
|
||||||
</div>
|
<div class="h-4">
|
||||||
<div v-if="submitError" class="text-red-500 text-sm mt-2">{{ submitError }}</div>
|
<FieldError v-if="errors.length" :errors="errors"></FieldError>
|
||||||
<div v-if="submitSuccess" class="text-green-500 text-sm mt-2">LOA submitted successfully!</div>
|
</div>
|
||||||
|
</FieldContent>
|
||||||
|
</Field>
|
||||||
|
</VeeField>
|
||||||
|
</div>
|
||||||
|
<div class="flex gap-5">
|
||||||
|
<VeeField v-slot="{ field, errors }" name="start_date">
|
||||||
|
<Field>
|
||||||
|
<FieldContent>
|
||||||
|
<FieldLabel>Start Date</FieldLabel>
|
||||||
|
<Popover>
|
||||||
|
<PopoverTrigger as-child>
|
||||||
|
<Button variant="outline" :class="cn(
|
||||||
|
'w-full justify-start text-left font-normal',
|
||||||
|
!field.value && 'text-muted-foreground',
|
||||||
|
)">
|
||||||
|
<CalendarIcon class="mr-2 h-4 w-4" />
|
||||||
|
{{ field.value ? df.format(field.value) : "Pick a date" }}
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent class="w-auto p-0">
|
||||||
|
<Calendar
|
||||||
|
:model-value="field.value
|
||||||
|
? new CalendarDate(field.value.getFullYear(), field.value.getMonth() + 1, field.value.getDate()) : null"
|
||||||
|
@update:model-value="(val: CalendarDate) => field.onChange(val.toDate(getLocalTimeZone()))"
|
||||||
|
layout="month-and-year" :min-value="today(getLocalTimeZone())" />
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
<div class="h-4">
|
||||||
|
<FieldError v-if="errors.length" :errors="errors"></FieldError>
|
||||||
|
</div>
|
||||||
|
</FieldContent>
|
||||||
|
</Field>
|
||||||
|
</VeeField>
|
||||||
|
<VeeField v-slot="{ field, errors }" name="end_date">
|
||||||
|
<Field>
|
||||||
|
<FieldContent>
|
||||||
|
<FieldLabel>End Date</FieldLabel>
|
||||||
|
<Popover>
|
||||||
|
<PopoverTrigger as-child>
|
||||||
|
<Button variant="outline" :class="cn(
|
||||||
|
'w-full justify-start text-left font-normal',
|
||||||
|
!field.value && 'text-muted-foreground',
|
||||||
|
)">
|
||||||
|
<CalendarIcon class="mr-2 h-4 w-4" />
|
||||||
|
{{ field.value ? df.format(field.value) : "Pick a date" }}
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent class="w-auto p-0">
|
||||||
|
<Calendar
|
||||||
|
:model-value="field.value ? new CalendarDate(field.value.getFullYear(), field.value.getMonth() + 1, field.value.getDate()) : null"
|
||||||
|
@update:model-value="(val: CalendarDate) => field.onChange(val.toDate(getLocalTimeZone()))"
|
||||||
|
:default-placeholder="defaultPlaceholder" :min-value="minEndDate"
|
||||||
|
:max-value="maxEndDate" layout="month-and-year">
|
||||||
|
</Calendar>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
<div class="h-4">
|
||||||
|
<FieldError v-if="errors.length" :errors="errors"></FieldError>
|
||||||
|
</div>
|
||||||
|
</FieldContent>
|
||||||
|
</Field>
|
||||||
|
</VeeField>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<VeeField v-slot="{ field, errors }" name="reason">
|
||||||
|
<Field>
|
||||||
|
<FieldContent>
|
||||||
|
<FieldLabel>Reason</FieldLabel>
|
||||||
|
<Textarea :model-value="field.value" @update:model-value="field.onChange"
|
||||||
|
placeholder="Reason for LOA" class="resize-none h-28"></Textarea>
|
||||||
|
<div class="h-4">
|
||||||
|
<FieldError v-if="errors.length" :errors="errors"></FieldError>
|
||||||
|
</div>
|
||||||
|
</FieldContent>
|
||||||
|
</Field>
|
||||||
|
</VeeField>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<Button type="submit">Submit</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -16,30 +16,53 @@ import {
|
|||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu"
|
} from "@/components/ui/dropdown-menu"
|
||||||
import { Ellipsis } from "lucide-vue-next";
|
import { Ellipsis } from "lucide-vue-next";
|
||||||
import { getAllLOAs, LOARequest } from "@/api/loa";
|
import { cancelLOA, extendLOA, getAllLOAs, getMyLOAs } from "@/api/loa";
|
||||||
import { onMounted, ref, computed } from "vue";
|
import { onMounted, ref, computed } from "vue";
|
||||||
|
import { LOARequest } from "@shared/types/loa";
|
||||||
|
import Dialog from "../ui/dialog/Dialog.vue";
|
||||||
|
import DialogTrigger from "../ui/dialog/DialogTrigger.vue";
|
||||||
|
import DialogContent from "../ui/dialog/DialogContent.vue";
|
||||||
|
import DialogHeader from "../ui/dialog/DialogHeader.vue";
|
||||||
|
import DialogTitle from "../ui/dialog/DialogTitle.vue";
|
||||||
|
import DialogDescription from "../ui/dialog/DialogDescription.vue";
|
||||||
|
import Button from "../ui/button/Button.vue";
|
||||||
|
import Calendar from "../ui/calendar/Calendar.vue";
|
||||||
|
import {
|
||||||
|
CalendarDate,
|
||||||
|
getLocalTimeZone,
|
||||||
|
} from "@internationalized/date"
|
||||||
|
import { el } from "@fullcalendar/core/internal-common";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
adminMode?: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
const LOAList = ref<LOARequest[]>([]);
|
const LOAList = ref<LOARequest[]>([]);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
LOAList.value = await getAllLOAs();
|
await loadLOAs();
|
||||||
});
|
});
|
||||||
|
|
||||||
function formatDate(dateStr: string): string {
|
async function loadLOAs() {
|
||||||
if (!dateStr) return "";
|
if (props.adminMode) {
|
||||||
return new Date(dateStr).toLocaleDateString("en-US", {
|
LOAList.value = await getAllLOAs();
|
||||||
|
} else {
|
||||||
|
LOAList.value = await getMyLOAs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDate(date: Date): string {
|
||||||
|
if (!date) return "";
|
||||||
|
date = typeof date === 'string' ? new Date(date) : date;
|
||||||
|
return date.toLocaleDateString("en-US", {
|
||||||
year: "numeric",
|
year: "numeric",
|
||||||
month: "short",
|
month: "short",
|
||||||
day: "numeric",
|
day: "numeric",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loaStatus(loa: {
|
function loaStatus(loa: LOARequest): "Upcoming" | "Active" | "Overdue" | "Closed" {
|
||||||
start_date: string;
|
if (loa.closed) return "Closed";
|
||||||
end_date: string;
|
|
||||||
deleted?: number;
|
|
||||||
}): "Upcoming" | "Active" | "Expired" | "Cancelled" {
|
|
||||||
if (loa.deleted) return "Cancelled";
|
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const start = new Date(loa.start_date);
|
const start = new Date(loa.start_date);
|
||||||
@@ -47,9 +70,9 @@ function loaStatus(loa: {
|
|||||||
|
|
||||||
if (now < start) return "Upcoming";
|
if (now < start) return "Upcoming";
|
||||||
if (now >= start && now <= end) return "Active";
|
if (now >= start && now <= end) return "Active";
|
||||||
if (now > end) return "Expired";
|
if (now > end) return "Overdue";
|
||||||
|
|
||||||
return "Expired"; // fallback
|
return "Overdue"; // fallback
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortByStartDate(loas: LOARequest[]): LOARequest[] {
|
function sortByStartDate(loas: LOARequest[]): LOARequest[] {
|
||||||
@@ -58,50 +81,108 @@ function sortByStartDate(loas: LOARequest[]): LOARequest[] {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortedLoas = computed(() => sortByStartDate(LOAList.value));
|
async function cancelAndReload(id: number) {
|
||||||
|
await cancelLOA(id, props.adminMode);
|
||||||
|
await loadLOAs();
|
||||||
|
}
|
||||||
|
|
||||||
|
const isExtending = ref(false);
|
||||||
|
const targetLOA = ref<LOARequest | null>(null);
|
||||||
|
const extendTo = ref<CalendarDate | null>(null);
|
||||||
|
|
||||||
|
const targetEnd = computed(() => { return targetLOA.value.extended_till ? targetLOA.value.extended_till : targetLOA.value.end_date })
|
||||||
|
|
||||||
|
function toCalendarDate(date: Date): CalendarDate {
|
||||||
|
if (typeof date === 'string')
|
||||||
|
date = new Date(date);
|
||||||
|
return new CalendarDate(date.getFullYear(), date.getMonth() + 1, date.getDate())
|
||||||
|
}
|
||||||
|
|
||||||
|
async function commitExtend() {
|
||||||
|
await extendLOA(targetLOA.value.id, extendTo.value.toDate(getLocalTimeZone()));
|
||||||
|
isExtending.value = false;
|
||||||
|
await loadLOAs();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="w-5xl mx-auto">
|
<div>
|
||||||
<Table>
|
<Dialog :open="isExtending" @update:open="(val) => isExtending = val">
|
||||||
<TableHeader>
|
<DialogContent>
|
||||||
<TableRow>
|
<DialogHeader>
|
||||||
<TableHead class="w-[100px]">Member</TableHead>
|
<DialogTitle>Extend {{ targetLOA.name }}'s Leave of Absence </DialogTitle>
|
||||||
<TableHead>Start</TableHead>
|
</DialogHeader>
|
||||||
<TableHead>End</TableHead>
|
<div class="flex gap-5">
|
||||||
<TableHead>Reason</TableHead>
|
<Calendar v-model="extendTo" class="rounded-md border shadow-sm w-min" layout="month-and-year"
|
||||||
<TableHead>Posted on</TableHead>
|
:min-value="toCalendarDate(targetEnd)"
|
||||||
<TableHead>Status</TableHead>
|
:max-value="toCalendarDate(targetEnd).add({ years: 1 })" />
|
||||||
</TableRow>
|
<div class="flex flex-col w-full gap-3 px-2">
|
||||||
</TableHeader>
|
<p>Quick Options</p>
|
||||||
<TableBody>
|
<Button variant="outline" @click="extendTo = toCalendarDate(targetEnd).add({ days: 7 })">1
|
||||||
<TableRow v-for="post in sortedLoas" :key="post.id" class="hover:bg-muted/50">
|
Week</Button>
|
||||||
<TableCell class="font-medium">
|
<Button variant="outline" @click="extendTo = toCalendarDate(targetEnd).add({ months: 1 })">1
|
||||||
{{ post.name }}
|
Month</Button>
|
||||||
</TableCell>
|
</div>
|
||||||
<TableCell>{{ formatDate(post.start_date) }}</TableCell>
|
</div>
|
||||||
<TableCell>{{ formatDate(post.end_date) }}</TableCell>
|
<div class="flex justify-end gap-4">
|
||||||
<TableCell>{{ post.reason }}</TableCell>
|
<Button variant="outline" @click="isExtending = false">Cancel</Button>
|
||||||
<TableCell>{{ formatDate(post.filed_date) }}</TableCell>
|
<Button @click="commitExtend">Extend</Button>
|
||||||
<TableCell>
|
</div>
|
||||||
<Badge v-if="loaStatus(post) === 'Upcoming'" class="bg-blue-500">Upcoming</Badge>
|
</DialogContent>
|
||||||
<Badge v-else-if="loaStatus(post) === 'Active'" class="bg-green-500">Active</Badge>
|
</Dialog>
|
||||||
<Badge v-else-if="loaStatus(post) === 'Expired'" class="bg-gray-400">Expired</Badge>
|
<div class="max-w-7xl w-full mx-auto">
|
||||||
<Badge v-else class="bg-red-500">Cancelled</Badge>
|
<Table>
|
||||||
</TableCell>
|
<TableHeader>
|
||||||
<TableCell @click.stop="console.log('hi')" class="text-right">
|
<TableRow>
|
||||||
<DropdownMenu>
|
<TableHead>Member</TableHead>
|
||||||
<DropdownMenuTrigger class="cursor-pointer">
|
<TableHead>Type</TableHead>
|
||||||
<Ellipsis></Ellipsis>
|
<TableHead>Start</TableHead>
|
||||||
</DropdownMenuTrigger>
|
<TableHead>End</TableHead>
|
||||||
<DropdownMenuContent>
|
<TableHead class="w-[500px]">Reason</TableHead>
|
||||||
<DropdownMenuItem :variant="'destructive'">Cancel</DropdownMenuItem>
|
<TableHead>Posted on</TableHead>
|
||||||
</DropdownMenuContent>
|
<TableHead>Status</TableHead>
|
||||||
</DropdownMenu>
|
</TableRow>
|
||||||
</TableCell>
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
</TableRow>
|
<TableRow v-for="post in LOAList" :key="post.id" class="hover:bg-muted/50">
|
||||||
</TableBody>
|
<TableCell class="font-medium">
|
||||||
</Table>
|
{{ post.name }}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{{ post.type_name }}</TableCell>
|
||||||
|
<TableCell>{{ formatDate(post.start_date) }}</TableCell>
|
||||||
|
<TableCell>{{ post.extended_till ? formatDate(post.extended_till) : formatDate(post.end_date) }}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{{ post.reason }}</TableCell>
|
||||||
|
<TableCell>{{ formatDate(post.filed_date) }}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Badge v-if="loaStatus(post) === 'Upcoming'" class="bg-blue-400">Upcoming</Badge>
|
||||||
|
<Badge v-else-if="loaStatus(post) === 'Active'" class="bg-green-500">Active</Badge>
|
||||||
|
<Badge v-else-if="loaStatus(post) === 'Overdue'" class="bg-yellow-400">Overdue</Badge>
|
||||||
|
<Badge v-else class="bg-gray-400">Ended</Badge>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell @click.stop="" class="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger class="cursor-pointer">
|
||||||
|
<Ellipsis></Ellipsis>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent>
|
||||||
|
<DropdownMenuItem v-if="!post.closed && props.adminMode"
|
||||||
|
@click="isExtending = true; targetLOA = post">
|
||||||
|
Extend
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem v-if="!post.closed" :variant="'destructive'"
|
||||||
|
@click="cancelAndReload(post.id)">End
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<!-- Fallback: no actions available -->
|
||||||
|
<p v-if="post.closed || (!props.adminMode && post.closed)" class="p-2 text-center text-sm">
|
||||||
|
No actions
|
||||||
|
</p>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { reactiveOmit } from "@vueuse/core";
|
import { getLocalTimeZone, today } from "@internationalized/date";
|
||||||
import { CalendarRoot, useForwardPropsEmits } from "reka-ui";
|
import { createReusableTemplate, reactiveOmit, useVModel } from "@vueuse/core";
|
||||||
|
import { CalendarRoot, useDateFormatter, useForwardPropsEmits } from "reka-ui";
|
||||||
|
import { createYear, createYearRange, toDate } from "reka-ui/date";
|
||||||
|
import { computed, toRaw } from "vue";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import {
|
||||||
|
NativeSelect,
|
||||||
|
NativeSelectOption,
|
||||||
|
} from '@/components/ui/native-select';
|
||||||
import {
|
import {
|
||||||
CalendarCell,
|
CalendarCell,
|
||||||
CalendarCellTrigger,
|
CalendarCellTrigger,
|
||||||
@@ -38,34 +45,165 @@ const props = defineProps({
|
|||||||
dir: { type: String, required: false },
|
dir: { type: String, required: false },
|
||||||
nextPage: { type: Function, required: false },
|
nextPage: { type: Function, required: false },
|
||||||
prevPage: { type: Function, required: false },
|
prevPage: { type: Function, required: false },
|
||||||
modelValue: { type: null, required: false },
|
modelValue: { type: null, required: false, default: undefined },
|
||||||
multiple: { type: Boolean, required: false },
|
multiple: { type: Boolean, required: false },
|
||||||
disableDaysOutsideCurrentView: { type: Boolean, required: false },
|
disableDaysOutsideCurrentView: { type: Boolean, required: false },
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
|
layout: { type: null, required: false, default: undefined },
|
||||||
|
yearRange: { type: Array, required: false },
|
||||||
});
|
});
|
||||||
const emits = defineEmits(["update:modelValue", "update:placeholder"]);
|
const emits = defineEmits(["update:modelValue", "update:placeholder"]);
|
||||||
|
|
||||||
const delegatedProps = reactiveOmit(props, "class");
|
const delegatedProps = reactiveOmit(props, "class", "layout", "placeholder");
|
||||||
|
|
||||||
|
const placeholder = useVModel(props, "placeholder", emits, {
|
||||||
|
passive: true,
|
||||||
|
defaultValue: props.defaultPlaceholder ?? today(getLocalTimeZone()),
|
||||||
|
});
|
||||||
|
|
||||||
|
const formatter = useDateFormatter(props.locale ?? "en");
|
||||||
|
|
||||||
|
const yearRange = computed(() => {
|
||||||
|
return (
|
||||||
|
props.yearRange ??
|
||||||
|
createYearRange({
|
||||||
|
start:
|
||||||
|
props?.minValue ??
|
||||||
|
(
|
||||||
|
toRaw(props.placeholder) ??
|
||||||
|
props.defaultPlaceholder ??
|
||||||
|
today(getLocalTimeZone())
|
||||||
|
).cycle("year", -100),
|
||||||
|
|
||||||
|
end:
|
||||||
|
props?.maxValue ??
|
||||||
|
(
|
||||||
|
toRaw(props.placeholder) ??
|
||||||
|
props.defaultPlaceholder ??
|
||||||
|
today(getLocalTimeZone())
|
||||||
|
).cycle("year", 10),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const [DefineMonthTemplate, ReuseMonthTemplate] = createReusableTemplate();
|
||||||
|
const [DefineYearTemplate, ReuseYearTemplate] = createReusableTemplate();
|
||||||
|
|
||||||
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<DefineMonthTemplate v-slot="{ date }">
|
||||||
|
<div class="**:data-[slot=native-select-icon]:right-1">
|
||||||
|
<div class="relative">
|
||||||
|
<div
|
||||||
|
class="absolute inset-0 flex h-full items-center text-sm pl-2 pointer-events-none"
|
||||||
|
>
|
||||||
|
{{ formatter.custom(toDate(date), { month: "short" }) }}
|
||||||
|
</div>
|
||||||
|
<NativeSelect
|
||||||
|
class="text-xs h-8 pr-6 pl-2 text-transparent relative"
|
||||||
|
@change="
|
||||||
|
(e) => {
|
||||||
|
placeholder = placeholder.set({
|
||||||
|
month: Number(e?.target?.value),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<NativeSelectOption
|
||||||
|
v-for="month in createYear({ dateObj: date })"
|
||||||
|
:key="month.toString()"
|
||||||
|
:value="month.month"
|
||||||
|
:selected="date.month === month.month"
|
||||||
|
>
|
||||||
|
{{ formatter.custom(toDate(month), { month: "short" }) }}
|
||||||
|
</NativeSelectOption>
|
||||||
|
</NativeSelect>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DefineMonthTemplate>
|
||||||
|
|
||||||
|
<DefineYearTemplate v-slot="{ date }">
|
||||||
|
<div class="**:data-[slot=native-select-icon]:right-1">
|
||||||
|
<div class="relative">
|
||||||
|
<div
|
||||||
|
class="absolute inset-0 flex h-full items-center text-sm pl-2 pointer-events-none"
|
||||||
|
>
|
||||||
|
{{ formatter.custom(toDate(date), { year: "numeric" }) }}
|
||||||
|
</div>
|
||||||
|
<NativeSelect
|
||||||
|
class="text-xs h-8 pr-6 pl-2 text-transparent relative"
|
||||||
|
@change="
|
||||||
|
(e) => {
|
||||||
|
placeholder = placeholder.set({
|
||||||
|
year: Number(e?.target?.value),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<NativeSelectOption
|
||||||
|
v-for="year in yearRange"
|
||||||
|
:key="year.toString()"
|
||||||
|
:value="year.year"
|
||||||
|
:selected="date.year === year.year"
|
||||||
|
>
|
||||||
|
{{ formatter.custom(toDate(year), { year: "numeric" }) }}
|
||||||
|
</NativeSelectOption>
|
||||||
|
</NativeSelect>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</DefineYearTemplate>
|
||||||
|
|
||||||
<CalendarRoot
|
<CalendarRoot
|
||||||
v-slot="{ grid, weekDays }"
|
v-slot="{ grid, weekDays, date }"
|
||||||
|
v-bind="forwarded"
|
||||||
|
v-model:placeholder="placeholder"
|
||||||
data-slot="calendar"
|
data-slot="calendar"
|
||||||
:class="cn('p-3', props.class)"
|
:class="cn('p-3', props.class)"
|
||||||
v-bind="forwarded"
|
|
||||||
>
|
>
|
||||||
<CalendarHeader>
|
<CalendarHeader class="pt-0">
|
||||||
<CalendarHeading />
|
<nav
|
||||||
|
class="flex items-center gap-1 absolute top-0 inset-x-0 justify-between"
|
||||||
|
>
|
||||||
|
<CalendarPrevButton>
|
||||||
|
<slot name="calendar-prev-icon" />
|
||||||
|
</CalendarPrevButton>
|
||||||
|
<CalendarNextButton>
|
||||||
|
<slot name="calendar-next-icon" />
|
||||||
|
</CalendarNextButton>
|
||||||
|
</nav>
|
||||||
|
|
||||||
<div class="flex items-center gap-1">
|
<slot
|
||||||
<CalendarPrevButton />
|
name="calendar-heading"
|
||||||
<CalendarNextButton />
|
:date="date"
|
||||||
</div>
|
:month="ReuseMonthTemplate"
|
||||||
|
:year="ReuseYearTemplate"
|
||||||
|
>
|
||||||
|
<template v-if="layout === 'month-and-year'">
|
||||||
|
<div class="flex items-center justify-center gap-1">
|
||||||
|
<ReuseMonthTemplate :date="date" />
|
||||||
|
<ReuseYearTemplate :date="date" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="layout === 'month-only'">
|
||||||
|
<div class="flex items-center justify-center gap-1">
|
||||||
|
<ReuseMonthTemplate :date="date" />
|
||||||
|
{{ formatter.custom(toDate(date), { year: "numeric" }) }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else-if="layout === 'year-only'">
|
||||||
|
<div class="flex items-center justify-center gap-1">
|
||||||
|
{{ formatter.custom(toDate(date), { month: "short" }) }}
|
||||||
|
<ReuseYearTemplate :date="date" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<CalendarHeading />
|
||||||
|
</template>
|
||||||
|
</slot>
|
||||||
</CalendarHeader>
|
</CalendarHeader>
|
||||||
|
|
||||||
<div class="flex flex-col gap-y-4 mt-4 sm:flex-row sm:gap-x-4 sm:gap-y-0">
|
<div class="flex flex-col gap-y-4 mt-4 sm:flex-row sm:gap-x-4 sm:gap-y-0">
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { cn } from "@/lib/utils";
|
|||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
date: { type: null, required: true },
|
date: { type: null, required: true },
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const props = defineProps({
|
|||||||
day: { type: null, required: true },
|
day: { type: null, required: true },
|
||||||
month: { type: null, required: true },
|
month: { type: null, required: true },
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false, default: "button" },
|
as: { type: null, required: false, default: "button" },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { cn } from "@/lib/utils";
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { CalendarGridBody } from "reka-ui";
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { CalendarGridHead } from "reka-ui";
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { cn } from "@/lib/utils";
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { cn } from "@/lib/utils";
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ const forwardedProps = useForwardProps(delegatedProps);
|
|||||||
data-slot="calendar-head-cell"
|
data-slot="calendar-head-cell"
|
||||||
:class="
|
:class="
|
||||||
cn(
|
cn(
|
||||||
'text-muted-foreground rounded-md w-8 font-normal text-[0.8rem]',
|
'text-muted-foreground rounded-md flex-1 font-normal text-[0.8rem]',
|
||||||
props.class,
|
props.class,
|
||||||
)
|
)
|
||||||
"
|
"
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { cn } from "@/lib/utils";
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -18,7 +18,10 @@ const forwardedProps = useForwardProps(delegatedProps);
|
|||||||
<CalendarHeader
|
<CalendarHeader
|
||||||
data-slot="calendar-header"
|
data-slot="calendar-header"
|
||||||
:class="
|
:class="
|
||||||
cn('flex justify-center pt-1 relative items-center w-full', props.class)
|
cn(
|
||||||
|
'flex justify-center pt-1 relative items-center w-full px-8',
|
||||||
|
props.class,
|
||||||
|
)
|
||||||
"
|
"
|
||||||
v-bind="forwardedProps"
|
v-bind="forwardedProps"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { cn } from "@/lib/utils";
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { buttonVariants } from '@/components/ui/button';
|
|||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
nextPage: { type: Function, required: false },
|
nextPage: { type: Function, required: false },
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -23,7 +23,6 @@ const forwardedProps = useForwardProps(delegatedProps);
|
|||||||
:class="
|
:class="
|
||||||
cn(
|
cn(
|
||||||
buttonVariants({ variant: 'outline' }),
|
buttonVariants({ variant: 'outline' }),
|
||||||
'absolute right-1',
|
|
||||||
'size-7 bg-transparent p-0 opacity-50 hover:opacity-100',
|
'size-7 bg-transparent p-0 opacity-50 hover:opacity-100',
|
||||||
props.class,
|
props.class,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { buttonVariants } from '@/components/ui/button';
|
|||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
prevPage: { type: Function, required: false },
|
prevPage: { type: Function, required: false },
|
||||||
asChild: { type: Boolean, required: false },
|
asChild: { type: Boolean, required: false },
|
||||||
as: { type: [String, Object, Function], required: false },
|
as: { type: null, required: false },
|
||||||
class: { type: null, required: false },
|
class: { type: null, required: false },
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -23,7 +23,6 @@ const forwardedProps = useForwardProps(delegatedProps);
|
|||||||
:class="
|
:class="
|
||||||
cn(
|
cn(
|
||||||
buttonVariants({ variant: 'outline' }),
|
buttonVariants({ variant: 'outline' }),
|
||||||
'absolute left-1',
|
|
||||||
'size-7 bg-transparent p-0 opacity-50 hover:opacity-100',
|
'size-7 bg-transparent p-0 opacity-50 hover:opacity-100',
|
||||||
props.class,
|
props.class,
|
||||||
)
|
)
|
||||||
|
|||||||
51
ui/src/components/ui/native-select/NativeSelect.vue
Normal file
51
ui/src/components/ui/native-select/NativeSelect.vue
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<script setup>
|
||||||
|
import { reactiveOmit, useVModel } from "@vueuse/core";
|
||||||
|
import { ChevronDownIcon } from "lucide-vue-next";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
inheritAttrs: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
modelValue: { type: null, required: false },
|
||||||
|
class: { type: null, required: false },
|
||||||
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits(["update:modelValue"]);
|
||||||
|
|
||||||
|
const modelValue = useVModel(props, "modelValue", emit, {
|
||||||
|
passive: true,
|
||||||
|
defaultValue: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
const delegatedProps = reactiveOmit(props, "class");
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div
|
||||||
|
class="group/native-select relative w-fit has-[select:disabled]:opacity-50"
|
||||||
|
data-slot="native-select-wrapper"
|
||||||
|
>
|
||||||
|
<select
|
||||||
|
v-bind="{ ...$attrs, ...delegatedProps }"
|
||||||
|
v-model="modelValue"
|
||||||
|
data-slot="native-select"
|
||||||
|
:class="
|
||||||
|
cn(
|
||||||
|
'border-input placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 dark:hover:bg-input/50 h-9 w-full min-w-0 appearance-none rounded-md border bg-transparent px-3 py-2 pr-9 text-sm shadow-xs transition-[color,box-shadow] outline-none disabled:pointer-events-none disabled:cursor-not-allowed',
|
||||||
|
'focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]',
|
||||||
|
'aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',
|
||||||
|
props.class,
|
||||||
|
)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</select>
|
||||||
|
<ChevronDownIcon
|
||||||
|
class="text-muted-foreground pointer-events-none absolute top-1/2 right-3.5 size-4 -translate-y-1/2 opacity-50 select-none"
|
||||||
|
aria-hidden="true"
|
||||||
|
data-slot="native-select-icon"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
19
ui/src/components/ui/native-select/NativeSelectOptGroup.vue
Normal file
19
ui/src/components/ui/native-select/NativeSelectOptGroup.vue
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<!-- @fallthroughAttributes true -->
|
||||||
|
<!-- @strictTemplates true -->
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
class: { type: null, required: false },
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<optgroup
|
||||||
|
data-slot="native-select-optgroup"
|
||||||
|
:class="cn('bg-popover text-popover-foreground', props.class)"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</optgroup>
|
||||||
|
</template>
|
||||||
19
ui/src/components/ui/native-select/NativeSelectOption.vue
Normal file
19
ui/src/components/ui/native-select/NativeSelectOption.vue
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<!-- @fallthroughAttributes true -->
|
||||||
|
<!-- @strictTemplates true -->
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
class: { type: null, required: false },
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<option
|
||||||
|
data-slot="native-select-option"
|
||||||
|
:class="cn('bg-popover text-popover-foreground', props.class)"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</option>
|
||||||
|
</template>
|
||||||
3
ui/src/components/ui/native-select/index.js
Normal file
3
ui/src/components/ui/native-select/index.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export { default as NativeSelect } from "./NativeSelect.vue";
|
||||||
|
export { default as NativeSelectOptGroup } from "./NativeSelectOptGroup.vue";
|
||||||
|
export { default as NativeSelectOption } from "./NativeSelectOption.vue";
|
||||||
@@ -20,10 +20,12 @@ const app = createApp(App)
|
|||||||
app.use(createPinia())
|
app.use(createPinia())
|
||||||
app.use(router)
|
app.use(router)
|
||||||
|
|
||||||
if (!import.meta.env.VITE_DISABLE_GLITCHTIP) {
|
if (import.meta.env.VITE_DISABLE_GLITCHTIP === "true") {
|
||||||
|
console.log("Glitchtip disabled");
|
||||||
|
} else {
|
||||||
let dsn = import.meta.env.VITE_GLITCHTIP_DSN;
|
let dsn = import.meta.env.VITE_GLITCHTIP_DSN;
|
||||||
let environment = import.meta.env.VITE_ENVIRONMENT;
|
let environment = import.meta.env.VITE_ENVIRONMENT;
|
||||||
|
let release = import.meta.env.VITE_APPLICATION_VERSION;
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
app,
|
app,
|
||||||
dsn: dsn,
|
dsn: dsn,
|
||||||
@@ -32,7 +34,7 @@ if (!import.meta.env.VITE_DISABLE_GLITCHTIP) {
|
|||||||
],
|
],
|
||||||
tracesSampleRate: 0.01,
|
tracesSampleRate: 0.01,
|
||||||
environment: environment,
|
environment: environment,
|
||||||
release: 'release tag'
|
release: release
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,15 +3,14 @@ import { ref, watch, nextTick, computed, onMounted } from 'vue'
|
|||||||
import FullCalendar from '@fullcalendar/vue3'
|
import FullCalendar from '@fullcalendar/vue3'
|
||||||
import dayGridPlugin from '@fullcalendar/daygrid'
|
import dayGridPlugin from '@fullcalendar/daygrid'
|
||||||
import interactionPlugin from '@fullcalendar/interaction'
|
import interactionPlugin from '@fullcalendar/interaction'
|
||||||
import { X, Clock, MapPin, User, ListTodo, ChevronLeft, ChevronRight, Plus } from 'lucide-vue-next'
|
import { ChevronLeft, ChevronRight, Plus } from 'lucide-vue-next'
|
||||||
import CreateCalendarEvent from '@/components/calendar/CreateCalendarEvent.vue'
|
import CreateCalendarEvent from '@/components/calendar/CreateCalendarEvent.vue'
|
||||||
import { getCalendarEvent, getMonthCalendarEvents } from '@/api/calendar'
|
import { CalendarEvent } from '@shared/types/calendar'
|
||||||
import { CalendarEvent, CalendarEventShort } from '@shared/types/calendar'
|
|
||||||
import { Calendar } from '@fullcalendar/core'
|
|
||||||
import ViewCalendarEvent from '@/components/calendar/ViewCalendarEvent.vue'
|
import ViewCalendarEvent from '@/components/calendar/ViewCalendarEvent.vue'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { useCalendarEvents } from '@/composables/useCalendarEvents'
|
import { useCalendarEvents } from '@/composables/useCalendarEvents'
|
||||||
import { useCalendarNavigation } from '@/composables/useCalendarNavigation'
|
import { useCalendarNavigation } from '@/composables/useCalendarNavigation'
|
||||||
|
import { useUserStore } from '@/stores/user'
|
||||||
|
|
||||||
const monthLabels = [
|
const monthLabels = [
|
||||||
'January', 'February', 'March', 'April', 'May', 'June',
|
'January', 'February', 'March', 'April', 'May', 'June',
|
||||||
@@ -24,13 +23,14 @@ function api() {
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
function buildFullDate(month: number, year: number): Date {
|
function buildFullDate(month: number, year: number): Date {
|
||||||
return new Date(year, month, 1); //default to first of month
|
return new Date(year, month, 1); //default to first of month
|
||||||
}
|
}
|
||||||
|
|
||||||
const { selectedMonth, selectedYear, years, goPrev, goNext, goToday, onDatesSet, goToSelectedDate } = useCalendarNavigation(api)
|
const { selectedMonth, selectedYear, years, goPrev, goNext, goToday, onDatesSet, goToSelectedDate } = useCalendarNavigation(api)
|
||||||
const { events, loadEvents} = useCalendarEvents(selectedMonth, selectedYear);
|
const { events, loadEvents } = useCalendarEvents(selectedMonth, selectedYear);
|
||||||
|
|
||||||
const panelOpen = ref(false)
|
const panelOpen = ref(false)
|
||||||
const activeEvent = ref<CalendarEvent | null>(null)
|
const activeEvent = ref<CalendarEvent | null>(null)
|
||||||
@@ -48,6 +48,7 @@ const dialogRef = ref<any>(null)
|
|||||||
|
|
||||||
// NEW: handle day/time slot clicks to start creating an event
|
// NEW: handle day/time slot clicks to start creating an event
|
||||||
function onDateClick(arg: { dateStr: string }) {
|
function onDateClick(arg: { dateStr: string }) {
|
||||||
|
if (!userStore.isLoggedIn) return;
|
||||||
dialogRef.value?.openDialog(arg.dateStr);
|
dialogRef.value?.openDialog(arg.dateStr);
|
||||||
// For now, just open the panel with a draft payload.
|
// For now, just open the panel with a draft payload.
|
||||||
// activeEvent.value = {
|
// activeEvent.value = {
|
||||||
@@ -202,7 +203,7 @@ onMounted(() => {
|
|||||||
@click="goToday">
|
@click="goToday">
|
||||||
Today
|
Today
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button v-if="userStore.isLoggedIn"
|
||||||
class="cursor-pointer ml-1 inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-sm text-primary-foreground hover:opacity-90"
|
class="cursor-pointer ml-1 inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-sm text-primary-foreground hover:opacity-90"
|
||||||
@click="onCreateEvent">
|
@click="onCreateEvent">
|
||||||
<Plus class="h-4 w-4" />
|
<Plus class="h-4 w-4" />
|
||||||
@@ -216,7 +217,8 @@ onMounted(() => {
|
|||||||
<aside v-if="panelOpen"
|
<aside v-if="panelOpen"
|
||||||
class="3xl:w-lg 2xl:w-md border-l bg-card text-foreground flex flex-col overflow-auto scrollbar-themed"
|
class="3xl:w-lg 2xl:w-md border-l bg-card text-foreground flex flex-col overflow-auto scrollbar-themed"
|
||||||
:style="{ height: 'calc(100vh - 61px)', position: 'sticky', top: '64px' }">
|
:style="{ height: 'calc(100vh - 61px)', position: 'sticky', top: '64px' }">
|
||||||
<ViewCalendarEvent ref="eventViewRef" @close="() => { router.push('/calendar'); }" @reload="loadEvents()" @edit="(val) => {dialogRef.openDialog(null, 'edit', val)}">
|
<ViewCalendarEvent ref="eventViewRef" @close="() => { router.push('/calendar'); }"
|
||||||
|
@reload="loadEvents()" @edit="(val) => { dialogRef.openDialog(null, 'edit', val) }">
|
||||||
</ViewCalendarEvent>
|
</ViewCalendarEvent>
|
||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -183,9 +183,9 @@ async function restartApp() {
|
|||||||
<li>When prompted, choose <em>“Yes”</em> to download all associated mods.</li>
|
<li>When prompted, choose <em>“Yes”</em> to download all associated mods.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
<a href="https://www.guilded.gg/Iceberg-gaming/groups/v3j2vAP3/channels/6979335e-60f7-4ab9-9590-66df69367d1e/docs/2013948655"
|
<a href="https://docs.iceberg-gaming.com/books/member-guides/page/new-member-setup-onboarding"
|
||||||
class="text-primary underline" target="_blank">
|
class="text-primary underline" target="_blank">
|
||||||
Click here for the full installation guide
|
Click here for the full installation guide (Requires Sign-in)
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
<!-- CONTACT SECTION -->
|
<!-- CONTACT SECTION -->
|
||||||
@@ -223,7 +223,7 @@ async function restartApp() {
|
|||||||
our forums and introduce yourself.
|
our forums and introduce yourself.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
If you have any questions, feel free to reach out on TeamSpeak, Discord, or Guilded,
|
If you have any questions, feel free to reach out on TeamSpeak or Discord
|
||||||
someone
|
someone
|
||||||
will always be around to help.
|
will always be around to help.
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -17,27 +17,24 @@ const showLOADialog = ref(false);
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Dialog v-model:open="showLOADialog" v-on:update:open="showLOADialog = false">
|
<div>
|
||||||
<DialogContent>
|
<Dialog v-model:open="showLOADialog" v-on:update:open="showLOADialog = false">
|
||||||
<DialogHeader>
|
<DialogContent class="sm:max-w-fit">
|
||||||
<DialogTitle>Post LOA</DialogTitle>
|
<DialogHeader>
|
||||||
<DialogDescription>
|
<DialogTitle>Post LOA</DialogTitle>
|
||||||
Post an LOA on behalf of a member.
|
<DialogDescription>
|
||||||
</DialogDescription>
|
Post an LOA on behalf of a member.
|
||||||
</DialogHeader>
|
</DialogDescription>
|
||||||
<LoaForm :admin-mode="true" class="my-5 w-full"></LoaForm>
|
</DialogHeader>
|
||||||
<!-- <DialogFooter>
|
<LoaForm :admin-mode="true" class="my-3"></LoaForm>
|
||||||
<Button variant="secondary" @click="showLOADialog = false">Cancel</Button>
|
</DialogContent>
|
||||||
<Button>Apply</Button>
|
</Dialog>
|
||||||
</DialogFooter> -->
|
<div class="max-w-5xl mx-auto pt-10">
|
||||||
</DialogContent>
|
<div class="flex justify-end mb-4">
|
||||||
</Dialog>
|
<Button @click="showLOADialog = true">Post LOA</Button>
|
||||||
|
</div>
|
||||||
<div class="max-w-5xl mx-auto pt-10">
|
<h1>LOA Log</h1>
|
||||||
<div class="flex justify-end mb-4">
|
<LoaList :admin-mode="true"></LoaList>
|
||||||
<Button @click="showLOADialog = true">Post LOA</Button>
|
|
||||||
</div>
|
</div>
|
||||||
<h1>LOA Log</h1>
|
|
||||||
<LoaList></LoaList>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
import LoaForm from '@/components/loa/loaForm.vue';
|
import LoaForm from '@/components/loa/loaForm.vue';
|
||||||
import { useUserStore } from '@/stores/user';
|
import { useUserStore } from '@/stores/user';
|
||||||
import { Member } from '@/api/member';
|
import { Member } from '@/api/member';
|
||||||
|
import LoaList from '@/components/loa/loaList.vue';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const user = userStore.user;
|
const user = userStore.user;
|
||||||
@@ -13,8 +15,24 @@ const memberFull: Member = {
|
|||||||
status: null,
|
status: null,
|
||||||
status_date: null,
|
status_date: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mode = ref<'submit' | 'view'>('submit')
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<LoaForm class="m-10" :member="memberFull"></LoaForm>
|
<div class="max-w-5xl mx-auto flex w-full flex-col mt-4 mb-10">
|
||||||
|
<div class="mb-8">
|
||||||
|
<p class="scroll-m-20 text-2xl font-semibold tracking-tight">Leave of Absence</p>
|
||||||
|
<div class="pt-3">
|
||||||
|
<div class="flex w-min *:px-10 pt-2 border-b *:w-full *:text-center *:pb-1 *:cursor-pointer">
|
||||||
|
<label :class="mode === 'submit' ? 'border-b-3 border-foreground' : 'mb-[2px]'"
|
||||||
|
@click="mode = 'submit'">Submit</label>
|
||||||
|
<label :class="mode === 'view' ? 'border-b-3 border-foreground' : 'mb-[2px]'"
|
||||||
|
@click="mode = 'view'">History</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<LoaForm v-if="mode === 'submit'" :member="memberFull"></LoaForm>
|
||||||
|
<LoaList v-if="mode === 'view'" :admin-mode="false"></LoaList>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
Reference in New Issue
Block a user