From 9c9b59602f6cdcc1c2d45aa7e4f558f89dbdbbcc Mon Sep 17 00:00:00 2001 From: Rinat Arsaev <11846445+KrickRay@users.noreply.github.com> Date: Fri, 15 Jan 2021 18:30:26 +0300 Subject: [PATCH] Add change delegate ruleset with refactor (#235) --- package-lock.json | 69 ++++---- package.json | 2 +- src/app/app.module.ts | 4 +- src/app/domain/domain.service.ts | 18 +++ ...nge-delegate-ruleset-dialog.component.html | 25 +++ ...-delegate-ruleset-dialog.component.spec.ts | 36 +++++ ...hange-delegate-ruleset-dialog.component.ts | 60 +++++++ .../change-delegate-ruleset-dialog.module.ts | 25 +++ .../change-delegate-ruleset-dialog/index.ts | 2 + .../change-target-dialog.component.html | 2 +- .../change-target-dialog.component.ts | 30 ++-- .../attach-new-ruleset-dialog.component.ts | 12 +- .../party-delegate-rulesets.component.html | 82 +--------- .../party-delegate-rulesets.component.ts | 108 ++++++------- .../party-delegate-rulesets.module.ts | 4 +- .../party-delegate-rulesets.service.ts | 111 +++++++------ ...y-payment-routing-rule-dialog.component.ts | 4 +- ...-payment-routing-rules-dialog.component.ts | 4 +- ...rty-payment-routing-ruleset.component.html | 58 +------ ...party-payment-routing-ruleset.component.ts | 126 +++++---------- .../party-payment-routing-ruleset.module.ts | 2 + .../routing-rules-list/index.ts | 2 + .../routing-rules-list.component.html | 72 +++++++++ .../routing-rules-list.component.spec.ts | 34 ++++ .../routing-rules-list.component.ts | 149 ++++++++++++++++++ .../routing-rules-list.module.ts | 28 ++++ ...hop-payment-routing-rule-dialog.service.ts | 8 +- .../shop-payment-routing-ruleset.service.ts | 2 +- .../target-ruleset-form.component.html | 4 +- .../target-ruleset-form.component.ts | 4 +- .../add-terminal-decision.service.ts | 9 +- .../remove-terminal-decision.service.ts | 6 +- src/app/thrift-services/ank/ank.service.ts | 2 +- .../damsel/claim-management.service.ts | 2 +- .../damsel/create-damsel-instance.ts | 24 --- .../thrift-services/damsel/damsel.module.ts | 9 +- .../damsel/domain-cache.service.ts | 28 ++-- .../thrift-services/damsel/domain.service.ts | 2 +- src/app/thrift-services/damsel/index.ts | 8 +- .../damsel/merchant-statistics.service.ts | 4 +- .../damsel/payment-processing.service.ts | 4 +- ...n-typed-manager.ts => provider.service.ts} | 25 +-- .../damsel/routing-rules/index.ts | 2 + .../routing-rules/routing-rules.module.ts | 8 + .../routing-rules.service.ts} | 112 ++++++++++--- .../routing-rules/utils/get-delegate.ts | 8 + ...inal-decision-property-for-shop.service.ts | 8 +- .../thrift-services/damsel/terminal/index.ts | 2 + .../damsel/terminal/terminal.module.ts | 8 + .../damsel/terminal/terminal.service.spec.ts | 20 +++ .../damsel/terminal/terminal.service.ts | 21 +++ .../damsel/utils/create-damsel-instance.ts | 24 +++ .../deanonimus/deanonimus.service.ts | 2 +- .../file-storage/file-storage.service.ts | 2 +- .../fistful/fistful-admin.service.ts | 2 +- .../fistful/fistful-stat.service.ts | 2 +- .../fistful/repairer.service.ts | 2 +- src/app/thrift-services/index.ts | 4 +- .../machinegun/automaton.service.ts | 2 +- .../messages/messages.service.ts | 2 +- .../{ => services/thrift}/thrift-service.ts | 2 +- .../skipper/chargebacks.service.ts | 2 +- .../skipper/skipper-instance-utils.ts | 2 +- .../thrift-services/utils/create-next-id.ts | 5 + .../{damsel => utils}/get-thrift-instance.ts | 6 +- .../create-thrift-instance-utils.ts | 0 .../thrift-instance/create-thrift-instance.ts | 0 .../{ => utils}/thrift-instance/index.ts | 0 .../thrift-instance/namespace-type.ts | 0 .../thrift-instance/object-to-json.ts | 0 .../thrift-instance-to-object.ts | 0 src/app/tokens.ts | 24 +++ .../confirm-action-dialog.component.html | 2 +- .../confirm-action-dialog.component.ts | 7 +- 74 files changed, 954 insertions(+), 537 deletions(-) create mode 100644 src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.html create mode 100644 src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.spec.ts create mode 100644 src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.ts create mode 100644 src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.module.ts create mode 100644 src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/index.ts create mode 100644 src/app/sections/payment-routing-rules/routing-rules-list/index.ts create mode 100644 src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.html create mode 100644 src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.spec.ts create mode 100644 src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.ts create mode 100644 src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.module.ts delete mode 100644 src/app/thrift-services/damsel/create-damsel-instance.ts rename src/app/thrift-services/damsel/{domain-typed-manager.ts => provider.service.ts} (65%) create mode 100644 src/app/thrift-services/damsel/routing-rules/index.ts create mode 100644 src/app/thrift-services/damsel/routing-rules/routing-rules.module.ts rename src/app/thrift-services/damsel/{payment-routing-rules.service.ts => routing-rules/routing-rules.service.ts} (77%) create mode 100644 src/app/thrift-services/damsel/routing-rules/utils/get-delegate.ts create mode 100644 src/app/thrift-services/damsel/terminal/index.ts create mode 100644 src/app/thrift-services/damsel/terminal/terminal.module.ts create mode 100644 src/app/thrift-services/damsel/terminal/terminal.service.spec.ts create mode 100644 src/app/thrift-services/damsel/terminal/terminal.service.ts create mode 100644 src/app/thrift-services/damsel/utils/create-damsel-instance.ts rename src/app/thrift-services/{ => services/thrift}/thrift-service.ts (97%) create mode 100644 src/app/thrift-services/utils/create-next-id.ts rename src/app/thrift-services/{damsel => utils}/get-thrift-instance.ts (66%) rename src/app/thrift-services/{ => utils}/thrift-instance/create-thrift-instance-utils.ts (100%) rename src/app/thrift-services/{ => utils}/thrift-instance/create-thrift-instance.ts (100%) rename src/app/thrift-services/{ => utils}/thrift-instance/index.ts (100%) rename src/app/thrift-services/{ => utils}/thrift-instance/namespace-type.ts (100%) rename src/app/thrift-services/{ => utils}/thrift-instance/object-to-json.ts (100%) rename src/app/thrift-services/{ => utils}/thrift-instance/thrift-instance-to-object.ts (100%) create mode 100644 src/app/tokens.ts diff --git a/package-lock.json b/package-lock.json index f3916110..2ad54e70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3760,13 +3760,13 @@ } }, "@rbkmoney/angular-templates": { - "version": "0.1.2", - "resolved": "https://npm.pkg.github.com/download/@rbkmoney/angular-templates/0.1.2/03923ba6c89fd4ba87e9acf77f1074d3693dbcfdc0e775f707d0338b7ad4b997", - "integrity": "sha512-io9DKeEbTQ0/h1UVkl18KjqWg3I2BxwHqvbSTpR7xkJ9J4VKqXS92BB1JYpOinQzY8W7qAxVYDosGBazhRIftA==", + "version": "0.2.2", + "resolved": "https://npm.pkg.github.com/download/@rbkmoney/angular-templates/0.2.2/0cf7c24313ca0e4f6b12ca9d666e0f83dcb3ca373cd95e4b57b9df41087b2f8a", + "integrity": "sha512-8QgSANZyXixa2HmwjlSXgppaR9p2NTzfn7Gt5Q6mmP1jHrHCfaN+Cso6e9Z2xth9Wae4BPz/tWYCRSWF0aLfSA==", "dev": true, "requires": { - "genry": "^0.15.0", - "lodash": "^4.17.15" + "genry": "^0.16.0", + "lodash": "^4.17.20" } }, "@rbkmoney/partial-fetcher": { @@ -7669,9 +7669,9 @@ } }, "easy-stack": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/easy-stack/-/easy-stack-1.0.0.tgz", - "integrity": "sha1-EskbMIWjfwuqM26UhurEv5Tj54g=", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/easy-stack/-/easy-stack-1.0.1.tgz", + "integrity": "sha512-wK2sCs4feiiJeFXn3zvY0p41mdU5VUgbgs1rNsc/y5ngFUijdWd+iIN8eoyuZHKB8xN6BL4PdWmzqFmxNg6V2w==", "dev": true }, "ecc-jsbn": { @@ -8933,9 +8933,9 @@ "dev": true }, "genry": { - "version": "0.15.0", - "resolved": "https://registry.npmjs.org/genry/-/genry-0.15.0.tgz", - "integrity": "sha512-XWjWNZzeXTKDtGsVyQSS6hnBlBDY/H7wMi0spj3bQv2yZ8+fVZy9M0TaS3W23NvRdNIZWx2iL6WGbLmqDQcNxA==", + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/genry/-/genry-0.16.0.tgz", + "integrity": "sha512-mgRduClrLDBS0JkaiFZBK2mP0ogFydKWIDMGmGOF2dS6YlbHa47ru6ZyYdx9AgUxFmWB1SFGTyahCRcAIK3gvg==", "dev": true, "requires": { "cosmiconfig": "^6.0.0", @@ -8944,7 +8944,7 @@ "ora": "^4.0.3", "pkg-up": "^3.1.0", "prettier": "^2.0.4", - "prompts": "^2.3.2", + "prompts": "^2.4.0", "ts-node": "^8.8.2", "yargs": "^15.3.1" }, @@ -8956,12 +8956,11 @@ "dev": true }, "ansi-styles": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", - "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "dev": true, "requires": { - "@types/color-name": "^1.1.1", "color-convert": "^2.0.1" } }, @@ -9021,9 +9020,9 @@ "dev": true }, "import-fresh": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz", - "integrity": "sha512-6e1q1cnWP2RXD9/keSkxHScg508CdXqXWgWBaETNhyuBFz+kUZlKboh+ISK+bU++DmbHimVBrOz/zzPe0sZ3sQ==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", "dev": true, "requires": { "parent-module": "^1.0.0", @@ -10459,18 +10458,18 @@ } }, "js-message": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.5.tgz", - "integrity": "sha1-IwDSSxrwjondCVvBpMnJz8uJLRU=", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.7.tgz", + "integrity": "sha512-efJLHhLjIyKRewNS9EGZ4UpI8NguuL6fKkhRxVuMmrGV2xN/0APGdQYwLFky5w9naebSZ0OwAGp0G6/2Cg90rA==", "dev": true }, "js-queue": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/js-queue/-/js-queue-2.0.0.tgz", - "integrity": "sha1-NiITz4YPRo8BJfxslqvBdCUx+Ug=", + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/js-queue/-/js-queue-2.0.2.tgz", + "integrity": "sha512-pbKLsbCfi7kriM3s1J4DDCo7jQkI58zPLHi0heXPzPlj0hjUsm+FesPUbE0DSbIVIK503A36aUBoCN7eMFedkA==", "dev": true, "requires": { - "easy-stack": "^1.0.0" + "easy-stack": "^1.0.1" } }, "js-sha256": { @@ -11919,14 +11918,14 @@ "integrity": "sha1-h6kGXNs1XTGC2PlM4RGIuCXGijs=" }, "node-ipc": { - "version": "9.1.1", - "resolved": "https://registry.npmjs.org/node-ipc/-/node-ipc-9.1.1.tgz", - "integrity": "sha512-FAyICv0sIRJxVp3GW5fzgaf9jwwRQxAKDJlmNFUL5hOy+W4X/I5AypyHoq0DXXbo9o/gt79gj++4cMr4jVWE/w==", + "version": "9.1.3", + "resolved": "https://registry.npmjs.org/node-ipc/-/node-ipc-9.1.3.tgz", + "integrity": "sha512-8RS4RZyS/KMKKYG8mrje+cLxwATe9dBCuOiqKFSWND4oOuKytfuKCiR9yinvhoXF/nGdX/WnbywaUee+9U87zA==", "dev": true, "requires": { "event-pubsub": "4.3.0", - "js-message": "1.0.5", - "js-queue": "2.0.0" + "js-message": "1.0.7", + "js-queue": "2.0.2" } }, "node-libs-browser": { @@ -13830,13 +13829,13 @@ } }, "prompts": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.3.2.tgz", - "integrity": "sha512-Q06uKs2CkNYVID0VqwfAl9mipo99zkBv/n2JtWY89Yxa3ZabWSrs0e2KTudKVa3peLUvYXMefDqIleLPVUBZMA==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.0.tgz", + "integrity": "sha512-awZAKrk3vN6CroQukBL+R9051a4R3zCZBlJm/HBfrSZ8iTpYix3VX1vU4mveiLpiwmOJT4wokTF9m6HUk4KqWQ==", "dev": true, "requires": { "kleur": "^3.0.3", - "sisteransi": "^1.0.4" + "sisteransi": "^1.0.5" } }, "protoduck": { diff --git a/package.json b/package.json index 7ae27fa1..5a2f9771 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "@angular-devkit/build-angular": "^0.1000.6", "@angular/cli": "^10.0.6", "@angular/compiler-cli": "^10.0.10", - "@rbkmoney/angular-templates": "^0.1.2", + "@rbkmoney/angular-templates": "^0.2.2", "@types/del": "^4.0.0", "@types/glob": "^7.1.3", "@types/humanize-duration": "~3.18.0", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index b8264b76..bb6c9222 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -35,11 +35,11 @@ import { SearchClaimsModule } from './sections/search-claims/search-claims.modul import { SearchPartiesModule } from './sections/search-parties/search-parties.module'; import { SettingsModule } from './settings'; import { ThemeManager, ThemeManagerModule, ThemeName } from './theme-manager'; +import { DEFAULT_DIALOG_CONFIG, DEFAULT_SEARCH_LIMIT, DIALOG_CONFIG, SEARCH_LIMIT } from './tokens'; /** * For use in specific locations (for example, questionary PDF document) */ - moment.locale('en'); @NgModule({ @@ -78,6 +78,8 @@ moment.locale('en'); { provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS }, { provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE] }, { provide: MAT_DATE_LOCALE, useValue: 'en' }, + { provide: SEARCH_LIMIT, useValue: DEFAULT_SEARCH_LIMIT }, + { provide: DIALOG_CONFIG, useValue: DEFAULT_DIALOG_CONFIG }, ], bootstrap: [AppComponent], }) diff --git a/src/app/domain/domain.service.ts b/src/app/domain/domain.service.ts index 7a6488a8..6f54a01a 100644 --- a/src/app/domain/domain.service.ts +++ b/src/app/domain/domain.service.ts @@ -9,6 +9,9 @@ import { DomainService as ThriftDomainService } from '../thrift-services/damsel/ import { DomainObject, Reference } from '../thrift-services/damsel/gen-model/domain'; import { Commit, Snapshot } from '../thrift-services/damsel/gen-model/domain_config'; +/** + * @deprecated duplicates thrift-services/damsel/domain-cache.service + */ @Injectable() export class DomainService { private shapshot$: Observable; @@ -17,16 +20,25 @@ export class DomainService { this.updateSnapshot(); } + /** + * @deprecated use DomainCacheService -> snapshot$ + */ get shapshot() { return this.shapshot$; } + /** + * @deprecated use DomainCacheService -> version$ + */ get version$(): Observable { return this.shapshot$.pipe( map(({ version }) => (version ? version.toNumber() : undefined)) ); } + /** + * @deprecated use DomainCacheService -> getObjects or specific service from thrift-services/damsel + */ getDomainObject(ref: Reference): Observable { return this.shapshot$.pipe( map(({ domain }) => { @@ -42,10 +54,16 @@ export class DomainService { ); } + /** + * @deprecated use DomainCacheService -> forceReload() + */ updateSnapshot() { return (this.shapshot$ = this.thriftDomainService.checkout(toGenReference())); } + /** + * @deprecated use DomainCacheService -> commit() + */ commit(commit: Commit) { return this.shapshot$.pipe( switchMap(({ version }) => diff --git a/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.html b/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.html new file mode 100644 index 00000000..ca5b52d6 --- /dev/null +++ b/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.html @@ -0,0 +1,25 @@ +
+
Change Delegate Ruleset
+ +
+ + Delegate Ruleset + + + #{{ i.ref.id }} {{ i.data.name }} + + + + + + + +
+ +
+ + +
+
diff --git a/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.spec.ts b/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.spec.ts new file mode 100644 index 00000000..20347b72 --- /dev/null +++ b/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.spec.ts @@ -0,0 +1,36 @@ +import { Component, DebugElement } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; + +import { ChangeDelegateRulesetDialogComponent } from './change-delegate-ruleset-dialog.component'; + +@Component({ + selector: 'cc-host', + template: ``, +}) +class HostComponent {} + +describe('ChangeDelegateRulesetDialogComponent', () => { + let fixture: ComponentFixture; + let debugElement: DebugElement; + let component: ChangeDelegateRulesetDialogComponent; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [], + declarations: [HostComponent, ChangeDelegateRulesetDialogComponent], + }).compileComponents(); + + fixture = TestBed.createComponent(HostComponent); + debugElement = fixture.debugElement.query( + By.directive(ChangeDelegateRulesetDialogComponent) + ); + component = debugElement.componentInstance; + + fixture.detectChanges(); + }); + + it('should be created', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.ts b/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.ts new file mode 100644 index 00000000..8732836b --- /dev/null +++ b/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.component.ts @@ -0,0 +1,60 @@ +import { ChangeDetectionStrategy, Component, Inject, OnInit } from '@angular/core'; +import { FormBuilder } from '@angular/forms'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; +import { map } from 'rxjs/operators'; + +import { RoutingRulesService } from '../../../thrift-services'; + +@UntilDestroy() +@Component({ + selector: 'cc-change-delegate-ruleset-dialog', + templateUrl: 'change-delegate-ruleset-dialog.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class ChangeDelegateRulesetDialogComponent implements OnInit { + form = this.fb.group({ + rulesetRefId: [], + description: '', + }); + + rulesets$ = this.routingRulesService.rulesets$; + + constructor( + private fb: FormBuilder, + private dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: { mainRulesetRefID: number; delegateIdx: number }, + private routingRulesService: RoutingRulesService + ) {} + + ngOnInit() { + this.routingRulesService + .getRuleset(this.data.mainRulesetRefID) + .pipe( + map((r) => r?.data?.decisions?.delegates?.[this.data?.delegateIdx]), + untilDestroyed(this) + ) + .subscribe((delegate) => { + this.form.patchValue({ + rulesetRefId: delegate?.ruleset?.id, + description: delegate?.description, + }); + }); + } + + cancel() { + this.dialogRef.close(); + } + + changeRuleset() { + this.routingRulesService + .changeDelegateRuleset({ + mainRulesetRefID: this.data.mainRulesetRefID, + delegateIdx: this.data.delegateIdx, + newDelegateRulesetRefID: this.form.value.rulesetRefId, + description: this.form.value.description, + }) + .pipe(untilDestroyed(this)) + .subscribe(() => this.dialogRef.close()); + } +} diff --git a/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.module.ts b/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.module.ts new file mode 100644 index 00000000..a101da1b --- /dev/null +++ b/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/change-delegate-ruleset-dialog.module.ts @@ -0,0 +1,25 @@ +import { CommonModule } from '@angular/common'; +import { NgModule } from '@angular/core'; +import { FlexLayoutModule } from '@angular/flex-layout'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; +import { MatInputModule } from '@angular/material/input'; +import { MatSelectModule } from '@angular/material/select'; + +import { ChangeDelegateRulesetDialogComponent } from './change-delegate-ruleset-dialog.component'; + +@NgModule({ + imports: [ + CommonModule, + FlexLayoutModule, + ReactiveFormsModule, + FormsModule, + MatInputModule, + MatButtonModule, + MatSelectModule, + ], + declarations: [ChangeDelegateRulesetDialogComponent], + exports: [ChangeDelegateRulesetDialogComponent], + providers: [], +}) +export class ChangeDelegateRulesetDialogModule {} diff --git a/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/index.ts b/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/index.ts new file mode 100644 index 00000000..49cda7e1 --- /dev/null +++ b/src/app/sections/payment-routing-rules/change-delegate-ruleset-dialog/index.ts @@ -0,0 +1,2 @@ +export * from './change-delegate-ruleset-dialog.component'; +export * from './change-delegate-ruleset-dialog.module'; diff --git a/src/app/sections/payment-routing-rules/change-target-dialog/change-target-dialog.component.html b/src/app/sections/payment-routing-rules/change-target-dialog/change-target-dialog.component.html index fee736e0..4ff2da4f 100644 --- a/src/app/sections/payment-routing-rules/change-target-dialog/change-target-dialog.component.html +++ b/src/app/sections/payment-routing-rules/change-target-dialog/change-target-dialog.component.html @@ -1,5 +1,5 @@
-
Change party delegate ruleset
+
Change main ruleset
(undefined); targetRulesetValid$ = new BehaviorSubject(undefined); initValue: Partial = {}; constructor( private dialogRef: MatDialogRef, - private paymentRoutingRulesService: PaymentRoutingRulesService, - @Inject(MAT_DIALOG_DATA) - public data: { mainRulesetRefID: number; rulesetID: number }, + private routingRulesService: RoutingRulesService, + @Inject(MAT_DIALOG_DATA) public data: { mainRulesetRefID: number; delegateIdx: number }, private errorService: ErrorService ) { - this.paymentRoutingRulesService + this.routingRulesService .getRuleset(data?.mainRulesetRefID) .pipe(untilDestroyed(this)) .subscribe((ruleset) => { this.initValue = { mainRulesetRefID: ruleset.ref.id, - mainDelegateDescription: ruleset?.data?.decisions?.delegates?.find( - (d) => d?.ruleset?.id === data?.rulesetID - )?.description, + mainDelegateDescription: + ruleset?.data?.decisions?.delegates?.[data?.delegateIdx]?.description, }; }); } changeTarget() { const { mainRulesetRefID, mainDelegateDescription } = this.targetRuleset$.value; - const { mainRulesetRefID: previousMainRulesetRefID, rulesetID } = this.data; - this.paymentRoutingRulesService - .changeDelegateRuleset({ + const { mainRulesetRefID: previousMainRulesetRefID, delegateIdx } = this.data; + this.routingRulesService + .changeMainRuleset({ previousMainRulesetRefID, mainRulesetRefID, mainDelegateDescription, - rulesetID, + delegateIdx, }) .pipe(untilDestroyed(this)) .subscribe(() => this.dialogRef.close(), this.errorService.error); diff --git a/src/app/sections/payment-routing-rules/party-delegate-rulesets/attach-new-ruleset-dialog/attach-new-ruleset-dialog.component.ts b/src/app/sections/payment-routing-rules/party-delegate-rulesets/attach-new-ruleset-dialog/attach-new-ruleset-dialog.component.ts index 996f3d45..0e330ef7 100644 --- a/src/app/sections/payment-routing-rules/party-delegate-rulesets/attach-new-ruleset-dialog/attach-new-ruleset-dialog.component.ts +++ b/src/app/sections/payment-routing-rules/party-delegate-rulesets/attach-new-ruleset-dialog/attach-new-ruleset-dialog.component.ts @@ -1,9 +1,9 @@ import { ChangeDetectionStrategy, Component, Inject } from '@angular/core'; import { FormBuilder } from '@angular/forms'; -import { MatDialogConfig, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { BehaviorSubject } from 'rxjs'; -import { PaymentRoutingRulesService } from 'src/app/thrift-services'; +import { RoutingRulesService } from 'src/app/thrift-services'; import { ErrorService } from '../../../../shared/services/error'; import { TargetRuleset } from '../../target-ruleset-form'; @@ -14,12 +14,6 @@ import { TargetRuleset } from '../../target-ruleset-form'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class AttachNewRulesetDialogComponent { - static defaultConfig: MatDialogConfig = { - disableClose: true, - width: '548px', - maxHeight: '90vh', - }; - form = this.fb.group({ ruleset: this.fb.group({ name: 'submain ruleset[by shop id]', @@ -33,7 +27,7 @@ export class AttachNewRulesetDialogComponent { constructor( private fb: FormBuilder, private dialogRef: MatDialogRef, - private paymentRoutingRulesService: PaymentRoutingRulesService, + private paymentRoutingRulesService: RoutingRulesService, @Inject(MAT_DIALOG_DATA) public data: { partyID: string }, private errorService: ErrorService ) {} diff --git a/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.component.html b/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.component.html index 357db283..889fedc4 100644 --- a/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.component.html +++ b/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.component.html @@ -2,7 +2,7 @@ -
+
Party delegate rulesets
- - - - - - - - - - - - - - - - - - - - - -
Payment institution - {{ element?.paymentInstitution?.data?.name }} - Main Ruleset - {{ element?.mainRuleset?.data?.name }} - Party delegate - {{ element?.partyDelegate?.description }} - - - - - - - -
- - -
-
- - -
Party delegate rulesets not found
-
+
diff --git a/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.component.ts b/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.component.ts index f1327277..9a3958b9 100644 --- a/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.component.ts +++ b/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.component.ts @@ -1,19 +1,15 @@ -import { ChangeDetectionStrategy, Component, ViewChild } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Inject } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { MatPaginator } from '@angular/material/paginator'; -import { MatTableDataSource } from '@angular/material/table'; import { Router } from '@angular/router'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; -import { combineLatest, ReplaySubject } from 'rxjs'; -import { filter, first, map, shareReplay, startWith, switchMap, take } from 'rxjs/operators'; - -import { ConfirmActionDialogComponent } from '@cc/components/confirm-action-dialog'; +import { combineLatest } from 'rxjs'; +import { first, map, switchMap, take } from 'rxjs/operators'; import { handleError } from '../../../../utils/operators/handle-error'; import { ErrorService } from '../../../shared/services/error'; -import { PaymentRoutingRulesService } from '../../../thrift-services'; +import { RoutingRulesService } from '../../../thrift-services'; import { DomainCacheService } from '../../../thrift-services/damsel/domain-cache.service'; -import { ChangeTargetDialogComponent } from '../change-target-dialog'; +import { DialogConfig, DIALOG_CONFIG } from '../../../tokens'; import { AttachNewRulesetDialogComponent } from './attach-new-ruleset-dialog'; import { PartyDelegateRulesetsService } from './party-delegate-rulesets.service'; @@ -25,32 +21,43 @@ import { PartyDelegateRulesetsService } from './party-delegate-rulesets.service' providers: [PartyDelegateRulesetsService], }) export class PartyDelegateRulesetsComponent { - displayedColumns = ['paymentInstitution', 'mainRuleset', 'partyDelegate', 'actions']; + displayedColumns = [ + { key: 'paymentInstitution', name: 'Payment institution' }, + { key: 'mainRuleset', name: 'Main ruleset' }, + { key: 'partyDelegate', name: 'Party delegate' }, + ]; isLoading$ = this.domainService.isLoading$; - - @ViewChild(MatPaginator) set paginator(paginator: MatPaginator) { - this.paginator$.next(paginator); - } - paginator$ = new ReplaySubject(1); - dataSource$ = combineLatest([ - this.partyDelegateRulesetsService.partyDelegateRulesets$, - this.paginator$.pipe(startWith(null)), - ]).pipe( - map(([v, paginator]) => { - const data = new MatTableDataSource(v); - data.paginator = paginator; - return data; - }), - shareReplay(1) + data$ = this.partyDelegateRulesetsService.getDelegatesWithPaymentInstitution().pipe( + map((rules) => + rules.map(({ mainRoutingRule, partyDelegate, paymentInstitution }) => ({ + parentRefId: mainRoutingRule?.ref?.id, + delegateIdx: mainRoutingRule?.data?.decisions?.delegates?.findIndex( + (d) => d === partyDelegate + ), + paymentInstitution: { + text: paymentInstitution?.data?.name, + caption: paymentInstitution?.ref?.id, + }, + mainRuleset: { + text: mainRoutingRule?.data?.name, + caption: mainRoutingRule?.ref?.id, + }, + partyDelegate: { + text: partyDelegate?.description, + caption: partyDelegate?.ruleset?.id, + }, + })) + ) ); constructor( private partyDelegateRulesetsService: PartyDelegateRulesetsService, - private paymentRoutingRulesService: PaymentRoutingRulesService, + private paymentRoutingRulesService: RoutingRulesService, private router: Router, private dialog: MatDialog, private domainService: DomainCacheService, - private errorService: ErrorService + private errorService: ErrorService, + @Inject(DIALOG_CONFIG) private dialogConfig: DialogConfig ) {} attachNewRuleset() { @@ -60,7 +67,7 @@ export class PartyDelegateRulesetsComponent { switchMap((partyID) => this.dialog .open(AttachNewRulesetDialogComponent, { - ...AttachNewRulesetDialogComponent.defaultConfig, + ...this.dialogConfig.medium, data: { partyID }, }) .afterClosed() @@ -71,40 +78,19 @@ export class PartyDelegateRulesetsComponent { .subscribe(); } - navigateToPartyRuleset(id: string) { - this.partyDelegateRulesetsService.partyID$ + navigateToPartyRuleset(parentRefId: number, delegateIdx: number) { + combineLatest([ + this.partyDelegateRulesetsService.partyID$, + this.paymentRoutingRulesService.getRuleset(parentRefId), + ]) .pipe(first(), untilDestroyed(this)) - .subscribe((partyID) => - this.router.navigate(['party', partyID, 'payment-routing-rules', id]) + .subscribe(([partyID, parent]) => + this.router.navigate([ + 'party', + partyID, + 'payment-routing-rules', + parent.data.decisions.delegates[delegateIdx].ruleset.id, + ]) ); } - - changeTarget(mainRulesetRefID: string, rulesetID: string) { - this.dialog - .open(ChangeTargetDialogComponent, { - ...ChangeTargetDialogComponent.defaultConfig, - data: { mainRulesetRefID, rulesetID }, - }) - .afterClosed() - .pipe(handleError(this.errorService.error), untilDestroyed(this)) - .subscribe(); - } - - deleteRuleset(mainRulesetRefID: number, rulesetRefID: number) { - this.dialog - .open(ConfirmActionDialogComponent) - .afterClosed() - .pipe( - filter((r) => r === 'confirm'), - switchMap(() => - this.paymentRoutingRulesService.deleteDelegate({ - mainRulesetRefID, - rulesetRefID, - }) - ), - handleError(this.errorService.error), - untilDestroyed(this) - ) - .subscribe(); - } } diff --git a/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.module.ts b/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.module.ts index aee49ba8..71cbb65a 100644 --- a/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.module.ts +++ b/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.module.ts @@ -13,7 +13,6 @@ import { MatPaginatorModule } from '@angular/material/paginator'; import { MatProgressBarModule } from '@angular/material/progress-bar'; import { MatRadioModule } from '@angular/material/radio'; import { MatSelectModule } from '@angular/material/select'; -import { MatTableModule } from '@angular/material/table'; import { RouterModule } from '@angular/router'; import { DetailsItemModule } from '@cc/components/details-item'; @@ -21,6 +20,7 @@ import { DetailsItemModule } from '@cc/components/details-item'; import { ErrorModule } from '../../../shared/services/error'; import { ChangeTargetDialogModule } from '../change-target-dialog'; import { PaymentRoutingRulesetHeaderModule } from '../payment-routing-ruleset-header'; +import { RoutingRulesListModule } from '../routing-rules-list'; import { TargetRulesetFormModule } from '../target-ruleset-form'; import { AttachNewRulesetDialogComponent } from './attach-new-ruleset-dialog'; import { PartyDelegateRulesetsRoutingModule } from './party-delegate-rulesets-routing.module'; @@ -37,7 +37,6 @@ const EXPORTED_DECLARATIONS = [PartyDelegateRulesetsComponent, AttachNewRulesetD CommonModule, RouterModule, MatCardModule, - MatTableModule, MatIconModule, MatPaginatorModule, MatMenuModule, @@ -52,6 +51,7 @@ const EXPORTED_DECLARATIONS = [PartyDelegateRulesetsComponent, AttachNewRulesetD ErrorModule, ChangeTargetDialogModule, TargetRulesetFormModule, + RoutingRulesListModule, ], declarations: EXPORTED_DECLARATIONS, exports: EXPORTED_DECLARATIONS, diff --git a/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.service.ts b/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.service.ts index eeb23062..e7403204 100644 --- a/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.service.ts +++ b/src/app/sections/payment-routing-rules/party-delegate-rulesets/party-delegate-rulesets.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { combineLatest } from 'rxjs'; -import { map, pluck, shareReplay, startWith } from 'rxjs/operators'; +import { map, pluck, startWith, switchMap } from 'rxjs/operators'; import { DomainCacheService } from 'src/app/thrift-services/damsel/domain-cache.service'; import { PaymentInstitutionObject, @@ -9,68 +9,67 @@ import { RoutingRulesObject, } from 'src/app/thrift-services/damsel/gen-model/domain'; -import { PaymentRoutingRulesService } from '../../../thrift-services'; +import { RoutingRulesService } from '../../../thrift-services'; @Injectable() export class PartyDelegateRulesetsService { partyID$ = this.route.params.pipe(startWith(this.route.snapshot.params), pluck('partyID')); - partyDelegateRulesets$ = combineLatest([ - this.domainService.getObjects('payment_institution'), - this.paymentRoutingRulesService.rulesets$, - this.partyID$, - ]).pipe( - map(([institutions, rules, partyID]) => { - const rulesetsWithInstitution = institutions - .map( - (i) => - [ - rules.find( - (r) => r?.ref?.id === i?.data?.payment_routing_rules?.policies?.id - ), - i, - ] as const - ) - .filter(([r]) => r); - const partyDelegateRulesets = rulesetsWithInstitution - .map( - ([r, i]) => - [ - r, - i, - r?.data?.decisions?.delegates - ?.map((d) => - d?.allowed?.condition?.party?.id === partyID ? d : undefined - ) - ?.filter((d) => d), - ] as const - ) - .filter(([, , d]) => d?.length) - .reduce( - (acc, [r, i, d]) => { - acc.push( - ...d.map((partyDelegate) => ({ - partyDelegate, - paymentInstitution: i, - mainRuleset: r, - })) - ); - return acc; - }, - [] as { - partyDelegate: RoutingDelegate; - paymentInstitution: PaymentInstitutionObject; - mainRuleset: RoutingRulesObject; - }[] - ); - return partyDelegateRulesets; - }), - shareReplay(1) - ); - constructor( private domainService: DomainCacheService, private route: ActivatedRoute, - private paymentRoutingRulesService: PaymentRoutingRulesService + private paymentRoutingRulesService: RoutingRulesService ) {} + + getDelegatesWithPaymentInstitution() { + return combineLatest([this.getPaymentInstitutionsWithRoutingRule(), this.partyID$]).pipe( + map(([paymentInstitutionsWithRoutingRule, partyID]) => + paymentInstitutionsWithRoutingRule + .map(({ routingRule: mainRoutingRule, paymentInstitution }) => ({ + mainRoutingRule, + paymentInstitution, + delegates: mainRoutingRule?.data?.decisions?.delegates + ?.map((d) => + d?.allowed?.condition?.party?.id === partyID ? d : undefined + ) + ?.filter((d) => d), + })) + .filter(({ delegates }) => delegates?.length) + .reduce< + { + partyDelegate: RoutingDelegate; + paymentInstitution: PaymentInstitutionObject; + mainRoutingRule: RoutingRulesObject; + }[] + >( + (acc, { delegates, ...rest }) => [ + ...acc, + ...delegates.map((partyDelegate) => ({ ...rest, partyDelegate })), + ], + [] + ) + ) + ); + } + + private getPaymentInstitutionsWithRoutingRule() { + return this.domainService.getObjects('payment_institution').pipe( + switchMap((paymentInstitutions) => + combineLatest( + paymentInstitutions.map((paymentInstitution) => + this.paymentRoutingRulesService + .getRuleset( + paymentInstitution?.data?.payment_routing_rules?.policies?.id + ) + .pipe( + map((routingRule) => ({ + paymentInstitution, + routingRule, + })) + ) + ) + ) + ) + ); + } } diff --git a/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/add-party-payment-routing-rule-dialog/add-party-payment-routing-rule-dialog.component.ts b/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/add-party-payment-routing-rule-dialog/add-party-payment-routing-rule-dialog.component.ts index 459648d9..089c0a3f 100644 --- a/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/add-party-payment-routing-rule-dialog/add-party-payment-routing-rule-dialog.component.ts +++ b/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/add-party-payment-routing-rule-dialog/add-party-payment-routing-rule-dialog.component.ts @@ -4,7 +4,7 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { ErrorService } from '../../../../shared/services/error'; -import { PaymentRoutingRulesService } from '../../../../thrift-services'; +import { RoutingRulesService } from '../../../../thrift-services'; import { Shop } from '../../../../thrift-services/damsel/gen-model/domain'; @UntilDestroy() @@ -21,7 +21,7 @@ export class AddPartyPaymentRoutingRuleDialogComponent { constructor( private fb: FormBuilder, private dialogRef: MatDialogRef, - private paymentRoutingRulesService: PaymentRoutingRulesService, + private paymentRoutingRulesService: RoutingRulesService, @Inject(MAT_DIALOG_DATA) public data: { refID: number; partyID: string; shops: Shop[] }, private errorService: ErrorService diff --git a/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/initialize-payment-routing-rules-dialog/initialize-payment-routing-rules-dialog.component.ts b/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/initialize-payment-routing-rules-dialog/initialize-payment-routing-rules-dialog.component.ts index 8bf7a48d..3573362f 100644 --- a/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/initialize-payment-routing-rules-dialog/initialize-payment-routing-rules-dialog.component.ts +++ b/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/initialize-payment-routing-rules-dialog/initialize-payment-routing-rules-dialog.component.ts @@ -4,7 +4,7 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { ErrorService } from '../../../../shared/services/error'; -import { PaymentRoutingRulesService } from '../../../../thrift-services'; +import { RoutingRulesService } from '../../../../thrift-services'; @UntilDestroy() @Component({ @@ -21,7 +21,7 @@ export class InitializePaymentRoutingRulesDialogComponent { constructor( private fb: FormBuilder, private dialogRef: MatDialogRef, - private paymentRoutingRulesService: PaymentRoutingRulesService, + private paymentRoutingRulesService: RoutingRulesService, @Inject(MAT_DIALOG_DATA) public data: { partyID: string; refID: number }, private errorService: ErrorService ) {} diff --git a/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.component.html b/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.component.html index 29b421fe..e2778c59 100644 --- a/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.component.html +++ b/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.component.html @@ -15,57 +15,11 @@ Party payment routing rules - - - - - - - - - - - - - - - - - -
Shop -
-
{{ element.shop.details?.name }}
-
{{ element.shop.id }}
-
-
Ruleset Ref ID{{ element.id }} - - - - - - -
- - -
-
- - -
- Party payment routing rules is empty -
-
+
@@ -75,7 +29,7 @@ fxLayoutAlign=" center" fxLayoutGap="24px" > -
Payment rules is not found
+
Payment rules not found
diff --git a/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.component.ts b/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.component.ts index 64d65222..56023353 100644 --- a/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.component.ts +++ b/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.component.ts @@ -1,25 +1,16 @@ -import { Component, ViewChild } from '@angular/core'; +import { Component, Inject } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { MatPaginator } from '@angular/material/paginator'; -import { MatTableDataSource } from '@angular/material/table'; import { Router } from '@angular/router'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; -import { combineLatest, ReplaySubject } from 'rxjs'; -import { filter, map, shareReplay, switchMap, take, withLatestFrom } from 'rxjs/operators'; +import { combineLatest } from 'rxjs'; +import { filter, map, shareReplay, switchMap, take } from 'rxjs/operators'; -import { ConfirmActionDialogComponent } from '@cc/components/confirm-action-dialog'; - -import { handleError } from '../../../../utils/operators/handle-error'; -import { ErrorService } from '../../../shared/services/error'; -import { PaymentRoutingRulesService } from '../../../thrift-services'; import { DomainCacheService } from '../../../thrift-services/damsel/domain-cache.service'; -import { ChangeTargetDialogComponent } from '../change-target-dialog'; +import { DialogConfig, DIALOG_CONFIG } from '../../../tokens'; import { AddPartyPaymentRoutingRuleDialogComponent } from './add-party-payment-routing-rule-dialog'; import { InitializePaymentRoutingRulesDialogComponent } from './initialize-payment-routing-rules-dialog'; import { PartyPaymentRoutingRulesetService } from './party-payment-routing-ruleset.service'; -const DIALOG_WIDTH = '548px'; - @UntilDestroy() @Component({ selector: 'cc-party-payment-routing-ruleset', @@ -30,44 +21,44 @@ const DIALOG_WIDTH = '548px'; export class PaymentRoutingRulesComponent { partyRuleset$ = this.partyPaymentRoutingRulesetService.partyRuleset$; partyID$ = this.partyPaymentRoutingRulesetService.partyID$; - displayedColumns = ['shop', 'id', 'actions']; isLoading$ = this.domainService.isLoading$; - @ViewChild(MatPaginator) set paginator(paginator: MatPaginator) { - this.paginator$.next(paginator); - } - paginator$ = new ReplaySubject(1); - dataSource$ = combineLatest([ - this.partyRuleset$, - this.partyPaymentRoutingRulesetService.shops$, - this.paginator$, - ]).pipe( + displayedColumns = [ + { key: 'shop', name: 'Shop' }, + { key: 'id', name: 'Delegate (Ruleset Ref ID)' }, + ]; + data$ = combineLatest([this.partyRuleset$, this.partyPaymentRoutingRulesetService.shops$]).pipe( filter(([r]) => !!r), - map(([ruleset, shops, paginator]) => { - const data = new MatTableDataSource( - ruleset.data.decisions.delegates - .filter((d) => d?.allowed?.condition?.party?.definition?.shop_is) - .map((d) => { - const shopId = d.allowed.condition.party.definition.shop_is; - return { - id: d.ruleset.id, - shop: shops.find((s) => s.id === shopId) || { id: shopId }, - }; - }) - ); - data.paginator = paginator; - return data; - }), + map(([ruleset, shops]) => + ruleset.data.decisions.delegates + .filter((d) => d?.allowed?.condition?.party?.definition?.shop_is) + .map((delegate) => { + const shopId = delegate.allowed.condition.party.definition.shop_is; + return { + parentRefId: ruleset.ref.id, + delegateIdx: ruleset.data.decisions.delegates.findIndex( + (d) => d === delegate + ), + id: { + text: delegate?.description, + caption: delegate?.ruleset?.id, + }, + shop: { + text: shops?.find((s) => s?.id === shopId)?.details?.name, + caption: shopId, + }, + }; + }) + ), shareReplay(1) ); constructor( private dialog: MatDialog, private partyPaymentRoutingRulesetService: PartyPaymentRoutingRulesetService, - private paymentRoutingRulesService: PaymentRoutingRulesService, private router: Router, private domainService: DomainCacheService, - private errorService: ErrorService + @Inject(DIALOG_CONFIG) private dialogConfig: DialogConfig ) {} initialize() { @@ -80,9 +71,7 @@ export class PaymentRoutingRulesComponent { switchMap(([partyID, refID]) => this.dialog .open(InitializePaymentRoutingRulesDialogComponent, { - disableClose: true, - width: DIALOG_WIDTH, - maxHeight: '90vh', + ...this.dialogConfig.medium, data: { partyID, refID }, }) .afterClosed() @@ -103,9 +92,7 @@ export class PaymentRoutingRulesComponent { switchMap(([refID, shops, partyID]) => this.dialog .open(AddPartyPaymentRoutingRuleDialogComponent, { - disableClose: true, - width: DIALOG_WIDTH, - maxHeight: '90vh', + ...this.dialogConfig.medium, data: { refID, shops, partyID }, }) .afterClosed() @@ -115,58 +102,21 @@ export class PaymentRoutingRulesComponent { .subscribe(); } - deleteRuleset(rulesetRefID: number) { - this.dialog - .open(ConfirmActionDialogComponent) - .afterClosed() - .pipe( - filter((r) => r === 'confirm'), - withLatestFrom(this.partyRuleset$), - switchMap(([, mainRuleset]) => - this.paymentRoutingRulesService.deleteDelegate({ - mainRulesetRefID: mainRuleset.ref.id, - rulesetRefID, - }) - ), - handleError(this.errorService.error), - untilDestroyed(this) - ) - .subscribe(); - } - - navigateToShopRuleset(refID: string) { + navigateToShopRuleset(parentRefId: number, delegateIdx: number) { combineLatest([ this.partyPaymentRoutingRulesetService.partyID$, - this.partyPaymentRoutingRulesetService.refID$, + this.partyPaymentRoutingRulesetService.partyRuleset$, ]) .pipe(take(1), untilDestroyed(this)) - .subscribe(([partyID, partyRefID]) => + .subscribe(([partyID, ruleset]) => this.router.navigate([ 'party', partyID, 'payment-routing-rules', - partyRefID, + parentRefId, 'shop-ruleset', - refID, + ruleset?.data?.decisions?.delegates?.[delegateIdx]?.ruleset?.id, ]) ); } - - changeTarget(rulesetID: string) { - this.partyRuleset$ - .pipe( - take(1), - switchMap((mainRuleset) => - this.dialog - .open(ChangeTargetDialogComponent, { - ...ChangeTargetDialogComponent.defaultConfig, - data: { mainRulesetRefID: mainRuleset.ref.id, rulesetID }, - }) - .afterClosed() - ), - handleError(this.errorService.error), - untilDestroyed(this) - ) - .subscribe(); - } } diff --git a/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.module.ts b/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.module.ts index 162d589a..d33319f6 100644 --- a/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.module.ts +++ b/src/app/sections/payment-routing-rules/party-payment-routing-ruleset/party-payment-routing-ruleset.module.ts @@ -22,6 +22,7 @@ import { ErrorModule } from '../../../shared/services/error'; import { DamselModule } from '../../../thrift-services'; import { ChangeTargetDialogModule } from '../change-target-dialog'; import { PaymentRoutingRulesetHeaderModule } from '../payment-routing-ruleset-header'; +import { RoutingRulesListModule } from '../routing-rules-list'; import { AddPartyPaymentRoutingRuleDialogModule } from './add-party-payment-routing-rule-dialog'; import { InitializePaymentRoutingRulesDialogModule } from './initialize-payment-routing-rules-dialog'; import { PartyPaymentRoutingRulesetRoutingModule } from './party-payment-routing-ruleset-routing.module'; @@ -54,6 +55,7 @@ import { PaymentRoutingRulesComponent } from './party-payment-routing-ruleset.co MatProgressBarModule, ErrorModule, ChangeTargetDialogModule, + RoutingRulesListModule, ], declarations: [PaymentRoutingRulesComponent], }) diff --git a/src/app/sections/payment-routing-rules/routing-rules-list/index.ts b/src/app/sections/payment-routing-rules/routing-rules-list/index.ts new file mode 100644 index 00000000..48780c45 --- /dev/null +++ b/src/app/sections/payment-routing-rules/routing-rules-list/index.ts @@ -0,0 +1,2 @@ +export * from './routing-rules-list.component'; +export * from './routing-rules-list.module'; diff --git a/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.html b/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.html new file mode 100644 index 00000000..3191b8db --- /dev/null +++ b/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.html @@ -0,0 +1,72 @@ + + + + + + + + + + + + + +
{{ column.name }} +
+
{{ element[column.key]?.text || ' ' }}
+
+ {{ element[column.key]?.caption || ' ' }} +
+
+ + {{ element[column.key] }} + +
+ + + + + + + + +
+ + +
+
+ + +
+ Routing rules not found +
+
diff --git a/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.spec.ts b/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.spec.ts new file mode 100644 index 00000000..82728a87 --- /dev/null +++ b/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.spec.ts @@ -0,0 +1,34 @@ +import { Component, DebugElement } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; + +import { RoutingRulesListComponent } from './routing-rules-list.component'; + +@Component({ + selector: 'cc-host', + template: ``, +}) +class HostComponent {} + +describe('RoutingRulesListComponent', () => { + let fixture: ComponentFixture; + let debugElement: DebugElement; + let component: RoutingRulesListComponent; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [], + declarations: [HostComponent, RoutingRulesListComponent], + }).compileComponents(); + + fixture = TestBed.createComponent(HostComponent); + debugElement = fixture.debugElement.query(By.directive(RoutingRulesListComponent)); + component = debugElement.componentInstance; + + fixture.detectChanges(); + }); + + it('should be created', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.ts b/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.ts new file mode 100644 index 00000000..1b9cd33c --- /dev/null +++ b/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.component.ts @@ -0,0 +1,149 @@ +import { + ChangeDetectionStrategy, + Component, + EventEmitter, + Inject, + Input, + Output, + ViewChild, +} from '@angular/core'; +import { MatDialog } from '@angular/material/dialog'; +import { MatPaginator } from '@angular/material/paginator'; +import { MatTableDataSource } from '@angular/material/table'; +import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; +import { combineLatest, ReplaySubject } from 'rxjs'; +import { filter, map, shareReplay, startWith, switchMap } from 'rxjs/operators'; + +import { ConfirmActionDialogComponent } from '../../../../components/confirm-action-dialog'; +import { handleError } from '../../../../utils/operators/handle-error'; +import { ErrorService } from '../../../shared/services/error'; +import { RoutingRulesService } from '../../../thrift-services'; +import { DialogConfig, DIALOG_CONFIG } from '../../../tokens'; +import { ChangeDelegateRulesetDialogComponent } from '../change-delegate-ruleset-dialog'; +import { ChangeTargetDialogComponent } from '../change-target-dialog'; + +type DelegateId = { + parentRefId: number; + delegateIdx: number; +}; + +@UntilDestroy() +@Component({ + selector: 'cc-routing-rules-list', + templateUrl: 'routing-rules-list.component.html', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class RoutingRulesListComponent { + @Input() displayedColumns: { key: keyof T; name: string }[]; + + @Input() set data(data: T[]) { + this.data$.next(data); + } + private data$ = new ReplaySubject(1); + + @Output() toDetails = new EventEmitter(); + + @ViewChild(MatPaginator) set paginator(paginator: MatPaginator) { + this.paginator$.next(paginator); + } + private paginator$ = new ReplaySubject(1); + + dataSource$ = combineLatest([ + this.data$, + this.paginator$.pipe(startWith(null)), + ]).pipe( + map(([d, paginator]) => { + const data = new MatTableDataSource(d); + data.paginator = paginator; + return data; + }), + shareReplay(1) + ); + + get allDisplayedColumns() { + if (!this.displayedColumns) { + return []; + } + return this.displayedColumns + .concat([ + { + key: 'actions', + name: 'Actions', + }, + ]) + .map(({ key }) => key); + } + + constructor( + private dialog: MatDialog, + private errorService: ErrorService, + private routingRulesService: RoutingRulesService, + @Inject(DIALOG_CONFIG) private dialogConfig: DialogConfig + ) {} + + getColumnsKeys(col) { + return col.key; + } + + changeDelegateRuleset(delegateId: DelegateId) { + this.dialog + .open(ChangeDelegateRulesetDialogComponent, { + ...this.dialogConfig.medium, + data: { + mainRulesetRefID: delegateId.parentRefId, + delegateIdx: delegateId.delegateIdx, + }, + }) + .afterClosed() + .pipe(handleError(this.errorService.error), untilDestroyed(this)) + .subscribe(); + } + + changeTarget(delegateId: DelegateId) { + this.dialog + .open(ChangeTargetDialogComponent, { + ...this.dialogConfig.medium, + data: { + mainRulesetRefID: delegateId.parentRefId, + delegateIdx: delegateId.delegateIdx, + }, + }) + .afterClosed() + .pipe(untilDestroyed(this)) + .subscribe({ error: this.errorService.error }); + } + + cloneDelegateRuleset(delegateId: DelegateId) { + this.dialog + .open(ConfirmActionDialogComponent, { data: { title: 'Clone delegate ruleset' } }) + .afterClosed() + .pipe( + filter((r) => r === 'confirm'), + switchMap(() => + this.routingRulesService.cloneDelegateRuleset({ + mainRulesetRefID: delegateId.parentRefId, + delegateIdx: delegateId.delegateIdx, + }) + ), + untilDestroyed(this) + ) + .subscribe({ error: this.errorService.error }); + } + + delete(delegateId: DelegateId) { + this.dialog + .open(ConfirmActionDialogComponent, { data: { title: 'Delete delegate' } }) + .afterClosed() + .pipe( + filter((r) => r === 'confirm'), + switchMap(() => + this.routingRulesService.deleteDelegate({ + mainRulesetRefID: delegateId.parentRefId, + delegateIdx: delegateId.delegateIdx, + }) + ), + untilDestroyed(this) + ) + .subscribe({ error: this.errorService.error }); + } +} diff --git a/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.module.ts b/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.module.ts new file mode 100644 index 00000000..b5d68659 --- /dev/null +++ b/src/app/sections/payment-routing-rules/routing-rules-list/routing-rules-list.module.ts @@ -0,0 +1,28 @@ +import { CommonModule } from '@angular/common'; +import { NgModule } from '@angular/core'; +import { FlexLayoutModule } from '@angular/flex-layout'; +import { MatButtonModule } from '@angular/material/button'; +import { MatCardModule } from '@angular/material/card'; +import { MatIconModule } from '@angular/material/icon'; +import { MatMenuModule } from '@angular/material/menu'; +import { MatPaginatorModule } from '@angular/material/paginator'; +import { MatTableModule } from '@angular/material/table'; + +import { RoutingRulesListComponent } from './routing-rules-list.component'; + +@NgModule({ + imports: [ + CommonModule, + MatMenuModule, + MatCardModule, + MatTableModule, + MatPaginatorModule, + MatTableModule, + MatIconModule, + FlexLayoutModule, + MatButtonModule, + ], + declarations: [RoutingRulesListComponent], + exports: [RoutingRulesListComponent], +}) +export class RoutingRulesListModule {} diff --git a/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/add-shop-payment-routing-rule-dialog/add-shop-payment-routing-rule-dialog.service.ts b/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/add-shop-payment-routing-rule-dialog/add-shop-payment-routing-rule-dialog.service.ts index f9a05c23..9a6b7428 100644 --- a/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/add-shop-payment-routing-rule-dialog/add-shop-payment-routing-rule-dialog.service.ts +++ b/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/add-shop-payment-routing-rule-dialog/add-shop-payment-routing-rule-dialog.service.ts @@ -4,7 +4,7 @@ import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { of } from 'rxjs'; import { startWith, switchMap, take } from 'rxjs/operators'; -import { DomainTypedManager, PaymentRoutingRulesService } from '../../../../thrift-services'; +import { RoutingRulesService, TerminalService } from '../../../../thrift-services'; import { Predicate } from '../../../../thrift-services/damsel/gen-model/domain'; import { AddShopPaymentRoutingRuleDialogComponent } from './add-shop-payment-routing-rule-dialog.component'; @@ -36,8 +36,8 @@ export class AddShopPaymentRoutingRuleDialogService { constructor( private fb: FormBuilder, private dialogRef: MatDialogRef, - private paymentRoutingRulesService: PaymentRoutingRulesService, - private domainTypedManager: DomainTypedManager, + private paymentRoutingRulesService: RoutingRulesService, + private terminalService: TerminalService, @Inject(MAT_DIALOG_DATA) public data: { partyID: string; refID: number } ) { this.form @@ -72,7 +72,7 @@ export class AddShopPaymentRoutingRuleDialogService { newTerminal, } = this.form.value; (terminalType === TerminalType.new - ? this.domainTypedManager.createTerminal({ + ? this.terminalService.createTerminal({ terminalName: newTerminal.name, terminalDescription: newTerminal.description, riskCoverage: newTerminal.riskCoverage, diff --git a/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/shop-payment-routing-ruleset.service.ts b/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/shop-payment-routing-ruleset.service.ts index 68465e7c..e514e631 100644 --- a/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/shop-payment-routing-ruleset.service.ts +++ b/src/app/sections/payment-routing-rules/shop-payment-routing-ruleset/shop-payment-routing-ruleset.service.ts @@ -6,7 +6,7 @@ import { map, pluck, shareReplay, switchMap, take } from 'rxjs/operators'; import { handleError } from '../../../../utils/operators/handle-error'; import { PartyService } from '../../../papi/party.service'; import { ErrorService } from '../../../shared/services/error'; -import { PaymentRoutingRulesService as PaymentRoutingRulesDamselService } from '../../../thrift-services'; +import { RoutingRulesService as PaymentRoutingRulesDamselService } from '../../../thrift-services'; @Injectable() export class ShopPaymentRoutingRulesetService { diff --git a/src/app/sections/payment-routing-rules/target-ruleset-form/target-ruleset-form.component.html b/src/app/sections/payment-routing-rules/target-ruleset-form/target-ruleset-form.component.html index 3cb3cebb..0d07ce07 100644 --- a/src/app/sections/payment-routing-rules/target-ruleset-form/target-ruleset-form.component.html +++ b/src/app/sections/payment-routing-rules/target-ruleset-form/target-ruleset-form.component.html @@ -1,5 +1,5 @@
-
Target Ruleset
+
Change Main Ruleset
@@ -39,7 +39,7 @@
- Payment Routing Ruleset + Main Ruleset #{{ i.ref.id }} {{ i.data.name }} diff --git a/src/app/sections/payment-routing-rules/target-ruleset-form/target-ruleset-form.component.ts b/src/app/sections/payment-routing-rules/target-ruleset-form/target-ruleset-form.component.ts index fe6b0fc3..e6fc9bb8 100644 --- a/src/app/sections/payment-routing-rules/target-ruleset-form/target-ruleset-form.component.ts +++ b/src/app/sections/payment-routing-rules/target-ruleset-form/target-ruleset-form.component.ts @@ -15,7 +15,7 @@ import { PaymentInstitutionObject } from 'src/app/thrift-services/damsel/gen-mod import { ComponentChanges } from '@cc/app/shared/utils'; -import { PaymentRoutingRulesService } from '../../../thrift-services'; +import { RoutingRulesService } from '../../../thrift-services'; import { Target } from './types/target'; import { TargetRuleset } from './types/target-ruleset'; @@ -47,7 +47,7 @@ export class TargetRulesetFormComponent implements OnChanges { constructor( private fb: FormBuilder, private domainService: DomainCacheService, - private paymentRoutingRulesService: PaymentRoutingRulesService + private paymentRoutingRulesService: RoutingRulesService ) { this.form.controls.target.valueChanges .pipe(startWith(this.form.value.target), untilDestroyed(this)) diff --git a/src/app/sections/shop-details/shop-providers/add-terminal-dialog/services/add-terminal-decision/add-terminal-decision.service.ts b/src/app/sections/shop-details/shop-providers/add-terminal-dialog/services/add-terminal-decision/add-terminal-decision.service.ts index 03ca1968..0852c26a 100644 --- a/src/app/sections/shop-details/shop-providers/add-terminal-dialog/services/add-terminal-decision/add-terminal-decision.service.ts +++ b/src/app/sections/shop-details/shop-providers/add-terminal-dialog/services/add-terminal-decision/add-terminal-decision.service.ts @@ -4,10 +4,7 @@ import { progress } from '@rbkmoney/partial-fetcher/dist/progress'; import { merge, Observable, Subject } from 'rxjs'; import { map, shareReplay, switchMap } from 'rxjs/operators'; -import { - AddDecisionToProvider, - DomainTypedManager, -} from '../../../../../../thrift-services/damsel'; +import { AddDecisionToProvider, ProviderService } from '../../../../../../thrift-services/damsel'; import { DomainCacheService } from '../../../../../../thrift-services/damsel/domain-cache.service'; import { PartyID, @@ -35,7 +32,7 @@ export class AddTerminalDecisionService { terminalID: this.terminalForm.value.id, })), switchMap((params) => - this.domainTypedManager.getProviderFromParams(params) + this.providerService.getProviderFromParams(params) ), switchMap(([params, providerObject]) => this.domainCacheService.commit(addDecisionToProviderCommit(providerObject, params)) @@ -47,7 +44,7 @@ export class AddTerminalDecisionService { constructor( private domainCacheService: DomainCacheService, - private domainTypedManager: DomainTypedManager, + private providerService: ProviderService, private fb: FormBuilder ) { this.terminalAdded$.subscribe(); diff --git a/src/app/sections/shop-details/shop-providers/services/remove-terminal-decision/remove-terminal-decision.service.ts b/src/app/sections/shop-details/shop-providers/services/remove-terminal-decision/remove-terminal-decision.service.ts index 88e74f50..ecaf63e6 100644 --- a/src/app/sections/shop-details/shop-providers/services/remove-terminal-decision/remove-terminal-decision.service.ts +++ b/src/app/sections/shop-details/shop-providers/services/remove-terminal-decision/remove-terminal-decision.service.ts @@ -7,7 +7,7 @@ import { catchError, filter, map, shareReplay, switchMap } from 'rxjs/operators' import { ConfirmActionDialogComponent } from '@cc/components/confirm-action-dialog'; -import { DomainTypedManager } from '../../../../../thrift-services/damsel'; +import { ProviderService } from '../../../../../thrift-services/damsel'; import { DomainCacheService } from '../../../../../thrift-services/damsel/domain-cache.service'; import { createRemoveTerminalFromShopCommit } from '../../../../../thrift-services/damsel/operations/create-remove-terminal-from-shop-commit'; import { RemoveTerminalFromShopParams } from '../../../../../thrift-services/damsel/operations/remove-terminal-from-shop-params'; @@ -40,7 +40,7 @@ export class RemoveTerminalDecisionService { ]) ), switchMap(([params]) => - this.domainTypedManager.getProviderFromParams(params) + this.providerService.getProviderFromParams(params) ), map(([params, providerObject]) => createRemoveTerminalFromShopCommit(providerObject, params) @@ -65,7 +65,7 @@ export class RemoveTerminalDecisionService { private dialog: MatDialog, private snackBar: MatSnackBar, private domainCacheService: DomainCacheService, - private domainTypedManager: DomainTypedManager + private providerService: ProviderService ) { this.terminalRemoved$.subscribe(); this.error$.subscribe(() => { diff --git a/src/app/thrift-services/ank/ank.service.ts b/src/app/thrift-services/ank/ank.service.ts index 095b42d9..4c826cb6 100644 --- a/src/app/thrift-services/ank/ank.service.ts +++ b/src/app/thrift-services/ank/ank.service.ts @@ -4,7 +4,7 @@ import { Observable } from 'rxjs'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; import { toGenReference } from '../converters'; import { PartyID } from '../damsel/gen-model/domain'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { QuestionaryID, QuestionaryParams, diff --git a/src/app/thrift-services/damsel/claim-management.service.ts b/src/app/thrift-services/damsel/claim-management.service.ts index 6fd0dfc7..2e26a4d5 100644 --- a/src/app/thrift-services/damsel/claim-management.service.ts +++ b/src/app/thrift-services/damsel/claim-management.service.ts @@ -3,7 +3,7 @@ import { Observable } from 'rxjs'; import { switchMap } from 'rxjs/operators'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { Claim, ClaimID, diff --git a/src/app/thrift-services/damsel/create-damsel-instance.ts b/src/app/thrift-services/damsel/create-damsel-instance.ts deleted file mode 100644 index af1d0d2b..00000000 --- a/src/app/thrift-services/damsel/create-damsel-instance.ts +++ /dev/null @@ -1,24 +0,0 @@ -import metadata from '../../../assets/meta-damsel.json'; -import { createThriftInstanceUtils } from '../thrift-instance'; -import * as base from './gen-nodejs/base_types'; -import * as claim_management from './gen-nodejs/claim_management_types'; -import * as domain_config from './gen-nodejs/domain_config_types'; -import * as domain from './gen-nodejs/domain_types'; -import * as geo_ip from './gen-nodejs/geo_ip_types'; -import * as merch_stat from './gen-nodejs/merch_stat_types'; -import * as payment_processing from './gen-nodejs/payment_processing_types'; - -const namespaces = { - base, - domain, - domain_config, - claim_management, - geo_ip, - merch_stat, - payment_processing, -}; - -export const { - createThriftInstance: createDamselInstance, - thriftInstanceToObject: damselInstanceToObject, -} = createThriftInstanceUtils(metadata, namespaces); diff --git a/src/app/thrift-services/damsel/damsel.module.ts b/src/app/thrift-services/damsel/damsel.module.ts index 6e558c7d..1dfe67f5 100644 --- a/src/app/thrift-services/damsel/damsel.module.ts +++ b/src/app/thrift-services/damsel/damsel.module.ts @@ -2,21 +2,22 @@ import { NgModule } from '@angular/core'; import { ClaimManagementService } from './claim-management.service'; import { DomainCacheService } from './domain-cache.service'; -import { DomainTypedManager } from './domain-typed-manager'; import { DomainService } from './domain.service'; import { MerchantStatisticsService } from './merchant-statistics.service'; import { PaymentProcessingService } from './payment-processing.service'; -import { PaymentRoutingRulesService } from './payment-routing-rules.service'; +import { ProviderService } from './provider.service'; +import { RoutingRulesModule } from './routing-rules'; +import { TerminalModule } from './terminal'; @NgModule({ + imports: [RoutingRulesModule, TerminalModule], providers: [ DomainService, - DomainTypedManager, + ProviderService, PaymentProcessingService, MerchantStatisticsService, DomainCacheService, ClaimManagementService, - PaymentRoutingRulesService, ], }) export class DamselModule {} diff --git a/src/app/thrift-services/damsel/domain-cache.service.ts b/src/app/thrift-services/damsel/domain-cache.service.ts index d07ecbf3..74a22f41 100644 --- a/src/app/thrift-services/damsel/domain-cache.service.ts +++ b/src/app/thrift-services/damsel/domain-cache.service.ts @@ -1,16 +1,15 @@ import { Injectable } from '@angular/core'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { BehaviorSubject, Observable, of, ReplaySubject } from 'rxjs'; -import { map, pluck, shareReplay, startWith, switchMap, take, tap } from 'rxjs/operators'; -import type { Int64 } from 'thrift-ts'; +import { map, pluck, share, shareReplay, startWith, switchMap, take, tap } from 'rxjs/operators'; import { getUnionKey } from '@cc/utils/get-union-key'; import { toGenReference } from '../converters'; -import { createDamselInstance, damselInstanceToObject } from './create-damsel-instance'; import { DomainService } from './domain.service'; import { Domain, DomainObject } from './gen-model/domain'; import { Commit, Snapshot, Version } from './gen-model/domain_config'; +import { createDamselInstance, damselInstanceToObject } from './utils/create-damsel-instance'; @UntilDestroy() @Injectable() @@ -21,7 +20,7 @@ export class DomainCacheService { domain: Observable; snapshot$: Observable; domain$: Observable; - version$: Observable; + version$: Observable; get isLoading$(): Observable { return this._isLoading$.asObservable(); } @@ -43,7 +42,7 @@ export class DomainCacheService { shareReplay(1) ); this.domain$ = this.snapshot$.pipe(pluck('domain')); - this.version$ = this.snapshot$.pipe(pluck('version')); + this.version$ = this.snapshot$.pipe(pluck('version')) as Observable; this.snapshot.pipe(untilDestroyed(this)).subscribe(); } @@ -61,17 +60,26 @@ export class DomainCacheService { ) ); - commit = (commit: Commit, version?: Version) => { - return (version ? of(version) : this.version$).pipe( - take(1), + commit = (commit: Commit, version?: Version | number, reload = true) => { + const version$ = version ? of(version) : this.version$.pipe(take(1)); + return version$.pipe( switchMap((v) => this.dmtService.commit( - createDamselInstance('domain_config', 'Version', v), + createDamselInstance('domain_config', 'Version', v as Version), createDamselInstance('domain_config', 'Commit', commit) ) ), map((v) => damselInstanceToObject('domain_config', 'Version', v)), - tap(() => this.forceReload()) + tap(() => reload && this.forceReload()), + share() ); }; + + sequenseCommits([commit, ...otherCommits]: Commit[], version?: Version | number) { + return otherCommits.length + ? this.commit(commit, version, false).pipe( + switchMap((v) => this.sequenseCommits(otherCommits, v)) + ) + : this.commit(commit, version); + } } diff --git a/src/app/thrift-services/damsel/domain.service.ts b/src/app/thrift-services/damsel/domain.service.ts index 603b1390..e16ab4d1 100644 --- a/src/app/thrift-services/damsel/domain.service.ts +++ b/src/app/thrift-services/damsel/domain.service.ts @@ -2,7 +2,7 @@ import { Injectable, NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { Commit, Limit, Reference, Snapshot, Version } from './gen-model/domain_config'; import * as Repository from './gen-nodejs/Repository'; diff --git a/src/app/thrift-services/damsel/index.ts b/src/app/thrift-services/damsel/index.ts index 626c9f98..13209ff8 100644 --- a/src/app/thrift-services/damsel/index.ts +++ b/src/app/thrift-services/damsel/index.ts @@ -1,8 +1,8 @@ export * from './operations'; -export * from './domain-typed-manager'; export * from './domain.service'; -export * from './get-thrift-instance'; -export * from './create-damsel-instance'; +export * from './utils/create-damsel-instance'; export * from './damsel.module'; -export * from './payment-routing-rules.service'; +export * from './routing-rules'; export * from './services'; +export * from './terminal'; +export * from './provider.service'; diff --git a/src/app/thrift-services/damsel/merchant-statistics.service.ts b/src/app/thrift-services/damsel/merchant-statistics.service.ts index 240b3229..9093e69f 100644 --- a/src/app/thrift-services/damsel/merchant-statistics.service.ts +++ b/src/app/thrift-services/damsel/merchant-statistics.service.ts @@ -3,11 +3,11 @@ import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; -import { createDamselInstance, damselInstanceToObject } from './create-damsel-instance'; +import { ThriftService } from '../services/thrift/thrift-service'; import { StatRequest, StatResponse } from './gen-model/merch_stat'; import * as MerchantStatistics from './gen-nodejs/MerchantStatistics'; import { StatRequest as ThriftStatRequest } from './gen-nodejs/merch_stat_types'; +import { createDamselInstance, damselInstanceToObject } from './utils/create-damsel-instance'; @Injectable() export class MerchantStatisticsService extends ThriftService { diff --git a/src/app/thrift-services/damsel/payment-processing.service.ts b/src/app/thrift-services/damsel/payment-processing.service.ts index 30416f20..4365d62f 100644 --- a/src/app/thrift-services/damsel/payment-processing.service.ts +++ b/src/app/thrift-services/damsel/payment-processing.service.ts @@ -4,8 +4,7 @@ import { Observable, timer } from 'rxjs'; import { first, map, share, switchMap } from 'rxjs/operators'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; -import { createDamselInstance, damselInstanceToObject } from './create-damsel-instance'; +import { ThriftService } from '../services/thrift/thrift-service'; import { InvoiceID, InvoicePaymentChargeback, @@ -29,6 +28,7 @@ import { InvoiceRepairScenario as InvoiceRepairScenarioObject, UserInfo as UserInfoObject, } from './gen-nodejs/payment_processing_types'; +import { createDamselInstance, damselInstanceToObject } from './utils/create-damsel-instance'; @Injectable() export class PaymentProcessingService extends ThriftService { diff --git a/src/app/thrift-services/damsel/domain-typed-manager.ts b/src/app/thrift-services/damsel/provider.service.ts similarity index 65% rename from src/app/thrift-services/damsel/domain-typed-manager.ts rename to src/app/thrift-services/damsel/provider.service.ts index 218f6586..cb7bb251 100644 --- a/src/app/thrift-services/damsel/domain-typed-manager.ts +++ b/src/app/thrift-services/damsel/provider.service.ts @@ -5,16 +5,11 @@ import { map, switchMap, take } from 'rxjs/operators'; import { DomainCacheService } from './domain-cache.service'; import { ProviderObject } from './gen-model/domain'; import { Version } from './gen-model/domain_config'; -import { - AddDecisionToProvider, - addDecisionToProviderCommit, - CreateTerminalParams, - getCreateTerminalCommit, -} from './operations'; +import { AddDecisionToProvider, addDecisionToProviderCommit } from './operations'; import { findDomainObject } from './operations/utils'; @Injectable() -export class DomainTypedManager { +export class ProviderService { constructor(private domainCacheService: DomainCacheService) {} getProviderFromParams( @@ -40,20 +35,4 @@ export class DomainTypedManager { ) ); } - - /** - * @deprecated select in separate service - */ - createTerminal(params: CreateTerminalParams): Observable { - let newTerminalID = null; - return this.domainCacheService.getObjects('terminal').pipe( - take(1), - switchMap((terminalObjects) => { - const { commit, id } = getCreateTerminalCommit(terminalObjects, params); - newTerminalID = id; - return this.domainCacheService.commit(commit); - }), - map(() => newTerminalID) - ); - } } diff --git a/src/app/thrift-services/damsel/routing-rules/index.ts b/src/app/thrift-services/damsel/routing-rules/index.ts new file mode 100644 index 00000000..6e5d3487 --- /dev/null +++ b/src/app/thrift-services/damsel/routing-rules/index.ts @@ -0,0 +1,2 @@ +export * from './routing-rules.module'; +export * from './routing-rules.service'; diff --git a/src/app/thrift-services/damsel/routing-rules/routing-rules.module.ts b/src/app/thrift-services/damsel/routing-rules/routing-rules.module.ts new file mode 100644 index 00000000..43f4c5df --- /dev/null +++ b/src/app/thrift-services/damsel/routing-rules/routing-rules.module.ts @@ -0,0 +1,8 @@ +import { NgModule } from '@angular/core'; + +import { RoutingRulesService } from './routing-rules.service'; + +@NgModule({ + providers: [RoutingRulesService], +}) +export class RoutingRulesModule {} diff --git a/src/app/thrift-services/damsel/payment-routing-rules.service.ts b/src/app/thrift-services/damsel/routing-rules/routing-rules.service.ts similarity index 77% rename from src/app/thrift-services/damsel/payment-routing-rules.service.ts rename to src/app/thrift-services/damsel/routing-rules/routing-rules.service.ts index 0baa3cbb..bb69737d 100644 --- a/src/app/thrift-services/damsel/payment-routing-rules.service.ts +++ b/src/app/thrift-services/damsel/routing-rules/routing-rules.service.ts @@ -1,19 +1,21 @@ import { Injectable } from '@angular/core'; import cloneDeep from 'lodash-es/cloneDeep'; import { combineLatest, Observable } from 'rxjs'; -import { map, shareReplay, switchMap, take } from 'rxjs/operators'; +import { map, pluck, shareReplay, switchMap, take } from 'rxjs/operators'; -import { DomainCacheService } from './domain-cache.service'; +import { createNextId } from '../../utils/create-next-id'; +import { DomainCacheService } from '../domain-cache.service'; import { Predicate, RoutingCandidate, RoutingDelegate, RoutingRulesObject, -} from './gen-model/domain'; -import { Version } from './gen-model/domain_config'; +} from '../gen-model/domain'; +import { Version } from '../gen-model/domain_config'; +import { getDelegate } from './utils/get-delegate'; @Injectable() -export class PaymentRoutingRulesService { +export class RoutingRulesService { constructor(private domainService: DomainCacheService) {} rulesets$: Observable = this.domainService @@ -25,7 +27,7 @@ export class PaymentRoutingRulesService { nextRefID$ = this.rulesets$.pipe( map((rulesets) => rulesets.map(({ ref }) => ref.id)), - map((ids) => Math.max(...ids) + 1) + map(createNextId) ); getRuleset(refID: number): Observable { @@ -263,19 +265,16 @@ export class PaymentRoutingRulesService { deleteDelegate({ mainRulesetRefID, - rulesetRefID, + delegateIdx, }: { mainRulesetRefID: number; - rulesetRefID: number; + delegateIdx: number; }): Observable { return this.getRuleset(mainRulesetRefID).pipe( take(1), switchMap((mainRuleset) => { const newMainPaymentRoutingRuleset = cloneDeep(mainRuleset); - newMainPaymentRoutingRuleset.data.decisions.delegates.splice( - this.getDelegateIdx(mainRuleset, rulesetRefID), - 1 - ); + newMainPaymentRoutingRuleset.data.decisions.delegates.splice(delegateIdx, 1); return this.domainService.commit({ ops: [ { @@ -290,15 +289,15 @@ export class PaymentRoutingRulesService { ); } - changeDelegateRuleset({ + changeMainRuleset({ previousMainRulesetRefID, mainRulesetRefID, - rulesetID, + delegateIdx, mainDelegateDescription, }: { previousMainRulesetRefID: number; mainRulesetRefID: number; - rulesetID: number; + delegateIdx: number; mainDelegateDescription?: string; }): Observable { return combineLatest([ @@ -309,7 +308,7 @@ export class PaymentRoutingRulesService { switchMap(([mainRuleset, previousMainRuleset]) => { const newPreviousMainRuleset = cloneDeep(previousMainRuleset); const [delegate] = newPreviousMainRuleset.data.decisions.delegates.splice( - this.getDelegateIdx(previousMainRuleset, rulesetID), + delegateIdx, 1 ); const newMainPaymentRoutingRuleset = cloneDeep(mainRuleset); @@ -340,9 +339,84 @@ export class PaymentRoutingRulesService { ); } - private getDelegateIdx(ruleset: RoutingRulesObject, delegateRulesetRefId: number) { - return ruleset.data.decisions.delegates.findIndex( - (d) => d?.ruleset?.id === delegateRulesetRefId + changeDelegateRuleset({ + mainRulesetRefID, + delegateIdx, + newDelegateRulesetRefID, + description, + }: { + mainRulesetRefID: number; + delegateIdx: number; + newDelegateRulesetRefID: number; + description?: string; + }): Observable { + return this.getRuleset(mainRulesetRefID).pipe( + take(1), + switchMap((mainRuleset) => { + const newMainRuleset = cloneDeep(mainRuleset); + newMainRuleset.data.decisions.delegates[ + delegateIdx + ].ruleset.id = newDelegateRulesetRefID; + if (description !== undefined) { + newMainRuleset.data.decisions.delegates[delegateIdx].description = description; + } + return this.domainService.commit({ + ops: [ + { + update: { + old_object: { routing_rules: mainRuleset }, + new_object: { routing_rules: newMainRuleset }, + }, + }, + ], + }); + }) + ); + } + + cloneDelegateRuleset({ + mainRulesetRefID, + delegateIdx, + }: { + mainRulesetRefID: number; + delegateIdx: number; + }): Observable { + return combineLatest([ + this.getRuleset(mainRulesetRefID), + this.getRuleset(mainRulesetRefID).pipe( + switchMap((r) => this.getRuleset(getDelegate(r, delegateIdx).ruleset.id)) + ), + this.nextRefID$, + ]).pipe( + take(1), + switchMap(([mainRuleset, delegateRuleset, nextRefID]) => { + const newMainRuleset = cloneDeep(mainRuleset); + getDelegate(newMainRuleset, delegateIdx).ruleset.id = nextRefID; + const newDelegateRuleset = cloneDeep(delegateRuleset); + newDelegateRuleset.ref.id = nextRefID; + return this.domainService.sequenseCommits([ + { + ops: [ + { + insert: { + object: { routing_rules: newDelegateRuleset }, + }, + }, + ], + }, + { + ops: [ + { + update: { + old_object: { routing_rules: mainRuleset }, + new_object: { routing_rules: newMainRuleset }, + }, + }, + ], + }, + ]); + }), + pluck('1') ); } diff --git a/src/app/thrift-services/damsel/routing-rules/utils/get-delegate.ts b/src/app/thrift-services/damsel/routing-rules/utils/get-delegate.ts new file mode 100644 index 00000000..4922f744 --- /dev/null +++ b/src/app/thrift-services/damsel/routing-rules/utils/get-delegate.ts @@ -0,0 +1,8 @@ +import { RoutingDelegate, RoutingRulesObject } from '../../gen-model/domain'; + +export function getDelegate( + ruleset: RoutingRulesObject, + delegateIdx: number +): RoutingDelegate | undefined { + return ruleset?.data?.decisions?.delegates?.[delegateIdx]; +} diff --git a/src/app/thrift-services/damsel/services/edit-terminal-decision-property-for-shop.service.ts b/src/app/thrift-services/damsel/services/edit-terminal-decision-property-for-shop.service.ts index c57a73ed..be091f4f 100644 --- a/src/app/thrift-services/damsel/services/edit-terminal-decision-property-for-shop.service.ts +++ b/src/app/thrift-services/damsel/services/edit-terminal-decision-property-for-shop.service.ts @@ -5,9 +5,9 @@ import { EMPTY, merge, Subject } from 'rxjs'; import { catchError, shareReplay, switchMap } from 'rxjs/operators'; import { DomainCacheService } from '../domain-cache.service'; -import { DomainTypedManager } from '../domain-typed-manager'; import { editTerminalDecisionPropertyForShopCommit } from '../operations/edit-terminal-decision-property-for-shop-commit'; import { EditTerminalDecisionPropertyParams } from '../operations/edit-terminal-decision-property-params'; +import { ProviderService } from '../provider.service'; @Injectable() export class EditTerminalDecisionPropertyForShopService { @@ -17,9 +17,7 @@ export class EditTerminalDecisionPropertyForShopService { edited$ = this.editProperty$.pipe( switchMap((params) => - this.domainTypedManager.getProviderFromParams( - params - ) + this.providerService.getProviderFromParams(params) ), switchMap(([params, provider]) => { return this.domainCacheService @@ -39,7 +37,7 @@ export class EditTerminalDecisionPropertyForShopService { constructor( private domainCacheService: DomainCacheService, private snackBar: MatSnackBar, - private domainTypedManager: DomainTypedManager + private providerService: ProviderService ) { this.error$.subscribe(() => { this.snackBar.open('An error occurred while editing providerObject'); diff --git a/src/app/thrift-services/damsel/terminal/index.ts b/src/app/thrift-services/damsel/terminal/index.ts new file mode 100644 index 00000000..1c894770 --- /dev/null +++ b/src/app/thrift-services/damsel/terminal/index.ts @@ -0,0 +1,2 @@ +export * from './terminal.service'; +export * from './terminal.module'; diff --git a/src/app/thrift-services/damsel/terminal/terminal.module.ts b/src/app/thrift-services/damsel/terminal/terminal.module.ts new file mode 100644 index 00000000..4928b8e8 --- /dev/null +++ b/src/app/thrift-services/damsel/terminal/terminal.module.ts @@ -0,0 +1,8 @@ +import { NgModule } from '@angular/core'; + +import { TerminalService } from './terminal.service'; + +@NgModule({ + providers: [TerminalService], +}) +export class TerminalModule {} diff --git a/src/app/thrift-services/damsel/terminal/terminal.service.spec.ts b/src/app/thrift-services/damsel/terminal/terminal.service.spec.ts new file mode 100644 index 00000000..7ec4348d --- /dev/null +++ b/src/app/thrift-services/damsel/terminal/terminal.service.spec.ts @@ -0,0 +1,20 @@ +import { TestBed } from '@angular/core/testing'; + +import { TerminalService } from './terminal.service'; + +describe('TerminalService', () => { + let service: TerminalService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [], + providers: [TerminalService], + }); + + service = TestBed.inject(TerminalService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/thrift-services/damsel/terminal/terminal.service.ts b/src/app/thrift-services/damsel/terminal/terminal.service.ts new file mode 100644 index 00000000..2f46ad0d --- /dev/null +++ b/src/app/thrift-services/damsel/terminal/terminal.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { mapTo, switchMap, take } from 'rxjs/operators'; + +import { DomainCacheService } from '../domain-cache.service'; +import { CreateTerminalParams, getCreateTerminalCommit } from '../operations'; + +@Injectable() +export class TerminalService { + constructor(private domainCacheService: DomainCacheService) {} + + createTerminal(params: CreateTerminalParams): Observable { + return this.domainCacheService.getObjects('terminal').pipe( + take(1), + switchMap((terminalObjects) => { + const { commit, id } = getCreateTerminalCommit(terminalObjects, params); + return this.domainCacheService.commit(commit).pipe(mapTo(id)); + }) + ); + } +} diff --git a/src/app/thrift-services/damsel/utils/create-damsel-instance.ts b/src/app/thrift-services/damsel/utils/create-damsel-instance.ts new file mode 100644 index 00000000..5f217138 --- /dev/null +++ b/src/app/thrift-services/damsel/utils/create-damsel-instance.ts @@ -0,0 +1,24 @@ +import metadata from '../../../../assets/meta-damsel.json'; +import { createThriftInstanceUtils } from '../../utils/thrift-instance'; +import * as base from '../gen-nodejs/base_types'; +import * as claim_management from '../gen-nodejs/claim_management_types'; +import * as domain_config from '../gen-nodejs/domain_config_types'; +import * as domain from '../gen-nodejs/domain_types'; +import * as geo_ip from '../gen-nodejs/geo_ip_types'; +import * as merch_stat from '../gen-nodejs/merch_stat_types'; +import * as payment_processing from '../gen-nodejs/payment_processing_types'; + +const namespaces = { + base, + domain, + domain_config, + claim_management, + geo_ip, + merch_stat, + payment_processing, +}; + +export const { + createThriftInstance: createDamselInstance, + thriftInstanceToObject: damselInstanceToObject, +} = createThriftInstanceUtils(metadata, namespaces); diff --git a/src/app/thrift-services/deanonimus/deanonimus.service.ts b/src/app/thrift-services/deanonimus/deanonimus.service.ts index 8eb34ce4..81cc49bb 100644 --- a/src/app/thrift-services/deanonimus/deanonimus.service.ts +++ b/src/app/thrift-services/deanonimus/deanonimus.service.ts @@ -2,7 +2,7 @@ import { Injectable, NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { SearchHit } from './gen-model/deanonimus'; import * as Deanonimus from './gen-nodejs/Deanonimus'; diff --git a/src/app/thrift-services/file-storage/file-storage.service.ts b/src/app/thrift-services/file-storage/file-storage.service.ts index 375911bf..1ad0aad4 100644 --- a/src/app/thrift-services/file-storage/file-storage.service.ts +++ b/src/app/thrift-services/file-storage/file-storage.service.ts @@ -2,7 +2,7 @@ import { Injectable, NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { Timestamp } from './gen-model/base'; import { FileData, diff --git a/src/app/thrift-services/fistful/fistful-admin.service.ts b/src/app/thrift-services/fistful/fistful-admin.service.ts index 4320655a..6552a354 100644 --- a/src/app/thrift-services/fistful/fistful-admin.service.ts +++ b/src/app/thrift-services/fistful/fistful-admin.service.ts @@ -2,7 +2,7 @@ import { Injectable, NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { DepositParams } from './gen-model/fistful_admin'; import * as FistfulAdmin from './gen-nodejs/FistfulAdmin'; import { DepositParams as DepositParamsObject } from './gen-nodejs/fistful_admin_types'; diff --git a/src/app/thrift-services/fistful/fistful-stat.service.ts b/src/app/thrift-services/fistful/fistful-stat.service.ts index 8fdd81e4..4e1144cb 100644 --- a/src/app/thrift-services/fistful/fistful-stat.service.ts +++ b/src/app/thrift-services/fistful/fistful-stat.service.ts @@ -6,7 +6,7 @@ import { map } from 'rxjs/operators'; import { SearchFormParams } from '../../deposits/search-form/search-form-params'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; import { QueryDSL } from '../../query-dsl'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { StatDeposit, StatRequest } from './gen-model/fistful_stat'; import * as FistfulStatistics from './gen-nodejs/FistfulStatistics'; import { StatRequest as ThriftStatRequest } from './gen-nodejs/fistful_stat_types'; diff --git a/src/app/thrift-services/fistful/repairer.service.ts b/src/app/thrift-services/fistful/repairer.service.ts index f117dd18..0660d105 100644 --- a/src/app/thrift-services/fistful/repairer.service.ts +++ b/src/app/thrift-services/fistful/repairer.service.ts @@ -2,7 +2,7 @@ import { Injectable, NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { RepairScenario, SessionID } from './gen-model/withdrawal_session'; import * as Repairer from './gen-nodejs/Repairer'; import { RepairScenario as RepairScenarioObject } from './gen-nodejs/withdrawal_session_types'; diff --git a/src/app/thrift-services/index.ts b/src/app/thrift-services/index.ts index 1800f4aa..34b4e63c 100644 --- a/src/app/thrift-services/index.ts +++ b/src/app/thrift-services/index.ts @@ -1,6 +1,6 @@ -export * from './thrift-service'; export * from './filters'; -export * from './thrift-instance'; +export * from './utils/thrift-instance'; +export * from './utils/get-thrift-instance'; export * from './ank'; export * from './file-storage'; export * from './messages'; diff --git a/src/app/thrift-services/machinegun/automaton.service.ts b/src/app/thrift-services/machinegun/automaton.service.ts index 71e4c614..e2a5269f 100644 --- a/src/app/thrift-services/machinegun/automaton.service.ts +++ b/src/app/thrift-services/machinegun/automaton.service.ts @@ -2,7 +2,7 @@ import { Injectable, NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { Namespace } from './gen-model/base'; import { Machine, MachineDescriptor, Reference } from './gen-model/state_processing'; import * as Automaton from './gen-nodejs/Automaton'; diff --git a/src/app/thrift-services/messages/messages.service.ts b/src/app/thrift-services/messages/messages.service.ts index b0698b5b..1649bf28 100644 --- a/src/app/thrift-services/messages/messages.service.ts +++ b/src/app/thrift-services/messages/messages.service.ts @@ -2,7 +2,7 @@ import { Injectable, NgZone } from '@angular/core'; import { Observable } from 'rxjs'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { Conversation, ConversationFilter, diff --git a/src/app/thrift-services/thrift-service.ts b/src/app/thrift-services/services/thrift/thrift-service.ts similarity index 97% rename from src/app/thrift-services/thrift-service.ts rename to src/app/thrift-services/services/thrift/thrift-service.ts index e04a1e4d..2f181166 100644 --- a/src/app/thrift-services/thrift-service.ts +++ b/src/app/thrift-services/services/thrift/thrift-service.ts @@ -3,7 +3,7 @@ import { Observable } from 'rxjs'; import { timeout } from 'rxjs/operators'; import connectClient from 'woody_js'; -import { KeycloakTokenInfoService } from '../keycloak-token-info.service'; +import { KeycloakTokenInfoService } from '../../../keycloak-token-info.service'; type Exception = { name: N; diff --git a/src/app/thrift-services/skipper/chargebacks.service.ts b/src/app/thrift-services/skipper/chargebacks.service.ts index c7e8adfc..3e3c9f92 100644 --- a/src/app/thrift-services/skipper/chargebacks.service.ts +++ b/src/app/thrift-services/skipper/chargebacks.service.ts @@ -3,7 +3,7 @@ import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { KeycloakTokenInfoService } from '../../keycloak-token-info.service'; -import { ThriftService } from '../thrift-service'; +import { ThriftService } from '../services/thrift/thrift-service'; import { ID } from './gen-model/base'; import { ChargebackData, ChargebackEvent, ChargebackFilter } from './gen-model/skipper'; import * as Skipper from './gen-nodejs/Skipper'; diff --git a/src/app/thrift-services/skipper/skipper-instance-utils.ts b/src/app/thrift-services/skipper/skipper-instance-utils.ts index c6fc90a6..883668a7 100644 --- a/src/app/thrift-services/skipper/skipper-instance-utils.ts +++ b/src/app/thrift-services/skipper/skipper-instance-utils.ts @@ -1,5 +1,5 @@ import metadata from '../../../assets/meta-skipper.json'; -import { createThriftInstanceUtils } from '../thrift-instance'; +import { createThriftInstanceUtils } from '../utils/thrift-instance'; import * as base from './gen-nodejs/base_types'; import * as chargeback from './gen-nodejs/chargeback_types'; import * as skipper from './gen-nodejs/skipper_types'; diff --git a/src/app/thrift-services/utils/create-next-id.ts b/src/app/thrift-services/utils/create-next-id.ts new file mode 100644 index 00000000..9553dc2f --- /dev/null +++ b/src/app/thrift-services/utils/create-next-id.ts @@ -0,0 +1,5 @@ +// TODO: numeric overflow, need logic to use the freed +// TODO: return Int64 +export function createNextId(ids: number[]) { + return Math.max(...ids) + 1; +} diff --git a/src/app/thrift-services/damsel/get-thrift-instance.ts b/src/app/thrift-services/utils/get-thrift-instance.ts similarity index 66% rename from src/app/thrift-services/damsel/get-thrift-instance.ts rename to src/app/thrift-services/utils/get-thrift-instance.ts index 4042371c..bbeffa43 100644 --- a/src/app/thrift-services/damsel/get-thrift-instance.ts +++ b/src/app/thrift-services/utils/get-thrift-instance.ts @@ -1,6 +1,6 @@ -import * as BaseTypes from './gen-nodejs/base_types'; -import * as DomainConfigTypes from './gen-nodejs/domain_config_types'; -import * as DomainTypes from './gen-nodejs/domain_types'; +import * as BaseTypes from '../damsel/gen-nodejs/base_types'; +import * as DomainConfigTypes from '../damsel/gen-nodejs/domain_config_types'; +import * as DomainTypes from '../damsel/gen-nodejs/domain_types'; export const SupportedNamespaces = { base: BaseTypes, diff --git a/src/app/thrift-services/thrift-instance/create-thrift-instance-utils.ts b/src/app/thrift-services/utils/thrift-instance/create-thrift-instance-utils.ts similarity index 100% rename from src/app/thrift-services/thrift-instance/create-thrift-instance-utils.ts rename to src/app/thrift-services/utils/thrift-instance/create-thrift-instance-utils.ts diff --git a/src/app/thrift-services/thrift-instance/create-thrift-instance.ts b/src/app/thrift-services/utils/thrift-instance/create-thrift-instance.ts similarity index 100% rename from src/app/thrift-services/thrift-instance/create-thrift-instance.ts rename to src/app/thrift-services/utils/thrift-instance/create-thrift-instance.ts diff --git a/src/app/thrift-services/thrift-instance/index.ts b/src/app/thrift-services/utils/thrift-instance/index.ts similarity index 100% rename from src/app/thrift-services/thrift-instance/index.ts rename to src/app/thrift-services/utils/thrift-instance/index.ts diff --git a/src/app/thrift-services/thrift-instance/namespace-type.ts b/src/app/thrift-services/utils/thrift-instance/namespace-type.ts similarity index 100% rename from src/app/thrift-services/thrift-instance/namespace-type.ts rename to src/app/thrift-services/utils/thrift-instance/namespace-type.ts diff --git a/src/app/thrift-services/thrift-instance/object-to-json.ts b/src/app/thrift-services/utils/thrift-instance/object-to-json.ts similarity index 100% rename from src/app/thrift-services/thrift-instance/object-to-json.ts rename to src/app/thrift-services/utils/thrift-instance/object-to-json.ts diff --git a/src/app/thrift-services/thrift-instance/thrift-instance-to-object.ts b/src/app/thrift-services/utils/thrift-instance/thrift-instance-to-object.ts similarity index 100% rename from src/app/thrift-services/thrift-instance/thrift-instance-to-object.ts rename to src/app/thrift-services/utils/thrift-instance/thrift-instance-to-object.ts diff --git a/src/app/tokens.ts b/src/app/tokens.ts new file mode 100644 index 00000000..36962b6c --- /dev/null +++ b/src/app/tokens.ts @@ -0,0 +1,24 @@ +import { InjectionToken } from '@angular/core'; +import { MatDialogConfig } from '@angular/material/dialog'; + +export const LAYOUT_GAP = new InjectionToken('layoutGap'); + +export const SEARCH_LIMIT = new InjectionToken('searchLimit'); +export const DEFAULT_SEARCH_LIMIT = 10; + +export type DialogConfig = { + small: MatDialogConfig; + medium: MatDialogConfig; + large: MatDialogConfig; +}; +export const DIALOG_CONFIG = new InjectionToken('dialogConfig'); +const baseConfig: MatDialogConfig = { + maxHeight: '90vh', + disableClose: true, + autoFocus: false, +}; +export const DEFAULT_DIALOG_CONFIG: DialogConfig = { + small: { ...baseConfig, width: '360px' }, + medium: { ...baseConfig, width: '552px' }, + large: { ...baseConfig, width: '648px' }, +}; diff --git a/src/components/confirm-action-dialog/confirm-action-dialog.component.html b/src/components/confirm-action-dialog/confirm-action-dialog.component.html index 054ad649..b3d48320 100644 --- a/src/components/confirm-action-dialog/confirm-action-dialog.component.html +++ b/src/components/confirm-action-dialog/confirm-action-dialog.component.html @@ -1,4 +1,4 @@ -

{{ data.title ? data.title : 'Confirm this action' }}

+

{{ title }}

, - @Inject(MAT_DIALOG_DATA) - public data: { title?: string } + @Inject(MAT_DIALOG_DATA) public data: { title?: string } ) {} + get title() { + return this.data?.title ?? 'Confirm this action'; + } + cancel() { this.dialogRef.close('cancel'); }