Skip to content

Commit

Permalink
Merge pull request #225 from netgrif/NAE-1928
Browse files Browse the repository at this point in the history
[NAE-1928] Refresh tabs on change
  • Loading branch information
renczesstefan authored Dec 13, 2023
2 parents 859ca03 + bd1970f commit a399e36
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ActivatedRoute} from '@angular/router';
import {filter} from 'rxjs/operators';
import {TabbedVirtualScrollComponent} from '../../abstract/tabbed-virtual-scroll.component';
import {AfterViewInit, Component, EventEmitter, Inject, Input, OnDestroy, Optional, Output} from '@angular/core';
import {Observable, Subject} from 'rxjs';
import {Observable, Subject, Subscription} from 'rxjs';
import {TaskPanelData} from '../task-panel-data/task-panel-data';
import {HeaderColumn} from '../../../header/models/header-column';
import {TaskEventNotification} from '../../../task-content/model/task-event-notification';
Expand Down Expand Up @@ -45,6 +45,8 @@ export abstract class AbstractDefaultTaskListComponent extends TabbedVirtualScro
* Emits notifications about task events
*/
@Output() taskEvent: EventEmitter<TaskEventNotification>;
protected _unsub: Subscription;
protected _canReload: boolean;

constructor(protected _taskViewService: TaskViewService,
protected _log: LoggerService,
Expand All @@ -54,12 +56,26 @@ export abstract class AbstractDefaultTaskListComponent extends TabbedVirtualScro
this.taskEvent = new EventEmitter<TaskEventNotification>();
this._taskPanelRefs = new Map<string, MatExpansionPanel>();
this._unsubscribe$ = new Subject<void>();
if (injectedTabData !== null) {
this._unsub = injectedTabData.tabSelected$.pipe(
filter(bool => bool)
).subscribe( () => {
if (this._canReload) {
this._taskViewService.reloadCurrentPage();
} else {
this._canReload = true;
}
});
}
}

ngOnDestroy(): void {
super.ngOnDestroy();
this.taskEvent.complete();
this._unsubscribe$.complete();
if (this._unsub) {
this._unsub.unsubscribe();
}
}

ngAfterViewInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ import {createMockNet} from '../../utility/tests/utility/create-mock-net';
import { OverflowService } from '../../header/services/overflow.service';
import {NAE_TASK_FORCE_OPEN} from '../../view/task-view/models/injection-token-task-force-open';
import {FrontActionService} from "../../actions/services/front-action.service";
import {NAE_TAB_DATA} from '../../tabs/tab-data-injection-token/tab-data-injection-token';
import {InjectedTabData} from '../../tabs/interfaces';

describe('AbtsractTaskPanelComponent', () => {
let component: TestTaskPanelComponent;
Expand Down Expand Up @@ -214,11 +216,12 @@ class TestTaskPanelComponent extends AbstractTaskPanelComponent implements After
protected _changedFieldsService: ChangedFieldsService,
protected _permissionService: PermissionService,
@Optional() overflowService: OverflowService,
@Optional() @Inject(NAE_TASK_FORCE_OPEN) protected _taskForceOpen: boolean) {
@Optional() @Inject(NAE_TASK_FORCE_OPEN) protected _taskForceOpen: boolean,
@Optional() @Inject(NAE_TAB_DATA) injectedTabData: InjectedTabData) {
super(_taskContentService, _log, _taskViewService, _paperView, _taskEventService, _assignTaskService,
_delegateTaskService, _cancelTaskService, _finishTaskService, _taskState, _taskDataService,
_assignPolicyService, _finishPolicyService, _callChain, _taskOperations, undefined, _translate,
_currencyPipe, _changedFieldsService, _permissionService, overflowService, _taskForceOpen);
_currencyPipe, _changedFieldsService, _permissionService, overflowService, _taskForceOpen, injectedTabData);
}

ngAfterViewInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ import {OverflowService} from '../../header/services/overflow.service';
import {NAE_TASK_FORCE_OPEN} from '../../view/task-view/models/injection-token-task-force-open';
import {CdkVirtualScrollViewport} from '@angular/cdk/scrolling';
import { FinishPolicyService } from '../../task/services/finish-policy.service';
import {NAE_TAB_DATA} from '../../tabs/tab-data-injection-token/tab-data-injection-token';
import {InjectedTabData} from '../../tabs/interfaces';
import {AfterAction} from '../../utility/call-chain/after-action';

