202 lines
3.6 KiB
JavaScript
202 lines
3.6 KiB
JavaScript
/*
|
|
|
|
Copyright (c) 2020, 2023, The Unified Company.
|
|
|
|
This code is part of Unify.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the ESA Software Community License - Strong Copyleft LICENSE,
|
|
as published by the ESA.
|
|
See the ESA Software Community License - Strong Copyleft LICENSE, for more details.
|
|
|
|
https://unifyjs.org
|
|
|
|
*/
|
|
|
|
import Console from '../server/console.js';
|
|
|
|
import tools from '../unify/tools.js';
|
|
|
|
import unify from '../unify/unify.js';
|
|
|
|
import querySQL from '../unify/querySQL.js';
|
|
|
|
import coll from '../unify/collection.js';
|
|
|
|
import clientRenderCollection from '../client/renderCollection.js';
|
|
|
|
import shared from '../unify/shared.js';
|
|
|
|
|
|
export default class renderCollection extends clientRenderCollection{
|
|
|
|
__className = "renderCollection";
|
|
|
|
updatedCache = false;
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
deleteRows() {
|
|
|
|
/*
|
|
var rows = this.rows;
|
|
|
|
for (var i = 0; i < rows.length; i++) {
|
|
|
|
var row = rows[i];
|
|
|
|
console.log("delete row", row.propertyName);
|
|
|
|
delete this[ row.propertyName ];
|
|
|
|
}
|
|
*/
|
|
|
|
}
|
|
|
|
getStoredRows( customQuery ) {
|
|
|
|
var customQuery = this.createQuery();
|
|
|
|
customQuery.debug = this.debug;
|
|
|
|
var storedRows = this.storageCollection.querySelect( customQuery );
|
|
|
|
return storedRows;
|
|
|
|
}
|
|
|
|
addCurrentRow( row, client, c ) {
|
|
|
|
//var object = collection.createInstance();
|
|
|
|
var parsedObject = this.addRow( row, client );
|
|
|
|
parsedObject.rowID = c;
|
|
|
|
this.rows.push( parsedObject );
|
|
|
|
}
|
|
|
|
addRows( rows, client, collection ) {
|
|
|
|
for( var c = 0; c < rows.length; c++ ) {
|
|
|
|
var row = rows[ c ];
|
|
|
|
this.addCurrentRow( row, client, c );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getFromCollection( collection, client ) {
|
|
|
|
//console.log("get parent that is table", collection);
|
|
|
|
if( collection.parent ) {
|
|
|
|
collection.id = collection.parent.id;
|
|
|
|
} else {
|
|
|
|
collection.id = this.id;
|
|
|
|
}
|
|
|
|
var customQuery = this.createQuery();
|
|
|
|
customQuery.debug = this.debug;
|
|
|
|
//console.log("this is renderCollection get from collection", this.getClassName(), this.getApplicationPath() );
|
|
|
|
// returns array directly from better-sqlite3
|
|
var rows = collection.querySelect( customQuery, this.filterObject, client );
|
|
|
|
//if( this.storageCollection.enabled ) {
|
|
|
|
// var storedRows = this.getStoredRows( customQuery );
|
|
|
|
//}
|
|
|
|
this.addRows( rows, client, collection );
|
|
|
|
collection.rows = this.rows;
|
|
|
|
}
|
|
|
|
get( client ) {
|
|
|
|
//this.deleteRows();
|
|
|
|
this.rows = new Array();
|
|
|
|
var collection = this.getCollection();
|
|
|
|
if( collection ) {
|
|
|
|
this.getFromCollection( collection, client );
|
|
|
|
} else {
|
|
|
|
console.log("This renderCollection has no collection.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
createQuery() {
|
|
|
|
var query = new querySQL();
|
|
|
|
var filter = this.filterObject;
|
|
|
|
unify.extend( filter );
|
|
|
|
return query;
|
|
|
|
}
|
|
|
|
createQueryChildCollection( child, query ) {
|
|
|
|
var collectionChildren = child.getChildren(); // this are the object properties of collection.object...
|
|
|
|
for( var b = 0; b< collectionChildren.length; b++ ) {
|
|
|
|
var collectionChild = collectionChildren[b];
|
|
|
|
if( collectionChild.like ) {
|
|
|
|
query.find( collectionChild.propertyName, collectionChild.like, "LIKE" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
findRow( storedRows, id ) {
|
|
|
|
for( var c = 0 ;c < storedRows.length; c++ ) {
|
|
|
|
var storedRow = storedRows[c];
|
|
|
|
if( storedRow.id == id ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|