168 lines
2.6 KiB
JavaScript
168 lines
2.6 KiB
JavaScript
|
|
|
|
import renderCollection from '/unify/renderCollection.js';
|
|
|
|
import groups from '/user/group/user.group.permission.js';
|
|
|
|
import gridViewBody from '/elements/gridView/gridView.body.js';
|
|
|
|
import OR from '/unify/sql/OR.js';
|
|
|
|
import AND from '/unify/sql/AND.js';
|
|
|
|
import LIKE from '/unify/sql/LIKE.js';
|
|
|
|
import GREATER from '/unify/sql/GREATER_OR_EQUAL.js';
|
|
|
|
import SMALLER from '/unify/sql/SMALLER_OR_EQUAL.js';
|
|
|
|
|
|
export default class newsListTableBody extends renderCollection, gridViewBody {
|
|
|
|
debug = true;
|
|
|
|
sort = "title";
|
|
|
|
page = 0;
|
|
|
|
limit = 2;
|
|
|
|
async create() {
|
|
|
|
//this.update();
|
|
|
|
}
|
|
|
|
async update( updatePagination = true ) {
|
|
|
|
if( updatePagination ) {
|
|
|
|
this.page = 0;
|
|
|
|
}
|
|
|
|
this.numberOfPages = await this.filterSearch( this.searchType, this.searchTerm, this.sort, this.direction, this.limit, this.page );
|
|
|
|
await this.sync();
|
|
|
|
if( updatePagination ) {
|
|
|
|
this.parents("newsItemPage").tableControl.pagination.create();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
node async filterSearch( searchType, searchTerm, order, direction, limit, page ) {
|
|
|
|
console.log("searchType", searchType);
|
|
|
|
console.log("search input", searchTerm);
|
|
|
|
console.log("search order", order);
|
|
|
|
console.log("direction", direction);
|
|
|
|
console.log("limit", limit);
|
|
|
|
console.log("from", page * limit);
|
|
|
|
|
|
|
|
var filter = this.getFilter();
|
|
|
|
switch( searchType ) {
|
|
|
|
case 0:
|
|
|
|
filter.search = OR( OR( LIKE( filter.title, searchTerm ), LIKE( filter.comments.body, searchTerm ) ), LIKE( filter.body, searchTerm ) );
|
|
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
filter.search = GREATER( filter.price, searchTerm );
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
filter.search = SMALLER( filter.price, searchTerm );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( !searchTerm ) {
|
|
|
|
filter.search = false;
|
|
|
|
}
|
|
|
|
switch( order ) {
|
|
|
|
case "title":
|
|
|
|
filter.order = filter.title;
|
|
|
|
break;
|
|
|
|
case "body":
|
|
|
|
filter.order = filter.body;
|
|
|
|
break;
|
|
|
|
case "price":
|
|
|
|
filter.order = filter.price;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if( direction == "desc" ) {
|
|
|
|
filter.direction = "desc";
|
|
|
|
} else {
|
|
|
|
filter.direction = "asc";
|
|
|
|
}
|
|
|
|
filter.limit = 1000;
|
|
|
|
filter.from = 0;
|
|
|
|
// See how many searched rows there are in total
|
|
this.get();
|
|
|
|
filter.limit = parseInt( limit );
|
|
|
|
filter.from = parseInt( page * limit );
|
|
|
|
var numberOfPages = Math.ceil( this.rows.length / limit );
|
|
|
|
console.log("numberOfPages", numberOfPages);
|
|
|
|
console.log("this.rows.length", this.rows.length);
|
|
|
|
console.log("limit", limit);
|
|
|
|
return numberOfPages;
|
|
|
|
}
|
|
|
|
permission() {
|
|
|
|
this.allow( groups.visitor, "READ" );
|
|
|
|
this.allow( groups.member, "READ" );
|
|
|
|
this.allow( groups.admin, "READ" );
|
|
|
|
}
|
|
|
|
} |