TSK-1613: Introduce Workplace store
This commit is contained in:
parent
e65093ca89
commit
0174191245
|
@ -3,11 +3,13 @@ import { ClassificationState } from './classification-store/classification.state
|
|||
import { WorkbasketState } from './workbasket-store/workbasket.state';
|
||||
import { AccessItemsManagementState } from './access-items-management-store/access-items-management.state';
|
||||
import { FilterState } from './filter-store/filter.state';
|
||||
import { WorkplaceState } from './workplace-store/workplace.state';
|
||||
|
||||
export const STATES = [
|
||||
EngineConfigurationState,
|
||||
ClassificationState,
|
||||
WorkbasketState,
|
||||
AccessItemsManagementState,
|
||||
FilterState
|
||||
FilterState,
|
||||
WorkplaceState
|
||||
];
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
export class SetFilterExpansion {
|
||||
static readonly type = '[Task list toolbar] Expand or collapse the Task filter';
|
||||
constructor(public isExpanded?: boolean) {}
|
||||
}
|
||||
|
||||
export class CalculateNumberOfCards {
|
||||
static readonly type = '[Task master] Calculate number of cards for task list';
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
import { Selector } from '@ngxs/store';
|
||||
import { WorkplaceState, WorkplaceStateModel } from './workplace.state';
|
||||
|
||||
export class WorkplaceSelectors {
|
||||
@Selector([WorkplaceState])
|
||||
static getFilterExpansion(state: WorkplaceStateModel): boolean {
|
||||
return state.isFilterExpanded;
|
||||
}
|
||||
|
||||
@Selector([WorkplaceState])
|
||||
static getNumberOfCards(state: WorkplaceStateModel): number {
|
||||
return state.cards;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
import { Action, NgxsOnInit, State, StateContext } from '@ngxs/store';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { CalculateNumberOfCards, SetFilterExpansion } from './workplace.actions';
|
||||
|
||||
@State<WorkplaceStateModel>({ name: 'WorkplaceState' })
|
||||
export class WorkplaceState implements NgxsOnInit {
|
||||
@Action(SetFilterExpansion)
|
||||
setFilterExpansion(ctx: StateContext<WorkplaceStateModel>, action: SetFilterExpansion): Observable<null> {
|
||||
const param = action.isExpanded;
|
||||
const isExpanded = typeof param !== 'undefined' ? param : !ctx.getState().isFilterExpanded;
|
||||
|
||||
ctx.setState({
|
||||
...ctx.getState(),
|
||||
isFilterExpanded: isExpanded
|
||||
});
|
||||
|
||||
ctx.dispatch(new CalculateNumberOfCards());
|
||||
|
||||
return of(null);
|
||||
}
|
||||
|
||||
@Action(CalculateNumberOfCards)
|
||||
calculateNumberOfCards(ctx: StateContext<WorkplaceStateModel>): Observable<null> {
|
||||
const cardHeight = 90;
|
||||
const totalHeight = window.innerHeight;
|
||||
const toolbarHeight = ctx.getState().isFilterExpanded ? 308 : 192;
|
||||
const occupiedHeight = 56 + 90 + toolbarHeight;
|
||||
|
||||
const cards = Math.max(1, Math.round((totalHeight - occupiedHeight) / cardHeight));
|
||||
|
||||
ctx.setState({
|
||||
...ctx.getState(),
|
||||
cards: cards
|
||||
});
|
||||
|
||||
return of(null);
|
||||
}
|
||||
|
||||
ngxsOnInit(ctx: StateContext<WorkplaceStateModel>): void {
|
||||
this.calculateNumberOfCards(ctx);
|
||||
|
||||
ctx.setState({
|
||||
...ctx.getState(),
|
||||
isFilterExpanded: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export interface WorkplaceStateModel {
|
||||
isFilterExpanded: boolean;
|
||||
cards: number;
|
||||
}
|
Loading…
Reference in New Issue