2 lines
8.2 KiB
JavaScript
2 lines
8.2 KiB
JavaScript
import{a as H}from"./chunk-YYB674MU.js";import{d as k,g as O,k as L,l as $,n as B,t as F}from"./chunk-UDFQV3WY.js";import"./chunk-MBEC6LK4.js";import{Eb as l,Fa as r,Fb as c,Gb as C,Jb as w,Kb as M,Lb as T,M as y,R as _,S as g,T as E,Ta as S,Tb as v,U as I,Xb as h,Ya as u,ca as x,jb as s,kb as i,lb as o,mb as A,pc as D,qb as f,qc as N,rb as b,rc as P,sb as m,vc as V,xc as R}from"./chunk-TVKQFRWX.js";import"./chunk-DAQOROHW.js";function G(t,n){if(t&1&&(i(0,"div",15),l(1),o()),t&2){let e=m();r(),c(e.notice())}}function j(t,n){if(t&1&&(i(0,"div",16),l(1),o()),t&2){let e=m();r(),c(e.error())}}function W(t,n){t&1&&(i(0,"div",17),l(1,"Chargement\u2026"),o())}function z(t,n){t&1&&(i(0,"div",18),E(),i(1,"svg",19),A(2,"path",20),o(),I(),i(3,"p",21),l(4,"Aucun commentaire dans cette cat\xE9gorie."),o()())}function q(t,n){if(t&1&&(i(0,"span"),l(1),o()),t&2){let e=m().$implicit;r(),C(" \xB7 ",e.authorEmail)}}function K(t,n){if(t&1&&(i(0,"span"),l(1),v(2,"date"),o()),t&2){let e=m(2).$implicit;r(),C(" le ",h(2,1,e.moderatedAt,"d MMMM y \xE0 HH:mm","","fr"))}}function Q(t,n){if(t&1&&(i(0,"p",39),l(1),u(2,K,3,6,"span",32),o()),t&2){let e=m().$implicit;r(),C("Trait\xE9 par ",e.moderatedBy),r(),s("ngIf",e.moderatedAt)}}function U(t,n){if(t&1){let e=f();i(0,"button",40),b("click",function(){_(e);let p=m().$implicit,d=m(2);return g(d.moderate(p,"APPROVED"))}),l(1,"Approuver"),o()}if(t&2){let e=m().$implicit,a=m(2);s("disabled",a.busyId()===e.id)}}function X(t,n){if(t&1){let e=f();i(0,"button",41),b("click",function(){_(e);let p=m().$implicit,d=m(2);return g(d.moderate(p,"REJECTED"))}),l(1,"Refuser"),o()}if(t&2){let e=m().$implicit,a=m(2);s("disabled",a.busyId()===e.id)}}function Y(t,n){if(t&1){let e=f();i(0,"article",24)(1,"div",25)(2,"div")(3,"div",26)(4,"span",27),l(5),o(),i(6,"time",28),l(7),v(8,"date"),o()(),i(9,"h2",29),l(10),o(),i(11,"p",30),l(12,"Par "),i(13,"strong",31),l(14),o(),u(15,q,2,1,"span",32),o()()(),i(16,"p",33),l(17),o(),u(18,Q,3,2,"p",34),i(19,"div",35),u(20,U,2,1,"button",36)(21,X,2,1,"button",37),i(22,"button",38),b("click",function(){let p=_(e).$implicit,d=m(2);return g(d.deleteComment(p))}),l(23,"Supprimer"),o()()()}if(t&2){let e=n.$implicit,a=m(2);r(4),s("ngClass",a.statusClass(e.status)),r(),c(a.statusLabel(e.status)),r(2),c(h(8,11,e.createdAt,"d MMMM y \xE0 HH:mm","","fr")),r(3),c(e.articleTitle),r(4),c(e.authorName),r(),s("ngIf",e.authorEmail),r(2),c(e.content),r(),s("ngIf",e.moderatedBy),r(2),s("ngIf",e.status!=="APPROVED"),r(),s("ngIf",e.status!=="REJECTED"),r(),s("disabled",a.busyId()===e.id)}}function Z(t,n){if(t&1&&(i(0,"div",22),u(1,Y,24,16,"article",23),o()),t&2){let e=m();r(),s("ngForOf",e.comments())}}var J=class t{service=y(H);comments=x([]);loading=x(!1);busyId=x(null);notice=x("");error=x("");selectedStatus="PENDING";ngOnInit(){this.loadComments()}loadComments(){this.loading.set(!0),this.error.set(""),this.service.getAdminComments(this.selectedStatus||void 0).subscribe({next:n=>{this.comments.set(n),this.loading.set(!1)},error:()=>{this.error.set("Impossible de charger les commentaires."),this.loading.set(!1)}})}moderate(n,e){this.busyId.set(n.id),this.notice.set(""),this.error.set(""),this.service.moderateComment(n.id,e).subscribe({next:()=>{this.notice.set(e==="APPROVED"?"Le commentaire est maintenant publi\xE9.":"Le commentaire a \xE9t\xE9 refus\xE9."),this.busyId.set(null),this.loadComments()},error:()=>{this.error.set("La modification du commentaire a \xE9chou\xE9."),this.busyId.set(null)}})}deleteComment(n){confirm(`Supprimer d\xE9finitivement le commentaire de ${n.authorName} ?`)&&(this.busyId.set(n.id),this.notice.set(""),this.error.set(""),this.service.deleteComment(n.id).subscribe({next:()=>{this.comments.update(e=>e.filter(a=>a.id!==n.id)),this.notice.set("Le commentaire a \xE9t\xE9 supprim\xE9."),this.busyId.set(null)},error:()=>{this.error.set("La suppression du commentaire a \xE9chou\xE9."),this.busyId.set(null)}}))}statusLabel(n){return{PENDING:"En attente",APPROVED:"Approuv\xE9",REJECTED:"Refus\xE9"}[n]}statusClass(n){return{PENDING:"bg-amber-100 text-amber-900",APPROVED:"bg-emerald-100 text-emerald-800",REJECTED:"bg-red-100 text-red-800"}[n]}static \u0275fac=function(e){return new(e||t)};static \u0275cmp=S({type:t,selectors:[["app-article-comments"]],decls:23,vars:6,consts:[[1,"mx-auto","max-w-6xl"],[1,"flex","flex-col","gap-4","sm:flex-row","sm:items-end","sm:justify-between"],[1,"text-2xl","font-bold","text-slate-900"],[1,"mt-1","text-slate-600"],[1,"text-sm","font-semibold","text-slate-700"],[1,"ml-2","rounded-lg","border","border-slate-300","bg-white","px-3","py-2","font-normal","outline-none","focus:border-primary-600",3,"ngModelChange","ngModel"],["value",""],["value","PENDING"],["value","APPROVED"],["value","REJECTED"],["class","mt-5 rounded-xl bg-emerald-50 px-4 py-3 text-sm text-emerald-800",4,"ngIf"],["class","mt-5 rounded-xl bg-red-50 px-4 py-3 text-sm text-red-700",4,"ngIf"],["class","mt-6 rounded-2xl border border-slate-200 bg-white p-8 text-center text-slate-500",4,"ngIf"],["class","mt-6 rounded-2xl border border-slate-200 bg-white p-10 text-center",4,"ngIf"],["class","mt-6 space-y-4",4,"ngIf"],[1,"mt-5","rounded-xl","bg-emerald-50","px-4","py-3","text-sm","text-emerald-800"],[1,"mt-5","rounded-xl","bg-red-50","px-4","py-3","text-sm","text-red-700"],[1,"mt-6","rounded-2xl","border","border-slate-200","bg-white","p-8","text-center","text-slate-500"],[1,"mt-6","rounded-2xl","border","border-slate-200","bg-white","p-10","text-center"],["fill","none","stroke","currentColor","viewBox","0 0 24 24",1,"mx-auto","h-10","w-10","text-slate-300"],["stroke-linecap","round","stroke-linejoin","round","stroke-width","1.5","d","M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 4v-4z"],[1,"mt-3","text-slate-600"],[1,"mt-6","space-y-4"],["class","rounded-2xl border border-slate-200 bg-white p-5 shadow-sm sm:p-6",4,"ngFor","ngForOf"],[1,"rounded-2xl","border","border-slate-200","bg-white","p-5","shadow-sm","sm:p-6"],[1,"flex","flex-col","gap-3","sm:flex-row","sm:items-start","sm:justify-between"],[1,"flex","flex-wrap","items-center","gap-2"],[1,"rounded-full","px-3","py-1","text-xs","font-bold",3,"ngClass"],[1,"text-xs","text-slate-500"],[1,"mt-3","font-bold","text-primary-950"],[1,"mt-1","text-sm","text-slate-500"],[1,"text-slate-700"],[4,"ngIf"],[1,"mt-4","whitespace-pre-line","rounded-xl","bg-slate-50","p-4","leading-7","text-slate-700"],["class","mt-3 text-xs text-slate-500",4,"ngIf"],[1,"mt-5","flex","flex-wrap","gap-2"],["type","button","class","rounded-lg bg-emerald-600 px-4 py-2 text-sm font-bold text-white hover:bg-emerald-700 disabled:opacity-50",3,"disabled","click",4,"ngIf"],["type","button","class","rounded-lg bg-amber-100 px-4 py-2 text-sm font-bold text-amber-900 hover:bg-amber-200 disabled:opacity-50",3,"disabled","click",4,"ngIf"],["type","button",1,"rounded-lg","border","border-red-200","px-4","py-2","text-sm","font-bold","text-red-700","hover:bg-red-50","disabled:opacity-50",3,"click","disabled"],[1,"mt-3","text-xs","text-slate-500"],["type","button",1,"rounded-lg","bg-emerald-600","px-4","py-2","text-sm","font-bold","text-white","hover:bg-emerald-700","disabled:opacity-50",3,"click","disabled"],["type","button",1,"rounded-lg","bg-amber-100","px-4","py-2","text-sm","font-bold","text-amber-900","hover:bg-amber-200","disabled:opacity-50",3,"click","disabled"]],template:function(e,a){e&1&&(i(0,"div",0)(1,"div",1)(2,"div")(3,"h1",2),l(4,"Commentaires des actualit\xE9s"),o(),i(5,"p",3),l(6,"Validez les commentaires avant leur publication sur le site."),o()(),i(7,"label",4),l(8," Afficher "),i(9,"select",5),T("ngModelChange",function(d){return M(a.selectedStatus,d)||(a.selectedStatus=d),d}),b("ngModelChange",function(){return a.loadComments()}),i(10,"option",6),l(11,"Tous les commentaires"),o(),i(12,"option",7),l(13,"En attente"),o(),i(14,"option",8),l(15,"Approuv\xE9s"),o(),i(16,"option",9),l(17,"Refus\xE9s"),o()()()(),u(18,G,2,1,"div",10)(19,j,2,1,"div",11)(20,W,2,0,"div",12)(21,z,5,0,"div",13)(22,Z,2,1,"div",14),o()),e&2&&(r(9),w("ngModel",a.selectedStatus),r(9),s("ngIf",a.notice()),r(),s("ngIf",a.error()),r(),s("ngIf",a.loading()),r(),s("ngIf",!a.loading()&&a.comments().length===0),r(),s("ngIf",!a.loading()&&a.comments().length))},dependencies:[R,D,N,P,F,$,B,L,k,O,V],encapsulation:2})};export{J as ArticleCommentsComponent};
|