File

packages/data/src/lib/resource-list/resource-list.component.ts

Description

The ResourceListComponent is an extension of ListComponent for SDK ListResources. It is meant to be extended and overriden the createList method. See e.g. AssetListComponent.

Extends

ListComponent

Implements

OnChanges WithLoader OnDestroy

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector ec-resource-list
template
listTemplate

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(loaderService: LoaderService, sdk: SdkService, notificationService: NotificationsService, symbol: SymbolService, resourceService: ResourceService, listConfig: ListConfigService, cdr: ChangeDetectorRef, route: ActivatedRoute)

The constructor will just call super of List

Parameters :
Name Type Optional
loaderService LoaderService No
sdk SdkService No
notificationService NotificationsService No
symbol SymbolService No
resourceService ResourceService No
listConfig ListConfigService No
cdr ChangeDetectorRef No
route ActivatedRoute No

Inputs

api
Type : Core

The API Connector that possesses the resource list, see https://entrecode.github.io/ec.sdk/#api-connectors

listResource
Type : ListResource

If listResource input is set, the given ListResource will be used directly and loading will be skipped.

loader
Type : LoaderComponent

The loader that should be shown while the list is loaded.

loadWhen
Type : boolean

If set to false, the list will wait for the flag to turn true before loading.

relation
Type : string

The name of the resource. If given, the generic ListResource loading will be used (api.resourceList)

solo
Type : boolean

If true, only one item is selectable next

autoFocusFirst
Default value : false
Inherited from ListComponent
Defined in ListComponent:58

If true, the first item in the list will always be focused after changed

collection
Type : Collection<T>
Inherited from ListComponent
Defined in ListComponent:42

The used collection

config
Type : ListConfig<T>
Inherited from ListComponent
Defined in ListComponent:38
items
Type : Array<T>
Inherited from ListComponent
Defined in ListComponent:40

The visible items

list
Type : List<T>
Inherited from ListComponent
Defined in ListComponent:52

The Instance of the List

pagination
Type : Pagination<T>
Inherited from ListComponent
Defined in ListComponent:54

Pagination that should be used

paginationConfig
Type : PaginationConfig
Inherited from ListComponent
Defined in ListComponent:56

Custom PaginationConfig

selection
Type : Selection<T>
Inherited from ListComponent
Defined in ListComponent:44

The used selection

solo
Type : boolean
Inherited from ListComponent
Defined in ListComponent:46

If true, only one item is selectable next

Outputs

changed
Type : EventEmitter<List<T>>
Inherited from ListComponent
Defined in ListComponent:62

emits after the list changed

columnClicked
Type : EventEmitter<Item<T>>
Inherited from ListComponent
Defined in ListComponent:48

Event emitter on item selection

selected
Type : EventEmitter<Selection<T>>
Inherited from ListComponent
Defined in ListComponent:50

Event emitter on selection change

Methods

Protected createList
createList()

The method to create the list

Returns : Promise | ResourceList
filter
filter(property: string, value: any)

This method will filter the list by a given property value and optional operator.

Parameters :
Name Type Optional
property string No
value any No
Returns : Promise<any>
initFilterQuery
initFilterQuery(fieldFilter: (property: string,value: any) => void)
Parameters :
Name Type Optional
fieldFilter function No
Returns : void
ngOnChanges
ngOnChanges(changes?)

When changing the model or the config, the list will update

Parameters :
Name Optional
changes Yes
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
update
update()

Creates/Updates the list and subscribes Observables.

Returns : void
columnClick
columnClick(item)
Inherited from ListComponent
Defined in ListComponent:104

Column click handler. Triggers select.emit(item) with fallback to selection.toggle

Parameters :
Name Optional
item No
Returns : any
filter
filter(property, value)
Inherited from ListComponent
Defined in ListComponent:162

Filters the list

Parameters :
Name Optional
property No
value No
Returns : void
focusFirst
focusFirst()
Inherited from ListComponent
Defined in ListComponent:130
Returns : void
focusNext
focusNext()
Inherited from ListComponent
Defined in ListComponent:136

Selects the next item

Returns : void
focusPrev
focusPrev()
Inherited from ListComponent
Defined in ListComponent:149

Selects the previous item

Returns : void
init
init(list: List)
Inherited from ListComponent
Defined in ListComponent:77
Parameters :
Name Type Optional
list List<T> No
Returns : void
ngOnChanges
ngOnChanges(changes?)
Inherited from ListComponent
Defined in ListComponent:68

Changing items or collection will trigger reconstructing the list with the new items. Changing the selection will reconstruct the selection

Parameters :
Name Optional
changes Yes
Returns : void
selectIndex
selectIndex(index: number)
Inherited from ListComponent
Defined in ListComponent:123

Selects the item with the given index

Parameters :
Name Type Optional
index number No
Returns : void
showHeader
showHeader()
Inherited from ListComponent
Defined in ListComponent:112

Decides if the header should be visible or not

Returns : any

Properties

Public cdr
Type : ChangeDetectorRef
list
Type : ResourceList

The instance of an EntryList

Public listConfig
Type : ListConfigService
resourceConfig
Type : ResourceConfig
Public route
Type : ActivatedRoute
Decorators :
@Optional()
Public cdr
Type : ChangeDetectorRef
Inherited from ListComponent
Defined in ListComponent:64
config
Type : ListConfig<T>
Default value : {}
Inherited from ListComponent
Defined in ListComponent:33

