File
Implements
Metadata
selector |
ec-upload-select |
templateUrl |
./upload-select.component.html |
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Outputs
|
|
options
|
Type : FileOptions
|
Default value : Object.assign({}, this.fileService.defaultOptions)
|
|
Methods
setGroup
|
setGroup(group)
|
|
Sets the asset group to upload to
|
toggleUrlInput
|
toggleUrlInput()
|
|
|
triggerUpload
|
triggerUpload(e)
|
|
|
uploadFromUrls
|
uploadFromUrls(urls, e)
|
|
Parameters :
Name |
Optional |
urls |
No
|
e |
No
|
|
Public
focusEvent
|
Type : EventEmitter<boolean>
|
Default value : new EventEmitter()
|
|
The event that focuses the url input
|
showUrlInput
|
Default value : false
|
|
Wether or not the url input should be visible
|
uploader
|
Type : UploadComponent
|
Decorators :
@ViewChild(UploadComponent)
|
|
The nested upload component
|
urlsToUpload
|
Type : string
|
Default value : ''
|
|
|
import { Component, OnInit, Input, EventEmitter, Output, ViewChild } from '@angular/core';
import { LoaderComponent } from '@ec.components/ui';
import { CrudConfig } from '../../crud/crud-config.interface';
import DMAssetResource from 'ec.sdk/lib/resources/publicAPI/DMAssetResource';
import PublicAssetResource from 'ec.sdk/lib/resources/publicAPI/PublicAssetResource';
import { SymbolService } from '@ec.components/ui';
import { UploadComponent } from '../upload/upload.component';
import { Upload, FileOptions, FileService } from '../file.service';
@Component({
selector: 'ec-upload-select',
templateUrl: './upload-select.component.html',
})
export class UploadSelectComponent implements OnInit {
@Input() readOnly: boolean;
@Input() custom: boolean;
@Input() disableDrop: boolean;
@Input() assetGroupID: string;
@Input() loader: LoaderComponent;
@Input() options: FileOptions = Object.assign({}, this.fileService.defaultOptions);
/** emits when the group has been set from the upload pop */
@Output() groupChanged: EventEmitter<string> = new EventEmitter();
/** Emits when an upload is complete. */
@Output() uploaded: EventEmitter<Upload> = new EventEmitter();
@Output() browse: EventEmitter<void> = new EventEmitter();
@Input() config: CrudConfig<DMAssetResource | PublicAssetResource>;
/** The nested upload component */
@ViewChild(UploadComponent) uploader: UploadComponent;
/** The Url to upload from */
urlsToUpload = '';
/** Wether or not the url input should be visible */
showUrlInput = false;
/** The event that focuses the url input */
public focusEvent: EventEmitter<boolean> = new EventEmitter();
constructor(public symbol: SymbolService, public fileService: FileService) {}
ngOnInit() {}
/** Sets the asset group to upload to */
setGroup(group) {
this.assetGroupID = group;
this.groupChanged.emit(group);
}
toggleUrlInput() {
this.showUrlInput = !this.showUrlInput;
setTimeout(() => {
this.focusEvent.emit(true);
});
}
uploadFromUrls(urls, e) {
this.uploader.uploadFiles(urls, e).then(() => {
this.urlsToUpload = '';
this.showUrlInput = false;
});
}
triggerUpload(e) {
this.uploader.trigger(e);
}
}
<div
class="file-upload ec-asset-upload ec-dropzone"
*ngIf="!readOnly"
(ecDropzone)="(uploader || uploaderChild)?.uploadFiles($event.dataTransfer.files, $event)"
[disabled]="disableDrop"
>
<div class="ec-dropzone__info">Drop to upload</div>
<ec-upload
[custom]="custom"
#uploaderChild
[options]="config.fileOptions"
(groupChanged)="setGroup($event)"
[loader]="loader"
[assetGroupID]="assetGroupID"
(success)="uploaded.emit($event)"
></ec-upload>
<div class="ec-asset-upload__controls">
<span [class.is-hidden]="showUrlInput">
<a (click)="triggerUpload($event)">{{ 'upload.link' | symbol }}</a>
<span *ngIf="!config?.disableUrlUpload && fileService.isNewAssetGroupID(assetGroupID)">
{{ 'upload.or' | symbol }}
<a (click)="toggleUrlInput()">{{ 'upload.url' | symbol }}</a>
</span>
<span *ngIf="!config?.disableListPop">
{{ 'upload.or' | symbol }}
<a (click)="browse.emit()">{{ 'upload.browse' | symbol }}</a>
</span>
</span>
<div [class.is-hidden]="!showUrlInput" data-flex="center">
<div class="input-group">
<input [(ngModel)]="urlsToUpload" placeholder="Enter URL..." class="input" type="text" [ecFocus]="focusEvent" />
<a class="btn" (click)="uploadFromUrls(urlsToUpload, $event)">{{ 'upload.url.start' | symbol }}</a>
</div>
<a (click)="toggleUrlInput()" class="btn btn_square btn_clear"><ec-icon name="close"></ec-icon></a>
</div>
</div>
</div>
Legend
Html element with directive