Skip to content

Commit

Permalink
Work for #3390: started designer tab
Browse files Browse the repository at this point in the history
  • Loading branch information
T_S_V committed Sep 5, 2022
1 parent 89bc2b1 commit 7c55cdd
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,88 @@ import { Component } from "@angular/core";
import { SurveyModel } from "survey-core";
import { CreatorBase } from "survey-creator-core";

const json = {
"logoPosition": "right",
"completedHtml": "<h3>Thank you for your feedback.</h3><h5>Your thoughts and ideas will help us to create a great product!</h5>",
"completedHtmlOnCondition": [
{
"expression": "{nps_score} > 8",
"html": "<h3>Thank you for your feedback.</h3><h5>We glad that you love our product. Your ideas and suggestions will help us to make our product even better!</h5>"
},
{
"expression": "{nps_score} < 7",
"html": "<h3>Thank you for your feedback.</h3><h5> We are glad that you share with us your ideas.We highly value all suggestions from our customers. We do our best to improve the product and reach your expectation.</h5><br />"
}
],
"pages": [
{
"name": "page1",
"elements": [
{
"type": "rating",
"name": "nps_score",
"title": "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?",
"isRequired": true,
"rateMin": 0,
"rateMax": 10,
"minRateDescription": "(Most unlikely)",
"maxRateDescription": "(Most likely)"
},
{
"type": "checkbox",
"name": "promoter_features",
"visible": false,
"visibleIf": "{nps_score} >= 9",
"title": "Which features do you value the most?",
"isRequired": true,
"validators": [
{
"type": "answercount",
"text": "Please select two features maximum.",
"maxCount": 2
}
],
"choices": [
"Performance",
"Stability",
"User Interface",
"Complete Functionality"
],
"hasOther": true,
"otherText": "Other feature:",
"colCount": 2
},
{
"type": "comment",
"name": "passive_experience",
"visible": false,
"visibleIf": "{nps_score} > 6 and {nps_score} < 9",
"title": "What do you like about our product?"
},
{
"type": "comment",
"name": "disappointed_experience",
"visible": false,
"visibleIf": "{nps_score} notempty",
"title": "What do you miss or find disappointing in your experience with our products?"
}
]
}
],
"showQuestionNumbers": "off"
};

@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styles: [":host { position: fixed; top: 0; bottom: 0; right: 0; left: 0;}"]
})
export class AppComponent {
public isTest = !!(<any>window)["%hammerhead%"];
public survey = new SurveyModel({
"logoPosition": "right",
"completedHtml": "<h3>Thank you for your feedback.</h3><h5>Your thoughts and ideas will help us to create a great product!</h5>",
"completedHtmlOnCondition": [
{
"expression": "{nps_score} > 8",
"html": "<h3>Thank you for your feedback.</h3><h5>We glad that you love our product. Your ideas and suggestions will help us to make our product even better!</h5>"
},
{
"expression": "{nps_score} < 7",
"html": "<h3>Thank you for your feedback.</h3><h5> We are glad that you share with us your ideas.We highly value all suggestions from our customers. We do our best to improve the product and reach your expectation.</h5><br />"
}
],
"pages": [
{
"name": "page1",
"elements": [
{
"type": "rating",
"name": "nps_score",
"title": "On a scale of zero to ten, how likely are you to recommend our product to a friend or colleague?",
"isRequired": true,
"rateMin": 0,
"rateMax": 10,
"minRateDescription": "(Most unlikely)",
"maxRateDescription": "(Most likely)"
},
{
"type": "checkbox",
"name": "promoter_features",
"visible": false,
"visibleIf": "{nps_score} >= 9",
"title": "Which features do you value the most?",
"isRequired": true,
"validators": [
{
"type": "answercount",
"text": "Please select two features maximum.",
"maxCount": 2
}
],
"choices": [
"Performance",
"Stability",
"User Interface",
"Complete Functionality"
],
"hasOther": true,
"otherText": "Other feature:",
"colCount": 2
},
{
"type": "comment",
"name": "passive_experience",
"visible": false,
"visibleIf": "{nps_score} > 6 and {nps_score} < 9",
"title": "What do you like about our product?"
},
{
"type": "comment",
"name": "disappointed_experience",
"visible": false,
"visibleIf": "{nps_score} notempty",
"title": "What do you miss or find disappointing in your experience with our products?"
}
]
}
],
"showQuestionNumbers": "off"
});
constructor() {
this.creator.JSON = json;
}

public survey = new SurveyModel(json);
public creator = new CreatorBase({ showLogicTab: true, showTranslationTab: true })
}
3 changes: 2 additions & 1 deletion packages/survey-creator-angular/src/angular-ui.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import { TestAgainActionComponent } from "./tabs/preview/test-again.component";
import { SurveyResultsComponent } from "./tabs/preview/survey-results.component";
import { SurveyResultsTableRowComponent } from "./tabs/preview/survey-results-row.component";
import { TestTabComponent } from "./tabs/preview/test.component";
import { PageDesignerComponent } from "./page.component";

