Skip to content

Commit

Permalink
Set sorts & filters as associative Array
Browse files Browse the repository at this point in the history
  • Loading branch information
lcharette committed Oct 5, 2024
1 parent f7538b3 commit 815006b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 41 deletions.
27 changes: 17 additions & 10 deletions app/assets/composables/sprunjer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ref, toValue, watchEffect, computed, type Ref, type ComputedRef } from 'vue'
import axios from 'axios'

interface AssociativeArray {
[key: string]: string;
}

interface Sprunjer {
dataUrl: string
size: Ref<number>
Expand All @@ -9,7 +13,8 @@ interface Sprunjer {
countFiltered: ComputedRef<number>
first: ComputedRef<number>
last: ComputedRef<number>
sorts: Ref<string>
sorts: Ref<AssociativeArray>
filters: Ref<AssociativeArray>
data: Ref<any>
loading: Ref<boolean>
count: ComputedRef<number>
Expand All @@ -22,7 +27,8 @@ const useSprunjer = (dataUrl: string) => {
// Sprunje parameters
const size = ref<number>(10)
const page = ref<number>(0)
const sorts = ref<string>('')
const sorts = ref<AssociativeArray>({})
const filters = ref<AssociativeArray>({})

// Raw data
const data = ref<any>({})
Expand All @@ -36,14 +42,14 @@ const useSprunjer = (dataUrl: string) => {
async function fetch() {
loading.value = true
axios
.get(
toValue(dataUrl) +
'?size=' +
size.value +
'&page=' +
page.value +
'&sorts%5Boccurred_at%5D=desc'
)
.get(toValue(dataUrl), {
params: {
size: size.value,
page: page.value,
sorts: sorts.value,
filters: filters.value
}
})
.then((response) => {
data.value = response.data
loading.value = false
Expand Down Expand Up @@ -104,6 +110,7 @@ const useSprunjer = (dataUrl: string) => {
size,
page,
sorts,
filters,
data,
fetch,
loading,
Expand Down
9 changes: 7 additions & 2 deletions dist/composables/sprunjer.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Ref, ComputedRef } from 'vue';
interface AssociativeArray {
[key: string]: string;
}
interface Sprunjer {
dataUrl: string;
size: Ref<number>;
Expand All @@ -7,7 +10,8 @@ interface Sprunjer {
countFiltered: ComputedRef<number>;
first: ComputedRef<number>;
last: ComputedRef<number>;
sorts: Ref<string>;
sorts: Ref<AssociativeArray>;
filters: Ref<AssociativeArray>;
data: Ref<any>;
loading: Ref<boolean>;
count: ComputedRef<number>;
Expand All @@ -19,7 +23,8 @@ declare const useSprunjer: (dataUrl: string) => {
dataUrl: string;
size: Ref<number, number>;
page: Ref<number, number>;
sorts: Ref<string, string>;
sorts: Ref<AssociativeArray, AssociativeArray>;
filters: Ref<AssociativeArray, AssociativeArray>;
data: Ref<any, any>;
fetch: () => Promise<void>;
loading: Ref<boolean, boolean>;
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"),g=require("./axios-tuVKNgv9.cjs"),h=c=>{const o=e.ref(10),u=e.ref(0),l=e.ref(""),t=e.ref({}),r=e.ref(!1);async function s(){r.value=!0,g.axios.get(e.toValue(c)+"?size="+o.value+"&page="+u.value+"&sorts%5Boccurred_at%5D=desc").then(n=>{t.value=n.data,r.value=!1}).catch(n=>{console.error(n)})}const i=e.computed(()=>Math.ceil(t.value.count_filtered/o.value)-1),a=e.computed(()=>t.value.count),d=e.computed(()=>u.value*o.value+1),v=e.computed(()=>Math.min((u.value+1)*o.value,a.value)),f=e.computed(()=>t.value.count_filtered),p=e.computed(()=>t.value.rows);function m(){console.log("Not yet implemented")}return e.watchEffect(()=>{s()}),{dataUrl:c,size:o,page:u,sorts:l,data:t,fetch:s,loading:r,downloadCsv:m,totalPages:i,countFiltered:f,count:a,rows:p,first:d,last:v}};exports.useSprunjer=h;
"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;
62 changes: 34 additions & 28 deletions dist/sprunjer.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
import { ref as n, computed as t, watchEffect as h, toValue as w } from "vue";
import { a as _ } from "./axios-CXDYiOMX.js";
const z = (s) => {
const o = n(10), a = n(0), v = n(""), e = n({}), r = n(!1);
async function c() {
r.value = !0, _.get(
w(s) + "?size=" + o.value + "&page=" + a.value + "&sorts%5Boccurred_at%5D=desc"
).then((u) => {
e.value = u.data, r.value = !1;
}).catch((u) => {
console.error(u);
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);
async function v() {
r.value = !0, y.get(x(u), {
params: {
size: a.value,
page: n.value,
sorts: l.value,
filters: c.value
}
}).then((s) => {
e.value = s.data, r.value = !1;
}).catch((s) => {
console.error(s);
});
}
const i = t(() => Math.ceil(e.value.count_filtered / o.value) - 1), l = t(() => e.value.count), f = t(() => a.value * o.value + 1), d = t(() => Math.min((a.value + 1) * o.value, l.value)), m = t(() => e.value.count_filtered), p = t(() => e.value.rows);
function g() {
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() {
console.log("Not yet implemented");
}
return h(() => {
c();
return w(() => {
v();
}), {
dataUrl: s,
size: o,
page: a,
sorts: v,
dataUrl: u,
size: a,
page: n,
sorts: l,
filters: c,
data: e,
fetch: c,
fetch: v,
loading: r,
downloadCsv: g,
totalPages: i,
countFiltered: m,
count: l,
rows: p,
first: f,
last: d
downloadCsv: h,
totalPages: f,
countFiltered: p,
count: i,
rows: g,
first: d,
last: m
};
};
export {
z as useSprunjer
_ as useSprunjer
};

0 comments on commit 815006b

Please sign in to comment.