Browse Source

feature(theme-basic): add new layout actions

pull/1568/head
mehmet-erim 7 years ago
parent
commit
9554ee2f90
  1. 5
      npm/ng-packs/packages/theme-basic/src/lib/actions/layout.actions.ts
  2. 22
      npm/ng-packs/packages/theme-basic/src/lib/states/layout.state.ts

5
npm/ng-packs/packages/theme-basic/src/lib/actions/layout.actions.ts

@ -4,3 +4,8 @@ export class LayoutAddNavigationElement {
static readonly type = '[Layout] Add Navigation Element';
constructor(public payload: Layout.NavigationElement | Layout.NavigationElement[]) {}
}
export class LayoutRemoveNavigationElementByName {
static readonly type = '[Layout] Remove Navigation ElementByName';
constructor(public name: string) {}
}

22
npm/ng-packs/packages/theme-basic/src/lib/states/layout.state.ts

@ -1,5 +1,5 @@
import { State, Action, StateContext, Selector } from '@ngxs/store';
import { LayoutAddNavigationElement } from '../actions/layout.actions';
import { LayoutAddNavigationElement, LayoutRemoveNavigationElementByName } from '../actions/layout.actions';
import { Layout } from '../models/layout';
import { TemplateRef } from '@angular/core';
import snq from 'snq';
@ -15,7 +15,7 @@ export class LayoutState {
}
@Action(LayoutAddNavigationElement)
layoutAction({ getState, patchState }: StateContext<Layout.State>, { payload = [] }: LayoutAddNavigationElement) {
layoutAddAction({ getState, patchState }: StateContext<Layout.State>, { payload = [] }: LayoutAddNavigationElement) {
let { navigationElements } = getState();
if (!Array.isArray(payload)) {
@ -42,4 +42,22 @@ export class LayoutState {
navigationElements,
});
}
@Action(LayoutRemoveNavigationElementByName)
layoutRemoveAction(
{ getState, patchState }: StateContext<Layout.State>,
{ name }: LayoutRemoveNavigationElementByName,
) {
let { navigationElements } = getState();
const index = navigationElements.findIndex(element => element.name === name);
if (index > -1) {
navigationElements = navigationElements.splice(index, 1);
}
return patchState({
navigationElements,
});
}
}

Loading…
Cancel
Save