tablevu 0.2.16 → 0.2.17
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 +1 -1
- package/dist/table.js +1 -1
- package/package.json +1 -1
- package/src/odata.js +38 -30
- package/src/table.js +26 -8
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")return q;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].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
|
|
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)}}}
|
package/dist/table.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h,onMounted,reactive,ref,watch,isReactive,isRef}from"vue";import adaptarr from"./array.js";const tablevuStatuses={Error:-1,Ready:0,Loading:1};const 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(props,{attrs,slots,emit,expose}){let rows=[];let rowg=[];let grps=[];let adapter=null;let timer=null;const spec=reactive({caption:null,group:{value:props.settings&&props.settings.group?props.settings.group.value:props.group?props.group:null,content:props.settings&&props.settings.group?props.settings.group.content:null,expandAll:true,class:"table-light"},page:{count:0,size:props.settings&&props.settings.page?props.settings.page.size:0,current:0,type:null},sort:props.settings&&props.settings.sort?props.settings.sort:[],columns:props.settings&&props.settings.columns?props.settings.columns:[],footer:{button:{class:"btn"}}});if(props.data){if(Array.isArray(props.data)){adapter=adaptarr}else{adapter=props.data}}if(props.filter)spec.filter=props.filter;watch(()=>props.search,(n,o)=>{const x=parseInt(props.settings.searchMinChar)||3;if(timer)clearTimeout(timer);if(o&&o.length>x&&(n==undefined||n==null||n.length<=x)||n&&n.length>x){timer=setTimeout(()=>{if(n&&n.length>x)spec.search=props.search;else spec.search=null;refresh()},444)}});if(props.filter)spec.filter=props.filter;watch(()=>props.filter,()=>{if(props.filter)spec.filter=props.filter;else spec.filter=null;refresh()},{deep:true});watch(()=>props.command,(n,o)=>{if(n&&n.length>0){const c=props.command[n.length-1];if(c&&c.name){if(c.name.toLowerCase()=="refresh")refresh();else if(c.name.toLowerCase()=="first")first();else if(c.name.toLowerCase()=="prior")prior();else if(c.name.toLowerCase()=="next")next();else if(c.name.toLowerCase()=="last")last();else console.log("Unknown command")}props.command.length=0}},{deep:true});function prepareGroup(g,r){grps=[];rowg=[];for(let i=0;i<r.length;i++){let v=null;let c=null;const o=r[i];if(g.value){if(typeof g.value=="function")v=g.value(o);else v=o[g.value]}else if(typeof g=="function")v=g(o);else{if(typeof g=="bigint"||typeof g=="number"){const l=parseInt(g);if(l)v=o[l]}else if(typeof g=="string")v=o[g]}if(g.content){if(typeof g.content=="function")c=g.content(o);else c=o[g.content]}let n=grps.findIndex(f=>f.group==v);if(n==-1){n=grps.push({group:v,content:c,expand:spec.group.expandAll})-1}rowg.push(n)}}function first(){page(1)}function prior(){if(spec.page.current>1){page(spec.page.current-1)}else{page(spec.page.current)}}function next(){page(spec.page.current+1)}function last(){page(spec.page.count)}function refresh(){page(spec.page.current)}function orderby(ind,dir){if(spec.sort&&spec.sort.length>0){let l=spec.sort.findIndex(f=>f.index==ind);if(l<0){let n=spec.columns[ind].name;l=spec.sort.findIndex(f=>f.name==n)}if(l==0){spec.sort[l].dir=dir?dir:spec.sort[0].dir?null:"desc"}else if(l>0){spec.sort.splice(l,1)}if(l!=0){spec.sort.unshift({index:ind,dir:dir?dir:null})}if(spec.sort.length>2){spec.sort.pop()}}else{spec.sort.push({index:ind,dir:dir?dir:null})}page(spec.page.current)}function page(currentPage){let dat=null;if(props.data){if(Array.isArray(props.data))dat=props.data}else return;spec.status=tablevuStatuses.Loading;if(adapter){adapter({pageSize:spec.page.size,currPage:currentPage,sort:spec.sort,cols:spec.columns,filter:spec.filter,search:spec.search},dat).then(ada=>{if(spec.onData)rows=spec.onData(ada.rows);else rows=ada.rows;if(spec.group&&(typeof spec.group=="string"||typeof spec.group=="bigint"||typeof spec.group=="object"&&spec.group.value))prepareGroup(spec.group,rows);spec.page.count=ada.count>0&&spec.page.size>0?Math.floor(ada.count/spec.page.size):0;spec.page.current=currentPage;spec.status=tablevuStatuses.Ready;spec.time=Date.now()})}}function renderValue(col,val){if(val){let v;if(col.type=="datetime"||col.type=="date"||col.type=="time"){let t=new Date(val);if(col.type=="date")v=t.toLocaleDateString();else if(col.type=="time")v=t.toLocaleTimeString();else v=t.toLocaleString()}else{if(col.type=="numeric"){v=parseFloat(val)}else{if(col.type=="integer"){v=parseInt(val)}else v=val}}return v}else return""}function renderCell(col,val){const o={style:{}};if(col.colspan&&col.colspan>1){o.colspan=col.colspan}if(col.style){o.style=col.style}if(col.align){o.style["text-align"]=col.align}if(col.width){o.style["max-width"]=col.width}const v=renderValue(col,val);return h("td",o,v)}function renderCustomCell(col,row){const o={style:{}};if(col.colspan&&col.colspan>1){o.colspan=col.colspan}if(col.style){o.style=col.style}if(col.align){o.style["text-align"]=col.align}if(col.width){o.style["max-width"]=col.width}let f=col.render(row);return h("td",o,f)}function renderGroup(grp){const b=h("button",{title:grp.expand,onClick:event=>{grp.expand=grp.expand?false:true;event.currentTarget.value=grp.expand?"▼":"►";spec.time=Date.now();event.preventDefault()},style:{padding:0,margin:"0 6px 0 0",width:"12px",height:"100%",border:"none",outline:0,backgroundColor:"transparent"}},grp.expand?"▼":"►");const v=grp.content||grp.group;return h("tr",{},h("td",{colspan:spec.columns.length,class:spec.group.class},[b,v]))}function renderRow(index,row){const o={};const r=[];o.key=index;o.index=index;if(props.rowid){o.rowid=row[props.rowid]}for(let i=0;i<spec.columns.length;i+=1){let v;const c=spec.columns[i];if(c.render){v=renderCustomCell(c,row);r.push(v)}else{if(c.depth){v=row;for(let j=0;j<c.depth.length;j+=1){if(v)v=v[c.depth[j]]}}else{v=row[c.name]}r.push(renderCell(c,v))}}o.ondblclick=event=>{const r=rows[event.currentTarget.attributes.index.value];emit("onRowDblClick",event,r)};if(props.onRowClick){o.onClick=event=>{const r=rows[event.currentTarget.attributes.index.value];props.onRowClick(event,r)}}return h("tr",o,r)}function renderHeader(){let ar=[];let sp=1;for(let i=0;i<spec.columns.length;i+=1){if(sp>1){sp--;continue}const cl=[];if(spec.columns[i].label){cl.push(h("span",spec.columns[i].label))}else{cl.push(h("span",spec.columns[i].name))}if(spec.sort&&spec.sort.length>0&&spec.sort[0].index==i){if(spec.sort[0].dir=="desc")cl.push(h("span",{style:{float:"right"}},"▼"));else cl.push(h("span",{style:{float:"right"}},"▲"))}let ch={position:"relative"};if(spec.columns[i].width){ch.width=spec.columns[i].width;ch.minWidth=spec.columns[i].width;ch.maxWidth=spec.columns[i].width}let cy={display:"block","font-weight":500,textDecoration:"none",textAlign:"center"};if(spec.columns[i].header){if(spec.columns[i].header.colspan)sp=parseInt(spec.columns[i].header.colspan)||1;if(spec.columns[i].header.style)ch.style=spec.columns[i].header.style;if(spec.columns[i].header.align)ch.textAlign=spec.columns[i].header.align}let a;let f;if(spec.columns[i].popup){const r=ref(null);let c=[h("a",{href:"#",onClick(event){orderby(i);event.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Ascending"),h("a",{href:"#",onClick(event){orderby(i,"desc");event.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Descending")];a=h("a",{href:"#",onClick(event){if(r.value&&r.value.style&&r.value.style.display&&r.value.style.display=="block")r.value.style.display="none";else r.value.style.display="block";event.preventDefault()},style:cy},cl);f=h("div",{ref:r,style:{position:"absolute",display:"none",width:spec.columns[i].width||"12rem",height:"fit-content",border:"1px solid lightgray",backgroundColor:"whitesmoke",zIndex:1,left:0,top:"2rem",bottom:0,right:0,padding:".25rem"}},c)}else a=h("a",{href:"#",onClick(event){orderby(i);event.preventDefault()},style:cy},cl);if(spec.columns[i].filter){}ar.push(h("th",{colspan:sp>1?sp:null,style:ch},[a,f]))}const tr=h("tr",{},ar);return[tr]}function renderBody(){const dr=[];if(rows&&rows.length>0){if(grps&&grps.length>0){let r=[];for(let g=0;g<grps.length;g++)r.push({index:g,childs:[]});for(let i=0;i<rows.length;i++){const x=rowg[i];r[x].childs.push(renderRow(i,rows[i]))}for(let g=0;g<grps.length;g++){dr.push(renderGroup(grps[g]));if(grps[g].expand)dr.push(r[g].childs)}}else{for(let i=0;i<rows.length;i++){dr.push(renderRow(i,rows[i]))}}}return dr}function renderFooter(){const fr=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:first,disabled:spec.page.current==1},"◀◀");const ls=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:last,disabled:spec.page.count==0||spec.page.current==spec.page.count},"▶▶");const pg=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem"},spec.page.current);const pr=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:prior,disabled:spec.page.current==1},"◀");const nx=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:next,disabled:spec.page.count>0&&spec.page.current==spec.page.count},"▶");const td=h("td",{colspan:spec.columns.length,align:"center"},[fr,pr,pg,nx,ls]);const tr=h("tr",{},[td]);return[tr]}function renderCaption(){return null}if(spec.columns.length==0){alert("Columns not defined !")}for(let i=0;i<spec.columns.length;i++)if(spec.columns[i].name&&spec.columns[i].name.indexOf(".")>-1){spec.columns[i].depth=spec.columns[i].name.split(".")}page(1);onMounted(()=>{});return{spec:spec,renderHeader:renderHeader,renderBody:renderBody,renderFooter:renderFooter,renderCaption:renderCaption}},render(props){let prps={class:"tablevu"};if(props.class)prps.class="tablevu "+props.class;if(props.style)prps.style=props.style;let cntn=[];cntn.push(h("thead",{},this.renderHeader()));if(this.spec.status==tablevuStatuses.Ready)cntn.push(h("tbody",{"data-time":this.spec.time},this.renderBody()));if(this.spec.caption)cntn.push(h("caption",{},this.renderCaption()));if(this.spec.page.size>0)cntn.push(h("tfoot",{},this.renderFooter()));return h("table",prps,cntn)}};export default tablevu;
|
|
1
|
+
import{h,onMounted,reactive,ref,watch,isReactive,isRef}from"vue";import adaptarr from"./array.js";const tablevuStatuses={Error:-1,Ready:0,Loading:1};const 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(props,{attrs,slots,emit,expose}){let rows=[];let rowg=[];let grps=[];let adapter=null;let timer=null;const spec=reactive({caption:null,group:{value:props.settings&&props.settings.group?props.settings.group.value:props.group?props.group:null,content:props.settings&&props.settings.group?props.settings.group.content:null,expandAll:true,class:"table-light"},page:{count:0,size:props.settings&&props.settings.page?props.settings.page.size:0,current:0,type:null},sort:props.settings&&props.settings.sort?props.settings.sort:[],columns:props.settings&&props.settings.columns?props.settings.columns:[],footer:{button:{class:"btn"}}});if(props.data){if(Array.isArray(props.data)){adapter=adaptarr}else{adapter=props.data}}if(props.search)spec.search=props.search;watch(()=>props.search,(n,o)=>{const x=parseInt(props.settings.searchMinChar)||3;if(timer)clearTimeout(timer);if(n&&n.length>x){spec.search=n;timer=setTimeout(()=>refresh,444)}else if(o&&o.length>x&&(n==undefined||n==null||n.length<=x)){spec.search=null;timer=setTimeout(()=>refresh,444)}});if(props.filter)spec.filter=props.filter;watch(()=>props.filter,()=>{if(props.filter)spec.filter=props.filter;else spec.filter=null;refresh()},{deep:true});watch(()=>props.command,(n,o)=>{if(n&&n.length>0){const c=props.command[n.length-1];if(c&&c.name){if(c.name.toLowerCase()=="refresh")refresh();else if(c.name.toLowerCase()=="first")first();else if(c.name.toLowerCase()=="prior")prior();else if(c.name.toLowerCase()=="next")next();else if(c.name.toLowerCase()=="last")last();else console.log("Unknown command")}props.command.length=0}},{deep:true});function prepareGroup(g,r){grps=[];rowg=[];for(let i=0;i<r.length;i++){let v=null;let c=null;const o=r[i];if(g.value){if(typeof g.value=="function")v=g.value(o);else v=o[g.value]}else if(typeof g=="function")v=g(o);else{if(typeof g=="bigint"||typeof g=="number"){const l=parseFloat(g);if(l)v=o[l]}else if(typeof g=="string")v=o[g]}if(g.content){if(typeof g.content=="function")c=g.content(o);else c=o[g.content]}let n=grps.findIndex(f=>f.group==v);if(n==-1){n=grps.push({group:v,content:c,expand:spec.group.expandAll})-1}rowg.push(n)}}function first(){page(1)}function prior(){if(spec.page.current>1){page(spec.page.current-1)}else{page(spec.page.current)}}function next(){page(spec.page.current+1)}function last(){page(spec.page.count)}function go(){let p;do{p=prompt(undefined,spec.page.current)}while(p==null||p==undefined||parseInt(p)>0);if(p&&p>0)page(p)}function refresh(){page(spec.page.current)}function orderby(ind,dir){if(spec.sort&&spec.sort.length>0){let l=spec.sort.findIndex(f=>f.index==ind);if(l<0){let n=spec.columns[ind].name;l=spec.sort.findIndex(f=>f.name==n)}if(l==0){spec.sort[l].dir=dir?dir:spec.sort[0].dir?null:"desc"}else if(l>0){spec.sort.splice(l,1)}if(l!=0){spec.sort.unshift({index:ind,dir:dir?dir:null})}if(spec.sort.length>2){spec.sort.pop()}}else{spec.sort.push({index:ind,dir:dir?dir:null})}page(spec.page.current)}function page(currentPage){let dat=null;if(props.data){if(Array.isArray(props.data))dat=props.data}else return;spec.status=tablevuStatuses.Loading;if(adapter){adapter({pageSize:spec.page.size,currPage:currentPage,sort:spec.sort,cols:spec.columns,filter:spec.filter,search:spec.search},dat).then(ada=>{if(spec.onData)rows=spec.onData(ada.rows);else rows=ada.rows;if(spec.group&&(typeof spec.group=="string"||typeof spec.group=="bigint"||typeof spec.group=="object"&&spec.group.value))prepareGroup(spec.group,rows);spec.page.count=ada.count>0&&spec.page.size>0?Math.floor(ada.count/spec.page.size):0;spec.page.current=currentPage;spec.status=tablevuStatuses.Ready;spec.time=Date.now()})}}function renderValue(col,val){if(val){let v;if(col.type=="datetime"||col.type=="date"||col.type=="time"){let t=new Date(val);if(col.type=="date")v=t.toLocaleDateString();else if(col.type=="time")v=t.toLocaleTimeString();else v=t.toLocaleString()}else{if(col.type=="numeric"){v=parseFloat(val)}else{if(col.type=="integer"){v=parseInt(val)}else v=val}}return v}else return""}function renderCell(col,val){const o={style:{}};if(col.colspan&&col.colspan>1){o.colspan=col.colspan}if(col.style){o.style=col.style}if(col.align){o.style["text-align"]=col.align}if(col.width){o.style["max-width"]=col.width}const v=renderValue(col,val);return h("td",o,v)}function renderCustomCell(col,row){const o={style:{}};if(col.colspan&&col.colspan>1){o.colspan=col.colspan}if(col.style){o.style=col.style}if(col.align){o.style["text-align"]=col.align}if(col.width){o.style["max-width"]=col.width}let f=col.render(row);return h("td",o,f)}function renderGroup(grp){const b=h("button",{title:grp.expand,onClick:event=>{grp.expand=grp.expand?false:true;event.currentTarget.value=grp.expand?"▼":"►";spec.time=Date.now();event.preventDefault()},style:{padding:0,margin:"0 6px 0 0",width:"12px",height:"100%",border:"none",outline:0,backgroundColor:"transparent"}},grp.expand?"▼":"►");const v=grp.content||grp.group;return h("tr",{},h("td",{colspan:spec.columns.length,class:spec.group.class},[b,v]))}function renderRow(index,row){const o={};const r=[];o.key=index;o.index=index;if(props.rowid){o.rowid=row[props.rowid]}for(let i=0;i<spec.columns.length;i+=1){let v;const c=spec.columns[i];if(c.render){v=renderCustomCell(c,row);r.push(v)}else{if(c.depth){v=row;for(let j=0;j<c.depth.length;j+=1){if(v)v=v[c.depth[j]]}}else{v=row[c.name]}r.push(renderCell(c,v))}}o.ondblclick=event=>{const r=rows[event.currentTarget.attributes.index.value];emit("onRowDblClick",event,r)};if(props.onRowClick){o.onClick=event=>{const r=rows[event.currentTarget.attributes.index.value];props.onRowClick(event,r)}}return h("tr",o,r)}function renderHeader(){let ar=[];let sp=1;for(let i=0;i<spec.columns.length;i+=1){if(sp>1){sp--;continue}const cl=[];if(spec.columns[i].label){cl.push(h("span",spec.columns[i].label))}else{cl.push(h("span",spec.columns[i].name))}if(spec.sort&&spec.sort.length>0&&spec.sort[0].index==i){if(spec.sort[0].dir=="desc")cl.push(h("span",{style:{float:"right"}},"▼"));else cl.push(h("span",{style:{float:"right"}},"▲"))}let ch={position:"relative"};if(spec.columns[i].width){ch.width=spec.columns[i].width;ch.minWidth=spec.columns[i].width;ch.maxWidth=spec.columns[i].width}let cy={display:"block","font-weight":500,textDecoration:"none",textAlign:"center"};if(spec.columns[i].header){if(spec.columns[i].header.colspan)sp=parseInt(spec.columns[i].header.colspan)||1;if(spec.columns[i].header.style)ch.style=spec.columns[i].header.style;if(spec.columns[i].header.align)ch.textAlign=spec.columns[i].header.align}let a;let f;if(spec.columns[i].popup){const r=ref(null);let c=[h("a",{href:"#",onClick(event){orderby(i);event.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Ascending"),h("a",{href:"#",onClick(event){orderby(i,"desc");event.preventDefault()},style:{display:"block",textDecoration:"none",color:"black",fontWeight:"initial",padding:".25rem"}},"Order by Descending")];a=h("a",{href:"#",onClick(event){if(r.value&&r.value.style&&r.value.style.display&&r.value.style.display=="block")r.value.style.display="none";else r.value.style.display="block";event.preventDefault()},style:cy},cl);f=h("div",{ref:r,style:{position:"absolute",display:"none",width:spec.columns[i].width||"12rem",height:"fit-content",border:"1px solid lightgray",backgroundColor:"whitesmoke",zIndex:1,left:0,top:"2rem",bottom:0,right:0,padding:".25rem"}},c)}else a=h("a",{href:"#",onClick(event){orderby(i);event.preventDefault()},style:cy},cl);if(spec.columns[i].filter){}ar.push(h("th",{colspan:sp>1?sp:null,style:ch},[a,f]))}const tr=h("tr",{},ar);return[tr]}function renderBody(){const dr=[];if(rows&&rows.length>0){if(grps&&grps.length>0){let r=[];for(let g=0;g<grps.length;g++)r.push({index:g,childs:[]});for(let i=0;i<rows.length;i++){const x=rowg[i];r[x].childs.push(renderRow(i,rows[i]))}for(let g=0;g<grps.length;g++){dr.push(renderGroup(grps[g]));if(grps[g].expand)dr.push(r[g].childs)}}else{for(let i=0;i<rows.length;i++){dr.push(renderRow(i,rows[i]))}}}return dr}function renderFooter(){const fr=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:first,disabled:spec.page.current==1},"◀◀");const ls=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:last,disabled:spec.page.count==0||spec.page.current==spec.page.count},"▶▶");const pg=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:go},spec.page.current+(spec.page.count>0?" / "+spec.page.count:""));const pr=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:prior,disabled:spec.page.current==1},"◀");const nx=h("button",{class:spec.footer.button.class,style:"font: initial; margin-right: .5rem",onClick:next,disabled:spec.page.count>0&&spec.page.current==spec.page.count},"▶");const td=h("td",{colspan:spec.columns.length,align:"center"},[fr,pr,pg,nx,ls]);const tr=h("tr",{},[td]);return[tr]}function renderCaption(){return null}if(spec.columns.length==0){alert("Columns not defined !")}for(let i=0;i<spec.columns.length;i++)if(spec.columns[i].name&&spec.columns[i].name.indexOf(".")>-1){spec.columns[i].depth=spec.columns[i].name.split(".")}page(1);onMounted(()=>{});return{spec:spec,renderHeader:renderHeader,renderBody:renderBody,renderFooter:renderFooter,renderCaption:renderCaption}},render(props){let prps={class:"tablevu"};if(props.class)prps.class="tablevu "+props.class;if(props.style)prps.style=props.style;let cntn=[];cntn.push(h("thead",{},this.renderHeader()));if(this.spec.status==tablevuStatuses.Ready)cntn.push(h("tbody",{"data-time":this.spec.time},this.renderBody()));if(this.spec.caption)cntn.push(h("caption",{},this.renderCaption()));if(this.spec.page.size>0)cntn.push(h("tfoot",{},this.renderFooter()));return h("table",prps,cntn)}};export default tablevu;
|
package/package.json
CHANGED
package/src/odata.js
CHANGED
|
@@ -11,24 +11,29 @@ function filter(q) {
|
|
|
11
11
|
} else
|
|
12
12
|
return '\'' + q + '\'';
|
|
13
13
|
} else {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
if (typeof(q) === 'number' || typeof(q) === 'boolean')
|
|
15
|
+
return q.toString();
|
|
16
|
+
else {
|
|
17
|
+
if (q.getMonth && typeof q.getMonth === "function")
|
|
18
|
+
return q.toISOString()
|
|
19
|
+
else
|
|
20
|
+
return q.func + '(' + q.params.join(',') + ')';
|
|
21
|
+
}
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
let s = '';
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
if (q && q.filters)
|
|
28
|
+
for (let i = 0; i < q.filters.length; i++) {
|
|
29
|
+
if (i > 0)
|
|
30
|
+
s = s + ` ${q.type || 'and'} `;
|
|
31
31
|
|
|
32
|
+
if (q.filters[i].child) {
|
|
33
|
+
if (q.filters[i].operator == 'any' || q.filters[i].operator == 'all') {
|
|
34
|
+
s = s + q.filters[i].child + '/' + q.filters[i].operator + '(i:' + filter(q.filters[i], 'i') + ')';
|
|
35
|
+
}
|
|
36
|
+
} else
|
|
32
37
|
if (q.filters[i].column) {
|
|
33
38
|
if (q.filters[i].operator == 'in')
|
|
34
39
|
s = s + fuval(q.filters[i].value) + ' ' + q.filters[i].operator + ' ' + q.filters[i].column;
|
|
@@ -92,31 +97,34 @@ export default class odata {
|
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
sefs(u, features);
|
|
95
|
-
|
|
96
|
-
// Select //
|
|
97
|
-
if (features.select && features.select.length > 0)
|
|
98
|
-
u.searchParams.append('$select', features.select.join(','));
|
|
99
|
-
|
|
100
|
-
// Expand //
|
|
101
|
-
if (features.expand && features.length > 0) {
|
|
102
|
-
const a =
|
|
103
|
-
u.searchParams.append('$expand', features.expand.map(m => m.name + ((m.select && m.select.length > 0) ? '($select=' + m.select.join(',') + ')' : '')).join(','));
|
|
104
|
-
}*/
|
|
100
|
+
|
|
105
101
|
// Filter //
|
|
106
102
|
let f = [];
|
|
107
103
|
|
|
108
104
|
// Static filter //
|
|
109
|
-
if (features.filter
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
if (features.filter) {
|
|
106
|
+
if (typeof(features.filter) == 'string')
|
|
107
|
+
f.push(features.filter);
|
|
108
|
+
else
|
|
109
|
+
if (Object.prototype.hasOwnProperty.call(features.filter, 'filters')) {
|
|
110
|
+
let l = filter(features.filter);
|
|
111
|
+
|
|
112
|
+
if (l)
|
|
113
|
+
f.push(l);
|
|
114
|
+
}
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
// Dynamic filter //
|
|
116
|
-
if (props.filter
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
if (props.filter) {
|
|
119
|
+
if (typeof(props.filter) == 'string')
|
|
120
|
+
f.push(props.filter);
|
|
121
|
+
else
|
|
122
|
+
if (props.filter && Object.prototype.hasOwnProperty.call(props.filter, 'filters')) {
|
|
123
|
+
let l = filter(props.filter);
|
|
124
|
+
|
|
125
|
+
if (l)
|
|
126
|
+
f.push(l);
|
|
127
|
+
}
|
|
120
128
|
}
|
|
121
129
|
|
|
122
130
|
// Search //
|
package/src/table.js
CHANGED
|
@@ -68,8 +68,8 @@ const tablevu = {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
// Setup Search Input //
|
|
71
|
-
if (props.
|
|
72
|
-
spec.
|
|
71
|
+
if (props.search)
|
|
72
|
+
spec.search = props.search;
|
|
73
73
|
|
|
74
74
|
//if (isRef(props.search) || isReactive(props.search))
|
|
75
75
|
watch(() => props.search, (n,o) => {
|
|
@@ -78,9 +78,16 @@ const tablevu = {
|
|
|
78
78
|
if (timer)
|
|
79
79
|
clearTimeout(timer);
|
|
80
80
|
|
|
81
|
-
if (
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
if (n && n.length > x) {
|
|
82
|
+
spec.search = n;
|
|
83
|
+
|
|
84
|
+
timer = setTimeout(() => refresh, 444);
|
|
85
|
+
} else
|
|
86
|
+
if (o && o.length > x && (n == undefined || n == null || n.length <= x)) {
|
|
87
|
+
spec.search = null;
|
|
88
|
+
|
|
89
|
+
timer = setTimeout(() => refresh, 444);
|
|
90
|
+
}
|
|
84
91
|
});
|
|
85
92
|
|
|
86
93
|
// Setup dynamic filter //
|
|
@@ -137,8 +144,8 @@ const tablevu = {
|
|
|
137
144
|
if (typeof g == 'function')
|
|
138
145
|
v = g(o);
|
|
139
146
|
else {
|
|
140
|
-
if (typeof g ==
|
|
141
|
-
const l =
|
|
147
|
+
if (typeof g == 'bigint' || typeof g == 'number') {
|
|
148
|
+
const l = parseFloat(g);
|
|
142
149
|
|
|
143
150
|
if (l)
|
|
144
151
|
v = o[l];
|
|
@@ -186,6 +193,17 @@ const tablevu = {
|
|
|
186
193
|
page(spec.page.count);
|
|
187
194
|
}
|
|
188
195
|
|
|
196
|
+
function go() { // Go Page //
|
|
197
|
+
let p;
|
|
198
|
+
|
|
199
|
+
do {
|
|
200
|
+
p = prompt(undefined, spec.page.current);
|
|
201
|
+
} while (p == null || p == undefined || parseInt(p) > 0);
|
|
202
|
+
|
|
203
|
+
if (p && p > 0)
|
|
204
|
+
page(p);
|
|
205
|
+
}
|
|
206
|
+
|
|
189
207
|
function refresh() { // Refresh active page //
|
|
190
208
|
page(spec.page.current);
|
|
191
209
|
}
|
|
@@ -496,7 +514,7 @@ const tablevu = {
|
|
|
496
514
|
function renderFooter() {
|
|
497
515
|
const fr = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: first, disabled: spec.page.current == 1 }, '◀◀');
|
|
498
516
|
const ls = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: last, disabled: spec.page.count == 0 || spec.page.current == spec.page.count }, '▶▶');
|
|
499
|
-
const pg = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem' }, spec.page.current);
|
|
517
|
+
const pg = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: go }, spec.page.current + (spec.page.count > 0 ? (' / ' + spec.page.count) : '' ));
|
|
500
518
|
const pr = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: prior, disabled: spec.page.current == 1 }, '◀');
|
|
501
519
|
const nx = h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: next, disabled: spec.page.count > 0 && spec.page.current == spec.page.count }, '▶');
|
|
502
520
|
const td = h('td', { colspan: spec.columns.length, align: 'center' }, [fr, pr, pg, nx, ls]);
|