Skip to content

Commit

Permalink
Allow dataUrl to be changed after initial load
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Oct 12, 2024
1 parent d2ad5df commit 9cb8f54
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 30 deletions.
5 changes: 3 additions & 2 deletions app/assets/composables/sprunjer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface AssociativeArray {
}

interface Sprunjer {
dataUrl: string
dataUrl: Ref<string>
size: Ref<number>
page: Ref<number>
totalPages: ComputedRef<number>
Expand All @@ -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<string>(defaultDataUrl)
const size = ref<number>(defaultSize)
const page = ref<number>(defaultPage)
const sorts = ref<AssociativeArray>(defaultSorts)
Expand Down
6 changes: 3 additions & 3 deletions dist/composables/sprunjer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ interface AssociativeArray {
[key: string]: string | null;
}
interface Sprunjer {
dataUrl: string;
dataUrl: Ref<string>;
size: Ref<number>;
page: Ref<number>;
totalPages: ComputedRef<number>;
Expand All @@ -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<string, string>;
size: Ref<number, number>;
page: Ref<number, number>;
sorts: Ref<AssociativeArray, AssociativeArray>;
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"),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;
48 changes: 24 additions & 24 deletions dist/sprunjer.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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
};

0 comments on commit 9cb8f54

Please sign in to comment.