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

@@ -1,127 +1,297 @@
import $ from "jquery";
import { ref } from "vue";
class User {
public username: string;
public kuerzel: string;
public points: number;
public id: number;
constructor (username: string, kuerzel: string, points: number, id: number) {
this.username = username;
this.kuerzel = kuerzel;
this.points=points;
this.id=id;
}
hatgetippt():boolean{
var hatgetippt=false;
$.ajax(RitzenbergenLib.api("/bulitipp/hatgetippt.php?userid="+this.id),{
async: false,
success(response): any{
hatgetippt=response==1;
console.log(response);
}
});
return hatgetippt;
}
public username: string;
public kuerzel: string;
public points: number;
public id: number;
constructor(username: string, kuerzel: string, points: number, id: number) {
this.username = username;
this.kuerzel = kuerzel;
this.points = points;
this.id = id;
}
hatgetippt(): boolean {
var hatgetippt = false;
$.ajax(
RitzenbergenLib.api("/bulitipp/hatgetippt.php?userid=" + this.id),
{
async: false,
success(response): any {
hatgetippt = response == 1;
console.log(response);
},
}
);
return hatgetippt;
}
}
class SpieltagSumme {
public user: User;
public tsPoints: number;
constructor (user: User, tsPoints: number) {
this.user = user;
this.tsPoints = tsPoints;
}
public user: User;
public tsPoints: number;
constructor(user: User, tsPoints: number) {
this.user = user;
this.tsPoints = tsPoints;
}
}
class RitzenbergenLib {
static get_img(mypath: string) {
if(mypath.startsWith("/")) return "https://bilder.ritzenbergen.de"+mypath;
else return "https://bilder.ritzenbergen.de/"+mypath;
}
static api(path:string){
if(path.startsWith("/")) return "http://192.168.188.38/Jonas/ritzenbergenapi"+path;
else return "http://192.168.188.38/Jonas/ritzenbergenapi/"+path;
}
static get_img(mypath: string) {
if (mypath.startsWith("/"))
return "https://bilder.ritzenbergen.de" + mypath;
else return "https://bilder.ritzenbergen.de/" + mypath;
}
static api(path: string) {
if (path.startsWith("/"))
return "http://192.168.188.38/Jonas/ritzenbergenapi" + path;
else return "http://192.168.188.38/Jonas/ritzenbergenapi/" + path;
}
}
class Paarung {
public heim: string;
public gast: string;
public id: number;
constructor (heim: string, gast: string, id: number) {
this.heim = heim;
this.gast = gast;
this.id=id;
}
public heim: string;
public gast: string;
public id: number;
constructor(heim: string, gast: string, id: number) {
this.heim = heim;
this.gast = gast;
this.id = id;
}
}
class Ergebnis {
paarung: Paarung;
heim: number;
gast: number;
constructor (paarung: Paarung, heim: number, gast: number) {
this.paarung = paarung;
this.heim = heim;
this.gast = gast;
}
paarung: Paarung;
heim: number;
gast: number;
constructor(paarung: Paarung, heim: number, gast: number) {
this.paarung = paarung;
this.heim = heim;
this.gast = gast;
}
}
class Tipp{
heim: number|null;
gast: number|null;
paarung: Paarung|null;
class Tipp {
heim: number | null;
gast: number | null;
paarung: Paarung | null;
constructor (paarung: Paarung|null, heim: number|null, gast: number|null) {
this.heim = heim;
this.gast = gast;
this.paarung = paarung;
}
constructor(
paarung: Paarung | null,
heim: number | null,
gast: number | null
) {
this.heim = heim;
this.gast = gast;
this.paarung = paarung;
}
}
class Spiel {
public paarung: Paarung;
public result: [number, number]|null;
public tipp: [number, number]|null;
constructor (paarung: Paarung, result: [number, number], tipp: [number, number]|null) {
this.paarung = paarung;
this.result = result;
this.tipp = tipp;
}
public calcPoints(){
if(this.tipp==null) return 0;
if(this.result[0]==this.tipp[0] && this.result[1]==this.tipp[1]) return 3;
let differenztipp=this.tipp[0]-this.tipp[1];
let differenz=this.result[0]-this.result[1];
if(differenztipp==differenz) return 2;
if(
(this.tipp[0]>this.tipp[1] && this.result[0]>this.result[1]) ||
(this.tipp[0]<this.tipp[1] && this.result[0]<this.result[1])
) return 1;
return 0;
}
public static async fetchSpiele(spieltag: number, userid: number):Spiel[]{
let params=new URLSearchParams({
spieltag: spieltag+1,
user: userid
});
return fetch(RitzenbergenLib.api("/bulitipp/spieltag-user.php?")+params.toString()).then((response)=>{
return response.json();
}).then((data)=>{
return data.data;
}).then((data)=>{
return data.map((el)=>{
return new Spiel(new Paarung(el.paarung.heim, el.paarung.gast, el.paarung.id),el.result, el.tipp);
});
public paarung: Paarung;
public result: [number, number] | null;
public tipp: [number, number] | null;
constructor(
paarung: Paarung,
result: [number, number],
tipp: [number, number] | null
) {
this.paarung = paarung;
this.result = result;
this.tipp = tipp;
}
public calcPoints() {
if (this.tipp == null) return 0;
if (this.result[0] == this.tipp[0] && this.result[1] == this.tipp[1])
return 3;
let differenztipp = this.tipp[0] - this.tipp[1];
let differenz = this.result[0] - this.result[1];
if (differenztipp == differenz) return 2;
if (
(this.tipp[0] > this.tipp[1] && this.result[0] > this.result[1]) ||
(this.tipp[0] < this.tipp[1] && this.result[0] < this.result[1])
)
return 1;
return 0;
}
public static async fetchSpiele(spieltag: number, userid: number): Spiel[] {
let params = new URLSearchParams({
spieltag: spieltag + 1,
user: userid,
});
return fetch(
RitzenbergenLib.api("/bulitipp/spieltag-user.php?") +
params.toString()
)
.then((response) => {
return response.json();
})
.then((data) => {
return data.data;
})
.then((data) => {
return data.map((el) => {
return new Spiel(
new Paarung(
el.paarung.heim,
el.paarung.gast,
el.paarung.id
),
el.result,
el.tipp
);
});
});
}
}
class Formular {
public id: number;
public name: string;
public minitext: string;
public ispublic: boolean;
public multiple: boolean;
public fields=ref<Field[]>([]);
constructor(
id: number,
name: string,
minitext: string,
ispublic: boolean,
multiple: boolean
) {
this.id = id;
this.name = name;
this.minitext = minitext;
this.ispublic = ispublic;
this.multiple = multiple;
this.getFields().then((fields)=>this.fields.value=fields);
}
public static async getForms(): Promise<Formular[]> {
let forms: Formular[] = [];
forms = await fetch(
RitzenbergenLib.api("/formulare/get_formulare.php"),
{
method: "GET",
}
)
.then((response) => response.json())
.then((result) =>
result.map(
(el: any) =>
new Formular(
el.id,
el.name,
el.minitext,
el.public,
el.multiple
)
)
);
return forms;
}
private async getFields(): Promise<Field[]> {
return fetch(
RitzenbergenLib.api(
"/formulare/get_fields.php?formular=" + this.id
),
{
method: "GET",
}
)
.then((response) => response.json())
.then((result) =>
result.map(
(el: any) =>
new Field(el.formular, el.name, el.value, el.type, {
id: el.id,
displayname: el.displayname,
displayvalue: el.displayvalue,
placeholder: el.placeholder,
title: el.title,
required: el.required == 1,
maxlength: el.maxlength,
min: el.min,
max: el.max,
multiple: el.multiple == 1,
checked: el.checked == 1,
})
)
);
}
}
type FieldType =
| "text"
| "password"
| "number"
| "range"
| "date"
| "time"
| "checkbox"
| "radio"
| "color"
| "submit"
| "textarea";
class Field {
id?: number;
formular: number;
name: string;
displayname?: string | null;
value: string;
displayvalue?: string | null;
placeholder?: string | null;
type: FieldType;
title?: string | null;
required: boolean;
maxlength?: number | null;
min?: number | null;
max?: number | null;
checked?: boolean | null;
constructor(
formular: number,
name: string,
value: string,
type: FieldType,
options?: {
id?: number;
displayname?: string | null;
displayvalue?: string | null;
placeholder?: string | null;
title?: string | null;
required?: boolean;
maxlength?: number | null;
min?: number | null;
max?: number | null;
multiple?: boolean | null;
checked?: boolean | null;
}
) {
this.id = options?.id;
this.formular = formular;
this.name = name;
this.displayname = options?.displayname ?? null;
this.value = value;
this.displayvalue = options?.displayvalue ?? null;
this.placeholder = options?.placeholder ?? null;
this.type = type;
this.title = options?.title ?? null;
this.required = options?.required ?? false;
this.maxlength = options?.maxlength ?? null;
this.min = options?.min ?? null;
this.max = options?.max ?? null;
this.checked = options?.checked ?? null;
}
}
export default {
RitzenbergenLib,
User,
SpieltagSumme,
Paarung,
Ergebnis,
Tipp,
Spiel
}
RitzenbergenLib,
User,
SpieltagSumme,
Paarung,
Ergebnis,
Tipp,
Spiel,
Formular,
Field,
};