[Major] Remove virtual addresses, added action warning confirmation

This commit is contained in:
Robert von Burg 2020-02-05 12:46:10 +01:00
parent a90ad2dfd1
commit 3e8876b2ee
6 changed files with 66 additions and 100 deletions

View File

@ -1,7 +1,7 @@
{
"name": "strolch-wc-plc",
"description": "Strolch PLC WebComponents",
"version": "0.1.0",
"version": "0.2.0",
"authors": ["Robert von Burg"],
"keywords": [
"strolch",

View File

@ -30,9 +30,15 @@
"stop": "Stoppen",
"reconfigure": "Neu Konfigurieren",
"info": "Info",
"reconnect": "Wiederhestellen"
"reconnect": "Wiederhestellen",
"lastUpdate": "Letzte Aktualisierung",
"confirmActionWarning": "Aktionswarnung",
"confirmActionWarningMsg": "Beim Auslösen von Befehlen können Aktoren eingeschaltet werden. Wollen Sie diese Aktion wirklich ausführen?"
},
"en": {
"confirmActionWarning": "Action Warning",
"confirmActionWarningMsg": "Sending commands can turn on actuators. Do you really want to execute this action?",
"lastUpdate": "Last Update",
"info": "Info",
"start": "Start",
"stop": "Stop",

View File

@ -7,6 +7,10 @@
localesPath: {
type: String,
value: './locales.json'
},
warningConfirmed: {
type: Boolean,
value: false
}
},
@ -77,7 +81,29 @@
onRequestError: function (e) {
this.fire("strolch-ajax-request-error", e.detail);
}
},
confirmActionWarning: function (callback) {
var bound = callback.bind(this);
if (this.warningConfirmed) {
bound();
return;
}
var confirmedCallback = function (confirmed) {
if (confirmed) {
this.warningConfirmed = true;
bound();
}
}.bind(this);
this.fire("cx-show-confirmation", {
title: this.localize('confirmActionWarning'),
text: this.localize('confirmActionWarningMsg'),
callback: confirmedCallback,
bind: this
});
}
}
</script>

View File

@ -28,7 +28,7 @@
<style is="custom-style" include="strolch-wc-plc-style">
.label {
min-width: 250px;
min-width: 300px;
margin-right: 10px;
}
</style>
@ -111,7 +111,7 @@
<template is="dom-repeat" items="[[connection.parameters]]" as="param">
<div class="g-flex-table-row">
<div class="g-flex-table-cell label">[[param.id]]</div>
<div class="g-flex-table-cell label" title="[[param.id]]">[[param.name]]</div>
<div class="g-flex-table-cell">[[param.value]]</div>
</div>
</template>

View File