@Component({
selector: 'ncc-abstract-legal-notice',
Expand Down Expand Up @@ -118,6 +121,8 @@ export abstract class AbstractTaskPanelComponent extends AbstractPanelWithImmedi
protected _subTaskData: Subscription;
protected _subPanelUpdate: Subscription;
protected _taskDisableButtonFunctions: DisableButtonFuntions;
protected _unsub: Subscription;
protected _canReload: boolean;

protected constructor(protected _taskContentService: TaskContentService,
protected _log: LoggerService,
Expand All @@ -140,7 +145,8 @@ export abstract class AbstractTaskPanelComponent extends AbstractPanelWithImmedi
protected _changedFieldsService: ChangedFieldsService,
protected _permissionService: PermissionService,
@Optional() overflowService: OverflowService,
@Optional() @Inject(NAE_TASK_FORCE_OPEN) protected _taskForceOpen: boolean) {
@Optional() @Inject(NAE_TASK_FORCE_OPEN) protected _taskForceOpen: boolean,
@Optional() @Inject(NAE_TAB_DATA) injectedTabData: InjectedTabData) {
super(_translate, _currencyPipe, overflowService);
this.taskEvent = new EventEmitter<TaskEventNotification>();
this.panelRefOutput = new EventEmitter<MatExpansionPanel>();
Expand Down Expand Up @@ -184,6 +190,17 @@ export abstract class AbstractTaskPanelComponent extends AbstractPanelWithImmedi
if (_disableFunctions) {
Object.assign(this._taskDisableButtonFunctions, _disableFunctions);
}
if (injectedTabData !== null) {
this._unsub = injectedTabData.tabSelected$.pipe(
filter(bool => bool && this.isExpanded())
).subscribe( () => {
if (this._canReload) {
this._taskDataService.initializeTaskDataFields(new AfterAction(), true)
} else {
this._canReload = true;
}
});
}
}

ngOnInit() {
Expand Down Expand Up @@ -416,6 +433,9 @@ export abstract class AbstractTaskPanelComponent extends AbstractPanelWithImmedi
this._taskOperations.destroy();
this._subPanelUpdate.unsubscribe();
this.taskEvent.complete();
if (this._unsub) {
this._unsub.unsubscribe();
}
}

public isForceOpen(): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Component, EventEmitter, Inject, Input, OnDestroy, Optional, Output} from '@angular/core';
import {Observable, Subject} from 'rxjs';
import {Observable, Subject, Subscription} from 'rxjs';
import {Case} from '../../../../resources/interface/case';
import {HeaderColumn} from '../../../../header/models/header-column';
import {CaseViewService} from '../../service/case-view-service';
import {LoggerService} from '../../../../logger/services/logger.service';
import {NAE_TAB_DATA} from '../../../../tabs/tab-data-injection-token/tab-data-injection-token';
import {InjectedTabData} from '../../../../tabs/interfaces';
import {ActivatedRoute} from '@angular/router';
import {filter, takeUntil} from 'rxjs/operators';
import {filter, take, takeUntil} from 'rxjs/operators';
import {TabbedVirtualScrollComponent} from '../../../../panel/abstract/tabbed-virtual-scroll.component';

@Component({
Expand All @@ -28,22 +28,38 @@ export abstract class AbstractDefaultCaseListComponent extends TabbedVirtualScro
public cases$: Observable<Array<Case>>;
public loading$: Observable<boolean>;
protected redirectCaseId: string;
protected unsubscribe$: Subject<void>;
protected _unsubscribe$: Subject<void>;
protected _unsub: Subscription;
protected _canReload: boolean;

constructor(protected _caseViewService: CaseViewService,
protected _log: LoggerService,
@Optional() @Inject(NAE_TAB_DATA) injectedTabData: InjectedTabData,
protected route?: ActivatedRoute) {
super(injectedTabData);
this.unsubscribe$ = new Subject<void>();
this._unsubscribe$ = new Subject<void>();
this.loading$ = this._caseViewService.loading$;
this.caseClick = new EventEmitter<Case>();
if (injectedTabData !== null) {
this._unsub = injectedTabData.tabSelected$.pipe(
filter(bool => bool)
).subscribe( () => {
if (this._canReload) {
this._caseViewService.reload();
} else {
this._canReload = true;
}
});
}
}

ngOnDestroy(): void {
super.ngOnDestroy();
this.caseClick.complete();
this.unsubscribe$.complete();
this._unsubscribe$.complete();
if (this._unsub) {
this._unsub.unsubscribe();
}
}

public onCaseClick(case_: Case) {
Expand All @@ -57,12 +73,12 @@ export abstract class AbstractDefaultCaseListComponent extends TabbedVirtualScro

this.route.queryParams.pipe(filter(pm => !!pm['caseId'])).subscribe(paramMap => {
this.redirectCaseId = paramMap['caseId'];
this.cases$.pipe(takeUntil(this.unsubscribe$)).subscribe(cases => {
this.cases$.pipe(takeUntil(this._unsubscribe$)).subscribe(cases => {
if (cases !== undefined && cases.length > 0) {
const _case = cases.find(c => c.stringId === this.redirectCaseId);
if (_case !== undefined) {
this.caseClick.emit(_case);
this.unsubscribe$.next();
this._unsubscribe$.next();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import {
TaskEventService,
TaskRequestStateService,
TaskViewService,
FrontActionService
FrontActionService,
NAE_TAB_DATA,
InjectedTabData
} from '@netgrif/components-core';
import {TaskContentComponent} from '../../task-content/task-content/task-content.component';
import {TranslateService} from '@ngx-translate/core';
Expand Down Expand Up @@ -79,11 +81,12 @@ export class TaskPanelComponent extends AbstractTaskPanelComponent {
protected _changedFieldsService: ChangedFieldsService,
protected _permissionService: PermissionService,
@Optional() overflowService: OverflowService,
@Optional() @Inject(NAE_TASK_FORCE_OPEN) protected _taskForceOpen: boolean) {
@Optional() @Inject(NAE_TASK_FORCE_OPEN) protected _taskForceOpen: boolean,
@Optional() @Inject(NAE_TAB_DATA) injectedTabData: InjectedTabData) {
super(_taskContentService, _log, _taskViewService, _paperView, _taskEventService, _assignTaskService,
_delegateTaskService, _cancelTaskService, _finishTaskService, _taskState, _taskDataService,
_assignPolicyService, _finishPolicyService, _callChain, _taskOperations, _disableFunctions, _translate, _currencyPipe, _changedFieldsService,
_permissionService, overflowService, _taskForceOpen);
_permissionService, overflowService, _taskForceOpen, injectedTabData);
if (_taskForceOpen) {
this.hidePanelHeader = true;
}
Expand Down

0 comments on commit a399e36

Please sign in to comment.