[Fix] keep selected type on refresh

This commit is contained in:
Robert von Burg 2018-10-15 12:54:32 +02:00
parent b0f9ec4bdc
commit e8ab8a46f0
2 changed files with 46 additions and 11 deletions

View File

@ -334,7 +334,6 @@
this.section = 'typesSummary';
this.selectedType = null;
this.objects = null;
Strolch.setQueryParamValue('type', null);
},
_noElements: function (objectSummaries) {
@ -342,8 +341,13 @@
},
_showTypeDetails: function (evt) {
this.selectedType = evt.model.item.type;
this.section = 'typeDetails';
this.offset = 0;
this.selectType(evt.model.item.type);
},
selectType: function (type) {
this.selectedType = type;
this.section = type == null ? 'typesSummary' : 'typeDetails';
this.objects = null;
console.log('Showing type ' + this.selectedType);
Strolch.setQueryParamValue('type', this.selectedType);
@ -514,8 +518,8 @@
},
reload: function () {
show: function () {
Strolch.setQueryParamValue('type', this.selectedType);
},
_handleAjaxResponse: function (evt) {

View File

@ -150,19 +150,22 @@
<div class="g-12">
<iron-pages selected="{{selectedObjectType}}" attr-for-selected="name">
<section name="Resource">
<strolch-wc-inspector-objects base-path="[[basePath]]"
<strolch-wc-inspector-objects id="resourcesInspector"
base-path="[[basePath]]"
realm="[[selectedRealm]]"
object-type="Resource"
object-summaries="[[resources]]"></strolch-wc-inspector-objects>
</section>
<section name="Order">
<strolch-wc-inspector-objects base-path="[[basePath]]"
<strolch-wc-inspector-objects id="ordersInspector"
base-path="[[basePath]]"
realm="[[selectedRealm]]"
object-type="Order"
object-summaries="[[orders]]"></strolch-wc-inspector-objects>
</section>
<section name="Activity">
<strolch-wc-inspector-objects base-path="[[basePath]]"
<strolch-wc-inspector-objects id="activitiesInspector"
base-path="[[basePath]]"
realm="[[selectedRealm]]"
object-type="Activity"
object-summaries="[[activities]]"></strolch-wc-inspector-objects>
@ -313,6 +316,9 @@
if (newValue != null) {
console.log('Selected object type changed from ' + oldValue + " to " + newValue);
Strolch.setQueryParamValue('objectType', newValue);
if (oldValue != null && newValue != oldValue) {
Strolch.setQueryParamValue('type', null);
}
this.reloadSelectedObjectType();
}
},
@ -474,21 +480,46 @@
return;
}
if (this.selectedObjectType == 'Resource' && this.resources != null) return;
if (this.selectedObjectType == 'Order' && this.orders != null) return;
if (this.selectedObjectType == 'Activity' && this.activities != null) return;
if (this.selectedObjectType == 'Resource' && this.resources != null) {
this.$$('#resourcesInspector').show();
return;
}
if (this.selectedObjectType == 'Order' && this.orders != null) {
this.$$('#ordersInspector').show();
return;
}
if (this.selectedObjectType == 'Activity' && this.activities != null) {
this.$$('#activitiesInspector').show();
return;
}
var typeToSelect = Strolch.getQueryParamValue('type');
function hasType(type, list) {
for (var i = 0; i < list.length; i++) {
if (list[i].type == type)
return true;
}
return false;
}
this._handleAjaxResponse = function (data) {
switch (data.detail.response.objectType) {
case 'Resource':
this.resources = data.detail.response;
this.$$('#resourcesInspector').selectType(hasType(typeToSelect, this.resources.types) ? typeToSelect : null);
break;
case 'Order':
this.orders = data.detail.response;
this.$$('#ordersInspector').selectType(hasType(typeToSelect, this.orders.types) ? typeToSelect : null);
break;
case 'Activity':
this.activities = data.detail.response;
this.$$('#activitiesInspector').selectType(hasType(typeToSelect, this.activities.types) ? typeToSelect : null);
break;
default:
console.log('Unhandled object type: ' + data.detail.response.objectType);
}