Skip to content

Commit

Permalink
- Added validation on Update/Create button
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrykb0802 committed Sep 7, 2023
1 parent b7917f2 commit 787144a
Showing 1 changed file with 47 additions and 46 deletions.
93 changes: 47 additions & 46 deletions scadalts-ui/src/components/datasources/MetaDataSource/point.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<v-select
v-model="datapoint.pointLocator.dataTypeId"
:items="datapointTypes"
@change="validateScript"
@change="validateScript"
></v-select>

</template>
<!-- Binary -->
<v-row v-if="datapoint.pointLocator.dataTypeId === DataTypes.BINARY">
Expand Down Expand Up @@ -316,31 +316,31 @@
</table>
</v-col>
</v-row>
<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-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-col>
<div v-if="this.validScript && this.resultMessage !== '' ">
<v-alert title="Script is valid" type="success">
Script results: {{this.resultMessage}}
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}}
</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-div>
<v-row>
<v-col :cols="datapoint.pointLocator.updateEvent === 'START_OF_CRON' ? 3 : 6">
<v-select
Expand Down Expand Up @@ -459,10 +459,10 @@ export default {
executionDelayPeriodType: "SECONDS"
}
},
validScript: true,
resultMessage: "",
validScript: true,
resultMessage: "",
ruleNotNull: (v) => !!v || this.$t('validation.rule.notNull'),
ruleValidScript: () => this.validScript || this.resultMessage,
ruleValidScript: () => this.validScript || this.resultMessage,
};
},
Expand Down Expand Up @@ -530,11 +530,12 @@ export default {
this.$emit('canceled');
},
save() {
async save() {
console.debug('VirtualDataSource.point.vue::save()');
if (this.validScript)
this.$emit('saved', this.datapoint);
},
await this.validateScript();
if (this.validScript)
this.$emit('saved', this.datapoint);
},
addMsValue(array) {
array.push(this.multistateValue);
Expand All @@ -555,24 +556,24 @@ 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;
}
} catch (e) {
console.log('error:' + e);
}
},
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

0 comments on commit 787144a

Please sign in to comment.