File

packages/data/src/lib/files/asset-list-pop/asset-list-pop.component.ts

Description

Entry Pop is an extension of Pop component to host an entry-form. You can use it like a normal pop but with the extra handling of an entry form inside. You can call edit with an entry object to edit an entry, or just call show. It is also possible to bind an entry directly which will then be bound to the form.

Extends

PopComponent

Implements

OnInit

Metadata

selector ec-asset-list-pop
templateUrl ./asset-list-pop.component.html

Index

Properties
Methods
Inputs
Outputs
HostBindings
HostListeners

Constructor

constructor(popService: PopService, listConfig: ListConfigService, fileService: FileService, sdk: SdkService, elementRef: ElementRef, symbol: SymbolService, cdr: ChangeDetectorRef)

Injects auth service and calls super constructor.

Parameters :
Name Type Optional
popService PopService No
listConfig ListConfigService No
fileService FileService No
sdk SdkService No
elementRef ElementRef No
symbol SymbolService No
cdr ChangeDetectorRef No

Inputs

assetGroupID
Type : string

The assetGroupID that should be picked from. If empty, legacy assets are used

config
Type : CrudConfig<PublicAssetResource>
Default value : {}

CrudConfig for customizing the entry-form and the pop.

selection
Type : Selection<PublicAssetResource>

The used selection

active
Type : boolean
Inherited from PopComponent
Defined in PopComponent:28

If true, .ec-pop is part of the DOM (*ngIf) + .active is set on .ec-pop-container.

hideOnClickOutside
Default value : false
Inherited from PopComponent
Defined in PopComponent:34

If set to true, the pop will hide when a click happens outside the pop.

hideOnEscape
Default value : true
Inherited from PopComponent
Defined in PopComponent:36

If set to false, esc will not close the pop

type
Type : string
Inherited from PopComponent
Defined in PopComponent:32

The used type on the host element

Outputs

columnClicked
Type : EventEmitter<Item<PublicAssetResource>>

Event emitter on item selection

groupChanged
Type : EventEmitter<string>

Emits when the group changes

toggle
Type : EventEmitter<boolean>
Inherited from PopComponent
Defined in PopComponent:38

HostBindings

class
Default value : 'ec-asset-list-pop modal-wrapper modal-wrapper_backdrop'

Set host class to make sure the type is used

HostListeners

document:click
Arguments : '$event'
document:click($event)
Inherited from PopComponent
Defined in PopComponent:43

Listens for document:click and hides

Methods

filterByTags
filterByTags(tags)
Parameters :
Name Optional
tags No
Returns : void
filterByTypes
filterByTypes(types)
Parameters :
Name Optional
types No
Returns : void
getGroupRelation
getGroupRelation()

Returns the full resource relation name based on the current assetGroupID

Returns : string
isLegacy
isLegacy()
Returns : boolean
ngOnInit
ngOnInit()
Returns : void
pasted
pasted(e, list)
Parameters :
Name Optional
e No
list No
Returns : void
select
select($event)

emits columnClicked event or toggles selection if no observers.

Parameters :
Name Optional
$event No
Returns : void
selectID
selectID(id)
Parameters :
Name Optional
id No
Returns : void
setGroup
setGroup(group)

Changes the assetGroupID to the given value, emits groupChange

Parameters :
Name Optional
group No
Returns : void
Public hide
hide()
Inherited from PopComponent
Defined in PopComponent:88

Hides the pop. Sets active false and removes pop from popService.stack

Returns : void
isOutside
isOutside(element)
Inherited from PopComponent
Defined in PopComponent:58

yields true if the given element is outside the pop / or is the wrapper element itself (the backdrop)

Parameters :
Name Optional
element No
Returns : boolean
Public show
show(e?)
Inherited from PopComponent
Defined in PopComponent:72

Shows the pop. Sets active true and adds pop to popService.stack

Parameters :
Name Optional
e Yes
Returns : void
Public toggle
toggle(e?)
Inherited from PopComponent
Defined in PopComponent:63

Shows if not active, hides if active.

Parameters :
Name Optional
e Yes
Returns : void

Properties

Public assetGroups
Type : string[]

The loaded assetGroups

assetTypes
Type : []
Default value : [ { value: 'image', label: this.symbol.resolve('dmAsset.field.label.type.image') }, { value: 'video', label: this.symbol.resolve('dmAsset.field.label.type.video') }, { value: 'audio', label: this.symbol.resolve('dmAsset.field.label.type.audio') }, { value: 'plain', label: this.symbol.resolve('dmAsset.field.label.type.plain') }, { value: 'document', label: this.symbol.resolve('dmAsset.field.label.type.document') }, { value: 'spreadsheet', label: this.symbol.resolve('dmAsset.field.label.type.spreadsheet') }, { value: 'other', label: this.symbol.resolve('dmAsset.field.label.type.other') }, ]
Public cdr
Type : ChangeDetectorRef
Public elementRef
Type : ElementRef
Public fileService
Type : FileService
Public groupChange
Type : Subject<string>
Default value : new Subject()

