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

546 lines
24 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-icon-button/paper-icon-button.html">
<link rel="import" href="../paper-header-panel/paper-header-panel.html">
<link rel="import" href="../iron-ajax/iron-ajax.html">
2017-02-06 18:13:36 +01:00
<link rel="import" href="../iron-pages/iron-pages.html">
2017-02-06 10:52:53 +01:00
<link rel="import" href="../paper-styles/color.html">
<link rel="import" href="../paper-styles/default-theme.html">
<link rel="import" href="../paper-styles/shadow.html">
<link rel="import" href="../paper-styles/typography.html">
2017-02-06 10:52:53 +01:00
<link rel="import" href="../strolch-wc-styles/strolch-wc-styles.html">
2017-02-06 10:52:53 +01:00
<dom-module id="strolch-wc-inspector-object">
<template>
<style is="strolch-wc-styles">
2017-02-06 10:52:53 +01:00
:host {
display: block;
}
.card {
padding: 1.0em;
margin: 1.0em;
cursor: pointer;
}
2017-02-08 12:18:50 +01:00
.title-bar {
background-color: var(--google-grey-300);
color: var(--google-grey-700);
}
.title {
padding: 8px;
background-color: rgb(224, 224, 224);
color: rgb(97, 97, 97);
font-size: 16px;
2017-02-08 12:18:50 +01:00
font-weight: 400;
line-height: 1.3;
margin: 0;
}
.sub {
font-size: small;
}
.table-title {
margin-bottom: 0;
2017-02-06 10:52:53 +01:00
padding: 0;
}
2017-02-06 18:13:36 +01:00
paper-material {
border-radius: 2px;
background-color: #ffffff;
}
paper-tabs {
2017-02-08 12:18:50 +01:00
border-top: solid #7F7F7F 1px;
2017-02-06 18:13:36 +01:00
--paper-tabs-selection-bar-color: var(--paper-amber-600);
background-color: #ffffff;
color: #000000;
}
2017-02-06 10:52:53 +01:00
</style>
<paper-material class="g-card g-m-3 g-mt-4" elevation="1">
2017-02-06 10:52:53 +01:00
2017-02-08 12:18:50 +01:00
<div class="g-container">
<div class="g-row title-bar" on-tap="_toggleExpanded">
2017-02-06 18:13:36 +01:00
2017-02-08 12:18:50 +01:00
<div class="g-11">
<h1 class="title"><span style="text-transform: uppercase">[[summary.objectType]]</span> <span
class="sub g-ml-4">Id:</span> [[summary.id]] <span class="sub g-ml-4">Name:</span>
[[summary.name]] <span class="sub g-ml-4">Type:</span>
[[summary.type]] </h1>
2017-02-08 12:18:50 +01:00
</div>
2017-02-06 18:13:36 +01:00
2017-02-08 12:18:50 +01:00
<div class="g-1">
<paper-icon-button id="expandedIcon" icon="expand-more"></paper-icon-button>
</div>
2017-02-06 18:13:36 +01:00
2017-02-08 12:18:50 +01:00
</div>
<div class="g-row">
<div class="g-12">
2017-02-06 18:13:36 +01:00
<!-- Tabs -->
2017-02-08 12:18:50 +01:00
<template is="dom-if" if="[[expanded]]">
<paper-tabs selected="{{selectedDetailType}}"
attr-for-selected="name"
fallback-selection="none">
<paper-tab name="details">Details</paper-tab>
2017-02-08 12:18:50 +01:00
<paper-tab name="parameters">Parameters</paper-tab>
<paper-tab name="policies">Policies</paper-tab>
<template is="dom-if" if="[[_isResource(summary.objectType)]]">
2017-02-08 12:18:50 +01:00
<paper-tab name="timedstates">Timed States</paper-tab>
2017-02-06 18:13:36 +01:00
</template>
<template is="dom-if" if="[[_isActivity(summary.objectType)]]">
<paper-tab name="elements">Elements</paper-tab>
</template>
2017-02-08 12:18:50 +01:00
</paper-tabs>
2017-02-06 18:13:36 +01:00
</template>
<!-- Tab sections -->
2017-02-08 12:18:50 +01:00
<iron-pages selected="[[selectedDetailType]]" attr-for-selected="name">
2017-02-06 18:13:36 +01:00
<!-- details -->
<section name="details" class="g-p-2 g-pt-0">
<template is="dom-if" if="[[!details]]">
<p class="g-center">Loading...</p>
</template>
<template is="dom-if" if="[[details]]">
<div class="g-row">
<div class="g-6">
<dl class="g-dl">
<dt>Id</dt>
<dd>[[details.id]]</dd>
<dt>Name</dt>
<dd>[[details.name]]</dd>
<dt>Type</dt>
<dd>[[details.type]]</dd>
</dl>
<template is="dom-if"
if="[[_isActivity(details.objectType)]]"
restamp="true">
<dl class="g-dl">
<dt>State</dt>
<dd>[[details.state]]</dd>
<dt>TimeOrdering</dt>
<dd>[[details.timeOrdering]]</dd>
<dt>Start</dt>
<dd>[[_formatDate(details.start)]]</dd>
<dt>End</dt>
<dd>[[_formatDate(details.end)]]</dd>
</dl>
</template>
<template is="dom-if" if="[[_isOrder(details.objectType)]]" restamp="true">
<dl class="g-dl">
<dt>State</dt>
<dd>[[details.state]]</dd>
<dt>Date</dt>
<dd>[[_formatDate(details.date)]]</dd>
</dl>
</template>
<template is="dom-if" if="[[_isAction(details.objectType)]]" restamp="true">
<dl class="g-dl">
<dt>State</dt>
<dd>[[details.state]]</dd>
<dt>Start</dt>
<dd>[[_formatDate(details.start)]]</dd>
<dt>End</dt>
<dd>[[_formatDate(details.end)]]</dd>
<dt>Resource Type</dt>
<dd>[[details.resourceType]]</dd>
<dt>Resource Id</dt>
<dd>[[details.resourceId]]</dd>
</dl>
</template>
</div>
<div class="g-6">
<template is="dom-if" if="[[details.version]]" restamp="true">
<dl class="g-dl">
<dt>CreatedAt</dt>
<dd>[[_formatDate(details.version.createdAt)]]</dd>
<dt>CreatedBy</dt>
<dd>[[details.version.createdBy]]</dd>
<dt>Deleted</dt>
<dd>[[details.version.deleted]]</dd>
<dt>Version</dt>
<dd>[[details.version.version]]</dd>
</dl>
</template>
</div>
</div>
</template>
</section>
2017-02-08 12:18:50 +01:00
<!-- parameters -->
<section name="parameters" class="g-p-2 g-pt-0">
<template is="dom-if" if="[[!details]]">
<p class="g-center">Loading...</p>
</template>
<template is="dom-if" if="[[details]]">
2017-02-06 18:13:36 +01:00
2017-02-08 12:18:50 +01:00
<template is="dom-if" if="[[_isEmpty(details.parameterBags)]]">
<p class="g-center">No parameters defined on [[summary.objectType]]
[[summary.id]]</p>
2017-02-08 12:18:50 +01:00
</template>
<template is="dom-if" if="[[_isNotEmpty(details.parameterBags)]]">
2017-02-06 18:13:36 +01:00
2017-02-08 12:18:50 +01:00
<table class="g-table">
<thead>
2017-02-06 18:13:36 +01:00
<tr>
2017-02-08 12:18:50 +01:00
<th>ParameterBag</th>
<th>Parameter Id</th>
<th>Name</th>
<th>Interpretation</th>
<th>UOM</th>
<th>Type</th>
<th>Value</th>
2017-02-06 18:13:36 +01:00
</tr>
2017-02-08 12:18:50 +01:00
</thead>
<tbody>
<template is="dom-repeat"
items="{{_asArray(details.parameterBags)}}"
as="bag">
<template is="dom-repeat"
items="{{_asArray(bag.value.parameters)}}"
as="param">
<tr>
<td>[[bag.value.id]]</td>
<td>[[param.value.id]]</td>
<td>[[param.value.name]]</td>
<td>[[param.value.interpretation]]</td>
<td>[[param.value.uom]]</td>
<td>[[param.value.type]]</td>
<td>[[param.value.value]]</td>
</tr>
</template>
</template>
2017-02-06 18:13:36 +01:00
</tbody>
</table>
2017-02-08 12:18:50 +01:00
</template>
</template>
</section>
<!-- policies -->
<section name="policies" class="g-p-2 g-pt-0">
<template is="dom-if" if="[[!details]]">
<p class="g-m-4 g-center">Loading...</p>
</template>
<template is="dom-if" if="[[details]]">
2017-02-06 18:13:36 +01:00
2017-02-08 12:18:50 +01:00
<template is="dom-if" if="[[_isEmpty(details.policies)]]">
<p class="g-pt-4 g-center">No policies defined on [[objectName]]
[[summary.id]]</p>
</template>
<template is="dom-if" if="[[_isNotEmpty(details.policies)]]">
<table class="g-table">
2017-02-06 18:13:36 +01:00
<thead>
<tr>
2017-02-08 12:18:50 +01:00
<th>Type</th>
2017-02-06 18:13:36 +01:00
<th>Value</th>
</tr>
</thead>
2017-02-08 12:18:50 +01:00
2017-02-06 18:13:36 +01:00
<tbody>
2017-02-08 12:18:50 +01:00
2017-02-06 18:13:36 +01:00
<template is="dom-repeat"
2017-02-08 12:18:50 +01:00
items="{{_asArray(details.policies)}}"
as="policy">
2017-02-06 18:13:36 +01:00
<tr>
2017-02-08 12:18:50 +01:00
<td>[[policy.key]]</td>
<td>[[policy.value]]</td>
2017-02-06 18:13:36 +01:00
</tr>
2017-02-08 12:18:50 +01:00
2017-02-06 18:13:36 +01:00
</template>
2017-02-08 12:18:50 +01:00
2017-02-06 18:13:36 +01:00
</tbody>
</table>
2017-02-08 12:18:50 +01:00
</template>
2017-02-06 18:13:36 +01:00
</template>
2017-02-08 12:18:50 +01:00
</section>
<!-- timedstates -->
<template is="dom-if" if="[[_isResource(summary.objectType)]]">
2017-02-08 12:18:50 +01:00
<section name="timedstates" class="g-p-2 g-pt-0">
<template is="dom-if" if="[[!details]]">
<p class="g-center">Loading...</p>
</template>
<template is="dom-if" if="[[details]]">
<template is="dom-if" if="[[_isEmpty(details.timedStates)]]">
<p class="g-pt-4 g-center">No timed states defined on [[objectName]]
[[summary.id]]</p>
</template>
<template is="dom-if" if="[[_isNotEmpty(details.timedStates)]]">
<template is="dom-repeat"
items="[[_asArray(details.timedStates)]]"
as="timedState">
<paper-material class="g-card" elevation="1">
<table class="g-table table-title">
<tbody>
<tr>
<td><b>Id</b> [[timedState.value.id]]</td>
<td><b>Name</b> [[timedState.value.name]]</td>
<td><b>Type</b> [[timedState.value.type]]</td>
</tr>
</tbody>
</table>
<table class="g-table">
<thead>
<tr>
<th>Time</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<template is="dom-repeat"
items="[[timedState.value.values]]"
as="timedStateValue">
<tr>
<td>[[timedStateValue.time]]</td>
<td>[[timedStateValue.value]]</td>
</tr>
</template>
</tbody>
</table>
</paper-material>
</template>
</template>
</template>
</section>
2017-02-06 18:13:36 +01:00
</template>
<!-- activity children -->
<template is="dom-if" if="[[_isActivity(summary.objectType)]]">
<section name="elements" class="g-p-2 g-pt-0">
<template is="dom-if" if="[[!details]]">
<p class="g-center">Loading...</p>
</template>
<template is="dom-if" if="[[details]]">
<template is="dom-repeat" items="[[details.elements]]" as="childElement">
<strolch-wc-inspector-object base-path="[[basePath]]"
app="[[app]]"
realm="[[realm]]"
details="[[childElement]]"
summary="[[childElement]]"
class="g-m-2"></strolch-wc-inspector-object>
</template>
</template>
</section>
</template>
2017-02-08 12:18:50 +01:00
</iron-pages>
2017-02-06 18:13:36 +01:00
2017-02-08 12:18:50 +01:00
</div>
</div>
</div>
2017-02-06 10:52:53 +01:00
</paper-material>
<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-object',
properties: {
app: {
type: Object,
value: function () {
return null;
}
},
basePath: {
type: String,
value: './'
},
2017-02-06 10:52:53 +01:00
realm: {
2017-02-06 18:13:36 +01:00
type: String,
2017-02-06 10:52:53 +01:00
value: function () {
return null;
}
},
summary: {
type: Object,
value: function () {
return null;
}
},
details: {
type: Object,
value: function () {
return null;
}
},
2017-02-06 18:13:36 +01:00
expanded: {
2017-02-06 10:52:53 +01:00
type: Boolean,
value: function () {
2017-02-06 18:13:36 +01:00
return false;
2017-02-06 10:52:53 +01:00
}
2017-02-06 18:13:36 +01:00
},
selectedDetailType: {
type: String,
value: function () {
return true;
},
observer: "selectedDetailTypeChanged"
2017-02-06 10:52:53 +01:00
}
},
_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;
}
},
2017-02-06 18:13:36 +01:00
_isResource: function (objectType) {
return objectType == 'Resource';
2017-02-06 18:13:36 +01:00
},
_isOrder: function (objectType) {
return objectType == 'Order';
2017-02-06 10:52:53 +01:00
},
2017-02-06 18:13:36 +01:00
_isActivity: function (objectType) {
return objectType == 'Activity';
2017-02-06 10:52:53 +01:00
},
_isAction: function (objectType) {
return objectType == 'Action';
2017-02-08 12:18:50 +01:00
},
2017-02-06 18:13:36 +01:00
_isEmpty: function (obj) {
if (obj == null)
return true;
if (obj instanceof Array) {
return obj.length == 0;
} else if (obj instanceof Object) {
return Object.keys(obj).length == 0;
}
return true;
},
_isNotEmpty: function (obj) {
return !this._isEmpty(obj);
2017-02-06 10:52:53 +01:00
},
2017-02-06 18:13:36 +01:00
_asArray: function (obj) {
if (!obj)
return [];
2017-02-06 10:52:53 +01:00
return Object.keys(obj).map(function (key) {
2017-02-06 18:13:36 +01:00
return {
key: key,
value: obj[key]
};
2017-02-06 10:52:53 +01:00
});
},
2017-02-08 12:18:50 +01:00
_formatDate: function (date) {
return Strolch.toDateTime(date);
},
2017-02-06 18:13:36 +01:00
_toggleExpanded: function (evt) {
this.expanded = !this.expanded;
this.$.expandedIcon.icon = this.expanded ? 'expand-less' : 'expand-more';
if (!this.expanded) {
this.selectedDetailType = null;
}
},
2017-02-06 10:52:53 +01:00
2017-02-06 18:13:36 +01:00
selectedDetailTypeChanged: function (newValue, oldValue) {
if (newValue != null) {
console.log('Selected detail type changed from ' + oldValue + " to " + newValue);
2017-02-06 18:13:36 +01:00
this.reloadDetails();
2017-02-06 10:52:53 +01:00
}
},
reloadDetails: function () {
if (this.details != null)
return;
2017-02-06 10:52:53 +01:00
this._handleAjaxResponse = function (data) {
this.details = data.detail.response;
console.log(this.objectType);
console.log(this.details);
2017-02-06 10:52:53 +01:00
};
this.$.ajax.url = this.basePath + 'rest/strolch/inspector/' + this.realm + '/' + this._typeSubPath(this.summary.objectType) + '/' + this.summary.type + '/' + this.summary.id;
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>