tablevu 0.2.2 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.js +1 -1
- package/dist/get.js +1 -1
- package/dist/odata.js +1 -1
- package/dist/table.js +1 -1
- package/dist/webapi.js +1 -1
- package/package.json +1 -1
- package/src/array.js +37 -1
- package/src/get.js +2 -2
- package/src/odata.js +17 -54
- package/src/table.js +97 -81
package/dist/array.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function
|
|
1
|
+
export default function(a,b){let c=[];return Array.isArray(b)&&(c=b),new Promise(b=>{if(a.pageSize&&(c=c.slice((a.currPage-1)*a.pageSize,a.currPage*a.pageSize)),a.sort&&0<a.sort.length)for(let d,b=a.sort.length-1;0<=b;b--)d=null,d=-1<a.sort[b].index?a.cols[a.sort[b].index].name:a.sort[b].name,"desc"==a.sort[b].dir?c.sort((c,a)=>c[d]<a[d]?1:a[d]<c[d]?-1:0):c.sort((c,a)=>c[d]>a[d]?1:a[d]>c[d]?-1:0);b({rows:c,count:c.length})})}
|
package/dist/get.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function get(
|
|
1
|
+
export default function get(a,b){return new Promise((d,e)=>{fetch(a,b).then(a=>a.json()).then(a=>{let b,e=0;a?(a.hasOwnProperty("value")?(b=a.value,e=a.hasOwnProperty("@count")?parseInt(a["@count"]):a.hasOwnProperty("count")?parseInt(a.count):0):(b=a,e=0),d({rows:b,count:e})):d({rows:null,count:null})}).catch(a=>{console.error(a),e(a)})})}
|
package/dist/odata.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import get from"./get.js";function filter(
|
|
1
|
+
import get from"./get.js";function filter(a){function b(a){if(null===a)return"null";if("string"==typeof a)return"'"+a+"'";if("number"==typeof a)return a;debugger;return a.getMonth&&"function"==typeof a.getMonth?a.toISOString():a.func+"("+a.params.join(",")+")"}let c="";if(a&&a.filters)for(let d=0;d<a.filters.length;d++)0<d&&(c+=` ${a.type||"and"} `),a.filters[d].column?"in"==a.filters[d].operator?c=c+b(a.filters[d].value)+" "+a.filters[d].operator+" "+a.filters[d].column:c=c+a.filters[d].column+" "+a.filters[d].operator+" "+b(a.filters[d].value):a.filters[d].func?c=c+a.filters[d].func+"("+a.filters[d].params.map(a=>b(a)).join(",")+")":a.filters[d]&&(c=c+"("+filter(a.filters[d])+")");return c}export default class odata{constructor(a,b){this.adapter=c=>{const d=new URL(a);console.log(d),c.pageSize&&(d.searchParams.append("$skip",c.pageSize*(c.currPage-1)),d.searchParams.append("$top",c.pageSize)),c.select&&0<c.select.length&&d.searchParams.append("$select",c.select.join(",")),c.expand&&0<c.expand.length&&d.searchParams.append("$expand",c.expand.map(a=>a.name+(a.select&&0<a.select.length?"($select="+a.select.join(",")+")":"")).join(","));let e=[];if(c.filter&&Object.prototype.hasOwnProperty.call(c.filter,"filters")){let a=filter(c.filter);a&&e.push(a)}if(c.filter){let a=filter(c.filter);a&&e.push(a)}if(c.search){let a=c.cols.filter(a=>null==a.searchable||!0==a.searchable).map(a=>"contains("+a.name.replaceAll(".","/")+",'"+c.search+"')").join(" or ");a&&e.push("("+a+")")}return 0<e.length&&d.searchParams.append("$filter",e.join(" and ")),c.sort&&0<c.sort.length&&d.searchParams.append("$orderby",c.sort.map(a=>{let b={index:-1,name:"",dir:null};return Object.prototype.hasOwnProperty.call(a,"index")?b.index=a.index:b.name=a.name,b.dir=a.dir,b}).map(a=>(-1<a.index?c.cols[a.index].name:a.name)+(a.dir?" "+a.dir:"")).join(",")),c.count&&d.searchParams.append("$count",!0),get(d,b)}}}
|
package/dist/table.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h,onMounted,reactive,ref,watch}from"vue";import adaptarr from"./array.js";const tablevuStatuses={Error:-1,Ready:0,Loading:1},tablevu={props:{settings:{type:Object,default:null},data:{type:[Array,Function]},search:{type:String},filter:{type:[Array,Object]},command:{type:Array,default:[]},rowid:{type:String},onRowClick:{type:Function},onRowDblClick:{type:Function},class:{type:String,default:"table"},style:{type:String,default:null}
|
|
1
|
+
import{h,onMounted,reactive,ref,watch,isReactive,isRef}from"vue";import adaptarr from"./array.js";const tablevuStatuses={Error:-1,Ready:0,Loading:1},tablevu={props:{settings:{type:Object,default:null},data:{type:[Array,Function]},group:{type:[String,Object]},search:{type:String},filter:{type:[Array,Object]},command:{type:Array,default:[]},rowid:{type:String},onRowClick:{type:Function},onRowDblClick:{type:Function},class:{type:String,default:"table"},style:{type:String,default:null}},emits:["onRowClick","onRowDblClick"],setup(a,{attrs:b,slots:c,emit:d,expose:e}){function f(a,b){z=[],y=[];for(let d=0;d<b.length;d++){let e=null,f=null;const c=b[d];if(a.value)e="function"==typeof a.value?a.value(c):c[a.value];else if("function"==typeof a)e=a(c);else if("bigint"==typeof a||"number"==typeof a){const b=parseInt(a);b&&(e=c[b])}else"string"==typeof a&&(e=c[a]);a.content&&("function"==typeof a.content?f=a.content(c):f=c[a.content]);let g=z.findIndex(a=>a.group==e);-1==g&&(g=z.push({group:e,content:f,expand:D.group.expandAll})-1),y.push(g)}}function g(){n(1)}function i(){1<D.page.current?n(D.page.current-1):n(D.page.current)}function j(){n(D.page.current+1)}function k(){n(D.page.count)}function l(){n(D.page.current)}function m(a,b){if(D.sort&&0<D.sort.length){let c=D.sort.findIndex(b=>b.index==a);if(0>c){let b=D.columns[a].name;c=D.sort.findIndex(a=>a.name==b)}0==c?D.sort[c].dir=b?b:D.sort[0].dir?null:"desc":0<c&&D.sort.splice(c,1),0!=c&&D.sort.unshift({index:a,dir:b?b:null}),2<D.sort.length&&D.sort.pop()}else D.sort.push({index:a,dir:b?b:null});n(D.page.current)}function n(b){let c=null;if(a.data)Array.isArray(a.data)&&(c=a.data);else return;D.status=tablevuStatuses.Loading,A&&A({pageSize:D.page.size,currPage:b,sort:D.sort,cols:D.columns,filter:D.filter,search:D.search},c).then(a=>{w=D.onData?D.onData(a.rows):a.rows,D.group&&("string"==typeof D.group||"bigint"==typeof D.group||"object"==typeof D.group&&D.group.value)&&f(D.group,w),D.page.count=0<a.count&&0<D.page.size?a.count/D.page.size:0,D.page.current=b,D.status=tablevuStatuses.Ready,D.time=Date.now()})}function p(a,b){if(b){let c;if("datetime"==a.type||"date"==a.type||"time"==a.type){let d=new Date(b);c="date"==a.type?d.toLocaleDateString():"time"==a.type?d.toLocaleTimeString():d.toLocaleString()}else c="numeric"==a.type?parseFloat(b):"integer"==a.type?parseInt(b):b;return c}return""}function q(a,b){const c={style:{}};a.colspan&&1<a.colspan&&(c.colspan=a.colspan),a.align&&(c.style["text-align"]=a.align),a.width&&(c.style["max-width"]=a.width),a.color&&(c.style.color=a.color),a.backgroundColor&&(c.style["background-color"]=a.backgroundColor);const d=p(a,b);return h("td",c,d)}function s(a,b){const c={style:{}};a.colspan&&1<a.colspan&&(c.colspan=a.colspan),a.align&&(c.style["text-align"]=a.align),a.width&&(c.style["max-width"]=a.width);let d=a.render(b);return h("td",c,d)}function t(a){const c=h("button",{title:a.expand,onClick:b=>{console.log(a.expand),a.expand=!a.expand,b.currentTarget.value=a.expand?"\u25BC":"\u25BA",D.time=Date.now(),b.preventDefault()},style:{padding:0,margin:"0 6px 0 0",width:"12px",height:"100%",border:"none",outline:0,backgroundColor:"transparent"}},a.expand?"\u25BC":"\u25BA"),b=a.content||a.group;return h("tr",{},h("td",{colspan:D.columns.length,class:D.group.class},[c,b]))}function u(b,e){const f={},g=[];f.key=b,f.index=b,a.rowid&&(f.rowid=e[a.rowid]);for(let a=0;a<D.columns.length;a+=1){let b;const d=D.columns[a];if(d.render)b=s(d,e),g.push(b);else{if(d.depth){b=e;for(let a=0;a<d.depth.length;a+=1)b&&(b=b[d.depth[a]])}else b=e[d.name];g.push(q(d,b))}}return f.ondblclick=a=>{const b=w[a.currentTarget.attributes.index.value];d("onRowDblClick",a,b)},a.onRowClick&&(f.onClick=b=>{const c=w[b.currentTarget.attributes.index.value];a.onRowClick(b,c)}),h("tr",f,g)}function v(){const a=[];if(w&&0<w.length)if(z&&0<z.length){let b=[];for(let a=0;a<z.length;a++)b.push({index:a,childs:[]});for(let a=0;a<w.length;a++){const c=y[a];b[c].childs.push(u(a,w[a]))}for(let c=0;c<z.length;c++)a.push(t(z[c])),z[c].expand&&a.push(b[c].childs)}else for(let b=0;b<w.length;b++)a.push(u(b,w[b]));return a}let w=[],y=[],z=[],A=null,B=null,C={rowClick:a.settings.onRowClick||a.onRowClick,rowDblClick:a.settings.onRowDblClick||a.onRowDblClick};const D=reactive({caption:null,group:{value:a.settings&&a.settings.group?a.settings.group.value:a.group?a.group:null,content:a.settings&&a.settings.group?a.settings.group.content:null,expandAll:!0,class:"table-light"},page:{count:0,size:a.settings&&a.settings.page?a.settings.page.size:0,current:0,type:null},sort:a.settings&&a.settings.sort?a.settings.sort:[],columns:a.settings&&a.settings.columns?a.settings.columns:[],footer:{button:{class:"btn"}}});a.data&&(Array.isArray(a.data)?A=adaptarr:A=a.data),a.filter&&(D.filter=a.filter),(isRef(a.search)||isReactive(a.search))&&watch(()=>a.search,(b,c)=>{const d=parseInt(a.settings.searchMinChar)||3;B&&clearTimeout(B),(c&&c.length>d&&(null==b||null==b||b.length<=d)||b&&b.length>d)&&(B=setTimeout(()=>{D.search=b&&b.length>d?a.search:null,l()},444))}),a.filter&&(D.filter=a.filter),(isRef(a.filter)||isReactive(a.filter))&&watch(()=>a.filter,()=>{D.filter=a.filter?a.filter:null,l()},{deep:!0}),(isRef(a.command)||isReactive(a.command))&&watch(()=>a.command,b=>{if(b&&0<b.length){const d=a.command[b.length-1];d&&d.name&&("refresh"==d.name.toLowerCase()?l():"first"==d.name.toLowerCase()?g():"prior"==d.name.toLowerCase()?i():"next"==d.name.toLowerCase()?j():"last"==d.name.toLowerCase()?k():console.log("Unknown command")),a.command.length=0}},{deep:!0}),0==D.columns.length&&alert("Columns not defined !");for(let f=0;f<D.columns.length;f++)D.columns[f].name&&-1<D.columns[f].name.indexOf(".")&&(D.columns[f].depth=D.columns[f].name.split("."));return n(1),onMounted(()=>{console.log("tablevu.mounted")}),{spec:D,renderHeader:function(){let b=[],c=1;for(let d=0;d<D.columns.length;d+=1){if(1<c){c--;continue}const e=[];D.columns[d].label?e.push(h("span",D.columns[d].label)):e.push(h("span",D.columns[d].name)),D.sort&&0<D.sort.length&&D.sort[0].index==d&&("desc"==D.sort[0].dir?e.push(h("span",{style:{float:"right"}},"\u25BC")):e.push(h("span",{style:{float:"right"}},"\u25B2")));let g={position:"relative"};D.columns[d].width&&(g.width=D.columns[d].width,g.minWidth=D.columns[d].width,g.maxWidth=D.columns[d].width);let i={display:"block","font-weight":500,textDecoration:"none",color:"black",textAlign:"center"};D.columns[d].header&&(D.columns[d].header.colspan&&(c=parseInt(D.columns[d].header.colspan)||1),D.columns[d].header.align&&(i.textAlign=D.columns[d].header.align),D.columns[d].header.backgroundColor&&(g.backgroundColor=D.columns[d].header.backgroundColor),D.columns[d].header.color&&(i.color=D.columns[d].header.color));let j,a;if(D.columns[d].popup){const b=ref(null);let f=[h("a",{href:"#",onClick(a){m(d),a.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Ascending"),h("a",{href:"#",onClick(a){m(d,"desc"),a.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Descending")];j=h("a",{href:"#",onClick(a){b.value.style.display=b.value&&b.value.style&&b.value.style.display&&"block"==b.value.style.display?"none":"block",a.preventDefault()},style:i},e),a=h("div",{ref:b,style:{position:"absolute",display:"none",width:D.columns[d].width||"12rem",height:"fit-content",border:"1px solid lightgray",backgroundColor:"whitesmoke",zIndex:1,left:0,top:"2rem",bottom:0,right:0,padding:".25rem"}},f)}else j=h("a",{href:"#",onClick(a){m(d),a.preventDefault()},style:i},e);D.columns[d].filter,b.push(h("th",{colspan:1<c?c:null,style:g},[j,a]))}const a=h("tr",{},b);return[a]},renderBody:v,renderFooter:function(){const a=h("button",{class:D.footer.button.class,style:"margin-right: .5rem",onClick:g,disabled:1==D.page.current},"\u25C0\u25C0"),b=h("button",{class:D.footer.button.class,style:"margin-right: .5rem",onClick:k,disabled:0<D.page.count},"\u25B6\u25B6"),c=h("button",{class:D.footer.button.class,style:"margin-right: .5rem"},D.page.current),d=h("button",{class:D.footer.button.class,style:"margin-right: .5rem",onClick:i,disabled:1==D.page.current},"\u25C0"),e=h("button",{class:D.footer.button.class,style:"margin-right: .5rem",onClick:j,disabled:0<D.page.count&&D.page.current==D.page.count},"\u25B6"),f=h("td",{colspan:D.columns.length,align:"center"},[a,d,c,e,b]),l=h("tr",{},[f]);return[l]},renderCaption:function(){return null}}},render(a){console.log("tablevu.render",this.spec.status);let b={class:"tablevu"};a.class&&(b.class="tablevu "+a.class),a.style&&(b.style=a.style);let c=[];return c.push(h("thead",{},this.renderHeader())),this.spec.status==tablevuStatuses.Ready&&c.push(h("tbody",{"data-time":this.spec.time},this.renderBody())),this.spec.caption&&c.push(h("caption",{},this.renderCaption())),0<this.spec.page.size&&c.push(h("tfoot",{},this.renderFooter())),h("table",b,c)}};export default tablevu;
|
package/dist/webapi.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import get from"./get.js";export default class webapi{constructor(
|
|
1
|
+
import get from"./get.js";export default class webapi{constructor(a,b,c){this.adapter=b=>{const d=new URL(a.url);b.pageSize&&(d.searchParams.append("skip",b.pageSize*(b.currPage-1)),d.searchParams.append("top",b.pageSize)),b.search&&d.searchParams.append("search",b.search),b.sort&&0<b.sort.length&&d.searchParams.append("orderby",b.sort.map(a=>{let b={index:-1,name:""};return Object.prototype.hasOwnProperty.call(a,"index")?b.index=a.index:b.name=a.name,b}).map(a=>-1<a.index?b.cols[a.index].name:a.name));let e=null;return e=c&&c.onfetch&&"function"==typeof c.onfetch?c.onfetch(new Request(d,a)):new Request(d,a),get(e)}}}
|
package/package.json
CHANGED
package/src/array.js
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
|
+
export default function (props, data) {
|
|
2
|
+
let d = [];
|
|
3
|
+
|
|
4
|
+
if (Array.isArray(data))
|
|
5
|
+
d = data;
|
|
6
|
+
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
// Paging //
|
|
9
|
+
if (props.pageSize) {
|
|
10
|
+
d = d.slice((props.currPage - 1) * props.pageSize, props.currPage * props.pageSize);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Sort //
|
|
14
|
+
if (props.sort && props.sort.length > 0) {
|
|
15
|
+
for (let i = props.sort.length - 1; i >= 0; i--) {
|
|
16
|
+
let f = null;
|
|
17
|
+
|
|
18
|
+
if (props.sort[i].index > -1)
|
|
19
|
+
f = props.cols[props.sort[i].index].name;
|
|
20
|
+
else
|
|
21
|
+
f = props.sort[i].name;
|
|
22
|
+
|
|
23
|
+
if (props.sort[i].dir == 'desc')
|
|
24
|
+
d.sort((a,b) => (a[f] < b[f]) ? 1 : ((b[f] < a[f]) ? -1 : 0));
|
|
25
|
+
else
|
|
26
|
+
d.sort((a,b) => (a[f] > b[f]) ? 1 : ((b[f] > a[f]) ? -1 : 0));
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
resolve({ rows: d, count: d.length })
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
/*
|
|
1
35
|
export default function adapter(params, data) {
|
|
2
|
-
|
|
36
|
+
debugger;
|
|
37
|
+
const rsl = data;
|
|
3
38
|
|
|
4
39
|
// Filter & Search //
|
|
5
40
|
if (params.filter || params.search) {
|
|
@@ -40,3 +75,4 @@ export default function adapter(params, data) {
|
|
|
40
75
|
|
|
41
76
|
return { rows: rsl, count: data.length };
|
|
42
77
|
}
|
|
78
|
+
*/
|
package/src/get.js
CHANGED
package/src/odata.js
CHANGED
|
@@ -6,14 +6,12 @@ function filter(q) {
|
|
|
6
6
|
if (q === null) {
|
|
7
7
|
return 'null'
|
|
8
8
|
} else if (typeof(q) === 'string') {
|
|
9
|
-
|
|
10
|
-
return q;
|
|
11
|
-
} else
|
|
12
|
-
return '\'' + q + '\'';
|
|
9
|
+
return '\'' + q + '\'';
|
|
13
10
|
} else {
|
|
14
11
|
if (typeof(q) === 'number')
|
|
15
12
|
return q;
|
|
16
13
|
else {
|
|
14
|
+
debugger;
|
|
17
15
|
if (q.getMonth && typeof q.getMonth === "function")
|
|
18
16
|
return q.toISOString()
|
|
19
17
|
else
|
|
@@ -46,59 +44,26 @@ function filter(q) {
|
|
|
46
44
|
return s;
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
function sefs(url, query, seperator) {
|
|
50
|
-
let r = '';
|
|
51
|
-
|
|
52
|
-
if (query.select && query.select.length > 0) {
|
|
53
|
-
if (seperator)
|
|
54
|
-
r += '$select=' + query.select.join(',');
|
|
55
|
-
else
|
|
56
|
-
url.searchParams.append('$select', query.select.join(','));
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
if (query.expand && query.expand.length > 0) {
|
|
60
|
-
let a = [];
|
|
61
|
-
|
|
62
|
-
query.expand.forEach(e => {
|
|
63
|
-
let q = sefs(null, e, ';');
|
|
64
|
-
|
|
65
|
-
if (q)
|
|
66
|
-
a.push(e.name + '(' + q + ')');
|
|
67
|
-
else
|
|
68
|
-
a.push(e.name);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
if (seperator)
|
|
72
|
-
r += (r.length > 0 ? seperator: '') + '$expand=' + a.join(',');
|
|
73
|
-
else
|
|
74
|
-
url.searchParams.append('$expand', a.join(','));
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return r;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
47
|
export default class odata {
|
|
81
|
-
constructor(
|
|
48
|
+
constructor(url, options) {
|
|
82
49
|
this.adapter = (props) => {
|
|
83
|
-
const u = new URL(
|
|
50
|
+
const u = new URL(url);
|
|
51
|
+
console.log(u);
|
|
84
52
|
|
|
85
53
|
// Paging //
|
|
86
54
|
if (props.pageSize) {
|
|
87
55
|
u.searchParams.append('$skip', props.pageSize * (props.currPage - 1));
|
|
88
56
|
u.searchParams.append('$top', props.pageSize);
|
|
89
57
|
}
|
|
90
|
-
|
|
91
|
-
sefs(u, data);
|
|
92
|
-
/*
|
|
58
|
+
|
|
93
59
|
// Select //
|
|
94
|
-
if (
|
|
95
|
-
u.searchParams.append('$select',
|
|
60
|
+
if (props.select && props.select.length > 0)
|
|
61
|
+
u.searchParams.append('$select', props.select.join(','));
|
|
96
62
|
|
|
97
63
|
// Expand //
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}*/
|
|
64
|
+
if (props.expand && props.expand.length > 0)
|
|
65
|
+
u.searchParams.append('$expand', props.expand.map(m => m.name + ((m.select && m.select.length > 0) ? '($select=' + m.select.join(',') + ')' : '')).join(','));
|
|
66
|
+
|
|
102
67
|
// Filter //
|
|
103
68
|
let f = [];
|
|
104
69
|
|
|
@@ -124,18 +89,16 @@ export default class odata {
|
|
|
124
89
|
|
|
125
90
|
if (f && f.length > 0)
|
|
126
91
|
u.searchParams.append('$filter', f.join(' and '));
|
|
127
|
-
|
|
92
|
+
|
|
128
93
|
// Sort //
|
|
129
94
|
if (props.sort && props.sort.length > 0)
|
|
130
|
-
u.searchParams.append('$orderby', props.sort.map(m => { let n = { index: -1, name: '', dir: null }; if (Object.prototype.hasOwnProperty.call(m, 'index')) { n.index = m.index } else { n.name = m.name }; n.dir = m.dir; return n; }).map(m => { return (m.index > -1 ? props.cols[m.index].name : m.name)
|
|
95
|
+
u.searchParams.append('$orderby', props.sort.map(m => { let n = { index: -1, name: '', dir: null }; if (Object.prototype.hasOwnProperty.call(m, 'index')) { n.index = m.index } else { n.name = m.name }; n.dir = m.dir; return n; }).map(m => { return (m.index > -1 ? props.cols[m.index].name : m.name) + (m.dir ? (' ' + m.dir): '') }).join(','));
|
|
131
96
|
|
|
132
|
-
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
else
|
|
136
|
-
r = new Request(u, req);
|
|
97
|
+
// Count //
|
|
98
|
+
if (props.count)
|
|
99
|
+
u.searchParams.append('$count', true);
|
|
137
100
|
|
|
138
|
-
return get(
|
|
101
|
+
return get(u, options);
|
|
139
102
|
}
|
|
140
103
|
}
|
|
141
104
|
}
|
package/src/table.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* https://github.com/endb/tablevu/LICENCE
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { h, onMounted, reactive, ref, watch } from 'vue';
|
|
8
|
+
import { h, onMounted, reactive, ref, watch, isReactive, isRef } from 'vue';
|
|
9
9
|
import adaptarr from './array.js';
|
|
10
10
|
|
|
11
11
|
const tablevuStatuses = { Error: -1, Ready: 0, Loading: 1 };
|
|
@@ -14,7 +14,7 @@ const tablevu = {
|
|
|
14
14
|
props: {
|
|
15
15
|
settings: { type: Object, default: null },
|
|
16
16
|
data: { type: [Array, Function] },
|
|
17
|
-
|
|
17
|
+
group: { type: [String, Object] },
|
|
18
18
|
search: { type: String },
|
|
19
19
|
filter: { type: [Array, Object] },
|
|
20
20
|
command: { type: Array, default: [] },
|
|
@@ -22,19 +22,26 @@ const tablevu = {
|
|
|
22
22
|
onRowClick: { type: Function },
|
|
23
23
|
onRowDblClick: { type: Function },
|
|
24
24
|
class: { type: String, default: 'table' },
|
|
25
|
-
style: { type: String, default: null }
|
|
26
|
-
buttonClass: { type: String, default: 'btn' }
|
|
25
|
+
style: { type: String, default: null }
|
|
27
26
|
},
|
|
28
27
|
|
|
29
28
|
emits: ['onRowClick', 'onRowDblClick'],
|
|
30
29
|
|
|
31
30
|
setup(props, { attrs, slots, emit, expose }) {
|
|
32
|
-
let grps = [];
|
|
33
31
|
let rows = [];
|
|
34
|
-
let
|
|
32
|
+
let rowg = [];
|
|
33
|
+
let grps = [];
|
|
34
|
+
|
|
35
|
+
let adapter = null;
|
|
36
|
+
let timer = null;
|
|
37
|
+
|
|
38
|
+
let events = {
|
|
39
|
+
rowClick: props.settings.onRowClick || props.onRowClick,
|
|
40
|
+
rowDblClick: props.settings.onRowDblClick || props.onRowDblClick
|
|
41
|
+
};
|
|
35
42
|
|
|
36
43
|
const spec = reactive({
|
|
37
|
-
|
|
44
|
+
caption: null,
|
|
38
45
|
group: {
|
|
39
46
|
value: (props.settings && props.settings.group) ? props.settings.group.value : props.group ? props.group: null, // string ise alan adı, int ise index, fonksiyon ise calistirip alacak.
|
|
40
47
|
content: (props.settings && props.settings.group) ? props.settings.group.content : null, // grid de ne gosterilecek
|
|
@@ -47,75 +54,78 @@ const tablevu = {
|
|
|
47
54
|
current: 0,
|
|
48
55
|
type: null // incrementral, dynamic
|
|
49
56
|
},
|
|
57
|
+
sort: (props.settings && props.settings.sort) ? props.settings.sort : [],
|
|
58
|
+
columns: (props.settings && props.settings.columns) ? props.settings.columns : [],
|
|
50
59
|
footer: {
|
|
51
60
|
button: {
|
|
52
|
-
first: { visible: true, content: null },
|
|
53
|
-
prior: { visible: true, content: null },
|
|
54
|
-
next: { visible: true, content: null },
|
|
55
|
-
last: { visible: true, content: null },
|
|
56
|
-
page: { visible: true, content: null },
|
|
57
|
-
size: { visible: true, content: null },
|
|
58
61
|
class: 'btn'
|
|
59
62
|
}
|
|
60
|
-
}
|
|
61
|
-
sort: (props.settings && props.settings.sort) ? props.settings.sort : [],
|
|
62
|
-
columns: (props.settings && props.settings.columns) ? props.settings.columns : [],
|
|
63
|
-
onRowClick: props.settings.onRowClick || props.onRowClick,
|
|
64
|
-
onRowDblClick: props.settings.onRowDblClick || props.onRowDblClick,
|
|
63
|
+
}
|
|
65
64
|
});
|
|
66
65
|
|
|
67
66
|
if (props.data) {
|
|
68
67
|
if (Array.isArray(props.data)) {
|
|
69
|
-
|
|
68
|
+
adapter = adaptarr;
|
|
70
69
|
}
|
|
71
70
|
else {
|
|
72
|
-
|
|
71
|
+
adapter = props.data;
|
|
73
72
|
}
|
|
74
73
|
};
|
|
75
74
|
|
|
76
|
-
// Setup
|
|
75
|
+
// Setup Search Input //
|
|
77
76
|
if (props.filter)
|
|
78
77
|
spec.filter = props.filter;
|
|
79
78
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
else
|
|
84
|
-
spec.filter = null;
|
|
79
|
+
if (isRef(props.search) || isReactive(props.search))
|
|
80
|
+
watch(() => props.search, (n,o) => {
|
|
81
|
+
const x = parseInt(props.settings.searchMinChar) || 3;
|
|
85
82
|
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
if (timer)
|
|
84
|
+
clearTimeout(timer);
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
86
|
+
if ((o && o.length > x && (n == undefined || n == null || n.length <= x)) || (n && n.length > x)) {
|
|
87
|
+
timer = setTimeout(() => { if (n && n.length > x) spec.search = props.search; else spec.search = null; refresh(); }, 444);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
93
90
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
91
|
+
// Setup dynamic filter //
|
|
92
|
+
if (props.filter)
|
|
93
|
+
spec.filter = props.filter;
|
|
94
|
+
|
|
95
|
+
if (isRef(props.filter) || isReactive(props.filter))
|
|
96
|
+
watch(() => props.filter, () => {
|
|
97
|
+
if (props.filter)
|
|
98
|
+
spec.filter = props.filter;
|
|
99
|
+
else
|
|
100
|
+
spec.filter = null;
|
|
101
|
+
|
|
102
|
+
refresh();
|
|
103
|
+
}, { deep: true });
|
|
98
104
|
|
|
99
105
|
// Setup commands //
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (c.name
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
if (isRef(props.command) || isReactive(props.command))
|
|
107
|
+
watch(() => props.command, (n,o) => {
|
|
108
|
+
if (n && n.length > 0) {
|
|
109
|
+
const c = props.command[n.length-1];
|
|
110
|
+
|
|
111
|
+
if (c && c.name) {
|
|
112
|
+
if (c.name.toLowerCase() == 'refresh') refresh()
|
|
113
|
+
else if (c.name.toLowerCase() == 'first') first()
|
|
114
|
+
else if (c.name.toLowerCase() == 'prior') prior()
|
|
115
|
+
else if (c.name.toLowerCase() == 'next') next()
|
|
116
|
+
else if (c.name.toLowerCase() == 'last') last()
|
|
117
|
+
else console.log('Unknown command');
|
|
118
|
+
}
|
|
112
119
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
120
|
+
props.command.length = 0;
|
|
121
|
+
}
|
|
122
|
+
}, { deep: true });
|
|
123
|
+
/*****************************************************************
|
|
116
124
|
|
|
125
|
+
*****************************************************************/
|
|
117
126
|
function prepareGroup(g, r) {
|
|
118
|
-
|
|
127
|
+
grps = [];
|
|
128
|
+
rowg = [];
|
|
119
129
|
|
|
120
130
|
for (let i = 0; i < r.length; i++) {
|
|
121
131
|
let v = null;
|
|
@@ -149,15 +159,14 @@ const tablevu = {
|
|
|
149
159
|
c = o[g.content];
|
|
150
160
|
};
|
|
151
161
|
|
|
152
|
-
|
|
162
|
+
let n = grps.findIndex(f => f.group == v);
|
|
153
163
|
|
|
154
|
-
if (n
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
s.push({ group: v, content: c, expand: spec.group.expandAll, rows: [o] });
|
|
158
|
-
};
|
|
164
|
+
if (n == -1) {
|
|
165
|
+
n = grps.push({ group: v, content: c, expand: spec.group.expandAll }) - 1;
|
|
166
|
+
};
|
|
159
167
|
|
|
160
|
-
|
|
168
|
+
rowg.push(n);
|
|
169
|
+
};
|
|
161
170
|
}
|
|
162
171
|
/*****************************************************************
|
|
163
172
|
|
|
@@ -190,6 +199,12 @@ const tablevu = {
|
|
|
190
199
|
if (spec.sort && spec.sort.length > 0) {
|
|
191
200
|
let l = spec.sort.findIndex(f => f.index == ind);
|
|
192
201
|
|
|
202
|
+
if (l < 0) {
|
|
203
|
+
let n = spec.columns[ind].name;
|
|
204
|
+
|
|
205
|
+
l = spec.sort.findIndex(f => f.name == n);
|
|
206
|
+
}
|
|
207
|
+
|
|
193
208
|
if (l == 0) {
|
|
194
209
|
spec.sort[l].dir = dir ? dir: (spec.sort[0].dir ? null : 'desc');
|
|
195
210
|
} else if (l > 0) {
|
|
@@ -221,25 +236,22 @@ const tablevu = {
|
|
|
221
236
|
|
|
222
237
|
spec.status = tablevuStatuses.Loading;
|
|
223
238
|
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
239
|
+
if (adapter) {
|
|
240
|
+
adapter({ pageSize: spec.page.size, currPage: currentPage, sort: spec.sort, cols: spec.columns, filter: spec.filter, search: spec.search }, dat).then(ada => {
|
|
227
241
|
if (spec.onData)
|
|
228
242
|
rows = spec.onData(ada.rows);
|
|
229
243
|
else
|
|
230
244
|
rows = ada.rows;
|
|
231
245
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (spec.group)
|
|
235
|
-
grps = prepareGroup(spec.group, rows);
|
|
246
|
+
if (spec.group && (typeof spec.group == 'string' || typeof spec.group == 'bigint' || (typeof spec.group == 'object' && spec.group.value )))
|
|
247
|
+
prepareGroup(spec.group, rows);
|
|
236
248
|
|
|
237
249
|
spec.page.count = (ada.count > 0 && spec.page.size > 0) ? (ada.count / spec.page.size) : 0
|
|
238
250
|
spec.page.current = currentPage;
|
|
239
251
|
|
|
240
252
|
spec.status = tablevuStatuses.Ready;
|
|
241
253
|
spec.time = Date.now();
|
|
242
|
-
|
|
254
|
+
});
|
|
243
255
|
}
|
|
244
256
|
}
|
|
245
257
|
/*****************************************************************
|
|
@@ -460,27 +472,31 @@ const tablevu = {
|
|
|
460
472
|
function renderBody() {
|
|
461
473
|
const dr = [];
|
|
462
474
|
|
|
463
|
-
if (
|
|
464
|
-
|
|
475
|
+
if (rows && rows.length > 0) {
|
|
476
|
+
if (grps && grps.length > 0) {
|
|
477
|
+
let r = [];
|
|
465
478
|
|
|
466
|
-
|
|
467
|
-
|
|
479
|
+
for (let g = 0; g < grps.length; g++)
|
|
480
|
+
r.push({ index: g, childs: [] });
|
|
468
481
|
|
|
469
|
-
|
|
482
|
+
for (let i = 0; i < rows.length; i++) {
|
|
483
|
+
const x = rowg[i];
|
|
470
484
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
485
|
+
r[x].childs.push(renderRow(i, rows[i]));
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
for (let g = 0; g < grps.length; g++) {
|
|
489
|
+
dr.push(renderGroup(grps[g]));
|
|
490
|
+
|
|
491
|
+
if (grps[g].expand)
|
|
492
|
+
dr.push(r[g].childs);
|
|
476
493
|
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
if (rows && rows.length > 0) {
|
|
480
|
-
for (let i = 0; i < rows.length; i += 1) {
|
|
494
|
+
} else {
|
|
495
|
+
for (let i = 0; i < rows.length; i++) {
|
|
481
496
|
dr.push(renderRow(i, rows[i]));
|
|
482
497
|
}
|
|
483
498
|
}
|
|
499
|
+
};
|
|
484
500
|
|
|
485
501
|
return dr;
|
|
486
502
|
}
|