mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
ability to change position of the dropdown menu (left|right) (#1590)
* ability to change position of the dropdown menu (left|right) * unit tests
This commit is contained in:
committed by
Mario Romano
parent
5c5911beef
commit
7c54090dea
@@ -177,6 +177,7 @@ platformBrowserDynamic().bootstrapModule(AppModule);
|
|||||||
| `data` | DataTableAdapter | instance of **ObjectDataTableAdapter** | data source |
|
| `data` | DataTableAdapter | instance of **ObjectDataTableAdapter** | data source |
|
||||||
| `multiselect` | boolean | false | Toggles multiple row selection, renders checkboxes at the beginning of each row |
|
| `multiselect` | boolean | false | Toggles multiple row selection, renders checkboxes at the beginning of each row |
|
||||||
| `actions` | boolean | false | Toggles data actions column |
|
| `actions` | boolean | false | Toggles data actions column |
|
||||||
|
| `actionsPosition` | string (left\|right) | right | Position of the actions dropdown menu. |
|
||||||
| `fallbackThumbnail` | string | | Fallback image for row ehre thubnail is missing|
|
| `fallbackThumbnail` | string | | Fallback image for row ehre thubnail is missing|
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
@@ -3,6 +3,10 @@
|
|||||||
class="mdl-data-table mdl-js-data-table full-width mdl-data-table-fix-firefox">
|
class="mdl-data-table mdl-js-data-table full-width mdl-data-table-fix-firefox">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<!-- Actions (left) -->
|
||||||
|
<th *ngIf="actions && actionsPosition === 'left'" class="alfresco-datatable__actions-header">
|
||||||
|
<span class="sr-only">Actions</span>
|
||||||
|
</th>
|
||||||
<!-- Columns -->
|
<!-- Columns -->
|
||||||
<th *ngIf="multiselect">
|
<th *ngIf="multiselect">
|
||||||
<label
|
<label
|
||||||
@@ -23,8 +27,8 @@
|
|||||||
<span *ngIf="col.srTitle" class="sr-only">{{col.srTitle}}</span>
|
<span *ngIf="col.srTitle" class="sr-only">{{col.srTitle}}</span>
|
||||||
<span *ngIf="col.title">{{col.title}}</span>
|
<span *ngIf="col.title">{{col.title}}</span>
|
||||||
</th>
|
</th>
|
||||||
<!-- Actions -->
|
<!-- Actions (right) -->
|
||||||
<th *ngIf="actions">
|
<th *ngIf="actions && actionsPosition === 'right'" class="alfresco-datatable__actions-header">
|
||||||
<span class="sr-only">Actions</span>
|
<span class="sr-only">Actions</span>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -34,6 +38,23 @@
|
|||||||
<tr *ngFor="let row of data.getRows(); let idx = index" tabindex="0"
|
<tr *ngFor="let row of data.getRows(); let idx = index" tabindex="0"
|
||||||
class="alfresco-datatable__row"
|
class="alfresco-datatable__row"
|
||||||
[class.alfresco-datatable__row--selected]="selectedRow === row">
|
[class.alfresco-datatable__row--selected]="selectedRow === row">
|
||||||
|
|
||||||
|
<!-- Actions (right) -->
|
||||||
|
<td *ngIf="actions && actionsPosition === 'left'" class="alfresco-datatable__actions-cell">
|
||||||
|
<button [id]="'action_menu_' + idx" alfresco-mdl-button class="mdl-button--icon" [attr.data-automation-id]="actions_menu">
|
||||||
|
<i class="material-icons">more_vert</i>
|
||||||
|
</button>
|
||||||
|
<ul alfresco-mdl-menu class="mdl-menu--bottom-left"
|
||||||
|
[attr.for]="'action_menu_' + idx">
|
||||||
|
<li class="mdl-menu__item"
|
||||||
|
[attr.data-automation-id]="action.title"
|
||||||
|
*ngFor="let action of getRowActions(row)"
|
||||||
|
(click)="onExecuteRowAction(row, action)">
|
||||||
|
{{action.title}}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</td>
|
||||||
|
|
||||||
<td *ngIf="multiselect">
|
<td *ngIf="multiselect">
|
||||||
<label
|
<label
|
||||||
class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect mdl-data-table__select"
|
class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect mdl-data-table__select"
|
||||||
@@ -71,8 +92,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td *ngIf="actions">
|
<!-- Actions (right) -->
|
||||||
<!-- action menu -->
|
<td *ngIf="actions && actionsPosition === 'right'" class="alfresco-datatable__actions-cell">
|
||||||
<button [id]="'action_menu_' + idx" alfresco-mdl-button class="mdl-button--icon" [attr.data-automation-id]="actions_menu">
|
<button [id]="'action_menu_' + idx" alfresco-mdl-button class="mdl-button--icon" [attr.data-automation-id]="actions_menu">
|
||||||
<i class="material-icons">more_vert</i>
|
<i class="material-icons">more_vert</i>
|
||||||
</button>
|
</button>
|
||||||
|
@@ -15,6 +15,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
|
import { CoreModule } from 'ng2-alfresco-core';
|
||||||
import { DataTableComponent } from './datatable.component';
|
import { DataTableComponent } from './datatable.component';
|
||||||
import {
|
import {
|
||||||
DataRow,
|
DataRow,
|
||||||
@@ -26,23 +28,75 @@ import {
|
|||||||
|
|
||||||
describe('DataTable', () => {
|
describe('DataTable', () => {
|
||||||
|
|
||||||
|
let fixture: ComponentFixture<DataTableComponent>;
|
||||||
let dataTable: DataTableComponent;
|
let dataTable: DataTableComponent;
|
||||||
|
let element: any;
|
||||||
let eventMock: any;
|
let eventMock: any;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
CoreModule.forRoot()
|
||||||
|
],
|
||||||
|
declarations: [DataTableComponent]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(DataTableComponent);
|
||||||
|
dataTable = fixture.componentInstance;
|
||||||
|
element = fixture.debugElement.nativeElement;
|
||||||
|
|
||||||
|
// usernameInput = element.querySelector('#username');
|
||||||
|
// passwordInput = element.querySelector('#password');
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// reset MDL handler
|
// reset MDL handler
|
||||||
window['componentHandler'] = null;
|
window['componentHandler'] = null;
|
||||||
dataTable = new DataTableComponent();
|
// dataTable = new DataTableComponent();
|
||||||
|
|
||||||
eventMock = {
|
eventMock = {
|
||||||
preventDefault: function () {}
|
preventDefault: function () {}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should put actions menu to the right by default', () => {
|
||||||
|
dataTable.data = new ObjectDataTableAdapter([], [
|
||||||
|
<DataColumn> {},
|
||||||
|
<DataColumn> {},
|
||||||
|
<DataColumn> {}
|
||||||
|
]);
|
||||||
|
dataTable.actions = true;
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
let headers = element.querySelectorAll('th');
|
||||||
|
expect(headers.length).toBe(4);
|
||||||
|
expect(headers[headers.length - 1].classList.contains('alfresco-datatable__actions-header')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should put actions menu to the left', () => {
|
||||||
|
dataTable.data = new ObjectDataTableAdapter([], [
|
||||||
|
<DataColumn> {},
|
||||||
|
<DataColumn> {},
|
||||||
|
<DataColumn> {}
|
||||||
|
]);
|
||||||
|
dataTable.actions = true;
|
||||||
|
dataTable.actionsPosition = 'left';
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
let headers = element.querySelectorAll('th');
|
||||||
|
expect(headers.length).toBe(4);
|
||||||
|
expect(headers[0].classList.contains('alfresco-datatable__actions-header')).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
it('should initialize default adapter', () => {
|
it('should initialize default adapter', () => {
|
||||||
expect(dataTable.data).toBeUndefined();
|
let table = new DataTableComponent();
|
||||||
dataTable.ngOnInit();
|
expect(table.data).toBeUndefined();
|
||||||
expect(dataTable.data).toEqual(jasmine.any(ObjectDataTableAdapter));
|
table.ngOnInit();
|
||||||
|
expect(table.data).toEqual(jasmine.any(ObjectDataTableAdapter));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should initialize with custom data', () => {
|
it('should initialize with custom data', () => {
|
||||||
|
@@ -44,6 +44,9 @@ export class DataTableComponent implements OnInit {
|
|||||||
@Input()
|
@Input()
|
||||||
actions: boolean = false;
|
actions: boolean = false;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
actionsPosition: string = 'right'; // left|right
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
fallbackThumbnail: string;
|
fallbackThumbnail: string;
|
||||||
|
|
||||||
|
@@ -181,6 +181,7 @@ The properties currentFolderId, folderNode and node are the entry initialization
|
|||||||
| `fallbackThumbnail` | string | | Path to fallback image to use if the row thumbnail is missing |
|
| `fallbackThumbnail` | string | | Path to fallback image to use if the row thumbnail is missing |
|
||||||
| `multiselect` | boolean | false | Toggles multiselect mode |
|
| `multiselect` | boolean | false | Toggles multiselect mode |
|
||||||
| `contentActions` | boolean | false | Toggles content actions for each row |
|
| `contentActions` | boolean | false | Toggles content actions for each row |
|
||||||
|
| `contentActionsPosition` | string (left\|right) | right | Position of the content actions dropdown menu. |
|
||||||
| `contextMenuActions` | boolean | false | Toggles context menus for each row |
|
| `contextMenuActions` | boolean | false | Toggles context menus for each row |
|
||||||
| `enablePagination` | boolean | true | Shows pagination |
|
| `enablePagination` | boolean | true | Shows pagination |
|
||||||
| `creationMenuActions` | boolean | true | Toggles the creation menu actions|
|
| `creationMenuActions` | boolean | true | Toggles the creation menu actions|
|
||||||
@@ -488,7 +489,7 @@ context.row.getValue('name')
|
|||||||
context.row.getValue('createdByUser.displayName')
|
context.row.getValue('createdByUser.displayName')
|
||||||
```
|
```
|
||||||
|
|
||||||
_You may want using **row** api to get raw value access.
|
You may want using **row** api to get raw value access.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<content-column title="Name" key="name" sortable="true" class="full-width ellipsis-cell">
|
<content-column title="Name" key="name" sortable="true" class="full-width ellipsis-cell">
|
||||||
|
@@ -7,6 +7,7 @@
|
|||||||
<alfresco-datatable
|
<alfresco-datatable
|
||||||
[data]="data"
|
[data]="data"
|
||||||
[actions]="contentActions"
|
[actions]="contentActions"
|
||||||
|
[actionsPosition]="contentActionsPosition"
|
||||||
[multiselect]="multiselect"
|
[multiselect]="multiselect"
|
||||||
[fallbackThumbnail]="fallbackThumbnail"
|
[fallbackThumbnail]="fallbackThumbnail"
|
||||||
(showRowContextMenu)="onShowRowContextMenu($event)"
|
(showRowContextMenu)="onShowRowContextMenu($event)"
|
||||||
|
@@ -74,6 +74,9 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
@Input()
|
@Input()
|
||||||
contentActions: boolean = false;
|
contentActions: boolean = false;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
contentActionsPosition: string = 'right'; // left|right
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
contextMenuActions: boolean = false;
|
contextMenuActions: boolean = false;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user