mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-968] Added Site Dropdown component to document list (#2093)
* [ADF-968] added demo project and new component * [ADF-968] added default option choice * [ADF-968] - moved site dropdown into documentlist * [ADF-968] fixed test for new component * [ADF-968] removed fdescribe for single cases * [ADF-968] fixed test to check rendering * [ADF-968] added conversion to Boolean forced by alfresco-js-api * [ADF-968]- moved site service into core * [ADF-968] reflected changes on js-api index * [ADF-968] fixed wrongly merged path from rebase * [ADF-968] fixed wrongly merged path from rebase * [ADF-968] fixed import problem on demo shell demo * [ADF-968] revert changes on package.json * [ADF-968] removed wrong package-lock * [ADF-968] applied changes from PR * [ADF-968] reindented file html
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
- [Breadcrumb Component](#breadcrumb-component)
|
||||
* [Properties](#properties-1)
|
||||
* [Events](#events-1)
|
||||
- [Dropdown Site Component](#dropdown-site-component)
|
||||
* [Events](#events-2)
|
||||
- [Menu Actions](#menu-actions)
|
||||
- [Custom columns](#custom-columns)
|
||||
* [DataColumn Properties](#datacolumn-properties)
|
||||
@@ -33,11 +35,13 @@
|
||||
+ [Folder actions](#folder-actions)
|
||||
* [Context Menu](#context-menu)
|
||||
* [Navigation mode](#navigation-mode)
|
||||
* [Events](#events-2)
|
||||
* [Events](#events-3)
|
||||
- [Advanced usage and customization](#advanced-usage-and-customization)
|
||||
* [Custom row filter](#custom-row-filter)
|
||||
* [Custom image resolver](#custom-image-resolver)
|
||||
* [Hiding columns on small screens](#hiding-columns-on-small-screens)
|
||||
* [Custom row permissions style](#custom-row-permissions-style)
|
||||
+ [Examples](#examples)
|
||||
* [Custom 'empty folder' template](#custom-empty-folder-template)
|
||||
* [Customizing default actions](#customizing-default-actions)
|
||||
- [Build from sources](#build-from-sources)
|
||||
@@ -357,6 +361,22 @@ DocumentList provides simple breadcrumb element to indicate the current position
|
||||
| --- | --- | --- |
|
||||
| navigate | [PathElementEntity](https://github.com/Alfresco/alfresco-js-api/blob/master/src/alfresco-core-rest-api/docs/PathElementEntity.md) |emitted when user clicks on a breadcrumb |
|
||||
|
||||
## Dropdown Site Component
|
||||
|
||||
DocumentList provides simple dropdown element to show sites for the current logged in user.
|
||||
|
||||
```html
|
||||
<adf-sites-dropdown
|
||||
(change)="getSiteContent($event)">
|
||||
</adf-sites-dropdown>
|
||||
```
|
||||
|
||||
### Events
|
||||
|
||||
| Name | Returned Type | Description |
|
||||
| --- | --- | --- |
|
||||
| change | [SiteModel](https://github.com/Alfresco/alfresco-ng2-components/blob/development/ng2-components/ng2-alfresco-documentlist/src/models/site.model.ts) | emitted when user select a site. When default option is selected an empty model is emitted |
|
||||
|
||||
## Menu Actions
|
||||
|
||||
DocumentList provides simple creation menu actions that provide the action to create a new folder.
|
||||
|
@@ -28,6 +28,7 @@ import { ContentColumnComponent } from './src/components/content-column/content-
|
||||
import { DocumentListComponent } from './src/components/document-list.component';
|
||||
import { DocumentMenuActionComponent } from './src/components/document-menu-action.component';
|
||||
import { EmptyFolderContentDirective } from './src/components/empty-folder/empty-folder-content.directive';
|
||||
import { DropdownSitesComponent } from './src/components/site-dropdown/sites-dropdown.component';
|
||||
import { MaterialModule } from './src/material.module';
|
||||
|
||||
import { DocumentActionsService } from './src/services/document-actions.service';
|
||||
@@ -43,6 +44,7 @@ export * from './src/components/content-action/content-action.component';
|
||||
export * from './src/components/content-action/content-action-list.component';
|
||||
export * from './src/components/empty-folder/empty-folder-content.directive';
|
||||
export * from './src/components/breadcrumb/breadcrumb.component';
|
||||
export * from './src/components/site-dropdown/sites-dropdown.component';
|
||||
|
||||
// data
|
||||
export * from './src/data/share-datatable-adapter';
|
||||
@@ -67,6 +69,7 @@ export const DOCUMENT_LIST_DIRECTIVES: any[] = [
|
||||
ContentActionListComponent,
|
||||
EmptyFolderContentDirective,
|
||||
BreadcrumbComponent,
|
||||
DropdownSitesComponent,
|
||||
DropdownBreadcrumbComponent
|
||||
];
|
||||
|
||||
|
@@ -0,0 +1,11 @@
|
||||
<div id="site-dropdown-container" class="adf-site-dropdown-container">
|
||||
<md-select class="adf-site-dropdown-list-element" id="site-dropdown"
|
||||
placeholder="{{'DROPDOWN.PLACEHOLDER_LABEL' | translate}}"
|
||||
[(ngModel)]="siteSelected"
|
||||
(ngModelChange)="selectedSite()">
|
||||
<md-option id="default_site_option" [value]="DEFAULT_VALUE">{{'DROPDOWN.DEFAULT_OPTION' | translate}}</md-option>
|
||||
<md-option *ngFor="let site of siteList" [value]="site.guid">
|
||||
{{ site.title }}
|
||||
</md-option>
|
||||
</md-select>
|
||||
</div>
|
@@ -0,0 +1,10 @@
|
||||
@import 'theming';
|
||||
|
||||
.adf-site-dropdown {
|
||||
|
||||
&-list-element {
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,160 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { DebugElement } from '@angular/core';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MdOptionModule, MdSelectModule } from '@angular/material';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { CoreModule } from 'ng2-alfresco-core';
|
||||
import { DropdownSitesComponent } from './sites-dropdown.component';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
let sitesList = {
|
||||
'list': {
|
||||
'pagination': {
|
||||
'count': 2,
|
||||
'hasMoreItems': false,
|
||||
'totalItems': 2,
|
||||
'skipCount': 0,
|
||||
'maxItems': 100
|
||||
},
|
||||
'entries': [
|
||||
{
|
||||
'entry': {
|
||||
'role': 'SiteManager',
|
||||
'visibility': 'PUBLIC',
|
||||
'guid': 'fake-1',
|
||||
'description': 'fake-test-site',
|
||||
'id': 'fake-test-site',
|
||||
'preset': 'site-dashboard',
|
||||
'title': 'fake-test-site'
|
||||
}
|
||||
},
|
||||
{
|
||||
'entry': {
|
||||
'role': 'SiteManager',
|
||||
'visibility': 'PUBLIC',
|
||||
'guid': 'fake-2',
|
||||
'description': 'This is a Sample Alfresco Team site.',
|
||||
'id': 'swsdp',
|
||||
'preset': 'site-dashboard',
|
||||
'title': 'fake-test-2'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
describe('DropdownSitesComponent', () => {
|
||||
|
||||
let component: any;
|
||||
let fixture: ComponentFixture<DropdownSitesComponent>;
|
||||
let debug: DebugElement;
|
||||
let element: HTMLElement;
|
||||
|
||||
beforeEach(async(() => {
|
||||
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot(),
|
||||
MdSelectModule,
|
||||
MdOptionModule
|
||||
],
|
||||
declarations: [
|
||||
DropdownSitesComponent
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(DropdownSitesComponent);
|
||||
debug = fixture.debugElement;
|
||||
element = fixture.nativeElement;
|
||||
component = fixture.componentInstance;
|
||||
});
|
||||
|
||||
describe('Rendering tests', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('Dropdown sites should be renedered', async(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
expect(element.querySelector('#site-dropdown-container')).toBeDefined();
|
||||
expect(element.querySelector('#site-dropdown')).toBeDefined();
|
||||
expect(element.querySelector('#site-dropdown-container')).not.toBeNull();
|
||||
expect(element.querySelector('#site-dropdown')).not.toBeNull();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'json',
|
||||
responseText: sitesList
|
||||
});
|
||||
}));
|
||||
|
||||
it('should load sites on init', async(() => {
|
||||
fixture.detectChanges();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'json',
|
||||
responseText: sitesList
|
||||
});
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||
fixture.detectChanges();
|
||||
let options: any = debug.queryAll(By.css('md-option'));
|
||||
expect(options[0].attributes['ng-reflect-value']).toBe('default');
|
||||
expect(options[1].attributes['ng-reflect-value']).toBe('fake-1');
|
||||
expect(options[2].attributes['ng-reflect-value']).toBe('fake-2');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should raise an event when a site is selected', (done) => {
|
||||
fixture.detectChanges();
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'json',
|
||||
responseText: sitesList
|
||||
});
|
||||
|
||||
fixture.whenStable().then(() => {
|
||||
fixture.detectChanges();
|
||||
debug.query(By.css('.mat-select-trigger')).triggerEventHandler('click', null);
|
||||
fixture.detectChanges();
|
||||
let options: any = debug.queryAll(By.css('md-option'));
|
||||
options[1].triggerEventHandler('click', null);
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
component.change.subscribe((site) => {
|
||||
expect(site.guid).toBe('fake-1');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,60 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
|
||||
import { AlfrescoTranslationService, SiteModel, SitesApiService } from 'ng2-alfresco-core';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-sites-dropdown',
|
||||
styleUrls: ['./sites-dropdown.component.scss'],
|
||||
templateUrl: './sites-dropdown.component.html'
|
||||
})
|
||||
export class DropdownSitesComponent implements OnInit {
|
||||
|
||||
@Output()
|
||||
change: EventEmitter<SiteModel> = new EventEmitter();
|
||||
|
||||
public DEFAULT_VALUE = 'default';
|
||||
|
||||
siteList = [];
|
||||
|
||||
public siteSelected: string;
|
||||
|
||||
constructor(translateService: AlfrescoTranslationService,
|
||||
private sitesService: SitesApiService) {
|
||||
if (translateService) {
|
||||
translateService.addTranslationFolder('ng2-alfresco-documentlist', 'assets/ng2-alfresco-documentlist');
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.sitesService.getSites().subscribe((result) => {
|
||||
this.siteList = result;
|
||||
});
|
||||
}
|
||||
|
||||
selectedSite() {
|
||||
let siteFound;
|
||||
if (this.siteSelected === this.DEFAULT_VALUE) {
|
||||
siteFound = new SiteModel();
|
||||
}else {
|
||||
siteFound = this.siteList.find( site => site.guid === this.siteSelected);
|
||||
}
|
||||
this.change.emit(siteFound);
|
||||
}
|
||||
|
||||
}
|
@@ -11,5 +11,9 @@
|
||||
"EMPTY": {
|
||||
"HEADER": "This folder is empty"
|
||||
}
|
||||
},
|
||||
"DROPDOWN": {
|
||||
"PLACEHOLDER_LABEL": "Site List",
|
||||
"DEFAULT_OPTION": "No Site Chosen"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user