diff --git a/app/assets/composables/sprunjer.ts b/app/assets/composables/sprunjer.ts index 974eb1fe..de13fa69 100644 --- a/app/assets/composables/sprunjer.ts +++ b/app/assets/composables/sprunjer.ts @@ -6,7 +6,7 @@ interface AssociativeArray { } interface Sprunjer { - dataUrl: string + dataUrl: Ref size: Ref page: Ref totalPages: ComputedRef @@ -25,13 +25,14 @@ interface Sprunjer { } const useSprunjer = ( - dataUrl: string, + defaultDataUrl: string, defaultSorts: AssociativeArray = {}, defaultFilters: AssociativeArray = {}, defaultSize: number = 10, defaultPage: number = 0 ) => { // Sprunje parameters + const dataUrl = ref(defaultDataUrl) const size = ref(defaultSize) const page = ref(defaultPage) const sorts = ref(defaultSorts) diff --git a/dist/composables/sprunjer.d.ts b/dist/composables/sprunjer.d.ts index 9c76a043..c826ccfe 100644 --- a/dist/composables/sprunjer.d.ts +++ b/dist/composables/sprunjer.d.ts @@ -3,7 +3,7 @@ interface AssociativeArray { [key: string]: string | null; } interface Sprunjer { - dataUrl: string; + dataUrl: Ref; size: Ref; page: Ref; totalPages: ComputedRef; @@ -20,8 +20,8 @@ interface Sprunjer { toggleSort: (column: string) => void; downloadCsv: () => void; } -declare const useSprunjer: (dataUrl: string, defaultSorts?: AssociativeArray, defaultFilters?: AssociativeArray, defaultSize?: number, defaultPage?: number) => { - dataUrl: string; +declare const useSprunjer: (defaultDataUrl: string, defaultSorts?: AssociativeArray, defaultFilters?: AssociativeArray, defaultSize?: number, defaultPage?: number) => { + dataUrl: Ref; size: Ref; page: Ref; sorts: Ref; diff --git a/dist/sprunjer.cjs b/dist/sprunjer.cjs index bf50e012..ef67f84a 100644 --- a/dist/sprunjer.cjs +++ b/dist/sprunjer.cjs @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),x=require("./axios-tuVKNgv9.cjs"),b=(c,v={},f={},d=10,p=0)=>{const o=e.ref(d),r=e.ref(p),a=e.ref(v),l=e.ref(f),t=e.ref({}),s=e.ref(!1);async function i(){s.value=!0,x.axios.get(e.toValue(c),{params:{size:o.value,page:r.value,sorts:a.value,filters:l.value}}).then(u=>{t.value=u.data,s.value=!1}).catch(u=>{console.error(u)})}const m=e.computed(()=>Math.max(Math.ceil((t.value.count_filtered??0)/o.value)-1,0)),g=e.computed(()=>t.value.count??0),h=e.computed(()=>Math.min(r.value*o.value+1,t.value.count??0)),w=e.computed(()=>Math.min((r.value+1)*o.value,t.value.count??0)),M=e.computed(()=>t.value.count_filtered??0),S=e.computed(()=>t.value.rows??[]);function y(){console.log("Not yet implemented")}function j(u){let n;a.value[u]==="asc"?n="desc":a.value[u]==="desc"?n=null:n="asc",a.value[u]=n}return e.watchEffect(()=>{i()}),{dataUrl:c,size:o,page:r,sorts:a,filters:l,data:t,fetch:i,loading:s,downloadCsv:y,totalPages:m,countFiltered:M,count:g,rows:S,first:h,last:w,toggleSort:j}};exports.useSprunjer=b; +"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),b=require("./axios-tuVKNgv9.cjs"),q=(v,f={},d={},p=10,m=0)=>{const l=e.ref(v),o=e.ref(p),r=e.ref(m),a=e.ref(f),c=e.ref(d),t=e.ref({}),s=e.ref(!1);async function i(){s.value=!0,b.axios.get(e.toValue(l),{params:{size:o.value,page:r.value,sorts:a.value,filters:c.value}}).then(u=>{t.value=u.data,s.value=!1}).catch(u=>{console.error(u)})}const g=e.computed(()=>Math.max(Math.ceil((t.value.count_filtered??0)/o.value)-1,0)),h=e.computed(()=>t.value.count??0),w=e.computed(()=>Math.min(r.value*o.value+1,t.value.count??0)),M=e.computed(()=>Math.min((r.value+1)*o.value,t.value.count??0)),S=e.computed(()=>t.value.count_filtered??0),y=e.computed(()=>t.value.rows??[]);function j(){console.log("Not yet implemented")}function x(u){let n;a.value[u]==="asc"?n="desc":a.value[u]==="desc"?n=null:n="asc",a.value[u]=n}return e.watchEffect(()=>{i()}),{dataUrl:l,size:o,page:r,sorts:a,filters:c,data:t,fetch:i,loading:s,downloadCsv:j,totalPages:g,countFiltered:S,count:h,rows:y,first:w,last:M,toggleSort:x}};exports.useSprunjer=q; diff --git a/dist/sprunjer.js b/dist/sprunjer.js index 7f5654ee..1cfa5887 100644 --- a/dist/sprunjer.js +++ b/dist/sprunjer.js @@ -1,13 +1,13 @@ -import { ref as a, computed as o, watchEffect as _, toValue as j } from "vue"; -import { a as C } from "./axios-CXDYiOMX.js"; -const N = (c, f = {}, d = {}, m = 10, p = 0) => { - const n = a(m), u = a(p), s = a(f), v = a(d), e = a({}), r = a(!1); +import { ref as a, computed as o, watchEffect as j, toValue as C } from "vue"; +import { a as E } from "./axios-CXDYiOMX.js"; +const O = (f, d = {}, m = {}, p = 10, g = 0) => { + const c = a(f), n = a(p), s = a(g), l = a(d), v = a(m), e = a({}), r = a(!1); async function i() { - r.value = !0, C.get(j(c), { + r.value = !0, E.get(C(c), { params: { size: n.value, - page: u.value, - sorts: s.value, + page: s.value, + sorts: l.value, filters: v.value } }).then((t) => { @@ -16,35 +16,35 @@ const N = (c, f = {}, d = {}, m = 10, p = 0) => { console.error(t); }); } - const g = o(() => Math.max(Math.ceil((e.value.count_filtered ?? 0) / n.value) - 1, 0)), h = o(() => e.value.count ?? 0), w = o(() => Math.min(u.value * n.value + 1, e.value.count ?? 0)), M = o(() => Math.min((u.value + 1) * n.value, e.value.count ?? 0)), x = o(() => e.value.count_filtered ?? 0), y = o(() => e.value.rows ?? []); - function z() { + const h = o(() => Math.max(Math.ceil((e.value.count_filtered ?? 0) / n.value) - 1, 0)), w = o(() => e.value.count ?? 0), M = o(() => Math.min(s.value * n.value + 1, e.value.count ?? 0)), x = o(() => Math.min((s.value + 1) * n.value, e.value.count ?? 0)), y = o(() => e.value.count_filtered ?? 0), z = o(() => e.value.rows ?? []); + function S() { console.log("Not yet implemented"); } - function S(t) { - let l; - s.value[t] === "asc" ? l = "desc" : s.value[t] === "desc" ? l = null : l = "asc", s.value[t] = l; + function _(t) { + let u; + l.value[t] === "asc" ? u = "desc" : l.value[t] === "desc" ? u = null : u = "asc", l.value[t] = u; } - return _(() => { + return j(() => { i(); }), { dataUrl: c, size: n, - page: u, - sorts: s, + page: s, + sorts: l, filters: v, data: e, fetch: i, loading: r, - downloadCsv: z, - totalPages: g, - countFiltered: x, - count: h, - rows: y, - first: w, - last: M, - toggleSort: S + downloadCsv: S, + totalPages: h, + countFiltered: y, + count: w, + rows: z, + first: M, + last: x, + toggleSort: _ }; }; export { - N as useSprunjer + O as useSprunjer };