diff --git a/app/assets/composables/sprunjer.ts b/app/assets/composables/sprunjer.ts index 0ae62466..0e2d3382 100644 --- a/app/assets/composables/sprunjer.ts +++ b/app/assets/composables/sprunjer.ts @@ -23,12 +23,18 @@ interface Sprunjer { downloadCsv: () => void } -const useSprunjer = (dataUrl: string) => { +const useSprunjer = ( + dataUrl: string, + defaultSorts: AssociativeArray = {}, + defaultFilters: AssociativeArray = {}, + defaultSize: number = 10, + defaultPage: number = 0 +) => { // Sprunje parameters - const size = ref(10) - const page = ref(0) - const sorts = ref({}) - const filters = ref({}) + const size = ref(defaultSize) + const page = ref(defaultPage) + const sorts = ref(defaultSorts) + const filters = ref(defaultFilters) // Raw data const data = ref({}) diff --git a/dist/composables/sprunjer.d.ts b/dist/composables/sprunjer.d.ts index 62478263..0aee34ca 100644 --- a/dist/composables/sprunjer.d.ts +++ b/dist/composables/sprunjer.d.ts @@ -19,7 +19,7 @@ interface Sprunjer { fetch: () => void; downloadCsv: () => void; } -declare const useSprunjer: (dataUrl: string) => { +declare const useSprunjer: (dataUrl: string, defaultSorts?: AssociativeArray, defaultFilters?: AssociativeArray, defaultSize?: number, defaultPage?: number) => { dataUrl: string; size: Ref; page: Ref; diff --git a/dist/sprunjer.cjs b/dist/sprunjer.cjs index 79d622f5..6dc31418 100644 --- a/dist/sprunjer.cjs +++ b/dist/sprunjer.cjs @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),h=require("./axios-tuVKNgv9.cjs"),w=s=>{const o=e.ref(10),u=e.ref(0),a=e.ref({}),c=e.ref({}),t=e.ref({}),r=e.ref(!1);async function l(){r.value=!0,h.axios.get(e.toValue(s),{params:{size:o.value,page:u.value,sorts:a.value,filters:c.value}}).then(n=>{t.value=n.data,r.value=!1}).catch(n=>{console.error(n)})}const v=e.computed(()=>Math.ceil(t.value.count_filtered/o.value)-1),i=e.computed(()=>t.value.count),f=e.computed(()=>u.value*o.value+1),d=e.computed(()=>Math.min((u.value+1)*o.value,i.value)),p=e.computed(()=>t.value.count_filtered),m=e.computed(()=>t.value.rows);function g(){console.log("Not yet implemented")}return e.watchEffect(()=>{l()}),{dataUrl:s,size:o,page:u,sorts:a,filters:c,data:t,fetch:l,loading:r,downloadCsv:g,totalPages:v,countFiltered:p,count:i,rows:m,first:f,last:d}};exports.useSprunjer=w; +"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),j=require("./axios-tuVKNgv9.cjs"),M=(s,v={},f={},d=10,p=0)=>{const o=e.ref(d),u=e.ref(p),a=e.ref(v),c=e.ref(f),t=e.ref({}),r=e.ref(!1);async function l(){r.value=!0,j.axios.get(e.toValue(s),{params:{size:o.value,page:u.value,sorts:a.value,filters:c.value}}).then(n=>{t.value=n.data,r.value=!1}).catch(n=>{console.error(n)})}const m=e.computed(()=>Math.ceil(t.value.count_filtered/o.value)-1),i=e.computed(()=>t.value.count),g=e.computed(()=>u.value*o.value+1),h=e.computed(()=>Math.min((u.value+1)*o.value,i.value)),w=e.computed(()=>t.value.count_filtered),y=e.computed(()=>t.value.rows);function S(){console.log("Not yet implemented")}return e.watchEffect(()=>{l()}),{dataUrl:s,size:o,page:u,sorts:a,filters:c,data:t,fetch:l,loading:r,downloadCsv:S,totalPages:m,countFiltered:w,count:i,rows:y,first:g,last:h}};exports.useSprunjer=M; diff --git a/dist/sprunjer.js b/dist/sprunjer.js index fcd0a587..5fb80bd8 100644 --- a/dist/sprunjer.js +++ b/dist/sprunjer.js @@ -1,9 +1,9 @@ -import { ref as t, computed as o, watchEffect as w, toValue as x } from "vue"; -import { a as y } from "./axios-CXDYiOMX.js"; -const _ = (u) => { - const a = t(10), n = t(0), l = t({}), c = t({}), e = t({}), r = t(!1); +import { ref as t, computed as o, watchEffect as M, toValue as _ } from "vue"; +import { a as j } from "./axios-CXDYiOMX.js"; +const F = (u, f = {}, d = {}, m = 10, p = 0) => { + const a = t(m), n = t(p), l = t(f), c = t(d), e = t({}), r = t(!1); async function v() { - r.value = !0, y.get(x(u), { + r.value = !0, j.get(_(u), { params: { size: a.value, page: n.value, @@ -16,11 +16,11 @@ const _ = (u) => { console.error(s); }); } - const f = o(() => Math.ceil(e.value.count_filtered / a.value) - 1), i = o(() => e.value.count), d = o(() => n.value * a.value + 1), m = o(() => Math.min((n.value + 1) * a.value, i.value)), p = o(() => e.value.count_filtered), g = o(() => e.value.rows); - function h() { + const g = o(() => Math.ceil(e.value.count_filtered / a.value) - 1), i = o(() => e.value.count), h = o(() => n.value * a.value + 1), w = o(() => Math.min((n.value + 1) * a.value, i.value)), x = o(() => e.value.count_filtered), y = o(() => e.value.rows); + function z() { console.log("Not yet implemented"); } - return w(() => { + return M(() => { v(); }), { dataUrl: u, @@ -31,15 +31,15 @@ const _ = (u) => { data: e, fetch: v, loading: r, - downloadCsv: h, - totalPages: f, - countFiltered: p, + downloadCsv: z, + totalPages: g, + countFiltered: x, count: i, - rows: g, - first: d, - last: m + rows: y, + first: h, + last: w }; }; export { - _ as useSprunjer + F as useSprunjer };