diff --git a/src/lib/components/assignment/SideMenu/CreateAssignmentInner.svelte b/src/lib/components/assignment/SideMenu/CreateAssignmentInner.svelte index fde946f..b7fe72a 100644 --- a/src/lib/components/assignment/SideMenu/CreateAssignmentInner.svelte +++ b/src/lib/components/assignment/SideMenu/CreateAssignmentInner.svelte @@ -45,9 +45,11 @@ import QuickAction from '$lib/components/buttons/QuickAction.svelte'; import NotTyppable from '$lib/components/select/NotTyppable.svelte'; import { self } from '$lib/utils/utils'; + import { mapObject } from '$lib/utils/objects/map'; const timetable = svocal('settings.timetable'); const presets = svocal('settings.homeworkPresets'); + const defaultSubjects = svocal('settings.homework.defaultSubject'); const dispatch = createEventDispatcher<{ submit: CreationPayload }>(); @@ -60,7 +62,11 @@ const initiallySelected = allowedClasses.filter(showClass); let classes: Class[] = []; - let classInput = initiallySelected.length === 1 ? initiallySelected[0] : ''; + const classInput = writable(initiallySelected.length === 1 ? initiallySelected[0] : ''); + $: { + const initiallySelected = selectableClasses.filter(showClass); + classInput.set(initiallySelected.length === 1 ? initiallySelected[0] : ''); + } let subject = ''; let description = ''; @@ -71,7 +77,7 @@ let inputMode: 'text' | 'presets' = 'text'; $: disabled = !( - classInput && + $classInput && subject && description && customDateToNormal(due) > customDateToNormal(from) @@ -90,6 +96,11 @@ due = normalToCustomDate(date); } + classInput.subscribe((cl) => { + const lowercased = mapObject($defaultSubjects, (key) => key.toLowerCase(), self); + subject = lowercased[cl.toLowerCase()] || subject; + }); + wasSuccessfull.subscribe((successfull) => { if (successfull) { subject = ''; @@ -115,8 +126,8 @@ label: readable(name), value: name }))} - value={[classInput]} - bind:firstValue={classInput} + value={[$classInput]} + bind:firstValue={$classInput} threshold={0.1} /> {/if} @@ -175,7 +186,7 @@ {disabled} on:click={() => { disabled = true; - dispatch('submit', { description, subject, due, from, school, class: classInput }); + dispatch('submit', { description, subject, due, from, school, class: $classInput }); }} > diff --git a/src/lib/constants/settings.ts b/src/lib/constants/settings.ts index 96419ba..53958b0 100644 --- a/src/lib/constants/settings.ts +++ b/src/lib/constants/settings.ts @@ -1,5 +1,5 @@ import type { Readable } from 'svelte/store'; -import { Calendar, Cog, PaintBrush, User, type IconSource } from 'svelte-hero-icons'; +import { Calendar, Cog, PaintBrush, User, BookOpen, type IconSource } from 'svelte-hero-icons'; import { i } from '$lib/i18n/store'; type Setting = @@ -31,6 +31,11 @@ export const settings: Setting[] = [ uri: '/color', label: i('settings.color'), icon: PaintBrush + }, + { + uri: '/homework', + label: i('settings.assignments'), + icon: BookOpen } ]; diff --git a/src/lib/locales/de.ts b/src/lib/locales/de.ts index 9762537..2b984f7 100644 --- a/src/lib/locales/de.ts +++ b/src/lib/locales/de.ts @@ -471,9 +471,6 @@ const de = { 'Ziehe ein Rechteck hier her, um es zu aus der Navigation zu entfernen.', 'settings.general.calendar': 'Kalender', 'settings.general.calendar.weekStartsOn': 'Erster Tag der Woche', - 'settings.general.assignments': 'Hausaufgaben', - 'settings.general.assignments.transparency': 'Transparenz überfälliger Hausaufgaben', - 'settings.general.assignments.presets': 'Voreinstellungen für neue Hausaufgaben', 'settings.general.launcher': 'Suche', 'settings.general.launcher.outlineWidth': 'Breite der grünen Umrandung', 'settings.general.launcher.width': 'Breite', @@ -526,6 +523,15 @@ const de = { 'settings.api.success': 'Erfolgreich gespeichert', 'settings.api.error': 'Hierbei handelt es sich nicht um einen Dlool Server', + 'settings.assignments': 'Hausaufgaben', + 'settings.assignments.title': 'Hausaufgaben Einstellungen', + 'settings.assignments.transparency': 'Transparenz überfälliger Hausaufgaben', + 'settings.assignments.presets': 'Voreinstellungen für neue Hausaufgaben', + 'settings.assignments.presets.new': 'Neues hinzufügen', + 'settings.assignments.default': 'Standard Fächer für Kurse', + 'settings.assignments.default.class.placeholder': 'Klasse/Kurs', + 'settings.assignments.default.class.subject': 'Fach', + 'settings.save': 'Speichern', 'holiday.noData': 'Es gibt keine Daten für diesen Monat', diff --git a/src/lib/locales/en.ts b/src/lib/locales/en.ts index e92257c..759635c 100644 --- a/src/lib/locales/en.ts +++ b/src/lib/locales/en.ts @@ -459,9 +459,6 @@ const en = { 'Drag and drop one rectangle here to remove it from your navigation.', 'settings.general.calendar': 'Calendar', 'settings.general.calendar.weekStartsOn': 'First day of the week', - 'settings.general.assignments': 'Assignments', - 'settings.general.assignments.transparency': 'transparency of overdue assignments', - 'settings.general.assignments.presets': 'Presets for new assignments', 'settings.general.launcher': 'Launcher', 'settings.general.launcher.outlineWidth': 'Width of the green outline', 'settings.general.launcher.width': 'Width', @@ -513,6 +510,15 @@ const en = { 'settings.api.success': 'Successfully saved', 'settings.api.error': "This isn't a Dlool-server", + 'settings.assignments': 'Assignments', + 'settings.assignments.title': 'Assignment-Settings', + 'settings.assignments.transparency': 'transparency of overdue assignments', + 'settings.assignments.presets': 'Presets for new assignments', + 'settings.assignments.presets.new': 'Add a new one', + 'settings.assignments.default': 'Default subjects for courses', + 'settings.assignments.default.class.placeholder': 'Course', + 'settings.assignments.default.class.subject': 'Subject', + 'settings.save': 'Save', 'holiday.noData': 'There is not data for this month', diff --git a/src/lib/utils/store/svocal.ts b/src/lib/utils/store/svocal.ts index 1564628..a0df260 100644 --- a/src/lib/utils/store/svocal.ts +++ b/src/lib/utils/store/svocal.ts @@ -62,6 +62,10 @@ const sv = { 'holidays.state': ['holidays.state', () => 'HE'], 'holidays.autoDetect': ['holidays.autoDetect', () => true], 'settings.homeworkPresets': ['settings.homeworkPresets', () => [] as string[]], + 'settings.homework.defaultSubject': [ + 'settings.homework.defaultSubject', + () => ({}) as Record + ], 'dlool-version': ['dlool-version', () => '2'] } as const; diff --git a/src/routes/settings/general/+page.svelte b/src/routes/settings/general/+page.svelte index efb39ea..df53a2c 100644 --- a/src/routes/settings/general/+page.svelte +++ b/src/routes/settings/general/+page.svelte @@ -1,5 +1,4 @@ + + + +
+

+ + `${Math.round(num * 100)}%`} + /> + +
+ + +
+ {#each $homeworkPresets as preset, ind} + + + homeworkPresets.update((old) => removeNthElement(old, ind))} + /> + + {/each} + + x.trim()).includes('')} + on:click={() => homeworkPresets.update((old) => ['', ...old])} + > + + +
+
+ +
+

+
+ {#each objectEntries($defaultSubjects) as [className, subject]} +
+ + { + defaultSubjects.update((obj) => removeKey(obj, className)); + }} + /> + { + defaultSubjects.update((obj) => replaceKey(obj, className, detail)); + }} + /> + + + + { + defaultSubjects.update((old) => { + old[className] = detail; + return old; + }); + }} + /> + +
+ {/each} + +
+ { + defaultSubjects.update((old) => ({ ...old, '': '' })); + }} + /> +
+
+
+