mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -9,7 +9,7 @@
|
|||||||
</mat-expansion-panel-header>
|
</mat-expansion-panel-header>
|
||||||
|
|
||||||
<adf-document-list
|
<adf-document-list
|
||||||
[currentFolderId]="'-sharedlinks-'"
|
[currentFolderId]="'-recent-'"
|
||||||
locationFormat="/files"
|
locationFormat="/files"
|
||||||
[cardview]="true"
|
[cardview]="true"
|
||||||
[showHeader]="false"
|
[showHeader]="false"
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
</mat-accordion>
|
</mat-accordion>
|
||||||
|
|
||||||
<div class="adf-site-container-style" id="site-container">
|
<div class="adf-site-container-style" id="site-container">
|
||||||
<adf-sites-dropdown (change)="getSiteContent($event)" [hideMyFiles]="false">
|
<adf-sites-dropdown (change)="getSiteContent($event)" [hideMyFiles]="false" >
|
||||||
</adf-sites-dropdown>
|
</adf-sites-dropdown>
|
||||||
</div>
|
</div>
|
||||||
<div class="document-list-container" fxLayout="row" fxLayoutAlign="start stretch" fxLayoutGap="16px">
|
<div class="document-list-container" fxLayout="row" fxLayoutAlign="start stretch" fxLayoutGap="16px">
|
||||||
|
@@ -23,7 +23,8 @@ Displays a dropdown menu to show and interact with the sites of the current user
|
|||||||
| hideMyFiles | boolean | false | Hide the "My Files" option added to the list by default |
|
| hideMyFiles | boolean | false | Hide the "My Files" option added to the list by default |
|
||||||
| siteList | [SitePaging](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SitePaging.md) | null | A custom list of sites to be displayed by the dropdown. If no value is given, the sites of the current user are displayed by default. A list of objects only with properties 'title' and 'guid' is enough to be able to display the dropdown. |
|
| siteList | [SitePaging](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/SitePaging.md) | null | A custom list of sites to be displayed by the dropdown. If no value is given, the sites of the current user are displayed by default. A list of objects only with properties 'title' and 'guid' is enough to be able to display the dropdown. |
|
||||||
| placeholder | string | 'DROPDOWN.PLACEHOLDER_LABEL' | The placeholder text/the key from translation files for the placeholder text to be shown by default |
|
| placeholder | string | 'DROPDOWN.PLACEHOLDER_LABEL' | The placeholder text/the key from translation files for the placeholder text to be shown by default |
|
||||||
|
| value | string | null | Id of the select site |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
| Name | Returned Type | Description |
|
| Name | Returned Type | Description |
|
||||||
|
@@ -6,10 +6,10 @@
|
|||||||
placeholder="{{placeholder | translate}}"
|
placeholder="{{placeholder | translate}}"
|
||||||
floatPlaceholder="never"
|
floatPlaceholder="never"
|
||||||
data-automation-id="site-my-files-select"
|
data-automation-id="site-my-files-select"
|
||||||
[(ngModel)]="siteSelected"
|
[(value)]="selected"
|
||||||
(ngModelChange)="selectedSite()">
|
(selectionChange)="selectedSite($event)">
|
||||||
<mat-option *ngIf="!hideMyFiles" data-automation-id="site-my-files-option" id="default_site_option" [value]="MY_FILES_VALUE">{{'DROPDOWN.MY_FILES_OPTION' | translate}}</mat-option>
|
<mat-option *ngIf="!hideMyFiles" data-automation-id="site-my-files-option" id="default_site_option" [value]="MY_FILES_VALUE">{{'DROPDOWN.MY_FILES_OPTION' | translate}}</mat-option>
|
||||||
<mat-option *ngFor="let site of siteList?.list.entries" [value]="site.entry.guid">
|
<mat-option *ngFor="let site of siteList?.list.entries" [value]="site">
|
||||||
{{ site.entry.title | translate}}
|
{{ site.entry.title | translate}}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
|
@@ -122,7 +122,11 @@ describe('DropdownSitesComponent', () => {
|
|||||||
it('should show the "My files" option by default', async(() => {
|
it('should show the "My files" option by default', async(() => {
|
||||||
component.hideMyFiles = false;
|
component.hideMyFiles = false;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: sitesList });
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: sitesList
|
||||||
|
});
|
||||||
|
|
||||||
openSelectbox();
|
openSelectbox();
|
||||||
|
|
||||||
@@ -135,7 +139,11 @@ describe('DropdownSitesComponent', () => {
|
|||||||
it('should hide the "My files" option if the developer desires that way', async(() => {
|
it('should hide the "My files" option if the developer desires that way', async(() => {
|
||||||
component.hideMyFiles = true;
|
component.hideMyFiles = true;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: sitesList });
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: sitesList
|
||||||
|
});
|
||||||
|
|
||||||
openSelectbox();
|
openSelectbox();
|
||||||
|
|
||||||
@@ -147,7 +155,11 @@ describe('DropdownSitesComponent', () => {
|
|||||||
|
|
||||||
it('should show the default placeholder label by default', async(() => {
|
it('should show the default placeholder label by default', async(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: sitesList });
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: sitesList
|
||||||
|
});
|
||||||
|
|
||||||
openSelectbox();
|
openSelectbox();
|
||||||
|
|
||||||
@@ -160,7 +172,11 @@ describe('DropdownSitesComponent', () => {
|
|||||||
it('should show custom placeholder label when the \'placeholder\' input property is given a value', async(() => {
|
it('should show custom placeholder label when the \'placeholder\' input property is given a value', async(() => {
|
||||||
component.placeholder = 'NODE_SELECTOR.SELECT_LOCATION';
|
component.placeholder = 'NODE_SELECTOR.SELECT_LOCATION';
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json', responseText: sitesList });
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: sitesList
|
||||||
|
});
|
||||||
|
|
||||||
openSelectbox();
|
openSelectbox();
|
||||||
|
|
||||||
@@ -203,9 +219,8 @@ describe('DropdownSitesComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
component.change.subscribe(() => {
|
component.change.subscribe(() => {
|
||||||
expect(options[0].attributes['ng-reflect-value']).toBe('default');
|
expect(options[1].nativeElement.innerText).toContain('PERSONAL_FILES');
|
||||||
expect(options[1].attributes['ng-reflect-value']).toBe('-my-');
|
expect(options[2].nativeElement.innerText).toContain('FILE_LIBRARIES');
|
||||||
expect(options[2].attributes['ng-reflect-value']).toBe('-mysites-');
|
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -228,9 +243,8 @@ describe('DropdownSitesComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
component.change.subscribe(() => {
|
component.change.subscribe(() => {
|
||||||
expect(options[0].attributes['ng-reflect-value']).toBe('default');
|
expect(options[1].nativeElement.innerText).toContain('fake-test-site');
|
||||||
expect(options[1].attributes['ng-reflect-value']).toBe('fake-1');
|
expect(options[2].nativeElement.innerText).toContain('fake-test-2');
|
||||||
expect(options[2].attributes['ng-reflect-value']).toBe('fake-2');
|
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -249,7 +263,7 @@ describe('DropdownSitesComponent', () => {
|
|||||||
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
let options: any = debug.queryAll(By.css('mat-option'));
|
let options: any = debug.queryAll(By.css('mat-option'));
|
||||||
options[1].triggerEventHandler('click', null);
|
options[1].nativeElement.click();
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -258,5 +272,22 @@ describe('DropdownSitesComponent', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be possiblle to select the default value', (done) => {
|
||||||
|
component.value = 'swsdp';
|
||||||
|
fixture.detectChanges();
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: sitesList
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
expect(component.selected.entry.title).toBe('fake-test-2');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
|
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
|
||||||
import { SitesService } from '@alfresco/adf-core';
|
import { SitesService } from '@alfresco/adf-core';
|
||||||
import { SitePaging, SiteEntry } from 'alfresco-js-api';
|
import { SitePaging, SiteEntry } from 'alfresco-js-api';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-sites-dropdown',
|
selector: 'adf-sites-dropdown',
|
||||||
@@ -40,6 +41,10 @@ export class DropdownSitesComponent implements OnInit {
|
|||||||
@Input()
|
@Input()
|
||||||
siteList: SitePaging = null;
|
siteList: SitePaging = null;
|
||||||
|
|
||||||
|
/** Id of the select site */
|
||||||
|
@Input()
|
||||||
|
value: string = null;
|
||||||
|
|
||||||
/** Text or a translation key to act as a placeholder. */
|
/** Text or a translation key to act as a placeholder. */
|
||||||
@Input()
|
@Input()
|
||||||
placeholder: string = 'DROPDOWN.PLACEHOLDER_LABEL';
|
placeholder: string = 'DROPDOWN.PLACEHOLDER_LABEL';
|
||||||
@@ -50,33 +55,38 @@ export class DropdownSitesComponent implements OnInit {
|
|||||||
@Output()
|
@Output()
|
||||||
change: EventEmitter<SiteEntry> = new EventEmitter();
|
change: EventEmitter<SiteEntry> = new EventEmitter();
|
||||||
|
|
||||||
|
selected: SiteEntry = null;
|
||||||
|
|
||||||
public MY_FILES_VALUE = 'default';
|
public MY_FILES_VALUE = 'default';
|
||||||
|
|
||||||
public siteSelected: string;
|
constructor(private sitesService: SitesService) {
|
||||||
|
}
|
||||||
constructor(private sitesService: SitesService) {}
|
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (!this.siteList) {
|
if (!this.siteList) {
|
||||||
this.setDefaultSiteList();
|
this.setDefaultSiteList().subscribe((result) => {
|
||||||
|
this.selected = this.siteList.list.entries.find(site => site.entry.id === this.value);
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedSite() {
|
selectedSite(event: any) {
|
||||||
let siteFound;
|
this.change.emit(event.value);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setDefaultSiteList() {
|
private setDefaultSiteList(): Observable<SitePaging> {
|
||||||
this.sitesService.getSites().subscribe((result) => {
|
let sitesObservable = this.sitesService.getSites();
|
||||||
|
|
||||||
|
sitesObservable.subscribe((result) => {
|
||||||
this.siteList = result;
|
this.siteList = result;
|
||||||
},
|
},
|
||||||
(error) => {});
|
(error) => {
|
||||||
|
});
|
||||||
|
|
||||||
|
return sitesObservable;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -57,9 +57,7 @@ export class NodeDeleteDirective implements OnChanges {
|
|||||||
@Input('adf-delete')
|
@Input('adf-delete')
|
||||||
selection: MinimalNodeEntity[] | DeletedNodeEntity[];
|
selection: MinimalNodeEntity[] | DeletedNodeEntity[];
|
||||||
|
|
||||||
/** If true then the nodes are deleted immediately rather than being
|
/** If true then the nodes are deleted immediately rather than being put in the trash */
|
||||||
* put in the trash.
|
|
||||||
*/
|
|
||||||
@Input()
|
@Input()
|
||||||
permanent: boolean = false;
|
permanent: boolean = false;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user