File

lib/common/src/meta-store/content/meta-store.component.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods
Inputs
Accessors

Constructor

constructor(changeDetectorRef: ChangeDetectorRef)
Parameters :
Name Type Optional
changeDetectorRef ChangeDetectorRef No

Inputs

filterControl
Type : FormControl | null
filterQuery
Type : string
itemClass
Type : Type<Item>
metaStore
Type : MetaStore
selectInto
Type : [] | null

Methods

Public filterItems
filterItems(items: Item[])
Parameters :
Name Type Optional
items Item[] No
Returns : Item[]
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Public setMetaStore
setMetaStore(metaStore: MetaStore)
Parameters :
Name Type Optional
metaStore MetaStore No
Returns : void
Public toggleSelect
toggleSelect(item: Item)
Parameters :
Name Type Optional
item Item No
Returns : void

Properties

Private _metaStore
Type : MetaStore
Public activeStores
Type : ItemStore[]
Default value : []
Protected destroy$
Default value : new Subject<void>()
Private query
Type : string | null
Public selected
Type : Item[] | null
Default value : null

Accessors

metaStore
getmetaStore()
setmetaStore(metaStore: MetaStore)
Parameters :
Name Type Optional
metaStore MetaStore No
Returns : void
selectInto
setselectInto(items: Item[] | null)
Parameters :
Name Type Optional
items Item[] | null No
Returns : void
filterQuery
setfilterQuery(query: string)
Parameters :
Name Type Optional
query string No
Returns : void
import  {
			Component,
			Input,
			OnInit,
			OnDestroy,
			Optional,
			Type,
			ChangeDetectionStrategy,
			ChangeDetectorRef,
		}             				from '@angular/core'

import	{	FormControl			}	from '@angular/forms'
import	{
			Subject,
			takeUntil,
			startWith
		}							from 'rxjs'
import	{
			Item,
			ItemStore
		}							from '@rcc/core'


import	{	MetaStore			}	from '../meta-store.class'

@Component({
	selector: 'rcc-meta-store',
	changeDetection: ChangeDetectionStrategy.OnPush,
	templateUrl: './meta-store.component.html',
	styleUrls: ['./meta-store.component.scss'],
})

export class MetaStoreComponent implements OnInit, OnDestroy {

	// @ContentChild(TemplateRef)
	// public itemLabelTemplate!	: TemplateRef<any>;

	@Input()
	public itemClass!			: Type<Item>

	@Input()
	set metaStore(metaStore : MetaStore) 	{ this.setMetaStore(metaStore) }
	get metaStore(): MetaStore				{ return this._metaStore }
	private _metaStore : MetaStore


	@Optional() @Input()
	public filterControl!		: FormControl | null

	@Optional() @Input()
	public set selectInto(items: Item[] | null)  {
		this.selected = items || null
	}

	@Optional() @Input()
	public set filterQuery(query: string){
		this.query = query
	}

	public activeStores			: ItemStore[] = []
	public selected				: Item[] | null  = null

	private query!				: string | null

	protected destroy$			= new Subject<void>()

	constructor(
		protected changeDetectorRef : ChangeDetectorRef
	){

	}

	public setMetaStore(metaStore : MetaStore) : void {

		this._metaStore = metaStore

		if(!metaStore) return;

		metaStore.change$
		.pipe(
			takeUntil(this.destroy$),
			startWith(null)
		)
		.subscribe( () => {
			this.activeStores = this.metaStore.stores?.filter( store => store.items?.length > 0 )
			this.changeDetectorRef.markForCheck()
		})

	}


	public filterItems(items: Item[]): Item[]{

		if(!this.query) return items

		return items.filter( (item:Item<unknown> ) => item.matches(this.query) )

	}


	public toggleSelect(item: Item): void {

		if(! Array.isArray(this.selected) ) return;

		const pos = this.selected.indexOf(item)

		pos == -1
		?	this.selected.push(item)
		:	this.selected.splice(pos,1)

	}

	ngOnInit() : void {
		if(this.filterControl){
				this.filterControl.valueChanges
				.pipe( takeUntil(this.destroy$) )
				.subscribe( value => this.query = value )
		}

	}

	ngOnDestroy() : void {
		this.destroy$.next()
		this.destroy$.complete()
	}

}
<ion-list *ngFor ="let store of activeStores">

	<ion-list-header
		[id]    = "store.name | toID: 'rcc-e2e'"
	>
		<h2>{{ store.name | translate }}</h2>
        <p> ({{(store.items).length}})</p>

	</ion-list-header>

	<ion-item-group>

		<rcc-item-tag
			*ngFor 		= "let item of filterItems(store.items)"
			[item]		= "item"
			[selected]	= "selected && selected.includes(item)"
			(click)		= "toggleSelect(item)"
		></rcc-item-tag>

	</ion-item-group>

	<ion-item
		*ngIf = "filterItems(store.items).length == 0"

	>
		<ion-label
			class	= "ion-text-center"
			[id]	= "'META_STORE.NO_ITEMS' | toID: 'rcc-e2e'"

		>
			{{ 'META_STORE.NO_ITEMS' | translate }}
		</ion-label>
	</ion-item>

</ion-list>

<ion-text
	*ngIf	= "activeStores.length == 0"
	class 	= "ion-text-center"
	[id]	= "'META_STORE.NO_ACTIVE_STORES' | toID: 'rcc-e2e'"

>
	<h3>{{ 'META_STORE.NO_ACTIVE_STORES' | translate }}</h3>
</ion-text>

./meta-store.component.scss

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""