Skip to content

Commit

Permalink
Bug/angular (surveyjs#5138)
Browse files Browse the repository at this point in the history
* Work for surveyjs/survey-creator#3623: rename SurveyAngularModule -> SurveyModule

* Angular: implement timer panel

* Angular: fix PopupSurveyComponent
  • Loading branch information
dk981234 committed Oct 31, 2022
1 parent f016ef0 commit e9c7df2
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 43 deletions.
6 changes: 3 additions & 3 deletions examples/angular-ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormsModule } from "@angular/forms";
import { BrowserModule } from "@angular/platform-browser";

import { AppComponent } from "./app.component";
import { SurveyAngularModule } from "survey-angular-ui";
import { SurveyModule } from "survey-angular-ui";
import { TestComponent } from "./components/test/test.component";
import { ExampleComponent } from "./components/example/example.component";
import { AppRoutingModule } from "./router.module";
Expand All @@ -23,12 +23,12 @@ import { CustomActionComponent } from "./components/test-custom-components/actio
CustomActionComponent
],
imports: [
BrowserModule, SurveyAngularModule, FormsModule, AppRoutingModule
BrowserModule, SurveyModule, FormsModule, AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
export class AppModule {
static declaration = [AngularItemTemplateComponent, CustomActionComponent]
}

4 changes: 2 additions & 2 deletions examples/angular-ui/src/app/components/test/test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export class TestComponent {
public isPopup: boolean;
constructor(private changeDetectorRef: ChangeDetectorRef) {
(window as any).Survey = Survey;
(<any>window).setSurvey = (survey: SurveyModel | Survey.PopupSurveyModel) => {
(<any>window).setSurvey = (survey: SurveyModel | Survey.PopupSurveyModel, isPopup: boolean) => {
this.model = survey;
this.isPopup = this.model instanceof Survey.PopupSurveyModel;
this.isPopup = isPopup;
this.changeDetectorRef.detectChanges();
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/survey-angular-ui/src/angular-ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import { ButtonGroupItemComponent } from "./questions/button-group/button-group-
import { MatrixRowComponent } from "./questions/matrix-row.component";
import { LogoImageComponent } from "./components/survey-header/logo-image.component";
import { SkeletonComponent } from "./components/skeleton/skeleton.component";
import { TimerPanelComponent } from "./components/timer-panel/timer-panel.component";
@NgModule({
declarations: [
VisibleDirective, Key2ClickDirective, PanelDynamicAddBtn, PanelDynamicNextBtn, PanelDynamicPrevBtn, PanelDynamicProgressText, ElementComponent, TemplateRendererComponent,
Expand All @@ -115,7 +116,7 @@ import { SkeletonComponent } from "./components/skeleton/skeleton.component";
SurveyHeaderComponent, ProgressDefaultComponent, ProgressButtonsComponent, SurveyNavigationButton, MatrixQuestionComponent, SvgIconComponent, FileQuestionComponent, SafeUrlPipe, SafeHtmlPipe, CommentQuestionComponent, SignaturePadQuestionComponent, ErrorsComponent,
MultipleTextComponent, MultipleTextItemComponent, DynamicComponentDirective, RankingQuestionComponent, RankingItemComponent, PanelDynamicQuestionComponent, EmbeddedViewContentComponent, CustomWidgetComponent, MatrixCellComponent, MatrixTableComponent, MatrixDropdownComponent,
MatrixDynamicComponent, MatrixDetailButtonComponent, MatrixDynamicRemoveButtonComponent, MatrixDynamicDragDropIconComponent, MatrixRequiredHeader, ExpressionComponent, SafeResourceUrlPipe, BrandInfoComponent,
CustomQuestionComponent, CompositeQuestionComponent, ButtonGroupItemComponent, ButtonGroupQuestionComponent, MatrixRowComponent, ModalComponent, LogoImageComponent, SkeletonComponent
CustomQuestionComponent, CompositeQuestionComponent, ButtonGroupItemComponent, ButtonGroupQuestionComponent, MatrixRowComponent, ModalComponent, LogoImageComponent, SkeletonComponent, TimerPanelComponent
],
imports: [
CommonModule, FormsModule
Expand All @@ -134,8 +135,8 @@ import { SkeletonComponent } from "./components/skeleton/skeleton.component";
SurveyHeaderComponent, ProgressDefaultComponent, ProgressButtonsComponent, SurveyNavigationButton, MatrixQuestionComponent, SvgIconComponent, FileQuestionComponent, SafeUrlPipe, SafeHtmlPipe, CommentQuestionComponent, SignaturePadQuestionComponent, ErrorsComponent,
MultipleTextComponent, MultipleTextItemComponent, DynamicComponentDirective, RankingQuestionComponent, RankingItemComponent, PanelDynamicQuestionComponent, EmbeddedViewContentComponent, CustomWidgetComponent, MatrixCellComponent, MatrixTableComponent, MatrixDropdownComponent,
MatrixDynamicComponent, MatrixDetailButtonComponent, MatrixDynamicRemoveButtonComponent, MatrixDynamicDragDropIconComponent, MatrixRequiredHeader, ExpressionComponent, SafeResourceUrlPipe, BrandInfoComponent,
CustomQuestionComponent, CompositeQuestionComponent, ButtonGroupQuestionComponent, ModalComponent, LogoImageComponent, SkeletonComponent
CustomQuestionComponent, CompositeQuestionComponent, ButtonGroupQuestionComponent, ModalComponent, LogoImageComponent, SkeletonComponent, TimerPanelComponent
],
providers: [PopupService],
})
export class SurveyAngularModule { }
export class SurveyModule { }
1 change: 1 addition & 0 deletions packages/survey-angular-ui/src/angular-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export * from "./components/element-header/element-header.component";
export * from "./components/element-title/element-title.component";
export * from "./components/survey-header/survey-header.component";
export * from "./components/skeleton/skeleton.component";
export * from "./components/timer-panel/timer-panel.component";

export * from "./components/element-title/dynamic-head.component";
export * from "./components/list/list.component";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component, Input } from "@angular/core";
import { Base, SurveyTimerModel } from "survey-core";
import { BaseAngular } from "../../base-angular";

@Component(
{
selector: "sv-timer-panel",
template: "<div class='model.survey.getCss().timerRoot'>{{model.text}}</div>"
}
)

export class TimerPanelComponent extends BaseAngular<SurveyTimerModel> {
@Input() model!: SurveyTimerModel;

protected getStateElement(): Base {
return this.model;
}
protected getModel(): SurveyTimerModel {
return this.model;
}
}
18 changes: 9 additions & 9 deletions packages/survey-angular-ui/src/popup.survey.component.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<div *ngIf="!!model && model.isShowing" [class]="model.cssRoot" style="position: fixed; bottom: 3px; right: 10px;" [style.width]="model.renderedWidth" [style.maxWidth]="model.renderedWidth">
<div [class]="model.cssHeaderRoot">
<span (click)="model.changeExpandCollapse()" style="width: 100%; cursor: pointer;">
<span style="padding-right:10px" [class]="model.cssHeaderTitle">{{model.locTitle.renderedHtml}}</span>
<span aria-hidden="true" [class]="model.cssButton"></span>
<div *ngIf="!!popup && popup.isShowing" [class]="popup.cssRoot" style="position: fixed; bottom: 3px; right: 10px;" [style.width]="popup.renderedWidth" [style.maxWidth]="popup.renderedWidth">
<div [class]="popup.cssHeaderRoot">
<span (click)="popup.changeExpandCollapse()" style="width: 100%; cursor: pointer;">
<span style="padding-right:10px" [class]="popup.cssHeaderTitle">{{popup.locTitle.renderedHtml}}</span>
<span aria-hidden="true" [class]="popup.cssButton"></span>
</span>
<span *ngIf="model.isExpanded" (click)="model.changeExpandCollapse()" style="float: right; cursor: pointer;">
<span style="padding-right:10px" [class]="model.cssHeaderTitle">X</span>
<span *ngIf="popup.isExpanded" (click)="popup.changeExpandCollapse()" style="float: right; cursor: pointer;">
<span style="padding-right:10px" [class]="popup.cssHeaderTitle">X</span>
</span>
</div>
<div *ngIf="model.isExpanded" [class]="model.cssBody">
<survey [model]="model.survey"></survey>
<div *ngIf="popup.isExpanded" [class]="popup.cssBody">
<survey [model]="popup.survey"></survey>
</div>
</div>
32 changes: 21 additions & 11 deletions packages/survey-angular-ui/src/popup.survey.component.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
import { ChangeDetectorRef, Component, Input } from "@angular/core";
import { ChangeDetectorRef, Component, Input, OnChanges, SimpleChanges } from "@angular/core";
import { PopupSurveyModel, SurveyModel } from "survey-core";
import { BaseAngular } from "./base-angular";
@Component({
selector: "popup-survey",
templateUrl: "./popup.survey.component.html",
styleUrls: ["./popup.survey.component.scss"]
})
export class PopupSurveyComponent extends BaseAngular<PopupSurveyModel> {
@Input() model!: PopupSurveyModel;
protected getModel(): PopupSurveyModel {
return this.model;
}
public get survey(): SurveyModel {
return this.model.survey;
}
export class PopupSurveyComponent extends BaseAngular<PopupSurveyModel> implements OnChanges {
@Input() model!: SurveyModel;
@Input() isExpanded?: boolean;
@Input() closeOnCompleteTimeout?: number;
public popup!: PopupSurveyModel;

constructor(changeDetectorRef: ChangeDetectorRef) {
super(changeDetectorRef);
changeDetectorRef.detach();
}
protected override onModelChanged(): void {
this.model.isShowing = true;
protected getModel(): PopupSurveyModel {
return this.popup;
}
ngOnChanges(changes: SimpleChanges): void {
if(changes["model"]?.currentValue !== changes["model"]?.previousValue) {
this.popup = new PopupSurveyModel(null, this.model);
}
if (this.isExpanded !== undefined) {
this.popup.isExpanded = this.isExpanded;
}
if (this.closeOnCompleteTimeout !== undefined) {
this.popup.closeOnCompleteTimeout = this.closeOnCompleteTimeout;
}
this.popup.isShowing = true;
this.changeDetectorRef.detectChanges();
}
}
14 changes: 6 additions & 8 deletions packages/survey-angular-ui/src/survey-content.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
<div class="sv_custom_header" [hidden]="model.hasLogo"></div>
<div [class]="model.css.container">
<div *ngIf="model.renderedHasHeader" [class]="model.css.header" [survey]="model" sv-ng-survey-header></div>
<ng-container *ngIf="model.isTimerPanelShowingOnTop && !model.isShowStartingPage">
<sv-timer-panel [model]="model.timerModel"></sv-timer-panel>
</ng-container>
<ng-container *ngIf="model.isShowProgressBarOnTop && !model.isShowStartingPage">
<ng-template [component]='{ name: "sv-progress-" + this.model.progressBarType, data: { model } }'></ng-template>
</ng-container>
<div *ngIf="model.isShowingPage" [class]="model.bodyCss" [style.width]="model.renderedWidth" [style.maxWidth]="model.renderedWidth">
<!-- ko if: isTimerPanelShowingOnTop && !isShowStartingPage -->
<!-- ko template: { name: 'survey-timerpanel' } -->
<!-- /ko -->
<!-- /ko -->
<sv-action-bar *ngIf="model.isNavigationButtonsShowingOnTop" [model]="model.navigationBar"></sv-action-bar>
<!-- ko if: activePage -->
<ng-container *ngIf="model.activePage">
Expand All @@ -24,13 +23,12 @@
<!-- /ko -->
<!-- /ko -->
<!-- /ko -->
<!-- ko if: isTimerPanelShowingOnBottom && !isShowStartingPage -->
<!-- ko template: { name: 'survey-timerpanel' } -->
<!-- /ko -->
<!-- /ko -->
<ng-container *ngIf="model.isShowProgressBarOnBottom && !model.isShowStartingPage">
<ng-template [component]='{ name: "sv-progress-" + this.model.progressBarType, data: { model } }'></ng-template>
</ng-container>
<ng-container *ngIf="model.isTimerPanelShowingOnBottom && !model.isShowStartingPage">
<sv-timer-panel [model]="model.timerModel"></sv-timer-panel>
</ng-container>
<sv-action-bar *ngIf="model.isNavigationButtonsShowingOnBottom" [model]="model.navigationBar"></sv-action-bar>
</div>
<div *ngIf="model.state === 'completed' && model.showCompletedPage" [class]="model.completedCss"
Expand Down
4 changes: 2 additions & 2 deletions packages/survey-angular-ui/test/events.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { TestBed } from "@angular/core/testing";
import { SurveyAngularModule } from "src/angular-ui.module";
import { SurveyModule } from "src/angular-ui.module";
import { SurveyComponent } from "src/survey.component";
import { SurveyModel } from "survey-core";

describe("event tests", () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SurveyAngularModule],
imports: [SurveyModule],
}).compileComponents();
TestBed;
});
Expand Down
6 changes: 3 additions & 3 deletions packages/survey-angular-ui/test/markup/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SurveyComponent } from "src/survey.component";
import { settings, StylesManager, SurveyModel } from "survey-core";
import { testQuestionMarkup } from "../../../../tests/markup/helper";
import { markupTests } from "../../../../tests/markup/etalon";
import { SurveyAngularModule } from "src/angular-ui.module";
import { SurveyModule } from "src/angular-ui.module";

const platformDescriptor = {
name: "Angular",
Expand Down Expand Up @@ -41,9 +41,9 @@ const blackList = [];
describe("etalon tests", () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SurveyAngularModule],
imports: [SurveyModule],
}).compileComponents();
TestBed.inject(SurveyAngularModule);
TestBed.inject(SurveyModule);
(<any>window).ResizeObserver = function () {
return {
observe: () => {},
Expand Down
99 changes: 99 additions & 0 deletions packages/survey-angular-ui/test/popup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { TestBed } from "@angular/core/testing";
import { SurveyModule } from "src/angular-ui.module";
import { PopupSurveyComponent } from "src/popup.survey.component";
import { SurveyModel } from "survey-core";

describe("popup survey tests", () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SurveyModule],
}).compileComponents();
TestBed;
});
it("check popup survey behavior", () => {
const fixture = TestBed.createComponent(PopupSurveyComponent);
const component = fixture.componentInstance;
let survey1 = new SurveyModel({});
let survey2 = new SurveyModel({});
component.model = survey1;
component.isExpanded = false;
component.ngOnChanges({ model: {
previousValue: undefined,
firstChange: true,
isFirstChange() {
return true;
},
currentValue: survey1,
},
isExpanded: {
previousValue: undefined,
firstChange: true,
isFirstChange() {
return true;
},
currentValue: false,
} });
expect(component.popup.isExpanded).toBe(false);
expect(component.popup.survey).toBe(survey1);
let previosPopup = component.popup;
component.model = survey2;
component.isExpanded = false;
component.ngOnChanges({ model: {
previousValue: survey1,
firstChange: false,
isFirstChange() {
return false;
},
currentValue: survey2,
},
isExpanded: {
previousValue: false,
firstChange: false,
isFirstChange() {
return false;
},
currentValue: false,
} });
expect(component.popup.isExpanded).toBe(false);
expect(component.popup.survey).toBe(survey2);
expect(component.popup !== previosPopup).toBe(true);
previosPopup = component.popup;
component.model = survey2;
component.isExpanded = true;
component.ngOnChanges({ model: {
previousValue: survey2,
firstChange: false,
isFirstChange() {
return false;
},
currentValue: survey2,
},
isExpanded: {
previousValue: false,
firstChange: false,
isFirstChange() {
return false;
},
currentValue: true,
} });
expect(component.popup.isExpanded).toBe(true);
expect(component.popup.survey).toBe(survey2);
expect(component.popup).toBe(previosPopup);
previosPopup = component.popup;

component.isExpanded = false;
component.model = survey2;
component.ngOnChanges({
isExpanded: {
previousValue: false,
firstChange: false,
isFirstChange() {
return false;
},
currentValue: false,
} });
expect(component.popup.isExpanded).toBe(false);
expect(component.popup.survey).toBe(survey2);
expect(component.popup).toBe(previosPopup);
});
});
3 changes: 1 addition & 2 deletions testCafe/survey/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ const initPopupSurvey = ClientFunction(
data: { survey: model },
});
} else if (framework === "angular") {
const popupSurvey = new window["Survey"].PopupSurveyModel(undefined, model);
window.setSurvey(popupSurvey);
window.setSurvey(model, true);
}
window["survey"] = model;
}
Expand Down

0 comments on commit e9c7df2

Please sign in to comment.