Commit 99f538054ad9a8c86f026b0f2227192da50a4fa1

Authored by Igor Kulikov
Committed by GitHub
2 parents c0ef747c 634890dc

Merge pull request #3253 from vvlladd28/feature/state/pushAndOpenState

[3.0] Add new method for state controller pushAndOpenState
... ... @@ -107,6 +107,11 @@ export class DefaultStateControllerComponent extends StateControllerComponent im
107 107 }
108 108 }
109 109
  110 + public pushAndOpenState(states: Array<StateObject>, openRightLayout?: boolean): void {
  111 + const state = states[states.length - 1];
  112 + this.openState(state.id, state.params, openRightLayout);
  113 + }
  114 +
110 115 public updateState(id: string, params?: StateParams, openRightLayout?: boolean): void {
111 116 if (!id) {
112 117 id = this.getStateId();
... ...
... ... @@ -17,7 +17,7 @@
17 17 import { Component, NgZone, OnDestroy, OnInit } from '@angular/core';
18 18 import { StateObject, StateParams } from '@core/api/widget-api.models';
19 19 import { ActivatedRoute, Router } from '@angular/router';
20   -import { Observable, of } from 'rxjs';
  20 +import { forkJoin, Observable, of } from 'rxjs';
21 21 import { StateControllerState } from './state-controller.models';
22 22 import { StateControllerComponent } from './state-controller.component';
23 23 import { StatesControllerService } from '@home/pages/dashboard/states/states-controller.service';
... ... @@ -116,6 +116,23 @@ export class EntityStateControllerComponent extends StateControllerComponent imp
116 116 }
117 117 }
118 118
  119 + public pushAndOpenState(states: Array<StateObject>, openRightLayout?: boolean): void {
  120 + if (this.states) {
  121 + for (const state of states) {
  122 + if (!this.states[state.id]) {
  123 + return;
  124 + }
  125 + }
  126 + forkJoin(states.map(state => this.resolveEntity(state.params))).subscribe(
  127 + () => {
  128 + this.stateObject.push(...states);
  129 + this.selectedStateIndex = this.stateObject.length - 1;
  130 + this.gotoState(this.stateObject[this.stateObject.length - 1].id, true, openRightLayout);
  131 + }
  132 + );
  133 + }
  134 + }
  135 +
119 136 public updateState(id: string, params?: StateParams, openRightLayout?: boolean): void {
120 137 if (!id) {
121 138 id = this.getStateId();
... ...
... ... @@ -22,7 +22,7 @@ import { NgZone, OnDestroy, OnInit } from '@angular/core';
22 22 import { ActivatedRoute, Params, Router } from '@angular/router';
23 23 import { StatesControllerService } from '@home/pages/dashboard/states/states-controller.service';
24 24 import { EntityId } from '@app/shared/models/id/entity-id';
25   -import { StateParams } from '@app/core/api/widget-api.models';
  25 +import { StateObject, StateParams } from '@app/core/api/widget-api.models';
26 26
27 27 export abstract class StateControllerComponent implements IStateControllerComponent, OnInit, OnDestroy {
28 28
... ... @@ -178,6 +178,8 @@ export abstract class StateControllerComponent implements IStateControllerCompon
178 178
179 179 public abstract openState(id: string, params?: StateParams, openRightLayout?: boolean): void;
180 180
  181 + public abstract pushAndOpenState(states: Array<StateObject>, openRightLayout?: boolean): void;
  182 +
181 183 public abstract resetState(): void;
182 184
183 185 public abstract updateState(id?: string, params?: StateParams, openRightLayout?: boolean): void;
... ...