This commit is contained in:
42
public/src/services/DialogService.ts
Normal file
42
public/src/services/DialogService.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type {Component} from "vue";
|
||||
import {Subject} from "rxjs";
|
||||
import type {ConfirmDialogOptions, DialogControls} from "@/components/dialog/dialog";
|
||||
import ConfirmDialog from "@/components/dialog/ConfirmDialog.vue";
|
||||
|
||||
export namespace Dialogs {
|
||||
|
||||
interface NextDialog {
|
||||
component: Component,
|
||||
controls: DialogControls,
|
||||
props: any
|
||||
}
|
||||
|
||||
export const subject = new Subject<NextDialog>()
|
||||
|
||||
|
||||
export function createDialog(component: Component, controls: DialogControls, props: any) {
|
||||
subject.next({component, controls, props})
|
||||
}
|
||||
|
||||
export async function confirm(options: ConfirmDialogOptions) {
|
||||
return new Promise<boolean | void>((resolve, reject) => {
|
||||
const controls: DialogControls = {
|
||||
onPositive() {
|
||||
resolve(true)
|
||||
},
|
||||
onNegative() {
|
||||
resolve(false)
|
||||
},
|
||||
onDismiss() {
|
||||
resolve()
|
||||
}
|
||||
}
|
||||
const next: NextDialog = {
|
||||
component: ConfirmDialog,
|
||||
controls,
|
||||
props: options
|
||||
}
|
||||
subject.next(next)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
import type {Gottesdienst, Mark} from "@/models/models";
|
||||
import type {Gottesdienst, GottesdienstGroup, Mark} from "@/models/models";
|
||||
import {Auth} from "@/services/auth";
|
||||
|
||||
|
||||
const API_ENDPOINT = "http://0.0.0.0:8080/api"
|
||||
const API_ENDPOINT = import.meta.env.MODE == "development"
|
||||
? "http://0.0.0.0:8080/api"
|
||||
: window.location.origin + "/api"
|
||||
|
||||
|
||||
export async function api(endpoint: string, method: string = "GET", body?: any ) {
|
||||
let isJson = (typeof body == "object")
|
||||
@@ -40,6 +43,26 @@ export namespace API {
|
||||
})
|
||||
}
|
||||
|
||||
export async function getPlans(): Promise<GottesdienstGroup[]> {
|
||||
return api("/groups").then(res => res.json())
|
||||
}
|
||||
|
||||
export async function createPlan(from, to) {
|
||||
return api("/groups", "POST", {
|
||||
id: -1,
|
||||
from,
|
||||
to
|
||||
}).then(res => res.json())
|
||||
}
|
||||
|
||||
export async function deletePlan(id) {
|
||||
return api("/groups?id=" + id, "DELETE").then(res => res.json())
|
||||
}
|
||||
|
||||
export async function updatePlan(group) {
|
||||
return api("/groups", "PATCH", group).then(res => res.json())
|
||||
}
|
||||
|
||||
function formatGottesdienste(data: any): Array<Gottesdienst>{
|
||||
return data.map(json => {
|
||||
json["date"] = new Date(json["date"])
|
||||
@@ -64,10 +87,26 @@ export namespace API {
|
||||
})
|
||||
}
|
||||
|
||||
export async function getMinistranten() {
|
||||
return api("/ministranten", "GET").then(res => res.json())
|
||||
}
|
||||
|
||||
export async function deleteGottesdienst(id) {
|
||||
return api("/gottesdienste?id=" + id, "DELETE")
|
||||
.then(data => data.status == 200)
|
||||
}
|
||||
export async function deleteMinistrant(id) {
|
||||
return api("/ministranten?id=" + id, "DELETE")
|
||||
.then(data => data.status == 200)
|
||||
}
|
||||
|
||||
export async function createMinistrant(ministrant) {
|
||||
return api("/ministranten", "PUT", ministrant).then(data => data.json())
|
||||
}
|
||||
export async function updateMinistrant(ministrant) {
|
||||
return api("/ministranten", "PATCH", ministrant)
|
||||
.then(data => data.status == 200)
|
||||
}
|
||||
|
||||
export async function setMarks(marks: Mark[]): Promise<boolean> {
|
||||
return api("/marks", "PATCH", marks)
|
||||
|
||||
Reference in New Issue
Block a user