Added some basic form checks
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pünkösd Marcell 2020-12-08 01:31:56 +01:00
parent 5757713f7e
commit f5ad932b12
2 changed files with 46 additions and 13 deletions

View File

@ -3,8 +3,8 @@
<md-dialog :md-active.sync="show.editor"> <md-dialog :md-active.sync="show.editor">
<md-dialog-title>{{ capitalizedType }} preferences</md-dialog-title> <md-dialog-title>{{ capitalizedType }} preferences</md-dialog-title>
<form novalidate class="editor-form" @submit.prevent="saveEdit">
<form class="editor-form">
<div v-if="type === 'ingest' && apiId !== null"> <div v-if="type === 'ingest' && apiId !== null">
@ -30,16 +30,25 @@
<md-field> <md-field>
<label>Width</label> <label>Width</label>
<md-input type="number" v-model="editorData.width"></md-input> <md-input type="number" v-model="editorData.width"></md-input>
<md-icon class="md-accent" v-if="show.mistakes && (!editorData.width || editorData.width <= 0)">
report_problem
</md-icon>
</md-field> </md-field>
<md-field> <md-field>
<label>Height</label> <label>Height</label>
<md-input type="number" v-model="editorData.height"></md-input> <md-input type="number" v-model="editorData.height"></md-input>
<md-icon class="md-accent" v-if="show.mistakes && (!editorData.height || editorData.height <= 0)">
report_problem
</md-icon>
</md-field> </md-field>
<md-field> <md-field>
<label>Bitrate</label> <label>Bitrate</label>
<md-input type="number" v-model="editorData.bitrate"></md-input> <md-input type="number" v-model="editorData.bitrate"></md-input>
<md-icon class="md-accent" v-if="show.mistakes && (!editorData.bitrate || editorData.bitrate <= 0)">
report_problem
</md-icon>
</md-field> </md-field>
@ -49,6 +58,7 @@
<md-field> <md-field>
<label>URL</label> <label>URL</label>
<md-input v-model="editorData.url"></md-input> <md-input v-model="editorData.url"></md-input>
<md-icon class="md-accent" v-if="show.mistakes && (!restreamerValid)">report_problem</md-icon>
</md-field> </md-field>
<md-field> <md-field>
@ -61,11 +71,11 @@
</form> </form>
<md-dialog-actions> <md-dialog-actions>
<md-button @click="show.editor = false">{{ discardButtonLabel }}</md-button> <md-button @click.prevent="show.editor = false">{{ discardButtonLabel }}</md-button>
<md-button class="md-primary" @click="saveEdit" v-if="type !== 'ingest'">Save</md-button> <md-button @click.prevent="saveEdit" class="md-primary" type="submit" v-if="type !== 'ingest'">Save</md-button>
</md-dialog-actions> </md-dialog-actions>
</md-dialog> </md-dialog>
<div class="flowchart-node" :style="nodeStyle" <div class="flowchart-node" :style="nodeStyle"
@ -185,7 +195,8 @@ export default {
return { return {
show: { show: {
delete: false, delete: false,
editor: false editor: false,
mistakes: false
}, },
editorData: {} editorData: {}
} }
@ -218,6 +229,15 @@ export default {
} else { } else {
return "DISCARD"; return "DISCARD";
} }
},
restreamerValid() {
let pattern = new RegExp('^((https?|rtmp):\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
return !!pattern.test(this.editorData.url);
} }
}, },
@ -247,9 +267,22 @@ export default {
this.show.editor = true; this.show.editor = true;
}, },
saveEdit() { saveEdit() {
let form_valid = true;
if (this.type === 'encoder') {
form_valid = this.editorData.width && this.editorData.height && this.editorData.bitrate &&
(this.editorData.width > 0) && (this.editorData.height > 0) && (this.editorData.bitrate > 0);
} else if (this.type === 'restreamer') {
form_valid = this.restreamerValid;
}
if (form_valid) {
this.show.editor = false; this.show.editor = false;
this.show.mistakes = false;
this.$emit('update:data', this.editorData); this.$emit('update:data', this.editorData);
this.$emit("dataUpdated", this.data); this.$emit("dataUpdated", this.data);
} else {
this.show.mistakes = true;
}
} }
} }
} }

View File

@ -80,14 +80,14 @@ export default {
case "ingest": case "ingest":
newNode.data = { newNode.data = {
url: "", url: "",
streamkey: "demokey" streamkey: ""
} }
break; break;
case "encoder": case "encoder":
newNode.data = { newNode.data = {
bitrate: 0, bitrate: 2500,
width: 0, width: 1280,
height: 0 height: 720
} }
break; break;
case "restreamer": case "restreamer":