feat(calendar): make all colors available as map
This commit is contained in:
parent
04013dba44
commit
9781e9be78
|
@ -6,7 +6,9 @@ import { select, Store } from '@ngrx/store';
|
|||
import { ProjectActionTypes, UpdateProjectOrder } from './store/project.actions';
|
||||
import * as shortid from 'shortid';
|
||||
import {
|
||||
selectArchivedProjects, selectCaldavCfgByProjectId,
|
||||
selectAllProjectColors,
|
||||
selectArchivedProjects,
|
||||
selectCaldavCfgByProjectId,
|
||||
selectGithubCfgByProjectId,
|
||||
selectGitlabCfgByProjectId,
|
||||
selectJiraCfgByProjectId,
|
||||
|
@ -24,12 +26,12 @@ import { map, shareReplay, switchMap, take } from 'rxjs/operators';
|
|||
import { isValidProjectExport } from './util/is-valid-project-export';
|
||||
import { SnackService } from '../../core/snack/snack.service';
|
||||
import { T } from '../../t.const';
|
||||
import { BreakNr, BreakTime, WorkContextType } from '../work-context/work-context.model';
|
||||
import { BreakNr, BreakTime, WorkContextColorEntry, WorkContextType } from '../work-context/work-context.model';
|
||||
import { WorkContextService } from '../work-context/work-context.service';
|
||||
import { GITHUB_TYPE, GITLAB_TYPE, JIRA_TYPE } from '../issue/issue.const';
|
||||
import { GitlabCfg } from '../issue/providers/gitlab/gitlab';
|
||||
import { ExportedProject } from './project-archive.model';
|
||||
import {CaldavCfg} from '../issue/providers/caldav/caldav.model';
|
||||
import { CaldavCfg } from '../issue/providers/caldav/caldav.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
|
@ -59,6 +61,7 @@ export class ProjectService {
|
|||
: of(false)
|
||||
)
|
||||
);
|
||||
projectColors$: Observable<WorkContextColorEntry[]> = this._store$.pipe(select(selectAllProjectColors));
|
||||
|
||||
// DYNAMIC
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import { GithubCfg } from '../../issue/providers/github/github.model';
|
|||
import {
|
||||
WorkContextAdvancedCfg,
|
||||
WorkContextAdvancedCfgKey,
|
||||
WorkContextColorEntry,
|
||||
WorkContextType
|
||||
} from '../../work-context/work-context.model';
|
||||
import {
|
||||
|
@ -65,6 +66,14 @@ export const selectUnarchivedProjects = createSelector(selectAllProjects, (proje
|
|||
|
||||
export const selectArchivedProjects = createSelector(selectAllProjects, (projects) => projects.filter(p => p.isArchived));
|
||||
|
||||
export const selectAllProjectColors = createSelector(
|
||||
selectAllProjects,
|
||||
(projects: Project[]): WorkContextColorEntry[] => projects.map(project => ({
|
||||
id: project.id,
|
||||
color: project.theme.primary
|
||||
}))
|
||||
);
|
||||
|
||||
// DYNAMIC SELECTORS
|
||||
// -----------------
|
||||
export const selectProjectById = createSelector(
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
UpdateTaskTags
|
||||
} from '../../tasks/store/task.actions';
|
||||
import { TODAY_TAG } from '../tag.const';
|
||||
import { WorkContextType } from '../../work-context/work-context.model';
|
||||
import { WorkContextColorEntry, WorkContextType } from '../../work-context/work-context.model';
|
||||
import {
|
||||
moveTaskDownInTodayList,
|
||||
moveTaskInTodayList,
|
||||
|
@ -38,7 +38,13 @@ export const selectAllTagsWithoutMyDay = createSelector(
|
|||
selectAllTags,
|
||||
(tags: Tag[]): Tag[] => tags.filter(tag => tag.id !== TODAY_TAG.id)
|
||||
);
|
||||
|
||||
export const selectAllTagColors = createSelector(
|
||||
selectAllTags,
|
||||
(tags: Tag[]): WorkContextColorEntry[] => tags.map(tag => ({
|
||||
id: tag.id,
|
||||
color: tag.color || tag.theme.primary
|
||||
}))
|
||||
);
|
||||
export const selectTagById = createSelector(
|
||||
selectTagFeatureState,
|
||||
(state: TagState, props: { id: string }): Tag => {
|
||||
|
|
|
@ -1,18 +1,26 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { select, Store } from '@ngrx/store';
|
||||
import { selectAllTags, selectAllTagsWithoutMyDay, selectTagById, selectTagsByIds } from './store/tag.reducer';
|
||||
import {
|
||||
selectAllTagColors,
|
||||
selectAllTags,
|
||||
selectAllTagsWithoutMyDay,
|
||||
selectTagById,
|
||||
selectTagsByIds
|
||||
} from './store/tag.reducer';
|
||||
import { addTag, deleteTag, deleteTags, updateTag, upsertTag } from './store/tag.actions';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Tag, TagState } from './tag.model';
|
||||
import * as shortid from 'shortid';
|
||||
import { DEFAULT_TAG } from './tag.const';
|
||||
import { TypedAction } from '@ngrx/store/src/models';
|
||||
import { WorkContextColorEntry } from '../work-context/work-context.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TagService {
|
||||
tags$: Observable<Tag[]> = this._store$.pipe(select(selectAllTags));
|
||||
tagsColors$: Observable<WorkContextColorEntry[]> = this._store$.pipe(select(selectAllTagColors));
|
||||
tagsNoMyDay$: Observable<Tag[]> = this._store$.pipe(select(selectAllTagsWithoutMyDay));
|
||||
|
||||
constructor(
|
||||
|
|
|
@ -86,3 +86,12 @@ export interface WorkContextState {
|
|||
activeType: WorkContextType | null;
|
||||
// additional entities state properties
|
||||
}
|
||||
|
||||
export interface WorkContextColorEntry {
|
||||
id: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export interface WorkContextColorMap {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
WorkContext,
|
||||
WorkContextAdvancedCfg,
|
||||
WorkContextAdvancedCfgKey,
|
||||
WorkContextColorMap,
|
||||
WorkContextState,
|
||||
WorkContextThemeCfg,
|
||||
WorkContextType
|
||||
|
@ -34,7 +35,7 @@ import { hasTasksToWorkOn, mapEstimateRemainingFromTasks } from './work-context.
|
|||
import { flattenTasks, selectTaskEntities, selectTasksWithSubTasksByIds } from '../tasks/store/task.selectors';
|
||||
import { Actions, ofType } from '@ngrx/effects';
|
||||
import { moveTaskToBacklogList } from './store/work-context-meta.actions';
|
||||
import { selectProjectById } from '../project/store/project.reducer';
|
||||
import { selectAllProjectColors, selectProjectById } from '../project/store/project.reducer';
|
||||
import { WorklogExportSettings } from '../worklog/worklog.model';
|
||||
import {
|
||||
AddToProjectBreakTime,
|
||||
|
@ -288,6 +289,26 @@ export class WorkContextService {
|
|||
shareReplay(1),
|
||||
);
|
||||
|
||||
allWorkContextColors$: Observable<WorkContextColorMap> = combineLatest([
|
||||
// avoid circular dep
|
||||
this._store$.pipe(select(selectAllProjectColors)),
|
||||
this._tagService.tagsColors$,
|
||||
]).pipe(
|
||||
map(([forProjects, forTags]) => {
|
||||
const workContextColorMap: WorkContextColorMap = {};
|
||||
forProjects.forEach((project) => {
|
||||
workContextColorMap[project.id] = project.color;
|
||||
});
|
||||
forTags.forEach((tag) => {
|
||||
workContextColorMap[tag.id] = tag.color;
|
||||
});
|
||||
return workContextColorMap;
|
||||
}),
|
||||
shareReplay(1),
|
||||
);
|
||||
|
||||
// allWorkContextColors$: Observable<any> =
|
||||
|
||||
constructor(
|
||||
private _store$: Store<WorkContextState>,
|
||||
private _actions$: Actions,
|
||||
|
|
Loading…
Reference in New Issue
Block a user