Skip to content

Commit

Permalink
working on #152, and #153, move title service to store
Browse files Browse the repository at this point in the history
  • Loading branch information
axtho committed Oct 17, 2017
1 parent b9aad26 commit d224ce2
Show file tree
Hide file tree
Showing 23 changed files with 108 additions and 147 deletions.
3 changes: 3 additions & 0 deletions core/src/modules/settings/settings.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ export class ToggleDrawerAction implements Action {

export class SetTitleAction implements Action {
readonly type = SET_TITLE;
constructor(public payload: string) { }
}

export class SetModuleAction implements Action {
readonly type = SET_MODULE;
constructor(public payload: string) { }
}

export class GetModuleTitleAction implements Action {
Expand All @@ -80,5 +82,6 @@ export type SettingActions
| UpdateSettingSuccessAction
| UpdateSettingFailureAction
| ClearSettingsMessageAction
| SetTitleAction
| SetContextButtonsAction
| SetContextButtonsAction;
14 changes: 11 additions & 3 deletions core/src/modules/settings/settings.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import 'rxjs/add/operator/toArray';
import 'rxjs/add/observable/of';
import { Injectable } from '@angular/core';
import { Action } from '@ngrx/store';
import { Effect, Actions, toPayload } from '@ngrx/effects';
import { Effect, Actions } from '@ngrx/effects';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import { Title } from '@angular/platform-browser';

import * as actions from './settings.actions';
import { HttpService } from '../../services/http.service';
Expand All @@ -19,7 +20,7 @@ import { SettingsState } from './settings.reducer';
export class SettingsEffects {

@Effect()
get$: Observable<Action> = this.actions$
getSettings$: Observable<Action> = this.actions$
.ofType(actions.LIST_SETTINGS)
.do(() => actions.ListSettingAction)
.switchMap(() =>
Expand All @@ -37,6 +38,13 @@ export class SettingsEffects {
.catch((r: any) => of(new actions.UpdateSettingFailureAction(r)))
);

@Effect({ dispatch: false })
setTitle$: Observable<Action> = this.actions$
.ofType(actions.SET_TITLE)
.map((action: actions.SetTitleAction) => action.payload)
.do((action: any) => this.browserTitle.setTitle(action + ' - Memberhive'));

constructor(private actions$: Actions,
private http: HttpService) { }
private http: HttpService,
private browserTitle: Title) { }
}
4 changes: 3 additions & 1 deletion core/src/modules/settings/settings.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export interface SystemSettings {
}

export interface LayoutSettings {
showDrawer: boolean;
showDrawer?: boolean;
title?: string;
module?: string;
contextButtons?: ContextButton[];
}

Expand Down
17 changes: 16 additions & 1 deletion core/src/modules/settings/settings.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const initialState: SettingsState = {
loaded: false,
loading: false,
layout: {
showDrawer: true
showDrawer: true,
title: '',
module: ''
},
people: {
list: ['email'],
Expand Down Expand Up @@ -119,11 +121,22 @@ export function settingsReducer(state: SettingsState = initialState,
return Object.assign({}, state, {
layout: {
showDrawer: state.layout.showDrawer,
title: state.layout.title,
contextButtons: action.payload
}
});
}

case actions.SET_TITLE: {
return Object.assign({}, state, {
layout: {
showDrawer: state.layout.showDrawer,
title: action.payload,
contextButtons: state.layout.contextButtons
}
});
}

default:
return state;
}
Expand All @@ -140,5 +153,7 @@ export const getPeopleListSettings: any = (state: SettingsState) => state.people
export const getProfileSettings: any = (state: SettingsState) => state.profile;

export const getShowDrawer: any = (state: SettingsState) => state.layout.showDrawer;
export const getTitle: any = (state: SettingsState) => state.layout.title;
export const getModule: any = (state: SettingsState) => state.layout.module;
export const getContextButtons: any = (state: SettingsState) => state.layout.contextButtons;
export const getSysGoogleKey: any = (state: SettingsState) => state.system.googleApiKey;
1 change: 1 addition & 0 deletions web/src/app/app.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const getProfileSettings: any = createSelector(getSettingsState, settings
export const getSysSettings: any = createSelector(getSettingsState, settings.getSysSettings);

export const getShowDrawer: any = createSelector(getSettingsState, settings.getShowDrawer);
export const getTitle: any = createSelector(getSettingsState, settings.getTitle);
export const getContextButtons: any = createSelector(getSettingsState, settings.getContextButtons);
export const getSysGoogleKey: any = createSelector(getSettingsState, settings.getSysGoogleKey);

Expand Down
4 changes: 1 addition & 3 deletions web/src/app/audit/audit.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { MatListModule, MatIconModule } from '@angular/material';
import { FlexLayoutModule } from '@angular/flex-layout';
import { MomentModule } from 'angular2-moment';

import { TitleService } from '../common/title.service';
import { AuditLogComponent } from './audit-log.component';
import { AuditService } from './audit.service';

Expand All @@ -27,7 +26,6 @@ import { AuditService } from './audit.service';
]
})
export class AuditModule {
constructor(titleService: TitleService) {
titleService.changeModule('Dashboard');
constructor() {
}
}
4 changes: 1 addition & 3 deletions web/src/app/common/common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { MhToggleDirective } from './animations/toggle/toggle.directive';
import { ShoutService } from './shout.service';
import { DialogService } from './dialog.service';
import { AuthGuard } from './auth-guard.service';
import { TitleService } from './title.service';

import { NotifyboxComponent } from './components/notifybox/notifybox.component';
import { FilterComponent } from './components/filter/filter.component';
Expand Down Expand Up @@ -66,8 +65,7 @@ const MATERIAL_MODULES: any[] = [
Title,
AuthGuard,
ShoutService,
DialogService,
TitleService
DialogService
],
exports: [
NotifyboxComponent,
Expand Down
45 changes: 0 additions & 45 deletions web/src/app/common/title.service.ts

This file was deleted.

49 changes: 29 additions & 20 deletions web/src/app/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Component, OnDestroy } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Store } from '@ngrx/store';
import { DragulaService } from 'ng2-dragula/ng2-dragula';
import { TitleService } from '../common/title.service';

import {
ContextButton,
Person,
SetContextButtonsAction
SettingsState,
LayoutSettings,
SetContextButtonsAction,
SetTitleAction
} from 'mh-core';

import * as app from '../app.store';
Expand All @@ -18,42 +20,49 @@ import * as app from '../app.store';
templateUrl: './dashboard.component.html'
})
export class DashboardComponent implements OnDestroy {
showDropzone: boolean = false;

private _settings: LayoutSettings;
private _alive: boolean = true;

people$: Observable<Person[]>;
currentUser$: Observable<Person>;

showDropzone: boolean = false;
now: string = new Date().toDateString();
dashletsRight: Array<string>;
dashletsLeft: Array<string>;

constructor(private _titleService: TitleService,
private _dragulaService: DragulaService,
constructor(private _dragulaService: DragulaService,
private _store: Store<app.AppState>) {
//_titleService.changeModule('Dashboard');
_titleService.setTitle('Dashboard');
this._dragulaService.setOptions('dashlet', {
moves: function (el: any, container: any, handle: any): boolean {
return handle.className.indexOf('handle') > -1;
}
});
this._dragulaService.drag.subscribe((value: any) => {
this.showDropzone = true;
});
this._dragulaService.dragend.subscribe((value: any) => {
this.showDropzone = false;
});

this.currentUser$ = this._store.select(app.getAuthPerson);
this.people$ = this._store.select(app.getPeople);

this._store.dispatch(new SetTitleAction('Dashboard'));
this.initDragServices();
this.setContextMenu();
}

setContextMenu(): void {
let buttons: ContextButton[] = [];

this._store.dispatch(new SetContextButtonsAction(buttons));
}

ngOnDestroy(): void {
this._dragulaService.destroy('dashlet');
this._alive = false;
}

private initDragServices(): void {
this._dragulaService.setOptions('dashlet', {
moves: function (el: any, container: any, handle: any): boolean {
return handle.className.indexOf('handle') > -1;
}
});
this._dragulaService.drag.subscribe((value: any) => {
this.showDropzone = true;
});
this._dragulaService.dragend.subscribe((value: any) => {
this.showDropzone = false;
});
}
}
12 changes: 5 additions & 7 deletions web/src/app/interaction/form/interaction-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Observable } from 'rxjs/Observable';
import { ActivatedRoute } from '@angular/router';
import { MatButtonToggleChange } from '@angular/material';

