strolch-wc-inspector/strolch-wc-sessions.html

256 lines
8.7 KiB
HTML

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-ajax/iron-ajax.html">
<link rel="import" href="../iron-pages/iron-pages.html">
<link rel="import" href="../paper-styles/color.html">
<link rel="import" href="../paper-material/paper-material.html">
<link rel="import" href="../paper-dialog/paper-dialog.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="../paper-item/paper-item.html">
<link rel="import" href="../paper-listbox/paper-listbox.html">
<link rel="import" href="../paper-tabs/paper-tabs.html">
<link rel="import" href="../strolch-wc-styles/strolch-wc-styles.html">
<link rel="import" href="../strolch-wc-debounced-input/strolch-wc-debounced-input.html">
<link rel="import" href="strolch-wc-inspector-behavior.html">
<link rel="import" href="strolch-wc-inspector-paging-behavior.html">
<dom-module id="strolch-wc-sessions">
<template>
<style is="custom-style" include="strolch-wc-styles">
:host {
display: block;
margin: 0;
padding: 0;
height: 100%;
}
paper-material {
background: white;
margin-top: 0.3em;
margin-bottom: 0.3em;
padding: 0.3em;
}
strolch-wc-debounced-input {
max-width: 200px;
display: inline-flex;
--regular-color: #919191;
--focus-color: #000000;
}
</style>
<div class="g-row g-pt-4">
<div class="g-12">
<paper-icon-button class="g-pull-right"
icon="refresh"
title="Refresh"
on-tap="reload"></paper-icon-button>
<strolch-wc-debounced-input id="debouncedInput"
class="g-pull-right"
debounced-input="{{searchTerm}}"
disabled="[[arrayFilled(filters)]]"></strolch-wc-debounced-input>
</div>
</div>
<paper-material elevation="1" class="g-m-3">
<div class="g-row g-pt-4">
<div class="g-12">
<div class="g-row">
<div class="g-2"><b>Username</b></div>
<div class="g-2"><b>Name</b></div>
<div class="g-3"><b>Roles</b></div>
<div class="g-2"><b>Login time</b></div>
<div class="g-2"><b>Last Access</b></div>
<div class="g-1"></div>
</div>
<template is="dom-repeat" items="[[dataObj.data]]">
<hr />
<div class="g-row">
<div class="g-2 g-auto-middle">[[item.username]]</div>
<div class="g-2 g-auto-middle">[[_getName(item)]]</div>
<div class="g-3 g-auto-middle">[[arrayToString(item.roles)]]</div>
<div class="g-2 g-auto-middle">[[toLocalDateTime(item.loginTime)]]</div>
<div class="g-2 g-auto-middle">[[toLocalDateTime(item.lastAccess)]]</div>
<div class="g-1 g-auto-middle">
<paper-icon-button icon="delete"
title="Remove"
on-tap="removeSession"></paper-icon-button>
</div>
</div>
</template>
</div>
</div>
<div class="g-row">
<div class="g-3">
</div>
<div class="g-6">
<div class="g-m-2 g-center">
<paper-icon-button icon="first-page" on-tap="_toFirstPage"></paper-icon-button>
<paper-icon-button icon="chevron-left" on-tap="_toPreviousPage"></paper-icon-button>
<span>[[dataObj.offset]] to [[_getEnd(dataObj)]] of [[dataObj.size]] ([[dataObj.dataSetSize]])</span>
<paper-icon-button icon="chevron-right" on-tap="_toNextPage"></paper-icon-button>
<paper-icon-button icon="last-page" on-tap="_toLastPage"></paper-icon-button>
</div>
</div>
<div class="g-3">
<paper-button on-tap="_setLimit">10</paper-button>
<paper-button on-tap="_setLimit">50</paper-button>
<paper-button on-tap="_setLimit">100</paper-button>
</div>
</div>
</paper-material>
<paper-dialog id="dlg" modal>
<h2>[[dlgTitle]]</h2>
<p>[[dlgText]]</p>
<div class="buttons">
<paper-button dialog-confirm autofocus>Close</paper-button>
</div>
</paper-dialog>
<iron-ajax id="ajax"
content-type="application/json"
handle-as="json"
on-response="_handleAjaxResponse"
on-error="onAjaxError"></iron-ajax>
</template>
<script>
Polymer({
is: 'strolch-wc-sessions',
behaviors: [
StrolchInspectorBehavior,
StrolchInspectorPagingBehavior
],
properties: {
sessions: {
type: Array
},
searchTerm: {
type: String,
observer: 'searchTermChanged'
},
propagateShowDialog: {
type: Boolean,
value: function () {
return false
}
}
},
toLocalDateTime: function (val) {
return Strolch.toLocalDateTime(val);
},
arrayToString: function (arr) {
var s = '';
for (var i = 0; i < arr.length; i++) {
s += arr[i];
if (i + 1 < arr.length)
s += ', ';
}
return s;
},
_getName: function (user) {
return user.firstname + ' ' + user.lastname;
},
listeners: {
"strolch-show-dialog": "onShowDialog"
},
onShowDialog: function (event) {
if (!this.propagateShowDialog) {
event.cancelBubble = true;
event.stopPropagation();
this.showError(event.detail.title, event.detail.text);
}
},
showError: function (title, text) {
this.dlgTitle = title;
this.dlgText = text;
console.log('ERROR: ' + this.dlgTitle + ': ' + this.dlgText);
this.$.dlg.open();
},
searchTermChanged: function (newValue, oldValue) {
if (newValue != null && oldValue != null) {
this.queryPage();
}
},
ready: function () {
//
},
reload: function () {
this.queryPage();
},
queryPage: function () {
this.dlgTitle = 'Sessions query failed';
this._handleAjaxResponse = function (data) {
this.dataObj = data.detail.response;
};
this.$.ajax.url = this.basePath + 'rest/strolch/sessions';
this.$.ajax.method = 'GET';
this.$.ajax.params = {
query: this.searchTerm,
offset: this.dataObj.offset,
limit: this.dataObj.limit,
orderBy: 'username'
};
this.$.ajax.generateRequest();
},
removeSession: function (evt) {
var sessionId = evt.model.item.sessionId;
this.dlgTitle = 'Remove session failed';
this._handleAjaxResponse = function (data) {
this.reload();
};
this.$.ajax.url = this.basePath + 'rest/strolch/sessions/' + sessionId;
this.$.ajax.method = 'DELETE';
this.$.ajax.generateRequest();
},
_handleAjaxResponse: function (evt) {
console.log('NOT YET DEFINED!');
}
});
</script>
</dom-module>