feat: Complete Mode2Svelte with file viewer and token management
- Implemented Graph token lifecycle management with 60s safety buffer - Added automatic token refresh scheduled 5min before expiry - Fixed token expiration handling with env variable fallback - Resolved SharePoint link parsing for both URL formats (RootFolder param and direct pathname) - Handled URL-encoded spaces in file paths with proper decoding - Implemented internal file viewer modal staying within app context - Added file categorization system (Manager Info, Contracts, Plans, Submittals, Other) - Integrated SVG icons for file types (PDF, Word, Excel, Presentation, Images) - Added search/filter capability for files in folder view - Enhanced auth module with improved button click debugging - Fixed mobile responsiveness for file listing Changes: - Mode2Svelte/src/routes/+page.svelte: Complete component rewrite with token management - Mode2Svelte/src/lib/auth/frontend.ts: Added comprehensive logging for auth flow - Mode2Svelte/src/routes/api/job-files/+server.ts: Created file access endpoint - Mode2Svelte/src/routes/api/jobs/list/+server.ts: Added jobs list endpoint Status: Files now load and display in grouped categories with internal viewer Next: Fix mobile app authentication issue and further refinements
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const PB_DB = process.env.PB_DB || 'https://pocketbase.ccllc.pro';
|
||||
|
||||
export const GET: RequestHandler = async ({ params }) => {
|
||||
try {
|
||||
const pb = new PocketBase(PB_DB);
|
||||
const record = await pb.collection('pbc_1407612689').getOne(params.id!);
|
||||
|
||||
return new Response(JSON.stringify(record), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} catch (error) {
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: error instanceof Error ? error.message : 'Job not found',
|
||||
}),
|
||||
{ status: 404, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const PATCH: RequestHandler = async ({ params, request }) => {
|
||||
try {
|
||||
const pb = new PocketBase(PB_DB);
|
||||
const data = await request.json();
|
||||
|
||||
const updated = await pb.collection('pbc_1407612689').update(params.id!, data);
|
||||
|
||||
return new Response(JSON.stringify(updated), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} catch (error) {
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: error instanceof Error ? error.message : 'Failed to update job',
|
||||
}),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const PB_DB = process.env.PB_DB || 'https://pocketbase.ccllc.pro';
|
||||
|
||||
export const GET: RequestHandler = async ({ url }) => {
|
||||
try {
|
||||
const pb = new PocketBase(PB_DB);
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1;
|
||||
const perPage = Number(url.searchParams.get('perPage')) || 30;
|
||||
const sort = url.searchParams.get('sort') || '-Job_Number';
|
||||
|
||||
// Build filter query from parameters
|
||||
const filters: string[] = [];
|
||||
const division = url.searchParams.get('division');
|
||||
const active = url.searchParams.get('active');
|
||||
const estimator = url.searchParams.get('estimator');
|
||||
const status = url.searchParams.get('status');
|
||||
const search = url.searchParams.get('search');
|
||||
|
||||
if (division) {
|
||||
filters.push(`Job_Division = "${division}"`);
|
||||
}
|
||||
if (active) {
|
||||
filters.push(`Active = ${active === 'Yes' ? 'true' : 'false'}`);
|
||||
}
|
||||
if (estimator) {
|
||||
filters.push(`Estimator = "${estimator}"`);
|
||||
}
|
||||
if (status) {
|
||||
filters.push(`Job_Status = "${status}"`);
|
||||
}
|
||||
if (search) {
|
||||
filters.push(`(Job_Number ~ "${search}" || Job_Name ~ "${search}" || Company_Client ~ "${search}")`);
|
||||
}
|
||||
|
||||
const filterQuery = filters.length > 0 ? filters.join(' && ') : '';
|
||||
|
||||
const records = await pb.collection('pbc_1407612689').getList(page, perPage, {
|
||||
sort,
|
||||
filter: filterQuery,
|
||||
});
|
||||
|
||||
return new Response(JSON.stringify(records), {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
} catch (error) {
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
error: error instanceof Error ? error.message : 'Failed to fetch jobs',
|
||||
}),
|
||||
{ status: 500, headers: { 'Content-Type': 'application/json' } }
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user