From 521436dd218781d560384a330b93d6cca82eb8f1 Mon Sep 17 00:00:00 2001 From: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> Date: Thu, 28 Sep 2023 19:47:31 +0200 Subject: [PATCH] feat(server): Add week numbers for templating (#4263) * add week numbers as template option * generate api * fix tests * change example date to show week padding * change example date to immich birthday --- cli/src/api/open-api/api.ts | 6 ++++++ .../doc/SystemConfigTemplateStorageOptionDto.md | 1 + .../system_config_template_storage_option_dto.dart | 12 +++++++++++- ...tem_config_template_storage_option_dto_test.dart | 5 +++++ server/immich-openapi-specs.json | 7 +++++++ .../storage-template/storage-template.service.ts | 2 ++ .../system-config-template-storage-option.dto.ts | 1 + .../domain/system-config/system-config.constants.ts | 2 ++ .../system-config/system-config.service.spec.ts | 2 ++ .../domain/system-config/system-config.service.ts | 2 ++ web/src/api/open-api/api.ts | 6 ++++++ .../storage-template-settings.svelte | 3 ++- .../supported-datetime-panel.svelte | 13 +++++++++++-- 13 files changed, 58 insertions(+), 4 deletions(-) diff --git a/cli/src/api/open-api/api.ts b/cli/src/api/open-api/api.ts index f9c983833f..67334711ee 100644 --- a/cli/src/api/open-api/api.ts +++ b/cli/src/api/open-api/api.ts @@ -3542,6 +3542,12 @@ export interface SystemConfigTemplateStorageOptionDto { * @memberof SystemConfigTemplateStorageOptionDto */ 'secondOptions': Array; + /** + * + * @type {Array} + * @memberof SystemConfigTemplateStorageOptionDto + */ + 'weekOptions': Array; /** * * @type {Array} diff --git a/mobile/openapi/doc/SystemConfigTemplateStorageOptionDto.md b/mobile/openapi/doc/SystemConfigTemplateStorageOptionDto.md index 18adaa6fad..6465fcbef8 100644 --- a/mobile/openapi/doc/SystemConfigTemplateStorageOptionDto.md +++ b/mobile/openapi/doc/SystemConfigTemplateStorageOptionDto.md @@ -14,6 +14,7 @@ Name | Type | Description | Notes **monthOptions** | **List** | | [default to const []] **presetOptions** | **List** | | [default to const []] **secondOptions** | **List** | | [default to const []] +**weekOptions** | **List** | | [default to const []] **yearOptions** | **List** | | [default to const []] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/mobile/openapi/lib/model/system_config_template_storage_option_dto.dart b/mobile/openapi/lib/model/system_config_template_storage_option_dto.dart index 23d17e16aa..da9138745f 100644 --- a/mobile/openapi/lib/model/system_config_template_storage_option_dto.dart +++ b/mobile/openapi/lib/model/system_config_template_storage_option_dto.dart @@ -19,6 +19,7 @@ class SystemConfigTemplateStorageOptionDto { this.monthOptions = const [], this.presetOptions = const [], this.secondOptions = const [], + this.weekOptions = const [], this.yearOptions = const [], }); @@ -34,6 +35,8 @@ class SystemConfigTemplateStorageOptionDto { List secondOptions; + List weekOptions; + List yearOptions; @override @@ -44,6 +47,7 @@ class SystemConfigTemplateStorageOptionDto { other.monthOptions == monthOptions && other.presetOptions == presetOptions && other.secondOptions == secondOptions && + other.weekOptions == weekOptions && other.yearOptions == yearOptions; @override @@ -55,10 +59,11 @@ class SystemConfigTemplateStorageOptionDto { (monthOptions.hashCode) + (presetOptions.hashCode) + (secondOptions.hashCode) + + (weekOptions.hashCode) + (yearOptions.hashCode); @override - String toString() => 'SystemConfigTemplateStorageOptionDto[dayOptions=$dayOptions, hourOptions=$hourOptions, minuteOptions=$minuteOptions, monthOptions=$monthOptions, presetOptions=$presetOptions, secondOptions=$secondOptions, yearOptions=$yearOptions]'; + String toString() => 'SystemConfigTemplateStorageOptionDto[dayOptions=$dayOptions, hourOptions=$hourOptions, minuteOptions=$minuteOptions, monthOptions=$monthOptions, presetOptions=$presetOptions, secondOptions=$secondOptions, weekOptions=$weekOptions, yearOptions=$yearOptions]'; Map toJson() { final json = {}; @@ -68,6 +73,7 @@ class SystemConfigTemplateStorageOptionDto { json[r'monthOptions'] = this.monthOptions; json[r'presetOptions'] = this.presetOptions; json[r'secondOptions'] = this.secondOptions; + json[r'weekOptions'] = this.weekOptions; json[r'yearOptions'] = this.yearOptions; return json; } @@ -98,6 +104,9 @@ class SystemConfigTemplateStorageOptionDto { secondOptions: json[r'secondOptions'] is List ? (json[r'secondOptions'] as List).cast() : const [], + weekOptions: json[r'weekOptions'] is List + ? (json[r'weekOptions'] as List).cast() + : const [], yearOptions: json[r'yearOptions'] is List ? (json[r'yearOptions'] as List).cast() : const [], @@ -154,6 +163,7 @@ class SystemConfigTemplateStorageOptionDto { 'monthOptions', 'presetOptions', 'secondOptions', + 'weekOptions', 'yearOptions', }; } diff --git a/mobile/openapi/test/system_config_template_storage_option_dto_test.dart b/mobile/openapi/test/system_config_template_storage_option_dto_test.dart index 57e059d9b8..6082748336 100644 --- a/mobile/openapi/test/system_config_template_storage_option_dto_test.dart +++ b/mobile/openapi/test/system_config_template_storage_option_dto_test.dart @@ -46,6 +46,11 @@ void main() { // TODO }); + // List weekOptions (default value: const []) + test('to test the property `weekOptions`', () async { + // TODO + }); + // List yearOptions (default value: const []) test('to test the property `yearOptions`', () async { // TODO diff --git a/server/immich-openapi-specs.json b/server/immich-openapi-specs.json index 21a905f6bd..a1f63e450d 100644 --- a/server/immich-openapi-specs.json +++ b/server/immich-openapi-specs.json @@ -7924,6 +7924,12 @@ }, "type": "array" }, + "weekOptions": { + "items": { + "type": "string" + }, + "type": "array" + }, "yearOptions": { "items": { "type": "string" @@ -7934,6 +7940,7 @@ "required": [ "yearOptions", "monthOptions", + "weekOptions", "dayOptions", "hourOptions", "minuteOptions", diff --git a/server/src/domain/storage-template/storage-template.service.ts b/server/src/domain/storage-template/storage-template.service.ts index 5191bf557d..f6265c972e 100644 --- a/server/src/domain/storage-template/storage-template.service.ts +++ b/server/src/domain/storage-template/storage-template.service.ts @@ -16,6 +16,7 @@ import { supportedMinuteTokens, supportedMonthTokens, supportedSecondTokens, + supportedWeekTokens, supportedYearTokens, } from '../system-config'; import { SystemConfigCore } from '../system-config/system-config.core'; @@ -239,6 +240,7 @@ export class StorageTemplateService { const dateTokens = [ ...supportedYearTokens, ...supportedMonthTokens, + ...supportedWeekTokens, ...supportedDayTokens, ...supportedHourTokens, ...supportedMinuteTokens, diff --git a/server/src/domain/system-config/response-dto/system-config-template-storage-option.dto.ts b/server/src/domain/system-config/response-dto/system-config-template-storage-option.dto.ts index c9150f1ddd..f0c8b9b64a 100644 --- a/server/src/domain/system-config/response-dto/system-config-template-storage-option.dto.ts +++ b/server/src/domain/system-config/response-dto/system-config-template-storage-option.dto.ts @@ -1,6 +1,7 @@ export class SystemConfigTemplateStorageOptionDto { yearOptions!: string[]; monthOptions!: string[]; + weekOptions!: string[]; dayOptions!: string[]; hourOptions!: string[]; minuteOptions!: string[]; diff --git a/server/src/domain/system-config/system-config.constants.ts b/server/src/domain/system-config/system-config.constants.ts index 6197dbf217..ca0497a9da 100644 --- a/server/src/domain/system-config/system-config.constants.ts +++ b/server/src/domain/system-config/system-config.constants.ts @@ -1,5 +1,6 @@ export const supportedYearTokens = ['y', 'yy']; export const supportedMonthTokens = ['M', 'MM', 'MMM', 'MMMM']; +export const supportedWeekTokens = ['W', 'WW']; export const supportedDayTokens = ['d', 'dd']; export const supportedHourTokens = ['h', 'hh', 'H', 'HH']; export const supportedMinuteTokens = ['m', 'mm']; @@ -18,6 +19,7 @@ export const supportedPresetTokens = [ '{{y}}-{{MMM}}-{{dd}}/{{filename}}', '{{y}}-{{MMMM}}-{{dd}}/{{filename}}', '{{y}}/{{y}}-{{MM}}/{{filename}}', + '{{y}}/{{y}}-{{WW}}/{{filename}}', ]; export const INITIAL_SYSTEM_CONFIG = 'INITIAL_SYSTEM_CONFIG'; diff --git a/server/src/domain/system-config/system-config.service.spec.ts b/server/src/domain/system-config/system-config.service.spec.ts index fc50839ba7..e084da9ad3 100644 --- a/server/src/domain/system-config/system-config.service.spec.ts +++ b/server/src/domain/system-config/system-config.service.spec.ts @@ -221,8 +221,10 @@ describe(SystemConfigService.name, () => { '{{y}}-{{MMM}}-{{dd}}/{{filename}}', '{{y}}-{{MMMM}}-{{dd}}/{{filename}}', '{{y}}/{{y}}-{{MM}}/{{filename}}', + '{{y}}/{{y}}-{{WW}}/{{filename}}', ], secondOptions: ['s', 'ss'], + weekOptions: ['W', 'WW'], yearOptions: ['y', 'yy'], }); }); diff --git a/server/src/domain/system-config/system-config.service.ts b/server/src/domain/system-config/system-config.service.ts index cf289b7f97..3359175010 100644 --- a/server/src/domain/system-config/system-config.service.ts +++ b/server/src/domain/system-config/system-config.service.ts @@ -10,6 +10,7 @@ import { supportedMonthTokens, supportedPresetTokens, supportedSecondTokens, + supportedWeekTokens, supportedYearTokens, } from './system-config.constants'; import { SystemConfigCore, SystemConfigValidator } from './system-config.core'; @@ -57,6 +58,7 @@ export class SystemConfigService { const options = new SystemConfigTemplateStorageOptionDto(); options.dayOptions = supportedDayTokens; + options.weekOptions = supportedWeekTokens; options.monthOptions = supportedMonthTokens; options.yearOptions = supportedYearTokens; options.hourOptions = supportedHourTokens; diff --git a/web/src/api/open-api/api.ts b/web/src/api/open-api/api.ts index f9c983833f..67334711ee 100644 --- a/web/src/api/open-api/api.ts +++ b/web/src/api/open-api/api.ts @@ -3542,6 +3542,12 @@ export interface SystemConfigTemplateStorageOptionDto { * @memberof SystemConfigTemplateStorageOptionDto */ 'secondOptions': Array; + /** + * + * @type {Array} + * @memberof SystemConfigTemplateStorageOptionDto + */ + 'weekOptions': Array; /** * * @type {Array} diff --git a/web/src/lib/components/admin-page/settings/storage-template/storage-template-settings.svelte b/web/src/lib/components/admin-page/settings/storage-template/storage-template-settings.svelte index 5cee5edb46..c0018edcb7 100644 --- a/web/src/lib/components/admin-page/settings/storage-template/storage-template-settings.svelte +++ b/web/src/lib/components/admin-page/settings/storage-template/storage-template-settings.svelte @@ -58,11 +58,12 @@ filetypefull: 'IMAGE', }; - const dt = luxon.DateTime.fromISO(new Date('2022-09-04T20:03:05.250').toISOString()); + const dt = luxon.DateTime.fromISO(new Date('2022-02-03T04:56:05.250').toISOString()); const dateTokens = [ ...templateOptions.yearOptions, ...templateOptions.monthOptions, + ...templateOptions.weekOptions, ...templateOptions.dayOptions, ...templateOptions.hourOptions, ...templateOptions.minuteOptions, diff --git a/web/src/lib/components/admin-page/settings/storage-template/supported-datetime-panel.svelte b/web/src/lib/components/admin-page/settings/storage-template/supported-datetime-panel.svelte index d95c58fda5..8a72268240 100644 --- a/web/src/lib/components/admin-page/settings/storage-template/supported-datetime-panel.svelte +++ b/web/src/lib/components/admin-page/settings/storage-template/supported-datetime-panel.svelte @@ -16,9 +16,9 @@

Asset's creation timestamp is used for the datetime information

-

Sample time 2022-09-04T20:03:05.250

+

Sample time 2022-02-03T04:56:05.250

-
+

YEAR

    @@ -37,6 +37,15 @@
+
+

WEEK

+
    + {#each options.weekOptions as weekFormat} +
  • {'{{'}{weekFormat}{'}}'} - {getLuxonExample(weekFormat)}
  • + {/each} +
+
+

DAY