280 lines
9.4 KiB
HTML
280 lines
9.4 KiB
HTML
<link rel="import" href="../polymer/polymer.html">
|
|
|
|
<link rel="import" href="../paper-toolbar/paper-toolbar.html">
|
|
|
|
<link rel="import" href="../iron-ajax/iron-ajax.html">
|
|
<link rel="import" href="../iron-pages/iron-pages.html">
|
|
|
|
<link rel="import" href="../strolch-wc-styles/strolch-wc-styles.html">
|
|
|
|
<link rel="import" href="strolch-wc-inspector-object.html">
|
|
|
|
<dom-module id="strolch-wc-inspector-objects">
|
|
|
|
<template>
|
|
|
|
<style is="strolch-wc-styles">
|
|
|
|
:host {
|
|
display: block;
|
|
margin: 0;
|
|
padding: 0;
|
|
height: 100%;
|
|
}
|
|
|
|
.title {
|
|
margin-top: 2em;
|
|
font-weight: bold;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.card {
|
|
background-color: #ffffff;
|
|
cursor: pointer;
|
|
border-style: none;
|
|
}
|
|
|
|
paper-toolbar {
|
|
--paper-toolbar-height: 42px;
|
|
}
|
|
|
|
</style>
|
|
|
|
<template is="dom-if" if="[[_noElements(objectSummaries)]]" restamp>
|
|
<p class="title g-center">No [[objectType]] objects exists.</p>
|
|
</template>
|
|
|
|
<template is="dom-if" if="[[!_noElements(objectSummaries)]]" restamp>
|
|
|
|
<iron-pages selected="{{section}}" attr-for-selected="name">
|
|
|
|
<section name="typesSummary" class="g-pt-4">
|
|
|
|
<template is="dom-repeat" items="[[objectSummaries.types]]">
|
|
<div class="g-row">
|
|
<div class="g-offset-4 g-4">
|
|
<paper-material class="card g-m-2 g-p-4" elevation="1" on-tap="_showTypeDetails">
|
|
<p class="g-mb-0">[[objectType]] of type <b>[[item.type]]</b> ([[item.size]])</p>
|
|
</paper-material>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</section>
|
|
|
|
<section name="typeDetails">
|
|
|
|
<div class="g-row">
|
|
<div class="g-12">
|
|
<paper-toolbar on-tap="_closeTypeDetails">
|
|
<paper-icon-button icon="arrow-back"></paper-icon-button>
|
|
<span class="align-text-bottom">Showing [[objectType]] objects of type [[selectedType]]</span>
|
|
</paper-toolbar>
|
|
|
|
<template is="dom-repeat" items="[[objects.data]]">
|
|
<strolch-wc-inspector-object base-path="[[basePath]]"
|
|
app="[[app]]"
|
|
realm="[[realm]]"
|
|
object="[[item]]"></strolch-wc-inspector-object>
|
|
</template>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="g-row">
|
|
<div class="g-12">
|
|
<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>[[objects.offset]] to [[_getEnd(objects)]] of [[objects.size]]</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>
|
|
|
|
</section>
|
|
|
|
</iron-pages>
|
|
|
|
</template>
|
|
|
|
<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-inspector-objects',
|
|
|
|
properties: {
|
|
app: {
|
|
type: Object,
|
|
value: function () {
|
|
return null;
|
|
}
|
|
},
|
|
basePath: {
|
|
type: String,
|
|
value: './'
|
|
},
|
|
realm: {
|
|
type: String,
|
|
value: function () {
|
|
return null;
|
|
}
|
|
},
|
|
objectType: {
|
|
type: String,
|
|
value: function () {
|
|
return null;
|
|
}
|
|
},
|
|
objectSummaries: {
|
|
type: Object,
|
|
value: function () {
|
|
return null;
|
|
}
|
|
},
|
|
section: {
|
|
type: String,
|
|
value: function () {
|
|
return 'typesSummary';
|
|
}
|
|
},
|
|
selectedType: {
|
|
type: String,
|
|
value: function () {
|
|
return null;
|
|
}
|
|
},
|
|
objects: {
|
|
type: Object,
|
|
value: function () {
|
|
return null;
|
|
}
|
|
},
|
|
offset: {
|
|
type: Number,
|
|
value: function () {
|
|
return 0;
|
|
}
|
|
},
|
|
limit: {
|
|
type: Number,
|
|
value: function () {
|
|
return 5;
|
|
}
|
|
}
|
|
},
|
|
|
|
_noElements: function (objectSummaries) {
|
|
return objectSummaries == null || objectSummaries.types.length == 0;
|
|
},
|
|
|
|
_showTypeDetails: function (evt) {
|
|
this.selectedType = evt.model.item.type;
|
|
this.section = 'typeDetails';
|
|
this.objects = null;
|
|
console.log('Showing type ' + this.selectedType);
|
|
Strolch.setQueryParamValue('type', this.selectedType);
|
|
this.reloadTypeDetails();
|
|
},
|
|
|
|
_closeTypeDetails: function () {
|
|
this.section = 'typesSummary';
|
|
this.selectedType = null;
|
|
this.objects = null;
|
|
Strolch.setQueryParamValue('type', null);
|
|
},
|
|
|
|
_typeSubPath: function (selectedType) {
|
|
if (selectedType == 'Resource') {
|
|
return 'resources';
|
|
} else if (selectedType == 'Order') {
|
|
return 'orders';
|
|
} else if (selectedType == 'Activity') {
|
|
return 'activities';
|
|
} else {
|
|
throw 'Unhandled selected type ' + selectedType;
|
|
}
|
|
},
|
|
|
|
_hasNext: function (objects) {
|
|
return objects != null && objects.nextOffset > objects.offset;
|
|
},
|
|
_hasPrevious: function (objects) {
|
|
return objects != null && objects.previousOffset < objects.offset;
|
|
},
|
|
|
|
_getEnd: function (objects) {
|
|
if (this._hasNext(objects))
|
|
return objects.nextOffset;
|
|
return objects == null ? 0 : objects.size;
|
|
},
|
|
|
|
_toFirstPage: function () {
|
|
this.offset = 0;
|
|
this.reloadTypeDetails();
|
|
},
|
|
_toPreviousPage: function () {
|
|
this.offset = this.objects.previousOffset;
|
|
this.reloadTypeDetails();
|
|
},
|
|
_toNextPage: function () {
|
|
this.offset = this.objects.nextOffset;
|
|
this.reloadTypeDetails(this.objects.nextOffset);
|
|
},
|
|
_toLastPage: function () {
|
|
this.offset = this.objects.lastOffset;
|
|
this.reloadTypeDetails(this.objects.lastOffset);
|
|
},
|
|
|
|
reloadTypeDetails: function () {
|
|
|
|
this._handleAjaxResponse = function (data) {
|
|
this.set('objects', data.detail.response);
|
|
console.log(data.detail.response);
|
|
};
|
|
|
|
var url = this.basePath + 'rest/strolch/inspector/' + this.realm + '/' + this._typeSubPath(this.objectType) + '/' + this.selectedType;
|
|
url += '?offset=' + this.offset + '&limit=' + this.limit + "&orderBy=id";
|
|
|
|
this.$.ajax.url = url;
|
|
this.$.ajax.method = 'GET';
|
|
this.$.ajax.generateRequest();
|
|
},
|
|
|
|
ready: function () {
|
|
|
|
},
|
|
|
|
reload: function () {
|
|
|
|
},
|
|
|
|
_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.app.showError(dlgTitle, dlgText);
|
|
}
|
|
});
|
|
|
|
</script>
|
|
|
|
</dom-module>
|