Skip to content

Commit

Permalink
fix(ionic/forms): render table header as text
Browse files Browse the repository at this point in the history
  • Loading branch information
sara-re authored and trik committed Oct 21, 2020
1 parent 3240bfc commit 5accdfb
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
/src/e2e-app/file-input/* @trik
/src/e2e-app/ion-calendar/* @trik
/src/e2e-app/ion-date-input-field/* @trik
/src/e2e-app/ion-table-field/* @trik
/src/e2e-app/mat-calendar/* @trik
/src/e2e-app/mat-date-input-field/* @trik
/src/e2e-app/mat-table-field/* @trik
Expand Down
1 change: 1 addition & 0 deletions src/e2e-app/e2e-app/e2e-app-layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<a mat-list-item [routerLink]="['file-input']">File input</a>
<a mat-list-item [routerLink]="['ion-calendar']">Ionic - Calendar</a>
<a mat-list-item [routerLink]="['ion-date-input-field']">Ionic - Date Input Field</a>
<a mat-list-item [routerLink]="['ion-table-field']">Ionic - Table Field</a>
<a mat-list-item [routerLink]="['mat-calendar']">Material - Calendar</a>
<a mat-list-item [routerLink]="['mat-date-input-field']">Material - Date Input Field</a>
<a mat-list-item [routerLink]="['mat-table-field']">Material - Table Field</a>
Expand Down
2 changes: 2 additions & 0 deletions src/e2e-app/e2e-app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Routes} from '@angular/router';
import {FileInputE2E} from '../file-input/file-input-e2e';
import {IonicCalendarE2E} from '../ion-calendar/calendar-e2e';
import {IonicDateInputFieldE2E} from '../ion-date-input-field/date-input-field-e2e';
import {IonicTableFieldE2E} from '../ion-table-field/table-field-e2e';
import {MaterialCalendarE2E} from '../mat-calendar/calendar-e2e';
import {MaterialDateInputFieldE2E} from '../mat-date-input-field/date-input-field-e2e';
import {MaterialTableFieldE2E} from '../mat-table-field/table-field-e2e';
Expand All @@ -12,6 +13,7 @@ export const E2E_APP_ROUTES: Routes = [
{path: 'file-input', component: FileInputE2E},
{path: 'ion-calendar', component: IonicCalendarE2E},
{path: 'ion-date-input-field', component: IonicDateInputFieldE2E},
{path: 'ion-table-field', component: IonicTableFieldE2E},
{path: 'mat-calendar', component: MaterialCalendarE2E},
{path: 'mat-date-input-field', component: MaterialDateInputFieldE2E},
{path: 'mat-table-field', component: MaterialTableFieldE2E},
Expand Down
39 changes: 39 additions & 0 deletions src/e2e-app/ion-table-field/table-field-e2e-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license
* Copyright (C) Gnucoop soc. coop.
*
* This file is part of the Advanced JSON forms (ajf).
*
* Advanced JSON forms (ajf) is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Advanced JSON forms (ajf) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
* General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Advanced JSON forms (ajf).
* If not, see http://www.gnu.org/licenses/.
*
*/

import {AjfFormsModule as CoreFormsModule} from '@ajf/core/forms';
import {AjfFormsModule} from '@ajf/ionic/forms';
import {NgModule} from '@angular/core';

import {IonicTableFieldE2E} from './table-field-e2e';

@NgModule({
imports: [
AjfFormsModule,
CoreFormsModule,
],
declarations: [
IonicTableFieldE2E,
],
})
export class IonicTableFieldE2eModule {
}
4 changes: 4 additions & 0 deletions src/e2e-app/ion-table-field/table-field-e2e.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>Ionic Table Field Example</h1>
<section>
<ajf-form [form]="form"></ajf-form>
</section>
45 changes: 45 additions & 0 deletions src/e2e-app/ion-table-field/table-field-e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {AjfForm, AjfFormSerializer} from '@ajf/core/forms';
import {Component, ViewEncapsulation} from '@angular/core';

const formSchema: any = {
nodes: [{
parent: 0,
id: 7,
name: 'table1',
label: 'Ionic Table Field Example',
nodeType: 3,
nodes: [{
id: 701,
parent: 7,
name: 'row',
rows: [['value1', 'value2', 'value3'], ['value4', 'value5', 'value6']],
label: '2.1',
editable: true,
nodeType: 0,
fieldType: 11,
rowLabels: [
'Row 1',
'Row 2',
],
columnLabels: ['Label 1', 'Label 2', 'Label 3']
}]
}]
};

