strolch-wc-inspector/strolch-wc-inspector-object...

218 lines
6.9 KiB
HTML
Raw Normal View History

<link rel="import" href="../polymer/polymer.html">
2017-02-06 10:52:53 +01:00
2017-02-06 18:13:36 +01:00
<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">
2017-02-06 10:52:53 +01:00
<link rel="import" href="../strolch-wc-styles/strolch-wc-styles.html">
<link rel="import" href="strolch-wc-inspector-object.html">
2017-02-06 10:52:53 +01:00
<dom-module id="strolch-wc-inspector-objects">
<template>
<style is="strolch-wc-styles">
2017-02-06 10:52:53 +01:00
:host {
display: block;
margin: 0;
padding: 0;
height: 100%;
}
.title {
margin-top: 2em;
font-weight: bold;
font-size: 1rem;
}
2017-02-06 18:13:36 +01:00
.card {
background-color: #ffffff;
2017-02-06 10:52:53 +01:00
cursor: pointer;
border-style: none;
}
2017-02-06 18:13:36 +01:00
paper-toolbar {
--paper-toolbar-height: 42px;
}
2017-02-06 10:52:53 +01:00
</style>
<template is="dom-if" if="[[_noElements(objectData)]]" restamp>
<p class="title g-center">No [[objectName]] objects exists.</p>
2017-02-06 10:52:53 +01:00
</template>
<template is="dom-if" if="[[!_noElements(objectData)]]" restamp>
<iron-pages selected="{{section}}" attr-for-selected="name">
2017-02-08 12:18:50 +01:00
<section name="typesSummary" class="g-pt-4">
2017-02-06 18:13:36 +01:00
<template is="dom-repeat" items="[[objectData.types]]">
<div class="g-row">
<div class="g-offset-4 g-4">
2017-02-08 12:18:50 +01:00
<paper-material class="card g-m-2 g-p-4" elevation="1" on-tap="_showTypeDetails">
<p class="g-mb-0">[[objectName]] of type <b>[[item.type]]</b> ([[item.size]])</p>
2017-02-06 18:13:36 +01:00
</paper-material>
</div>
</div>
</template>
2017-02-06 10:52:53 +01:00
</section>
<section name="typeDetails">
<div class="g-row">
<div class="g-12">
2017-02-06 18:13:36 +01:00
<paper-toolbar>
<paper-icon-button icon="arrow-back" on-tap="_closeTypeDetails"></paper-icon-button>
2017-02-06 10:52:53 +01:00
<span class="align-text-bottom">Showing [[objectName]] objects of type [[selectedType]]</span>
2017-02-06 18:13:36 +01:00
</paper-toolbar>
2017-02-06 10:52:53 +01:00
<template is="dom-repeat" items="[[typeData.elements]]">
<strolch-wc-inspector-object base-path="[[basePath]]"
app="[[app]]"
2017-02-06 10:52:53 +01:00
realm="[[realm]]"
object-name="[[objectName]]"
object-type="[[objectType]]"
summary="[[item]]"></strolch-wc-inspector-object>
</template>
</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: './'
},
2017-02-06 10:52:53 +01:00
realm: {
type: String,
value: function () {
return null;
}
},
objectName: {
type: String,
value: function () {
return null;
}
},
objectType: {
type: String,
value: function () {
return null;
}
},
objectData: {
type: Object,
value: function () {
return null;
}
},
section: {
type: String,
value: function () {
return 'typesSummary';
}
},
selectedType: {
type: String,
value: function () {
return null;
}
},
typeData: {
type: Object,
value: function () {
return null;
}
}
},
_noElements: function (objectData) {
return objectData == null || objectData.types.length == 0;
},
_showTypeDetails: function (evt) {
this.selectedType = evt.model.item.type;
this.section = 'typeDetails';
this.typeData = null;
console.log('Showing type ' + this.selectedType);
Strolch.setQueryParamValue('type', this.selectedType);
this.reloadTypeDetails();
},
_closeTypeDetails: function () {
this.section = 'typesSummary';
this.selectedType = null;
this.typeData = null;
Strolch.setQueryParamValue('type', null);
},
reloadTypeDetails: function () {
this._handleAjaxResponse = function (data) {
this.typeData = data.detail.response;
};
this.$.ajax.url = this.basePath + 'rest/strolch/inspector/' + this.realm + '/' + this.objectType + '/' + this.selectedType;
2017-02-06 10:52:53 +01:00
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>