Skip to content

Commit 806c0d3

Browse files
committed
feat: set picture item area via gRPC
1 parent 3c9709d commit 806c0d3

File tree

7 files changed

+352
-63
lines changed

7 files changed

+352
-63
lines changed

src/app/cutaway/brands/brands.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component, OnInit} from '@angular/core';
22
import {ActivatedRoute} from '@angular/router';
3-
import {ItemPictureType, ItemType} from '@grpc/spec.pb';
3+
import {ItemType, PictureItemType} from '@grpc/spec.pb';
44
import {APIItem, ItemService} from '@services/item';
55
import {PageEnvService} from '@services/page-env.service';
66
import {CatalogueListItem, CatalogueListItemPicture} from '@utils/list-item/list-item.component';
@@ -23,15 +23,15 @@ export class CutawayBrandsComponent implements OnInit {
2323
descendant_pictures: {
2424
perspective_id: 9,
2525
status: 'accepted',
26-
type_id: ItemPictureType.ITEM_PICTURE_CONTENT,
26+
type_id: PictureItemType.PICTURE_ITEM_CONTENT,
2727
},
2828
fields:
2929
'name_html,name_default,description,has_text,preview_pictures.route,preview_pictures.picture.name_text,current_pictures_count',
3030
limit: 12,
3131
page,
3232
preview_pictures: {
3333
perspective_id: 9,
34-
type_id: ItemPictureType.ITEM_PICTURE_CONTENT,
34+
type_id: PictureItemType.PICTURE_ITEM_CONTENT,
3535
},
3636
type_id: ItemType.ITEM_TYPE_BRAND,
3737
}),

