Skip to content

Commit

Permalink
Add defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Oct 5, 2024
1 parent 815006b commit c7dae40
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
16 changes: 11 additions & 5 deletions app/assets/composables/sprunjer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>(10)
const page = ref<number>(0)
const sorts = ref<AssociativeArray>({})
const filters = ref<AssociativeArray>({})
const size = ref<number>(defaultSize)
const page = ref<number>(defaultPage)
const sorts = ref<AssociativeArray>(defaultSorts)
const filters = ref<AssociativeArray>(defaultFilters)

// Raw data
const data = ref<any>({})
Expand Down
2 changes: 1 addition & 1 deletion dist/composables/sprunjer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number, number>;
page: Ref<number, number>;
Expand Down
2 changes: 1 addition & 1 deletion dist/sprunjer.cjs
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 15 additions & 15 deletions dist/sprunjer.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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
};

0 comments on commit c7dae40

Please sign in to comment.