The current list config

focusItem
Type : Item<T>
Inherited from ListComponent
Defined in ListComponent:60

Current focus

isLoading
Default value : false
Inherited from ListComponent
Defined in ListComponent:36

Config input for List

Public listConfig
Type : ListConfigService
Inherited from ListComponent
Defined in ListComponent:64
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnChanges, OnDestroy, Optional } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import {
  componentDestroyed, ListComponent,
  ListConfigService,





  listTemplate, LoaderComponent,
  LoaderService,
  NotificationsService,
  SymbolService,
  WithLoader
} from '@ec.components/ui';
import Core from 'ec.sdk/lib/Core';
import ListResource from 'ec.sdk/lib/resources/ListResource';
import Resource from 'ec.sdk/lib/resources/Resource';
import { takeUntil } from 'rxjs/operators';
import { ResourceConfig } from '../resource-config/resource-config.service';
import { ResourceService } from '../resource-config/resource.service';
import { SdkService } from '../sdk/sdk.service';
import { ResourceList } from './resource-list';

/** The ResourceListComponent is an extension of ListComponent for SDK ListResources.
 * It is meant to be extended and overriden the createList method. See e.g. AssetListComponent. */
@Component({
  selector: 'ec-resource-list',
  template: listTemplate,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ResourceListComponent extends ListComponent<Resource> implements OnChanges, WithLoader, OnDestroy {
  resourceConfig: ResourceConfig;
  /** If listResource input is set, the given ListResource will be used directly and loading will be skipped. */
  @Input() listResource: ListResource;
  /** If true, only one item is selectable next */
  @Input() solo: boolean;
  /** If set to false, the list will wait for the flag to turn true before loading. */
  @Input() loadWhen: boolean;
  /** The instance of an EntryList */
  list: ResourceList;
  /** The API Connector that possesses the resource list, see https://entrecode.github.io/ec.sdk/#api-connectors */
  @Input() api: Core; // sdk api connector
  /** The name of the resource. If given, the generic ListResource loading will be used (api.resourceList) */
  @Input() relation: string;
  /** The loader that should be shown while the list is loaded. */
  @Input() loader: LoaderComponent;

  /** The constructor will just call super of List*/
  constructor(
    protected loaderService: LoaderService,
    protected sdk: SdkService,
    protected notificationService: NotificationsService,
    protected symbol: SymbolService,
    protected resourceService: ResourceService,
    public listConfig: ListConfigService,
    public cdr: ChangeDetectorRef,
    @Optional() public route: ActivatedRoute,
  ) {
    super(listConfig, cdr);
    this.resourceConfig = this.resourceService.config;
    if (route) {
      route.queryParams.subscribe((query) => {
        this.config.query = Object.assign({}, query);
      });
    }
  }

  /** The method to create the list*/
  protected createList(): Promise<ResourceList | void> | ResourceList {
    if (!this.relation || !this.api) {
      return;
      // return Promise.reject(`cannot create ResourceList: no relation or api given. Relation: ${this.relation} API: ${this.api}`);
    }
    const namespace = this.relation.split('.')[0];
    this.config = Object.assign({}, this.resourceConfig.get(namespace) || {}, this.config || {});

    this.resourceService.change({ relation: namespace })
      .pipe(takeUntil(componentDestroyed(this)))
      .subscribe((update) => {
        this.list.load();
      });

    return new ResourceList(this.config, this.api, this.relation, this.listResource);
  }

  ngOnDestroy() {
  }

  /** Creates/Updates the list and subscribes Observables.  */
  update() {
    if (this.loadWhen === false) {
      return;
    }
    this.config = Object.assign(this.config || {}, this.configInput || {});
    Promise.resolve(this.createList()).then((list) => {
      if (!list) {
        return;
      }
      this.init(list);
      if (this.list.promise) {
        this.loaderService.wait(this.list.promise, this.loader);
      }
      this.list.loading$.subscribe((promise: Promise<any>) => {
        this.loaderService.wait(promise, this.loader);
        this.isLoading = true;
        this.cdr.markForCheck();
        promise.then(() => {
          this.isLoading = false;
          this.cdr.markForCheck();
        });
      });
      this.list.error$.subscribe((err) => {
        this.notificationService.emit({
          title: this.symbol.resolve('error.load'),
          error: err,
        });
      });
    });
  }

  /** When changing the model or the config, the list will update*/
  ngOnChanges(changes?) {
    if (changes && changes.relation && changes.relation.previousValue) {
      this.config = this.configInput;
      delete this.selection;
    }
    this.update();
  }

  /** This method will filter the list by a given property value and optional operator. */
  filter(property: string, value: any): Promise<any> {
    return this.list.filter(property, value);
  }

  initFilterQuery(fieldFilter: (property: string, value: any) => { property; value }) {
    if (!this.config.query || !this.config.fields || !fieldFilter) {
      return;
    }
    Object.keys(this.config.query)
      .filter((property) => fieldFilter(property, this.config.query[property]))
      .map((property) => fieldFilter(property, this.config.query[property]))
      .filter((filter) => {
        return Object.keys(this.config.fields).indexOf(filter.property) !== -1;
      })
      .forEach((filter) => {
        this.config.filter = Object.assign(this.config.filter || {}, {
          [filter.property]: filter.value,
        });
      });
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""