Subject that is nexted when the items update

Public listConfig
Type : ListConfigService
Public popService
Type : PopService
resourceList
Type : ResourceListComponent
Decorators :
@ViewChild(ResourceListComponent)

The nested resource-list

Public sdk
Type : SdkService
searchbar
Type : SearchbarComponent
Decorators :
@ViewChild(SearchbarComponent)

The nested searchbar

Public symbol
Type : SymbolService
tagSelectConfig
Type : CrudConfig<PublicTagResource>
Default value : { disableCreatePop: true, disableListPop: true, methods: ['get'], }
typeSelectConfig
Type : object
Default value : { label: 'label', identifier: 'value', fields: { label: {}, }, }
uploadConfig
activated
Default value : false
Inherited from PopComponent
Defined in PopComponent:30

Flip and stays true after first show

clickEvent
Inherited from PopComponent
Defined in PopComponent:40
Public elementRef
Type : ElementRef
Inherited from PopComponent
Defined in PopComponent:55
import {
  ChangeDetectorRef,
  Component,
  ElementRef,
  EventEmitter,
  HostBinding,
  Input,
  OnInit,
  Output,
  ViewChild,
} from '@angular/core';
import { Item, Selection } from '@ec.components/core';
import { PopComponent, PopService, SearchbarComponent, SymbolService, ListConfigService } from '@ec.components/ui';
import PublicAssetResource from 'ec.sdk/lib/resources/publicAPI/PublicAssetResource';
import PublicTagResource from 'ec.sdk/lib/resources/publicAPI/PublicTagResource';
import { Subject } from 'rxjs';
import { CrudConfig } from '../../crud/crud-config.interface';
import { ResourceListComponent } from '../../resource-list/resource-list.component';
import { SdkService } from '../../sdk/sdk.service';
import { FileService } from '../file.service';

/** Entry Pop is an extension of Pop component to host an entry-form.
 * You can use it like a normal pop but with the extra handling of an entry form inside.
 * You can call edit with an entry object to edit an entry, or just call show.
 * It is also possible to bind an entry directly which will then be bound to the form.
 * */
@Component({
  selector: 'ec-asset-list-pop',
  templateUrl: './asset-list-pop.component.html',
})
export class AssetListPopComponent extends PopComponent implements OnInit {
  /** CrudConfig for customizing the entry-form and the pop.*/
  @Input() config: CrudConfig<PublicAssetResource> = {};
  /** The used selection */
  @Input() selection: Selection<PublicAssetResource>;
  /** The assetGroupID that should be picked from. If empty, legacy assets are used */
  @Input() assetGroupID: string;
  /** Event emitter on item selection */
  @Output() columnClicked: EventEmitter<Item<PublicAssetResource>> = new EventEmitter();
  /** Emits when the group changes */
  @Output() groupChanged: EventEmitter<string> = new EventEmitter();
  /** Subject that is nexted when the items update */
  public groupChange: Subject<string> = new Subject();
  /** The loaded assetGroups */
  public assetGroups: string[];
  /** The nested searchbar */
  @ViewChild(SearchbarComponent) searchbar: SearchbarComponent;
  /** The nested resource-list */
  @ViewChild(ResourceListComponent) resourceList: ResourceListComponent;
  uploadConfig: CrudConfig<PublicAssetResource> & { disableListPop: boolean };
  tagSelectConfig: CrudConfig<PublicTagResource> = {
    disableCreatePop: true,
    disableListPop: true,
    methods: ['get'],
  };
  assetTypes = [
    { value: 'image', label: this.symbol.resolve('dmAsset.field.label.type.image') },
    { value: 'video', label: this.symbol.resolve('dmAsset.field.label.type.video') },
    { value: 'audio', label: this.symbol.resolve('dmAsset.field.label.type.audio') },
    { value: 'plain', label: this.symbol.resolve('dmAsset.field.label.type.plain') },
    { value: 'document', label: this.symbol.resolve('dmAsset.field.label.type.document') },
    { value: 'spreadsheet', label: this.symbol.resolve('dmAsset.field.label.type.spreadsheet') },
    { value: 'other', label: this.symbol.resolve('dmAsset.field.label.type.other') },
  ];
  typeSelectConfig = {
    label: 'label',
    identifier: 'value',
    fields: {
      label: {},
    },
  };

  /** Set host class to make sure the type is used */
  @HostBinding('class') class = 'ec-asset-list-pop modal-wrapper modal-wrapper_backdrop';

  /** Injects auth service and calls super constructor. */
  constructor(
    public popService: PopService,
    public listConfig: ListConfigService,
    public fileService: FileService,
    public sdk: SdkService,
    public elementRef: ElementRef,
    public symbol: SymbolService,
    public cdr: ChangeDetectorRef,
  ) {
    super(popService, elementRef, cdr);
  }


  pasted(e, list) {
  }

