From ed64c91da69f4e4140acbde901f3f84b768db4af Mon Sep 17 00:00:00 2001 From: martin <74269598+martabal@users.noreply.github.com> Date: Sun, 23 Jul 2023 05:00:43 +0200 Subject: [PATCH] fix: hide faces (#3352) * fix: hide faces * remove unused variable * fix: work even if one fails * better style for hidden people * add hide face in the menu dropdown * add buttons to toggle visibility for all faces * add server test * close modal with escape key * fix: explore page * improve show & hide faces modal * keep name on people card * simplify layout * sticky app bar in show-hide page * fix format --------- Co-authored-by: Alex Tran --- cli/src/api/open-api/api.ts | 132 ++++++++++++ mobile/openapi/.openapi-generator/FILES | 6 + mobile/openapi/README.md | Bin 18182 -> 18362 bytes mobile/openapi/doc/PeopleUpdateDto.md | Bin 0 -> 471 bytes mobile/openapi/doc/PeopleUpdateItem.md | Bin 0 -> 628 bytes mobile/openapi/doc/PersonApi.md | Bin 12619 -> 14702 bytes mobile/openapi/lib/api.dart | Bin 5903 -> 5978 bytes mobile/openapi/lib/api/person_api.dart | Bin 10410 -> 12129 bytes mobile/openapi/lib/api_client.dart | Bin 18521 -> 18687 bytes .../openapi/lib/model/people_update_dto.dart | Bin 0 -> 2796 bytes .../openapi/lib/model/people_update_item.dart | Bin 0 -> 4983 bytes .../openapi/test/people_update_dto_test.dart | Bin 0 -> 607 bytes .../openapi/test/people_update_item_test.dart | Bin 0 -> 992 bytes mobile/openapi/test/person_api_test.dart | Bin 1302 -> 1456 bytes server/immich-openapi-specs.json | 85 +++++++- server/src/domain/person/person.dto.ts | 41 +++- .../src/domain/person/person.service.spec.ts | 10 + server/src/domain/person/person.service.ts | 19 ++ .../immich/controllers/person.controller.ts | 6 + web/src/api/open-api/api.ts | 132 ++++++++++++ .../assets/thumbnail/image-thumbnail.svelte | 8 +- .../faces-page/merge-face-selector.svelte | 2 +- .../components/faces-page/people-card.svelte | 11 +- .../components/faces-page/show-hide.svelte | 40 +++- web/src/routes/(user)/people/+page.svelte | 200 +++++++++++++----- 25 files changed, 620 insertions(+), 72 deletions(-) create mode 100644 mobile/openapi/doc/PeopleUpdateDto.md create mode 100644 mobile/openapi/doc/PeopleUpdateItem.md create mode 100644 mobile/openapi/lib/model/people_update_dto.dart create mode 100644 mobile/openapi/lib/model/people_update_item.dart create mode 100644 mobile/openapi/test/people_update_dto_test.dart create mode 100644 mobile/openapi/test/people_update_item_test.dart 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 a075ebc76c7a7914cd86362736e28fafa36316ba..e7f172f98d3d7d23beb83b4b6f678375455d7e4b 100644 GIT binary patch delta 129 zcmZqcW8BrxxS>{oCBGmib#kME91n=0sZgV!r4@~ delta 19 acmdnh&)C+-xS>{I^JN8Qnaw7)ZCn6PE(az6 diff --git a/mobile/openapi/doc/PeopleUpdateDto.md b/mobile/openapi/doc/PeopleUpdateDto.md new file mode 100644 index 0000000000000000000000000000000000000000..8a3538b0b5d8251d6cfcb7aa831671a20d00edf8 GIT binary patch literal 471 zcma)2L2AP=5WMRZ3qB+k$ho(rkl-8wNid~78H0tjX+eMeOX% zEHedAK(B+X92p#|1}TjA5{zc7nS>|`*poKEZwNC5f*#)WD~i7FjgBm=3ltd^7yRyG zxXPxPu(;3E*{O+X8QJ0_j@lu7!t+PSUyaicZD312O-JIyP**R3SCdkI%|gmBCy_Ey zTPgQ;;)m;SJ4W{?Ww*QqD`(22$uff{eI6N@U?4v+v|T4e+ip?=89e05U`*Csx2&qw x({^1Sw#lF{G@KoJ);WWLz*BA&LU-oK(Qi2t5Y8Y+vL7#df<@GO!@yU0@gu{mVgd zl2tQcbd{mKQWMfJFkuucX%ODv@#yn6!`KG$OwOii=b-5i%V>rN^`P3Q-V^93-a@dQ(a2(?GzxU1b|J^fEX4EHW(rWX&j|oX3R*Y- delta 17 ZcmaD?bUJB63e)E0O#9U~yBTV5002&c2R{G+ diff --git a/mobile/openapi/lib/api.dart b/mobile/openapi/lib/api.dart index 819f3092ad4c8372dcb56556410c0b1959c8824d..36415d353ae9746d6bccf935c625e7fcd1dd4b61 100644 GIT binary patch delta 38 rcmeCzyQQ~b5+6%`K~CyqMpk*Af>aPQzO*1Ev1IZ+eyPn9`0665r;#e6<_^C1V9S diff --git a/mobile/openapi/lib/api/person_api.dart b/mobile/openapi/lib/api/person_api.dart index 7ced3bf7af7a18e18b6805457be1d0914ed7ab84..0d5b60182669e82998f555ed36414fc3522c07f8 100644 GIT binary patch delta 213 zcmZ1#_%Lq6L&eF*89l`VQu7OPQbP+;5=&BDO7deB3cv!BbCe9#K{DZ)B^e$iB?X>& zY55vxieYNcD}_(qz+}y-U<(!5+^f8n5s%UGlf&esluN;uLd?W%w8Z2Os`9cJPJuWR M;_l5K<#uuc0FN3{c>n+a delta 12 UcmaDDw<>VML&eQAG)}Ss04#e3F8}}l diff --git a/mobile/openapi/lib/api_client.dart b/mobile/openapi/lib/api_client.dart index b36572fb4acdf2722d233afab1fdfb58be29ddb4..000629e1c8072340c1ceb7ce1908b19d111b3246 100644 GIT binary patch delta 80 zcmcaPf${%D#to0aSVG(~wkNi^UnzkGN>lhruueMxrftGO3YN4I}k`-@T-$ z$co!!GhoZ2?&mq@lA26LlL@@}ax;JN=j?j+>CMgT0xqxK&tkZk!}a_IKFlw!F8_Ll zW@P!gVA`fHlV4ws=vJ(y(mY!!ovlR0&!CZw;YG$PzTwiw;a+TNrR`AkOFLl8zzpx7KMgSA+{}Z>3mIfF|zJqCs)$m@;mP;!{vU{k-JYDdQoTV}Z2F@b zgtV~c7D{HyKUBdntMl*lLNbv&=f*I-Bbt%9k{e;1S>#(wg1d*I-{fbjgv8v$)R$6V^Pz$$&Qd^i`GnI+G-4DDfdHk>{Oeq(yN+aD>JAk7wZQphlXKq{7*`M5tVy zL}-t$Q<^dQU>>^c-EW(UuI1jYh`Df+U`O~gcrv?Y9p&HZa~iT{&^t4 zlan4`h7Bd8EC&~s-6BKi-1GS?b;{~TB!;MogcXHnz31t14fr0Q+T}1(?GYJ1& z6gM+11^wwAq6HgPcU?-?HIRZH4A7M9 z>B&)DJas@ZMqe?n=UbJ@L0osV!E`4`*MiUa@v literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..16130b4036cf45b4cbb37a6a9adbd6848b4af214 GIT binary patch literal 4983 zcmeHLZExE)5dQ98aVd(%!BnT~ry-r47HzVnYvQ6!2Mk7F&=MW9l|_%FVi;-u`<^33 zTej>Z7|?Gm&?F-7j>qSodyx(gTZf1A=F4UO`5z}2C!gM2p1h;evkxZ;z3bCO|B}x8 z@6JyD*@GBMzRrYk-ItwTU$*#BT^HKO;aHpDSmpAF%A&L~8_HZxW#N+etfn(<+*S>d z&&9$HXQdk&`ERKV)C)1i&zUgz?WD0VZtQmTR2SBX!VOi11Jzhb}qRewK%H93(W+b9p08;zh1yAq_&4RpzZO4O~byEKf`8 zXe{!aMk4)2PP5-^8zHM)CbyWy+tXVR3S2TIvMh*gaR7erxS&4(`q&0!jNS^?fc`Nt z*vkO;KoVp*aaj9WI&ZrQHhlMJmeWxoRKBvt^!xZTNIxn_&0JfCtV*dHWz|UK$}N5- z4!HOO6KAA#evBLm1fE6jpBDega!R#`9BMmLD62lPu=TV4fKk&fvF9r;`B zH6^#)fgxDwH3ha5<=^SMSv#^!PT?}9dpOKb_Z&a&>@xfK_jTyiuxmmIs=!8BKI?7&XcQT#1 zMYIW0pb@t#(|XS1GOMokBW(hux(zyZI3xUR;CKZN1GJ)Hqbl)sxJCz~dmw8~Ge8?5 zUIV()a+37ah0709uc?KrANibH(ckjwZlKgED*76X|;nECs`NOFg@IF{2u(EHE* i3w{%?sv2>)m=dc*yf#W?r>WN&W)>jYi-A literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..841b6de6d85048f3befc2eeea25cc9a3c36e219a GIT binary patch literal 607 zcmZuuOKTf35WerPn4WBdlTCdJNfQ!Srx=`U3C^LEq71vUwun|zrCAqK^4~L(Vay8HxTid?2}03_4YN05`i4|3knlW&o!VpnXPZlOnQ#}oKh00_9#77ggULql-& zku#oL7J^&{H~8@=NqToa&TQq}wSH2$n`aKa3 t$dikS%LVX;zz4ZP;2k{g1)leA7rHbi34s`FH-;n|TIbNyM&6xW57kPlG@D{d{(DEV4J9@> zIY?rL?=cVMd6wred0G~qzs(+I-zUr26y}S&*$AcuJQPc~FQ$w6&rbr2$eUVuzP=cL zxyWKjt+5`<#`>}$jhE1yK44v<#tsdS_AzzNdOpff`j6U#()C<={N0lmx>23nPI-A5 zeGqXUj?*h^0xQEM)nZ5up-=R1)J&7XP-<&hf$>_I^6Pn7t(6a1wyhBcPF25DiHxwRIFHvJ5KUtoKt=+OXr0CHs-aV4hG+0M0}ymWMrokb zM1^pDKpLK1Wdd!z?cHz?#Sb8Z5$pt$eYY}-^xL9#sJVcW(&F?)4k;fhc(;rf3bZ0kyxH$$Wv%Qz+)^zc_vE1V N!1sBJT-wrW_77n!HS+)f literal 0 HcmV?d00001 diff --git a/mobile/openapi/test/person_api_test.dart b/mobile/openapi/test/person_api_test.dart index a49f40aa6b71aaf82a989de3b9ef2ae7588a8f5d..abdde5367f5a30fa0495604f2cdd022071b3e05c 100644 GIT binary patch delta 59 zcmbQnwSjv>4a?-)%#zBb1u2OosR60^1v#l25GoWb!};odeVW 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}