[add] page:calendar_add [add] page:event_add

This commit is contained in:
Fenris Wolf 2024-09-26 13:38:25 +02:00
parent c668ab5c7d
commit 8f3a4cb9db
9 changed files with 552 additions and 19 deletions

View file

@ -0,0 +1,43 @@
{
"meta": {
"identifier": "deu"
},
"tree": {
"common.timezone_shift": "Zeitzonen-Verschiebung",
"common.date": "Datum",
"common.time": "Uhrzeit",
"access_level.none": "nichts",
"access_level.view": "nur lesen",
"access_level.edit": "lesen und bearbeiten",
"access_level.admin": "voll",
"event.event": "Termin",
"event.name": "Name",
"event.begin": "Anfang",
"event.end": "Ende",
"event.location": "Ort",
"event.description": "Beschreibung",
"resource.kind": "Art",
"resource.kinds.local.title": "lokal",
"resource.kinds.local.event_ids": "Termin-IDs",
"resource.kinds.caldav.title": "CalDAV",
"resource.kinds.caldav.url": "URL",
"resource.kinds.caldav.read_only": "nur lesen",
"calendar.calendar": "Kalender",
"calendar.name": "Name",
"calendar.resource": "Resource",
"calendar.access.access": "Zugriff",
"calendar.access.default_level": "Standard-Zugriff",
"calendar.access.attributed": "Zuweisungen",
"page.login.title": "Anmelden",
"page.login.internal.name": "Name",
"page.login.internal.password": "Kennwort",
"page.login.internal.do": "Anmelden",
"page.login.oidc.via": "via {{title}}",
"page.logout.title": "Abmelden",
"page.events.title": "Übersicht",
"page.calendar_add.title": "Kalendar anlegen",
"page.calendar_add.actions.do": "anlegen",
"page.event_add.title": "Termin anlegen",
"page.event_add.actions.do": "anlegen"
}
}

View file

@ -0,0 +1,43 @@
{
"meta": {
"identifier": "eng"
},
"tree": {
"common.timezone_shift": "Timezone shift",
"common.date": "date",
"common.time": "time",
"access_level.none": "none",
"access_level.view": "read only",
"access_level.edit": "read and write",
"access_level.admin": "full",
"event.event": "event",
"event.name": "name",
"event.begin": "begin",
"event.end": "end",
"event.location": "location",
"event.description": "description",
"resource.kind": "kind",
"resource.kinds.local.title": "local",
"resource.kinds.local.event_ids": "event ids",
"resource.kinds.caldav.title": "CalDAV",
"resource.kinds.caldav.url": "URL",
"resource.kinds.caldav.read_only": "read-only",
"calendar.calendar": "Kalendar",
"calendar.name": "name",
"calendar.resource": "resource",
"calendar.access.access": "access",
"calendar.access.default_level": "default level",
"calendar.access.attributed": "attributed",
"page.login.title": "Login",
"page.login.internal.name": "name",
"page.login.internal.password": "password",
"page.login.internal.do": "login",
"page.login.oidc.via": "via {{title}}",
"page.logout.title": "Logout",
"page.events.title": "Overview",
"page.calendar_add.title": "Add calendar",
"page.calendar_add.actions.do": "anlegen",
"page.event_add.title": "Add event",
"page.event_add.actions.do": "anlegen"
}
}

View file

@ -235,10 +235,9 @@ namespace _zeitbild.frontend_web.backend
) : Promise< ) : Promise<
Array< Array<
{ {
key : _zeitbild.frontend_web.type.calendar_id; id : int;
preview : { name : string;
name : string; access_level : string;
}
} }
> >
> >
@ -254,7 +253,7 @@ namespace _zeitbild.frontend_web.backend
/** /**
*/ */
export async function calendar_add( export async function calendar_add(
calendar_object : _zeitbild.frontend_web.type.type_calendar_object calendar_object : _zeitbild.frontend_web.type.calendar_object
) : Promise< ) : Promise<
_zeitbild.frontend_web.type.calendar_id _zeitbild.frontend_web.type.calendar_id
> >

