Показать сообщение отдельно
  #2 (permalink)  
Старый 13.06.2018, 11:26
Аспирант
Отправить личное сообщение для okuznetsov1 Посмотреть профиль Найти все сообщения от okuznetsov1
 
Регистрация: 02.11.2016
Сообщений: 65

.
journal.epic.ts:

........................................................................

@Injectable()
export class WorkingTimeJournalDetailEpics {

    /**
     * Инъектируем зависимости в конструкторе
     * @param service
     * @param actions
     */
    constructor(private service: WorkingTimeJournalDetailService,
                private actions: WorkingTimeJournalDetailActions) {
        this.service.columnSetting = columnSettings;
    }

    /**
     * Создает корневого посредника путем комбинирования дочерних
     */
    public createEpic() {
        return createEpicMiddleware(combineEpics(
            this.createAddReportEpic(),
            this.createLoadPageEpic(),
            this.createReceivePageEpic()
        ));
    }

    /**
     * Обработка действия добавления новго отчета
     */
    private createAddReportEpic() {
        return (action$, store) => action$
            .filter(a => {
debugger;
                return a;
            })
            .ofType(Actions.GROUPS_ADD, Actions.GROUPS_ADD_SELECTED)
            .filter(action => inArrayFilter(WIDGET_NAME, action.payload.additional.widgets))
            .map(action => this.actions.addGroup(action.payload.id));
    }

    /**
     * Обработка действия загрузка страницы
     */
    private createLoadPageEpic() {
        return (action$, store) => action$
            .ofType(WorkingTimeJournalDetailActions.LOAD_PAGE)
            .switchMap(action => {
                if (action.payload.userId) {
                    const state = store.getState();
                    const report = state[WORKING_TIME_JOURNAL_DETAIL_REDUX_NODE][action.meta.reportId];
                    let sort = report.sort;

                    const dateRange: DateRangeInterface = filters && filters.dateRange ? filters.dateRange : {
                        from: moment().startOf('day').utcOffset(0, true),
                        to: moment().endOf('day').utcOffset(0, true),
                    };

                    const loadFilters = {
                        user_id: action.payload.userId,
                        date_from: dateRange.from.utc().format(),
                        date_to: dateRange.to.utc().format()
                    };

                    return this.loadSliceFromService(action, loadFilters);
                } else {
                    return Observable.empty();
                }
            });
    }

    private createReceivePageEpic() {
        return (action$, store) => action$
            .ofType(WorkingTimeJournalDetailActions.RECEIVE_PAGE)
            .map(action => {
                return {type: 'NOP'};
            });
    }

    /**
     * Загрузка данных среза пользователей из сервиса
     * @param action
     * @param filters
     */
    private loadSliceFromService(action, filters?: any) {
        return this.service.getAll(filters)
            .map(data => {
                return this.actions.receivePage(action.meta.reportId, {items: data.items, total: data.total});
            });
    }
}



roor.epics.ts:

@Injectable()
export class RootEpics {
    constructor(private appEpics: AppEpics,
                private groupsEpics: GroupsEpics,
                private workingTimeJournalDetailEpics: WorkingTimeJournalDetailEpics,
                 ...............................................................................................................
       ) {
    }

    public createEpics() {
        return [
            this.appEpics.createAppEpics(),
            this.groupsEpics.createEpic(),
            this.workingTimeJournalDetailEpics.createEpic(),
            .............................................................................
        ];
    }
}



store.module.ts:


@NgModule({
    imports: [
        NgReduxModule,
        WorkingTimeJournalDetailModule,
        ........................................................
    ],
    providers: [RootEpics, GroupsEpics],
})
export class StoreModule {
    constructor(ngRedux: NgRedux<AppStateInterface>,
                devTools: DevToolsExtension,
                rootEpics: RootEpics) {
        if (!environment.production) {
            const storeEnhancers = devTools.isEnabled()
                ? [devTools.enhancer()]
                : [];


            ngRedux.configureStore(
                rootReducer,
                INITIAL_STATE,
                [
                    ...rootEpics.createEpics()
                ],
                storeEnhancers
            );
        } else {
            ngRedux.configureStore(rootReducer, INITIAL_STATE, [...rootEpics.createEpics()]);
        }
    }
}
Ответить с цитированием