-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from DatepollSystems/feature/tab-colors
Feature/tab colors
- Loading branch information
Showing
13 changed files
with
234 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/app/home/_shared/components/color/app-text-color-by-background.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {computed, Directive, inject, input} from '@angular/core'; | ||
import {AppAdjustDarkModeColor} from '@home-shared/components/color/app-adjust-dark-mode-color.pipe'; | ||
import {AppIsLightColorPipe} from '@home-shared/components/color/app-is-light-color.pipe'; | ||
import {ThemeService} from '@shared/services/theme.service'; | ||
|
||
@Directive({ | ||
selector: '[app-text-color-by-background]', | ||
standalone: true, | ||
host: { | ||
'[class.text-white]': 'textWhite()', | ||
'[class.text-dark]': 'textBlack()', | ||
'[class.text-body-emphasis]': 'textEmphasis()', | ||
}, | ||
}) | ||
export class AppTextColorByBackgroundDirective { | ||
color = input.required<string | undefined | null>(); | ||
|
||
adjustDarkMode = new AppAdjustDarkModeColor(); | ||
isLightColor = new AppIsLightColorPipe(); | ||
theme = inject(ThemeService).currentTheme; | ||
|
||
textWhite = computed(() => this.color() && !this.isLightColor.transform(this.adjustDarkMode.transform(this.color(), this.theme().id))); | ||
textBlack = computed(() => this.color() && this.isLightColor.transform(this.adjustDarkMode.transform(this.color(), this.theme().id))); | ||
textEmphasis = computed(() => !this.color()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,118 @@ | ||
import {HttpParams} from '@angular/common/http'; | ||
import {inject, signal, Signal, WritableSignal} from '@angular/core'; | ||
import {DestroyRef, effect, inject, signal, Signal, WritableSignal} from '@angular/core'; | ||
import {toSignal} from '@angular/core/rxjs-interop'; | ||
import {ActivatedRoute, Router} from '@angular/router'; | ||
|
||
import {map} from 'rxjs'; | ||
import {map, merge, Subscription} from 'rxjs'; | ||
|
||
import {n_from} from 'dfts-helper'; | ||
import {SortDirection} from 'dfx-bootstrap-table'; | ||
import {loggerOf, n_from} from 'dfts-helper'; | ||
import {NgbPaginator, NgbSort, SortDirection} from 'dfx-bootstrap-table'; | ||
|
||
export interface PageableDto { | ||
/** | ||
* @format int32 | ||
* @min 0 | ||
*/ | ||
page?: number; | ||
/** | ||
* @format int32 | ||
* @min 1 | ||
*/ | ||
size?: number; | ||
sort?: string; | ||
page: number; | ||
size: number; | ||
sort: { | ||
direction: SortDirection; | ||
name: string; | ||
}; | ||
query?: string; | ||
} | ||
|
||
export function getPaginationParams(options: PageableDto): HttpParams { | ||
let params = new HttpParams(); | ||
params = params.append('page', options.page ?? 0); | ||
params = params.append('size', options.size ?? 10); | ||
if (options.sort) { | ||
params = params.append('sort', options.sort); | ||
} | ||
params = params.append('page', options.page); | ||
params = params.append('size', options.size); | ||
params = params.append( | ||
'sort', | ||
`${options.sort.name},${options.sort.direction.length > 0 ? options.sort.direction : DEFAULT_SORT_DIRECTION}`, | ||
); | ||
if (options.query && options.query.length > 0) { | ||
params = params.append('query', options.query); | ||
} | ||
return params; | ||
} | ||
|
||
export function getSortParam(active?: string, direction: 'asc' | 'desc' | '' = ''): string | undefined { | ||
return active && direction !== '' ? `${active},${direction}` : undefined; | ||
} | ||
const DEFAULT_SORT_DIRECTION = 'desc'; | ||
const DEFAULT_PAGE_SIZE = 20; | ||
|
||
const lumber = loggerOf('pagination'); | ||
|
||
export function injectPagination( | ||
defaultSortBy: string, | ||
defaultSortDirection: SortDirection = 'desc', | ||
): { | ||
params: Signal<{page: number; size: number; sort: string; direction: SortDirection}>; | ||
export function injectPagination({ | ||
defaultSortBy, | ||
defaultSortDirection, | ||
defaultPageSize, | ||
paginator, | ||
sort, | ||
}: { | ||
defaultSortBy: string; | ||
defaultSortDirection?: SortDirection; | ||
defaultPageSize?: number; | ||
paginator: Signal<NgbPaginator>; | ||
sort: Signal<NgbSort>; | ||
}): { | ||
params: Signal<PageableDto>; | ||
totalElements: WritableSignal<number>; | ||
loading: WritableSignal<boolean>; | ||
activatedRoute: ActivatedRoute; | ||
updateParams: (queryParams: {size: number; page: number; sort: string; direction: SortDirection}) => void; | ||
} { | ||
const activatedRoute = inject(ActivatedRoute); | ||
const router = inject(Router); | ||
|
||
const params = toSignal( | ||
let subscription: Subscription | undefined; | ||
inject(DestroyRef).onDestroy(() => { | ||
subscription?.unsubscribe(); | ||
}); | ||
|
||
effect(() => { | ||
const _paginator = paginator(); | ||
const _sort = sort(); | ||
|
||
subscription?.unsubscribe(); | ||
|
||
subscription = merge(_paginator.page, _sort.sortChange).subscribe(() => { | ||
const queryParams = { | ||
size: _paginator.pageSize, | ||
page: _paginator.pageIndex, | ||
sort: _sort.active, | ||
direction: _sort.direction, | ||
}; | ||
lumber.log('updatePaginationParams', 'new params', queryParams); | ||
void router.navigate([], { | ||
relativeTo: activatedRoute, | ||
queryParamsHandling: 'merge', | ||
queryParams, | ||
}); | ||
}); | ||
}); | ||
|
||
const loading = signal(true); | ||
const totalElements = signal<number>(0); | ||
|
||
const params: Signal<PageableDto> = toSignal( | ||
activatedRoute.queryParamMap.pipe( | ||
map((it) => ({ | ||
page: it.get('page') ? n_from(it.get('page')) : 0, | ||
size: it.get('size') ? n_from(it.get('size')) : 20, | ||
sort: it.get('sort') ?? defaultSortBy, | ||
direction: (it.get('direction') as SortDirection | undefined) ?? defaultSortDirection, | ||
size: it.get('size') ? n_from(it.get('size')) : defaultPageSize ?? DEFAULT_PAGE_SIZE, | ||
sort: { | ||
name: it.get('sort') ?? defaultSortBy, | ||
direction: (it.get('direction') as SortDirection | undefined) ?? defaultSortDirection ?? DEFAULT_SORT_DIRECTION, | ||
}, | ||
})), | ||
), | ||
{ | ||
initialValue: { | ||
page: 0, | ||
size: 20, | ||
sort: defaultSortBy, | ||
direction: defaultSortDirection, | ||
size: defaultPageSize ?? DEFAULT_PAGE_SIZE, | ||
sort: { | ||
name: defaultSortBy, | ||
direction: defaultSortDirection ?? DEFAULT_SORT_DIRECTION, | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
const loading = signal(true); | ||
const totalElements = signal<number>(0); | ||
|
||
const updateParams = (queryParams: {size: number; page: number; sort: string; direction: string}): void => | ||
void router.navigate([], { | ||
relativeTo: activatedRoute, | ||
queryParamsHandling: 'merge', | ||
queryParams, | ||
}); | ||
|
||
return { | ||
params, | ||
loading, | ||
totalElements, | ||
activatedRoute, | ||
updateParams, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.