feat: use SettingTabsService in setting management

pull/4377/head
Arman Ozak 5 years ago
parent 74f476ef89
commit 0fb0ebad5d

@ -1,6 +1,6 @@
import { SettingTab } from '@abp/ng.theme.shared';
import { ABP } from '@abp/ng.core';
export class SetSelectedSettingTab {
static readonly type = '[SettingManagement] Set Selected Tab';
constructor(public payload: SettingTab) {}
constructor(public payload: ABP.Tab) {}
}

@ -1,7 +1,7 @@
import { ConfigState } from '@abp/ng.core';
import { getSettingTabs, SettingTab } from '@abp/ng.theme.shared';
import { Component, OnInit, TrackByFunction } from '@angular/core';
import { ABP, SettingTabsService } from '@abp/ng.core';
import { Component, OnDestroy, OnInit, TrackByFunction } from '@angular/core';
import { Store } from '@ngxs/store';
import { Subscription } from 'rxjs';
import { SetSelectedSettingTab } from '../actions/setting-management.actions';
import { SettingManagementState } from '../states/setting-management.state';
@ -9,35 +9,34 @@ import { SettingManagementState } from '../states/setting-management.state';
selector: 'abp-setting-management',
templateUrl: './setting-management.component.html',
})
export class SettingManagementComponent implements OnInit {
settings: SettingTab[] = [];
export class SettingManagementComponent implements OnDestroy, OnInit {
private subscription = new Subscription();
settings: ABP.Tab[] = [];
set selected(value: SettingTab) {
set selected(value: ABP.Tab) {
this.store.dispatch(new SetSelectedSettingTab(value));
}
get selected(): SettingTab {
get selected(): ABP.Tab {
const value = this.store.selectSnapshot(SettingManagementState.getSelectedTab);
if ((!value || !value.component) && this.settings.length) {
return this.settings[0];
}
return value;
return value?.component ? value : this.settings[0] || ({} as ABP.Tab);
}
trackByFn: TrackByFunction<SettingTab> = (_, item) => item.name;
trackByFn: TrackByFunction<ABP.Tab> = (_, item) => item.name;
constructor(private store: Store, private settingTabs: SettingTabsService) {}
constructor(private store: Store) {}
ngOnDestroy() {
this.subscription.unsubscribe();
}
ngOnInit() {
this.settings = getSettingTabs()
.filter(setting =>
this.store.selectSnapshot(ConfigState.getGrantedPolicy(setting.requiredPolicy)),
)
.sort((a, b) => a.order - b.order);
if (!this.selected && this.settings.length) {
this.selected = this.settings[0];
}
this.subscription.add(
this.settingTabs.visible$.subscribe(settings => {
this.settings = settings;
if (!this.selected) this.selected = this.settings[0];
}),
);
}
}

@ -1,7 +1,7 @@
import { SettingTab } from '@abp/ng.theme.shared';
import { ABP } from '@abp/ng.core';
export namespace SettingManagement {
export interface State {
selectedTab: SettingTab;
selectedTab?: ABP.Tab;
}
}

@ -1,11 +1,11 @@
import { Injectable } from '@angular/core';
import { Action, Selector, State, StateContext } from '@ngxs/store';
import { SetSelectedSettingTab } from '../actions/setting-management.actions';
import { SettingManagement } from '../models/setting-management';
import { Injectable } from '@angular/core';
@State<SettingManagement.State>({
name: 'SettingManagementState',
defaults: { selectedTab: {} } as SettingManagement.State,
defaults: {},
})
@Injectable()
export class SettingManagementState {

Loading…
Cancel
Save