src/app/index/index.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ export class IndexComponent implements OnInit {
5656
protected readonly contentPersons$ = this.items.getTopPersonsList(
5757
new GetTopPersonsListRequest({
5858
language: this.languageService.language,
59-
pictureItemType: PictureItemType.PICTURE_CONTENT,
59+
pictureItemType: PictureItemType.PICTURE_ITEM_CONTENT,
6060
}),
6161
);
6262
protected readonly authorPersons$ = this.items.getTopPersonsList(
6363
new GetTopPersonsListRequest({
6464
language: this.languageService.language,
65-
pictureItemType: PictureItemType.PICTURE_AUTHOR,
65+
pictureItemType: PictureItemType.PICTURE_ITEM_AUTHOR,
6666
}),
6767
);
6868

src/app/moder/pictures/item/area/area.component.ts

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import {Component, OnDestroy, OnInit} from '@angular/core';
22
import {ActivatedRoute, Router} from '@angular/router';
3+
import {SetPictureItemAreaRequest} from '@grpc/spec.pb';
4+
import {PicturesClient} from '@grpc/spec.pbsc';
35
import {PageEnvService} from '@services/page-env.service';
46
import {APIPicture, PictureService} from '@services/picture';
57
import {PictureItemService} from '@services/picture-item';
68
import * as $ from 'jquery';
7-
import {BehaviorSubject, Subscription} from 'rxjs';
8-
import {debounceTime, distinctUntilChanged, map, switchMap, tap} from 'rxjs/operators';
9+
import {BehaviorSubject, EMPTY, Subscription} from 'rxjs';
10+
import {catchError, debounceTime, distinctUntilChanged, map, switchMap, tap} from 'rxjs/operators';
911

1012
// @ts-expect-error Legacy
1113
import Jcrop from '../../../../jcrop/jquery.Jcrop.js';
14+
import {ToastsService} from '../../../../toasts/toasts.service';
1215

1316
interface Crop {
1417
h: number;
@@ -45,6 +48,8 @@ export class ModerPicturesItemAreaComponent implements OnInit, OnDestroy {
4548
private readonly route: ActivatedRoute,
4649
private readonly pictureService: PictureService,
4750
private readonly pageEnv: PageEnvService,
51+
private readonly picturesClient: PicturesClient,
52+
private readonly toastService: ToastsService,
4853
) {}
4954

5055
ngOnInit(): void {
@@ -175,17 +180,29 @@ export class ModerPicturesItemAreaComponent implements OnInit, OnDestroy {
175180
}
176181

177182
protected saveCrop() {
178-
const area = {
179-
height: Math.round(this.currentCrop.h),
180-
left: Math.round(this.currentCrop.x),
181-
top: Math.round(this.currentCrop.y),
182-
width: Math.round(this.currentCrop.w),
183-
};
184-
185-
this.picture &&
186-
this.pictureItemService.setArea$(this.id, this.itemID, this.type, area).subscribe(() => {
187-
this.picture && this.router.navigate(['/moder/pictures', this.picture.id]);
188-
});
183+
if (this.picture) {
184+
this.picturesClient
185+
.setPictureItemArea(
186+
new SetPictureItemAreaRequest({
187+
cropHeight: Math.round(this.currentCrop.h),
188+
cropLeft: Math.round(this.currentCrop.x),
189+
cropTop: Math.round(this.currentCrop.y),
190+
cropWidth: Math.round(this.currentCrop.w),
191+
itemId: '' + this.itemID,
192+
pictureId: '' + this.id,
193+
type: this.type,
194+
}),
195+
)
196+
.pipe(
197+
catchError((error: unknown) => {
198+
this.toastService.handleError(error);
199+
return EMPTY;
200+
}),
201+
)
202+
.subscribe(() => {
203+
this.picture && this.router.navigate(['/moder/pictures', this.picture.id]);
204+
});
205+
}
189206
}
190207

191208
protected onLoad(e: Event) {

src/app/moder/pictures/item/move/move.component.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ export class ModerPicturesItemMoveComponent implements OnInit {
7070
);
7171
}
7272

73-
private readonly isContentTypeOrEmpty$ = this.isSrcTypeOrEmpty$(PictureItemType.PICTURE_CONTENT);
73+
private readonly isContentTypeOrEmpty$ = this.isSrcTypeOrEmpty$(PictureItemType.PICTURE_ITEM_CONTENT);
7474
protected readonly showBrands$ = this.isContentTypeOrEmpty$;
7575
protected readonly showFactories$ = this.isContentTypeOrEmpty$;
7676
protected readonly showMuseums$ = this.isContentTypeOrEmpty$;
7777
protected readonly showPersons$ = this.isContentTypeOrEmpty$;
78-
protected readonly showAuthors$ = this.isSrcTypeOrEmpty$(PictureItemType.PICTURE_AUTHOR);
79-
protected readonly showCopyrights$ = this.isSrcTypeOrEmpty$(PictureItemType.PICTURE_COPYRIGHTS);
78+
protected readonly showAuthors$ = this.isSrcTypeOrEmpty$(PictureItemType.PICTURE_ITEM_AUTHOR);
79+
protected readonly showCopyrights$ = this.isSrcTypeOrEmpty$(PictureItemType.PICTURE_ITEM_COPYRIGHTS);
8080

8181
protected readonly showTabBar$ = combineLatest([
8282
this.showBrands$,
@@ -106,9 +106,9 @@ export class ModerPicturesItemMoveComponent implements OnInit {
106106
);
107107
}
108108

109-
protected readonly factoriesActive$ = this.tabActive$('show_factories', PictureItemType.PICTURE_CONTENT);
110-
protected readonly museumsActive$ = this.tabActive$('show_museums', PictureItemType.PICTURE_CONTENT);
111-
protected readonly personsActive$ = this.tabActive$('show_persons', PictureItemType.PICTURE_CONTENT);
109+
protected readonly factoriesActive$ = this.tabActive$('show_factories', PictureItemType.PICTURE_ITEM_CONTENT);
110+
protected readonly museumsActive$ = this.tabActive$('show_museums', PictureItemType.PICTURE_ITEM_CONTENT);
111+
protected readonly personsActive$ = this.tabActive$('show_persons', PictureItemType.PICTURE_ITEM_CONTENT);
112112

113113
protected readonly authorsActive$ = combineLatest([
114114
this.showAuthors$,
@@ -120,15 +120,15 @@ export class ModerPicturesItemMoveComponent implements OnInit {
120120
]).pipe(
121121
map(
122122
([showAuthors, {srcItemID, srcType}, active]) =>
123-
showAuthors && !srcItemID && (active || srcType === PictureItemType.PICTURE_AUTHOR),
123+
showAuthors && !srcItemID && (active || srcType === PictureItemType.PICTURE_ITEM_AUTHOR),
124124
),
125125
shareReplay(1),
126126
);
127127

128-
protected readonly copyrightsActive$ = this.tabActive$('show_copyrights', PictureItemType.PICTURE_COPYRIGHTS);
128+
protected readonly copyrightsActive$ = this.tabActive$('show_copyrights', PictureItemType.PICTURE_ITEM_COPYRIGHTS);
129129

130130
protected readonly brandsActive$ = combineLatest([
131-
this.isSrcTypeOrEmpty$(PictureItemType.PICTURE_CONTENT),
131+
this.isSrcTypeOrEmpty$(PictureItemType.PICTURE_ITEM_CONTENT),
132132
this.factoriesActive$,
133133
this.museumsActive$,
134134
this.personsActive$,
@@ -190,7 +190,7 @@ export class ModerPicturesItemMoveComponent implements OnInit {
190190
page,
191191
typeId: ItemType.ITEM_TYPE_MUSEUM,
192192
}),
193-
PictureItemType.PICTURE_CONTENT,
193+
PictureItemType.PICTURE_ITEM_CONTENT,
194194
),
195195
),
196196
);
@@ -205,7 +205,7 @@ export class ModerPicturesItemMoveComponent implements OnInit {
205205
page,
206206
typeId: ItemType.ITEM_TYPE_FACTORY,
207207
}),
208-
PictureItemType.PICTURE_CONTENT,
208+
PictureItemType.PICTURE_ITEM_CONTENT,
209209
),
210210
),
211211
);
@@ -235,10 +235,10 @@ export class ModerPicturesItemMoveComponent implements OnInit {
235235
}
236236

