diff --git a/cli/src/api/open-api/api.ts b/cli/src/api/open-api/api.ts index 8798d28c3b..e605dce060 100644 --- a/cli/src/api/open-api/api.ts +++ b/cli/src/api/open-api/api.ts @@ -1802,6 +1802,50 @@ export interface PeopleResponseDto { */ 'people': Array; } +/** + * + * @export + * @interface PeopleUpdateDto + */ +export interface PeopleUpdateDto { + /** + * + * @type {Array} + * @memberof PeopleUpdateDto + */ + 'people': Array; +} +/** + * + * @export + * @interface PeopleUpdateItem + */ +export interface PeopleUpdateItem { + /** + * Person id. + * @type {string} + * @memberof PeopleUpdateItem + */ + 'id': string; + /** + * Person name. + * @type {string} + * @memberof PeopleUpdateItem + */ + 'name'?: string; + /** + * Asset is used to get the feature face thumbnail. + * @type {string} + * @memberof PeopleUpdateItem + */ + 'featureFaceAssetId'?: string; + /** + * Person visibility + * @type {boolean} + * @memberof PeopleUpdateItem + */ + 'isHidden'?: boolean; +} /** * * @export @@ -8896,6 +8940,50 @@ export const PersonApiAxiosParamCreator = function (configuration?: Configuratio options: localVarRequestOptions, }; }, + /** + * + * @param {PeopleUpdateDto} peopleUpdateDto + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updatePeople: async (peopleUpdateDto: PeopleUpdateDto, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'peopleUpdateDto' is not null or undefined + assertParamExists('updatePeople', 'peopleUpdateDto', peopleUpdateDto) + const localVarPath = `/person`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication cookie required + + // authentication api_key required + await setApiKeyToObject(localVarHeaderParameter, "x-api-key", configuration) + + // authentication bearer required + // http bearer authentication required + await setBearerAuthToObject(localVarHeaderParameter, configuration) + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(peopleUpdateDto, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @param {string} id @@ -9005,6 +9093,16 @@ export const PersonApiFp = function(configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.mergePerson(id, mergePersonDto, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, + /** + * + * @param {PeopleUpdateDto} peopleUpdateDto + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async updatePeople(peopleUpdateDto: PeopleUpdateDto, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { + const localVarAxiosArgs = await localVarAxiosParamCreator.updatePeople(peopleUpdateDto, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, /** * * @param {string} id @@ -9071,6 +9169,15 @@ export const PersonApiFactory = function (configuration?: Configuration, basePat mergePerson(requestParameters: PersonApiMergePersonRequest, options?: AxiosRequestConfig): AxiosPromise> { return localVarFp.mergePerson(requestParameters.id, requestParameters.mergePersonDto, options).then((request) => request(axios, basePath)); }, + /** + * + * @param {PersonApiUpdatePeopleRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updatePeople(requestParameters: PersonApiUpdatePeopleRequest, options?: AxiosRequestConfig): AxiosPromise> { + return localVarFp.updatePeople(requestParameters.peopleUpdateDto, options).then((request) => request(axios, basePath)); + }, /** * * @param {PersonApiUpdatePersonRequest} requestParameters Request parameters. @@ -9160,6 +9267,20 @@ export interface PersonApiMergePersonRequest { readonly mergePersonDto: MergePersonDto } +/** + * Request parameters for updatePeople operation in PersonApi. + * @export + * @interface PersonApiUpdatePeopleRequest + */ +export interface PersonApiUpdatePeopleRequest { + /** + * + * @type {PeopleUpdateDto} + * @memberof PersonApiUpdatePeople + */ + readonly peopleUpdateDto: PeopleUpdateDto +} + /** * Request parameters for updatePerson operation in PersonApi. * @export @@ -9243,6 +9364,17 @@ export class PersonApi extends BaseAPI { return PersonApiFp(this.configuration).mergePerson(requestParameters.id, requestParameters.mergePersonDto, options).then((request) => request(this.axios, this.basePath)); } + /** + * + * @param {PersonApiUpdatePeopleRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PersonApi + */ + public updatePeople(requestParameters: PersonApiUpdatePeopleRequest, options?: AxiosRequestConfig) { + return PersonApiFp(this.configuration).updatePeople(requestParameters.peopleUpdateDto, options).then((request) => request(this.axios, this.basePath)); + } + /** * * @param {PersonApiUpdatePersonRequest} requestParameters Request parameters. diff --git a/mobile/openapi/.openapi-generator/FILES b/mobile/openapi/.openapi-generator/FILES index 5e8a7ee704..ad445090a2 100644 --- a/mobile/openapi/.openapi-generator/FILES +++ b/mobile/openapi/.openapi-generator/FILES @@ -72,6 +72,8 @@ doc/OAuthConfigDto.md doc/OAuthConfigResponseDto.md doc/PartnerApi.md doc/PeopleResponseDto.md +doc/PeopleUpdateDto.md +doc/PeopleUpdateItem.md doc/PersonApi.md doc/PersonResponseDto.md doc/PersonUpdateDto.md @@ -210,6 +212,8 @@ lib/model/o_auth_callback_dto.dart lib/model/o_auth_config_dto.dart lib/model/o_auth_config_response_dto.dart lib/model/people_response_dto.dart +lib/model/people_update_dto.dart +lib/model/people_update_item.dart lib/model/person_response_dto.dart lib/model/person_update_dto.dart lib/model/queue_status_dto.dart @@ -325,6 +329,8 @@ test/o_auth_config_dto_test.dart test/o_auth_config_response_dto_test.dart test/partner_api_test.dart test/people_response_dto_test.dart +test/people_update_dto_test.dart +test/people_update_item_test.dart test/person_api_test.dart test/person_response_dto_test.dart test/person_update_dto_test.dart diff --git a/mobile/openapi/README.md b/mobile/openapi/README.md index a075ebc76c..e7f172f98d 100644 Binary files a/mobile/openapi/README.md and b/mobile/openapi/README.md differ diff --git a/mobile/openapi/doc/PeopleUpdateDto.md b/mobile/openapi/doc/PeopleUpdateDto.md new file mode 100644 index 0000000000..8a3538b0b5 Binary files /dev/null and b/mobile/openapi/doc/PeopleUpdateDto.md differ diff --git a/mobile/openapi/doc/PeopleUpdateItem.md b/mobile/openapi/doc/PeopleUpdateItem.md new file mode 100644 index 0000000000..7f7edf311b Binary files /dev/null and b/mobile/openapi/doc/PeopleUpdateItem.md differ diff --git a/mobile/openapi/doc/PersonApi.md b/mobile/openapi/doc/PersonApi.md index 609043526e..0f6f2030cf 100644 Binary files a/mobile/openapi/doc/PersonApi.md and b/mobile/openapi/doc/PersonApi.md differ diff --git a/mobile/openapi/lib/api.dart b/mobile/openapi/lib/api.dart index 819f3092ad..36415d353a 100644 Binary files a/mobile/openapi/lib/api.dart and b/mobile/openapi/lib/api.dart differ diff --git a/mobile/openapi/lib/api/person_api.dart b/mobile/openapi/lib/api/person_api.dart index 7ced3bf7af..0d5b601826 100644 Binary files a/mobile/openapi/lib/api/person_api.dart and b/mobile/openapi/lib/api/person_api.dart differ diff --git a/mobile/openapi/lib/api_client.dart b/mobile/openapi/lib/api_client.dart index b36572fb4a..000629e1c8 100644 Binary files a/mobile/openapi/lib/api_client.dart and b/mobile/openapi/lib/api_client.dart differ diff --git a/mobile/openapi/lib/model/people_update_dto.dart b/mobile/openapi/lib/model/people_update_dto.dart new file mode 100644 index 0000000000..3c39c4bdb8 Binary files /dev/null and b/mobile/openapi/lib/model/people_update_dto.dart differ diff --git a/mobile/openapi/lib/model/people_update_item.dart b/mobile/openapi/lib/model/people_update_item.dart new file mode 100644 index 0000000000..16130b4036 Binary files /dev/null and b/mobile/openapi/lib/model/people_update_item.dart differ diff --git a/mobile/openapi/test/people_update_dto_test.dart b/mobile/openapi/test/people_update_dto_test.dart new file mode 100644 index 0000000000..841b6de6d8 Binary files /dev/null and b/mobile/openapi/test/people_update_dto_test.dart differ diff --git a/mobile/openapi/test/people_update_item_test.dart b/mobile/openapi/test/people_update_item_test.dart new file mode 100644 index 0000000000..3a9d3b5c86 Binary files /dev/null and b/mobile/openapi/test/people_update_item_test.dart differ diff --git a/mobile/openapi/test/person_api_test.dart b/mobile/openapi/test/person_api_test.dart index a49f40aa6b..abdde5367f 100644 Binary files a/mobile/openapi/test/person_api_test.dart and b/mobile/openapi/test/person_api_test.dart differ diff --git a/server/immich-openapi-specs.json b/server/immich-openapi-specs.json index a9375f3d7f..2b681a026b 100644 --- a/server/immich-openapi-specs.json +++ b/server/immich-openapi-specs.json @@ -2546,6 +2546,49 @@ "api_key": [] } ] + }, + "put": { + "operationId": "updatePeople", + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PeopleUpdateDto" + } + } + } + }, + "responses": { + "200": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/BulkIdResponseDto" + } + } + } + } + } + }, + "tags": [ + "Person" + ], + "security": [ + { + "bearer": [] + }, + { + "cookie": [] + }, + { + "api_key": [] + } + ] } }, "/person/{id}": { @@ -5028,13 +5071,13 @@ "type": "boolean" }, "error": { - "type": "string", "enum": [ "duplicate", "no_permission", "not_found", "unknown" - ] + ], + "type": "string" } }, "required": [ @@ -5906,6 +5949,44 @@ "people" ] }, + "PeopleUpdateDto": { + "type": "object", + "properties": { + "people": { + "type": "array", + "items": { + "$ref": "#/components/schemas/PeopleUpdateItem" + } + } + }, + "required": [ + "people" + ] + }, + "PeopleUpdateItem": { + "type": "object", + "properties": { + "id": { + "type": "string", + "description": "Person id." + }, + "name": { + "type": "string", + "description": "Person name." + }, + "featureFaceAssetId": { + "type": "string", + "description": "Asset is used to get the feature face thumbnail." + }, + "isHidden": { + "type": "boolean", + "description": "Person visibility" + } + }, + "required": [ + "id" + ] + }, "PersonResponseDto": { "type": "object", "properties": { diff --git a/server/src/domain/person/person.dto.ts b/server/src/domain/person/person.dto.ts index 41430afaf2..7b99da0dbd 100644 --- a/server/src/domain/person/person.dto.ts +++ b/server/src/domain/person/person.dto.ts @@ -1,6 +1,6 @@ import { AssetFaceEntity, PersonEntity } from '@app/infra/entities'; -import { Transform } from 'class-transformer'; -import { IsBoolean, IsOptional, IsString } from 'class-validator'; +import { Transform, Type } from 'class-transformer'; +import { IsArray, IsBoolean, IsNotEmpty, IsOptional, IsString, ValidateNested } from 'class-validator'; import { toBoolean, ValidateUUID } from '../domain.util'; export class PersonUpdateDto { @@ -26,6 +26,43 @@ export class PersonUpdateDto { isHidden?: boolean; } +export class PeopleUpdateDto { + @IsArray() + @ValidateNested({ each: true }) + @Type(() => PeopleUpdateItem) + people!: PeopleUpdateItem[]; +} + +export class PeopleUpdateItem { + /** + * Person id. + */ + @IsString() + @IsNotEmpty() + id!: string; + + /** + * Person name. + */ + @IsOptional() + @IsString() + name?: string; + + /** + * Asset is used to get the feature face thumbnail. + */ + @IsOptional() + @IsString() + featureFaceAssetId?: string; + + /** + * Person visibility + */ + @IsOptional() + @IsBoolean() + isHidden?: boolean; +} + export class MergePersonDto { @ValidateUUID({ each: true }) ids!: string[]; diff --git a/server/src/domain/person/person.service.spec.ts b/server/src/domain/person/person.service.spec.ts index 52a8d0f5dc..10d5763f91 100644 --- a/server/src/domain/person/person.service.spec.ts +++ b/server/src/domain/person/person.service.spec.ts @@ -188,6 +188,16 @@ describe(PersonService.name, () => { }); }); + describe('updateAll', () => { + it('should throw an error when personId is invalid', async () => { + personMock.getById.mockResolvedValue(null); + await expect( + sut.updatePeople(authStub.admin, { people: [{ id: 'person-1', name: 'Person 1' }] }), + ).resolves.toEqual([{ error: BulkIdErrorReason.UNKNOWN, id: 'person-1', success: false }]); + expect(personMock.update).not.toHaveBeenCalled(); + }); + }); + describe('handlePersonCleanup', () => { it('should delete people without faces', async () => { personMock.getAllWithoutFaces.mockResolvedValue([personStub.noName]); diff --git a/server/src/domain/person/person.service.ts b/server/src/domain/person/person.service.ts index 9f22cf96f5..0758b5f2c9 100644 --- a/server/src/domain/person/person.service.ts +++ b/server/src/domain/person/person.service.ts @@ -8,6 +8,7 @@ import { mapPerson, MergePersonDto, PeopleResponseDto, + PeopleUpdateDto, PersonResponseDto, PersonSearchDto, PersonUpdateDto, @@ -96,6 +97,24 @@ export class PersonService { return mapPerson(person); } + async updatePeople(authUser: AuthUserDto, dto: PeopleUpdateDto): Promise { + const results: BulkIdResponseDto[] = []; + for (const person of dto.people) { + try { + await this.update(authUser, person.id, { + isHidden: person.isHidden, + name: person.name, + featureFaceAssetId: person.featureFaceAssetId, + }), + results.push({ id: person.id, success: true }); + } catch (error: Error | any) { + this.logger.error(`Unable to update ${person.id} : ${error}`, error?.stack); + results.push({ id: person.id, success: false, error: BulkIdErrorReason.UNKNOWN }); + } + } + return results; + } + async handlePersonCleanup() { const people = await this.repository.getAllWithoutFaces(); for (const person of people) { diff --git a/server/src/immich/controllers/person.controller.ts b/server/src/immich/controllers/person.controller.ts index 7620145128..d0dcd84413 100644 --- a/server/src/immich/controllers/person.controller.ts +++ b/server/src/immich/controllers/person.controller.ts @@ -5,6 +5,7 @@ import { ImmichReadStream, MergePersonDto, PeopleResponseDto, + PeopleUpdateDto, PersonResponseDto, PersonSearchDto, PersonService, @@ -32,6 +33,11 @@ export class PersonController { return this.service.getAll(authUser, withHidden); } + @Put() + updatePeople(@AuthUser() authUser: AuthUserDto, @Body() dto: PeopleUpdateDto): Promise { + return this.service.updatePeople(authUser, dto); + } + @Get(':id') getPerson(@AuthUser() authUser: AuthUserDto, @Param() { id }: UUIDParamDto): Promise { return this.service.getById(authUser, id); diff --git a/web/src/api/open-api/api.ts b/web/src/api/open-api/api.ts index a2f076a402..f5b1b52ccf 100644 --- a/web/src/api/open-api/api.ts +++ b/web/src/api/open-api/api.ts @@ -1802,6 +1802,50 @@ export interface PeopleResponseDto { */ 'people': Array; } +/** + * + * @export + * @interface PeopleUpdateDto + */ +export interface PeopleUpdateDto { + /** + * + * @type {Array} + * @memberof PeopleUpdateDto + */ + 'people': Array; +} +/** + * + * @export + * @interface PeopleUpdateItem + */ +export interface PeopleUpdateItem { + /** + * Person id. + * @type {string} + * @memberof PeopleUpdateItem + */ + 'id': string; + /** + * Person name. + * @type {string} + * @memberof PeopleUpdateItem + */ + 'name'?: string; + /** + * Asset is used to get the feature face thumbnail. + * @type {string} + * @memberof PeopleUpdateItem + */ + 'featureFaceAssetId'?: string; + /** + * Person visibility + * @type {boolean} + * @memberof PeopleUpdateItem + */ + 'isHidden'?: boolean; +} /** * * @export @@ -8940,6 +8984,50 @@ export const PersonApiAxiosParamCreator = function (configuration?: Configuratio options: localVarRequestOptions, }; }, + /** + * + * @param {PeopleUpdateDto} peopleUpdateDto + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updatePeople: async (peopleUpdateDto: PeopleUpdateDto, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'peopleUpdateDto' is not null or undefined + assertParamExists('updatePeople', 'peopleUpdateDto', peopleUpdateDto) + const localVarPath = `/person`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication cookie required + + // authentication api_key required + await setApiKeyToObject(localVarHeaderParameter, "x-api-key", configuration) + + // authentication bearer required + // http bearer authentication required + await setBearerAuthToObject(localVarHeaderParameter, configuration) + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(peopleUpdateDto, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @param {string} id @@ -9049,6 +9137,16 @@ export const PersonApiFp = function(configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.mergePerson(id, mergePersonDto, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, + /** + * + * @param {PeopleUpdateDto} peopleUpdateDto + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async updatePeople(peopleUpdateDto: PeopleUpdateDto, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { + const localVarAxiosArgs = await localVarAxiosParamCreator.updatePeople(peopleUpdateDto, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, /** * * @param {string} id @@ -9116,6 +9214,15 @@ export const PersonApiFactory = function (configuration?: Configuration, basePat mergePerson(id: string, mergePersonDto: MergePersonDto, options?: any): AxiosPromise> { return localVarFp.mergePerson(id, mergePersonDto, options).then((request) => request(axios, basePath)); }, + /** + * + * @param {PeopleUpdateDto} peopleUpdateDto + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updatePeople(peopleUpdateDto: PeopleUpdateDto, options?: any): AxiosPromise> { + return localVarFp.updatePeople(peopleUpdateDto, options).then((request) => request(axios, basePath)); + }, /** * * @param {string} id @@ -9206,6 +9313,20 @@ export interface PersonApiMergePersonRequest { readonly mergePersonDto: MergePersonDto } +/** + * Request parameters for updatePeople operation in PersonApi. + * @export + * @interface PersonApiUpdatePeopleRequest + */ +export interface PersonApiUpdatePeopleRequest { + /** + * + * @type {PeopleUpdateDto} + * @memberof PersonApiUpdatePeople + */ + readonly peopleUpdateDto: PeopleUpdateDto +} + /** * Request parameters for updatePerson operation in PersonApi. * @export @@ -9289,6 +9410,17 @@ export class PersonApi extends BaseAPI { return PersonApiFp(this.configuration).mergePerson(requestParameters.id, requestParameters.mergePersonDto, options).then((request) => request(this.axios, this.basePath)); } + /** + * + * @param {PersonApiUpdatePeopleRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PersonApi + */ + public updatePeople(requestParameters: PersonApiUpdatePeopleRequest, options?: AxiosRequestConfig) { + return PersonApiFp(this.configuration).updatePeople(requestParameters.peopleUpdateDto, options).then((request) => request(this.axios, this.basePath)); + } + /** * * @param {PersonApiUpdatePersonRequest} requestParameters Request parameters. diff --git a/web/src/lib/components/assets/thumbnail/image-thumbnail.svelte b/web/src/lib/components/assets/thumbnail/image-thumbnail.svelte index ac6ba58bbc..3ac09de78a 100644 --- a/web/src/lib/components/assets/thumbnail/image-thumbnail.svelte +++ b/web/src/lib/components/assets/thumbnail/image-thumbnail.svelte @@ -15,12 +15,15 @@ export let circle = false; export let hidden = false; let complete = false; + + export let eyeColor = 'white'; {altText} (complete = true)} /> + {#if hidden}
- +
{/if} diff --git a/web/src/lib/components/faces-page/merge-face-selector.svelte b/web/src/lib/components/faces-page/merge-face-selector.svelte index c610911444..6313e3340e 100644 --- a/web/src/lib/components/faces-page/merge-face-selector.svelte +++ b/web/src/lib/components/faces-page/merge-face-selector.svelte @@ -25,7 +25,7 @@ $: unselectedPeople = people.filter((source) => !selectedPeople.includes(source) && source.id !== person.id); onMount(async () => { - const { data } = await api.personApi.getAllPeople({ withHidden: true }); + const { data } = await api.personApi.getAllPeople({ withHidden: false }); people = data.people; }); diff --git a/web/src/lib/components/faces-page/people-card.svelte b/web/src/lib/components/faces-page/people-card.svelte index c91e28c006..9edeb27761 100644 --- a/web/src/lib/components/faces-page/people-card.svelte +++ b/web/src/lib/components/faces-page/people-card.svelte @@ -20,17 +20,19 @@ const onMergeFacesClicked = () => { dispatch('merge-faces', person); }; + + const onHideFaceClicked = () => { + dispatch('hide-face', person); + };
-
+
{#if person.name} - + {person.name} {/if} @@ -50,6 +52,7 @@ {#if showContextMenu} (showContextMenu = false)}> + onHideFaceClicked()} text="Hide face" /> onChangeNameClicked()} text="Change name" /> onMergeFacesClicked()} text="Merge faces" /> diff --git a/web/src/lib/components/faces-page/show-hide.svelte b/web/src/lib/components/faces-page/show-hide.svelte index 8665a2c411..0a45f29300 100644 --- a/web/src/lib/components/faces-page/show-hide.svelte +++ b/web/src/lib/components/faces-page/show-hide.svelte @@ -1,12 +1,19 @@ -
-
-
- dispatch('closeClick')} /> -

Show & hide faces

-
- dispatch('doneClick')}>Done +
+ dispatch('closeClick')} /> +
-
- +
+
+ dispatch('reset-visibility')} /> + dispatch('toggle-visibility')} + /> +
+ {#if !showLoadingSpinner} + dispatch('doneClick')}>Done + {:else} + + {/if}
+ +
+ +
diff --git a/web/src/routes/(user)/people/+page.svelte b/web/src/routes/(user)/people/+page.svelte index 09f2bb6653..274205451c 100644 --- a/web/src/routes/(user)/people/+page.svelte +++ b/web/src/routes/(user)/people/+page.svelte @@ -5,7 +5,7 @@ import PeopleCard from '$lib/components/faces-page/people-card.svelte'; import FullScreenModal from '$lib/components/shared-components/full-screen-modal.svelte'; import Button from '$lib/components/elements/buttons/button.svelte'; - import { api, type PersonResponseDto } from '@api'; + import { api, PeopleUpdateItem, type PersonResponseDto } from '@api'; import { goto } from '$app/navigation'; import { AppRoute } from '$lib/constants'; import { handleError } from '$lib/utils/handle-error'; @@ -17,41 +17,86 @@ import IconButton from '$lib/components/elements/buttons/icon-button.svelte'; import EyeOutline from 'svelte-material-icons/EyeOutline.svelte'; import ImageThumbnail from '$lib/components/assets/thumbnail/image-thumbnail.svelte'; + import { onDestroy, onMount } from 'svelte'; + import { browser } from '$app/environment'; export let data: PageData; let selectHidden = false; - let changeCounter = 0; let initialHiddenValues: Record = {}; + let eyeColorMap: Record = {}; + let people = data.people.people; let countTotalPeople = data.people.total; let countVisiblePeople = data.people.visible; + let showLoadingSpinner = false; + let toggleVisibility = false; + people.forEach((person: PersonResponseDto) => { initialHiddenValues[person.id] = person.isHidden; }); + const onKeyboardPress = (event: KeyboardEvent) => handleKeyboardPress(event); + + onMount(() => { + document.addEventListener('keydown', onKeyboardPress); + }); + + onDestroy(() => { + if (browser) { + document.removeEventListener('keydown', onKeyboardPress); + } + }); + + const handleKeyboardPress = (event: KeyboardEvent) => { + switch (event.key) { + case 'Escape': + handleCloseClick(); + return; + } + }; + const handleCloseClick = () => { - selectHidden = false; - people.forEach((person: PersonResponseDto) => { + for (const person of people) { person.isHidden = initialHiddenValues[person.id]; - }); + } + // trigger reactivity + people = people; + + // Reset variables used on the "Show & hide faces" modal + showLoadingSpinner = false; + selectHidden = false; + toggleVisibility = false; + }; + + const handleResetVisibility = () => { + for (const person of people) { + person.isHidden = initialHiddenValues[person.id]; + } + + // trigger reactivity + people = people; + }; + + const handleToggleVisibility = () => { + toggleVisibility = !toggleVisibility; + for (const person of people) { + person.isHidden = toggleVisibility; + } + + // trigger reactivity + people = people; }; const handleDoneClick = async () => { - selectHidden = false; + showLoadingSpinner = true; + let changed: PeopleUpdateItem[] = []; try { - // Reset the counter before checking changes - let changeCounter = 0; - // Check if the visibility for each person has been changed for (const person of people) { if (person.isHidden !== initialHiddenValues[person.id]) { - changeCounter++; - await api.personApi.updatePerson({ - id: person.id, - personUpdateDto: { isHidden: person.isHidden }, - }); + changed.push({ id: person.id, isHidden: person.isHidden }); // Update the initial hidden values initialHiddenValues[person.id] = person.isHidden; @@ -61,18 +106,34 @@ } } - if (changeCounter > 0) { + if (changed.length > 0) { + const { data: results } = await api.personApi.updatePeople({ + peopleUpdateDto: { people: changed }, + }); + const count = results.filter(({ success }) => success).length; + if (results.length - count > 0) { + notificationController.show({ + type: NotificationType.Error, + message: `Unable to change the visibility for ${results.length - count} ${ + results.length - count <= 1 ? 'person' : 'people' + }`, + }); + } notificationController.show({ type: NotificationType.Info, - message: `Visibility changed for ${changeCounter} ${changeCounter <= 1 ? 'person' : 'people'}`, + message: `Visibility changed for ${count} ${count <= 1 ? 'person' : 'people'}`, }); } } catch (error) { handleError( error, - `Unable to change the visibility for ${changeCounter} ${changeCounter <= 1 ? 'person' : 'people'}`, + `Unable to change the visibility for ${changed.length} ${changed.length <= 1 ? 'person' : 'people'}`, ); } + // Reset variables used on the "Show & hide faces" modal + showLoadingSpinner = false; + selectHidden = false; + toggleVisibility = false; }; let showChangeNameModal = false; @@ -85,6 +146,37 @@ edittingPerson = detail; }; + const handleHideFace = async (event: CustomEvent) => { + try { + const { data: updatedPerson } = await api.personApi.updatePerson({ + id: event.detail.id, + personUpdateDto: { isHidden: true }, + }); + + people = people.map((person: PersonResponseDto) => { + if (person.id === updatedPerson.id) { + return updatedPerson; + } + return person; + }); + + people.forEach((person: PersonResponseDto) => { + initialHiddenValues[person.id] = person.isHidden; + }); + + countVisiblePeople--; + + showChangeNameModal = false; + + notificationController.show({ + message: 'Changed visibility succesfully', + type: NotificationType.Info, + }); + } catch (error) { + handleError(error, 'Unable to hide person'); + } + }; + const handleMergeFaces = (event: CustomEvent) => { goto(`${AppRoute.PEOPLE}/${event.detail.id}?action=merge`); }; @@ -132,13 +224,16 @@ {#if countVisiblePeople > 0}
- {#key selectHidden} - {#each people as person (person.id)} - {#if !person.isHidden} - - {/if} - {/each} - {/key} + {#each people as person (person.id)} + {#if !person.isHidden} + + {/if} + {/each}
{:else} @@ -184,32 +279,35 @@ {/if} {#if selectHidden} - -
-
- {#each people as person (person.id)} -
-
- -
- {#if person.name} - - {person.name} - - {/if} -
- {/each} -
-
+ + {#each people as person (person.id)} + + {/each} {/if}