[ADF-2312] Sites Dropdown component - default select option (#2994)

* fix gallery view sort drop down empty values
restore recent in main pace
trashcan example demo shell add multi select

* add selectable default value

* remove change delete directive

* remove fdescribe

* missing return type
This commit is contained in:
Eugenio Romano
2018-02-24 18:00:41 +00:00
committed by GitHub
parent a2ff6d85b0
commit 76cf4f178e
6 changed files with 75 additions and 35 deletions

View File

@@ -18,6 +18,7 @@
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { SitesService } from '@alfresco/adf-core';
import { SitePaging, SiteEntry } from 'alfresco-js-api';
import { Observable } from 'rxjs/Observable';
@Component({
selector: 'adf-sites-dropdown',
@@ -40,6 +41,10 @@ export class DropdownSitesComponent implements OnInit {
@Input()
siteList: SitePaging = null;
/** Id of the select site */
@Input()
value: string = null;
/** Text or a translation key to act as a placeholder. */
@Input()
placeholder: string = 'DROPDOWN.PLACEHOLDER_LABEL';
@@ -50,33 +55,38 @@ export class DropdownSitesComponent implements OnInit {
@Output()
change: EventEmitter<SiteEntry> = new EventEmitter();
selected: SiteEntry = null;
public MY_FILES_VALUE = 'default';
public siteSelected: string;
constructor(private sitesService: SitesService) {}
constructor(private sitesService: SitesService) {
}
ngOnInit() {
if (!this.siteList) {
this.setDefaultSiteList();
this.setDefaultSiteList().subscribe((result) => {
this.selected = this.siteList.list.entries.find(site => site.entry.id === this.value);
},
(error) => {
});
}
}
selectedSite() {
let siteFound;
if (this.siteSelected === this.MY_FILES_VALUE) {
siteFound = { entry: {}};
} else {
siteFound = this.siteList.list.entries.find( site => site.entry.guid === this.siteSelected);
}
this.change.emit(siteFound);
selectedSite(event: any) {
this.change.emit(event.value);
}
setDefaultSiteList() {
this.sitesService.getSites().subscribe((result) => {
private setDefaultSiteList(): Observable<SitePaging> {
let sitesObservable = this.sitesService.getSites();
sitesObservable.subscribe((result) => {
this.siteList = result;
},
(error) => {});
(error) => {
});
return sitesObservable;
}
}