2 lines
16 KiB
JavaScript
2 lines
16 KiB
JavaScript
import{a as ee}from"./chunk-YEESETR2.js";import{c as J,d as $,e as K,f as Q,g as U,h as X,p as Y,t as Z}from"./chunk-UDFQV3WY.js";import{e as H,i as O}from"./chunk-ZEULGWAI.js";import"./chunk-MBEC6LK4.js";import{Eb as a,Fa as s,Fb as C,Gb as E,Jb as w,Kb as y,Lb as S,Oa as G,Ob as T,R as m,Rb as R,S as u,T as h,Ta as N,U as M,Ya as A,ca as f,db as x,fb as v,hb as P,ib as F,jb as _,kb as i,lb as r,mb as g,nb as j,ob as B,pc as D,qb as b,qc as z,rb as p,rc as L,sb as d,sc as W,xc as q}from"./chunk-TVKQFRWX.js";import{a as k,b as V}from"./chunk-DAQOROHW.js";var ie=()=>({"background-color":"#00843B","border-color":"#00843B"}),ne=()=>({}),re=(o,t,e)=>({"bg-green-50 border-green-500 text-green-700":o,"bg-red-50 border-red-500 text-red-700":t,"bg-blue-50 border-blue-500 text-blue-700":e}),oe=(o,t)=>t.id;function le(o,t){o&1&&(i(0,"div",10),g(1,"div",15),r())}function ae(o,t){o&1&&(i(0,"div",10),h(),i(1,"svg",16),g(2,"path",17),r(),M(),i(3,"p",5),a(4,"Aucun minist\xE8re pour le moment"),r()())}function se(o,t){if(o&1){let e=b();i(0,"tr")(1,"td")(2,"div",23)(3,"p",24),a(4),r()()(),i(5,"td"),a(6),r(),i(7,"td"),a(8),r(),i(9,"td",25)(10,"div",26)(11,"button",27),p("click",function(){let n=m(e).$implicit,c=d(2);return u(c.viewArticle(n))}),h(),i(12,"svg",28),g(13,"path",29)(14,"path",30),r()(),M(),i(15,"button",31),p("click",function(){let n=m(e).$implicit,c=d(2);return u(c.editArticle(n))}),h(),i(16,"svg",32),g(17,"path",33),r()(),M(),i(18,"button",34),p("click",function(){let n=m(e).$implicit,c=d(2);return u(c.deleteArticle(n))}),h(),i(19,"svg",35),g(20,"path",36),r()()()()()}if(o&2){let e=t.$implicit;s(4),C(e.nomGeneral),s(2),C(e.nomReel),s(2),C(e.acronyme)}}function ce(o,t){if(o&1){let e=b();j(0),i(1,"button",37),p("click",function(){let n=m(e).$implicit,c=d(2);return u(c.goToPage(n))}),a(2),r(),B()}if(o&2){let e=t.$implicit,l=d(2);s(),_("ngClass",l.currentPage()===e?"px-3 py-1 border rounded text-white":"px-3 py-1 border border-gray-300 rounded hover:bg-gray-100 transition-colors")("ngStyle",l.currentPage()===e?T(3,ie):T(4,ne)),s(),E(" ",e," ")}}function de(o,t){if(o&1){let e=b();i(0,"div",11)(1,"table",18)(2,"thead")(3,"tr")(4,"th"),a(5,"Nom G\xE8neral"),r(),i(6,"th"),a(7,"Nom d'accroche"),r(),i(8,"th"),a(9,"Accronyme"),r(),i(10,"th",19),a(11,"Actions"),r()()(),i(12,"tbody"),P(13,se,21,3,"tr",null,oe),r()(),i(15,"div",20)(16,"button",21),p("click",function(){m(e);let n=d();return u(n.prevPage())}),a(17," \xAB Pr\xE9c\xE9dent "),r(),A(18,ce,3,5,"ng-container",22),i(19,"button",21),p("click",function(){m(e);let n=d();return u(n.nextPage())}),a(20," Suivant \xBB "),r()()()}if(o&2){let e=d();s(13),F(e.articles()),s(3),_("disabled",e.currentPage()===1),s(2),_("ngForOf",e.pages()),s(),_("disabled",e.currentPage()===e.totalPages())}}function me(o,t){o&1&&g(0,"div",53)}function ue(o,t){if(o&1){let e=b();i(0,"div",12)(1,"div",38)(2,"div",39)(3,"h2",40),a(4),r()(),i(5,"form",41,0),p("ngSubmit",function(){m(e);let n=d();return u(n.saveArticle())}),i(7,"div")(8,"label",42),a(9,"Nom G\xE9n\xE9ral "),i(10,"span",43),a(11,"*"),r()(),i(12,"input",44,1),S("ngModelChange",function(n){m(e);let c=d();return y(c.form.nomGeneral,n)||(c.form.nomGeneral=n),u(n)}),r()(),i(14,"div",45)(15,"div")(16,"label",42),a(17,"Nom d'accroche "),i(18,"span",43),a(19,"*"),r()(),i(20,"input",46,1),S("ngModelChange",function(n){m(e);let c=d();return y(c.form.nomReel,n)||(c.form.nomReel=n),u(n)}),r()(),i(22,"div")(23,"label",42),a(24,"Acronyme"),i(25,"span",43),a(26,"*"),r()(),i(27,"input",47,1),S("ngModelChange",function(n){m(e);let c=d();return y(c.form.acronyme,n)||(c.form.acronyme=n),u(n)}),r()()(),i(29,"div")(30,"label",42),a(31,"Mission G\xE9n\xE9rale"),r(),i(32,"textarea",48),S("ngModelChange",function(n){m(e);let c=d();return y(c.form.missionGeneral,n)||(c.form.missionGeneral=n),u(n)}),r()(),i(33,"div")(34,"label",42),a(35,"Logo "),i(36,"span",43),a(37,"*"),r()(),i(38,"input",49),p("change",function(n){m(e);let c=d();return u(c.onFileSelected(n))}),r()(),i(39,"div")(40,"label",42),a(41,"Image pour Premi\xE8re Page "),i(42,"span",43),a(43,"*"),r()(),i(44,"input",49),p("change",function(n){m(e);let c=d();return u(c.onFileSelected1(n))}),r()(),i(45,"div",50)(46,"button",51),p("click",function(){m(e);let n=d();return u(n.closeModal())}),a(47,"Annuler"),r(),i(48,"button",52),x(49,me,1,0,"div",53),a(50),r()()()()()}if(o&2){let e=d();s(4),E(" ",e.editingArticle()?"Modifier l'article":"Nouvel article"," "),s(8),w("ngModel",e.form.nomGeneral),s(8),w("ngModel",e.form.nomReel),s(7),w("ngModel",e.form.acronyme),s(5),w("ngModel",e.form.missionGeneral),s(16),_("disabled",e.saving()),s(),v(e.saving()?49:-1),s(),E(" ",e.editingArticle()?"Mettre \xE0 jour":"Cr\xE9er"," ")}}function pe(o,t){o&1&&(h(),i(0,"svg",57),g(1,"path",58),r())}function ge(o,t){o&1&&(h(),i(0,"svg",57),g(1,"path",59),r())}function fe(o,t){o&1&&(h(),i(0,"svg",57),g(1,"path",60),r())}function _e(o,t){if(o&1&&(i(0,"div",13)(1,"div",54),A(2,pe,2,0,"svg",55)(3,ge,2,0,"svg",55)(4,fe,2,0,"svg",55),i(5,"span",56),a(6),r()()()),o&2){let e=d();s(),_("ngClass",R(5,re,e.notification().type==="success",e.notification().type==="error",e.notification().type==="info")),s(),_("ngIf",e.notification().type==="success"),s(),_("ngIf",e.notification().type==="error"),s(),_("ngIf",e.notification().type==="info"),s(2),C(e.notification().message)}}function he(o,t){if(o&1){let e=b();i(0,"div",14)(1,"div",61)(2,"h3",62),a(3,"Confirmation"),r(),i(4,"p",63),a(5),r(),i(6,"div",64)(7,"button",65),p("click",function(){m(e);let n=d();return u(n.closeConfirmModal())}),a(8," Annuler "),r(),i(9,"button",66),p("click",function(){m(e);let n=d();return u(n.confirmModal().onConfirm())}),a(10," Supprimer "),r()()()()}if(o&2){let e=d();s(5),C(e.confirmModal().message)}}var te=class o{constructor(t,e){this.apiService=t;this.router=e}notification=f({show:!1,message:"",type:"success"});articles=f([]);loading=f(!0);showModal=f(!1);editingArticle=f(null);saving=f(!1);selectedImage=null;selectedImage1=null;fileError=!1;fileError1=!1;currentPage=f(1);pageSize=7;totalPages=f(1);form={nomGeneral:"",nomReel:"",acronyme:"",missionGeneral:"",presentationSynthetique:"",presentationGlobale:""};ngOnInit(){this.loadArticles()}loadArticles(t=0){this.loading.set(!0),this.apiService.getAllMins(t,this.pageSize).subscribe({next:e=>{e.success&&(this.articles.set(e.data.content),this.totalPages.set(e.data.totalPages),this.currentPage.set(t+1)),this.loading.set(!1)},error:()=>{this.loading.set(!1)}})}nextPage(){this.currentPage()<this.totalPages()&&this.loadArticles(this.currentPage())}prevPage(){this.currentPage()>1&&this.loadArticles(this.currentPage()-2)}goToPage(t){this.loadArticles(t-1)}pages(){return Array.from({length:this.totalPages()},(t,e)=>e+1)}openModal(){this.form={nomGeneral:"",nomReel:"",acronyme:"",missionGeneral:"",presentationGlobale:"",presentationSynthetique:""},this.selectedImage=null,this.selectedImage1=null,this.fileError=!1,this.fileError1=!1,this.editingArticle.set(null),this.showModal.set(!0)}closeModal(t){this.showModal.set(!1),this.editingArticle.set(null),this.selectedImage=null,this.selectedImage1=null,this.fileError=!1,this.fileError1=!1,t?.resetForm()}onFileSelected(t){let e=t.target;if(!e.files||e.files.length===0){this.selectedImage=null;return}let l=e.files[0];if(!l.type.startsWith("image/")){alert("Pour une actualit\xE9, veuillez s\xE9lectionner une image"),e.value="",this.selectedImage=null;return}this.selectedImage=l,this.fileError=!1}onFileSelected1(t){let e=t.target;if(!e.files||e.files.length===0){this.selectedImage1=null;return}let l=e.files[0];if(!l.type.startsWith("image/")){alert("Pour une actualit\xE9, veuillez s\xE9lectionner une image"),e.value="",this.selectedImage1=null;return}this.selectedImage1=l,this.fileError1=!1}viewArticle(t){this.router.navigate(["/admin/ministere",t.id])}editArticle(t){this.form={nomGeneral:t.nomGeneral,nomReel:t.nomReel,acronyme:t.acronyme,missionGeneral:t.missionGeneral,presentationGlobale:t.presentationGlobale,presentationSynthetique:t.presentationSynthetique},this.editingArticle.set(t),this.showModal.set(!0)}saveArticle(t){if(!this.form.nomGeneral||!this.form.nomReel)return;this.saving.set(!0);let e=this.editingArticle(),l={nomGeneral:this.form.nomGeneral,nomReel:this.form.nomReel,acronyme:this.form.acronyme,missionGeneral:this.form.missionGeneral,presentationGlobale:this.form.presentationGlobale,presentationSynthetique:this.form.presentationSynthetique},n=new FormData;n.append("ministere",new Blob([JSON.stringify(l)],{type:"application/json"})),n.append("authorId","1"),this.selectedImage&&n.append("logo",this.selectedImage),this.selectedImage1&&n.append("image",this.selectedImage1),(e?this.apiService.updatemin(e.id,n):this.apiService.createmin(n)).subscribe({next:I=>{this.loadArticles(),this.closeModal(t),this.saving.set(!1),this.showNotification(e?"Minist\xE8re mis \xE0 jour avec succ\xE8s":"Minist\xE8re cr\xE9\xE9 avec succ\xE8s","success")},error:I=>{console.error("Erreur lors de la sauvegarde",I),this.saving.set(!1),this.showNotification("Erreur lors de la sauvegarde","error")}})}deleteArticle1(t){confirm(`Supprimer l'article "${t.nomGeneral}" ?`)&&this.apiService.deleteArticle(t.id).subscribe({next:()=>this.loadArticles()})}trackByArticleId(t,e){return e.id}showNotification(t,e="success",l=2e3){this.notification.set({show:!0,message:t,type:e}),setTimeout(()=>this.notification.update(n=>V(k({},n),{show:!1})),l)}confirmModal=f({show:!1,message:"",onConfirm:()=>{}});openConfirmModal(t,e){this.confirmModal.set({show:!0,message:t,onConfirm:e})}closeConfirmModal(){this.confirmModal.update(t=>V(k({},t),{show:!1}))}deleteArticle(t){this.openConfirmModal(`Voulez-vous vraiment supprimer l'article "${t.nomGeneral}" ?`,()=>{this.apiService.deleteMin(t.id).subscribe({next:()=>{this.loadArticles(),this.closeConfirmModal(),this.showNotification("Article supprim\xE9 avec succ\xE8s","success")},error:()=>{this.showNotification("Erreur lors de la suppression","error"),this.closeConfirmModal()}})})}static \u0275fac=function(e){return new(e||o)(G(ee),G(H))};static \u0275cmp=N({type:o,selectors:[["app-ministere"]],decls:18,vars:4,consts:[["articleForm","ngForm"],["title","ngModel"],[1,"space-y-6"],[1,"flex","flex-col","sm:flex-row","sm:items-center","sm:justify-between","gap-4"],[1,"text-2xl","font-bold","text-neutral-900"],[1,"text-neutral-500"],[1,"btn-primary",2,"background-color","#00843B",3,"click"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-5","h-5","mr-2"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M12 6v6m0 0v6m0-6h6m-6 0H6"],[1,"card","p-0"],[1,"p-8","text-center"],[1,"table-container"],[1,"fixed","inset-0","bg-black/50","flex","items-center","justify-center","z-50","p-4"],[1,"fixed","top-4","right-4","z-50","pointer-events-none"],[1,"fixed","inset-0","bg-black/30","flex","items-center","justify-center","z-50","p-4"],[1,"spinner","w-8","h-8","mx-auto"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-12","h-12","text-neutral-300","mx-auto","mb-4"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z"],[1,"table"],[1,"text-right"],[1,"flex","justify-end","items-center","mt-2","px-6","py-2","gap-2","border-t","border-gray-200","bg-gray-50","rounded-b-lg"],[1,"px-3","py-1","border","border-gray-300","rounded","hover:bg-gray-100","disabled:opacity-50","transition-colors",3,"click","disabled"],[4,"ngFor","ngForOf"],[1,"max-w-xs"],[1,"font-medium","text-neutral-900","truncate"],[1,"px-6","py-4","text-right"],[1,"flex","justify-end","gap-2"],["title","Voir l'article",1,"flex","items-center","justify-center","p-2","border-2","border-blue-500","rounded-full","bg-white","hover:bg-blue-50","transition-colors",3,"click"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-4","h-4","text-blue-500"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M15 12a3 3 0 11-6 0 3 3 0 016 0z"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M2.458 12C3.732 7.943 7.523 5 12 5c4.477 0 8.268 2.943 9.542 7-1.274 4.057-5.065 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"],["title","Modifier",1,"flex","items-center","justify-center","p-2","border-2","border-green-500","rounded-full","bg-white","hover:bg-green-50","transition-colors",3,"click"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-4","h-4","text-green-500"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"],["title","Supprimer",1,"flex","items-center","justify-center","p-2","border-2","border-red-500","rounded-full","bg-white","hover:bg-red-50","transition-colors",3,"click"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-4","h-4","text-red-500"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"],[3,"click","ngClass","ngStyle"],[1,"bg-white","rounded-2xl","shadow-xl","w-full","max-w-2xl","max-h-[90vh]","overflow-y-auto"],[1,"p-6","border-b","border-neutral-200"],[1,"text-xl","font-semibold","text-neutral-900"],["novalidate","",1,"p-6","space-y-5",3,"ngSubmit"],[1,"label"],[1,"text-red-500"],["type","text","name","nomGeneral","required","",1,"input",3,"ngModelChange","ngModel"],[1,"grid","grid-cols-1","md:grid-cols-2","gap-6"],["type","text","name","nomReel","required","",1,"input",3,"ngModelChange","ngModel"],["type","text","name","acronyme","required","",1,"input",3,"ngModelChange","ngModel"],["name","missionGeneral","rows","2",1,"input","resize-none",3,"ngModelChange","ngModel"],["type","file","accept","image/*",1,"input",3,"change"],[1,"flex","justify-end","gap-3","pt-4","border-t","border-neutral-200"],["type","button",1,"px-4","py-2","rounded-lg","border","border-red-500","text-red-500","hover:bg-red-50","transition-colors","font-medium",3,"click"],["type","submit",1,"px-4","py-2","rounded-lg","bg-[#00843B]","text-white","hover:bg-[#006830]","transition-colors","font-medium","flex","items-center","justify-center","gap-2",3,"disabled"],[1,"spinner","w-4","h-4","mr-2"],[1,"pointer-events-auto","border-l-4","rounded-lg","shadow-lg","p-6","max-w-sm","w-full","flex","items-center","gap-4","animate-fade-in",3,"ngClass"],["class","w-6 h-6 flex-shrink-0","fill","none","stroke","currentColor","viewBox","0 0 24 24",4,"ngIf"],[1,"text-sm","font-medium"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"w-6","h-6","flex-shrink-0"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M5 13l4 4L19 7"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M6 18L18 6M6 6l12 12"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","2","d","M13 16h-1v-4h-1m1-4h.01M12 20a8 8 0 100-16 8 8 0 000 16z"],[1,"bg-white","rounded-2xl","shadow-xl","w-full","max-w-md","p-6","space-y-4"],[1,"text-lg","font-semibold","text-neutral-900"],[1,"text-neutral-700"],[1,"flex","justify-end","gap-3","mt-4"],[1,"px-4","py-2","rounded-lg","border","border-gray-300","text-gray-700","hover:bg-gray-100","transition-colors","font-medium",3,"click"],[1,"px-4","py-2","rounded-lg","bg-red-600","text-white","hover:bg-red-700","transition-colors","font-medium",3,"click"]],template:function(e,l){e&1&&(i(0,"div",2)(1,"div",3)(2,"div")(3,"h1",4),a(4,"Minist\xE8re"),r(),i(5,"p",5),a(6,"G\xE9rez les minist\xE8res"),r()(),i(7,"button",6),p("click",function(){return l.openModal()}),h(),i(8,"svg",7),g(9,"path",8),r(),a(10," Nouvel minist\xE8re "),r()(),M(),i(11,"div",9),x(12,le,2,0,"div",10)(13,ae,5,0,"div",10)(14,de,21,3,"div",11),r(),x(15,ue,51,8,"div",12),r(),x(16,_e,7,9,"div",13),x(17,he,11,1,"div",14)),e&2&&(s(12),v(l.loading()?12:l.articles().length===0?13:14),s(3),v(l.showModal()?15:-1),s(),v(l.notification().show?16:-1),s(),v(l.confirmModal().show?17:-1))},dependencies:[q,D,z,L,W,Z,X,J,$,K,Y,U,Q,O],encapsulation:2})};export{te as MinistereComponent};
|