feat: Add Leaflet map integration and project coordinates handling
- Updated package.json to include dependencies for Leaflet and Playwright testing. - Added new images for Leaflet markers and layers. - Created scripts for generating test data with project coordinates. - Enhanced ProjectViewPage to display project coordinates and integrated ProjectMap component. - Modified ProjectForm to include coordinates input field. - Implemented CustomWMTSMap and EnhancedLeafletMap components for improved map functionality. - Created ProjectMap component to dynamically render project location on the map. - Added mapLayers configuration for various base layers including Polish Geoportal. - Implemented WMTS capabilities handling for dynamic layer loading. - Updated database initialization to include coordinates column in projects table. - Modified project creation and update functions to handle coordinates. - Added utility functions for formatting project status and deadlines.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import db from "./db";
|
||||
import db from "./db.js";
|
||||
|
||||
export default function initializeDatabase() {
|
||||
db.exec(`
|
||||
@@ -118,4 +118,24 @@ export default function initializeDatabase() {
|
||||
} catch (e) {
|
||||
// Column already exists, ignore error
|
||||
}
|
||||
// Migration: Add coordinates column to projects table
|
||||
try {
|
||||
db.exec(`
|
||||
ALTER TABLE projects ADD COLUMN coordinates TEXT;
|
||||
`);
|
||||
} catch (e) {
|
||||
// Column already exists, ignore error
|
||||
}
|
||||
|
||||
// Migration: Copy data from geo_info to coordinates and drop geo_info
|
||||
try {
|
||||
db.exec(`
|
||||
UPDATE projects SET coordinates = geo_info WHERE geo_info IS NOT NULL;
|
||||
`);
|
||||
db.exec(`
|
||||
ALTER TABLE projects DROP COLUMN geo_info;
|
||||
`);
|
||||
} catch (e) {
|
||||
// Column migration already done or geo_info doesn't exist, ignore error
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,15 +37,12 @@ export function createProject(data) {
|
||||
|
||||
// 2. Generate sequential number and project number
|
||||
const sequentialNumber = (contractInfo.project_count || 0) + 1;
|
||||
const projectNumber = `${sequentialNumber}/${contractInfo.contract_number}`;
|
||||
|
||||
const stmt = db.prepare(`
|
||||
const projectNumber = `${sequentialNumber}/${contractInfo.contract_number}`; const stmt = db.prepare(`
|
||||
INSERT INTO projects (
|
||||
contract_id, project_name, project_number, address, plot, district, unit, city, investment_number, finish_date,
|
||||
wp, contact, notes, project_type, project_status
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`);
|
||||
stmt.run(
|
||||
wp, contact, notes, project_type, project_status, coordinates
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`);stmt.run(
|
||||
data.contract_id,
|
||||
data.project_name,
|
||||
projectNumber,
|
||||
@@ -58,17 +55,16 @@ export function createProject(data) {
|
||||
data.finish_date,
|
||||
data.wp,
|
||||
data.contact,
|
||||
data.notes,
|
||||
data.project_type || "design",
|
||||
data.project_status || "registered"
|
||||
data.notes, data.project_type || "design",
|
||||
data.project_status || "registered",
|
||||
data.coordinates || null
|
||||
);
|
||||
}
|
||||
|
||||
export function updateProject(id, data) {
|
||||
const stmt = db.prepare(`
|
||||
export function updateProject(id, data) { const stmt = db.prepare(`
|
||||
UPDATE projects SET
|
||||
contract_id = ?, project_name = ?, project_number = ?, address = ?, plot = ?, district = ?, unit = ?, city = ?,
|
||||
investment_number = ?, finish_date = ?, wp = ?, contact = ?, notes = ?, project_type = ?, project_status = ?
|
||||
investment_number = ?, finish_date = ?, wp = ?, contact = ?, notes = ?, project_type = ?, project_status = ?, coordinates = ?
|
||||
WHERE project_id = ?
|
||||
`);
|
||||
stmt.run(
|
||||
@@ -84,9 +80,9 @@ export function updateProject(id, data) {
|
||||
data.finish_date,
|
||||
data.wp,
|
||||
data.contact,
|
||||
data.notes,
|
||||
data.project_type || "design",
|
||||
data.notes, data.project_type || "design",
|
||||
data.project_status || "registered",
|
||||
data.coordinates || null,
|
||||
id
|
||||
);
|
||||
}
|
||||
|
||||
40
src/lib/utils.js
Normal file
40
src/lib/utils.js
Normal file
@@ -0,0 +1,40 @@
|
||||
// Test utilities for deadline and status formatting
|
||||
export const getDeadlineVariant = (days) => {
|
||||
if (days < 0) return "danger";
|
||||
if (days <= 7) return "warning";
|
||||
return "success";
|
||||
};
|
||||
|
||||
export const formatProjectStatus = (status) => {
|
||||
switch (status) {
|
||||
case "registered":
|
||||
return "Zarejestrowany";
|
||||
case "in_progress_design":
|
||||
return "W realizacji (projektowanie)";
|
||||
case "in_progress_construction":
|
||||
return "W realizacji (realizacja)";
|
||||
case "fulfilled":
|
||||
return "Zakończony";
|
||||
default:
|
||||
return "-";
|
||||
}
|
||||
};
|
||||
|
||||
export const formatProjectType = (type) => {
|
||||
switch (type) {
|
||||
case "design":
|
||||
return "Projektowanie";
|
||||
case "construction":
|
||||
return "Realizacja";
|
||||
case "design+construction":
|
||||
return "Projektowanie + Realizacja";
|
||||
default:
|
||||
return "-";
|
||||
}
|
||||
};
|
||||
|
||||
export const getDeadlineText = (daysRemaining) => {
|
||||
if (daysRemaining === 0) return "Due Today";
|
||||
if (daysRemaining > 0) return `${daysRemaining} days left`;
|
||||
return `${Math.abs(daysRemaining)} days overdue`;
|
||||
};
|
||||
Reference in New Issue
Block a user