PageSourceSearch

https://anpg.co.ao/assets/AdminTaxonomiesPage-CdWOj77c.js

js anpg.co.ao collected 2026-10-02 16:45:54 UTC 13,656 bytes, 7 lines download raw bytes

1/* ANPG DEVTEAM - 29/09/2026, 14:34:20 */
2import{e as Ee,u as U,d as g,j as e}from"./data-vendor-BRYI0K8G.js";import{r as l}from"./react-vendor-Bj9LQV-u.js";import{A as De}from"./AdminLayout-h_nmul7P.js";import{e as we,ao as C,b as c,w as T,af as G,ag as J,ah as W,ai as X,bf as Y,bM as Z,bh as o,an as S}from"./index-B5fS5HUA.js";import{I as v}from"./input-CtWCrhgd.js";import{L as d}from"./label-ByFBDaC1.js";import{S as P}from"./switch-B0x4NxgT.js";import{B as V}from"./badge-jukGcCw8.js";import{T as Ae,a as Fe,b as L,c as b,d as qe,e as f}from"./table-BTascmHv.js";import{S as Pe,a as Ve,b as Le,c as Oe,d as ze}from"./select-CIRt4Z_4.js";import{A as ee,a as se,b as re,c as ie,d as ae,e as te,f as oe,g as ne}from"./alert-dialog-J_9uTetV.js";import{C as le,b as ce,c as de,d as me,a as xe}from"./card-SWKDiSm6.js";import{P as ue}from"./plus-lNvdMfmK.js";import{L as $e}from"./lock-BuPS0Fev.js";import{P as he}from"./pencil-C8r3g6iN.js";import{T as pe}from"./trash-2-BmjaA2Y9.js";import"./message-square-3F19oJ7J.js";import"./newspaper-B1VsFBcy.js";import"./tag-zpo8YYRH.js";import"./camera-DF73IPZH.js";import"./shield-check-DBFg_Isw.js";import"./sliders-horizontal-CI8TRfgr.js";import"./user-check-Omtv7yGv.js";import"./network-Bioht48n.js";import"./clock-DjVV6Aw0.js";import"./book-open-BvZy1lzn.js";import"./bot-Ckp6pNDt.js";import"./gavel-D8KhpCGX.js";import"./presentation-Bg7Ve6-F.js";import"./star-BMTUmwlW.js";import"./clipboard-check-AscQTU3D.js";import"./folder-open-DBolFNfs.js";import"./settings-2-5vee-iyr.js";import"./rocket-OwwOM41y.js";import"./user-B2J0vviq.js";import"./arrow-left-B5pHXlkl.js";import"./circle-check-big-R1zEC76Q.js";import"./charts-vendor-Cs07Jtv5.js";import"./motion-vendor-DMc3mo8t.js";import"./i18n-vendor-BSIZ7LIS.js";import"./index-D6PzSG9l.js";import"./index-BdQq_4o_.js";import"./index-BatE7gkT.js";import"./chevron-up-CYP72WxE.js";/**
3 * @license lucide-react v0.462.0 - ISC
4 *
5 * This source code is licensed under the ISC license.
6 * See the LICENSE file in the root directory of this source tree.
7 */const Ke=we("Tags",[["path",{d:"m15 5 6.3 6.3a2.4 2.4 0 0 1 0 3.4L17 19",key:"1cbfv1"}],["path",{d:"M9.586 5.586A2 2 0 0 0 8.172 5H3a1 1 0 0 0-1 1v5.172a2 2 0 0 0 .586 1.414L8.29 18.29a2.426 2.426 0 0 0 3.42 0l3.58-3.58a2.426 2.426 0 0 0 0-3.42z",key:"135mg7"}],["circle",{cx:"6.5",cy:"9.5",r:".5",fill:"currentColor",key:"5pm5xn"}]]),Qe=["global","exploration","production","local_content","investor","production_incremental","media"],O={vkey:"",name_pt:"",scope:"exploration",is_hierarchical:!1,is_system:!1,is_active:!0,sort_order:0},z={code:"",label_pt:"",sort_order:0,is_active:!0};function Fs(){const h=Ee(),[$,K]=l.useState(null),[je,k]=l.useState(!1),[y,E]=l.useState(null),[i,m]=l.useState({...O}),[p,D]=l.useState(null),[ge,w]=l.useState(!1),[A,F]=l.useState(null),[a,u]=l.useState({...z}),[j,q]=l.useState(null),{data:n,isLoading:ve}=U({queryKey:["admin-taxonomy-vocabularies"],queryFn:async()=>(await S.list({sort:"sort_order,name_pt",limit:200})).data}),r=l.useMemo(()=>(n==null?void 0:n.find(s=>{var t;return s.id===($??((t=n==null?void 0:n[0])==null?void 0:t.id))}))??null,[n,$]),{data:x,isLoading:fe}=U({queryKey:["admin-taxonomy-terms",r==null?void 0:r.id],enabled:!!(r!=null&&r.id),queryFn:async()=>(await C.list({vocabulary_id:r.id,sort:"sort_order,label_pt",limit:500})).data}),Q=g({mutationFn:s=>S.create(s),onSuccess:()=>{h.invalidateQueries({queryKey:["admin-taxonomy-vocabularies"]}),o.success("Vocabulário criado"),_()},onError:s=>o.error(`Erro: ${s.message}`)}),H=g({mutationFn:({id:s,data:t})=>S.update(s,t),onSuccess:()=>{h.invalidateQueries({queryKey:["admin-taxonomy-vocabularies"]}),o.success("Vocabulário actualizado"),_()},onError:s=>o.error(`Erro: ${s.message}`)}),ye=g({mutationFn:s=>S.delete(s),onSuccess:()=>{h.invalidateQueries({queryKey:["admin-taxonomy-vocabularies"]}),o.success("Vocabulário eliminado"),D(null),K(null)},onError:s=>o.error(`Erro: ${s.message}`)}),I=g({mutationFn:s=>C.create(s),onSuccess:()=>{h.invalidateQueries({queryKey:["admin-taxonomy-terms",r==null?void 0:r.id]}),o.success("Termo criado"),N()},onError:s=>o.error(`Erro: ${s.message}`)}),B=g({mutationFn:({id:s,data:t})=>C.update(s,t),onSuccess:()=>{h.invalidateQueries({queryKey:["admin-taxonomy-terms",r==null?void 0:r.id]}),o.success("Termo actualizado"),N()},onError:s=>o.error(`Erro: ${s.message}`)}),be=g({mutationFn:s=>C.delete(s),onSuccess:()=>{h.invalidateQueries({queryKey:["admin-taxonomy-terms",r==null?void 0:r.id]}),o.success("Termo eliminado"),q(null)},onError:s=>o.error(`Erro: ${s.message}`)}),_=()=>{k(!1),E(null),m({...O})},N=()=>{w(!1),F(null),u({...z})},_e=()=>{E(null),m({...O}),k(!0)},Ne=s=>{E(s),m({vkey:s.vkey,name_pt:s.name_pt,scope:s.scope,is_hierarchical:!!s.is_hierarchical,is_system:!!s.is_system,is_active:!!s.is_active,sort_order:s.sort_order??0}),k(!0)},Ce=()=>{F(null),u({...z}),w(!0)},Te=s=>{F(s),u({code:s.code,label_pt:s.label_pt,sort_order:s.sort_order??0,is_active:!!s.is_active}),w(!0)},Se=s=>{if(s.preventDefault(),!i.vkey||!i.name_pt){o.error("Chave e nome (PT) são obrigatórios");return}const t={vkey:i.vkey.trim(),name_pt:i.name_pt.trim(),scope:i.scope,is_hierarchical:i.is_hierarchical?1:0,is_system:i.is_system?1:0,is_active:i.is_active?1:0,sort_order:Number(i.sort_order)||0};y?H.mutate({id:y.id,data:t}):Q.mutate(t)},ke=s=>{if(s.preventDefault(),!r)return;if(!a.code||!a.label_pt){o.error("Código e rótulo (PT) são obrigatórios");return}const t={vocabulary_id:r.id,parent_id:null,code:a.code.trim(),label_pt:a.label_pt.trim(),sort_order:Number(a.sort_order)||0,is_active:a.is_active?1:0};A?B.mutate({id:A.id,data:t}):I.mutate(t)},M=Q.isPending||H.isPending,R=I.isPending||B.isPending;return e.jsxs(De,{title:"Taxonomias",subtitle:"Vocabulários e termos globais (Definições)",children:[e.jsx("main",{className:"container mx-auto px-4 py-8",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[340px_1fr] gap-6",children:[e.jsxs(le,{children:[e.jsx(ce,{children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsxs(de,{className:"flex items-center gap-2",children:[e.jsx(Ke,{className:"h-5 w-5"}),"Vocabulários"]}),e.jsx(me,{children:"Listas reutilizáveis"})]}),e.jsx(c,{size:"sm",onClick:_e,children:e.jsx(ue,{className:"h-4 w-4"})})]})}),e.jsx(xe,{className:"space-y-1",children:ve?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(T,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):(n==null?void 0:n.length)===0?e.jsx("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"Sem vocabulários"}):n==null?void 0:n.map(s=>{const t=(r==null?void 0:r.id)===s.id;return e.jsxs("button",{onClick:()=>K(s.id),className:`w-full text-left rounded-md px-3 py-2 border transition-colors ${t?"bg-primary/10 border-primary":"border-transparent hover:bg-muted"}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"font-medium text-sm flex items-center gap-1.5",children:[s.name_pt,!!s.is_system&&e.jsx($e,{className:"h-3 w-3 text-muted-foreground"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(V,{variant:"outline",className:"text-[10px]",children:s.scope}),!s.is_active&&e.jsx(V,{variant:"secondary",className:"text-[10px]",children:"off"})]})]}),e.jsx("span",{className:"text-xs text-muted-foreground font-mono",children:s.vkey})]},s.id)})})]}),e.jsxs(le,{children:[e.jsx(ce,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(de,{children:r?`Termos · ${r.name_pt}`:"Termos"}),e.jsx(me,{children:r?`${(x==null?void 0:x.length)??0} termo(s)`:"Selecione um vocabulário"})]}),e.jsx("div",{className:"flex gap-2",children:r&&e.jsxs(e.Fragment,{children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>Ne(r),children:[e.jsx(he,{className:"h-4 w-4 mr-1"}),"Editar vocabulário"]}),!r.is_system&&e.jsx(c,{variant:"outline",size:"sm",className:"text-destructive",onClick:()=>D(r),children:e.jsx(pe,{className:"h-4 w-4"})}),e.jsxs(c,{size:"sm",onClick:Ce,children:[e.jsx(ue,{className:"h-4 w-4 mr-1"}),"Termo"]})]})})]})}),e.jsx(xe,{children:r?fe?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(T,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"rounded-md border",children:e.jsxs(Ae,{children:[e.jsx(Fe,{children:e.jsxs(L,{children:[e.jsx(b,{children:"Rótulo (PT)"}),e.jsx(b,{children:"Código"}),e.jsx(b,{children:"Ordem"}),e.jsx(b,{children:"Estado"}),e.jsx(b,{className:"text-right",children:"Acções"})]})}),e.jsx(qe,{children:(x==null?void 0:x.length)===0?e.jsx(L,{children:e.jsx(f,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"Nenhum termo"})}):x==null?void 0:x.map(s=>e.jsxs(L,{children:[e.jsx(f,{className:"font-medium",children:s.label_pt}),e.jsx(f,{className:"font-mono text-xs",children:s.code}),e.jsx(f,{children:s.sort_order}),e.jsx(f,{children:e.jsx(V,{variant:s.is_active?"default":"secondary",children:s.is_active?"Activo":"Inactivo"})}),e.jsx(f,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c,{variant:"ghost",size:"icon",onClick:()=>Te(s),children:e.jsx(he,{className:"h-4 w-4"})}),e.jsx(c,{variant:"ghost",size:"icon",className:"text-destructive",onClick:()=>q(s),children:e.jsx(pe,{className:"h-4 w-4"})})]})})]},s.id))})]})}):e.jsx("p",{className:"text-sm text-muted-foreground py-10 text-center",children:"Selecione um vocabulário à esquerda."})})]})]})}),e.jsx(G,{open:je,onOpenChange:s=>{s||_()},children:e.jsx(J,{children:e.jsxs("form",{onSubmit:Se,children:[e.jsxs(W,{children:[e.jsx(X,{children:y?"Editar Vocabulário":"Novo Vocabulário"}),e.jsx(Y,{children:"Uma lista reutilizável de termos (ex.: Bacias, Temas)."})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(d,{children:"Chave (vkey) *"}),e.jsx(v,{value:i.vkey,onChange:s=>m({...i,vkey:s.target.value}),placeholder:"basin",disabled:!!y&&!!y.is_system,className:"font-mono"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(d,{children:"Nome *"}),e.jsx(v,{value:i.name_pt,onChange:s=>m({...i,name_pt:s.target.value})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(d,{children:"Âmbito"}),e.jsxs(Pe,{value:i.scope,onValueChange:s=>m({...i,scope:s}),children:[e.jsx(Ve,{children:e.jsx(Le,{})}),e.jsx(Oe,{children:Qe.map(s=>e.jsx(ze,{value:s,children:s},s))})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(d,{children:"Ordem"}),e.jsx(v,{type:"number",value:i.sort_order,onChange:s=>m({...i,sort_order:s.target.value})})]})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{checked:i.is_hierarchical,onCheckedChange:s=>m({...i,is_hierarchical:s})}),e.jsx(d,{children:"Hierárquico"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{checked:i.is_active,onCheckedChange:s=>m({...i,is_active:s})}),e.jsx(d,{children:"Activo"})]})]})]}),e.jsxs(Z,{children:[e.jsx(c,{type:"button",variant:"outline",onClick:_,children:"Cancelar"}),e.jsxs(c,{type:"submit",disabled:M,children:[M&&e.jsx(T,{className:"h-4 w-4 mr-2 animate-spin"}),"Guardar"]})]})]})})}),e.jsx(G,{open:ge,onOpenChange:s=>{s||N()},children:e.jsx(J,{children:e.jsxs("form",{onSubmit:ke,children:[e.jsxs(W,{children:[e.jsx(X,{children:A?"Editar Termo":"Novo Termo"}),e.jsx(Y,{children:r?`Vocabulário: ${r.name_pt}`:""})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(d,{children:"Código *"}),e.jsx(v,{value:a.code,onChange:s=>u({...a,code:s.target.value}),placeholder:"baixo-congo",className:"font-mono"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(d,{children:"Rótulo *"}),e.jsx(v,{value:a.label_pt,onChange:s=>u({...a,label_pt:s.target.value})})]}),e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsxs("div",{className:"grid gap-2 w-28",children:[e.jsx(d,{children:"Ordem"}),e.jsx(v,{type:"number",value:a.sort_order,onChange:s=>u({...a,sort_order:s.target.value})})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-6",children:[e.jsx(P,{checked:a.is_active,onCheckedChange:s=>u({...a,is_active:s})}),e.jsx(d,{children:"Activo"})]})]})]}),e.jsxs(Z,{children:[e.jsx(c,{type:"button",variant:"outline",onClick:N,children:"Cancelar"}),e.jsxs(c,{type:"submit",disabled:R,children:[R&&e.jsx(T,{className:"h-4 w-4 mr-2 animate-spin"}),"Guardar"]})]})]})})}),e.jsx(ee,{open:!!p,onOpenChange:s=>{s||D(null)},children:e.jsxs(se,{children:[e.jsxs(re,{children:[e.jsx(ie,{children:"Eliminar vocabulário?"}),e.jsxs(ae,{children:['Esta acção elimina "',p==null?void 0:p.name_pt,'" e todos os seus termos. Não pode ser desfeita.']})]}),e.jsxs(te,{children:[e.jsx(oe,{children:"Cancelar"}),e.jsx(ne,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>p&&ye.mutate(p.id),children:"Eliminar"})]})]})}),e.jsx(ee,{open:!!j,onOpenChange:s=>{s||q(null)},children:e.jsxs(se,{children:[e.jsxs(re,{children:[e.jsx(ie,{children:"Eliminar termo?"}),e.jsxs(ae,{children:['Esta acção elimina "',j==null?void 0:j.label_pt,'". Não pode ser desfeita.']})]}),e.jsxs(te,{children:[e.jsx(oe,{children:"Cancelar"}),e.jsx(ne,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>j&&be.mutate(j.id),children:"Eliminar"})]})]})})]})}export{Fs as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.