@ -33,7 +33,7 @@
</style>
<paper-card elevation="1">
<div class="header"><h3>[[device.name]]</h3></div>
<div class="header"><h3>[[device.description]]</h3></div>
<div class="card-content">
<div class="g-row">
@ -42,8 +42,10 @@
<template is="dom-repeat" items="[[addresses]]" as="address">
<div class="g-flex-table-row">
<div class="g-flex-table-cell address-field" title="[[address.id]]">
<div class="address">[[address.resource]] - [[address.action]]</div>
<div class="hw-address">[[address.address]]</div>
<div class="address">[[address.description]]</div>
<div class="hw-address">&nbsp;&nbsp;&nbsp;[[address.resource]] - [[address.action]]
</div>
<div class="hw-address">&nbsp;&nbsp;&nbsp;[[address.address]]</div>
</div>
<div class="g-flex-table-cell address-field no-grow">
<template is="dom-if" if="[[isBoolean(address.valueType)]]">
@ -251,6 +253,13 @@
},
sendAddress: function (type, resource, action, value) {
this.confirmActionWarning(function () {
this._sendAddress(type, resource, action, value);
});
},
_sendAddress: function (type, resource, action, value) {
console.log("Sending " + type + " for " + resource + " - " + action + ": " + value);
this.$.ajaxPutAddress.body = {
type: type,

View File

@ -31,62 +31,21 @@
<template>
<style is="custom-style" include="strolch-wc-plc-style">
h2 {
margin-bottom: 10px;
}
.actions {
padding: 0;
margin: 0;
}
</style>
<div class="actions">
<p>[[localize('lastUpdate')]]: [[lastUpdate]]</p>
<paper-icon-button class="g-pull-right" icon="refresh" on-tap="_refresh"></paper-icon-button>
</div>
<template is="dom-if" if="[[arrayFilled(virtualAddresses)]]">
<h2>[[localize('virtualAddresses')]]</h2>
<paper-card elevation="1">
<div class="card-content">
<div class="g-row">
<div class="g-12">
<template is="dom-repeat" items="[[virtualAddresses]]" as="address">
<div class="g-flex-table-row">
<div class="g-flex-table-cell address-field">
<div class="address">[[address.resource]] - [[address.action]]</div>
<div class="hw-address">[[address.address]]</div>
</div>
<div class="g-flex-table-cell no-grow value-cell">
<template is="dom-if" if="[[isBoolean(address.type)]]">
<paper-radio-group selected="{{address.value}}" attr-for-selected="name">
<paper-radio-button name="true">[[localize('on')]]
</paper-radio-button>
<paper-radio-button name="false">[[localize('off')]]
</paper-radio-button>
</paper-radio-group>
</template>
<template is="dom-if" if="[[isNumber(address.type)]]">
<paper-input class="value-input"
value="{{address.value}}"
no-label-float></paper-input>
</template>
<template is="dom-if" if="[[isString(address.type)]]">
<paper-input class="value-input"
value="{{address.value}}"
no-label-float></paper-input>
</template>
</div>
<div class="g-flex-table-cell no-grow">
<paper-button raised on-tap="sendAddressNotification">[[localize('notify')]]
</paper-button>
</div>
</div>
</template>
</div>
</div>
</div>
</paper-card>
</template>
<template is="dom-repeat" items="[[devicesByGroup]]" as="group">
<h2>[[group.name]]</h2>
@ -108,22 +67,6 @@
on-response="onGetDevicesResponse"
on-error="onRequestError"></iron-ajax>
<iron-ajax id="ajaxGetVirtualAddresses"
url="[[baseRestPath]]/plc/addresses/virtual"
content-type="application/json"
handle-as="json"
method="GET"
on-response="onGetVirtualAddressesResponse"
on-error="onRequestError"></iron-ajax>
<iron-ajax id="ajaxPutAddress"
url="[[baseRestPath]]/plc/addresses"
content-type="application/json"
handle-as="json"
method="PUT"
on-response="_refresh"
on-error="onAjaxError"></iron-ajax>
<strolch-wc-ws-observer id="observerHandler" ws-path="[[wsObserverPath]]"></strolch-wc-ws-observer>
</template>
@ -137,6 +80,12 @@
],
properties: {
lastUpdate: {
type: String,
value: function () {
return Strolch.toLocalDateTime(new Date());
}
},
observerHandler: {
type: Object,
value: function () {
@ -147,10 +96,6 @@
type: Boolean,
value: false
},
virtualAddresses: {
type: Array,
value: []
},
devicesByGroup: {
type: Array,
value: []
@ -166,39 +111,17 @@
/* Listeners */
onGetDevicesResponse: function (e) {
this.devicesByGroup = e.detail.response.data;
},
onGetVirtualAddressesResponse: function (e) {
this.virtualAddresses = e.detail.response.data;
},
sendAddressNotification: function (e) {
var a = e.model.address;
this.sendAddress("Notification", a.resource, a.action, a.value);
},
sendAddress: function (type, resource, action, value) {
console.log("Sending " + type + " for " + resource + " - " + action + ": " + value);
this.$.ajaxPutAddress.body = {
type: type,
resource: resource,
action: action,
value: value
};
this.$.ajaxPutAddress.generateRequest();
this.lastUpdate = Strolch.toLocalDateTime(new Date());
},
_refresh: function () {
this.$.ajaxGetDevices.generateRequest();
this.$.ajaxGetVirtualAddresses.generateRequest();
if (!this.registeredForUpdates) {
this.$.observerHandler.register("Resource", "PlcAddress", "strolch-wc-plc-logical-devices", true, this.handleUpdate.bind(this));
this.registeredForUpdates = true;
}
},
onAjaxError: function (e) {
this._refresh();
this.onRequestError(e);
},
/* Lifecycle */
reload: function () {
@ -210,6 +133,8 @@
for (var i = 0; i < elements.length; i++) {
this.observerHandler.notifyUpdate(objectType, type, elements[i].id, elements[i]);
}
this.lastUpdate = Strolch.toLocalDateTime(new Date());
}
});