222 lines
6.7 KiB
HTML
222 lines
6.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">
|
|
|
|
<dom-module id="strolch-wc-sessions">
|
|
|
|
<template>
|
|
|
|
<style is="strolch-wc-styles">
|
|
|
|
:host {
|
|
display: block;
|
|
margin: 0;
|
|
padding: 0;
|
|
height: 100%;
|
|
}
|
|
|
|
.g-table {
|
|
font-size: small;
|
|
}
|
|
|
|
.g-table th, .g-table td {
|
|
vertical-align: inherit;
|
|
}
|
|
|
|
</style>
|
|
|
|
<div class="g-row">
|
|
|
|
<div class="g-12">
|
|
|
|
<table class="g-table">
|
|
|
|
<thead>
|
|
<tr>
|
|
<td>Session Id</td>
|
|
<td>Username</td>
|
|
<td>Firstname</td>
|
|
<td>Lastname</td>
|
|
<td>Roles</td>
|
|
<td>Login time</td>
|
|
<td>Last Access</td>
|
|
<td></td>
|
|
</tr>
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<template is="dom-repeat" items="[[sessions]]">
|
|
|
|
<tr>
|
|
<td>[[item.sessionId]]</td>
|
|
<td>[[item.username]]</td>
|
|
<td>[[item.firstname]]</td>
|
|
<td>[[item.lastname]]</td>
|
|
<td>[[item.roles]]</td>
|
|
<td>[[toLocalDateTime(item.loginTime)]]</td>
|
|
<td>[[toLocalDateTime(item.lastAccess)]]</td>
|
|
<td>
|
|
<paper-icon-button icon="delete"
|
|
title="Remove"
|
|
on-tap="removeSession"></paper-icon-button>
|
|
</td>
|
|
</tr>
|
|
|
|
</template>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<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="_handleAjaxError"></iron-ajax>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
Polymer({
|
|
|
|
is: 'strolch-wc-sessions',
|
|
|
|
properties: {
|
|
basePath: {
|
|
type: String,
|
|
value: './'
|
|
},
|
|
dlgTitle: {
|
|
type: String
|
|
},
|
|
dlgText: {
|
|
type: String
|
|
},
|
|
sessions: {
|
|
type: Array
|
|
}
|
|
},
|
|
|
|
toLocalDateTime: function (val) {
|
|
return Strolch.toLocalDateTime(val);
|
|
},
|
|
|
|
listeners: {},
|
|
|
|
onAjaxError: function (event) {
|
|
var dlgTitle = event.detail.title;
|
|
var data = event.detail;
|
|
var dlgText;
|
|
if (data.detail.request.response) {
|
|
if (data.detail.request.response.msg) {
|
|
dlgText = data.detail.request.response.msg;
|
|
} else if (data.detail.request.response.charAt(0) == '{') {
|
|
var json = JSON.parse(data.detail.request.response);
|
|
if (json.msg) {
|
|
dlgText = json.msg;
|
|
} else {
|
|
dlgText = data.detail.request.response;
|
|
}
|
|
} else {
|
|
dlgText = data.detail.request.response;
|
|
}
|
|
} else {
|
|
dlgText = data.detail.error;
|
|
}
|
|
|
|
this.fire('strolch-show-dialog', {
|
|
title: dlgTitle,
|
|
text: dlgText
|
|
});
|
|
},
|
|
onShowDialog: function (event) {
|
|
var dlgTitle = event.detail.title;
|
|
var dlgText = event.detail.text;
|
|
this.showError(dlgTitle, dlgText);
|
|
},
|
|
|
|
ready: function () {
|
|
//
|
|
},
|
|
|
|
reload: function () {
|
|
|
|
this.dlgTitle = 'Sessions query failed';
|
|
this._handleAjaxResponse = function (data) {
|
|
this.sessions = data.detail.response;
|
|
};
|
|
|
|
this.$.ajax.url = this.basePath + 'rest/strolch/sessions';
|
|
this.$.ajax.method = 'GET';
|
|
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!');
|
|
},
|
|
|
|
_handleAjaxError: function (data) {
|
|
var dlgTitle = 'Debug action failed';
|
|
var dlgText;
|
|
if (data.detail.request.response) {
|
|
dlgText = data.detail.request.response.msg;
|
|
} else {
|
|
dlgText = data.detail.error;
|
|
}
|
|
this.showError(dlgTitle, dlgText);
|
|
},
|
|
|
|
showError: function (title, text) {
|
|
this.dlgTitle = title;
|
|
this.dlgText = text;
|
|
console.log('ERROR: ' + this.dlgTitle + ': ' + this.dlgText);
|
|
this.$.dlg.open();
|
|
}
|
|
});
|
|
|
|
</script>
|
|
|
|
</dom-module>
|