237237
protected readonly persons$: Observable<{items: HtmlAndSelectItemParams[]; paginator?: Pages}> =
238-
this.authorsAndPersons$(this.searchPersonControl, PictureItemType.PICTURE_CONTENT);
238+
this.authorsAndPersons$(this.searchPersonControl, PictureItemType.PICTURE_ITEM_CONTENT);
239239

240240
protected readonly authors$: Observable<{items: HtmlAndSelectItemParams[]; paginator?: Pages}> =
241-
this.authorsAndPersons$(this.searchAuthorControl, PictureItemType.PICTURE_AUTHOR);
241+
this.authorsAndPersons$(this.searchAuthorControl, PictureItemType.PICTURE_ITEM_AUTHOR);
242242

243243
protected readonly copyrights$: Observable<{items: HtmlAndSelectItemParams[]; paginator?: Pages}> = this.page$.pipe(
244244
switchMap((page) =>
@@ -250,7 +250,7 @@ export class ModerPicturesItemMoveComponent implements OnInit {
250250
page,
251251
typeId: ItemType.ITEM_TYPE_COPYRIGHT,
252252
}),
253-
PictureItemType.PICTURE_COPYRIGHTS,
253+
PictureItemType.PICTURE_ITEM_COPYRIGHTS,
254254
),
255255
),
256256
);
@@ -293,7 +293,7 @@ export class ModerPicturesItemMoveComponent implements OnInit {
293293
page: 1,
294294
typeId: ItemType.ITEM_TYPE_VEHICLE,
295295
}),
296-
PictureItemType.PICTURE_COPYRIGHTS,
296+
PictureItemType.PICTURE_ITEM_COPYRIGHTS,
297297
),
298298
),
299299
);

src/app/services/picture-item.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ import {APIService} from './api.service';
55
import {APIItem} from './item';
66
import {APIPicture} from './picture';
77

8-
export interface APIPictureItemAreaPostData {
9-
height: number;
10-
left: number;
11-
top: number;
12-
width: number;
13-
}
14-
158
export interface APIPictureItemPostData {
169
perspective_id?: null | number;
1710
}
@@ -64,14 +57,6 @@ export class PictureItemService {
6457
});
6558
}
6659

67-
public setArea$(pictureId: number, itemId: number, type: number, area: APIPictureItemAreaPostData): Observable<void> {
68-
return this.api.request<void>('PUT', 'picture-item/' + pictureId + '/' + itemId + '/' + type, {
69-
body: {
70-
area,
71-
},
72-
});
73-
}
74-
7560
public create$(pictureId: number, itemId: string, type: number, data: APIPictureItemPostData): Observable<void> {
7661
return this.api.request<void>('POST', 'picture-item/' + pictureId + '/' + itemId + '/' + type, {body: data});
7762
}

0 commit comments

Comments
 (0)