Skip to content

Commit

Permalink
Merge pull request #2737 from SCADA-LTS/feature/#2384_Added_test_scri…
Browse files Browse the repository at this point in the history
…pt_in_Meta_Data_Source_on_new_UI

Feature/#2384 added test script in meta data source on new UI
  • Loading branch information
Limraj authored Oct 25, 2023
2 parents 10b3c97 + ee7c8c3 commit 824fc37
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
58 changes: 49 additions & 9 deletions scadalts-ui/src/components/datasources/MetaDataSource/point.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<v-select
v-model="datapoint.pointLocator.dataTypeId"
:items="datapointTypes"
@change="validateScript"
></v-select>

</template>
Expand Down Expand Up @@ -65,9 +66,7 @@
<v-text-field type="Number" label="Values" v-model="multistateValue">
<v-icon
slot="append"
@click="
addMsValue(datapoint.pointLocator.incrementMultistateChange.values)
"
@click="addMsValue(datapoint.pointLocator.incrementMultistateChange.values)"
>mdi-plus</v-icon
>
</v-text-field>
Expand Down Expand Up @@ -294,7 +293,7 @@
:placeholder="$t('scriptList.selectDatapoint')"
item-text="name"
v-model="selectedDatapointId"
@change="addDatapoint"
@change="addDatapoint(); validateScript();"
:items="filteredDatapoints"
></v-select>
</v-col>
Expand All @@ -309,22 +308,39 @@
<v-icon
color="red"
style="cursor: pointer; border: 0"
@click="removeDatapoint(p.dataPointXid)"
@click="removeDatapoint(p.dataPointXid); validateScript();"
>mdi-close</v-icon
>
</td>
</tr>
</table>
</v-col>
</v-row>

<v-textarea :rules="[ruleNotNull]"
<v-textarea :rules="[ruleNotNull, ruleValidScript]"
style="width: 100%; font-family: monospace"
:label="$t('scriptList.script')"
v-model="datapoint.pointLocator.script"
rows=3
@focusout="validateScript"
ref="scriptBodyTextarea"
required
error-count="0"
></v-textarea>
<v-col>
<v-btn block color="primary" @click="validateScript"
>{{ $t('script.runScript') }}
</v-btn>
</v-col>
<div v-if = "this.validScript && this.resultMessage !== '' ">
<v-alert title="Script is valid" type="success">
Script results: {{this.resultMessage}}
</v-alert>
</div>
<v-div v-if = "!this.validScript && this.resultMessage !== '' ">
<v-alert title = "Script error" type="error">
Script error: {{this.resultMessage}}
</v-alert>
</v-div>
<v-row>
<v-col :cols="datapoint.pointLocator.updateEvent === 'START_OF_CRON' ? 3 : 6">
<v-select
Expand Down Expand Up @@ -443,7 +459,10 @@ export default {
executionDelayPeriodType: "SECONDS"
}
},
validScript: true,
resultMessage: "",
ruleNotNull: (v) => !!v || this.$t('validation.rule.notNull'),
ruleValidScript: () => this.validScript || this.resultMessage,
};
},
Expand Down Expand Up @@ -511,9 +530,11 @@ export default {
this.$emit('canceled');
},
save() {
async save() {
console.debug('VirtualDataSource.point.vue::save()');
this.$emit('saved', this.datapoint);
await this.validateScript();
if (this.validScript)
this.$emit('saved', this.datapoint);
},
addMsValue(array) {
Expand All @@ -535,6 +556,25 @@ export default {
return;
}
},
async validateScript() {
try {
if (this.datapoint.pointLocator.script === ""){
this.validScript = false;
this.resultMessage = this.$t('validation.rule.notNull');
}
else {
let resp = await this.$store.dispatch('requestPost', {
url: `/datapoint/meta/test`,
data: this.datapoint.pointLocator
});
this.validScript = resp.success;
this.resultMessage = resp.message;
this.$refs.scriptBodyTextarea.validate();
}
} catch (e) {
console.log('error:' + e);
}
},
},
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion scadalts-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@
"event.audit.recip.list.9": "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}",
"event.audit.recip.mailingList": "mailing list '{0}'",
"event.audit.recip.user": "user '{0}'",
"event.audit.scheduledEvent": "Scheduled event",
"event.bacnet.covFailed": "COV subscription failed at {0}, point disabled: {1}",
"event.bacnet.deviceError": "No response from device at {0}, point init failed",
"event.bacnet.iamError": "IAm broadcast failure: {0}",
Expand Down Expand Up @@ -1054,6 +1053,7 @@
"userDetails.view.forceAdminTitle": "The function is enforced by the Admin",
"userDetails.view.enableFullScreen": "Enable full screen mode",
"userDetails.view.hideShortcutDisableFullScreen": "Hide shortcut to disable full screen",
"script.runScript": "Run script",
"systemsettings.event.pendingLimit": "Event Pending Limit",
"systemsettings.event.pendingCacheEnabled": "Enabled Event Pending Cache",
"systemsettings.workitems.reporting.enabled": "Work items reporting enabled",
Expand Down

0 comments on commit 824fc37

Please sign in to comment.