1449 lines
70 KiB
TypeScript
1449 lines
70 KiB
TypeScript
import { router, useForm, usePage } from '@inertiajs/react';
|
|
import { useEffect, useState } from 'react';
|
|
import { Management, Field, control, button } from '../management/shared';
|
|
|
|
type DocumentFile = {
|
|
id: string;
|
|
file_name: string;
|
|
media_type: string;
|
|
size_bytes: number | null;
|
|
issuer: string | null;
|
|
uploaded_by: number | null;
|
|
created_at: string;
|
|
status: string;
|
|
data_classification: string;
|
|
version_no: number;
|
|
sha256: string;
|
|
rights_status: string;
|
|
malware_scan_status: string;
|
|
malware_scanned_at: string | null;
|
|
malware_failure_reason: string | null;
|
|
malware_engine_version: string | null;
|
|
malware_signatures_at: string | null;
|
|
malware_scan_attempts: number;
|
|
};
|
|
type Association = {
|
|
target_type: string;
|
|
target_key: string;
|
|
relationship: string;
|
|
applicability: string;
|
|
condition_text: string;
|
|
basis_reference: string;
|
|
review_status: string;
|
|
};
|
|
type Resource = {
|
|
id: number;
|
|
document_id: string;
|
|
title: string;
|
|
description: string | null;
|
|
category: string;
|
|
topic: string;
|
|
document_type: string;
|
|
document_number: string | null;
|
|
document_date: string | null;
|
|
applicable_from: string | null;
|
|
applicable_until: string | null;
|
|
source_url: string | null;
|
|
language: string;
|
|
version_label: string | null;
|
|
document_group_id: string | null;
|
|
territorial_scope: string;
|
|
territory_id: string | null;
|
|
source_confirmation: string;
|
|
legal_status: string;
|
|
rights_status: string;
|
|
data_classification: string;
|
|
source_reference: string;
|
|
legislation: boolean;
|
|
essential: boolean;
|
|
published: boolean;
|
|
issuer: string | null;
|
|
metadata_version: number;
|
|
independent_review: boolean;
|
|
file_name: string;
|
|
file_status: string;
|
|
file_rights_status: string;
|
|
duplicate_of_resource_id: number | null;
|
|
links: Association[];
|
|
revisions: {
|
|
revision_no: number;
|
|
change_type: string;
|
|
actor_user_id: number | null;
|
|
created_at: string;
|
|
}[];
|
|
};
|
|
type ResourceForm = Omit<
|
|
Association,
|
|
| 'target_type'
|
|
| 'target_key'
|
|
| 'relationship'
|
|
| 'applicability'
|
|
| 'condition_text'
|
|
| 'basis_reference'
|
|
| 'review_status'
|
|
> & {
|
|
document_id: string;
|
|
title: string;
|
|
description: string;
|
|
category: string;
|
|
topic: string;
|
|
document_type: string;
|
|
issuer: string;
|
|
document_number: string;
|
|
document_date: string;
|
|
applicable_from: string;
|
|
applicable_until: string;
|
|
source_url: string;
|
|
language: string;
|
|
version_label: string;
|
|
document_group_id: string;
|
|
territorial_scope: string;
|
|
territory_id: string;
|
|
source_confirmation: string;
|
|
legal_status: string;
|
|
rights_status: string;
|
|
data_classification: string;
|
|
source_reference: string;
|
|
legislation: boolean;
|
|
essential: boolean;
|
|
independent_review: boolean;
|
|
metadata_version: number;
|
|
associations: Association[];
|
|
};
|
|
const emptyAssociation: Association = {
|
|
target_type: 'module',
|
|
target_key: '',
|
|
relationship: 'supports',
|
|
applicability: 'support',
|
|
condition_text: '',
|
|
basis_reference: '',
|
|
review_status: 'pending',
|
|
};
|
|
const emptyResource = (): ResourceForm => ({
|
|
document_id: '',
|
|
title: '',
|
|
description: '',
|
|
category: '',
|
|
topic: '',
|
|
document_type: 'unknown',
|
|
issuer: '',
|
|
document_number: '',
|
|
document_date: '',
|
|
applicable_from: '',
|
|
applicable_until: '',
|
|
source_url: '',
|
|
language: 'unknown',
|
|
version_label: '',
|
|
document_group_id: '',
|
|
territorial_scope: 'unknown',
|
|
territory_id: '',
|
|
source_confirmation: 'unconfirmed',
|
|
legal_status: 'unknown',
|
|
rights_status: 'unconfirmed',
|
|
data_classification: 'internal',
|
|
source_reference: '',
|
|
legislation: false,
|
|
essential: false,
|
|
independent_review: false,
|
|
metadata_version: 1,
|
|
associations: [],
|
|
});
|
|
|
|
export default function Manage({
|
|
documents,
|
|
resources,
|
|
partnerships,
|
|
territories,
|
|
incompleteCount,
|
|
possibleDuplicates,
|
|
malwareHealth,
|
|
malwareCounts,
|
|
requirementCatalogue,
|
|
requirementAssociationsEnabled,
|
|
disclosureAuthorization,
|
|
legacyContentEnabled = false,
|
|
documentAccessOnly = false,
|
|
editorialScopeOnly = false,
|
|
managementFilters = {},
|
|
associationOptions = {},
|
|
}: {
|
|
managementFilters?: {q?: string; state?: string; intent?: string};
|
|
associationOptions?: Record<string, {value: string | number; label: string}[]>;
|
|
legacyContentEnabled?: boolean;
|
|
documentAccessOnly?: boolean;
|
|
editorialScopeOnly?: boolean;
|
|
documents: DocumentFile[];
|
|
resources: Resource[];
|
|
requirementCatalogue: { key: string; label: string; tax: string }[];
|
|
requirementAssociationsEnabled: boolean;
|
|
disclosureAuthorization: {
|
|
external_id: string;
|
|
occurred_at: string;
|
|
resources: {
|
|
id: number;
|
|
title: string;
|
|
published: boolean;
|
|
rights_status: string;
|
|
}[];
|
|
} | null;
|
|
territories: { id: string; name: string; location_type: string }[];
|
|
incompleteCount: number;
|
|
possibleDuplicates: number;
|
|
malwareHealth: {
|
|
available: boolean;
|
|
engine: string;
|
|
engine_version: string | null;
|
|
signatures_at: string | null;
|
|
signature_age_hours: number | null;
|
|
reason_code: string | null;
|
|
};
|
|
malwareCounts: Record<string, number>;
|
|
partnerships: {
|
|
id: number;
|
|
title: string;
|
|
sector: string;
|
|
province: string;
|
|
offer: string;
|
|
seeking: string;
|
|
status: string;
|
|
}[];
|
|
}) {
|
|
const [editingId, setEditingId] = useState<number | null>(null);
|
|
const [actionError, setActionError] = useState('');
|
|
const [query, setQuery] = useState(managementFilters.q ?? '');
|
|
const [stateFilter, setStateFilter] = useState(managementFilters.state ?? '');
|
|
const { flash } = usePage<{flash?: {uploaded_document_id?: string}}>().props;
|
|
const upload = useForm<{
|
|
file: File | null;
|
|
original_source: string;
|
|
issuer: string;
|
|
intent: string;
|
|
}>({ file: null, original_source: '', issuer: '', intent: managementFilters.intent ?? 'document' });
|
|
const form = useForm<ResourceForm>({...emptyResource(), ...(managementFilters.intent === 'legislation' ? {document_type: 'legislation', legislation: true} : {})});
|
|
const chooseDocument = (id: string) => {
|
|
const document = documents.find((item) => item.id === id);
|
|
form.setData((current) => ({...current, document_id: id,
|
|
issuer: current.issuer || document?.issuer || '',
|
|
title: current.title || document?.file_name || '',
|
|
}));
|
|
};
|
|
useEffect(() => {
|
|
if (flash?.uploaded_document_id && !editingId && !form.data.document_id) chooseDocument(flash.uploaded_document_id);
|
|
}, [flash?.uploaded_document_id]);
|
|
const setAssociation = (
|
|
index: number,
|
|
key: keyof Association,
|
|
value: string,
|
|
) =>
|
|
form.setData(
|
|
'associations',
|
|
form.data.associations.map((item, row) =>
|
|
row === index ? { ...item, [key]: value } : item,
|
|
),
|
|
);
|
|
|
|
return (
|
|
<Management title={documentAccessOnly ? "Os meus ficheiros privados" : editorialScopeOnly ? "Gestão editorial do acervo autorizado" : "Biblioteca documental e Bolsa de Parcerias"}>
|
|
{documentAccessOnly && <p>Carregue e consulte os seus ficheiros. Este acesso não permite publicar nem consultar ficheiros privados de outras contas.</p>}
|
|
{!documentAccessOnly && <>
|
|
{!editorialScopeOnly && <>
|
|
<a className="underline" href="/management/editorial-installation">
|
|
Estado da gestão editorial
|
|
</a>
|
|
</>}
|
|
<section
|
|
className="rounded border border-amber-700 bg-amber-50 p-4"
|
|
aria-live="polite"
|
|
>
|
|
<h2 className="font-bold">Revisão da biblioteca</h2>
|
|
<p>
|
|
{incompleteCount} registos têm metadados por completar;{' '}
|
|
{possibleDuplicates} possíveis duplicados estão sinalizados
|
|
para revisão. A contagem não é certificação documental.
|
|
</p>
|
|
</section>
|
|
</>}
|
|
<section
|
|
className="space-y-3 rounded border p-5"
|
|
aria-label="Estado antimalware"
|
|
>
|
|
<h2 className="text-xl font-bold">Análise antimalware</h2>
|
|
<p role={malwareHealth.available ? 'status' : 'alert'}>
|
|
Scanner{' '}
|
|
{malwareHealth.available ? 'disponível' : 'indisponível'} ·{' '}
|
|
{malwareHealth.engine}
|
|
{malwareHealth.engine_version
|
|
? ` ${malwareHealth.engine_version}`
|
|
: ''}
|
|
{malwareHealth.signatures_at
|
|
? ` · assinaturas ${new Date(malwareHealth.signatures_at).toLocaleString()}`
|
|
: ''}
|
|
{malwareHealth.reason_code
|
|
? ` · ${malwareHealth.reason_code}`
|
|
: ''}
|
|
</p>
|
|
<ul className="flex flex-wrap gap-x-5 gap-y-1 text-sm">
|
|
{Object.entries(malwareCounts).map(([status, count]) => (
|
|
<li key={status}>
|
|
{status}: {count}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<p className="text-sm">
|
|
Resultado negativo significa apenas que nenhuma ameaça foi
|
|
detectada. A análise não publica o documento.
|
|
</p>
|
|
{documents.filter(
|
|
(d) =>
|
|
d.status === 'active' &&
|
|
d.malware_scan_status === 'clean' &&
|
|
d.malware_scanned_at !== null,
|
|
).length > 0 && (
|
|
<div className="space-y-2">
|
|
<h3 className="font-semibold">
|
|
Ficheiros privados disponíveis para revisão
|
|
administrativa
|
|
</h3>
|
|
<ul className="space-y-1">
|
|
{documents
|
|
.filter(
|
|
(d) =>
|
|
d.status === 'active' &&
|
|
d.malware_scan_status === 'clean' &&
|
|
d.malware_scanned_at !== null,
|
|
)
|
|
.map((d) => (
|
|
<li
|
|
key={d.id}
|
|
className="flex flex-wrap items-center gap-3"
|
|
>
|
|
<span>
|
|
{d.file_name} ·{' '}
|
|
{d.data_classification} · análise
|
|
limpa
|
|
</span>
|
|
<a
|
|
className="underline"
|
|
href={`/management/documents/${d.id}/download`}
|
|
>
|
|
Consultar cópia privada
|
|
</a>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
)}
|
|
{documents
|
|
.filter((d) => d.malware_scan_status !== 'clean')
|
|
.map((d) => (
|
|
<article
|
|
key={d.id}
|
|
className="flex flex-wrap items-center justify-between gap-3 rounded border p-3"
|
|
>
|
|
<div>
|
|
<p className="font-semibold">
|
|
{d.file_name} · {d.malware_scan_status}
|
|
</p>
|
|
<p className="text-sm">
|
|
{d.malware_failure_reason ??
|
|
'A aguardar resultado'}
|
|
{d.malware_scanned_at
|
|
? ` · ${new Date(d.malware_scanned_at).toLocaleString()}`
|
|
: ''}
|
|
</p>
|
|
</div>
|
|
{['pending', 'inconclusive', 'failed'].includes(
|
|
d.malware_scan_status,
|
|
) && (
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
onClick={() =>
|
|
router.post(
|
|
`/management/documents/${d.id}/malware/retry`,
|
|
{},
|
|
{ preserveScroll: true },
|
|
)
|
|
}
|
|
>
|
|
Tentar novamente
|
|
</button>
|
|
)}
|
|
{d.malware_scan_status === 'infected' && (
|
|
<span role="alert">
|
|
Ficheiro bloqueado; substitua por um novo
|
|
upload após revisão.
|
|
</span>
|
|
)}
|
|
</article>
|
|
))}
|
|
</section>
|
|
<form
|
|
id="receber"
|
|
className="space-y-4 rounded border p-5"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
upload.post('/management/portal-services/upload', {
|
|
forceFormData: true,
|
|
preserveScroll: true,
|
|
onSuccess: () => upload.reset(),
|
|
});
|
|
}}
|
|
>
|
|
<h2 className="text-xl font-bold">
|
|
Receber documento em privado
|
|
</h2>
|
|
<p>
|
|
PDF, TXT, CSV, DOC/DOCX, ODT, XLSX, PNG, JPEG ou WebP, até
|
|
10 MiB. O ficheiro fica no armazenamento privado e em
|
|
quarentena; não é publicado nem descarregável publicamente
|
|
enquanto não passar a validação de segurança existente.
|
|
</p>
|
|
<Field label="Ficheiro">
|
|
<input
|
|
type="file"
|
|
accept=".pdf,.txt,.csv,.doc,.docx,.odt,.xlsx,.png,.jpg,.jpeg,.webp"
|
|
required
|
|
onChange={(e) =>
|
|
upload.setData('file', e.target.files?.[0] ?? null)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Entidade/autor (se conhecido)">
|
|
<input
|
|
className={control}
|
|
value={upload.data.issuer}
|
|
onChange={(e) =>
|
|
upload.setData('issuer', e.target.value)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Origem HTTPS identificada (opcional)">
|
|
<input
|
|
type="url"
|
|
className={control}
|
|
value={upload.data.original_source}
|
|
onChange={(e) =>
|
|
upload.setData('original_source', e.target.value)
|
|
}
|
|
/>
|
|
</Field>
|
|
{Object.entries(upload.errors).map(([key, error]) => (
|
|
<p role="alert" key={key}>
|
|
{error}
|
|
</p>
|
|
))}
|
|
<button className={button} disabled={upload.processing}>
|
|
Guardar em quarentena
|
|
</button>
|
|
</form>
|
|
|
|
{!documentAccessOnly && <>
|
|
{managementFilters.intent === 'legislation' && <p className="rounded border p-4">Nova legislação: reutilize o original, complete diploma/tipo, entidade emitente, número, datas e âmbito. Registe alterações e revogações nas associações. Publicar para consulta não activa cálculos no simulador.</p>}
|
|
<form
|
|
className="space-y-4 rounded border p-5"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
const options = {
|
|
preserveScroll: true,
|
|
onSuccess: () => {
|
|
form.reset();
|
|
setEditingId(null);
|
|
},
|
|
};
|
|
if (editingId)
|
|
form.put(
|
|
`/management/portal-services/resources/${editingId}`,
|
|
options,
|
|
);
|
|
else
|
|
form.post(
|
|
'/management/portal-services/resources',
|
|
options,
|
|
);
|
|
}}
|
|
>
|
|
<h2 className="text-xl font-bold">
|
|
{editingId
|
|
? 'Editar metadados documentais'
|
|
: 'Registar documento na biblioteca'}
|
|
</h2>
|
|
<p>
|
|
O registo começa como rascunho. A publicação é uma acção
|
|
separada e exige ficheiro público validado, fonte
|
|
identificada e direitos autorizados.
|
|
</p>
|
|
<Field label="Documento recebido">
|
|
<select
|
|
required
|
|
className={control}
|
|
value={form.data.document_id}
|
|
onChange={(e) => chooseDocument(e.target.value)}
|
|
>
|
|
<option value="">
|
|
Seleccionar ficheiro ou registo existente
|
|
</option>
|
|
{documents.map((d) => (
|
|
<option key={d.id} value={d.id}>
|
|
{d.file_name} · {d.status} ·{' '}
|
|
{d.data_classification} · malware{' '}
|
|
{d.malware_scan_status} · v{d.version_no}
|
|
</option>
|
|
))}
|
|
</select>
|
|
<p className="text-sm">
|
|
Pode registar ou corrigir metadados privados enquanto a
|
|
análise decorre. A classificação pública e a publicação
|
|
continuam bloqueadas até a análise limpa corresponder ao
|
|
hash actual.
|
|
</p>
|
|
</Field>
|
|
<details open className="rounded border p-4">
|
|
<summary className="cursor-pointer text-lg font-semibold">
|
|
1. Identificação
|
|
</summary>
|
|
<div className="mt-4 grid gap-3 sm:grid-cols-2">
|
|
<h3 className="text-lg font-semibold sm:col-span-2">
|
|
Identificação
|
|
</h3>
|
|
<Field label="Título">
|
|
<input
|
|
required
|
|
className={control}
|
|
value={form.data.title}
|
|
onChange={(e) =>
|
|
form.setData('title', e.target.value)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Tipo documental">
|
|
<select
|
|
className={control}
|
|
value={form.data.document_type}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'document_type',
|
|
e.target.value,
|
|
)
|
|
}
|
|
>
|
|
{[
|
|
['legislation', 'Legislação'],
|
|
['procedure', 'Procedimento'],
|
|
['official_form', 'Formulário oficial'],
|
|
[
|
|
'digital_adaptation',
|
|
'Adaptação digital de formulário oficial',
|
|
],
|
|
['guidance_template', 'Modelo orientativo'],
|
|
['guide', 'Guia'],
|
|
['study', 'Estudo'],
|
|
['reference_data', 'Dados de referência'],
|
|
['unknown', 'Por classificar'],
|
|
].map(([v, label]) => (
|
|
<option key={v} value={v}>
|
|
{label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
<Field label="Descrição em linguagem clara">
|
|
<textarea
|
|
className={control}
|
|
value={form.data.description}
|
|
onChange={(e) =>
|
|
form.setData('description', e.target.value)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Categoria">
|
|
<input
|
|
required
|
|
className={control}
|
|
value={form.data.category}
|
|
onChange={(e) =>
|
|
form.setData('category', e.target.value)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field
|
|
label={
|
|
legacyContentEnabled
|
|
? 'Assunto (opcional)'
|
|
: 'Assunto'
|
|
}
|
|
>
|
|
<input
|
|
required={!legacyContentEnabled}
|
|
className={control}
|
|
value={form.data.topic}
|
|
onChange={(e) =>
|
|
form.setData('topic', e.target.value)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Entidade emitente / autor">
|
|
<input
|
|
className={control}
|
|
value={form.data.issuer}
|
|
onChange={(e) =>
|
|
form.setData('issuer', e.target.value)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Número documental">
|
|
<input
|
|
className={control}
|
|
value={form.data.document_number}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'document_number',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Data documental">
|
|
<input
|
|
type="date"
|
|
className={control}
|
|
value={form.data.document_date}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'document_date',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
</div>
|
|
</details>
|
|
<details className="rounded border p-4">
|
|
<summary className="cursor-pointer text-lg font-semibold">
|
|
2. Fonte, versão e ficheiro
|
|
</summary>
|
|
<div className="mt-4 grid gap-3 sm:grid-cols-2">
|
|
<h3 className="text-lg font-semibold sm:col-span-2">
|
|
Fonte, versão e ficheiro
|
|
</h3>
|
|
<Field label="Fonte oficial/origem HTTPS">
|
|
<input
|
|
type="url"
|
|
className={control}
|
|
value={form.data.source_url}
|
|
onChange={(e) =>
|
|
form.setData('source_url', e.target.value)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Referência da fonte e autorização">
|
|
<input
|
|
required
|
|
className={control}
|
|
value={form.data.source_reference}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'source_reference',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Idioma (código, ex. pt)">
|
|
<input
|
|
required
|
|
maxLength={12}
|
|
className={control}
|
|
value={form.data.language}
|
|
onChange={(e) =>
|
|
form.setData('language', e.target.value)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Versão">
|
|
<input
|
|
className={control}
|
|
value={form.data.version_label}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'version_label',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Grupo de versões/traduções">
|
|
<input
|
|
className={control}
|
|
value={form.data.document_group_id}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'document_group_id',
|
|
e.target.value,
|
|
)
|
|
}
|
|
placeholder="UUID partilhado entre versões relacionadas"
|
|
/>
|
|
</Field>
|
|
</div>
|
|
</details>
|
|
<details className="rounded border p-4">
|
|
<summary className="cursor-pointer text-lg font-semibold">
|
|
3. Enquadramento, acesso e publicação
|
|
</summary>
|
|
<div className="mt-4 grid gap-3 sm:grid-cols-2">
|
|
<h3 className="text-lg font-semibold sm:col-span-2">
|
|
Enquadramento territorial e documental
|
|
</h3>
|
|
<Field label="Âmbito territorial">
|
|
<select
|
|
className={control}
|
|
value={form.data.territorial_scope}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'territorial_scope',
|
|
e.target.value,
|
|
)
|
|
}
|
|
>
|
|
{[
|
|
['unknown', 'Por confirmar'],
|
|
['national', 'Nacional'],
|
|
['provincial', 'Provincial'],
|
|
['district', 'Distrital'],
|
|
['locality', 'Localidade'],
|
|
['multiple', 'Múltiplos territórios'],
|
|
].map(([v, label]) => (
|
|
<option key={v} value={v}>
|
|
{label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
<Field label="Território (ID da base territorial)">
|
|
<select
|
|
className={control}
|
|
value={form.data.territory_id}
|
|
onChange={(e) =>
|
|
form.setData('territory_id', e.target.value)
|
|
}
|
|
>
|
|
<option value="">Não indicado</option>
|
|
{territories.map((t) => (
|
|
<option key={t.id} value={t.id}>
|
|
{t.name} · {t.location_type}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
<Field label="Confirmação da origem">
|
|
<select
|
|
className={control}
|
|
value={form.data.source_confirmation}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'source_confirmation',
|
|
e.target.value,
|
|
)
|
|
}
|
|
>
|
|
<option value="unconfirmed">
|
|
Por confirmar
|
|
</option>
|
|
<option value="identified">
|
|
Origem identificada
|
|
</option>
|
|
<option value="official_confirmed">
|
|
Fonte oficial confirmada
|
|
</option>
|
|
</select>
|
|
</Field>
|
|
<Field label="Situação jurídica">
|
|
<select
|
|
className={control}
|
|
value={form.data.legal_status}
|
|
onChange={(e) =>
|
|
form.setData('legal_status', e.target.value)
|
|
}
|
|
>
|
|
{[
|
|
['unknown', 'Por confirmar'],
|
|
['not_applicable', 'Não aplicável'],
|
|
['in_force', 'Indicada como vigente'],
|
|
['historical', 'Histórica'],
|
|
['proposed', 'Proposta'],
|
|
['repealed', 'Revogada'],
|
|
['amended', 'Alterada'],
|
|
].map(([v, label]) => (
|
|
<option key={v} value={v}>
|
|
{label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
<Field label="Aplicável desde (se documentado)">
|
|
<input
|
|
type="date"
|
|
className={control}
|
|
value={form.data.applicable_from}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'applicable_from',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Aplicável até (se documentado)">
|
|
<input
|
|
type="date"
|
|
className={control}
|
|
value={form.data.applicable_until}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'applicable_until',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Direitos de utilização">
|
|
<select
|
|
className={control}
|
|
value={form.data.rights_status}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'rights_status',
|
|
e.target.value,
|
|
)
|
|
}
|
|
>
|
|
<option value="unconfirmed">
|
|
Por confirmar
|
|
</option>
|
|
<option value="authorized">
|
|
Autorizados e registados
|
|
</option>
|
|
<option value="restricted">Restritos</option>
|
|
</select>
|
|
</Field>
|
|
<Field label="Classificação do ficheiro">
|
|
<select
|
|
className={control}
|
|
value={form.data.data_classification}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'data_classification',
|
|
e.target.value,
|
|
)
|
|
}
|
|
>
|
|
<option value="internal">
|
|
Privado (interno)
|
|
</option>
|
|
<option value="public">
|
|
Público após confirmar a fonte e os direitos
|
|
</option>
|
|
</select>
|
|
<p className="text-sm">
|
|
Classificar como público não publica o registo.
|
|
A publicação continua a exigir análise limpa,
|
|
fonte adequada e acção separada.
|
|
</p>
|
|
</Field>
|
|
</div>
|
|
</details>
|
|
<details className="rounded border p-4">
|
|
<summary className="cursor-pointer text-lg font-semibold">
|
|
4. Revisão e associações a requisitos
|
|
</summary>
|
|
<div className="mt-4 space-y-4">
|
|
<h3 className="text-lg font-semibold">
|
|
Revisão e disponibilização
|
|
</h3>
|
|
<label className="flex gap-2">
|
|
<input
|
|
type="checkbox"
|
|
checked={form.data.legislation}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'legislation',
|
|
e.target.checked,
|
|
)
|
|
}
|
|
/>
|
|
Incluir também em Legislação e Incentivos
|
|
</label>
|
|
<label className="flex gap-2">
|
|
<input
|
|
type="checkbox"
|
|
checked={form.data.essential}
|
|
onChange={(e) =>
|
|
form.setData('essential', e.target.checked)
|
|
}
|
|
/>
|
|
Destacar como essencial na página inicial
|
|
</label>
|
|
<label className="flex gap-2">
|
|
<input
|
|
type="checkbox"
|
|
checked={form.data.independent_review}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'independent_review',
|
|
e.target.checked,
|
|
)
|
|
}
|
|
/>
|
|
Foi realizada revisão independente por outro gestor
|
|
</label>
|
|
<fieldset className="space-y-3 rounded border p-4">
|
|
<legend className="font-semibold">
|
|
Relações com etapas, módulos e requisitos
|
|
</legend>
|
|
<p className="text-sm">
|
|
“Obrigatório” e “condicional” exigem fundamento.
|
|
Relacionar o mesmo documento a vários módulos
|
|
não cria cópias.
|
|
</p>
|
|
{!requirementAssociationsEnabled && (
|
|
<p role="status" className="text-sm">
|
|
As associações documentais a requisitos
|
|
serão activadas após a migração de
|
|
compatibilidade do catálogo.
|
|
</p>
|
|
)}
|
|
{form.data.associations.map(
|
|
(association, index) => (
|
|
<div
|
|
className="grid gap-2 rounded border p-3 sm:grid-cols-2"
|
|
key={index}
|
|
>
|
|
<label>
|
|
Tipo
|
|
<select
|
|
className={control}
|
|
value={association.target_type}
|
|
onChange={(e) =>
|
|
setAssociation(
|
|
index,
|
|
'target_type',
|
|
e.target.value,
|
|
)
|
|
}
|
|
>
|
|
{[
|
|
'theme',
|
|
'module',
|
|
'activity',
|
|
'stage',
|
|
'procedure',
|
|
'entity',
|
|
'territory',
|
|
'document',
|
|
'investment_type',
|
|
'legal_source',
|
|
'sector',
|
|
'opportunity',
|
|
'requirement',
|
|
]
|
|
.filter(
|
|
(v) =>
|
|
v !==
|
|
'requirement' ||
|
|
requirementAssociationsEnabled,
|
|
)
|
|
.map((v) => (
|
|
<option key={v} value={v}>
|
|
{({theme:'Tema', module:'Módulo',activity:'Actividade',stage:'Etapa',procedure:'Procedimento',entity:'Entidade',territory:'Território',document:'Documento / diploma',investment_type:'Modalidade de investimento',legal_source:'Fonte legal',requirement:'Requisito',sector:'Sector',opportunity:'Oportunidade'} as Record<string,string>)[v] ?? v}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Chave exacta
|
|
{association.target_type ===
|
|
'requirement' ? (
|
|
<select
|
|
className={control}
|
|
required
|
|
value={
|
|
association.target_key
|
|
}
|
|
onChange={(e) =>
|
|
setAssociation(
|
|
index,
|
|
'target_key',
|
|
e.target.value,
|
|
)
|
|
}
|
|
>
|
|
<option value="">
|
|
Seleccionar
|
|
identificador técnico
|
|
</option>
|
|
{requirementCatalogue.map(
|
|
(item) => (
|
|
<option
|
|
key={item.key}
|
|
value={item.key}
|
|
>
|
|
{item.label} (
|
|
{item.key})
|
|
</option>
|
|
),
|
|
)}
|
|
</select>
|
|
) : associationOptions[association.target_type] ? (
|
|
<select className={control} required value={association.target_key} onChange={(e) => setAssociation(index, 'target_key', e.target.value)}>
|
|
<option value="">Seleccione um registo existente</option>
|
|
{association.target_key && !associationOptions[association.target_type].some((o) => String(o.value) === association.target_key) && <option value={association.target_key}>Referência histórica guardada</option>}
|
|
{associationOptions[association.target_type].map((o) => <option key={o.value} value={o.value}>{o.label}</option>)}
|
|
</select>
|
|
) : (
|
|
<input
|
|
required
|
|
className={control}
|
|
value={
|
|
association.target_key
|
|
}
|
|
onChange={(e) =>
|
|
setAssociation(
|
|
index,
|
|
'target_key',
|
|
e.target.value,
|
|
)
|
|
}
|
|
placeholder="Chave exacta existente (actividade, módulo, procedimento…)"
|
|
/>
|
|
)}
|
|
</label>
|
|
<label>
|
|
Relação
|
|
<select
|
|
className={control}
|
|
value={association.relationship}
|
|
onChange={(e) =>
|
|
setAssociation(
|
|
index,
|
|
'relationship',
|
|
e.target.value,
|
|
)
|
|
}
|
|
>
|
|
{[
|
|
'applies_to',
|
|
'supports',
|
|
'version_of',
|
|
'translation_of',
|
|
'amends',
|
|
'repeals',
|
|
'implements',
|
|
'cites',
|
|
'related_to',
|
|
].map((v) => (
|
|
<option key={v}>{v}</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Aplicabilidade
|
|
<select
|
|
className={control}
|
|
value={
|
|
association.applicability
|
|
}
|
|
onChange={(e) =>
|
|
setAssociation(
|
|
index,
|
|
'applicability',
|
|
e.target.value,
|
|
)
|
|
}
|
|
>
|
|
{[
|
|
'support',
|
|
'optional_template',
|
|
'conditional',
|
|
'required',
|
|
'evidence',
|
|
].map((v) => (
|
|
<option key={v}>{v}</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label>
|
|
Condição
|
|
<textarea
|
|
className={control}
|
|
value={
|
|
association.condition_text
|
|
}
|
|
onChange={(e) =>
|
|
setAssociation(
|
|
index,
|
|
'condition_text',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</label>
|
|
<label>
|
|
Fundamento documental
|
|
<textarea
|
|
className={control}
|
|
value={
|
|
association.basis_reference
|
|
}
|
|
onChange={(e) =>
|
|
setAssociation(
|
|
index,
|
|
'basis_reference',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</label>
|
|
<label>
|
|
Conferência da citação
|
|
<select
|
|
className={control}
|
|
value={
|
|
association.review_status ??
|
|
'pending'
|
|
}
|
|
onChange={(e) =>
|
|
setAssociation(
|
|
index,
|
|
'review_status',
|
|
e.target.value,
|
|
)
|
|
}
|
|
>
|
|
<option value="pending">
|
|
Pendente
|
|
</option>
|
|
<option value="confirmed">
|
|
Citação conferida no
|
|
documento
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<button
|
|
type="button"
|
|
className="underline sm:col-span-2"
|
|
onClick={() =>
|
|
form.setData(
|
|
'associations',
|
|
form.data.associations.filter(
|
|
(_, row) =>
|
|
row !== index,
|
|
),
|
|
)
|
|
}
|
|
>
|
|
Remover relação
|
|
</button>
|
|
</div>
|
|
),
|
|
)}
|
|
<button
|
|
type="button"
|
|
className="rounded border px-3 py-2"
|
|
onClick={() =>
|
|
form.setData('associations', [
|
|
...form.data.associations,
|
|
{ ...emptyAssociation },
|
|
])
|
|
}
|
|
>
|
|
Adicionar relação
|
|
</button>
|
|
</fieldset>
|
|
</div>
|
|
</details>
|
|
{Object.entries(form.errors).map(([key, error]) => (
|
|
<p role="alert" key={key}>
|
|
{error}
|
|
</p>
|
|
))}
|
|
<div className="flex gap-3">
|
|
<button className={button} disabled={form.processing}>
|
|
{editingId
|
|
? 'Guardar alterações'
|
|
: 'Guardar como rascunho'}
|
|
</button>
|
|
{editingId && (
|
|
<button
|
|
type="button"
|
|
className="rounded border px-4 py-2"
|
|
onClick={() => {
|
|
setEditingId(null);
|
|
form.reset();
|
|
}}
|
|
>
|
|
Cancelar edição
|
|
</button>
|
|
)}
|
|
</div>
|
|
</form>
|
|
|
|
{disclosureAuthorization && (
|
|
<section
|
|
className="space-y-3 rounded border border-emerald-700 bg-emerald-50 p-5"
|
|
aria-labelledby="disclosure-authorization-title"
|
|
>
|
|
<h2
|
|
id="disclosure-authorization-title"
|
|
className="text-xl font-bold"
|
|
>
|
|
Autorização expressa de disponibilização documental
|
|
</h2>
|
|
<p>
|
|
Registada em{' '}
|
|
{new Date(
|
|
disclosureAuthorization.occurred_at,
|
|
).toLocaleString()}
|
|
; origem: instrução do utilizador, sem atribuição a
|
|
gestor. Abrange consulta e download dos documentos
|
|
listados e não certifica autenticidade ou vigência, nem
|
|
activa cálculos fiscais.
|
|
</p>
|
|
<ul className="list-disc pl-6">
|
|
{disclosureAuthorization.resources.map((resource) => (
|
|
<li key={resource.id}>
|
|
#{resource.id} · {resource.title} ·{' '}
|
|
{resource.published
|
|
? 'já publicado'
|
|
: `rascunho (${resource.rights_status})`}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<p className="text-sm">
|
|
A acção mantém a autenticação de gestão e só publica
|
|
ficheiros activos cujo hash corresponda ao resultado
|
|
antimalware e que tenham fonte identificada. As
|
|
situações de fonte e vigência são preservadas e
|
|
apresentadas ao público. Registos que falhem estes
|
|
controlos ficam pendentes individualmente.
|
|
</p>
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={disclosureAuthorization.resources.every(
|
|
(resource) => resource.published,
|
|
)}
|
|
onClick={() =>
|
|
router.post(
|
|
'/management/portal-services/disclosure-authorization/apply',
|
|
{},
|
|
{ preserveScroll: true },
|
|
)
|
|
}
|
|
>
|
|
Aplicar autorização e disponibilizar documentos
|
|
elegíveis
|
|
</button>
|
|
</section>
|
|
)}
|
|
|
|
<h2 id="conteudos" className="text-xl font-bold">
|
|
Registos, pendências e duplicados por rever
|
|
</h2>
|
|
<form className="flex flex-wrap gap-3 rounded border p-4" aria-label="Pesquisar conteúdos" onSubmit={(e) => {e.preventDefault(); router.get('/management/portal-services', {q:query,state:stateFilter}, {preserveState:true,preserveScroll:true});}}>
|
|
<Field label="Pesquisar título, ficheiro, número ou entidade"><input className={control} value={query} onChange={(e) => setQuery(e.target.value)} /></Field>
|
|
<Field label="Estado do conteúdo"><select className={control} value={stateFilter} onChange={(e) => setStateFilter(e.target.value)}><option value="">Todos</option><option value="draft">Rascunhos</option><option value="published">Publicados</option><option value="withdrawn">Retirados</option></select></Field>
|
|
<button className={button}>Pesquisar conteúdos</button>
|
|
</form>
|
|
<p>Mostram-se até 200 registos por pesquisa. Refine o título ou o estado para localizar conteúdos anteriores.</p>
|
|
{!resources.length && <p role="status">Sem conteúdos correspondentes no seu âmbito de acesso.</p>}
|
|
{resources.map((r) => (
|
|
<article key={r.id} className="space-y-3 rounded border p-4">
|
|
<h3 className="font-bold">
|
|
{r.title} · {r.published ? 'Publicado' : r.revisions.some((v) => ['unpublished', 'withdrawn'].includes(v.change_type)) ? 'Retirado' : 'Rascunho'}
|
|
</h3>
|
|
<p>
|
|
Ficheiro: {r.file_name} · {r.file_status} ·{' '}
|
|
{r.data_classification} · direitos: {r.rights_status} ·
|
|
fonte: {r.source_confirmation} · estado jurídico:{' '}
|
|
{r.legal_status}
|
|
</p>
|
|
<p className="text-sm">
|
|
Período de aplicação registado:{' '}
|
|
{r.applicable_from || r.applicable_until
|
|
? `${r.applicable_from ?? 'início não indicado'} — ${r.applicable_until ?? 'sem data final indicada'}`
|
|
: 'não registado'}
|
|
.
|
|
</p>
|
|
<p className="text-sm whitespace-pre-line">
|
|
Descrição e limites:{' '}
|
|
{r.description || 'Descrição ainda não registada.'}
|
|
</p>
|
|
<p className="text-sm whitespace-pre-line">
|
|
Fonte e fundamento de utilização/direitos:{' '}
|
|
{r.source_reference ||
|
|
'Referência de fonte e direitos não registada.'}
|
|
</p>
|
|
{r.duplicate_of_resource_id && (
|
|
<p role="status">
|
|
Possível duplicado do registo #
|
|
{r.duplicate_of_resource_id}; requer comparação
|
|
documental. Nenhuma fusão foi feita.
|
|
</p>
|
|
)}
|
|
{!!r.revisions?.length && (
|
|
<details>
|
|
<summary className="cursor-pointer font-semibold">
|
|
Histórico de metadados e publicação (
|
|
{r.revisions.length})
|
|
</summary>
|
|
<ol className="list-decimal pl-6 text-sm">
|
|
{r.revisions.map((revision) => (
|
|
<li key={revision.revision_no}>
|
|
v{revision.revision_no} ·{' '}
|
|
{revision.change_type} · gestor #
|
|
{revision.actor_user_id ?? 'removido'} ·{' '}
|
|
{revision.created_at}
|
|
</li>
|
|
))}
|
|
</ol>
|
|
</details>
|
|
)}
|
|
{!r.description ||
|
|
!r.source_url ||
|
|
r.source_confirmation === 'unconfirmed' ||
|
|
r.legal_status === 'unknown' ||
|
|
r.rights_status === 'unconfirmed' ? (
|
|
<p className="text-amber-900">
|
|
Pendências:{' '}
|
|
{[
|
|
!r.description && 'descrição',
|
|
!r.source_url && 'URL da fonte',
|
|
r.source_confirmation === 'unconfirmed' &&
|
|
'confirmação da origem',
|
|
r.legal_status === 'unknown' &&
|
|
'situação jurídica',
|
|
r.rights_status === 'unconfirmed' && 'direitos',
|
|
]
|
|
.filter(Boolean)
|
|
.join(', ')}
|
|
.
|
|
</p>
|
|
) : null}
|
|
<div className="flex flex-wrap gap-3">
|
|
<button
|
|
type="button"
|
|
className="rounded border px-3 py-2"
|
|
onClick={() => {
|
|
setEditingId(r.id);
|
|
form.setData({
|
|
document_id: r.document_id,
|
|
title: r.title,
|
|
description: r.description ?? '',
|
|
category: r.category,
|
|
topic: r.topic,
|
|
document_type: r.document_type,
|
|
issuer: r.issuer ?? '',
|
|
document_number: r.document_number ?? '',
|
|
document_date: r.document_date ?? '',
|
|
applicable_from: r.applicable_from ?? '',
|
|
applicable_until: r.applicable_until ?? '',
|
|
source_url: r.source_url ?? '',
|
|
language: r.language,
|
|
version_label: r.version_label ?? '',
|
|
document_group_id:
|
|
r.document_group_id ?? '',
|
|
territorial_scope: r.territorial_scope,
|
|
territory_id: r.territory_id ?? '',
|
|
source_confirmation: r.source_confirmation,
|
|
legal_status: r.legal_status,
|
|
rights_status: r.rights_status,
|
|
data_classification: r.data_classification,
|
|
source_reference: r.source_reference,
|
|
legislation: r.legislation,
|
|
essential: r.essential,
|
|
independent_review: r.independent_review,
|
|
metadata_version: r.metadata_version,
|
|
associations: r.links.map((link) => ({
|
|
...link,
|
|
condition_text:
|
|
link.condition_text ?? '',
|
|
basis_reference:
|
|
link.basis_reference ?? '',
|
|
review_status:
|
|
link.review_status ?? 'pending',
|
|
})),
|
|
});
|
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
}}
|
|
>
|
|
Editar metadados
|
|
</button>
|
|
<a
|
|
className={button}
|
|
href={`/management/portal-services/resources/${r.id}/article`}
|
|
>
|
|
Editar artigo
|
|
</a>
|
|
<a className={button} href={`/management/portal-services/resources/${r.id}/article/preview`}>Ler / pré-visualizar artigo</a>
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
onClick={() => {
|
|
setActionError('');
|
|
router.post(
|
|
`/management/portal-services/resources/${r.id}`,
|
|
{ published: !r.published },
|
|
{
|
|
preserveScroll: true,
|
|
onError: (errors) =>
|
|
setActionError(
|
|
Object.values(errors)[0] ??
|
|
'A transição foi recusada; confirme o estado do ficheiro, fonte e direitos.',
|
|
),
|
|
},
|
|
);
|
|
}}
|
|
>
|
|
{r.published ? 'Retirar da publicação' : 'Publicar'}
|
|
</button>
|
|
</div>
|
|
{actionError && <p role="alert">{actionError}</p>}
|
|
</article>
|
|
))}
|
|
|
|
<h2 className="text-xl font-bold">Propostas de parceria</h2>
|
|
{partnerships.map((p) => (
|
|
<article key={p.id} className="space-y-3 rounded border p-4">
|
|
<h3 className="font-bold">{p.title}</h3>
|
|
<p>
|
|
{p.sector} · {p.province} ·{' '}
|
|
{p.status === 'published'
|
|
? 'Publicado'
|
|
: p.status === 'pending'
|
|
? 'Pendente'
|
|
: 'Retirado'}
|
|
</p>
|
|
<p className="whitespace-pre-line">Oferece: {p.offer}</p>
|
|
<p className="whitespace-pre-line">Procura: {p.seeking}</p>
|
|
<button
|
|
className={button}
|
|
onClick={() =>
|
|
router.post(
|
|
`/management/portal-services/partnerships/${p.id}`,
|
|
{ published: p.status !== 'published' },
|
|
{ preserveScroll: true },
|
|
)
|
|
}
|
|
>
|
|
{p.status === 'published'
|
|
? 'Retirar'
|
|
: 'Aprovar e publicar'}
|
|
</button>
|
|
</article>
|
|
))}
|
|
</>}
|
|
</Management>
|
|
);
|
|
}
|