View file

@ -1,4 +1,78 @@
/**
*/
class class_input_datetime implements lib_plankton.zoo_input.interface_input<_zeitbild.frontend_web.helpers.type_datetime>
{
/**
*/
private core : lib_plankton.zoo_input.class_input_group<_zeitbild.frontend_web.helpers.type_datetime>;
/**
*/
public constructor(
prefix : string
)
{
this.core = new lib_plankton.zoo_input.class_input_group<_zeitbild.frontend_web.helpers.type_datetime>(
[
{
"name": "timezone_shift",
"input": new lib_plankton.zoo_input.class_input_number(
),
"label": (prefix + lib_plankton.translate.get("common.timezone_shift")),
},
{
"name": "date",
"input": new lib_plankton.zoo_input.class_input_date(
),
"label": (prefix + lib_plankton.translate.get("common.date")),
},
{
"name": "time",
"input": new lib_plankton.zoo_input.class_input_soft<type_time>(
new lib_plankton.zoo_input.class_input_time(
)
),
"label": (prefix + lib_plankton.translate.get("common.time")),
},
]
);
}
/**
*/
public async setup(
parent : HTMLElement
) : Promise<void>
{
return this.core.setup(parent);
}
/**
*/
public async read(
) : Promise<_zeitbild.frontend_web.helpers.type_datetime>
{
return this.core.read();
}
/**
*/
public async write(
value : _zeitbild.frontend_web.helpers.type_datetime
) : Promise<void>
{
return this.core.write(value);
}
}
/** /**
*/ */
namespace _zeitbild.frontend_web namespace _zeitbild.frontend_web
@ -12,8 +86,20 @@ namespace _zeitbild.frontend_web
// conf // conf
await _zeitbild.frontend_web.conf.init("conf.json"); await _zeitbild.frontend_web.conf.init("conf.json");
// init // init
await _zeitbild.frontend_web.backend.init(); await _zeitbild.frontend_web.backend.init();
await lib_plankton.translate.initialize(
{
"verbosity": 1,
"packages": [
JSON.parse(await lib_plankton.file.read("data/localization/deu.loc.json")),
JSON.parse(await lib_plankton.file.read("data/localization/eng.loc.json")),
],
"order": ["deu", "eng"],
"autopromote": false,
}
);
lib_plankton.zoo_page.init( lib_plankton.zoo_page.init(
document.querySelector("main"), document.querySelector("main"),
{ {
@ -26,7 +112,6 @@ namespace _zeitbild.frontend_web
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin( target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
"login", "login",
{ {
"form": "",
} }
); );
const form : lib_plankton.zoo_form.class_form< const form : lib_plankton.zoo_form.class_form<
@ -45,18 +130,18 @@ namespace _zeitbild.frontend_web
{ {
"name": "name", "name": "name",
"input": new lib_plankton.zoo_input.class_input_text(), "input": new lib_plankton.zoo_input.class_input_text(),
"label": "Name", // TODO: translate "label": lib_plankton.translate.get("page.login.internal.name"),
}, },
{ {
"name": "password", "name": "password",
"input": new lib_plankton.zoo_input.class_input_password(), "input": new lib_plankton.zoo_input.class_input_password(),
"label": "Kennwort", // TODO: translate "label": lib_plankton.translate.get("page.login.internal.password"),
}, },
] ]
), ),
[ [
{ {
"label": "Anmelden", // TODO: translate "label": lib_plankton.translate.get("page.login.internal.do"),
"target": "submit", "target": "submit",
"procedure": async (get_value, get_representation) => { "procedure": async (get_value, get_representation) => {
const value : any = await get_value(); const value : any = await get_value();
@ -98,9 +183,9 @@ namespace _zeitbild.frontend_web
case "oidc": { case "oidc": {
let element_a : HTMLElement = document.createElement("a");; let element_a : HTMLElement = document.createElement("a");;
element_a.textContent = lib_plankton.string.coin( element_a.textContent = lib_plankton.string.coin(
"via {{label}}", // TODO: translate lib_plankton.translate.get("page.login.oidc.via"),
{ {
"label": preparation.data.label, "title": preparation.data.label,
} }
); );
element_a.setAttribute("href", preparation.data.url); element_a.setAttribute("href", preparation.data.url);
@ -133,6 +218,329 @@ namespace _zeitbild.frontend_web
} }
); );
}, },
"calendar_add": async (parameters, target_element) => {
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
"calendar_add",
{
"label": lib_plankton.translate.get("page.calendar_add.title")
}
);
const form : lib_plankton.zoo_form.class_form<
_zeitbild.frontend_web.type.calendar_object,
{
name : string;
access_default_level : string;
resource_kind : string;
}
> = new lib_plankton.zoo_form.class_form<
_zeitbild.frontend_web.type.calendar_object,
{
name : string;
access_default_level : string;
resource_kind : string;
}
>(
(calendar_object) => ({
"name": calendar_object.name,
"access_default_level": (() => {
switch (calendar_object.access.default_level) {
case _zeitbild.frontend_web.type.enum_access_level.none: return "none";
case _zeitbild.frontend_web.type.enum_access_level.view: return "view";
case _zeitbild.frontend_web.type.enum_access_level.edit: return "edit";
case _zeitbild.frontend_web.type.enum_access_level.admin: return "admin";
}
}) (),
"resource_kind": calendar_object.resource.kind,
}),
(raw) => ({
"name": raw.name,
"access": {
"default_level": (() => {
switch (raw.access_default_level) {
case "none": return _zeitbild.frontend_web.type.enum_access_level.none;
case "view": return _zeitbild.frontend_web.type.enum_access_level.view;
case "edit": return _zeitbild.frontend_web.type.enum_access_level.edit;
case "admin": return _zeitbild.frontend_web.type.enum_access_level.admin;
}
}) (),
"attributed": lib_plankton.map.hashmap.implementation_map(
lib_plankton.map.hashmap.make(
x => x.toFixed(0)
)
),
},
"resource": (() => {
switch (raw.resource_kind) {
case "local": {
return {
"kind": "local",
"data": {
"events": [],
}
};
break;
}
case "caldav": {
return {
"kind": "caldav",
"data": {
"url": "", // TODO
"read_only": true, // TODO
}
};
break;
}
default: {
throw (new Error("invalid resource kind: " + raw.resource_kind));
break;
}
}
}) (),
}),
new lib_plankton.zoo_input.class_input_group<any>(
[
{
"name": "name",
"input": new lib_plankton.zoo_input.class_input_text(),
"label": lib_plankton.translate.get("calendar.name")
},
{
"name": "access_default_level",
"input": new lib_plankton.zoo_input.class_input_selection(
[
{
"value": "none",
"label": lib_plankton.translate.get("access_level.none"),
},
{
"value": "view",
"label": lib_plankton.translate.get("access_level.view")
},
{
"value": "edit",
"label": lib_plankton.translate.get("access_level.edit")
},
{
"value": "admin",
"label": lib_plankton.translate.get("access_level.admin")
},
]
),
"label": lib_plankton.string.coin(
"{{default_level}}",
{
"head": lib_plankton.translate.get("calendar.access.access"),
"default_level": lib_plankton.translate.get("calendar.access.default_level"),
}
)
},
{
"name": "resource_kind",
"input": new lib_plankton.zoo_input.class_input_selection(
[
{
"value": "local",
"label": lib_plankton.translate.get("resource.kinds.local.title")
},
{
"value": "caldav",
"label": lib_plankton.translate.get("resource.kinds.caldav.title")
},
]
),
"label": lib_plankton.translate.get("resource.kind")
},
]
),
[
{
"label": lib_plankton.translate.get("page.calendar_add.actions.do"),
"target": "submit",
"procedure": async (get_value, get_representation) => {
const value : any = await get_value();
try {
await _zeitbild.frontend_web.backend.calendar_add(
value
);
lib_plankton.zoo_page.set(
{
"name": "events",
"parameters": {}
}
);
}
catch (error) {
// do nothing
/*
lib_plankton.zoo_page.set(
{
"name": "event_add",
"parameters": {
}
}
);
*/
}
}
},
]
);
await form.setup(document.querySelector("#calendar_add_form"));
},
"event_add": async (parameters, target_element) => {
const calendar_id : int = parseInt(parameters["calendar_id"]);
target_element.innerHTML = await _zeitbild.frontend_web.helpers.template_coin(
"event_add",
{
"label": lib_plankton.translate.get("page.event_add.title")
}
);
const form : lib_plankton.zoo_form.class_form<
{
calendar_id : _zeitbild.frontend_web.type.calendar_id;
event_object : _zeitbild.frontend_web.type.event_object;
},
{
calendar_id : string;
name : string;
begin : _zeitbild.frontend_web.helpers.type_datetime;
end : (null | _zeitbild.frontend_web.helpers.type_datetime);
location : (null | string);
description : (null | string);
}
> = new lib_plankton.zoo_form.class_form<
{
calendar_id : _zeitbild.frontend_web.type.calendar_id;
event_object : _zeitbild.frontend_web.type.event_object;
},
{
calendar_id : string;
name : string;
begin : _zeitbild.frontend_web.helpers.type_datetime;
end : (null | _zeitbild.frontend_web.helpers.type_datetime);
location : (null | string);
description : (null | string);
}
>(
(value) => ({
"calendar_id": value.calendar_id.toFixed(0),
"name": value.event_object.name,
"begin": value.event_object.begin,
"end": value.event_object.end,
"location": value.event_object.location,
"description": value.event_object.description,
}),
(representation) => ({
"calendar_id": parseInt(representation.calendar_id),
"event_object": {
"name": representation.name,
"begin": representation.begin,
"end": representation.end,
"location": representation.location,
"description": representation.description,
}
}),
new lib_plankton.zoo_input.class_input_group<any>(
[
{
"name": "calendar_id",
"input": new lib_plankton.zoo_input.class_input_selection(
(await _zeitbild.frontend_web.backend.calendar_list())
.filter(
(entry) => (["edit","admin"].includes(entry.access_level))
)
.map(
(entry) => ({
"value": entry.id.toFixed(0),
"label": entry.name,
})
)
),
"label": lib_plankton.translate.get("calendar.calendar")
},
{
"name": "name",
"input": new lib_plankton.zoo_input.class_input_text(
),
"label": lib_plankton.translate.get("event.name")
},
{
"name": "begin",
"input": new class_input_datetime(
""
),
"label": lib_plankton.translate.get("event.begin")
},
{
"name": "end",
"input": new lib_plankton.zoo_input.class_input_soft<_zeitbild.frontend_web.helpers.type_datetime>(
new class_input_datetime(
""
)
),
"label": lib_plankton.translate.get("event.end")
},
{
"name": "location",
"input": new lib_plankton.zoo_input.class_input_soft<string>(
new lib_plankton.zoo_input.class_input_text(
)
),
"label": lib_plankton.translate.get("event.location")
},
{
"name": "description",
"input": new lib_plankton.zoo_input.class_input_soft<string>(
new lib_plankton.zoo_input.class_input_text(
)
),
"label": lib_plankton.translate.get("event.description")
},
]
),
[
{
"label": lib_plankton.translate.get("page.event_add.actions.do"),
"target": "submit",
"procedure": async (get_value, get_representation) => {
const value : any = await get_value();
try {
await _zeitbild.frontend_web.backend.calendar_event_add(
value.calendar_id,
value.event_object
);
lib_plankton.zoo_page.set(
{
"name": "events",
"parameters": {}
}
);
}
catch (error) {
// do nothing
/*
lib_plankton.zoo_page.set(
{
"name": "event_add",
"parameters": {
}
}
);
*/
}
}
},
]
);
/*
await form.write(
{
"calendar_id": parameters["calendar_id"],
}
);
*/
await form.setup(document.querySelector("#event_add_form"));
},
"events": async (parameters, target_element) => { "events": async (parameters, target_element) => {
const content = await _zeitbild.frontend_web.view.calendar_view_table_html( const content = await _zeitbild.frontend_web.view.calendar_view_table_html(
{ {
@ -161,16 +569,24 @@ namespace _zeitbild.frontend_web
); );
lib_plankton.zoo_page.add_nav_entry( lib_plankton.zoo_page.add_nav_entry(
{"name": "login", "parameters": {}}, {"name": "login", "parameters": {}},
{"label": "Login"} {"label": lib_plankton.translate.get("page.login.title")}
); // TODO: translate );
lib_plankton.zoo_page.add_nav_entry( lib_plankton.zoo_page.add_nav_entry(
{"name": "events", "parameters": {}}, {"name": "events", "parameters": {}},
{"label": "Events"} {"label": lib_plankton.translate.get("page.events.title")}
); // TODO: translate );
lib_plankton.zoo_page.add_nav_entry(
{"name": "calendar_add", "parameters": {}},
{"label": lib_plankton.translate.get("page.calendar_add.title")}
);
lib_plankton.zoo_page.add_nav_entry(
{"name": "event_add", "parameters": {}},
{"label": lib_plankton.translate.get("page.event_add.title")}
);
lib_plankton.zoo_page.add_nav_entry( lib_plankton.zoo_page.add_nav_entry(
{"name": "logout", "parameters": {}}, {"name": "logout", "parameters": {}},
{"label": "Logout"} {"label": lib_plankton.translate.get("page.logout.title")}
); // TODO: translate );
// exec // exec
lib_plankton.zoo_page.start(); lib_plankton.zoo_page.start();

View file

@ -88,7 +88,7 @@ namespace _zeitbild.frontend_web.type
/** /**
*/ */
export type type_calendar_object = { export type calendar_object = {
name : string; name : string;
access : { access : {
default_level : enum_access_level; default_level : enum_access_level;

View file

@ -125,3 +125,19 @@ a:hover {
font-weight: bold; font-weight: bold;
font-size: 0.8em; font-size: 0.8em;
} }
.plankton_input_soft_container > * {
display: inline-block;
}
.plankton_input_soft_setter {
margin-right: 8px;
}
.plankton_input_soft_inactive {
display: none !important;
}
.plankton_input_group {
margin-left: 48px;
}

View file

@ -0,0 +1,5 @@
<div id="calendar_add">
<h2>{{label}}</h2>
<div id="calendar_add_form">
</div>
</div>

View file

@ -0,0 +1,5 @@
<div id="event_add">
<h2>{{label}}</h2>
<div id="event_add_form">
</div>
</div>

View file

@ -17,7 +17,7 @@ cmd_tsc := ${dir_tools}/typescript/node_modules/.bin/tsc
## rules ## rules
.PHONY: default .PHONY: default
default: index templates style logic default: index templates style logic data
.PHONY: index .PHONY: index
index: ${dir_build}/index.html index: ${dir_build}/index.html
@ -63,3 +63,9 @@ ${dir_build}/logic.js: \
@ ${cmd_log} "logic | link …" @ ${cmd_log} "logic | link …"
@ ${cmd_mkdir} $(dir $@) @ ${cmd_mkdir} $(dir $@)
@ ${cmd_cat} $^ > $@ @ ${cmd_cat} $^ > $@
.PHONY: data
data:
@ ${cmd_log} "data …"
@ ${cmd_mkdir} ${dir_build}/data
@ ${cmd_cp} -r -u -v ${dir_source}/data/* ${dir_build}/data/