From 55d2817cd8cdb3090f47a25523d3f062a2d2062d Mon Sep 17 00:00:00 2001 From: Rinat Arsaev <11846445+A77AY@users.noreply.github.com> Date: Mon, 26 Aug 2024 18:13:08 +0500 Subject: [PATCH] IMP-301: New shop selector (#381) --- src/app/app.component.ts | 4 +- src/app/sections/sections-routing.module.ts | 2 +- src/app/sections/tariffs/index.ts | 1 - src/app/sections/tariffs/tariffs.module.ts | 10 - .../shops-term-set-history-card/index.ts | 0 ...shops-term-set-history-card.component.html | 0 .../shops-term-set-history-card.component.ts | 2 +- .../shops-terms/shops-terms.component.html} | 2 +- .../shops-terms/shops-terms.component.ts} | 22 +-- .../shops-terms/shops-terms.service.ts} | 2 +- .../shops-terms}/utils/shop-fees-columns.ts | 0 .../terminals-term-set-history-card/index.ts | 0 ...inals-term-set-history-card.component.html | 0 ...rminals-term-set-history-card.component.ts | 0 .../terminals-terms.component.html | 2 +- .../terminals-terms.component.ts | 4 +- .../terminals-terms.service.ts | 0 .../utils/create-terminal-fees-column.ts | 0 .../wallets-term-set-history-card/index.ts | 0 ...llets-term-set-history-card.component.html | 0 ...wallets-term-set-history-card.component.ts | 2 +- .../utils/wallet-fees-columns.ts | 0 .../wallets-terms.component.html} | 2 +- .../wallets-terms/wallets-terms.component.ts} | 22 +-- .../wallets-terms/wallets-terms.service.ts} | 2 +- src/app/sections/terms/index.ts | 1 + .../{tariffs => terms}/routing-config.ts | 0 .../terms-routing.module.ts} | 14 +- .../terms.component.html} | 0 .../terms.component.ts} | 6 +- src/app/sections/terms/terms.ts | 10 + .../utils/get-inline-decisions.ts | 0 ...s-one-hundred-percent-cash-flow-posting.ts | 0 .../utils/is-that-currency.ts | 0 .../shop-field/shop-field.component.html | 21 +- .../shop-field/shop-field.component.scss | 8 - .../shop-field/shop-field.component.ts | 186 ++++++++++++------ .../shop-field/shop-field.module.ts | 10 +- 38 files changed, 204 insertions(+), 131 deletions(-) delete mode 100644 src/app/sections/tariffs/index.ts delete mode 100644 src/app/sections/tariffs/tariffs.module.ts rename src/app/sections/{tariffs => terms}/components/shops-term-set-history-card/index.ts (100%) rename src/app/sections/{tariffs => terms}/components/shops-term-set-history-card/shops-term-set-history-card.component.html (100%) rename src/app/sections/{tariffs => terms}/components/shops-term-set-history-card/shops-term-set-history-card.component.ts (97%) rename src/app/sections/{tariffs/components/shops-tariffs/shops-tariffs.component.html => terms/components/shops-terms/shops-terms.component.html} (96%) rename src/app/sections/{tariffs/components/shops-tariffs/shops-tariffs.component.ts => terms/components/shops-terms/shops-terms.component.ts} (90%) rename src/app/sections/{tariffs/components/shops-tariffs/shops-tariffs.service.ts => terms/components/shops-terms/shops-terms.service.ts} (93%) rename src/app/sections/{tariffs/components/shops-tariffs => terms/components/shops-terms}/utils/shop-fees-columns.ts (100%) rename src/app/sections/{tariffs => terms}/components/terminals-term-set-history-card/index.ts (100%) rename src/app/sections/{tariffs => terms}/components/terminals-term-set-history-card/terminals-term-set-history-card.component.html (100%) rename src/app/sections/{tariffs => terms}/components/terminals-term-set-history-card/terminals-term-set-history-card.component.ts (100%) rename src/app/sections/{tariffs => terms}/components/terminals-terms/terminals-terms.component.html (98%) rename src/app/sections/{tariffs => terms}/components/terminals-terms/terminals-terms.component.ts (98%) rename src/app/sections/{tariffs => terms}/components/terminals-terms/terminals-terms.service.ts (100%) rename src/app/sections/{tariffs => terms}/components/terminals-terms/utils/create-terminal-fees-column.ts (100%) rename src/app/sections/{tariffs => terms}/components/wallets-term-set-history-card/index.ts (100%) rename src/app/sections/{tariffs => terms}/components/wallets-term-set-history-card/wallets-term-set-history-card.component.html (100%) rename src/app/sections/{tariffs => terms}/components/wallets-term-set-history-card/wallets-term-set-history-card.component.ts (97%) rename src/app/sections/{tariffs/components/wallets-tariffs => terms/components/wallets-terms}/utils/wallet-fees-columns.ts (100%) rename src/app/sections/{tariffs/components/wallets-tariffs/wallets-tariffs.component.html => terms/components/wallets-terms/wallets-terms.component.html} (96%) rename src/app/sections/{tariffs/components/wallets-tariffs/wallets-tariffs.component.ts => terms/components/wallets-terms/wallets-terms.component.ts} (90%) rename src/app/sections/{tariffs/components/wallets-tariffs/wallets-tariffs.service.ts => terms/components/wallets-terms/wallets-terms.service.ts} (93%) create mode 100644 src/app/sections/terms/index.ts rename src/app/sections/{tariffs => terms}/routing-config.ts (100%) rename src/app/sections/{tariffs/tariffs-routing.module.ts => terms/terms-routing.module.ts} (70%) rename src/app/sections/{tariffs/tariffs.component.html => terms/terms.component.html} (100%) rename src/app/sections/{tariffs/tariffs.component.ts => terms/terms.component.ts} (88%) create mode 100644 src/app/sections/terms/terms.ts rename src/app/sections/{tariffs => terms}/utils/get-inline-decisions.ts (100%) rename src/app/sections/{tariffs => terms}/utils/is-one-hundred-percent-cash-flow-posting.ts (100%) rename src/app/sections/{tariffs => terms}/utils/is-that-currency.ts (100%) delete mode 100644 src/app/shared/components/shop-field/shop-field.component.scss diff --git a/src/app/app.component.ts b/src/app/app.component.ts index c9e62d5c..96cad6c9 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -18,8 +18,8 @@ import { ROUTING_CONFIG as REPAIRING_ROUTING_CONFIG } from './sections/repairing import { ROUTING_CONFIG as PARTIES_ROUTING_CONFIG } from './sections/search-parties/routing-config'; import { SHOPS_ROUTING_CONFIG } from './sections/shops'; import { ROUTING_CONFIG as SOURCES_ROUTING_CONFIG } from './sections/sources/routing-config'; -import { ROUTING_CONFIG as TARIFFS_ROUTING_CONFIG } from './sections/tariffs/routing-config'; import { ROUTING_CONFIG as TERMINALS_ROUTING_CONFIG } from './sections/terminals'; +import { ROUTING_CONFIG as TERMS_ROUTING_CONFIG } from './sections/terms/routing-config'; import { ROUTING_CONFIG as WALLETS_ROUTING_CONFIG } from './sections/wallets/routing-config'; import { ROUTING_CONFIG as WITHDRAWALS_ROUTING_CONFIG } from './sections/withdrawals/routing-config'; import { SidenavInfoService } from './shared/components/sidenav-info'; @@ -84,7 +84,7 @@ export class AppComponent { { label: 'Terms', url: '/terms', - services: TARIFFS_ROUTING_CONFIG.services, + services: TERMS_ROUTING_CONFIG.services, }, ], [ diff --git a/src/app/sections/sections-routing.module.ts b/src/app/sections/sections-routing.module.ts index dc20ebdd..e099f3a9 100644 --- a/src/app/sections/sections-routing.module.ts +++ b/src/app/sections/sections-routing.module.ts @@ -70,7 +70,7 @@ const ROUTES: Routes = [ }, { path: 'terms', - loadChildren: () => import('./tariffs').then((m) => m.TariffsModule), + loadChildren: () => import('./terms').then((m) => m.Terms), }, { path: '404', diff --git a/src/app/sections/tariffs/index.ts b/src/app/sections/tariffs/index.ts deleted file mode 100644 index 4d934e2c..00000000 --- a/src/app/sections/tariffs/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './tariffs.module'; diff --git a/src/app/sections/tariffs/tariffs.module.ts b/src/app/sections/tariffs/tariffs.module.ts deleted file mode 100644 index 4fe09a6f..00000000 --- a/src/app/sections/tariffs/tariffs.module.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { CommonModule } from '@angular/common'; -import { NgModule } from '@angular/core'; - -import { ShopsTariffsComponent } from './components/shops-tariffs/shops-tariffs.component'; -import { TariffsRoutingModule } from './tariffs-routing.module'; - -@NgModule({ - imports: [CommonModule, TariffsRoutingModule, ShopsTariffsComponent], -}) -export class TariffsModule {} diff --git a/src/app/sections/tariffs/components/shops-term-set-history-card/index.ts b/src/app/sections/terms/components/shops-term-set-history-card/index.ts similarity index 100% rename from src/app/sections/tariffs/components/shops-term-set-history-card/index.ts rename to src/app/sections/terms/components/shops-term-set-history-card/index.ts diff --git a/src/app/sections/tariffs/components/shops-term-set-history-card/shops-term-set-history-card.component.html b/src/app/sections/terms/components/shops-term-set-history-card/shops-term-set-history-card.component.html similarity index 100% rename from src/app/sections/tariffs/components/shops-term-set-history-card/shops-term-set-history-card.component.html rename to src/app/sections/terms/components/shops-term-set-history-card/shops-term-set-history-card.component.html diff --git a/src/app/sections/tariffs/components/shops-term-set-history-card/shops-term-set-history-card.component.ts b/src/app/sections/terms/components/shops-term-set-history-card/shops-term-set-history-card.component.ts similarity index 97% rename from src/app/sections/tariffs/components/shops-term-set-history-card/shops-term-set-history-card.component.ts rename to src/app/sections/terms/components/shops-term-set-history-card/shops-term-set-history-card.component.ts index 0e2038b9..8a5793b1 100644 --- a/src/app/sections/tariffs/components/shops-term-set-history-card/shops-term-set-history-card.component.ts +++ b/src/app/sections/terms/components/shops-term-set-history-card/shops-term-set-history-card.component.ts @@ -12,7 +12,7 @@ import { getShopCashFlowSelectors, isShopTermSetDecision, SHOP_FEES_COLUMNS, -} from '../shops-tariffs/utils/shop-fees-columns'; +} from '../shops-terms/utils/shop-fees-columns'; @Component({ selector: 'cc-shops-term-set-history-card', diff --git a/src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.html b/src/app/sections/terms/components/shops-terms/shops-terms.component.html similarity index 96% rename from src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.html rename to src/app/sections/terms/components/shops-terms/shops-terms.component.html index c5fbbdcc..23d603a9 100644 --- a/src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.html +++ b/src/app/sections/terms/components/shops-terms/shops-terms.component.html @@ -21,7 +21,7 @@ [hasMore]="hasMore$ | async" [maxSize]="250" [progress]="isLoading$ | async" - [treeData]="tariffs$ | async" + [treeData]="terms$ | async" (more)="more()" (update)="update($event)" > diff --git a/src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.ts b/src/app/sections/terms/components/shops-terms/shops-terms.component.ts similarity index 90% rename from src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.ts rename to src/app/sections/terms/components/shops-terms/shops-terms.component.ts index 214dbd83..cd486b96 100644 --- a/src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.component.ts +++ b/src/app/sections/terms/components/shops-terms/shops-terms.component.ts @@ -43,7 +43,7 @@ import { import { getInlineDecisions2, InlineDecision2 } from '../../utils/get-inline-decisions'; import { ShopsTermSetHistoryCardComponent } from '../shops-term-set-history-card'; -import { ShopsTariffsService } from './shops-tariffs.service'; +import { ShopsTermsService } from './shops-terms.service'; import { isShopTermSetDecision, SHOP_FEES_COLUMNS, @@ -57,7 +57,7 @@ type Params = Pick & >; @Component({ - selector: 'cc-shops-tariffs', + selector: 'cc-shops-terms', standalone: true, imports: [ CommonModule, @@ -73,9 +73,9 @@ type Params = Pick & VSelectPipe, MatTooltip, ], - templateUrl: './shops-tariffs.component.html', + templateUrl: './shops-terms.component.html', }) -export class ShopsTariffsComponent implements OnInit { +export class ShopsTermsComponent implements OnInit { filtersForm = this.fb.group( createControls({ currencies: null, @@ -85,7 +85,7 @@ export class ShopsTariffsComponent implements OnInit { term_sets_ids: null, }), ); - tariffs$ = this.shopsTariffsService.result$.pipe( + terms$ = this.shopsTermsService.result$.pipe( map((terms) => terms.map((t) => ({ value: t, @@ -100,8 +100,8 @@ export class ShopsTariffsComponent implements OnInit { })), ), ); - hasMore$ = this.shopsTariffsService.hasMore$; - isLoading$ = this.shopsTariffsService.isLoading$; + hasMore$ = this.shopsTermsService.hasMore$; + isLoading$ = this.shopsTermsService.isLoading$; columns: Column2[] = [ createShopColumn( (d) => ({ @@ -138,7 +138,7 @@ export class ShopsTariffsComponent implements OnInit { private initFiltersValue = this.filtersForm.value; constructor( - private shopsTariffsService: ShopsTariffsService, + private shopsTermsService: ShopsTermsService, private fb: NonNullableFormBuilder, private qp: QueryParamsService, @Inject(DEBOUNCE_TIME_MS) private debounceTimeMs: number, @@ -158,7 +158,7 @@ export class ShopsTariffsComponent implements OnInit { load(params: Params, options?: LoadOptions) { const { currencies, term_sets_ids, ...otherParams } = params; - this.shopsTariffsService.load( + this.shopsTermsService.load( clean({ common_search_query_params: { currencies }, term_sets_ids: term_sets_ids?.map?.((id) => ({ id })), @@ -169,10 +169,10 @@ export class ShopsTariffsComponent implements OnInit { } update(options?: UpdateOptions) { - this.shopsTariffsService.reload(options); + this.shopsTermsService.reload(options); } more() { - this.shopsTariffsService.more(); + this.shopsTermsService.more(); } } diff --git a/src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.service.ts b/src/app/sections/terms/components/shops-terms/shops-terms.service.ts similarity index 93% rename from src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.service.ts rename to src/app/sections/terms/components/shops-terms/shops-terms.service.ts index 6a074da3..b44fec36 100644 --- a/src/app/sections/tariffs/components/shops-tariffs/shops-tariffs.service.ts +++ b/src/app/sections/terms/components/shops-terms/shops-terms.service.ts @@ -14,7 +14,7 @@ import { DominatorService } from '@cc/app/api/dominator'; @Injectable({ providedIn: 'root', }) -export class ShopsTariffsService extends FetchSuperclass { +export class ShopsTermsService extends FetchSuperclass { constructor( private dominatorService: DominatorService, private log: NotifyLogService, diff --git a/src/app/sections/tariffs/components/shops-tariffs/utils/shop-fees-columns.ts b/src/app/sections/terms/components/shops-terms/utils/shop-fees-columns.ts similarity index 100% rename from src/app/sections/tariffs/components/shops-tariffs/utils/shop-fees-columns.ts rename to src/app/sections/terms/components/shops-terms/utils/shop-fees-columns.ts diff --git a/src/app/sections/tariffs/components/terminals-term-set-history-card/index.ts b/src/app/sections/terms/components/terminals-term-set-history-card/index.ts similarity index 100% rename from src/app/sections/tariffs/components/terminals-term-set-history-card/index.ts rename to src/app/sections/terms/components/terminals-term-set-history-card/index.ts diff --git a/src/app/sections/tariffs/components/terminals-term-set-history-card/terminals-term-set-history-card.component.html b/src/app/sections/terms/components/terminals-term-set-history-card/terminals-term-set-history-card.component.html similarity index 100% rename from src/app/sections/tariffs/components/terminals-term-set-history-card/terminals-term-set-history-card.component.html rename to src/app/sections/terms/components/terminals-term-set-history-card/terminals-term-set-history-card.component.html diff --git a/src/app/sections/tariffs/components/terminals-term-set-history-card/terminals-term-set-history-card.component.ts b/src/app/sections/terms/components/terminals-term-set-history-card/terminals-term-set-history-card.component.ts similarity index 100% rename from src/app/sections/tariffs/components/terminals-term-set-history-card/terminals-term-set-history-card.component.ts rename to src/app/sections/terms/components/terminals-term-set-history-card/terminals-term-set-history-card.component.ts diff --git a/src/app/sections/tariffs/components/terminals-terms/terminals-terms.component.html b/src/app/sections/terms/components/terminals-terms/terminals-terms.component.html similarity index 98% rename from src/app/sections/tariffs/components/terminals-terms/terminals-terms.component.html rename to src/app/sections/terms/components/terminals-terms/terminals-terms.component.html index d153246d..ba3e01b8 100644 --- a/src/app/sections/tariffs/components/terminals-terms/terminals-terms.component.html +++ b/src/app/sections/terms/components/terminals-terms/terminals-terms.component.html @@ -18,7 +18,7 @@ wallets: arrayColumnTemplate }" [columns]="columns" - [data]="tariffs$ | async" + [data]="terms$ | async" [hasMore]="hasMore$ | async" [progress]="isLoading$ | async" (more)="more()" diff --git a/src/app/sections/tariffs/components/terminals-terms/terminals-terms.component.ts b/src/app/sections/terms/components/terminals-terms/terminals-terms.component.ts similarity index 98% rename from src/app/sections/tariffs/components/terminals-terms/terminals-terms.component.ts rename to src/app/sections/terms/components/terminals-terms/terminals-terms.component.ts index 05d21605..1296e1e1 100644 --- a/src/app/sections/tariffs/components/terminals-terms/terminals-terms.component.ts +++ b/src/app/sections/terms/components/terminals-terms/terminals-terms.component.ts @@ -48,7 +48,7 @@ type Params = Pick & >; @Component({ - selector: 'cc-terminals-tariffs', + selector: 'cc-terminals-terms', standalone: true, imports: [ CommonModule, @@ -73,7 +73,7 @@ export class TerminalsTermsComponent implements OnInit { terminal_ids: null, }), ); - tariffs$ = this.terminalsTermsService.result$; + terms$ = this.terminalsTermsService.result$; hasMore$ = this.terminalsTermsService.hasMore$; isLoading$ = this.terminalsTermsService.isLoading$; columns: Column[] = [ diff --git a/src/app/sections/tariffs/components/terminals-terms/terminals-terms.service.ts b/src/app/sections/terms/components/terminals-terms/terminals-terms.service.ts similarity index 100% rename from src/app/sections/tariffs/components/terminals-terms/terminals-terms.service.ts rename to src/app/sections/terms/components/terminals-terms/terminals-terms.service.ts diff --git a/src/app/sections/tariffs/components/terminals-terms/utils/create-terminal-fees-column.ts b/src/app/sections/terms/components/terminals-terms/utils/create-terminal-fees-column.ts similarity index 100% rename from src/app/sections/tariffs/components/terminals-terms/utils/create-terminal-fees-column.ts rename to src/app/sections/terms/components/terminals-terms/utils/create-terminal-fees-column.ts diff --git a/src/app/sections/tariffs/components/wallets-term-set-history-card/index.ts b/src/app/sections/terms/components/wallets-term-set-history-card/index.ts similarity index 100% rename from src/app/sections/tariffs/components/wallets-term-set-history-card/index.ts rename to src/app/sections/terms/components/wallets-term-set-history-card/index.ts diff --git a/src/app/sections/tariffs/components/wallets-term-set-history-card/wallets-term-set-history-card.component.html b/src/app/sections/terms/components/wallets-term-set-history-card/wallets-term-set-history-card.component.html similarity index 100% rename from src/app/sections/tariffs/components/wallets-term-set-history-card/wallets-term-set-history-card.component.html rename to src/app/sections/terms/components/wallets-term-set-history-card/wallets-term-set-history-card.component.html diff --git a/src/app/sections/tariffs/components/wallets-term-set-history-card/wallets-term-set-history-card.component.ts b/src/app/sections/terms/components/wallets-term-set-history-card/wallets-term-set-history-card.component.ts similarity index 97% rename from src/app/sections/tariffs/components/wallets-term-set-history-card/wallets-term-set-history-card.component.ts rename to src/app/sections/terms/components/wallets-term-set-history-card/wallets-term-set-history-card.component.ts index 43ffe6d9..33839e76 100644 --- a/src/app/sections/tariffs/components/wallets-term-set-history-card/wallets-term-set-history-card.component.ts +++ b/src/app/sections/terms/components/wallets-term-set-history-card/wallets-term-set-history-card.component.ts @@ -12,7 +12,7 @@ import { WALLET_FEES_COLUMNS, isWalletTermSetDecision, getWalletCashFlowSelectors, -} from '../wallets-tariffs/utils/wallet-fees-columns'; +} from '../wallets-terms/utils/wallet-fees-columns'; @Component({ selector: 'cc-wallets-term-set-history-card', diff --git a/src/app/sections/tariffs/components/wallets-tariffs/utils/wallet-fees-columns.ts b/src/app/sections/terms/components/wallets-terms/utils/wallet-fees-columns.ts similarity index 100% rename from src/app/sections/tariffs/components/wallets-tariffs/utils/wallet-fees-columns.ts rename to src/app/sections/terms/components/wallets-terms/utils/wallet-fees-columns.ts diff --git a/src/app/sections/tariffs/components/wallets-tariffs/wallets-tariffs.component.html b/src/app/sections/terms/components/wallets-terms/wallets-terms.component.html similarity index 96% rename from src/app/sections/tariffs/components/wallets-tariffs/wallets-tariffs.component.html rename to src/app/sections/terms/components/wallets-terms/wallets-terms.component.html index 67764771..924047af 100644 --- a/src/app/sections/tariffs/components/wallets-tariffs/wallets-tariffs.component.html +++ b/src/app/sections/terms/components/wallets-terms/wallets-terms.component.html @@ -18,7 +18,7 @@ [hasMore]="hasMore$ | async" [maxSize]="250" [progress]="isLoading$ | async" - [treeData]="tariffs$ | async" + [treeData]="terms$ | async" (more)="more()" (update)="update($event)" > diff --git a/src/app/sections/tariffs/components/wallets-tariffs/wallets-tariffs.component.ts b/src/app/sections/terms/components/wallets-terms/wallets-terms.component.ts similarity index 90% rename from src/app/sections/tariffs/components/wallets-tariffs/wallets-tariffs.component.ts rename to src/app/sections/terms/components/wallets-terms/wallets-terms.component.ts index 2f452792..b29f5e69 100644 --- a/src/app/sections/tariffs/components/wallets-tariffs/wallets-tariffs.component.ts +++ b/src/app/sections/terms/components/wallets-terms/wallets-terms.component.ts @@ -50,7 +50,7 @@ import { getWalletCashFlowSelectors, isWalletTermSetDecision, } from './utils/wallet-fees-columns'; -import { WalletsTariffsService } from './wallets-tariffs.service'; +import { WalletsTermsService } from './wallets-terms.service'; type Params = Pick & Overwrite< @@ -59,7 +59,7 @@ type Params = Pick & >; @Component({ - selector: 'cc-wallets-tariffs', + selector: 'cc-wallets-terms', standalone: true, imports: [ CommonModule, @@ -75,9 +75,9 @@ type Params = Pick & MatTooltip, VSelectPipe, ], - templateUrl: './wallets-tariffs.component.html', + templateUrl: './wallets-terms.component.html', }) -export class WalletsTariffsComponent implements OnInit { +export class WalletsTermsComponent implements OnInit { filtersForm = this.fb.group( createControls({ currencies: null, @@ -88,7 +88,7 @@ export class WalletsTariffsComponent implements OnInit { identity_ids: null, }), ); - tariffs$ = this.walletsTariffsService.result$.pipe( + terms$ = this.walletsTermsService.result$.pipe( map((terms) => terms.map((t) => ({ value: t, @@ -104,8 +104,8 @@ export class WalletsTariffsComponent implements OnInit { })), ), ); - hasMore$ = this.walletsTariffsService.hasMore$; - isLoading$ = this.walletsTariffsService.isLoading$; + hasMore$ = this.walletsTermsService.hasMore$; + isLoading$ = this.walletsTermsService.isLoading$; columns: Column2[] = [ createWalletColumn((d) => ({ id: d.wallet_id, name: d.wallet_name, partyId: d.owner_id }), { sticky: 'start', @@ -135,7 +135,7 @@ export class WalletsTariffsComponent implements OnInit { private initFiltersValue = this.filtersForm.value; constructor( - private walletsTariffsService: WalletsTariffsService, + private walletsTermsService: WalletsTermsService, private fb: NonNullableFormBuilder, private qp: QueryParamsService, @Inject(DEBOUNCE_TIME_MS) private debounceTimeMs: number, @@ -155,7 +155,7 @@ export class WalletsTariffsComponent implements OnInit { load(params: Params, options?: LoadOptions) { const { currencies, term_sets_ids, identity_ids, ...otherParams } = params; - this.walletsTariffsService.load( + this.walletsTermsService.load( clean({ common_search_query_params: { currencies }, term_sets_ids: term_sets_ids?.map?.((id) => ({ id })), @@ -167,10 +167,10 @@ export class WalletsTariffsComponent implements OnInit { } update(options?: UpdateOptions) { - this.walletsTariffsService.reload(options); + this.walletsTermsService.reload(options); } more() { - this.walletsTariffsService.more(); + this.walletsTermsService.more(); } } diff --git a/src/app/sections/tariffs/components/wallets-tariffs/wallets-tariffs.service.ts b/src/app/sections/terms/components/wallets-terms/wallets-terms.service.ts similarity index 93% rename from src/app/sections/tariffs/components/wallets-tariffs/wallets-tariffs.service.ts rename to src/app/sections/terms/components/wallets-terms/wallets-terms.service.ts index 2534b8ea..df502527 100644 --- a/src/app/sections/tariffs/components/wallets-tariffs/wallets-tariffs.service.ts +++ b/src/app/sections/terms/components/wallets-terms/wallets-terms.service.ts @@ -17,7 +17,7 @@ import { DominatorService } from '@cc/app/api/dominator'; @Injectable({ providedIn: 'root', }) -export class WalletsTariffsService extends FetchSuperclass { +export class WalletsTermsService extends FetchSuperclass { constructor( private dominatorService: DominatorService, private log: NotifyLogService, diff --git a/src/app/sections/terms/index.ts b/src/app/sections/terms/index.ts new file mode 100644 index 00000000..8f53aac0 --- /dev/null +++ b/src/app/sections/terms/index.ts @@ -0,0 +1 @@ +export * from './terms'; diff --git a/src/app/sections/tariffs/routing-config.ts b/src/app/sections/terms/routing-config.ts similarity index 100% rename from src/app/sections/tariffs/routing-config.ts rename to src/app/sections/terms/routing-config.ts diff --git a/src/app/sections/tariffs/tariffs-routing.module.ts b/src/app/sections/terms/terms-routing.module.ts similarity index 70% rename from src/app/sections/tariffs/tariffs-routing.module.ts rename to src/app/sections/terms/terms-routing.module.ts index b2b789fb..f9638a2a 100644 --- a/src/app/sections/tariffs/tariffs-routing.module.ts +++ b/src/app/sections/terms/terms-routing.module.ts @@ -3,28 +3,28 @@ import { RouterModule } from '@angular/router'; import { AppAuthGuardService } from '../../shared/services'; -import { ShopsTariffsComponent } from './components/shops-tariffs/shops-tariffs.component'; +import { ShopsTermsComponent } from './components/shops-terms/shops-terms.component'; import { TerminalsTermsComponent } from './components/terminals-terms/terminals-terms.component'; -import { WalletsTariffsComponent } from './components/wallets-tariffs/wallets-tariffs.component'; +import { WalletsTermsComponent } from './components/wallets-terms/wallets-terms.component'; import { ROUTING_CONFIG } from './routing-config'; -import { TariffsComponent } from './tariffs.component'; +import { TermsComponent } from './terms.component'; @NgModule({ imports: [ RouterModule.forChild([ { path: '', - component: TariffsComponent, + component: TermsComponent, canActivate: [AppAuthGuardService], data: ROUTING_CONFIG, children: [ { path: 'shops', - component: ShopsTariffsComponent, + component: ShopsTermsComponent, }, { path: 'wallets', - component: WalletsTariffsComponent, + component: WalletsTermsComponent, }, { path: 'terminals', @@ -41,4 +41,4 @@ import { TariffsComponent } from './tariffs.component'; ], exports: [RouterModule], }) -export class TariffsRoutingModule {} +export class TermsRoutingModule {} diff --git a/src/app/sections/tariffs/tariffs.component.html b/src/app/sections/terms/terms.component.html similarity index 100% rename from src/app/sections/tariffs/tariffs.component.html rename to src/app/sections/terms/terms.component.html diff --git a/src/app/sections/tariffs/tariffs.component.ts b/src/app/sections/terms/terms.component.ts similarity index 88% rename from src/app/sections/tariffs/tariffs.component.ts rename to src/app/sections/terms/terms.component.ts index 0b784d24..38364035 100644 --- a/src/app/sections/tariffs/tariffs.component.ts +++ b/src/app/sections/terms/terms.component.ts @@ -7,12 +7,12 @@ import { Link, NavComponent } from '@vality/ng-core'; import { SidenavInfoService } from '@cc/app/shared/components/sidenav-info'; @Component({ - selector: 'cc-tariffs', + selector: 'cc-terms', standalone: true, imports: [CommonModule, RouterOutlet, MatSidenavModule, NavComponent], - templateUrl: './tariffs.component.html', + templateUrl: './terms.component.html', }) -export class TariffsComponent { +export class TermsComponent { links: Link[] = [ { label: 'Shops', diff --git a/src/app/sections/terms/terms.ts b/src/app/sections/terms/terms.ts new file mode 100644 index 00000000..61bb49d5 --- /dev/null +++ b/src/app/sections/terms/terms.ts @@ -0,0 +1,10 @@ +import { CommonModule } from '@angular/common'; +import { NgModule } from '@angular/core'; + +import { ShopsTermsComponent } from './components/shops-terms/shops-terms.component'; +import { TermsRoutingModule } from './terms-routing.module'; + +@NgModule({ + imports: [CommonModule, TermsRoutingModule, ShopsTermsComponent], +}) +export class Terms {} diff --git a/src/app/sections/tariffs/utils/get-inline-decisions.ts b/src/app/sections/terms/utils/get-inline-decisions.ts similarity index 100% rename from src/app/sections/tariffs/utils/get-inline-decisions.ts rename to src/app/sections/terms/utils/get-inline-decisions.ts diff --git a/src/app/sections/tariffs/utils/is-one-hundred-percent-cash-flow-posting.ts b/src/app/sections/terms/utils/is-one-hundred-percent-cash-flow-posting.ts similarity index 100% rename from src/app/sections/tariffs/utils/is-one-hundred-percent-cash-flow-posting.ts rename to src/app/sections/terms/utils/is-one-hundred-percent-cash-flow-posting.ts diff --git a/src/app/sections/tariffs/utils/is-that-currency.ts b/src/app/sections/terms/utils/is-that-currency.ts similarity index 100% rename from src/app/sections/tariffs/utils/is-that-currency.ts rename to src/app/sections/terms/utils/is-that-currency.ts diff --git a/src/app/shared/components/shop-field/shop-field.component.html b/src/app/shared/components/shop-field/shop-field.component.html index e357b44e..88261380 100644 --- a/src/app/shared/components/shop-field/shop-field.component.html +++ b/src/app/shared/components/shop-field/shop-field.component.html @@ -1,8 +1,13 @@ - - {{ multiple ? 'Shops' : 'Shop' }} - - - {{ shop.details.name }} - - - + diff --git a/src/app/shared/components/shop-field/shop-field.component.scss b/src/app/shared/components/shop-field/shop-field.component.scss deleted file mode 100644 index 5e70ee46..00000000 --- a/src/app/shared/components/shop-field/shop-field.component.scss +++ /dev/null @@ -1,8 +0,0 @@ -:host { - overflow: hidden; - text-overflow: ellipsis; -} - -mat-form-field { - width: 100%; -} diff --git a/src/app/shared/components/shop-field/shop-field.component.ts b/src/app/shared/components/shop-field/shop-field.component.ts index f25b4910..1bec376b 100644 --- a/src/app/shared/components/shop-field/shop-field.component.ts +++ b/src/app/shared/components/shop-field/shop-field.component.ts @@ -1,92 +1,160 @@ import { - ChangeDetectionStrategy, Component, Input, - OnChanges, - OnInit, booleanAttribute, DestroyRef, + inject, + AfterViewInit, + input, + Injector, } from '@angular/core'; -import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { Shop } from '@vality/domain-proto/domain'; -import { PartyID, ShopID } from '@vality/domain-proto/payment_processing'; +import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop'; +import { PartyID, Shop, Party } from '@vality/domain-proto/internal/domain'; +import { ShopID } from '@vality/domain-proto/payment_processing'; import { createControlProviders, FormControlSuperclass, - setDisabled, - isEmpty, - ComponentChanges, + debounceTimeWithFirst, + Option, + NotifyLogService, + progressTo, } from '@vality/ng-core'; -import { BehaviorSubject, defer, of } from 'rxjs'; -import { filter, map, share, switchMap } from 'rxjs/operators'; +import { + BehaviorSubject, + of, + Subject, + combineLatest, + Observable, + concat, + scheduled, + asyncScheduler, + concatMap, +} from 'rxjs'; +import { map, switchMap, distinctUntilChanged, catchError } from 'rxjs/operators'; -import { PartyManagementService } from '@cc/app/api/payment-processing'; +import { DeanonimusService } from '../../../api/deanonimus'; +import { PartyManagementService } from '../../../api/payment-processing'; +import { DEBOUNCE_TIME_MS } from '../../../tokens'; @Component({ selector: 'cc-shop-field', templateUrl: './shop-field.component.html', - styleUrls: ['./shop-field.component.scss'], providers: createControlProviders(() => ShopFieldComponent), - changeDetection: ChangeDetectionStrategy.OnPush, }) -export class ShopFieldComponent - extends FormControlSuperclass< - M extends true ? Shop[] : Shop, - M extends true ? ShopID[] : ShopID - > - implements OnChanges, OnInit +export class ShopFieldComponent + extends FormControlSuperclass + implements AfterViewInit { - @Input() partyId: PartyID; - @Input({ transform: booleanAttribute }) multiple: M; + @Input() label: string; @Input({ transform: booleanAttribute }) required: boolean; + @Input() size?: string; + @Input() appearance?: string; + @Input() hint?: string; + @Input({ transform: booleanAttribute }) multiple = false; + partyId = input(); - shops$ = defer(() => this.partyId$).pipe( - switchMap((partyId) => - partyId - ? this.partyManagementService - .Get(partyId) - .pipe(map(({ shops }) => Array.from(shops.values()))) - : of([]), - ), - share(), - ); + options$ = new BehaviorSubject[]>([]); + searchChange$ = new Subject(); + progress$ = new BehaviorSubject(0); - private partyId$ = new BehaviorSubject(null); + private debounceTimeMs = inject(DEBOUNCE_TIME_MS); constructor( private partyManagementService: PartyManagementService, - private destroyRef: DestroyRef, + private deanonimusService: DeanonimusService, + private log: NotifyLogService, + private dr: DestroyRef, + private injector: Injector, ) { super(); } - setDisabledState(isDisabled: boolean) { - super.setDisabledState(!this.partyId || isDisabled); - } - - ngOnChanges(changes: ComponentChanges): void { - super.ngOnChanges(changes); - if (changes.partyId && this.partyId !== this.partyId$.value) { - this.partyId$.next(changes.partyId.currentValue); - setDisabled(this.control, !this.partyId); - } - } - - ngOnInit() { - this.shops$ - .pipe( - filter( - (shops) => - !isEmpty(this.control.value) && - (Array.isArray(this.control.value) - ? !this.control.value.every((v) => shops.some((s) => s.id === v)) - : !shops.some((s) => s.id === this.control.value)), + ngAfterViewInit() { + const initValues = this.getCurrentValues(); + combineLatest([ + concat( + scheduled(initValues.length ? initValues : [''], asyncScheduler), + this.searchChange$.pipe( + distinctUntilChanged(), + debounceTimeWithFirst(this.debounceTimeMs), ), - takeUntilDestroyed(this.destroyRef), + ), + toObservable(this.partyId, { injector: this.injector }).pipe( + switchMap((partyId) => + partyId + ? this.partyManagementService.Get(partyId).pipe(progressTo(this.progress$)) + : of(null), + ), + ), + ]) + .pipe( + concatMap(([term, party]) => + party + ? of(this.searchShopsByParty(party, term)) + : this.searchShops(term).pipe(progressTo(this.progress$)), + ), + takeUntilDestroyed(this.dr), ) - .subscribe(() => { - this.control.setValue(null); + .subscribe((options) => { + const oldOptions = this.options$.value; + this.options$.next( + this.getCurrentValues().reduce((acc, v) => { + if (acc.every((o) => o.value !== v)) { + acc.push( + oldOptions.find((f) => f.value === v) ?? { + label: `#${v}`, + value: v, + description: v, + }, + ); + } + return acc; + }, options), + ); }); - super.ngOnInit(); + } + + private searchShops(search: string): Observable[]> { + return this.deanonimusService.searchShopText(search).pipe( + map((partyShops) => + partyShops.map((p) => ({ + label: p.shop.details.name, + value: p.shop.id, + description: p.shop.id, + })), + ), + catchError((err) => { + this.log.error(err, 'Search error'); + return of([]); + }), + ); + } + + private searchShopsByParty(party: Party, search: string): Option[] { + const searchStr = search.trim().toLowerCase(); + return Array.from(party.shops.values()) + .map((shop) => ({ party, shop })) + .sort( + (a, b) => + +this.includeSearchStr(a, searchStr) - +this.includeSearchStr(b, searchStr), + ) + .map((p) => ({ + label: p.shop.details.name, + value: p.shop.id, + description: p.shop.id, + })); + } + + private includeSearchStr({ shop, party }: { party: Party; shop: Shop }, searchStr: string) { + return [shop.id, shop.details.name, party.id, party.party_name].some((v) => + String(v ?? '') + .toLowerCase() + .includes(searchStr), + ); + } + + private getCurrentValues() { + const v = this.control.value; + return v ? (Array.isArray(v) ? v : [v]) : []; } } diff --git a/src/app/shared/components/shop-field/shop-field.module.ts b/src/app/shared/components/shop-field/shop-field.module.ts index 123a6777..76eb6004 100644 --- a/src/app/shared/components/shop-field/shop-field.module.ts +++ b/src/app/shared/components/shop-field/shop-field.module.ts @@ -3,12 +3,20 @@ import { NgModule } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatSelectModule } from '@angular/material/select'; +import { SelectFieldModule } from '@vality/ng-core'; import { ShopFieldComponent } from './shop-field.component'; @NgModule({ declarations: [ShopFieldComponent], - imports: [CommonModule, MatFormFieldModule, MatSelectModule, FormsModule, ReactiveFormsModule], + imports: [ + CommonModule, + MatFormFieldModule, + MatSelectModule, + FormsModule, + ReactiveFormsModule, + SelectFieldModule, + ], exports: [ShopFieldComponent], }) export class ShopFieldModule {}