-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added DbxFirebaseModelHistoryPopoverButtonComponent
- Loading branch information
Showing
27 changed files
with
412 additions
and
53 deletions.
There are no files selected for viewing
10 changes: 7 additions & 3 deletions
10
apps/demo/src/app/modules/demo/modules/app/container/history.component.html
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,7 +1,11 @@ | ||
<dbx-content-page dbxAppContextState="public"> | ||
<dbx-content-container> | ||
<h2>History</h2> | ||
<p>View recently viewed items here.</p> | ||
<dbx-firebase-model-type-instance-list [state$]="state$"></dbx-firebase-model-type-instance-list> | ||
<dbx-section-page header="History"> | ||
<div sectionHeader> | ||
<dbx-spacer></dbx-spacer> | ||
<dbx-firebase-model-history-popover-button></dbx-firebase-model-history-popover-button> | ||
</div> | ||
<dbx-firebase-model-history [historyFilter]="historyFilter"></dbx-firebase-model-history> | ||
</dbx-section-page> | ||
</dbx-content-container> | ||
</dbx-content-page> |
5 changes: 2 additions & 3 deletions
5
apps/demo/src/app/modules/demo/modules/app/container/history.component.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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import { Component } from '@angular/core'; | ||
import { DbxFirebaseModelTrackerService } from '@dereekb/dbx-firebase'; | ||
import { DbxFirebaseModelTrackerHistoryFilter, DbxFirebaseModelTrackerService } from '@dereekb/dbx-firebase'; | ||
import { loadingStateFromObs } from '@dereekb/rxjs'; | ||
|
||
@Component({ | ||
templateUrl: './history.component.html' | ||
}) | ||
export class DemoAppHistoryComponent { | ||
readonly historyPairs$ = this.dbxFirebaseModelTrackerService.loadHistoryPairs(); | ||
readonly state$ = loadingStateFromObs(this.historyPairs$); | ||
readonly historyFilter: DbxFirebaseModelTrackerHistoryFilter = {}; | ||
|
||
constructor(readonly dbxFirebaseModelTrackerService: DbxFirebaseModelTrackerService) {} | ||
} |
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,8 +1,9 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { DbxFirebaseModelHistoryModule } from './modules/model/model.history.module'; | ||
import { DbxFirebaseModelTypesModule } from './modules/model/model.types.module'; | ||
import { DbxFirebaseModelStoreModule } from './modules/store/model.store.module'; | ||
|
||
@NgModule({ | ||
exports: [DbxFirebaseModelStoreModule, DbxFirebaseModelTypesModule] | ||
exports: [DbxFirebaseModelStoreModule, DbxFirebaseModelHistoryModule, DbxFirebaseModelTypesModule] | ||
}) | ||
export class DbxFirebaseModelModule {} |
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
46 changes: 46 additions & 0 deletions
46
packages/dbx-firebase/src/lib/model/modules/model/model.history.component.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,46 @@ | ||
import { Component, Input, OnDestroy } from '@angular/core'; | ||
import { AnchorForValueFunction } from '@dereekb/dbx-web'; | ||
import { loadingStateFromObs } from '@dereekb/rxjs'; | ||
import { Maybe } from '@dereekb/util'; | ||
import { BehaviorSubject, switchMap, shareReplay } from 'rxjs'; | ||
import { DbxFirebaseModelTrackerHistoryFilter, DbxFirebaseModelTrackerService } from './model.tracker.service'; | ||
import { DbxFirebaseModelTypesServiceInstancePair } from './model.types.service'; | ||
|
||
@Component({ | ||
selector: 'dbx-firebase-model-history', | ||
template: ` | ||
<dbx-firebase-model-type-instance-list [state$]="state$" [dbxListItemModifier] [dbxListItemAnchorModifier]="anchorForItem"> | ||
<ng-content empty select="[empty]"></ng-content> | ||
</dbx-firebase-model-type-instance-list> | ||
` | ||
}) | ||
export class DbxFirebaseModelHistoryComponent implements OnDestroy { | ||
private _historyFilter = new BehaviorSubject<Maybe<DbxFirebaseModelTrackerHistoryFilter>>(undefined); | ||
|
||
@Input() | ||
anchorForItem?: Maybe<AnchorForValueFunction<DbxFirebaseModelTypesServiceInstancePair>>; | ||
|
||
@Input() | ||
get historyFilter() { | ||
return this._historyFilter.value; | ||
} | ||
|
||
set historyFilter(historyFilter: Maybe<DbxFirebaseModelTrackerHistoryFilter>) { | ||
this._historyFilter.next(historyFilter); | ||
} | ||
|
||
readonly historyFilter$ = this._historyFilter.asObservable(); | ||
|
||
readonly historyPairs$ = this.historyFilter$.pipe( | ||
switchMap((x) => this.dbxFirebaseModelTrackerService.filterHistoryPairs(x)), | ||
shareReplay(1) | ||
); | ||
|
||
readonly state$ = loadingStateFromObs(this.historyPairs$); | ||
|
||
constructor(readonly dbxFirebaseModelTrackerService: DbxFirebaseModelTrackerService) {} | ||
|
||
ngOnDestroy(): void { | ||
this._historyFilter.complete(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/dbx-firebase/src/lib/model/modules/model/model.history.module.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,16 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { DbxButtonModule, DbxListLayoutModule, DbxModelInfoModule, DbxPopoverInteractionModule, DbxRouterListModule } from '@dereekb/dbx-web'; | ||
import { DbxFirebaseModelHistoryComponent } from './model.history.component'; | ||
import { DbxFirebaseModelHistoryPopoverButtonComponent } from './model.history.popover.button.component'; | ||
import { DbxFirebaseModelHistoryPopoverComponent } from './model.history.popover.component'; | ||
import { DbxFirebaseModelTypesModule } from './model.types.module'; | ||
|
||
const declarations = [DbxFirebaseModelHistoryComponent, DbxFirebaseModelHistoryPopoverButtonComponent, DbxFirebaseModelHistoryPopoverComponent]; | ||
|
||
@NgModule({ | ||
imports: [CommonModule, DbxButtonModule, DbxRouterListModule, DbxPopoverInteractionModule, DbxModelInfoModule, DbxListLayoutModule, DbxFirebaseModelTypesModule], | ||
declarations, | ||
exports: declarations | ||
}) | ||
export class DbxFirebaseModelHistoryModule {} |
43 changes: 43 additions & 0 deletions
43
packages/dbx-firebase/src/lib/model/modules/model/model.history.popover.button.component.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,43 @@ | ||
import { ChangeDetectionStrategy, Component, ElementRef, Input, ViewChild } from '@angular/core'; | ||
import { AbstractPopoverRefDirective, DbxPopoverService } from '@dereekb/dbx-web'; | ||
import { NgPopoverRef } from 'ng-overlay-container'; | ||
import { DbxFirebaseModelHistoryPopoverComponent, DbxFirebaseModelHistoryPopoverParams } from './model.history.popover.component'; | ||
|
||
export type DbxFirebaseModelHistoryPopoverButtonConfig = DbxFirebaseModelHistoryPopoverParams; | ||
|
||
@Component({ | ||
selector: 'dbx-firebase-model-history-popover-button', | ||
template: ` | ||
<dbx-icon-button #button (buttonClick)="showHistoryPopover()" icon="history"></dbx-icon-button> | ||
`, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class DbxFirebaseModelHistoryPopoverButtonComponent extends AbstractPopoverRefDirective<unknown, unknown> { | ||
@ViewChild('button', { read: ElementRef, static: false }) | ||
buttonElement!: ElementRef; | ||
|
||
@Input() | ||
config?: DbxFirebaseModelHistoryPopoverButtonConfig; | ||
|
||
constructor(private readonly popupService: DbxPopoverService) { | ||
super(); | ||
} | ||
|
||
protected override _makePopoverRef(origin?: ElementRef): NgPopoverRef<unknown, unknown> { | ||
const config = this.config; | ||
|
||
if (!origin) { | ||
throw new Error('Missing origin.'); | ||
} | ||
|
||
return DbxFirebaseModelHistoryPopoverComponent.openPopover(this.popupService, { | ||
origin, | ||
...config | ||
}); | ||
} | ||
|
||
showHistoryPopover(): void { | ||
const origin = this.buttonElement.nativeElement; | ||
this.showPopover(origin); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/dbx-firebase/src/lib/model/modules/model/model.history.popover.component.html
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,12 @@ | ||
<dbx-popover-content> | ||
<!-- Header --> | ||
<dbx-popover-header [icon]="icon" [header]="header"></dbx-popover-header> | ||
<!-- Content --> | ||
<dbx-popover-scroll-content> | ||
<dbx-firebase-model-history [historyFilter]="historyFilter" [anchorForItem]="anchorForItem"> | ||
<dbx-list-empty-content empty> | ||
<p>{{ emptyText }}</p> | ||
</dbx-list-empty-content> | ||
</dbx-firebase-model-history> | ||
</dbx-popover-scroll-content> | ||
</dbx-popover-content> |
87 changes: 87 additions & 0 deletions
87
packages/dbx-firebase/src/lib/model/modules/model/model.history.popover.component.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,87 @@ | ||
import { Component, ElementRef, Type, OnInit, OnDestroy } from '@angular/core'; | ||
import { NgPopoverRef } from 'ng-overlay-container'; | ||
import { AbstractPopoverDirective, AnchorForValueFunction, DbxPopoverComponent, DbxPopoverKey, DbxPopoverService } from '@dereekb/dbx-web'; | ||
import { Maybe } from '@dereekb/util'; | ||
import { DbxFirebaseModelTypesServiceInstancePair } from './model.types.service'; | ||
import { DbxFirebaseModelTrackerHistoryFilter } from './model.tracker.service'; | ||
|
||
export interface DbxFirebaseModelHistoryPopoverParams { | ||
/** | ||
* Custom icon | ||
* | ||
* Defaults to "history" | ||
*/ | ||
icon?: string; | ||
/** | ||
* Custom header text | ||
* | ||
* Defaults to "History" | ||
*/ | ||
header?: string; | ||
/** | ||
* Custom empty text when no items exist. | ||
*/ | ||
emptyText?: string; | ||
/** | ||
* Origin to add the popover to. | ||
*/ | ||
origin: ElementRef; | ||
/** | ||
* Optional config to pass to the DbxFirebaseHistoryComponent | ||
*/ | ||
historyFilter?: Maybe<DbxFirebaseModelTrackerHistoryFilter>; | ||
/** | ||
* Anchor | ||
*/ | ||
anchorForItem?: Maybe<AnchorForValueFunction<DbxFirebaseModelTypesServiceInstancePair>>; | ||
} | ||
|
||
export const DEFAULT_FIREBASE_HISTORY_COMPONENT_POPOVER_KEY = 'history'; | ||
|
||
@Component({ | ||
templateUrl: './model.history.popover.component.html' | ||
}) | ||
export class DbxFirebaseModelHistoryPopoverComponent extends AbstractPopoverDirective<unknown, DbxFirebaseModelHistoryPopoverParams> { | ||
static openPopover(popupService: DbxPopoverService, { origin, header, icon, emptyText, historyFilter, anchorForItem }: DbxFirebaseModelHistoryPopoverParams, popoverKey?: DbxPopoverKey): NgPopoverRef { | ||
return popupService.open({ | ||
key: popoverKey ?? DEFAULT_FIREBASE_HISTORY_COMPONENT_POPOVER_KEY, | ||
origin, | ||
componentClass: DbxFirebaseModelHistoryPopoverComponent, | ||
data: { | ||
header, | ||
icon, | ||
emptyText, | ||
historyFilter, | ||
anchorForItem | ||
} as DbxFirebaseModelHistoryPopoverParams | ||
}); | ||
} | ||
|
||
constructor(popover: DbxPopoverComponent<unknown, DbxFirebaseModelHistoryPopoverParams>) { | ||
super(popover); | ||
} | ||
|
||
get params(): DbxFirebaseModelHistoryPopoverParams { | ||
return this.popover.data as DbxFirebaseModelHistoryPopoverParams; | ||
} | ||
|
||
get icon() { | ||
return this.params.icon ?? 'history'; | ||
} | ||
|
||
get header() { | ||
return this.params.header ?? 'History'; | ||
} | ||
|
||
get emptyText() { | ||
return this.params.header ?? 'History is empty.'; | ||
} | ||
|
||
get historyFilter() { | ||
return this.params.historyFilter; | ||
} | ||
|
||
get anchorForItem() { | ||
return this.params.anchorForItem; | ||
} | ||
} |
78 changes: 76 additions & 2 deletions
78
packages/dbx-firebase/src/lib/model/modules/model/model.tracker.service.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
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
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.