make indentation consistent

This commit is contained in:
j3d1 2023-11-27 01:14:52 +01:00
parent d52575aa42
commit 9f63414ba2
27 changed files with 858 additions and 804 deletions

View file

@ -1,22 +1,22 @@
<template>
<div class="input-group-append">
<div class="input-group-append">
<span
class="input-group-text"
data-toggle="tooltip"
data-placement="top"
:title="type"
>{{ type[0] }}</span>
<button
type="button"
class="btn"
:class="'btn-' + color"
data-toggle="tooltip"
data-placement="top"
:title="tooltip"
>
<font-awesome-icon :icon="icon"/>
</button>
</div>
<button
type="button"
class="btn"
:class="'btn-' + color"
data-toggle="tooltip"
data-placement="top"
:title="tooltip"
>
<font-awesome-icon :icon="icon"/>
</button>
</div>
</template>
<script>
@ -24,27 +24,27 @@ import $ from 'jquery';
import 'bootstrap/js/dist/tooltip';
export default {
name: 'Addon',
props: [ 'type', 'isValid' ],
mounted() {
$('[data-toggle="tooltip"]').tooltip();
},
computed: {
icon() {
if (this.isValid == undefined) return 'pen';
if (this.isValid == false) return 'times';
return 'check';
name: 'Addon',
props: ['type', 'isValid'],
mounted() {
$('[data-toggle="tooltip"]').tooltip();
},
color() {
if (this.isValid == undefined) return 'info';
if (this.isValid == false) return 'danger';
return 'success';
},
tooltip() {
if (this.isValid == undefined) return 'no data validation';
if (this.isValid == false) return 'data invalid';
return 'data valid';
computed: {
icon() {
if (this.isValid == undefined) return 'pen';
if (this.isValid == false) return 'times';
return 'check';
},
color() {
if (this.isValid == undefined) return 'info';
if (this.isValid == false) return 'danger';
return 'success';
},
tooltip() {
if (this.isValid == undefined) return 'no data validation';
if (this.isValid == false) return 'data invalid';
return 'data valid';
}
}
}
};
</script>

View file

@ -7,7 +7,8 @@
class="btn btn-outline-secondary dropdown-toggle"
type="button"
data-toggle="dropdown"
>Search</button>
>Search
</button>
<div class="dropdown-menu">
<a
v-for="(option, index) in sortedOptions"
@ -16,20 +17,20 @@
@click="setInternalValue(option)"
:class="{ active: option == selectedOption }"
>
{{ option[nameKey] }}
{{ option[nameKey] }}
</a>
</div>
</div>
<input type="text" class="form-control" :id="label" v-model="internalName">
<div class="input-group-append">
<button
class="btn"
:class="{ 'btn-info disabled': isValid, 'btn-success': !isValid }"
v-if="!isValid"
@click="addOption()"
>
<font-awesome-icon icon="plus"/>
</button>
<button
class="btn"
:class="{ 'btn-info disabled': isValid, 'btn-success': !isValid }"
v-if="!isValid"
@click="addOption()"
>
<font-awesome-icon icon="plus"/>
</button>
</div>
<Addon type="Combo Box" :is-valid="isValid"/>
</div>
@ -40,37 +41,40 @@
import Addon from './Addon';
export default {
name: 'InputCombo',
components: {Addon},
props: [ 'label', 'model', 'nameKey', 'uniqueKey', 'options', 'onOptionAdd' ],
data: ({ options, model, nameKey, uniqueKey }) => ({
internalName: model[nameKey],
selectedOption: options.filter(e => e[uniqueKey] == model[uniqueKey])[0],
addingOption: false
}),
computed: {
isValid: ({options, nameKey, internalName}) => options.some(e => e[nameKey] == internalName),
sortedOptions: ({options, nameKey}) => options.sort((a, b) => a[nameKey].localeCompare(b[nameKey], 'en', { numeric: true })),
},
watch: {
internalName(newValue) {
if (this.isValid) {
if(!this.selectedOption || newValue!=this.selectedOption[this.nameKey]){
this.selectedOption = this.options.filter(e => e[this.nameKey] === newValue)[0];
}
this.model[this.nameKey] = this.selectedOption[this.nameKey];
this.model[this.uniqueKey] = this.selectedOption[this.uniqueKey];
}
}
},
methods: {
setInternalValue(option) {
this.selectedOption = option;
this.internalName = option[this.nameKey];
name: 'InputCombo',
components: {Addon},
props: ['label', 'model', 'nameKey', 'uniqueKey', 'options', 'onOptionAdd'],
data: ({options, model, nameKey, uniqueKey}) => ({
internalName: model[nameKey],
selectedOption: options.filter(e => e[uniqueKey] == model[uniqueKey])[0],
addingOption: false
}),
computed: {
isValid: ({options, nameKey, internalName}) => options.some(e => e[nameKey] == internalName),
sortedOptions: ({
options,
nameKey
}) => options.sort((a, b) => a[nameKey].localeCompare(b[nameKey], 'en', {numeric: true})),
},
addOption() {
this.onOptionAdd({[this.nameKey]: this.internalName});
watch: {
internalName(newValue) {
if (this.isValid) {
if (!this.selectedOption || newValue != this.selectedOption[this.nameKey]) {
this.selectedOption = this.options.filter(e => e[this.nameKey] === newValue)[0];
}
this.model[this.nameKey] = this.selectedOption[this.nameKey];
this.model[this.uniqueKey] = this.selectedOption[this.uniqueKey];
}
}
},
methods: {
setInternalValue(option) {
this.selectedOption = option;
this.internalName = option[this.nameKey];
},
addOption() {
this.onOptionAdd({[this.nameKey]: this.internalName});
}
}
}
};
</script>

View file

@ -25,7 +25,7 @@
</label>
<input type="file" id="file" accept="image/png" class="d-none" @change="onFileChange($event)">
<button v-if="!capturing" class="btn my-2 ml-auto btn-secondary" @click="openStream()">
<font-awesome-icon icon="camera"/>
<font-awesome-icon icon="camera"/>
</button>
<div v-if="capturing" class="btn-group my-2 ml-auto">
<button class="btn btn-success" @click="captureVideoImage()">
@ -44,80 +44,84 @@
</template>
<script>
import { mapMutations } from 'vuex';
import {mapMutations} from 'vuex';
export default {
name: 'InputPhoto',
props: [ 'model', 'field', 'onCapture' ],
data: () => ({
capturing: false,
streaming: false,
stream: undefined,
dataImage: undefined
}),
methods: {
...mapMutations(['createToast']),
openStream() {
if (!this.capturing) {
this.capturing = true;
this.streaming = false;
navigator.mediaDevices.getUserMedia({video: { facingMode: "environment" }, audio: false}).then(stream => {
this.stream = stream;
const { video } = this.$refs;
video.srcObject = stream;
video.play();
video.addEventListener('canplay', () => {
this.streaming = true;
}, false);
}).catch(err => console.log(err)); // todo: toast error
}
name: 'InputPhoto',
props: ['model', 'field', 'onCapture'],
data: () => ({
capturing: false,
streaming: false,
stream: undefined,
dataImage: undefined
}),
methods: {
...mapMutations(['createToast']),
openStream() {
if (!this.capturing) {
this.capturing = true;
this.streaming = false;
navigator.mediaDevices.getUserMedia({video: {facingMode: "environment"}, audio: false}).then(stream => {
this.stream = stream;
const {video} = this.$refs;
video.srcObject = stream;
video.play();
video.addEventListener('canplay', () => {
this.streaming = true;
}, false);
}).catch(err => console.log(err)); // todo: toast error
}
},
captureVideoImage() {
const {video, canvas} = this.$refs;
const context = canvas.getContext('2d');
const {videoWidth, videoHeight} = video;
canvas.width = videoWidth;
canvas.height = videoHeight;
context.drawImage(video, 0, 0, videoWidth, videoHeight);
this.dataImage = canvas.toDataURL('image/png');
this.onCapture(this.dataImage);
this.closeStream();
},
closeStream() {
if (this.capturing) {
this.stream.getTracks().forEach(s => s.stop());
this.capturing = false;
this.streaming = false;
}
},
onFileChange({target}) {
const file = target.files[0];
var reader = new FileReader();
reader.readAsDataURL(file);
const self = this;
reader.onload = function () {
self.dataImage = reader.result;
self.onCapture(self.dataImage);
self.closeStream();
};
reader.onerror = function (error) {
this.createToast({
title: 'Error: Failed to parse image file',
message: error.toString(),
color: 'danger'
});
console.log('Error: ', error);
};
}
},
captureVideoImage() {
const { video, canvas } = this.$refs;
const context = canvas.getContext('2d');
const { videoWidth, videoHeight } = video;
canvas.width = videoWidth;
canvas.height = videoHeight;
context.drawImage(video, 0, 0, videoWidth, videoHeight);
this.dataImage = canvas.toDataURL('image/png');
this.onCapture(this.dataImage);
this.closeStream();
mounted() {
if (!this.model[this.field])
this.openStream();
},
closeStream() {
if (this.capturing) {
this.stream.getTracks().forEach(s => s.stop());
this.capturing = false;
this.streaming = false;
}
},
onFileChange({ target }) {
const file = target.files[0];
var reader = new FileReader();
reader.readAsDataURL(file);
const self = this;
reader.onload = function () {
self.dataImage = reader.result;
self.onCapture(self.dataImage);
self.closeStream();
};
reader.onerror = function (error) {
this.createToast({ title: 'Error: Failed to parse image file', message: error.toString(), color: 'danger' });
console.log('Error: ', error);
};
beforeDestroy() {
this.closeStream();
}
},
mounted() {
if (!this.model[this.field])
this.openStream();
},
beforeDestroy() {
this.closeStream();
}
};
</script>
<style>
.img-preview{
.img-preview {
max-height: 30vh;
}
}
</style>

View file

@ -13,17 +13,17 @@
import Addon from './Addon';
export default {
name: 'InputString',
components: { Addon },
props: [ 'label', 'model', 'field', 'validationFn' ],
computed: {
hasValidationFn({ validationFn }) {
return validationFn != undefined;
},
isValid({ model, field, validationFn, hasValidationFn }) {
if (!hasValidationFn) return true;
return validationFn(model[field]);
name: 'InputString',
components: {Addon},
props: ['label', 'model', 'field', 'validationFn'],
computed: {
hasValidationFn({validationFn}) {
return validationFn != undefined;
},
isValid({model, field, validationFn, hasValidationFn}) {
if (!hasValidationFn) return true;
return validationFn(model[field]);
}
}
}
};
</script>