Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dexie": "^3.2.7",
"firebase": "^10.14.1",
"html2pdf.js": "^0.10.3",
"pdf-lib": "^1.17.1",
"react": "^18.3.1",
"react-chartjs-2": "^5.3.1",
"react-dom": "^18.3.1",
Expand Down
37 changes: 37 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Cable from './pages/Cable';
import Breaker from './pages/Breaker';
import Tools from './pages/Tools';
import Panel from './pages/Panel';
import EMReports from './pages/EMReports';
import './index.css';

function App() {
Expand All @@ -30,6 +31,7 @@ function App() {
<Route path="/parameters" element={<Parameters />} />
<Route path="/multiphase" element={<MultiPhase />} />
<Route path="/reports" element={<Reports />} />
<Route path="/em" element={<EMReports />} />
<Route path="/cable" element={<Cable />} />
<Route path="/breaker" element={<Breaker />} />
<Route path="/tools" element={<Tools />} />
Expand Down
1 change: 1 addition & 0 deletions src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const Layout: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const otherItems = [
{ path: '/multiphase', label: 'Multi-Fase', icon: ChartBarIcon, color: 'text-gray-400' },
{ path: '/panel', label: 'Painel', icon: Squares2X2Icon, color: 'text-gray-400' },
{ path: '/em-reports', label: 'Eletromecânico', icon: DocumentTextIcon, color: 'text-gray-400' },
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Point EM nav item to an existing route

The new sidebar entry navigates to /em-reports, but the router only registers the EM list at /em in src/App.tsx (no /em-reports route exists). In practice, clicking "Eletromecânico" from the menu sends users to an unmatched URL instead of the page introduced in this commit, making the feature inaccessible through normal navigation.

Useful? React with 👍 / 👎.

{ path: '/reports', label: 'Relatórios', icon: DocumentTextIcon, color: 'text-gray-400' },
{ path: '/parameters', label: 'Parâmetros', icon: CogIcon, color: 'text-gray-400' },
{ path: '/equipment', label: 'Equipamentos', icon: CircleStackIcon, color: 'text-gray-400' },
Expand Down
76 changes: 70 additions & 6 deletions src/db/database.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Dexie, { Table } from 'dexie';
import {
IRReport,
EletroMecanicoReport,
MultiPhaseConfig,
MultiPhaseReport,
AILearningHistory,
Expand Down Expand Up @@ -33,10 +34,11 @@ export class EletriLabDB extends Dexie {
aiLearningHistory!: Table<AILearningHistory>;
categoryProfiles!: Table<CategoryProfile>;
systemConfigs!: Table<SystemConfig>;
emReports!: Table<EletroMecanicoReport>;

constructor() {
super('EletriLabDB');

this.version(4).stores({
// Tabelas originais
equipment: 'id, tag, category, status, location, manufacturer',
Expand All @@ -51,7 +53,27 @@ export class EletriLabDB extends Dexie {
multiPhaseReports: '++id, configId, createdAt, isSaved',
aiLearningHistory: '++id, category, phaseCount, createdAt',
categoryProfiles: '++id, category, createdAt',
systemConfigs: '++id, createdAt'
systemConfigs: '++id, createdAt',
// OBS: versão 4 não tinha EM; mantemos aqui para não quebrar ambientes já com v4.
// A tabela EM real e indexação correta fica na v5.
emReports: '++id, module, discipline, createdAt'
});

// Versão 5: Tabela EM com chave string (id) e índices úteis.
// Importante: usar `id` (não ++id) porque `EletroMecanicoReport.id` já é string.
this.version(5).stores({
equipment: 'id, tag, category, status, location, manufacturer',
report: 'id, number, date, client, status, responsible',
test: 'id, reportId, equipmentId, testType, result, performedAt',
configuration: 'id',
irReports: '++id, category, createdAt, isSaved',
parameters: '++id, key, category',
multiPhaseConfigs: '++id, equipmentType, createdAt',
multiPhaseReports: '++id, configId, createdAt, isSaved',
aiLearningHistory: '++id, category, phaseCount, createdAt',
categoryProfiles: '++id, category, createdAt',
systemConfigs: '++id, createdAt',
emReports: 'id, module, discipline, createdAt'
});
}
}
Expand Down Expand Up @@ -416,6 +438,43 @@ export const dbUtils = {
}
},

// === ELETROMECÂNICO (novo) ===
async getAllEMReports(): Promise<EletroMecanicoReport[]> {
try {
return await db.emReports.orderBy('createdAt').reverse().toArray();
} catch (error) {
console.error('Erro ao buscar relatórios EM:', error);
return [];
}
},

async getEMReport(id: string): Promise<EletroMecanicoReport | null> {
try {
return await db.emReports.get(id) || null;
} catch (error) {
console.error('Erro ao buscar relatório EM:', error);
return null;
}
},

async saveEMReport(report: EletroMecanicoReport): Promise<void> {
try {
await db.emReports.put(report);
} catch (error) {
console.error('Erro ao salvar relatório EM:', error);
throw error;
}
},

async deleteEMReport(id: string): Promise<void> {
try {
await db.emReports.delete(id);
} catch (error) {
console.error('Erro ao deletar relatório EM:', error);
throw error;
}
},

async getSavedIRReports(): Promise<IRReport[]> {
try {
return await db.irReports.where('isSaved').equals(1).toArray();
Expand Down Expand Up @@ -598,7 +657,7 @@ export const dbUtils = {
// Backup/Restore simples (banco local IndexedDB)
async exportAll(): Promise<any> {
try {
const [equipment, reports, tests, irReports, multiConfigs, multiReports, ai, profiles, system, config] = await Promise.all([
const [equipment, reports, tests, irReports, multiConfigs, multiReports, ai, profiles, system, config, emReports] = await Promise.all([
db.equipment.toArray(),
db.report.toArray(),
db.test.toArray(),
Expand All @@ -608,7 +667,8 @@ export const dbUtils = {
db.aiLearningHistory.toArray(),
db.categoryProfiles.toArray(),
db.systemConfigs.toArray(),
db.configuration.toArray()
db.configuration.toArray(),
db.emReports.toArray(),
]);
return {
version: 1,
Expand All @@ -619,6 +679,7 @@ export const dbUtils = {
irReports,
multiConfigs,
multiReports,
emReports,
ai,
profiles,
system,
Expand All @@ -641,11 +702,12 @@ export const dbUtils = {
db.test.clear(),
]);
});
await db.transaction('rw', db.irReports, db.multiPhaseConfigs, db.multiPhaseReports, async () => {
await db.transaction('rw', db.irReports, db.multiPhaseConfigs, db.multiPhaseReports, db.emReports, async () => {
await Promise.all([
db.irReports.clear(),
db.multiPhaseConfigs.clear(),
db.multiPhaseReports.clear(),
db.emReports.clear(),
]);
});
await db.transaction('rw', db.aiLearningHistory, db.categoryProfiles, db.systemConfigs, db.configuration, async () => {
Expand All @@ -663,10 +725,11 @@ export const dbUtils = {
if (data.reports?.length) await db.report.bulkAdd(data.reports);
if (data.tests?.length) await db.test.bulkAdd(data.tests);
});
await db.transaction('rw', db.irReports, db.multiPhaseConfigs, db.multiPhaseReports, async () => {
await db.transaction('rw', db.irReports, db.multiPhaseConfigs, db.multiPhaseReports, db.emReports, async () => {
if (data.irReports?.length) await db.irReports.bulkAdd(data.irReports);
if (data.multiConfigs?.length) await db.multiPhaseConfigs.bulkAdd(data.multiConfigs);
if (data.multiReports?.length) await db.multiPhaseReports.bulkAdd(data.multiReports);
if (data.emReports?.length) await db.emReports.bulkAdd(data.emReports);
});
await db.transaction('rw', db.aiLearningHistory, db.categoryProfiles, db.systemConfigs, db.configuration, async () => {
if (data.ai?.length) await db.aiLearningHistory.bulkAdd(data.ai);
Expand Down Expand Up @@ -821,6 +884,7 @@ export const dbUtils = {
await db.test.clear();
await db.configuration.clear();
await db.irReports.clear();
await db.emReports.clear();
await db.parameters.clear();
await db.multiPhaseConfigs.clear();
await db.multiPhaseReports.clear();
Expand Down
Loading
Loading