Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the support for the Item Control grid extension. #117

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"ts-node": "~10.9.1",
"tslint": "~6.1.3",
"typescript": "~4.8.4",
"webpack-cli": "^4.10.0"
"webpack-cli": "^4.10.0",
"lodash": "^4.17.21"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to add another 70KB unless it's absolutely necessary. forEach and includes could be done without lodash.

}
}
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { SafeHtmlPipe } from './safe-html.pipe';
import { LhcButtonPopoverComponent } from './lhc-button-popover/lhc-button-popover.component';
import { LhcItemAttachmentComponent } from './lhc-item-attachment/lhc-item-attachment.component';
import { LhcItemMessagesComponent } from './lhc-item-messages/lhc-item-messages.component';
import { LhcItemGirdComponent } from './lhc-item-gird/lhc-item-gird.component';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename it to lhc-group-grid as it is similar to lhc-group-matrix.

Copy link
Contributor

@lhcye lhcye Jan 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and LhcGroupGridComponent



registerLocaleData(en);
Expand Down Expand Up @@ -87,7 +88,8 @@ registerLocaleData(en);
SafeHtmlPipe,
LhcButtonPopoverComponent,
LhcItemAttachmentComponent,
LhcItemMessagesComponent
LhcItemMessagesComponent,
LhcItemGirdComponent
],
imports: [
BrowserModule,
Expand Down
3 changes: 3 additions & 0 deletions src/app/lhc-form/lhc-form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<ng-container *ngSwitchCase="'matrix'">
<lhc-group-matrix [item]="lhcFormData" [formLevel]='true'></lhc-group-matrix>
</ng-container>
<ng-container *ngSwitchCase="'grid'">
<lhc-item-gird [item]="lhcFormData" [formLevel]='true'></lhc-item-gird>
</ng-container>
<!-- vertical -->
<ng-container *ngSwitchDefault>
<!-- data row, for each item -->
Expand Down
Empty file.
51 changes: 51 additions & 0 deletions src/app/lhc-item-gird/lhc-item-gird.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<div *ngIf="item" class="lhc-layout-grid lf-table-item {{lhcDataService.getSiblingStatus(item)}}">
<div class="lf-form-grid-table-title" *ngIf="!formLevel">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CSS class names starting with 'lf-' are legacy names used in the previous versions of lforms, and will be cleaned up eventually. Please use 'lhc-' when adding new CSS class names.

<lhc-item-question-text [item]="item"></lhc-item-question-text>
</div>

<table class="lf-form-grid-table lf-form-table">
<colgroup>
<col class="lf-question">
<col *ngFor="let answer of item.items[0].answers">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of columns should be from item.items, right? The "other-answer" is not needed. Your implementation looks similar to the "matrix" ("table in fhir itemControl). If that's what you need, "matrix" has been implemented in lforms.

There was discussion on chat.fhir.org (https://chat.fhir.org/#narrow/stream/179255-questionnaire/topic/Grid.20Question) that the items under each group are not necessary same. The grid could be sparse.

<col class="other-answer" *ngIf="item.items[0].dataType ==='CWE'">
</colgroup>
<thead>

<tr class="lhc-grid-table-header-row">
<th class="lhc-form-grid-table-header"></th>
<th class="lhc-form-grid-table-header">{{item.question}}</th>
<th *ngFor="let header of uniqueGridHeaders; index as i;" class="lhc-form-grid-table-header"
id="answer-{{index}}">{{header}}</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let subItem of item.items; trackBy: lhcDataService.trackByElementId">
<tr *ngIf="subItem && lhcDataService.targetShown(subItem) && !subItem._isHiddenFromView" role="radiogroup" aria-labeledby="label-{{subItem._elementId }}"
aria-describedby="help-{{ subItem._parentItem._elementId }} help-{{ subItem._elementId }}">
<td class="lf-question">
<lhc-item-question-text [item]="subItem"></lhc-item-question-text>
<lhc-item-messages [item]="subItem"></lhc-item-messages>
</td>

<td>
<div class="lf-form-item-data tooltipContainer">
<lhc-item-question [item]="subItem" [options]="{hideQuestionText: true}" class="lhc-de">
</lhc-item-question>
</div>
</td>

<ng-container *ngFor="let cell of subItem.items; trackBy: lhcDataService.trackByElementId">
<td *ngIf="cell && lhcDataService.targetShown(cell) && !cell._isHiddenFromView"
class="{{lhcDataService.getRowClass(cell)}} {{lhcDataService.getSkipLogicClass(cell)}} {{lhcDataService.getActiveRowClass(cell)}}">
<div class="lf-form-item-data tooltipContainer">
<lhc-item-question [item]="cell" [options]="{hideQuestionText: true}" class="lhc-de">
</lhc-item-question>
</div>
</td>
</ng-container>

</tr>
</ng-container>
</tbody>
</table>
</div>
23 changes: 23 additions & 0 deletions src/app/lhc-item-gird/lhc-item-gird.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { LhcItemGirdComponent } from './lhc-item-gird.component';

describe('LhcItemGirdComponent', () => {
let component: LhcItemGirdComponent;
let fixture: ComponentFixture<LhcItemGirdComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ LhcItemGirdComponent ]
})
.compileComponents();

fixture = TestBed.createComponent(LhcItemGirdComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
32 changes: 32 additions & 0 deletions src/app/lhc-item-gird/lhc-item-gird.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Component, Input } from '@angular/core';
import { LhcDataService} from '../../lib/lhc-data.service';
import * as _ from "lodash";

@Component({
selector: 'lhc-item-gird',
templateUrl: './lhc-item-gird.component.html',
styleUrls: ['./lhc-item-gird.component.css']
})
export class LhcItemGirdComponent {


@Input() item;
@Input() formLevel: boolean = false;
uniqueGridHeaders: any[] = [];
constructor(public lhcDataService: LhcDataService) {
}

ngOnInit(): void {
this.createCustomHeaders(this.item);
}

createCustomHeaders(item): void{
_.forEach(item.items, (questionItems, key) => {
_.forEach(questionItems.items, (subItems,key) => {
if(!_.includes(this.uniqueGridHeaders, subItems.question) && subItems.skipLogic?.conditions[0]?.trigger?.value != 'alwaysHide'){
this.uniqueGridHeaders.push(subItems.question);
}
});
});
}
}
3 changes: 3 additions & 0 deletions src/app/lhc-item-group/lhc-item-group.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
<ng-container *ngSwitchCase="'vertical'">
<lhc-group-vertical [item]="item"></lhc-group-vertical>
</ng-container>
<ng-container *ngSwitchCase="'grid'">
<lhc-item-gird [item]="item"></lhc-item-gird>
</ng-container>
</ng-container>
10 changes: 8 additions & 2 deletions src/fhir/sdc-import-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,13 +801,19 @@ function addCommonSDCImportFns(ns) {
break;
case 'Table': // backward-compatibility with old export
case 'gtable': // Not in STU3, but we'll accept it
if(lfItem.dataType === 'SECTION') {
if (lfItem.dataType === 'SECTION') {
displayControl.questionLayout = "horizontal";
}
break;

case 'grid': // Not in STU3, but we'll accept it
if (lfItem.dataType === 'SECTION') {
displayControl.questionLayout = "grid";
}
break;
case 'Matrix': // backward-compatibility with old export
case 'table':
if(lfItem.dataType === 'SECTION') {
if (lfItem.dataType === 'SECTION') {
displayControl.questionLayout = "matrix";
}
break;
Expand Down
61 changes: 61 additions & 0 deletions src/grid-table.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*** grid layout ***/
.lhc-form .lhc-layout-grid.lhc-item {
padding-bottom: 2px;
}
.lhc-form .lf-form-grid-table {
border-collapse: separate;
border-radius: 4px;
box-sizing: border-box;
margin: 2px 4px 0 1px;
text-align: left;
border: 1px solid #ced5d9;
}
.lhc-form .lf-form-grid-table .lhc-grid-table-header-row {
background: #E8E8E8;
}

.lhc-form-grid-table-header {
overflow: hidden;
vertical-align: top;
background: none repeat scroll 0 0 #E8E8E8;
padding: 4px 2px;
text-align: left ;
color: #666666;
font-weight: 400;
-moz-border-radius: 4px;
border-radius: 4px;
}

.lhc-form .lf-form-grid-table-title {
background: #e6f1ff; /*#E8E8E8;*/
-moz-border-radius: 4px;
border-radius: 4px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin: 0 0 0 1px;
text-align: left;

border-width: 0;
border-top: 2px solid white; /* leave space between headers */
padding: 4px 2px 4px 2px;
}
.lhc-form .lf-form-grid-table .lf-question {
width: 25%;
}
.lhc-form .lf-form-grid-answer {
padding-left: 5px;
padding-right: 5px;
}

.lhc-form .lf-form-grid-cell-other {
text-align: center;
}
.lhc-form .lf-form-grid-table th {
padding: 4px;
}
.lhc-form .lf-form-grid-table td {
padding: 4px;
border-top: 1px solid #ced5d9;
}
/*** end of grid layout ***/
4 changes: 4 additions & 0 deletions src/lhc-form.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@
.lhc-form.lf-template-table .lhc-layout-matrix {
padding-right: 6px;
}
/*** grid layout ***/
.lhc-form.lf-template-table .lhc-layout-grid {
padding-right: 6px;
}

/* not to show title when the entire form is in horizontal or matrix layout */
.lf-top-section .lhc-layout-horizontal .lhc-form-horizontal-table-title,
Expand Down
17 changes: 17 additions & 0 deletions src/treeline-bar.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@
}
/* end of tree lines */

/*no tree lines for form level horizontal and grid layouts */
.lf-top-section .lhc-layout-grid.lhc-item,
.lf-top-section .lhc-layout-grid.lhc-item {
padding: 0 4px 0 3px;
}
.lf-top-section .lhc-layout-horizontal.lhc-item::before,
.lf-top-section .lhc-layout-grid.lhc-item::before {
border: 0;
}
.lf-top-section .lhc-layout-horizontal.lhc-item::after,
.lf-top-section .lhc-layout-grid.lhc-item::after {
border: 0;
}
/* end of tree lines */



/* bar style */
/* no horizontal bar */
.lf-indentation-bar .lhc-item::before {
Expand Down