mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2367] [Demo shell] Fix default site (#3004)
* fix default site scenario * add default my files object in the list
This commit is contained in:
@@ -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)="onSiteChange($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">
|
||||||
|
@@ -365,8 +365,8 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSiteContent(site: SiteEntry) {
|
onSiteChange(site: SiteEntry) {
|
||||||
this.currentFolderId = site && site.entry.guid ? site.entry.guid : DEFAULT_FOLDER_TO_SHOW;
|
this.currentFolderId = site.entry.guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDocumentListCurrentFolderId() {
|
getDocumentListCurrentFolderId() {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<div id="site-dropdown-container" class="adf-site-dropdown-container">
|
<div id="site-dropdown-container" class="adf-site-dropdown-container">
|
||||||
<mat-form-field>
|
<mat-form-field>
|
||||||
<mat-select
|
<mat-select
|
||||||
|
data-automation-id="site-my-files-option"
|
||||||
class="adf-site-dropdown-list-element"
|
class="adf-site-dropdown-list-element"
|
||||||
id="site-dropdown"
|
id="site-dropdown"
|
||||||
placeholder="{{placeholder | translate}}"
|
placeholder="{{placeholder | translate}}"
|
||||||
@@ -8,7 +9,6 @@
|
|||||||
data-automation-id="site-my-files-select"
|
data-automation-id="site-my-files-select"
|
||||||
[(value)]="selected"
|
[(value)]="selected"
|
||||||
(selectionChange)="selectedSite($event)">
|
(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 *ngFor="let site of siteList?.list.entries" [value]="site">
|
<mat-option *ngFor="let site of siteList?.list.entries" [value]="site">
|
||||||
{{ site.entry.title | translate}}
|
{{ site.entry.title | translate}}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
|
@@ -23,7 +23,33 @@ import { DropdownSitesComponent } from './sites-dropdown.component';
|
|||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
let sitesList = {
|
describe('DropdownSitesComponent', () => {
|
||||||
|
|
||||||
|
let component: any;
|
||||||
|
let fixture: ComponentFixture<DropdownSitesComponent>;
|
||||||
|
let debug: DebugElement;
|
||||||
|
let element: HTMLElement;
|
||||||
|
let sitesList: any;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
MaterialModule
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
DropdownSitesComponent
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(DropdownSitesComponent);
|
||||||
|
debug = fixture.debugElement;
|
||||||
|
element = fixture.nativeElement;
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
|
||||||
|
sitesList = {
|
||||||
'list': {
|
'list': {
|
||||||
'pagination': {
|
'pagination': {
|
||||||
'count': 2,
|
'count': 2,
|
||||||
@@ -58,31 +84,6 @@ let sitesList = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('DropdownSitesComponent', () => {
|
|
||||||
|
|
||||||
let component: any;
|
|
||||||
let fixture: ComponentFixture<DropdownSitesComponent>;
|
|
||||||
let debug: DebugElement;
|
|
||||||
let element: HTMLElement;
|
|
||||||
|
|
||||||
beforeEach(async(() => {
|
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
imports: [
|
|
||||||
MaterialModule
|
|
||||||
],
|
|
||||||
declarations: [
|
|
||||||
DropdownSitesComponent
|
|
||||||
]
|
|
||||||
}).compileComponents();
|
|
||||||
}));
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
fixture = TestBed.createComponent(DropdownSitesComponent);
|
|
||||||
debug = fixture.debugElement;
|
|
||||||
element = fixture.nativeElement;
|
|
||||||
component = fixture.componentInstance;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Rendering tests', () => {
|
describe('Rendering tests', () => {
|
||||||
@@ -128,13 +129,14 @@ describe('DropdownSitesComponent', () => {
|
|||||||
responseText: sitesList
|
responseText: sitesList
|
||||||
});
|
});
|
||||||
|
|
||||||
openSelectbox();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(window.document.querySelector('[data-automation-id="site-my-files-option"]')).not.toBeNull();
|
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||||
|
fixture.detectChanges();
|
||||||
|
let options: any = debug.queryAll(By.css('mat-option'));
|
||||||
|
expect(options[0].nativeElement.innerText).toContain('DROPDOWN.MY_FILES_OPTION');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}));
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -145,11 +147,12 @@ describe('DropdownSitesComponent', () => {
|
|||||||
responseText: sitesList
|
responseText: sitesList
|
||||||
});
|
});
|
||||||
|
|
||||||
openSelectbox();
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(window.document.querySelector('[data-automation-id="site-my-files-option"]')).toBeNull();
|
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||||
|
fixture.detectChanges();
|
||||||
|
let options: any = debug.queryAll(By.css('mat-option'));
|
||||||
|
expect(options[0].nativeElement.innerText).not.toContain('DROPDOWN.MY_FILES_OPTION');
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -219,12 +222,12 @@ describe('DropdownSitesComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
component.change.subscribe(() => {
|
component.change.subscribe(() => {
|
||||||
expect(options[1].nativeElement.innerText).toContain('PERSONAL_FILES');
|
expect(options[2].nativeElement.innerText).toContain('PERSONAL_FILES');
|
||||||
expect(options[2].nativeElement.innerText).toContain('FILE_LIBRARIES');
|
expect(options[3].nativeElement.innerText).toContain('FILE_LIBRARIES');
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should load sites by default', (done) => {
|
it('should load sites by default', async(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -232,23 +235,15 @@ describe('DropdownSitesComponent', () => {
|
|||||||
responseText: sitesList
|
responseText: sitesList
|
||||||
});
|
});
|
||||||
|
|
||||||
openSelectbox();
|
|
||||||
|
|
||||||
let options: any = [];
|
|
||||||
fixture.whenStable().then(() => {
|
fixture.whenStable().then(() => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
options = debug.queryAll(By.css('mat-option'));
|
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||||
options[0].triggerEventHandler('click', null);
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
let options: any = debug.queryAll(By.css('mat-option'));
|
||||||
|
|
||||||
component.change.subscribe(() => {
|
|
||||||
expect(options[1].nativeElement.innerText).toContain('fake-test-site');
|
expect(options[1].nativeElement.innerText).toContain('fake-test-site');
|
||||||
expect(options[2].nativeElement.innerText).toContain('fake-test-2');
|
expect(options[2].nativeElement.innerText).toContain('fake-test-2');
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
it('should raise an event when a site is selected', (done) => {
|
it('should raise an event when a site is selected', (done) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
@@ -18,7 +18,6 @@
|
|||||||
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',
|
||||||
@@ -57,18 +56,14 @@ export class DropdownSitesComponent implements OnInit {
|
|||||||
|
|
||||||
selected: SiteEntry = null;
|
selected: SiteEntry = null;
|
||||||
|
|
||||||
public MY_FILES_VALUE = 'default';
|
public MY_FILES_VALUE = '-my-';
|
||||||
|
|
||||||
constructor(private sitesService: SitesService) {
|
constructor(private sitesService: SitesService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (!this.siteList) {
|
if (!this.siteList) {
|
||||||
this.setDefaultSiteList().subscribe((result) => {
|
this.setDefaultSiteList();
|
||||||
this.selected = this.siteList.list.entries.find(site => site.entry.id === this.value);
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -77,16 +72,25 @@ export class DropdownSitesComponent implements OnInit {
|
|||||||
this.change.emit(event.value);
|
this.change.emit(event.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private setDefaultSiteList(): Observable<SitePaging> {
|
private setDefaultSiteList() {
|
||||||
let sitesObservable = this.sitesService.getSites();
|
this.sitesService.getSites().subscribe((result) => {
|
||||||
|
|
||||||
sitesObservable.subscribe((result) => {
|
|
||||||
this.siteList = result;
|
this.siteList = result;
|
||||||
|
|
||||||
|
if (!this.hideMyFiles) {
|
||||||
|
let myItem = { entry: { id: '-my-', guid: '-my-', title: 'DROPDOWN.MY_FILES_OPTION' } };
|
||||||
|
|
||||||
|
this.siteList.list.entries.unshift(myItem);
|
||||||
|
|
||||||
|
if (!this.value) {
|
||||||
|
this.value = '-my-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.selected = this.siteList.list.entries.find(site => site.entry.id === this.value);
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
return sitesObservable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -80,7 +80,6 @@ export function createTranslateLoader(http: HttpClient, logService: LogService)
|
|||||||
return new TranslateLoaderService(http, logService);
|
return new TranslateLoaderService(http, logService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function providers() {
|
export function providers() {
|
||||||
return [
|
return [
|
||||||
AuthenticationService,
|
AuthenticationService,
|
||||||
|
Reference in New Issue
Block a user