@@ -1,8 +1,24 @@
|
||||
export function markPreparationDirty(
|
||||
form: HTMLFormElement,
|
||||
dirty: boolean,
|
||||
managed = false,
|
||||
): void {
|
||||
form.setAttribute('data-preparation-dirty', dirty ? 'true' : 'false');
|
||||
if (managed) form.setAttribute('data-preparation-managed', 'true');
|
||||
// Explicit query forms change consultation criteria, not a business preparation.
|
||||
form.setAttribute(
|
||||
'data-preparation-dirty',
|
||||
dirty && form.getAttribute('data-query-form') !== 'true'
|
||||
? 'true'
|
||||
: 'false',
|
||||
);
|
||||
}
|
||||
|
||||
/** A form that publishes its own dirty state owns clearing and restoring it. */
|
||||
export function usesGenericPreparationTracking(form: HTMLFormElement): boolean {
|
||||
return (
|
||||
form.getAttribute('data-query-form') !== 'true' &&
|
||||
form.getAttribute('data-preparation-managed') !== 'true'
|
||||
);
|
||||
}
|
||||
|
||||
/** Recover restored preparations even when their effect ran before the guard subscribed. */
|
||||
@@ -20,6 +36,7 @@ export function connectedDirtyForms(
|
||||
].filter(
|
||||
(form) =>
|
||||
form.isConnected &&
|
||||
form.getAttribute('data-query-form') !== 'true' &&
|
||||
form.getAttribute('data-preparation-dirty') !== 'false',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import type { ProcurementGroup } from '@/lib/procurement-navigation';
|
||||
|
||||
const terms: Record<string, string> = {
|
||||
supply_agreements:
|
||||
'acordo acordos contrato contratos vigência fornecimento',
|
||||
supply_imports:
|
||||
'importação alfândega aduaneira despachante transitário pauta',
|
||||
receipts: 'receber entrega recepção divergência',
|
||||
operational_orders: 'produção manutenção oficina ordem',
|
||||
capital_register:
|
||||
'projecto projeto imobilizado activo ativo património cadastro',
|
||||
my_workflow_tasks: 'tarefa pendência próxima acção',
|
||||
pending_approvals: 'aprovar aprovação decidir decisão',
|
||||
suppliers: 'fornecedor cadastro documento',
|
||||
supplier_evaluations: 'avaliar avaliação fornecedor',
|
||||
invoices: 'factura conferir conferência fornecedor',
|
||||
payments: 'pagamento liquidar liquidação saldo confirmação',
|
||||
budgets: 'orçamento reforço dotação saldo',
|
||||
stock_operations: 'inventário contagem saída entrega',
|
||||
inventory_lots: 'lote validade quarentena',
|
||||
audit_private: 'auditoria exportar exportação privada',
|
||||
audit_metadata: 'auditoria evento histórico metadados',
|
||||
};
|
||||
|
||||
export const normalizeMenuText = (value: string) =>
|
||||
value
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLocaleLowerCase('pt');
|
||||
|
||||
export const matchesMenuSearch = (text: string, query: string) => {
|
||||
const haystack = normalizeMenuText(text);
|
||||
return normalizeMenuText(query)
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.every((word) => haystack.includes(word));
|
||||
};
|
||||
|
||||
/** Search only the already authorised navigation; never introduce a route or grant. */
|
||||
export function searchProcurementMenu(
|
||||
groups: ProcurementGroup[],
|
||||
query: string,
|
||||
): ProcurementGroup[] {
|
||||
return groups
|
||||
.map((group) => ({
|
||||
...group,
|
||||
entries: group.entries.filter((entry) =>
|
||||
matchesMenuSearch(
|
||||
`${group.label} ${entry.section ?? ''} ${entry.label} ${terms[entry.id] ?? ''}`,
|
||||
query,
|
||||
),
|
||||
),
|
||||
}))
|
||||
.filter((group) => group.entries.length > 0);
|
||||
}
|
||||
@@ -35,6 +35,7 @@ export function procurementNavigation(
|
||||
orderCancellation = false,
|
||||
operationalOrders = false,
|
||||
privateAudit = false,
|
||||
capitalRegister = false,
|
||||
): ProcurementGroup[] {
|
||||
const groups: ProcurementGroup[] = [
|
||||
{
|
||||
@@ -42,6 +43,11 @@ export function procurementNavigation(
|
||||
label: 'Requisições',
|
||||
icon: ClipboardList,
|
||||
entries: [
|
||||
{
|
||||
id: 'my_workflow_tasks',
|
||||
label: 'As minhas tarefas',
|
||||
path: '/requisicoes/tarefas',
|
||||
},
|
||||
{
|
||||
id: 'process_search',
|
||||
label: 'Pesquisar processos',
|
||||
@@ -57,11 +63,6 @@ export function procurementNavigation(
|
||||
label: 'Minhas requisições',
|
||||
path: '/requisicoes?view=mine',
|
||||
},
|
||||
{
|
||||
id: 'my_workflow_tasks',
|
||||
label: 'As minhas tarefas',
|
||||
path: '/requisicoes/tarefas',
|
||||
},
|
||||
{
|
||||
id: 'my_drafts',
|
||||
label: 'Os meus rascunhos',
|
||||
@@ -69,7 +70,7 @@ export function procurementNavigation(
|
||||
},
|
||||
{
|
||||
id: 'all_requests',
|
||||
label: 'Todas as autorizadas',
|
||||
label: 'Requisições autorizadas',
|
||||
path: '/requisicoes?view=all',
|
||||
},
|
||||
{ id: 'planning', label: 'Planeamento', path: '/planeamento' },
|
||||
@@ -424,6 +425,12 @@ export function procurementNavigation(
|
||||
path: '/equipamentos',
|
||||
roles: inventory,
|
||||
},
|
||||
{
|
||||
id: 'capital_register',
|
||||
label: 'Projectos e imobilizado',
|
||||
path: '/projectos-imobilizado',
|
||||
roles: inventory,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -557,9 +564,25 @@ export function procurementNavigation(
|
||||
label: 'Compras',
|
||||
icon: ClipboardList,
|
||||
entries: purchasing.flatMap((group) =>
|
||||
group.entries.map((entry) => ({
|
||||
(group.id === 'sourcing'
|
||||
? [
|
||||
...group.entries.filter(
|
||||
(entry) => entry.id !== 'supply_imports',
|
||||
),
|
||||
...group.entries.filter(
|
||||
(entry) => entry.id === 'supply_imports',
|
||||
),
|
||||
]
|
||||
: group.entries
|
||||
).map((entry) => ({
|
||||
...entry,
|
||||
section: group.label,
|
||||
section:
|
||||
entry.id === 'supply_imports'
|
||||
? 'Importação'
|
||||
: group.id === 'sourcing' &&
|
||||
entry.id.startsWith('supply_')
|
||||
? 'Fornecimento e reposição'
|
||||
: group.label,
|
||||
})),
|
||||
),
|
||||
},
|
||||
@@ -596,6 +619,7 @@ export function procurementNavigation(
|
||||
(entry.id !== 'audit_private' || privateAudit) &&
|
||||
(entry.id !== 'operational_orders' ||
|
||||
operationalOrders) &&
|
||||
(entry.id !== 'capital_register' || capitalRegister) &&
|
||||
(entry.id !== 'new_request' ||
|
||||
!Array.isArray(role) ||
|
||||
role.includes('requester')) &&
|
||||
@@ -615,6 +639,29 @@ export function activeProcurementEntry(
|
||||
url: string,
|
||||
): string | undefined {
|
||||
const current = new URL(url, 'http://local');
|
||||
if (
|
||||
(current.pathname === '/compras/acordos/vigencia' ||
|
||||
(current.pathname === '/compras/fornecimento' &&
|
||||
['agreements', 'contracts'].includes(
|
||||
current.searchParams.get('view') ?? 'agreements',
|
||||
))) &&
|
||||
groups.some((group) =>
|
||||
group.entries.some((entry) => entry.id === 'supply_agreements'),
|
||||
)
|
||||
)
|
||||
return 'supply_agreements';
|
||||
if (
|
||||
(/^\/requisicoes\/\d+\/(classificacao-pautal|base-legal|estimativa-importacao)(?:\/|$)/.test(
|
||||
current.pathname,
|
||||
) ||
|
||||
/^\/compras\/importacoes\/\d+\/(custos|documentos|suporte-bancario|acompanhamento)(?:\/|$)/.test(
|
||||
current.pathname,
|
||||
)) &&
|
||||
groups.some((group) =>
|
||||
group.entries.some((entry) => entry.id === 'supply_imports'),
|
||||
)
|
||||
)
|
||||
return 'supply_imports';
|
||||
if (/^\/ordens\/\d+\/recepcoes/.test(current.pathname)) return 'receipts';
|
||||
if (/^\/requisicoes\/\d+\/adjudicacao(?:\/|$)/.test(current.pathname))
|
||||
return 'orders';
|
||||
@@ -644,5 +691,17 @@ export function activeProcurementEntry(
|
||||
return target.pathname.length * 100 + target.searchParams.size;
|
||||
};
|
||||
matches.sort((a, b) => specificity(b.path) - specificity(a.path));
|
||||
if (
|
||||
matches.length === 0 &&
|
||||
/^\/administracao\/(prazos-aprovacao|revisao-urgencias)(?:\/|$)/.test(
|
||||
current.pathname,
|
||||
) &&
|
||||
groups.some((group) =>
|
||||
group.entries.some(
|
||||
(entry) => entry.id === 'organization_parameters',
|
||||
),
|
||||
)
|
||||
)
|
||||
return 'organization_parameters';
|
||||
return matches[0]?.id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user