  /** Changes the assetGroupID to the given value, emits groupChange */
  setGroup(group) {
    if (!group) {
      return;
    }
    this.groupChanged.emit(group);
    if (this.searchbar) {
      this.searchbar.clear();
      this.searchbar.focusEvent.emit(true);
    }
    this.assetGroupID = group;
  }

  filterByTags(tags) {
    this.resourceList.filter('tags', tags);
  }
  filterByTypes(types) {
    this.resourceList.filter('type', types);
  }

  ngOnInit() {
    this.fileService.assetGroupList().then((assetGroups) => {
      this.assetGroups = assetGroups;
    });
    this.uploadConfig = Object.assign({}, this.config, { disableListPop: true });
    this.config = Object.assign(
      this.fileService.getAssetConfig(this.assetGroupID),
      {
        hidePagination: true,
        disableHeader: true,
        fields: {
          thumb: {
            form: false,
            list: true,
            label: this.symbol.resolve('asset.field.label.thumb'),
            view: 'preview',
            resolve: (asset) => {
              if (asset.type !== 'image' || !asset.thumbnails || !asset.thumbnails.length) {
                return '';
              }
              return asset.thumbnails[0].url;
            },
            immutable: true,
            disabled: true
          },
          title: {
            label: '',
            classes: 'is-fit',
          },
        },
      },
      this.config,
    );
  }

  selectID(id) {
    if (this.getGroupRelation() === 'legacyAsset') {
      console.warn('This is not supported by legacy assets');
      return;
    }
    this.resourceList.list.load({ filter: { assetID: id } });
  }

  /** emits columnClicked event or toggles selection if no observers. */
  select($event) {
    if (this.columnClicked.observers.length) {
      this.columnClicked.emit($event);
    } else if (this.selection) {
      this.selection.toggle($event);
    }
    this.searchbar.focusEvent.emit(true);
  }

  /** Returns the full resource relation name based on the current assetGroupID  */
  getGroupRelation() {
    return this.fileService.isOldAssetGroupID(this.assetGroupID) ? 'legacyAsset' : 'dmAsset.' + this.assetGroupID;
  }

  isLegacy() {
    return this.getGroupRelation() === 'legacyAsset';
  }

  /*   showTagSelect() {
      return this.config.hideAssetGroupSelect === false;
    } */
}
<div
  class="asset-list-pop modal ec-dropzone"
  *ngIf="active"
  (ecDropzone)="uploadSelect?.uploader?.uploadFiles($event.dataTransfer.files, $event)"
  [attr.data-col]="config?.popColumns || 12"
>
  <button (click)="hide()" class="modal__dismiss" type="button">
    <ec-icon name="close"></ec-icon>
  </button>
  <div class="ec-dropzone__info">Drop to upload</div>
  <div class="modal__header">
    <ec-upload-select
      (uploaded)="fileService.selectUpload($event, selection)"
      #uploadSelect
      [disableDrop]="true"
      [config]="uploadConfig"
      [assetGroupID]="assetGroupID"
    ></ec-upload-select>
    <div data-grid="small-gutter" *ngIf="active && sdk.apiResolved">
      <div data-col="6@md">
        <ec-searchbar
          #searchbar
          [listComponent]="resourceList"
          [list]="resourceList"
          (pasted)="pasted($event, resourceList)"
        ></ec-searchbar>
      </div>
      <div data-col="6@md" *ngIf="!isLegacy()">
        <div data-grid="small-gutter">
          <div data-col="6@sm">
            <ec-resource-select
              (changed)="filterByTags($event.getValue())"
              placeholder="Tags.."
              [config]="tagSelectConfig"
              relation="tags"
              [api]="sdk.api"
            ></ec-resource-select>
          </div>
          <div data-col="6@sm">
            <ec-select
              (changed)="filterByTypes($event.getValue())"
              placeholder="Types..."
              [config]="typeSelectConfig"
              [values]="assetTypes"
            ></ec-select>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="modal__body">
    <ec-resource-list
      #resourceList
      [relation]="getGroupRelation()"
      [api]="sdk.api"
      [selection]="selection"
      (columnClicked)="select($event)"
      [config]="config"
      [loader]="popLoader"
      class="ec-asset-list"
    >
      <div data-ec-list-empty-filtered>
        <p>
          {{ 'list.filter.noResults' | symbol }}
          <a (click)="resourceList?.list?.clearFilter()">{{ 'list.filter.reset' | symbol }}</a>
        </p>
        <a
          *ngIf="!!listConfig.getFilteredID(resourceList?.list)"
          (click)="selectID(listConfig.getFilteredID(resourceList?.list))"
          >Select ID</a
        >
      </div>
    </ec-resource-list>
    <!-- (changed)="searchbar.updatedList($event)" -->
  </div>
  <div class="modal__footer">
    <ec-pagination [pagination]="resourceList?.list?.pagination"></ec-pagination>
  </div>
  <ec-loader #popLoader class="ec-loader loader is-global"></ec-loader>
</div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""