File

repository/shared/select-modal/repository-select-modal.component.ts

Description

RepositorySelectModalComponent displays repository entries options and allows to select them.

import { take } from 'rxjs/operators';
import { RepositorySelectModalComponent, ModalSelectionMode, RepositoryType } from '@c8y/ngx-components/repository/shared';

const initialState = {
  repositoryType: RepositoryType.FIRMWARE,
  title: gettext('Install firmware'),
  subTitle: gettext('Available firmwares matching the device type'),
  icon: 'c8y-firmware',
  mode: ModalSelectionMode.SINGLE,
  labels: { ok: gettext('Install') },
  disableSelected: false
};

const modal = this.bsModal.show(RepositorySelectModalComponent, {
  ignoreBackdropClick: true,
  initialState
});

modal.content.load.next();
modal.content.resultEmitter.pipe(take(1)).subscribe((firmware) => {
  ...
})

Metadata

Index

Properties
Methods

Constructor

constructor(repositoryService: RepositoryService, translateService: TranslateService)
Parameters :
Name Type Optional
repositoryService RepositoryService No
translateService TranslateService No

Methods

Async aggregate
aggregate(mos: IManagedObject[])
Parameters :
Name Type Optional
mos IManagedObject[] No
getAndAssignRepositoryBinaries
getAndAssignRepositoryBinaries(mos: IManagedObject[])
Parameters :
Name Type Optional
mos IManagedObject[] No
Returns : {}
getSelectModalObject
getSelectModalObject(repositoryEntry: RepositoryCategory, options: ISelectModalOption[])
Parameters :
Name Type Optional
repositoryEntry RepositoryCategory No
options ISelectModalOption[] No
Returns : ISelectModalObject
getSelectModalOptions
getSelectModalOptions(versions: RepositoryBinary[], selectedItems: SelectedRepositoryBinary[], repositoryEntry: RepositoryCategory, repositoryType: RepositoryType)
Parameters :
Name Type Optional
versions RepositoryBinary[] No
selectedItems SelectedRepositoryBinary[] No
repositoryEntry RepositoryCategory No
repositoryType RepositoryType No
isBinaryRepositorySelected
isBinaryRepositorySelected(selectedItems: SelectedRepositoryBinary[], repositoryEntry: RepositoryCategory, repositoryBinary: RepositoryBinary, repositoryType: RepositoryType)
Parameters :
Name Type Optional
selectedItems SelectedRepositoryBinary[] No
repositoryEntry RepositoryCategory No
repositoryBinary RepositoryBinary No
repositoryType RepositoryType No
Returns : boolean
ngOnInit
ngOnInit()
Returns : void
result
result(selectedItems: SelectedRepositoryBinary[])
Parameters :
Name Type Optional
selectedItems SelectedRepositoryBinary[] No
Returns : void
search
search(filterCriteria: FilterCriteria)
Parameters :
Name Type Optional
filterCriteria FilterCriteria No
Returns : void

Properties

additionalFilterTemplate
Type : TemplateRef<any>

Optional Allows to provide additional template that will be rendered in the filters block on top of the results list in the select modal.

areMoreEntries
Type : boolean
Default value : false

Optional Allows to show a warning that the search criteria should be narrowed down. By default, this warning is hidden.

badgeTemplates
Type : object
Default value : { '=1': gettext('{{count}} version'), other: gettext('{{count}} versions') }

Optional Allows to use custom badges templates.

import { gettext } from '@c8y/ngx-components';

const badgeTemplates = { '=1': gettext('{{count}} version'), other: gettext('{{count}} versions') };
const initialState = { badgeTemplates };
deviceTypeQuery
Type : any
Default value : {}

Optional Allows to provide device type query to restrict search criteria. Only takes effect when repositoryEntriesWithVersions$ is not provided, otherwise modal's caller have to provide already filtered data in the repositoryEntriesWithVersions$.

disableSelected
Type : boolean
Default value : true

Allows to block selection of the other versions from the same repository entry.

filterCriteria
Type : FilterCriteria
Default value : {}
icon
Type : string

Optional Allows to use custom icon in the modal header.

labels
Type : ModalLabels
Default value : { ok: gettext('Save') }

