diff --git a/src/app/sections/payment-section/integrations/integrations.component.scss b/src/app/sections/payment-section/integrations/integrations.component.scss index 32ab2153..861a0d2b 100644 --- a/src/app/sections/payment-section/integrations/integrations.component.scss +++ b/src/app/sections/payment-section/integrations/integrations.component.scss @@ -1,4 +1,4 @@ .dsh-integrations { max-width: 720px; - margin: auto; + margin: auto auto 20px; } diff --git a/src/app/sections/payment-section/integrations/webhooks/receive-webhooks.service.ts b/src/app/sections/payment-section/integrations/webhooks/receive-webhooks.service.ts index b593e8f0..6a6d5ca3 100644 --- a/src/app/sections/payment-section/integrations/webhooks/receive-webhooks.service.ts +++ b/src/app/sections/payment-section/integrations/webhooks/receive-webhooks.service.ts @@ -1,43 +1,71 @@ import { Injectable } from '@angular/core'; import { MatSnackBar } from '@angular/material/snack-bar'; +import { ActivatedRoute, Router } from '@angular/router'; import { TranslocoService } from '@ngneat/transloco'; import sortBy from 'lodash.sortby'; -import { BehaviorSubject, Observable, of, Subject } from 'rxjs'; -import { catchError, filter, map, shareReplay, switchMap } from 'rxjs/operators'; +import { BehaviorSubject, combineLatest, Observable, of, Subject } from 'rxjs'; +import { catchError, filter, first, map, pluck, shareReplay, switchMap } from 'rxjs/operators'; import { Webhook } from '../../../../api-codegen/capi/swagger-codegen'; import { WebhooksService } from '../../../../api/webhooks'; import { booleanDebounceTime, progress, SHARE_REPLAY_CONF } from '../../../../custom-operators'; +const WEBHOOK_LIMIT = 10; + @Injectable() export class ReceiveWebhooksService { - private webhooksState$ = new BehaviorSubject(null); - private receiveWebhooks$ = new Subject(); + private webhooksOffset$: BehaviorSubject = new BehaviorSubject(WEBHOOK_LIMIT); + private webhooksState$: BehaviorSubject = new BehaviorSubject(null); + private receiveWebhooks$: Subject = new Subject(); webhooks$: Observable = this.webhooksState$.pipe( filter(s => !!s), map(w => sortBy(w, i => !i.active)), + switchMap(webhooks => combineLatest([this.webhooksOffset$, of(webhooks)])), + map(([offset, webhooks]) => webhooks.slice(0, offset)), shareReplay(SHARE_REPLAY_CONF) ); - webhooksReceived$ = this.webhooks$.pipe( - map(s => !!s), - shareReplay(SHARE_REPLAY_CONF) - ); - - isLoading$ = progress(this.receiveWebhooks$, this.webhooksState$).pipe( + isLoading$: Observable = progress(this.receiveWebhooks$, this.webhooks$).pipe( booleanDebounceTime(), shareReplay(SHARE_REPLAY_CONF) ); + hasMore$: Observable = combineLatest([this.webhooksState$, this.webhooksOffset$]).pipe( + map(([webhooks, offset]) => webhooks?.length > offset), + shareReplay(SHARE_REPLAY_CONF) + ); + constructor( private webhooksService: WebhooksService, private snackBar: MatSnackBar, - private transloco: TranslocoService + private transloco: TranslocoService, + private route: ActivatedRoute, + private router: Router ) { + this.isLoading$.subscribe(); + this.route.queryParams + .pipe( + first(), + pluck('offset'), + filter(l => !!l), + map(offset => parseInt(offset, 10)) + ) + .subscribe(offset => { + this.webhooksOffset$.next(offset); + }); + + this.webhooksOffset$.subscribe(offset => { + this.router.navigate([location.pathname], { + queryParams: { + offset + } + }); + }); + this.receiveWebhooks$ .pipe( - switchMap(_ => + switchMap(() => this.webhooksService.getWebhooks().pipe( catchError(err => { console.error(err); @@ -47,10 +75,16 @@ export class ReceiveWebhooksService { ) ) ) - .subscribe(webhooks => this.webhooksState$.next(webhooks)); + .subscribe(webhooks => { + this.webhooksState$.next(webhooks); + }); } receiveWebhooks() { this.receiveWebhooks$.next(); } + + getMoreWebhooks() { + this.webhooksOffset$.next(this.webhooksOffset$.value + WEBHOOK_LIMIT); + } } diff --git a/src/app/sections/payment-section/integrations/webhooks/webhook-panel/webhook-panel.component.ts b/src/app/sections/payment-section/integrations/webhooks/webhook-panel/webhook-panel.component.ts index 003fd000..99664002 100644 --- a/src/app/sections/payment-section/integrations/webhooks/webhook-panel/webhook-panel.component.ts +++ b/src/app/sections/payment-section/integrations/webhooks/webhook-panel/webhook-panel.component.ts @@ -1,4 +1,4 @@ -import { Component, Inject, Input, OnChanges, SimpleChanges } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Inject, Input, OnChanges, SimpleChanges } from '@angular/core'; import isEqual from 'lodash.isequal'; import { pluck } from 'rxjs/operators'; @@ -11,7 +11,8 @@ type InvoicesEventTypesEnum = InvoicesTopic.EventTypesEnum; @Component({ selector: 'dsh-webhook-panel', templateUrl: 'webhook-panel.component.html', - providers: [WebhookPanelService] + providers: [WebhookPanelService], + changeDetection: ChangeDetectionStrategy.OnPush }) export class WebhookPanelComponent implements OnChanges { @Input() diff --git a/src/app/sections/payment-section/integrations/webhooks/webhooks.component.html b/src/app/sections/payment-section/integrations/webhooks/webhooks.component.html index 9d83960d..2cba759c 100644 --- a/src/app/sections/payment-section/integrations/webhooks/webhooks.component.html +++ b/src/app/sections/payment-section/integrations/webhooks/webhooks.component.html @@ -16,12 +16,10 @@ - +
+
diff --git a/src/app/sections/payment-section/integrations/webhooks/webhooks.component.ts b/src/app/sections/payment-section/integrations/webhooks/webhooks.component.ts index f77fb1db..1ee0dc08 100644 --- a/src/app/sections/payment-section/integrations/webhooks/webhooks.component.ts +++ b/src/app/sections/payment-section/integrations/webhooks/webhooks.component.ts @@ -5,12 +5,13 @@ import { CreateWebhookService } from './create-webhook.service'; import { ReceiveWebhooksService } from './receive-webhooks.service'; @Component({ - templateUrl: 'webhooks.component.html' + templateUrl: 'webhooks.component.html', + providers: [ReceiveWebhooksService, CreateWebhookService] }) export class WebhooksComponent implements OnInit { webhooks$ = this.receiveWebhooksService.webhooks$; isLoading$ = this.receiveWebhooksService.isLoading$; - webhooksReceived$ = this.receiveWebhooksService.webhooksReceived$; + hasMore$ = this.receiveWebhooksService.hasMore$; constructor( private receiveWebhooksService: ReceiveWebhooksService, @@ -25,4 +26,8 @@ export class WebhooksComponent implements OnInit { createWebhook() { this.createWebhookService.createWebhook(); } + + getMoreWebhooks() { + this.receiveWebhooksService.getMoreWebhooks(); + } } diff --git a/src/app/sections/payment-section/integrations/webhooks/webhooks.module.ts b/src/app/sections/payment-section/integrations/webhooks/webhooks.module.ts index 7ef0cc7e..d26f3e78 100644 --- a/src/app/sections/payment-section/integrations/webhooks/webhooks.module.ts +++ b/src/app/sections/payment-section/integrations/webhooks/webhooks.module.ts @@ -12,12 +12,10 @@ import { TranslocoModule } from '@ngneat/transloco'; import { ButtonModule } from '@dsh/components/buttons'; import { EmptySearchResultModule } from '@dsh/components/empty-search-result'; import { SpinnerModule } from '@dsh/components/indicators'; +import { ShowMorePanelModule } from '@dsh/components/show-more-panel'; -import { ShopService } from '../../../../api/shop'; import { WebhooksModule as ApiWebhooksModule } from '../../../../api/webhooks'; -import { CreateWebhookService } from './create-webhook.service'; import { CreateWebhookComponent } from './create-webhook/create-webhook.component'; -import { ReceiveWebhooksService } from './receive-webhooks.service'; import { WebhookPanelModule } from './webhook-panel/webhook-panel.module'; import { WebhooksRoutingModule } from './webhooks-routing.module'; import { WebhooksComponent } from './webhooks.component'; @@ -38,10 +36,10 @@ import { WebhooksComponent } from './webhooks.component'; TranslocoModule, WebhookPanelModule, SpinnerModule, - EmptySearchResultModule + EmptySearchResultModule, + ShowMorePanelModule ], declarations: [WebhooksComponent, CreateWebhookComponent], - entryComponents: [CreateWebhookComponent], - providers: [ReceiveWebhooksService, CreateWebhookService, ShopService] + entryComponents: [CreateWebhookComponent] }) export class WebhooksModule {} diff --git a/src/app/sections/payment-section/operations/payments/search-form/search-form.service.ts b/src/app/sections/payment-section/operations/payments/search-form/search-form.service.ts index ea5cffa3..3c8a1c2c 100644 --- a/src/app/sections/payment-section/operations/payments/search-form/search-form.service.ts +++ b/src/app/sections/payment-section/operations/payments/search-form/search-form.service.ts @@ -66,7 +66,7 @@ export class SearchFormService { } private initForm(defaultLimit = 20): FormGroup { - const form = this.fb.group({ + return this.fb.group({ date: { begin: moment().startOf('month'), end: moment().endOf('month') @@ -88,6 +88,5 @@ export class SearchFormService { paymentAmountTo: '', rrn: '' }); - return form; } } diff --git a/src/app/sections/payment-section/payouts/payouts.component.html b/src/app/sections/payment-section/payouts/payouts.component.html index e7b3329f..e9f50f5e 100644 --- a/src/app/sections/payment-section/payouts/payouts.component.html +++ b/src/app/sections/payment-section/payouts/payouts.component.html @@ -12,11 +12,8 @@ - - - + +
{{ t.emptySearchResult }} diff --git a/src/app/sections/payment-section/payouts/payouts.module.ts b/src/app/sections/payment-section/payouts/payouts.module.ts index fe309ecb..5b69601b 100644 --- a/src/app/sections/payment-section/payouts/payouts.module.ts +++ b/src/app/sections/payment-section/payouts/payouts.module.ts @@ -13,6 +13,7 @@ import { RangeDatepickerModule } from '@dsh/components/form-controls'; import { SpinnerModule } from '@dsh/components/indicators'; import { LayoutModule } from '@dsh/components/layout'; import { ScrollUpModule } from '@dsh/components/navigation'; +import { ShowMorePanelModule } from '@dsh/components/show-more-panel'; import { SearchModule } from '../../../api'; import { PayoutPanelModule } from './payouts-panels-list'; @@ -39,7 +40,8 @@ import { SearchFormComponent } from './search-form'; MatInputModule, SpinnerModule, ScrollUpModule, - RangeDatepickerModule + RangeDatepickerModule, + ShowMorePanelModule ], declarations: [PayoutsComponent, SearchFormComponent], exports: [PayoutsComponent] diff --git a/src/components/show-more-panel/index.ts b/src/components/show-more-panel/index.ts new file mode 100644 index 00000000..c022e8d9 --- /dev/null +++ b/src/components/show-more-panel/index.ts @@ -0,0 +1 @@ +export * from './show-more-panel.module'; diff --git a/src/components/show-more-panel/show-more-panel.component.html b/src/components/show-more-panel/show-more-panel.component.html new file mode 100644 index 00000000..d82fa6a0 --- /dev/null +++ b/src/components/show-more-panel/show-more-panel.component.html @@ -0,0 +1,5 @@ + + + diff --git a/src/components/show-more-panel/show-more-panel.component.scss b/src/components/show-more-panel/show-more-panel.component.scss new file mode 100644 index 00000000..4fc0778f --- /dev/null +++ b/src/components/show-more-panel/show-more-panel.component.scss @@ -0,0 +1,3 @@ +.dsh-show-more-panel { + padding: 10px 20px; +} diff --git a/src/components/show-more-panel/show-more-panel.component.ts b/src/components/show-more-panel/show-more-panel.component.ts new file mode 100644 index 00000000..432ea34b --- /dev/null +++ b/src/components/show-more-panel/show-more-panel.component.ts @@ -0,0 +1,18 @@ +import { Component, EventEmitter, Input, Output } from '@angular/core'; + +@Component({ + selector: 'dsh-show-more-panel', + templateUrl: 'show-more-panel.component.html', + styleUrls: ['show-more-panel.component.scss'] +}) +export class ShowMorePanelComponent { + @Input() + isLoading = false; + + @Output() + showMore: EventEmitter = new EventEmitter(); + + getMore() { + this.showMore.emit(); + } +} diff --git a/src/components/show-more-panel/show-more-panel.module.ts b/src/components/show-more-panel/show-more-panel.module.ts new file mode 100644 index 00000000..71aee005 --- /dev/null +++ b/src/components/show-more-panel/show-more-panel.module.ts @@ -0,0 +1,15 @@ +import { NgModule } from '@angular/core'; +import { FlexModule } from '@angular/flex-layout'; +import { TranslocoModule } from '@ngneat/transloco'; + +import { ButtonModule } from '@dsh/components/buttons'; +import { CardModule } from '@dsh/components/layout'; + +import { ShowMorePanelComponent } from './show-more-panel.component'; + +@NgModule({ + declarations: [ShowMorePanelComponent], + imports: [CardModule, ButtonModule, FlexModule, TranslocoModule], + exports: [ShowMorePanelComponent] +}) +export class ShowMorePanelModule {}