3 lines
12 KiB
JavaScript
3 lines
12 KiB
JavaScript
import{e as N,f as O,g as E,c as r,a as e,t as s,i as t,F as B,y as v,z as k,d as w,r as q,j as S,k as U,l as _,J,h as Q,o as d,m as T}from"./BMplCfh_.js";import{_ as X}from"./DlAUqK2U.js";const G={class:"mb-8"},K={class:"text-2xl font-bold text-white"},W={class:"text-slate-400 mt-1"},Y={key:0,class:"flex items-center justify-center py-20"},Z={class:"text-slate-400 flex items-center gap-3"},ee={key:1,class:"bg-rose-500/10 border border-rose-500/30 rounded-xl p-6 mb-8"},te={class:"text-rose-400"},se={class:"bg-slate-800 rounded-xl border border-slate-700 p-6 mb-6"},oe={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-4"},ae={class:"block text-xs font-medium text-slate-400 uppercase tracking-wider mb-1.5"},ie=["placeholder"],le={class:"block text-xs font-medium text-slate-400 uppercase tracking-wider mb-1.5"},ne={class:"block text-xs font-medium text-slate-400 uppercase tracking-wider mb-1.5"},re={class:"block text-xs font-medium text-slate-400 uppercase tracking-wider mb-1.5"},de=["placeholder"],ce={class:"flex items-end gap-2"},ue=["title"],me={key:0,class:"bg-slate-800 rounded-xl border border-slate-700 p-12 text-center"},pe={class:"text-slate-400 text-sm"},xe={class:"text-slate-500 text-xs mt-1"},_e={key:1,class:"bg-slate-800 rounded-xl border border-slate-700 overflow-hidden"},ge={class:"overflow-x-auto"},fe={class:"w-full"},he={class:"border-b border-slate-700"},be={class:"text-left px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider"},ve={class:"text-left px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider"},ke={class:"text-right px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider"},we={class:"text-right px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider"},ye={class:"text-right px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider"},Ce={class:"text-left px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider"},je={class:"text-left px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider"},Se={class:"text-left px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider"},Ue={class:"divide-y divide-slate-700/50"},Ve={class:"px-4 py-3 text-sm text-slate-400 font-mono"},Me={class:"px-4 py-3"},Be={class:"flex items-center gap-2"},Te={class:"text-sm text-slate-300"},De={class:"text-xs text-slate-500 font-mono"},ze={class:"px-4 py-3 text-right"},Ie={class:"px-4 py-3 text-right"},Le={key:0,class:"text-sm font-semibold text-rose-400"},Pe={key:1,class:"text-sm text-slate-500"},He={class:"px-4 py-3 text-right"},Re={key:0,class:"text-sm text-cyan-400 font-mono"},$e={key:1,class:"text-sm text-slate-500"},Ae={class:"px-4 py-3 max-w-xs"},Fe=["title"],Ne={class:"px-4 py-3"},Oe={key:0,class:"flex items-center gap-1.5"},Ee={class:"inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-slate-700 text-slate-300"},qe={key:0,class:"text-xs text-slate-500 font-mono"},Je={key:1,class:"text-sm text-slate-500"},Qe={class:"px-4 py-3 text-sm text-slate-400 whitespace-nowrap"},Xe={class:"flex items-center justify-between px-4 py-3 border-t border-slate-700"},Ge={class:"text-sm text-slate-400"},Ke={key:0,class:"text-slate-500"},We={class:"flex items-center gap-2"},Ye=["disabled"],Ze={class:"text-sm text-slate-400 px-2"},et=["disabled"],tt={key:3,class:"fixed bottom-6 right-6 z-50 bg-emerald-600 text-white px-4 py-3 rounded-lg shadow-lg text-sm flex items-center gap-2 animate-slide-up"},st=N({__name:"ledger",setup(ot){const{t:o}=O(),y=_(!0),C=_(!1),g=_([]),p=_(0),c=_(0),m=_(50),h=_(""),l=J({user_id:null,date_from:"",date_to:"",reason_search:""});let j=null;function D(){const i=Q("access_token").value;return i?{Authorization:`Bearer ${i}`,"Content-Type":"application/json"}:{"Content-Type":"application/json"}}function V(n){h.value=n,setTimeout(()=>{h.value=""},3e3)}function b(){j&&clearTimeout(j),j=setTimeout(()=>{c.value=0,x()},400)}function z(){l.user_id=null,l.date_from="",l.date_to="",l.reason_search="",c.value=0,x()}const I=T(()=>Math.floor(c.value/m.value)+1),L=T(()=>Math.max(1,Math.ceil(p.value/m.value)));function P(){c.value>0&&(c.value=Math.max(0,c.value-m.value),x())}function H(){c.value+m.value<p.value&&(c.value+=m.value,x())}function R(n){return n?new Date(n).toLocaleDateString("hu-HU",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"—"}function $(){const n=new URLSearchParams;return n.set("limit",String(m.value)),n.set("offset",String(c.value)),l.user_id&&n.set("user_id",String(l.user_id)),l.date_from&&n.set("date_from",l.date_from),l.date_to&&n.set("date_to",l.date_to),l.reason_search&&n.set("reason_search",l.reason_search),n.toString()}async function x(){y.value=!0,C.value=!1;try{const n=$(),i=await $fetch(`/api/v1/admin/gamification/points-ledger?${n}`,{headers:D()});g.value=i,i.length<m.value?p.value=c.value+i.length:p.value=c.value+m.value+1}catch(n){console.error("Failed to fetch points ledger:",n),C.value=!0}finally{y.value=!1}}function A(){if(g.value.length===0){V(o("gamification.ledger.csv_no_data"));return}const n=["ID","User ID","User Name","Points","Penalty Change","XP","Reason","Source Type","Source ID","Created At"],i=g.value.map(u=>[u.id,u.user_id,`"${(u.user_name||"").replace(/"/g,'""')}"`,u.points,u.penalty_change||0,u.xp||0,`"${(u.reason||"").replace(/"/g,'""')}"`,u.source_type||"",u.source_id||"",u.created_at||""]),a=[n.join(","),...i.map(u=>u.join(","))].join(`
|
|
`),F=new Blob([a],{type:"text/csv;charset=utf-8;"}),M=URL.createObjectURL(F),f=document.createElement("a");f.setAttribute("href",M),f.setAttribute("download",`points_ledger_${new Date().toISOString().slice(0,10)}.csv`),document.body.appendChild(f),f.click(),document.body.removeChild(f),URL.revokeObjectURL(M),V(o("gamification.ledger.csv_started"))}return E(()=>{x()}),(n,i)=>(d(),r("div",null,[e("div",G,[e("h1",K,s(t(o)("gamification.ledger.title")),1),e("p",W,s(t(o)("gamification.ledger.subtitle")),1)]),t(y)?(d(),r("div",Y,[e("div",Z,[i[4]||(i[4]=e("svg",{class:"w-5 h-5 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})],-1)),e("span",null,s(t(o)("gamification.ledger.loading")),1)])])):t(C)?(d(),r("div",ee,[e("p",te,s(t(o)("gamification.ledger.load_error")),1),e("button",{onClick:x,class:"mt-3 text-sm text-rose-300 hover:text-rose-200 underline"},s(t(o)("gamification.ledger.retry")),1)])):(d(),r(B,{key:2},[e("div",se,[e("div",oe,[e("div",null,[e("label",ae,s(t(o)("gamification.ledger.filter_user_id")),1),v(e("input",{"onUpdate:modelValue":i[0]||(i[0]=a=>t(l).user_id=a),type:"number",min:"1",placeholder:t(o)("gamification.ledger.user_id_placeholder"),class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-amber-500/50 focus:border-amber-500 text-sm",onInput:b},null,40,ie),[[k,t(l).user_id,void 0,{number:!0}]])]),e("div",null,[e("label",le,s(t(o)("gamification.ledger.filter_date_from")),1),v(e("input",{"onUpdate:modelValue":i[1]||(i[1]=a=>t(l).date_from=a),type:"date",class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-amber-500/50 focus:border-amber-500 text-sm",onChange:b},null,544),[[k,t(l).date_from]])]),e("div",null,[e("label",ne,s(t(o)("gamification.ledger.filter_date_to")),1),v(e("input",{"onUpdate:modelValue":i[2]||(i[2]=a=>t(l).date_to=a),type:"date",class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-amber-500/50 focus:border-amber-500 text-sm",onChange:b},null,544),[[k,t(l).date_to]])]),e("div",null,[e("label",re,s(t(o)("gamification.ledger.filter_reason")),1),v(e("input",{"onUpdate:modelValue":i[3]||(i[3]=a=>t(l).reason_search=a),type:"text",placeholder:t(o)("gamification.ledger.reason_placeholder"),class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-amber-500/50 focus:border-amber-500 text-sm",onInput:b},null,40,de),[[k,t(l).reason_search]])]),e("div",ce,[e("button",{onClick:x,class:"px-4 py-2 bg-amber-600 hover:bg-amber-500 text-white rounded-lg text-sm font-medium transition flex items-center gap-2"},[i[5]||(i[5]=e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1)),w(" "+s(t(o)("gamification.ledger.search")),1)]),e("button",{onClick:z,class:"px-4 py-2 bg-slate-700 hover:bg-slate-600 text-slate-300 rounded-lg text-sm font-medium transition"},s(t(o)("gamification.ledger.clear")),1),e("button",{onClick:A,class:"px-4 py-2 bg-emerald-600 hover:bg-emerald-500 text-white rounded-lg text-sm font-medium transition flex items-center gap-2 ml-auto",title:t(o)("gamification.ledger.csv_download")},[i[6]||(i[6]=e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1)),w(" "+s(t(o)("gamification.ledger.csv")),1)],8,ue)])])]),t(g).length===0?(d(),r("div",me,[i[7]||(i[7]=e("svg",{class:"w-12 h-12 mx-auto text-slate-600 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1)),e("p",pe,s(t(o)("gamification.ledger.no_results")),1),e("p",xe,s(t(o)("gamification.ledger.no_results_hint")),1)])):(d(),r("div",_e,[e("div",ge,[e("table",fe,[e("thead",null,[e("tr",he,[e("th",be,s(t(o)("gamification.ledger.col_id")),1),e("th",ve,s(t(o)("gamification.ledger.col_user")),1),e("th",ke,s(t(o)("gamification.ledger.col_points")),1),e("th",we,s(t(o)("gamification.ledger.col_penalty")),1),e("th",ye,s(t(o)("gamification.ledger.col_xp")),1),e("th",Ce,s(t(o)("gamification.ledger.col_reason")),1),e("th",je,s(t(o)("gamification.ledger.col_source")),1),e("th",Se,s(t(o)("gamification.ledger.col_date")),1)])]),e("tbody",Ue,[(d(!0),r(B,null,q(t(g),a=>(d(),r("tr",{key:a.id,class:"hover:bg-slate-700/30 transition"},[e("td",Ve,s(a.id),1),e("td",Me,[e("div",Be,[e("span",Te,s(a.user_name),1),e("span",De,"#"+s(a.user_id),1)])]),e("td",ze,[e("span",{class:U(["text-sm font-semibold",a.points>0?"text-emerald-400":a.points<0?"text-rose-400":"text-slate-400"])},s(a.points>0?"+":"")+s(a.points),3)]),e("td",Ie,[a.penalty_change?(d(),r("span",Le," +"+s(a.penalty_change),1)):(d(),r("span",Pe,"—"))]),e("td",He,[a.xp?(d(),r("span",Re,s(a.xp),1)):(d(),r("span",$e,"—"))]),e("td",Ae,[e("p",{class:"text-sm text-slate-300 truncate",title:a.reason},s(a.reason),9,Fe)]),e("td",Ne,[a.source_type?(d(),r("div",Oe,[e("span",Ee,s(a.source_type),1),a.source_id?(d(),r("span",qe,"#"+s(a.source_id),1)):S("",!0)])):(d(),r("span",Je,"—"))]),e("td",Qe,s(R(a.created_at)),1)]))),128))])])]),e("div",Xe,[e("p",Ge,[w(s(t(p))+" "+s(t(o)("gamification.ledger.total_results"))+" "+s(t(g).length)+" "+s(t(o)("gamification.ledger.shown"))+" ",1),t(l).user_id||t(l).date_from||t(l).date_to||t(l).reason_search?(d(),r("span",Ke," ("+s(t(o)("gamification.ledger.filtered"))+") ",1)):S("",!0)]),e("div",We,[e("button",{onClick:P,disabled:t(c)===0,class:U(["px-3 py-1.5 rounded-lg text-sm font-medium transition disabled:opacity-30 disabled:cursor-not-allowed",t(c)===0?"text-slate-600":"text-slate-300 hover:bg-slate-700 hover:text-white"])},s(t(o)("gamification.ledger.prev")),11,Ye),e("span",Ze,s(t(I))+" / "+s(t(L)),1),e("button",{onClick:H,disabled:t(c)+t(m)>=t(p),class:U(["px-3 py-1.5 rounded-lg text-sm font-medium transition disabled:opacity-30 disabled:cursor-not-allowed",t(c)+t(m)>=t(p)?"text-slate-600":"text-slate-300 hover:bg-slate-700 hover:text-white"])},s(t(o)("gamification.ledger.next")),11,et)])])]))],64)),t(h)?(d(),r("div",tt,[i[8]||(i[8]=e("svg",{class:"w-4 h-4 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),w(" "+s(t(h)),1)])):S("",!0)]))}}),lt=X(st,[["__scopeId","data-v-46ba4a43"]]);export{lt as default};
|