Skip to content
Snippets Groups Projects
Commit 12d1701b authored by Neuber, Eugen Ramon's avatar Neuber, Eugen Ramon :speech_balloon: Committed by Reiter, Christoph
Browse files

Merge branch 'ajax-pipeline'

parent 18678aa4
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,12 @@ ...@@ -19,6 +19,12 @@
- example `<vpu-data-table-view lang="de"></vpu-data-table-view>` - example `<vpu-data-table-view lang="de"></vpu-data-table-view>`
- `entry-point-url` (optional, default is the TU Graz entry point url): entry point url to access the api - `entry-point-url` (optional, default is the TU Graz entry point url): entry point url to access the api
- example `<vpu-data-table-view entry-point-url="http://127.0.0.1:8000"></vpu-data-table-view>` - example `<vpu-data-table-view entry-point-url="http://127.0.0.1:8000"></vpu-data-table-view>`
- `paging` (optional, required to let datatable do the paging of loaded rows)
- example `<vpu-data-table-view paging></vpu-data-table-view>`
- `searching` (optional, required if a search box is desired)
- example `<vpu-data-table-view searching></vpu-data-table-view>`
- `wait-until-all-loaded` (optional, required if all rows must load before use)
- example `<vpu-data-table-view wait-until-all-loaded></vpu-data-table-view>`
# Local development # Local development
```bash ```bash
......
...@@ -5,12 +5,14 @@ import resp2 from 'datatables.net-responsive-dt'; ...@@ -5,12 +5,14 @@ import resp2 from 'datatables.net-responsive-dt';
import {setting, getAPiUrl, getAssetURL, } from './utils.js'; import {setting, getAPiUrl, getAssetURL, } from './utils.js';
import {i18n} from './i18n'; import {i18n} from './i18n';
import {html, LitElement} from 'lit-element'; import {html, LitElement} from 'lit-element';
import {unsafeHTML} from 'lit-html/directives/unsafe-html.js';
import JSONLD from 'vpu-common/jsonld'; import JSONLD from 'vpu-common/jsonld';
import commonUtils from 'vpu-common/utils'; import commonUtils from 'vpu-common/utils';
import {unsafeHTML} from 'lit-html/directives/unsafe-html.js'; import {unsafeHTML} from 'lit-html/directives/unsafe-html.js';
dt(window, $); dt(window, $);
resp(window, $); resp(window, $);
resp2(window, $);
class DataTableView extends LitElement { class DataTableView extends LitElement {
constructor() { constructor() {
...@@ -28,10 +30,12 @@ class DataTableView extends LitElement { ...@@ -28,10 +30,12 @@ class DataTableView extends LitElement {
this.display_columns = []; // all possible columns, in desired order for the table this.display_columns = []; // all possible columns, in desired order for the table
// datatable properties // datatable properties
this.table = null; this.table = null;
this.paging = 1; this.responsive = null;
this.searching = 1; this.paging = false;
this.searching = false;
// //
this.is_loading = false; this.is_loading = false;
this.wait_until_all_loaded = false;
} }
static get properties() { static get properties() {
...@@ -47,9 +51,10 @@ class DataTableView extends LitElement { ...@@ -47,9 +51,10 @@ class DataTableView extends LitElement {
show_columns: { type: Array, attribute: false }, show_columns: { type: Array, attribute: false },
display_columns: { type: Array, attribute: false }, display_columns: { type: Array, attribute: false },
table: { type: Object, attribute: false }, table: { type: Object, attribute: false },
paging: { type: String }, paging: { type: Boolean },
searching: { type: String }, searching: { type: Boolean },
is_loading: { type: Boolean }, is_loading: { type: Boolean, attribute: false },
wait_until_all_loaded: { type: Boolean, attribute: 'wait-until-all-loaded'}
}; };
} }
...@@ -82,8 +87,6 @@ class DataTableView extends LitElement { ...@@ -82,8 +87,6 @@ class DataTableView extends LitElement {
} }
setup_columns() { setup_columns() {
//let cols = this.table_columns.slice();
if (this.whitelist_cols === '*') { if (this.whitelist_cols === '*') {
const blacklist_cols = this.blacklist_cols.split(' '); const blacklist_cols = this.blacklist_cols.split(' ');
this.show_columns = this.table_columns.filter(col => blacklist_cols.indexOf(col) === -1); this.show_columns = this.table_columns.filter(col => blacklist_cols.indexOf(col) === -1);
...@@ -92,10 +95,10 @@ class DataTableView extends LitElement { ...@@ -92,10 +95,10 @@ class DataTableView extends LitElement {
} }
this.display_columns = this.show_columns.slice(); this.display_columns = this.show_columns.slice();
for(let i=0; i < this.table_columns.length; ++i) { for(let i=0; i < this.table_columns.length; ++i) {
if (this.display_columns.indexOf(this.table_columns[i]) === -1) if (this.display_columns.indexOf(this.table_columns[i]) === -1) {
this.display_columns.push(this.table_columns[i]); this.display_columns.push(this.table_columns[i]);
} }
}
} }
set_datatable(columns) { set_datatable(columns) {
...@@ -110,8 +113,8 @@ class DataTableView extends LitElement { ...@@ -110,8 +113,8 @@ class DataTableView extends LitElement {
}, },
columns: columns, columns: columns,
data: [], data: [],
paging: this.paging > 0, paging: this.paging,
searching: this.searching > 0, searching: this.searching,
}); });
try { try {
...@@ -127,29 +130,23 @@ class DataTableView extends LitElement { ...@@ -127,29 +130,23 @@ class DataTableView extends LitElement {
//console.log('rows = ' + rows); //console.log('rows = ' + rows);
const that = this; const that = this;
if (this.table) { if (this.table) {
this.table.clear(); columns.forEach(function (item, index) {
columns.forEach(function (item, index) { that.table.columns([index]).visible(item.visible === true); }); let i = that.display_columns.indexOf(item.title);
// console.log('item = {' + item.title + ', ' + item.visible + '} i = ' + i);
that.table.columns([i]).visible(item.visible == true);
// TODO that.table.columns([index]).title = item.title;
});
rows.forEach(row => this.table.row.add(row)); rows.forEach(row => this.table.row.add(row));
// now ready to draw // now ready to draw
this.table.draw(); this.table.draw();
} }
} }
loadWebPageElement() { async loader(page) {
if (window.VPUAuthToken === undefined || window.VPUAuthToken === "") { const apiUrlWithFilter = this.apiUrl + '?search=' + this.filter + '&page=' + page;
return;
}
if (this.apiUrl === null || this.jsonld === null) {
return;
}
const apiUrlWithFilter = this.apiUrl + '?search=' + this.filter;
console.log('apiUrlWithFilter = ' + apiUrlWithFilter);
const that = this; const that = this;
this.is_loading = true;
fetch(apiUrlWithFilter, { return await fetch(apiUrlWithFilter, {
headers: { headers: {
'Content-Type': 'application/ld+json', 'Content-Type': 'application/ld+json',
'Authorization': 'Bearer ' + window.VPUAuthToken, 'Authorization': 'Bearer ' + window.VPUAuthToken,
...@@ -168,6 +165,7 @@ class DataTableView extends LitElement { ...@@ -168,6 +165,7 @@ class DataTableView extends LitElement {
title: that.display_columns[i], title: that.display_columns[i],
visible: that.show_columns.indexOf(that.display_columns[i]) > -1 visible: that.show_columns.indexOf(that.display_columns[i]) > -1
}; };
if (items) {
for (let j = 0; j < items.length; ++j) { for (let j = 0; j < items.length; ++j) {
if (rows[j] === undefined) { if (rows[j] === undefined) {
rows[j] = []; rows[j] = [];
...@@ -175,11 +173,32 @@ class DataTableView extends LitElement { ...@@ -175,11 +173,32 @@ class DataTableView extends LitElement {
rows[j][i] = items[j][that.display_columns[i]] || ''; rows[j][i] = items[j][that.display_columns[i]] || '';
} }
} }
}
that.update_datatable(columns, rows); that.update_datatable(columns, rows);
if (!that.wait_until_all_loaded)
that.is_loading = false; that.is_loading = false;
})
.catch(); return items.length;
});
}
async call_loader(page) {
return await this.loader(page);
}
async loadWebPageElement() {
if (window.VPUAuthToken === undefined || window.VPUAuthToken === "") {
return;
}
if (this.apiUrl === null || this.jsonld === null) {
return;
}
this.is_loading = true;
let page = 1;
while (await this.call_loader(page++) === 50) {}
this.is_loading = false;
} }
update(changedProperties) { update(changedProperties) {
...@@ -187,14 +206,17 @@ class DataTableView extends LitElement { ...@@ -187,14 +206,17 @@ class DataTableView extends LitElement {
// noinspection FallThroughInSwitchStatementJS // noinspection FallThroughInSwitchStatementJS
switch (propName) { switch (propName) {
case "lang": case "lang":
i18n.changeLanguage(this.lang); i18n.changeLanguage(this.lang).catch(e => { console.log(e)});
break; break;
case "filter":
case "whitelist_cols": case "whitelist_cols":
case "blacklist_cols": case "blacklist_cols":
this.setup_columns();
case "filter":
case "paging": case "paging":
case "searching": case "searching":
this.loadWebPageElement(); if (this.table)
this.table.clear();
this.loadWebPageElement().catch(e => { console.log(e)});
break; break;
case "value": case "value":
case "entryPointUrl": case "entryPointUrl":
...@@ -203,8 +225,10 @@ class DataTableView extends LitElement { ...@@ -203,8 +225,10 @@ class DataTableView extends LitElement {
that.jsonld = jsonld; that.jsonld = jsonld;
that.apiUrl = that.jsonld.getApiUrlForIdentifier("http://schema.org/" + that.value); that.apiUrl = that.jsonld.getApiUrlForIdentifier("http://schema.org/" + that.value);
}); });
this.loadWebPageElement(); this.loadWebPageElement().catch(e => { console.log(e)});
break; break;
default:
// nothing to do for this properties
} }
}); });
......
...@@ -79,7 +79,8 @@ class DataTableViewDemo extends LitElement { ...@@ -79,7 +79,8 @@ class DataTableViewDemo extends LitElement {
whitelisted-columns="*" whitelisted-columns="*"
blacklisted-columns="phoneExtension name" blacklisted-columns="phoneExtension name"
id="dt1" id="dt1"
paging="1" paging
searching
></vpu-data-table-view> ></vpu-data-table-view>
</div> </div>
</div> </div>
...@@ -95,8 +96,7 @@ class DataTableViewDemo extends LitElement { ...@@ -95,8 +96,7 @@ class DataTableViewDemo extends LitElement {
whitelisted-columns="name telephone email" whitelisted-columns="name telephone email"
blacklisted-columns="" blacklisted-columns=""
id="dt2" id="dt2"
paging="0" wait-until-all-loaded
searching="0"
></vpu-data-table-view> ></vpu-data-table-view>
</div> </div>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment