tablevu 0.2.20 → 0.2.21

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/odata.js CHANGED
@@ -1 +1 @@
1
- import get from"./get.js";function filter(q){function fuval(q){if(q===null){return"null"}else if(typeof q==="string"){if(q.length==10&&q[4]=="-"&&q[7]=="-"&&Date.parse(q)){return q}else return"'"+q+"'"}else{if(typeof q==="number"||typeof q==="boolean")return q.toString();else{if(q.getMonth&&typeof q.getMonth==="function")return q.toISOString();else return q.func+"("+q.params.join(",")+")"}}}let s="";if(q&&q.filters)for(let i=0;i<q.filters.length;i++){if(i>0)s=s+` ${q.type||"and"} `;if(q.filters[i].child){if(q.filters[i].operator=="any"||q.filters[i].operator=="all"){s=s+q.filters[i].child+"/"+q.filters[i].operator+"(i:"+filter(q.filters[i],"i")+")"}}else if(q.filters[i].column){if(q.filters[i].operator=="in")s=s+fuval(q.filters[i].value)+" "+q.filters[i].operator+" "+q.filters[i].column;else s=s+q.filters[i].column+" "+q.filters[i].operator+" "+fuval(q.filters[i].value)}else{if(q.filters[i].func)s=s+q.filters[i].func+"("+q.filters[i].params.map(m=>fuval(m)).join(",")+")";else if(q.filters[i])s=s+"("+filter(q.filters[i])+")"}}return s}function sefs(url,query,seperator){let r="";if(query.select&&query.select.length>0){if(seperator)r+="$select="+query.select.join(",");else url.searchParams.append("$select",query.select.join(","))}if(query.expand&&query.expand.length>0){let a=[];query.expand.forEach(e=>{let q=sefs(null,e,";");if(q)a.push(e.name+"("+q+")");else a.push(e.name)});if(seperator)r+=(r.length>0?seperator:"")+"$expand="+a.join(",");else url.searchParams.append("$expand",a.join(","))}if(query.count)url.searchParams.append("$count",true);return r}export default class odata{constructor(req,features){this.adapter=props=>{const u=new URL(req.url);if(props.pageSize){u.searchParams.append("$skip",props.pageSize*(props.currPage-1));u.searchParams.append("$top",props.pageSize)}sefs(u,features);let f=[];if(features.filter){if(typeof features.filter=="string")f.push(features.filter);else if(Object.prototype.hasOwnProperty.call(features.filter,"filters")){let l=filter(features.filter);if(l)f.push(l)}}if(props.filter){if(typeof props.filter=="string")f.push(props.filter);else if(props.filter&&Object.prototype.hasOwnProperty.call(props.filter,"filters")){let l=filter(props.filter);if(l)f.push(l)}}if(props.search){let l=props.cols.filter(q=>q.searchable==undefined||q.searchable==true).map(q=>"contains("+q.name.replaceAll(".","/")+",'"+props.search+"')").join(" or ");if(l)f.push("("+l+")")}if(f&&f.length>0)u.searchParams.append("$filter",f.join(" and "));if(props.sort&&props.sort.length>0)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).replaceAll(".","/")+(m.dir?" "+m.dir:"")}).join(","));let r=null;if(features&&features.onfetch&&typeof features.onfetch=="function")r=features.onfetch(new Request(u,req));else r=new Request(u,req);return get(r)}}}
1
+ import get from"./get.js";function filter(q){function fuval(q){if(q===null){return"null"}else if(typeof q==="string"){if(q.length==10&&q[4]=="-"&&q[7]=="-"&&Date.parse(q)){return q}else return"'"+q+"'"}else{if(typeof q==="number"||typeof q==="boolean")return q.toString();else{if(q.getMonth&&typeof q.getMonth==="function")return q.toISOString();else return q.func+"("+q.params.join(",")+")"}}}let s="";if(q&&q.filters)for(let i=0;i<q.filters.length;i++){if(i>0)s=s+` ${q.type||"and"} `;if(q.filters[i].child){if(q.filters[i].operator=="any"||q.filters[i].operator=="all"){s=s+q.filters[i].child+"/"+q.filters[i].operator+"(i:"+filter(q.filters[i],"i")+")"}}else if(q.filters[i].column){if(q.filters[i].operator=="in")s=s+fuval(q.filters[i].value)+" "+q.filters[i].operator+" "+q.filters[i].column;else s=s+q.filters[i].column+" "+q.filters[i].operator+" "+fuval(q.filters[i].value)}else{if(q.filters[i].func)s=s+q.filters[i].func+"("+q.filters[i].params.map(m=>fuval(m)).join(",")+")";else if(q.filters[i])s=s+"("+filter(q.filters[i])+")"}}return s}function sefs(url,query,seperator){let r="";if(query.select&&query.select.length>0){if(seperator)r+="$select="+query.select.join(",");else url.searchParams.append("$select",query.select.join(","))}if(query.expand&&query.expand.length>0){let a=[];query.expand.forEach(e=>{let q=sefs(null,e,";");if(q)a.push(e.name+"("+q+")");else a.push(e.name)});if(seperator)r+=(r.length>0?seperator:"")+"$expand="+a.join(",");else url.searchParams.append("$expand",a.join(","))}if(query.orderby){if(seperator)r+="$orderby="+query.orderby;else url.searchParams.append("$orderby",query.orderby)}if(query.top&&parseInt(query.top)>=0){if(seperator)r+="$top="+query.top;else url.searchParams.append("$top",query.top)}if(query.skip&&parseInt(query.skip)>=0){if(seperator)r+="$skip="+query.skip;else url.searchParams.append("$skip",query.skip)}if(query.count){if(seperator)r+="$count=true";else url.searchParams.append("$count",true)}return r}export default class odata{constructor(req,features){this.adapter=props=>{const u=new URL(req.url);if(props.pageSize){u.searchParams.append("$skip",props.pageSize*(props.currPage-1));u.searchParams.append("$top",props.pageSize)}sefs(u,features);let f=[];if(features.filter){if(typeof features.filter=="string")f.push(features.filter);else if(Object.prototype.hasOwnProperty.call(features.filter,"filters")){let l=filter(features.filter);if(l)f.push(l)}}if(props.filter){if(typeof props.filter=="string")f.push(props.filter);else if(props.filter&&Object.prototype.hasOwnProperty.call(props.filter,"filters")){let l=filter(props.filter);if(l)f.push(l)}}if(props.search){let l=props.cols.filter(q=>q.searchable==undefined||q.searchable==true).map(q=>"contains("+q.name.replaceAll(".","/")+",'"+props.search+"')").join(" or ");if(l)f.push("("+l+")")}if(f&&f.length>0)u.searchParams.append("$filter",f.join(" and "));if(props.sort&&props.sort.length>0)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).replaceAll(".","/")+(m.dir?" "+m.dir:"")}).join(","));let r=null;if(features&&features.onfetch&&typeof features.onfetch=="function")r=features.onfetch(new Request(u,req));else r=new Request(u,req);return get(r)}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tablevu",
3
- "version": "0.2.20",
3
+ "version": "0.2.21",
4
4
  "description": "vue 3 data table",
5
5
  "main": "index.js",
6
6
  "directories": {
package/src/odata.js CHANGED
@@ -79,8 +79,33 @@ function sefs(url, query, seperator) {
79
79
  url.searchParams.append('$expand', a.join(','));
80
80
  };
81
81
 
82
- if (query.count)
83
- url.searchParams.append('$count', true);
82
+ if (query.orderby) {
83
+ if (seperator)
84
+ r += '$orderby=' + query.orderby;
85
+ else
86
+ url.searchParams.append('$orderby', query.orderby);
87
+ };
88
+
89
+ if (query.top && parseInt(query.top) >= 0) {
90
+ if (seperator)
91
+ r += '$top=' + query.top;
92
+ else
93
+ url.searchParams.append('$top', query.top);
94
+ };
95
+
96
+ if (query.skip && parseInt(query.skip) >= 0) {
97
+ if (seperator)
98
+ r += '$skip=' + query.skip;
99
+ else
100
+ url.searchParams.append('$skip', query.skip);
101
+ };
102
+
103
+ if (query.count) {
104
+ if (seperator)
105
+ r += '$count=true';
106
+ else
107
+ url.searchParams.append('$count', true);
108
+ };
84
109
 
85
110
  return r;
86
111
  }