Optional Allows to provide custom labels for the buttons responsible for confirm/dismiss modal actions.

load
Type : Subject<void>
Default value : new Subject()

Loads the content of the modal. Must be invoked by the modal's caller.

modalEntries
Type : Observable<ISelectModalObject[]>
Default value : merge( this.repositoryEntries$, this.updateInstallableList$.pipe( map((updateItemEvent: IUpdateItemEvent<any>) => { const itemToUpdate: ISelectModalObject = (this.repositoryEntries || []).find( item => item.groupId === updateItemEvent.object.groupId ); if (itemToUpdate) { const optionToUpdate: ISelectModalOption = (itemToUpdate.options || []).find( option => option.obj.id === (updateItemEvent.object as any).selectedId ); if (optionToUpdate) { optionToUpdate.template = updateItemEvent.template; if (updateItemEvent.mapper) { optionToUpdate.obj = updateItemEvent.mapper(optionToUpdate.obj); } } } return this.repositoryEntries; }) ) )
mode
Type : ModalSelectionMode
Default value : ModalSelectionMode.SINGLE

Optional Allows to change selection mode. Supported options:

  • single: only single option can be selected.
  • multiple: multiple options can be selected.
onChoiceUpdated
Type : EventEmitter<ISelectModalObject>
Default value : new EventEmitter<ISelectModalObject>()

Emits whenever a new repository binary have been selected in the modal.

repositoryEntries$
Type : Observable<ISelectModalObject[]>
Default value : this.load.pipe( switchMap(() => this.repositoryEntriesWithVersions$), mergeMap(mos => this.aggregate(mos)), tap(items => { this.areMoreEntries = items.length >= this.PAGE_SIZE ? true : false; }), tap(items => (this.repositoryEntries = items)) )
repositoryEntriesWithVersions$
Type : Observable<IManagedObject[]>
Default value : undefined

Optional Allows to provide custom data.

import { from } from 'rxjs';

const repositoryEntry = { name: 'ExampleEntry', type: 'c8y_Firmware' };
const versions = [{ c8y_Firmware: { version: '1.0.0', url: 'http://example.com' } }];

const initialState = {repositoryEntriesWithVersions$: from({ ...repositoryEntry, versions })};
repositoryType
Type : RepositoryType.FIRMWARE | RepositoryType.SOFTWARE

Repository entry type.

resultEmitter
Type : EventEmitter<SelectedRepositoryBinary[]>
Default value : new EventEmitter< SelectedRepositoryBinary[] >()

Emits the list of selected options.

searchQuery
Type : any
Default value : {}

Optional Allows to provide query to restrict search criteria. Only takes effect when repositoryEntriesWithVersions$ is not provided, otherwise modal's caller have to provide already filtered data in the repositoryEntriesWithVersions$.

searchTerm
Type : BehaviorSubject<FilterCriteria>
Default value : new BehaviorSubject({})

Optional Emits a filter criteria object currently entered in the filter input. Use it to filter the items if you use custom repositoryEntriesWithVersions$.

selected
Type : SelectedRepositoryBinary[]

Optional Allows to pass the array of items. Each item from this array will be marked as selected in the modal.

showFilter
Type : boolean
Default value : true

Optional Allows to hide the name filter input field. By default, the filter input field is displayed.

subTitle
Type : string

Optional Allows to provide custom modal subtitle.

title
Type : string
Default value : gettext('Select repository entry')

Optional Allows to provide custom modal title.

updateInstallableList$
Type : Subject<IUpdateItemEvent<any>>
Default value : new Subject()

Triggers an update of the item list emitted.

<c8y-select-modal
  [icon]="icon"
  [title]="title"
  [subTitle]="subTitle"
  [items]="modalEntries | async"
  [mode]="mode"
  [disableSelected]="disableSelected"
  [labels]="labels"
  [showFilter]="showFilter"
  [additionalFilterTemplate]="additionalFilterTemplate"
  [areMoreEntries]="areMoreEntries"
  (search)="search({ name: $event })"
  (onChoiceUpdated)="onChoiceUpdated.emit($event)"
  (result)="result($event)"
>
</c8y-select-modal>

results matching ""

    No results matching ""