2023-09-08 22:51:46 -04:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {
|
|
|
|
|
notificationController,
|
|
|
|
|
NotificationType,
|
|
|
|
|
} from '$lib/components/shared-components/notification/notification';
|
|
|
|
|
import { handleError } from '$lib/utils/handle-error';
|
2023-11-25 18:53:30 +00:00
|
|
|
import { api, SystemConfigDto } from '@api';
|
2023-09-26 09:03:57 +02:00
|
|
|
import { cloneDeep, isEqual } from 'lodash-es';
|
2023-09-08 22:51:46 -04:00
|
|
|
import { fade } from 'svelte/transition';
|
2023-09-26 09:03:57 +02:00
|
|
|
import SettingAccordion from '../setting-accordion.svelte';
|
2023-09-08 22:51:46 -04:00
|
|
|
import SettingButtonsRow from '../setting-buttons-row.svelte';
|
2023-09-26 09:03:57 +02:00
|
|
|
import SettingSwitch from '../setting-switch.svelte';
|
2023-11-09 17:10:56 +01:00
|
|
|
import SettingInputField, { SettingInputFieldType } from '../setting-input-field.svelte';
|
2023-12-14 17:55:15 +01:00
|
|
|
import type { ResetOptions } from '$lib/utils/dipatch';
|
2023-09-08 22:51:46 -04:00
|
|
|
|
2023-09-26 09:03:57 +02:00
|
|
|
export let config: SystemConfigDto; // this is the config that is being edited
|
2023-09-08 22:51:46 -04:00
|
|
|
export let disabled = false;
|
|
|
|
|
|
2023-09-26 09:03:57 +02:00
|
|
|
let savedConfig: SystemConfigDto;
|
|
|
|
|
let defaultConfig: SystemConfigDto;
|
2023-09-08 22:51:46 -04:00
|
|
|
|
2023-12-14 17:55:15 +01:00
|
|
|
const handleReset = (detail: ResetOptions) => {
|
|
|
|
|
if (detail.default) {
|
|
|
|
|
resetToDefault();
|
|
|
|
|
} else {
|
|
|
|
|
reset();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-26 09:03:57 +02:00
|
|
|
async function refreshConfig() {
|
2023-09-08 22:51:46 -04:00
|
|
|
[savedConfig, defaultConfig] = await Promise.all([
|
2023-09-26 09:03:57 +02:00
|
|
|
api.systemConfigApi.getConfig().then((res) => res.data),
|
2023-11-03 21:33:15 -04:00
|
|
|
api.systemConfigApi.getConfigDefaults().then((res) => res.data),
|
2023-09-08 22:51:46 -04:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function saveSetting() {
|
|
|
|
|
try {
|
|
|
|
|
const { data: current } = await api.systemConfigApi.getConfig();
|
|
|
|
|
const { data: updated } = await api.systemConfigApi.updateConfig({
|
2023-09-26 09:03:57 +02:00
|
|
|
systemConfigDto: {
|
|
|
|
|
...current,
|
|
|
|
|
map: {
|
|
|
|
|
enabled: config.map.enabled,
|
2023-11-09 17:10:56 +01:00
|
|
|
lightStyle: config.map.lightStyle,
|
|
|
|
|
darkStyle: config.map.darkStyle,
|
2023-09-26 09:03:57 +02:00
|
|
|
},
|
|
|
|
|
reverseGeocoding: {
|
|
|
|
|
enabled: config.reverseGeocoding.enabled,
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-09-08 22:51:46 -04:00
|
|
|
});
|
|
|
|
|
|
2023-09-26 09:03:57 +02:00
|
|
|
config = cloneDeep(updated);
|
|
|
|
|
savedConfig = cloneDeep(updated);
|
2023-09-08 22:51:46 -04:00
|
|
|
|
|
|
|
|
notificationController.show({ message: 'Settings saved', type: NotificationType.Info });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
handleError(error, 'Unable to save settings');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function reset() {
|
|
|
|
|
const { data: resetConfig } = await api.systemConfigApi.getConfig();
|
|
|
|
|
|
2023-09-26 09:03:57 +02:00
|
|
|
config = cloneDeep(resetConfig);
|
|
|
|
|
savedConfig = cloneDeep(resetConfig);
|
2023-09-08 22:51:46 -04:00
|
|
|
|
|
|
|
|
notificationController.show({
|
|
|
|
|
message: 'Reset settings to the recent saved settings',
|
|
|
|
|
type: NotificationType.Info,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function resetToDefault() {
|
2023-11-03 21:33:15 -04:00
|
|
|
const { data: configs } = await api.systemConfigApi.getConfigDefaults();
|
2023-09-08 22:51:46 -04:00
|
|
|
|
2023-09-26 09:03:57 +02:00
|
|
|
config = cloneDeep(configs);
|
|
|
|
|
defaultConfig = cloneDeep(configs);
|
2023-09-08 22:51:46 -04:00
|
|
|
|
|
|
|
|
notificationController.show({
|
|
|
|
|
message: 'Reset map settings to default',
|
|
|
|
|
type: NotificationType.Info,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2023-09-26 09:03:57 +02:00
|
|
|
<div class="mt-2">
|
|
|
|
|
{#await refreshConfig() then}
|
2023-09-08 22:51:46 -04:00
|
|
|
<div in:fade={{ duration: 500 }}>
|
|
|
|
|
<form autocomplete="off" on:submit|preventDefault>
|
2023-09-26 09:03:57 +02:00
|
|
|
<div class="flex flex-col gap-4">
|
|
|
|
|
<SettingAccordion title="Map Settings" subtitle="Manage map settings">
|
|
|
|
|
<div class="ml-4 mt-4 flex flex-col gap-4">
|
|
|
|
|
<SettingSwitch
|
|
|
|
|
title="ENABLED"
|
|
|
|
|
{disabled}
|
|
|
|
|
subtitle="Enable map features"
|
|
|
|
|
bind:checked={config.map.enabled}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
|
|
<SettingInputField
|
|
|
|
|
inputType={SettingInputFieldType.TEXT}
|
2023-11-09 17:10:56 +01:00
|
|
|
label="Light Style"
|
|
|
|
|
desc="URL to a style.json map theme"
|
|
|
|
|
bind:value={config.map.lightStyle}
|
|
|
|
|
disabled={disabled || !config.map.enabled}
|
|
|
|
|
isEdited={config.map.lightStyle !== savedConfig.map.lightStyle}
|
|
|
|
|
/>
|
|
|
|
|
<SettingInputField
|
|
|
|
|
inputType={SettingInputFieldType.TEXT}
|
|
|
|
|
label="Dark Style"
|
|
|
|
|
desc="URL to a style.json map theme"
|
|
|
|
|
bind:value={config.map.darkStyle}
|
2023-09-26 09:03:57 +02:00
|
|
|
disabled={disabled || !config.map.enabled}
|
2023-11-09 17:10:56 +01:00
|
|
|
isEdited={config.map.darkStyle !== savedConfig.map.darkStyle}
|
2023-09-26 09:03:57 +02:00
|
|
|
/>
|
|
|
|
|
</div></SettingAccordion
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
<SettingAccordion title="Reverse Geocoding Settings">
|
|
|
|
|
<svelte:fragment slot="subtitle">
|
|
|
|
|
<p class="text-sm dark:text-immich-dark-fg">
|
|
|
|
|
Manage <a
|
|
|
|
|
href="https://immich.app/docs/features/reverse-geocoding"
|
|
|
|
|
class="underline"
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer">Reverse Geocoding</a
|
|
|
|
|
> settings
|
|
|
|
|
</p>
|
|
|
|
|
</svelte:fragment>
|
|
|
|
|
<div class="ml-4 mt-4 flex flex-col gap-4">
|
|
|
|
|
<SettingSwitch
|
|
|
|
|
title="ENABLED"
|
|
|
|
|
{disabled}
|
|
|
|
|
subtitle="Enable reverse geocoding"
|
|
|
|
|
bind:checked={config.reverseGeocoding.enabled}
|
|
|
|
|
/>
|
|
|
|
|
</div></SettingAccordion
|
|
|
|
|
>
|
2023-09-08 22:51:46 -04:00
|
|
|
|
|
|
|
|
<SettingButtonsRow
|
2023-12-14 17:55:15 +01:00
|
|
|
on:reset={({ detail }) => handleReset(detail)}
|
2023-09-08 22:51:46 -04:00
|
|
|
on:save={saveSetting}
|
2023-09-26 09:03:57 +02:00
|
|
|
showResetToDefault={!isEqual(
|
|
|
|
|
{ ...savedConfig.map, ...savedConfig.reverseGeocoding },
|
|
|
|
|
{ ...defaultConfig.map, ...defaultConfig.reverseGeocoding },
|
|
|
|
|
)}
|
2023-09-08 22:51:46 -04:00
|
|
|
{disabled}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
|
|
|
|
{/await}
|
|
|
|
|
</div>
|