diff --git a/lib/plankton/plankton.d.ts b/lib/plankton/plankton.d.ts index 30c6b9f..9da3c53 100644 --- a/lib/plankton/plankton.d.ts +++ b/lib/plankton/plankton.d.ts @@ -882,6 +882,9 @@ declare namespace lib_plankton.call { /** */ export function sleep(seconds: float): Promise; + /** + */ + export function null_prop(value_from: (null | type_value_from), function_: ((value: type_value_from) => type_value_to)): (null | type_value_to); export {}; } declare namespace lib_plankton.file { diff --git a/lib/plankton/plankton.js b/lib/plankton/plankton.js index 8509b96..6a8b172 100644 --- a/lib/plankton/plankton.js +++ b/lib/plankton/plankton.js @@ -2043,6 +2043,16 @@ var lib_plankton; })); } call.sleep = sleep; + /** + */ + function null_prop(value_from, function_) { + return ((value_from === null) + ? + null + : + function_(value_from)); + } + call.null_prop = null_prop; })(call = lib_plankton.call || (lib_plankton.call = {})); })(lib_plankton || (lib_plankton = {})); /* @@ -3792,10 +3802,10 @@ var lib_plankton; options = Object.assign({ "compare_value": instance_compare }, options); - if (is_empty(list)) { + /*if (is_empty(list)) { throw (new Error("the max-arg of an empty list is not defined")); } - else { + else */ { return (list .reduce(function (result, element, index) { var value = target_function(element); diff --git a/source/data/localization/deu.loc.json b/source/data/localization/deu.loc.json index cf92d58..f5ec083 100644 --- a/source/data/localization/deu.loc.json +++ b/source/data/localization/deu.loc.json @@ -47,7 +47,8 @@ "calendar.access.access": "Zugriff", "calendar.access.public": "öffentlich", "calendar.access.default_level": "Standard", - "calendar.access.attributed": "Zuweisungen", + "calendar.access.attributed_group": "Gruppen-Zuweisungen", + "calendar.access.attributed_user": "Nutzer-Zuweisungen", "widget.listview.add": "Termin anlegen", "widget.weekview.controls.year": "Jahr", "widget.weekview.controls.week": "Woche", diff --git a/source/data/localization/eng.loc.json b/source/data/localization/eng.loc.json index beec643..47785ec 100644 --- a/source/data/localization/eng.loc.json +++ b/source/data/localization/eng.loc.json @@ -47,7 +47,8 @@ "calendar.access.access": "access", "calendar.access.public": "public", "calendar.access.default_level": "default", - "calendar.access.attributed": "attributed", + "calendar.access.attributed_group": "group attributed", + "calendar.access.attributed_user": "user attributed", "widget.listview.add": "add event", "widget.weekview.controls.year": "year", "widget.weekview.controls.week": "week", diff --git a/source/helpers.ts b/source/helpers.ts index 92a791a..34b0292 100644 --- a/source/helpers.ts +++ b/source/helpers.ts @@ -151,7 +151,42 @@ namespace _dali.helpers /** */ - export function input_attributed_access( + export function input_attributed_access_group( + groups : Array<{id : _dali.type_group_id; object : _dali.type_group_object;}> + ) + : lib_plankton.zoo_input.class_input_hashmap< + _dali.type_group_id, + _dali.enum_access_level + > + { + return ( + new lib_plankton.zoo_input.class_input_hashmap<_dali.type_group_id, _dali.enum_access_level>( + // hash_key + (group_id) => group_id.toFixed(0), + // key_input_factory + () => new lib_plankton.zoo_input.class_input_wrapped( + new lib_plankton.zoo_input.class_input_selection( + groups + .map( + (group) => ({ + "value": group.id.toFixed(0), + "label": group.object.label, + }) + ) + ), + x => parseInt(x), + x => x.toFixed(0) + ), + // value_input_factory + () => input_access_level() + ) + ); + } + + + /** + */ + export function input_attributed_access_user( users : Array<{id : _dali.type_user_id; name : string;}> ) : lib_plankton.zoo_input.class_input_hashmap< diff --git a/source/model.ts b/source/model.ts index fe14509..b42bcf4 100644 --- a/source/model.ts +++ b/source/model.ts @@ -4,6 +4,12 @@ namespace _dali.model /** */ type type_state = { + groups : Array< + { + id : _dali.type_group_id; + object : _dali.type_group_object; + } + >; users : Array< { id : _dali.type_user_id; @@ -110,6 +116,23 @@ namespace _dali.model } + /** + */ + export async function group_list( + ) + : Promise< + Array< + { + id : _dali.type_group_id; + object : _dali.type_group_object; + } + > + > + { + return Promise.resolve(_state.groups); + } + + /** */ export async function user_list( @@ -196,12 +219,30 @@ namespace _dali.model "access": { "public": data.access.public, "default_level": _dali.access_level_decode(data.access.default_level), - "attributed": lib_plankton.map.hashmap.implementation_map( + "attributed_group": lib_plankton.map.hashmap.implementation_map( lib_plankton.map.hashmap.make( x => x.toFixed(0), { "pairs": ( - data.access.attributed + data.access.attributed_group + .map( + (entry) => ( + { + "key": entry.group_id, + "value": _dali.access_level_decode(entry.level), + } + ) + ) + ), + } + ) + ), + "attributed_user": lib_plankton.map.hashmap.implementation_map( + lib_plankton.map.hashmap.make( + x => x.toFixed(0), + { + "pairs": ( + data.access.attributed_user .map( (entry) => ( { @@ -244,8 +285,19 @@ namespace _dali.model "access": { "public": calendar_object.access.public, "default_level": _dali.access_level_encode(calendar_object.access.default_level), - "attributed": ( - lib_plankton.map.dump(calendar_object.access.attributed) + "attributed_group": ( + lib_plankton.map.dump(calendar_object.access.attributed_group) + .map( + (pair) => ( + { + "group_id": pair.key, + "level": _dali.access_level_encode(pair.value), + } + ) + ) + ), + "attributed_user": ( + lib_plankton.map.dump(calendar_object.access.attributed_user) .map( (pair) => ( { @@ -254,7 +306,7 @@ namespace _dali.model } ) ) - ) + ), }, /** * @todo @@ -298,15 +350,24 @@ namespace _dali.model "access": { "public": calendar_object.access.public, "default_level": _dali.access_level_encode(calendar_object.access.default_level), - "attributed": ( - lib_plankton.map.dump(calendar_object.access.attributed) + "attributed_group": ( + lib_plankton.map.dump(calendar_object.access.attributed_group) + .map( + (pair) => ({ + "group_id": pair.key, + "level": _dali.access_level_encode(pair.value), + }) + ) + ), + "attributed_user": ( + lib_plankton.map.dump(calendar_object.access.attributed_user) .map( (pair) => ({ "user_id": pair.key, "level": _dali.access_level_encode(pair.value), }) ) - ) + ), }, } ); @@ -554,13 +615,8 @@ namespace _dali.model : Promise { _state = { - "users": ( - _dali.is_logged_in() - ? - (await _dali.backend.user_list()) - : - [] - ), + "groups": [], + "users": [], "calendars": lib_plankton.map.hashmap.implementation_map( lib_plankton.map.hashmap.make( calendar_id => calendar_id.toFixed(0) @@ -577,6 +633,20 @@ namespace _dali.model _dali.listen_login( async () => { + _state.groups = ( + (await _dali.backend.group_list()) + .map( + entry => ( + { + "id": entry.id, + "object": { + "name": entry.name, + "label": entry.label, + } + } + ) + ) + ); _state.users = await _dali.backend.user_list(); await sync_calendars(); lib_plankton.map.clear(_state.events); @@ -586,6 +656,7 @@ namespace _dali.model ); _dali.listen_logout( async () => { + _state.groups = []; _state.users = []; await sync_calendars(); lib_plankton.map.clear(_state.events); diff --git a/source/pages/overview/logic.ts b/source/pages/overview/logic.ts index 374caab..bb026aa 100644 --- a/source/pages/overview/logic.ts +++ b/source/pages/overview/logic.ts @@ -136,6 +136,7 @@ namespace _dali.pages.overview : Promise { const widget = new _dali.widgets.calendar_edit.class_widget_calendar_edit( + await _dali.model.group_list(), await _dali.model.user_list(), { "name": "", @@ -143,7 +144,18 @@ namespace _dali.pages.overview "access": { "public": false, "default_level": _dali.enum_access_level.view, - "attributed": lib_plankton.map.hashmap.implementation_map< + "attributed_group": lib_plankton.map.hashmap.implementation_map< + _dali.type_group_id, + _dali.enum_access_level + >( + lib_plankton.map.hashmap.make< + _dali.type_group_id, + _dali.enum_access_level + >( + group_id => group_id.toFixed(0), + ) + ), + "attributed_user": lib_plankton.map.hashmap.implementation_map< _dali.type_user_id, _dali.enum_access_level >( @@ -235,6 +247,7 @@ namespace _dali.pages.overview calendar_id ); const widget = new _dali.widgets.calendar_edit.class_widget_calendar_edit( + await _dali.model.group_list(), await _dali.model.user_list(), calendar_object, { @@ -290,75 +303,82 @@ namespace _dali.pages.overview ) : Promise { - const widget = new _dali.widgets.event_edit.class_widget_event_edit( - (await get_available_calendars()), - { - "calendar_id": null, - "event_name": "", - "event_begin": lib_plankton.call.convey( - date, - [ - x => ({ - "timezone_shift": 0, - "date": date, - "time": {"hour": 12, "minute": 0, "second": 0} - }), - lib_plankton.pit.from_datetime, - x => lib_plankton.pit.shift_hour(x, 0), - lib_plankton.pit.to_datetime, - ] - ), - "event_end": lib_plankton.call.convey( - date, - [ - x => ({ - "timezone_shift": 0, - "date": date, - "time": {"hour": 12, "minute": 0, "second": 0} - }), - lib_plankton.pit.from_datetime, - x => lib_plankton.pit.shift_hour(x, +1), - lib_plankton.pit.to_datetime, - ] - ), - "event_location": null, - "event_link": null, - "event_description": null, - }, - { - "read_only": false, - "action_cancel": () => { - _dali.overlay.toggle({"mode": false}); + if (! _dali.is_logged_in()) + { + // do nothing + } + else + { + const widget = new _dali.widgets.event_edit.class_widget_event_edit( + (await get_available_calendars()), + { + "calendar_id": null, + "event_name": "", + "event_begin": lib_plankton.call.convey( + date, + [ + x => ({ + "timezone_shift": 0, + "date": date, + "time": {"hour": 12, "minute": 0, "second": 0} + }), + lib_plankton.pit.from_datetime, + x => lib_plankton.pit.shift_hour(x, 0), + lib_plankton.pit.to_datetime, + ] + ), + "event_end": lib_plankton.call.convey( + date, + [ + x => ({ + "timezone_shift": 0, + "date": date, + "time": {"hour": 12, "minute": 0, "second": 0} + }), + lib_plankton.pit.from_datetime, + x => lib_plankton.pit.shift_hour(x, +1), + lib_plankton.pit.to_datetime, + ] + ), + "event_location": null, + "event_link": null, + "event_description": null, }, - "action_add": (data) => { - _dali.model.event_add( - data.calendar_id, - { - "name": data.event_name, - "begin": data.event_begin, - "end": data.event_end, - "location": data.event_location, - "link": data.event_link, - "description": data.event_description, - } - ) - .then( - () => { - update_entries(); - _dali.overlay.toggle({"mode": false}); - } - ) - .catch( - (reason) => { - // todo - } - ); - }, - } - ); - _dali.overlay.clear(); - _dali.overlay.toggle({"mode": true}); - await widget.load(_dali.overlay.get_content_element()); + { + "read_only": false, + "action_cancel": () => { + _dali.overlay.toggle({"mode": false}); + }, + "action_add": (data) => { + _dali.model.event_add( + data.calendar_id, + { + "name": data.event_name, + "begin": data.event_begin, + "end": data.event_end, + "location": data.event_location, + "link": data.event_link, + "description": data.event_description, + } + ) + .then( + () => { + update_entries(); + _dali.overlay.toggle({"mode": false}); + } + ) + .catch( + (reason) => { + // todo + } + ); + }, + } + ); + _dali.overlay.clear(); + _dali.overlay.toggle({"mode": true}); + await widget.load(_dali.overlay.get_content_element()); + } } /** diff --git a/source/resources/backend.ts b/source/resources/backend.ts index 3fc73d1..fc43fb7 100644 --- a/source/resources/backend.ts +++ b/source/resources/backend.ts @@ -411,6 +411,28 @@ namespace _dali.backend } + /** + */ + export function group_list( + ) + : Promise< + Array< + { + id : int; + name : string; + label : string; + } + > + > + { + return call( + lib_plankton.http.enum_method.get, + "/groups", + null + ); + } + + /** */ export function user_list( @@ -512,12 +534,18 @@ namespace _dali.backend access : { public : boolean; default_level : string; - attributed : Array< + attributed_group : Array< + { + group_id : int; + level : string; + } + >; + attributed_user : Array< { user_id : int; level : string; } - > + >; }; resource_id : int; } @@ -544,7 +572,13 @@ namespace _dali.backend access : { public : boolean; default_level : string; - attributed : Array< + attributed_group : Array< + { + group_id : int; + level : string; + } + >; + attributed_user : Array< { user_id : int; level : string; @@ -595,7 +629,13 @@ namespace _dali.backend access : { public : boolean; default_level : string; - attributed : Array< + attributed_group : Array< + { + group_id : int; + level : string; + } + >; + attributed_user : Array< { user_id : int; level : string; diff --git a/source/types.ts b/source/types.ts index 1f7b695..7c79492 100644 --- a/source/types.ts +++ b/source/types.ts @@ -14,6 +14,19 @@ namespace _dali } + /** + */ + export type type_group_id = int; + + + /** + */ + export type type_group_object = { + name : string; + label : string; + }; + + /** */ export type type_user_id = int; @@ -23,6 +36,7 @@ namespace _dali */ export type type_user_object = { name : string; + label : string; email_address : ( null | @@ -137,7 +151,11 @@ namespace _dali access : { public : boolean; default_level : enum_access_level; - attributed : lib_plankton.map.type_map< + attributed_group : lib_plankton.map.type_map< + type_group_id, + enum_access_level + >; + attributed_user : lib_plankton.map.type_map< type_user_id, enum_access_level >; diff --git a/source/widgets/calendar_edit/logic.ts b/source/widgets/calendar_edit/logic.ts index a5b54e4..9b3e970 100644 --- a/source/widgets/calendar_edit/logic.ts +++ b/source/widgets/calendar_edit/logic.ts @@ -7,6 +7,11 @@ namespace _dali.widgets.calendar_edit implements lib_plankton.zoo_widget.interface_widget { + /** + */ + private groups : Array<{id : _dali.type_group_id; object : _dali.type_group_object;}>; + + /** */ private users : Array<{id : _dali.type_user_id; name : string;}>; @@ -45,6 +50,7 @@ namespace _dali.widgets.calendar_edit /** */ public constructor( + groups : Array<{id : _dali.type_group_id; object : _dali.type_group_object;}>, users : Array<{id : _dali.type_user_id; name : string;}>, initial_value : _dali.type_calendar_object, { @@ -67,6 +73,7 @@ namespace _dali.widgets.calendar_edit } ) { + this.groups = groups; this.users = users; this.initial_value = initial_value; this.read_only = read_only; @@ -121,9 +128,14 @@ namespace _dali.widgets.calendar_edit "label": lib_plankton.translate.get("calendar.access.default_level"), }, { - "name": "attributed", - "input": _dali.helpers.input_attributed_access(this.users), - "label": lib_plankton.translate.get("calendar.access.attributed"), + "name": "attributed_group", + "input": _dali.helpers.input_attributed_access_group(this.groups), + "label": lib_plankton.translate.get("calendar.access.attributed_group"), + }, + { + "name": "attributed_user", + "input": _dali.helpers.input_attributed_access_user(this.users), + "label": lib_plankton.translate.get("calendar.access.attributed_user"), }, ] ),