
dev-ui.qwc-cache-caches.js Maven / Gradle / Ivy
import { LitElement, html, css} from 'lit';
import { JsonRpc } from 'jsonrpc';
import '@vaadin/icon';
import '@vaadin/button';
import '@vaadin/text-field';
import '@vaadin/text-area';
import '@vaadin/form-layout';
import '@vaadin/progress-bar';
import '@vaadin/checkbox';
import '@vaadin/grid';
import { columnBodyRenderer } from '@vaadin/grid/lit.js';
import '@vaadin/grid/vaadin-grid-sort-column.js';
export class QwcCacheCaches extends LitElement {
jsonRpc = new JsonRpc(this);
// Component style
static styles = css`
.button {
background-color: transparent;
cursor: pointer;
}
.clearIcon {
color: orange;
}
`;
// Component properties
static properties = {
"_caches": {state: true}
}
// Components callbacks
/**
* Called when displayed
*/
connectedCallback() {
super.connectedCallback();
this.jsonRpc.getAll().then(jsonRpcResponse => {
this._caches = new Map();
jsonRpcResponse.result.forEach(c => {
this._caches.set(c.name, c);
});
});
}
/**
* Called when it needs to render the components
* @returns {*}
*/
render() {
if (this._caches) {
return this._renderCacheTable();
} else {
return html`Loading caches...`;
}
}
// View / Templates
_renderCacheTable() {
let caches = [...this._caches.values()];
return html`
`;
}
_actionRenderer(cache) {
return html`
this._clear(cache.name)} class="button">
Clear
`;
}
_nameRenderer(cache) {
return html`
this._refresh(cache.name)} class="button">
${cache.name}`;
}
_clear(name) {
this.jsonRpc.clear({name: name}).then(jsonRpcResponse => {
this._updateCache(jsonRpcResponse.result)
});
}
_refresh(name) {
this.jsonRpc.refresh({name: name}).then(jsonRpcResponse => {
this._updateCache(jsonRpcResponse.result)
});
}
_updateCache(cache){
if (this._caches.has(cache.name) && cache.size !== -1) {
this._caches.set(cache.name, cache);
this.requestUpdate();
}
}
}
customElements.define('qwc-cache-caches', QwcCacheCaches);
© 2015 - 2025 Weber Informatics LLC | Privacy Policy