Forms hinzugefügt

This commit is contained in:
R40fendt
2025-12-24 00:26:44 +01:00
parent 3576b88bf5
commit b5506cb44c
5 changed files with 493 additions and 331 deletions

View File

@@ -0,0 +1,93 @@
<script lang="ts" setup>
import RitzenbergenLib from "../ritzenbergenlib.ts";
import { defineProps, ref } from "vue";
const props = defineProps({
form: {
type: RitzenbergenLib.Formular,
required: true,
},
});
const form = props.form;
let results = ref([]);
fetch(
RitzenbergenLib.RitzenbergenLib.api(
"/formulare/get_results.php?id=" + form.id
)
)
.then((res) => res.json())
.then((data) => {
results.value = data;
});
const myfields = [];
form.fields.forEach((field: RitzenbergenLib.Field) => {
if (myfields.find((el) => el.name == field.name) == undefined) {
myfields.push(field);
}
});
function prettyResult(result: any) {
if (result == undefined) {
return "";
}
if (result.value instanceof Array) {
let tempresult = result.value;
let cancel = false;
tempresult = tempresult.map((el) => {
let field = form.fields.find((f) => f.value == el);
if (field == undefined) {
cancel = true;
return el;
}
return field.displayvalue ?? el;
});
if (!cancel) result.value = tempresult;
return result.value.join(", ");
}
if (result.type == "radio") {
let field = form.fields.find((f) => f.value == result.value);
if (field != undefined) {
return field.displayvalue ?? result.value;
}
}
return result.value;
}
</script>
<template>
<h1>Ergebnisse {{ form.name }}</h1>
<table>
<thead>
<tr>
<td v-for="(field, i) in myfields" :key="i">
{{ field.displayname ?? field.name }}
</td>
<td>Zeitstempel</td>
</tr>
</thead>
<tbody>
<tr v-for="(result, ri) in results" :key="ri">
<td v-for="(field, fi) in myfields" :key="fi" :style="field.type=='color'?{ 'backgroundColor': result.data.find((el) => el.name == field.name).value, width: '10px', height: '10px' }:{}">
<span v-if="field.type!='color'">{{
prettyResult(
result.data.find(
(el) =>
el.name == field.name ||
el.name + "[]" == field.name
)
)
}}</span>
<span v-else ></span>
</td>
<td>{{ result.timestamp }}</td>
</tr>
</tbody>
</table>
</template>
<style scoped>
@import "../assets/css/bulitipp2.css";
</style>