import { TitleService } from '../../common/title.service';

import * as app from '../../app.store';
import {
AuthService,
Expand All @@ -16,7 +14,8 @@ import {
Interaction,
Person,
AddInteractionAction,
UpdateInteractionAction
UpdateInteractionAction,
SetTitleAction
} from 'mh-core';

@Component({
Expand Down Expand Up @@ -44,13 +43,13 @@ export class InteractionFormComponent implements OnInit, OnDestroy {
visibility: any[] = [];
actionVerbs: any[] = [];

constructor(titleService: TitleService,
private _fb: FormBuilder,
constructor(private _fb: FormBuilder,
private _auth: AuthService,
private _store: Store<app.AppState>,
private _route: ActivatedRoute,
private _location: Location) {
titleService.setTitle('Create Interaction');

this._store.dispatch(new SetTitleAction('Create Interaction'));
this.people$ = this._store.select(app.getPeople);
this._store.select(app.getSelectedPerson)
.takeWhile(() => this._alive)
Expand Down Expand Up @@ -79,7 +78,6 @@ export class InteractionFormComponent implements OnInit, OnDestroy {
];

this.actionVerbs = ['call', 'meet', 'follow up', 'schedule', 'do', 'check'];

this._authorId = this._auth.getPersonId();
}

Expand Down
4 changes: 1 addition & 3 deletions web/src/app/interaction/interaction.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { Component } from '@angular/core';
import { TitleService } from '../common/title.service';

@Component({
moduleId: 'mh-interaction',
selector: 'mh-interaction',
templateUrl: './interaction.component.html'
})
export class InteractionComponent {
constructor(titleService: TitleService) {
titleService.changeModule('Person');
constructor() {
}
}
5 changes: 1 addition & 4 deletions web/src/app/interaction/interaction.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import { InteractionComponent } from './interaction.component';
import { InteractionFormComponent } from './form/interaction-form.component';
import { InteractionListComponent } from './list/interaction-list.component';

import { TitleService } from '../common/title.service';

import { TinyMCEComponent } from '../common/tinymce/tinymce.component';
import { ViewComponent } from './view/view.component';

Expand Down Expand Up @@ -61,7 +59,6 @@ import { ViewComponent } from './view/view.component';
]
})
export class InteractionModule {
constructor(titleService: TitleService) {
titleService.changeModule('Interactions');
constructor() {
}
}
8 changes: 3 additions & 5 deletions web/src/app/person/create/person-create.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import {
ContextButton,
SetContextButtonsAction,
PersonCalcGeoAction,
SetTitleAction,
CalcGeoCodePayload
} from 'mh-core';

import { TitleService } from '../../common/title.service';

@Component({
selector: 'mh-person-create',
templateUrl: './person-create.component.html',
Expand All @@ -28,10 +27,8 @@ export class PersonCreateComponent implements OnDestroy {
googleApiKey: string;
people: Person[];

constructor(titleService: TitleService,
private _store: Store<app.AppState>,
constructor(private _store: Store<app.AppState>,
private _router: Router) {
titleService.setTitle('Create Person');
this.settings$ = this._store.select(app.getPeopleSettings);
this._store.select(app.getSysGoogleKey).takeWhile(() => this._alive)
.subscribe((key: string) => this.googleApiKey = key);
Expand All @@ -44,6 +41,7 @@ export class PersonCreateComponent implements OnDestroy {
}
});
this._setContextMenu();
this._store.dispatch(new SetTitleAction('Create Person'));
}

savePerson(person: Person): void {
Expand Down
Loading

0 comments on commit d224ce2

Please sign in to comment.