@NgModule({
declarations: [CreatorComponent, DesignerTabComponent, SvgBundleComponent, TabbledMenuComponent, TabbedMenuItemComponent, TabbedMenuItemWrapperComponent, SidebarComponent, SidebarTabComponent, ObjectSelectorComponent, PropertyGridComponent, TextareaJsonEditorComponent, AceJsonEditorComponent, LogicTabComponent, LogicAddButtonComponent, ActionButtonComponent, LinkValueQuestionComponent, EmbeddedSurveyQuestionComponent, TranslationTabComponent, TranslationSkeletonComponent, SimulatorComponent, TestTabComponent, TestAgainActionComponent, SurveyResultsComponent, SurveyResultsTableRowComponent],
declarations: [CreatorComponent, DesignerTabComponent, PageDesignerComponent, SvgBundleComponent, TabbledMenuComponent, TabbedMenuItemComponent, TabbedMenuItemWrapperComponent, SidebarComponent, SidebarTabComponent, ObjectSelectorComponent, PropertyGridComponent, TextareaJsonEditorComponent, AceJsonEditorComponent, LogicTabComponent, LogicAddButtonComponent, ActionButtonComponent, LinkValueQuestionComponent, EmbeddedSurveyQuestionComponent, TranslationTabComponent, TranslationSkeletonComponent, SimulatorComponent, TestTabComponent, TestAgainActionComponent, SurveyResultsComponent, SurveyResultsTableRowComponent],
imports: [
CommonModule, FormsModule, SurveyAngularModule
],
Expand Down
27 changes: 27 additions & 0 deletions packages/survey-creator-angular/src/page.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div *ngIf="model && adorner" class="svc-page__content" [class]="adorner.css" [key2click]
(click)="adorner.select(adorner, $event)"
data-bind="click: select, key2click, clickBubble: false, css: css, attr: { id: page.id }, event: { mouseover: function(m, e) { hover(e, $element); }, mouseleave: function(m, e) { hover(e, $element); } }">
<div class="svc-page__content-actions">
<!-- ko component: { name: 'sv-action-bar', params: { model: actionContainer } } -->
<!-- /ko -->
</div>
<page [model]="model" [survey]="survey"></page>
<div *ngIf="adorner.showAddQuestionButton" class="svc-page__add-new-question svc-btn" [key2click]
(click)="adorner.addNewQuestion(adorner, $event)"
data-bind="click: addNewQuestion, key2click, clickBubble: false, event: { mouseover: function(m, e) { hoverStopper(e, $element); }}">
<span class="svc-text svc-text--normal svc-text--bold">
{{ adorner.addNewQuestionText }}
</span>
<!-- ko with: questionTypeSelectorModel -->
<button type="button" [key2click] (click)="adorner.questionTypeSelectorModel.action()"
data-bind="click: action, key2click, clickBubble: false, attr: { title: title, 'aria-label': title }"
class="svc-page__question-type-selector">
<svg class="svc-page__question-type-selector-icon" [iconName]="adorner.questionTypeSelectorModel.iconName"
[size]="24" sv-ng-svg-icon></svg>
<!-- <sv-svg-icon class="svc-page__question-type-selector-icon" params="iconName: iconName, size: 24, title: title">
</sv-svg-icon> -->
<!-- <sv-popup params="model: popupModel"></sv-popup> -->
</button>
<!-- /ko -->
</div>
</div>
32 changes: 32 additions & 0 deletions packages/survey-creator-angular/src/page.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ChangeDetectorRef, Component, Input, ViewContainerRef } from "@angular/core";
import { AngularComponentFactory, BaseAngular, EmbeddedViewContentComponent } from "survey-angular-ui";
import { PageModel, SurveyModel } from "survey-core";
import { CreatorBase, PageAdorner } from "survey-creator-core";

@Component({
selector: "svc-page",
templateUrl: "./page.component.html",
styles: []
})
export class PageDesignerComponent extends BaseAngular<PageModel> {
@Input() model!: PageModel;
@Input() survey!: SurveyModel;
@Input() creator!: CreatorBase;
public adorner?: PageAdorner;
constructor(changeDetectorRef: ChangeDetectorRef, viewContainerRef?: ViewContainerRef) {
super(changeDetectorRef, viewContainerRef);
if(this.model) {
this.adorner = new PageAdorner(this.creator, this.model);
}
}
protected override onModelChanged(): void {
super.onModelChanged();
this.adorner = new PageAdorner(this.creator, this.model);
}
protected getModel(): PageModel {
return this.model;
}
}

AngularComponentFactory.Instance.registerComponent("svc-page", PageDesignerComponent);

56 changes: 55 additions & 1 deletion packages/survey-creator-angular/src/tabs/designer.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
<ng-template #template>
<!-- <svc-adaptive-toolbox *ngIf="model.isToolboxVisible" params="model: creator"></svc-adaptive-toolbox> -->
<div class="svc-tab-designer" [class]="model.getRootCss()" (click)="model.clickDesigner()">
TODO implement designer tab
<div class="svc-tab-designer_content">
<ng-container *ngIf="model.showPlaceholder">
<div *ngIf="creator.showHeaderInEmptySurvey && creator.allowEditSurveyTitle" class="svc-designer-header">
<!-- ko template: { name: 'survey-header', data: survey } -->
<!-- /ko -->
</div>
<div class="svc-designer__placeholder-container"
data-bind="attr: { 'data-sv-drop-target-survey-element': 'newGhostPage' }">
<span class="svc-designer-placeholder-text svc-text svc-text--normal" data-bind="text: placeholderText">
</span>
<svc-page class="svc-designer-placeholder-page" params="survey: survey, creator: creator, page: newPage">
</svc-page>
</div>
</ng-container>

<ng-container *ngIf="!model.showPlaceholder">
<div [class]="model.getDesignerCss()" [style.width]="survey.width">
<div *ngIf="creator.allowEditSurveyTitle" class="svc-designer-header">
<!-- ko template: { name: 'survey-header', data: survey } -->
<!-- /ko -->
</div>

<!-- ko if: survey.isShowProgressBarOnTop -->
<!-- ko component: { name: 'sv-progress-' + survey.progressBarType, params: { model: survey } } -->
<!-- /ko -->
<!-- /ko -->

<ng-container *ngIf="creator.pageEditMode !== 'bypage'">
<svc-page *ngFor="let page of survey.pages" class="svc-page"
data-bind="attr: { 'data-sv-drop-target-survey-element': page.name, 'data-sv-drop-target-page': page.name }"
[model]="page" [survey]="survey" [creator]="creator"></svc-page>
<svc-page *ngIf="model.showNewPage && model.newPage" class="svc-page"
data-bind="attr: { 'data-sv-drop-target-survey-element': 'newGhostPage' }" [model]="model.newPage"
[survey]="survey" [creator]="creator"></svc-page>
</ng-container>

<ng-container *ngIf="model.pagesController.page2Display && creator.pageEditMode === 'bypage'">
<svc-page class="svc-page"
data-bind="attr: { 'data-sv-drop-target-survey-element': 'newGhostPage', 'data-sv-drop-target-page': pagesController.page2Display.name }"
[model]="model.pagesController.page2Display" [survey]="survey" [creator]="creator"></svc-page>
</ng-container>

<!-- ko if: survey.isShowProgressBarOnBottom -->
<!-- ko component: { name: 'sv-progress-' + survey.progressBarType, params: { model: survey } } -->
<!-- /ko -->
<!-- /ko -->
</div>

<div *ngIf="creator.showPageNavigator" class="svc-tab-designer__page-navigator">
<!-- <svc-page-navigator params="controller: pagesController, pageEditMode: creator.pageEditMode">
</svc-page-navigator> -->
</div>
</ng-container>
</div>
</div>
</ng-template>

0 comments on commit 7c55cdd

Please sign in to comment.