@Component({
selector: 'ion-table-field-e2e',
templateUrl: 'table-field-e2e.html',
styles: [`
.ajf-slider-container {
min-height: 400px;
}`],
encapsulation: ViewEncapsulation.None
})
export class IonicTableFieldE2E {
formSchema: string = JSON.stringify(formSchema);
form: AjfForm;

constructor() {
this.form = AjfFormSerializer.fromJson(formSchema);
}
}
2 changes: 2 additions & 0 deletions src/e2e-app/main-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {E2E_APP_ROUTES} from './e2e-app/routes';
import {FileInputE2eModule} from './file-input/file-input-e2e-module';
import {IonicCalendarE2eModule} from './ion-calendar/calendar-e2e-module';
import {IonicDateInputFieldE2eModule} from './ion-date-input-field/date-input-field-e2e-module';
import {IonicTableFieldE2eModule} from './ion-table-field/table-field-e2e-module';
import {MaterialCalendarE2eModule} from './mat-calendar/calendar-e2e-module';
import {MaterialDateInputFieldE2eModule} from './mat-date-input-field/date-input-field-e2e-module';
import {MaterialTableFieldE2eModule} from './mat-table-field/table-field-e2e-module';
Expand All @@ -27,6 +28,7 @@ import {MaterialTableFieldE2eModule} from './mat-table-field/table-field-e2e-mod
FileInputE2eModule,
IonicCalendarE2eModule,
IonicDateInputFieldE2eModule,
IonicTableFieldE2eModule,
MaterialCalendarE2eModule,
MaterialDateInputFieldE2eModule,
MaterialTableFieldE2eModule,
Expand Down
23 changes: 23 additions & 0 deletions src/ionic/forms/table-field.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {browser, by, element, ExpectedConditions, Key} from 'protractor';

describe('ajf-table-field', () => {
beforeEach(async () => await browser.get('/ion-table-field'));

it('should show a table field', async () => {
expect(await element(by.className('ajf-table-field')).isPresent()).toBe(true);
const cells = await element.all(by.tagName('td')).getWebElements();
expect(cells.length).toBe(12);
cells.forEach(async cell => console.log(await cell.getText()));
expect(await cells[0].getText()).toBe('2.1');
expect(await cells[4].getText()).toBe('Row 1');
expect(await cells[8].getText()).toBe('Row 2');
});

it('should show table header', async () => {
const cells = await element.all(by.tagName('td')).getWebElements();
cells.forEach(async cell => console.log(await cell.getText()));
expect(await cells[1].getText()).toBe('Label 1');
expect(await cells[2].getText()).toBe('Label 2');
expect(await cells[3].getText()).toBe('Label 3');
});
});
26 changes: 15 additions & 11 deletions src/ionic/forms/table-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@
</td>
<ng-container *ngIf="columns.length > 1">
<td *ngFor="let c of columns[1]; let column = index">
<ng-container *ngIf="c|ajfGetTableCellControl as contr">
<ng-container *ngIf="contr != null">
<input *ngIf="row > 0 && contr.show && (node.rows[row-1][column]|ajfIsCellEditable); else plainTextCell"
(focusout)="contr!.show = false" type="number" [formControl]="contr.control" autoFocus>
<ng-template #plainTextCell>
<span *ngIf="row > 0; else labelCell" class="ajf-table-cell"
(click)="goToCell(row, column)">{{ contr.control!.value | ajfTranslateIfString | ajfFormatIfNumber: '.0-2' }}</span>
<ng-template #labelCell>{{ contr | ajfTranslateIfString | ajfFormatIfNumber: '.0-2' }}</ng-template>
</ng-template>
</ng-container>
<ng-container *ngIf="row == 0; else controlCell">
{{ c | ajfTranslateIfString | ajfFormatIfNumber: '.0-2' }}
</ng-container>
<ng-template #controlCell>
<ng-container *ngIf="c|ajfGetTableCellControl as contr">
<ng-container *ngIf="contr != null">
<input *ngIf="contr.show && (node.rows[row-1][column]|ajfIsCellEditable); else plainTextCell"
(focusout)="contr!.show = false" type="number" [formControl]="contr.control" autoFocus>
<ng-template #plainTextCell>
<span class="ajf-table-cell"
(click)="goToCell(row, column)">{{ contr.control!.value | ajfTranslateIfString | ajfFormatIfNumber: '.0-2' }}</span>
</ng-template>
</ng-container>
</ng-container>
</ng-template>
</td>
</ng-container>
</tr>
</ng-container>
</ng-container>
</table>
</table>

0 comments on commit 5accdfb

Please sign in to comment.