-
Notifications
You must be signed in to change notification settings - Fork 1
/
strolch-wc-sessions.html
295 lines (241 loc) · 9.56 KB
/
strolch-wc-sessions.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<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-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-app-style">
:host {
display: block;
margin: 0;
padding: 0;
}
paper-material {
padding: 4px;
margin: 0 0 8px;
}
.table {
min-width: 100%;
display: flex;
flex-direction: column;
}
.table-row {
box-sizing: border-box;
display: flex;
flex-direction: row;
margin-top: -1px;
padding-top: 5px;
padding-bottom: 5px;
}
.table-heading {
font-weight: bold;
}
.table-heading,
.table-cell {
display: flex;
padding: 0 12px;
overflow: hidden;
align-items: center;
flex-basis: 80px;
flex-grow: 1;
flex-shrink: 0;
justify-content: flex-start;
min-height: 48px;
}
.source {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 100px;
}
.login-time,
.last-access {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 100px;
}
.username {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 100px;
}
.groups, .roles {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 100px;
}
.actions {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 100px;
}
.data {
padding-top: 10px;
padding-bottom: 10px;
}
.data:nth-child(even) {
background: #f7f7f7;
}
</style>
<div class="actions actions-right">
<paper-icon-button icon="refresh" title="Refresh" on-tap="reload"></paper-icon-button>
</div>
<paper-material elevation="1">
<div class="table">
<div class="table-row">
<div class="table-heading username"><b>Username</b></div>
<div class="table-heading groups"><b>Groups</b></div>
<div class="table-heading roles"><b>Roles</b></div>
<div class="table-heading source"><b>Source</b></div>
<div class="table-heading login-time"><b>Login time</b></div>
<div class="table-heading last-access"><b>Last Access</b></div>
<div class="table-heading actions"></div>
</div>
<template is="dom-repeat" items="[[dataObj.data]]" as="session">
<div class="table-row data">
<div class="table-cell username">[[session.username]] <br><br>[[_getName(session)]]</div>
<div class="table-cell groups">[[arrayToString(session.groups)]]</div>
<div class="table-cell roles">[[arrayToString(session.roles)]]</div>
<div class="table-cell source">[[session.source]]</div>
<div class="table-cell login-time">[[toLocalDateTime(session.loginTime)]]</div>
<div class="table-cell last-access">[[toLocalDateTime(session.lastAccess)]]</div>
<div class="table-cell actions">
<paper-icon-button icon="delete" title="Remove" on-tap="removeSession"></paper-icon-button>
</div>
</div>
</template>
</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) {
if (newValue != 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.session.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>