diff --git a/libs/shared/src/lib/components/dashboard-filter/filter-builder-modal/filter-builder-modal.component.ts b/libs/shared/src/lib/components/dashboard-filter/filter-builder-modal/filter-builder-modal.component.ts index a1061285e1..0348199941 100644 --- a/libs/shared/src/lib/components/dashboard-filter/filter-builder-modal/filter-builder-modal.component.ts +++ b/libs/shared/src/lib/components/dashboard-filter/filter-builder-modal/filter-builder-modal.component.ts @@ -18,13 +18,13 @@ import { ButtonModule, SnackbarService, TooltipModule } from '@oort-front/ui'; import { DialogModule, AlertModule } from '@oort-front/ui'; import { renderGlobalProperties } from '../../../survey/render-global-properties'; import { ReferenceDataService } from '../../../services/reference-data/reference-data.service'; -import { FormHelpersService } from '../../../services/form-helper/form-helper.service'; +import { + FormHelpersService, + QuestionType, +} from '../../../services/form-helper/form-helper.service'; import { Question } from '../../../survey/types'; import 'survey-core/survey.i18n.min.js'; -import { - CustomJSONEditorComponent, - SurveyCustomJSONEditorPlugin, -} from '../../form-builder/custom-json-editor/custom-json-editor.component'; +import { SurveyCustomJSONEditorPlugin } from '../../form-builder/custom-json-editor/custom-json-editor.component'; import { updateModalChoicesAndValue } from '../../../survey/global-properties/reference-data'; import { HttpClient } from '@angular/common/http'; //import 'survey-creator-core/survey-creator-core.i18n.min.js'; @@ -46,26 +46,26 @@ const DEFAULT_STRUCTURE = { * Commented types are not yet implemented. */ const QUESTION_TYPES = [ - 'text', - 'checkbox', - 'radiogroup', - 'dropdown', - 'tagbox', - 'comment', + QuestionType.TEXT, + QuestionType.CHECKBOX, + QuestionType.RADIO_GROUP, + QuestionType.DROPDOWN, + QuestionType.TAGBOX, + QuestionType.COMMENT, // 'rating', // 'ranking', // 'imagepicker', - 'boolean', + QuestionType.BOOLEAN, // 'image', - 'html', + QuestionType.HTML, // 'signaturepad', // 'expression', // 'matrix', // 'matrixdropdown', // 'matrixdynamic', // 'multipletext', - 'panel', - 'paneldynamic', + QuestionType.PANEL, + QuestionType.PANEL_DYNAMIC, ]; /** @@ -170,7 +170,6 @@ const CORE_QUESTION_ALLOWED_PROPERTIES = [ AlertModule, SurveyCreatorModule, ButtonModule, - CustomJSONEditorComponent, ], }) export class FilterBuilderModalComponent diff --git a/libs/shared/src/lib/components/email/constant.ts b/libs/shared/src/lib/components/email/constant.ts index 1525c23b42..929f84ae69 100644 --- a/libs/shared/src/lib/components/email/constant.ts +++ b/libs/shared/src/lib/components/email/constant.ts @@ -1,5 +1,12 @@ +import { QuestionType } from './../../services/form-helper/form-helper.service'; + /** Select field types */ -export const selectFieldTypes = ['select', 'dropdown', 'checkbox', 'tagbox']; +export const selectFieldTypes = [ + QuestionType.SELECT, + QuestionType.DROPDOWN, + QuestionType.CHECKBOX, + QuestionType.TAGBOX, +]; /** * Regex for valid strings in layout page select */ @@ -11,4 +18,8 @@ export const emailRegex = /** * Array for missing types */ -export const missingTypesArray = ['matrix', 'matrixdynamic', 'matrixdropdown']; +export const missingTypesArray = [ + QuestionType.MATRIX, + QuestionType.MATRIX_DYNAMIC, + QuestionType.MATRIX_DROPDOWN, +]; diff --git a/libs/shared/src/lib/components/form-builder/form-builder.component.ts b/libs/shared/src/lib/components/form-builder/form-builder.component.ts index 3687ec2e8f..c4a09bb8bf 100644 --- a/libs/shared/src/lib/components/form-builder/form-builder.component.ts +++ b/libs/shared/src/lib/components/form-builder/form-builder.component.ts @@ -24,7 +24,10 @@ import { } from 'survey-core'; import { SurveyCreatorModel } from 'survey-creator-core'; import { Form } from '../../models/form.model'; -import { FormHelpersService } from '../../services/form-helper/form-helper.service'; +import { + FormHelpersService, + QuestionType, +} from '../../services/form-helper/form-helper.service'; import { ReferenceDataService } from '../../services/reference-data/reference-data.service'; import { updateModalChoicesAndValue } from '../../survey/global-properties/reference-data'; import { renderGlobalProperties } from '../../survey/render-global-properties'; @@ -37,27 +40,27 @@ import { SurveyCustomJSONEditorPlugin } from './custom-json-editor/custom-json-e * Commented types are not yet implemented. */ const QUESTION_TYPES = [ - 'text', - 'checkbox', - 'radiogroup', - 'dropdown', - 'tagbox', - 'comment', - // 'rating', - // 'ranking', - // 'imagepicker', - 'boolean', - 'image', - 'html', - // 'signaturepad', - 'expression', - 'file', - 'matrix', - 'matrixdropdown', - 'matrixdynamic', - 'multipletext', - 'panel', - 'paneldynamic', + QuestionType.TEXT, + QuestionType.CHECKBOX, + QuestionType.RADIO_GROUP, + QuestionType.DROPDOWN, + QuestionType.TAGBOX, + QuestionType.COMMENT, + // 'RATING, + // 'RANKING, + // 'IMAGEPICKER, + QuestionType.BOOLEAN, + QuestionType.IMAGE, + QuestionType.HTML, + // 'SIGNATUREPAD, + QuestionType.EXPRESSION, + QuestionType.FILE, + QuestionType.MATRIX, + QuestionType.MATRIX_DROPDOWN, + QuestionType.MATRIX_DYNAMIC, + QuestionType.MULTIPLE_TEXT, + QuestionType.PANEL, + QuestionType.PANEL_DYNAMIC, ]; /** @@ -542,7 +545,7 @@ export class FormBuilderComponent question.choices = []; } } - if (question.getType() === 'multipletext') { + if (question.getType() === QuestionType.MULTIPLE_TEXT) { let validQuestion = true; // Check if every item of the questions is valid, otherwise stop loop and function question.items.every((item: any) => { @@ -569,7 +572,7 @@ export class FormBuilderComponent return false; } } - if (question.getType() === 'matrix') { + if (question.getType() === QuestionType.MATRIX) { question.columns.forEach((x: any) => { x.text = x.text || x.value || x; x.value = this.formHelpersService.toSnakeCase(x.value || x.text || x); @@ -579,7 +582,7 @@ export class FormBuilderComponent x.value = this.formHelpersService.toSnakeCase(x.value || x.text || x); }); } - if (question.getType() === 'matrixdropdown') { + if (question.getType() === QuestionType.MATRIX_DROPDOWN) { question.columns.forEach((x: any) => { x.title = x.title || x.name || x; x.name = this.formHelpersService.toSnakeCase(x.name || x.title || x); @@ -589,7 +592,10 @@ export class FormBuilderComponent x.value = this.formHelpersService.toSnakeCase(x.value || x.text || x); }); } - if (['resource', 'resources'].includes(question.getType())) { + if ( + question.getType() === QuestionType.RESOURCE || + question.getType() === QuestionType.RESOURCES + ) { if (question.relatedName) { question.relatedName = this.formHelpersService.toSnakeCase( question.relatedName @@ -664,7 +670,10 @@ export class FormBuilderComponent } } // Check that at least an application is selected in the properties of users and owner question - if (['users', 'owner'].includes(question.getType())) { + if ( + question.getType() === QuestionType.USERS || + question.getType() === QuestionType.OWNER + ) { if (!question.applications) { this.snackBar.openSnackBar( this.translate.instant('pages.formBuilder.errors.selectApplication', { diff --git a/libs/shared/src/lib/components/form/form-examples.stories.ts b/libs/shared/src/lib/components/form/form-examples.stories.ts index 66a3362201..64760fc726 100644 --- a/libs/shared/src/lib/components/form/form-examples.stories.ts +++ b/libs/shared/src/lib/components/form/form-examples.stories.ts @@ -19,6 +19,7 @@ import { ResizeBatchService } from '@progress/kendo-angular-common'; import { IconsService } from '@progress/kendo-angular-icons'; import { ComponentCollection, CustomWidgetCollection } from 'survey-core'; import { DateInputsModule } from '@progress/kendo-angular-dateinputs'; +import { QuestionType } from '../../services/form-helper/form-helper.service'; // You can create new stories getting the logic from: https://surveyjs.io/create-free-survey @@ -173,14 +174,14 @@ export const MultiPages: Story = { elements: [ { title: 'Dropdown', - type: 'dropdown', + type: QuestionType.DROPDOWN, name: 'question1', ...sharedQuestion(args), choices: ['Item 1', 'Item 2', 'Item 3'], }, { title: 'Radiogroup', - type: 'radiogroup', + type: QuestionType.RADIO_GROUP, name: 'question2', ...sharedQuestion(args), choices: ['Item a', 'Item b', 'Item c'], @@ -192,7 +193,7 @@ export const MultiPages: Story = { elements: [ { title: 'Yes/No', - type: 'boolean', + type: QuestionType.BOOLEAN, name: 'question1', ...sharedQuestion(args), }, @@ -203,7 +204,7 @@ export const MultiPages: Story = { elements: [ { title: 'Date', - type: 'text', + type: QuestionType.TEXT, name: 'question1', inputType: 'date', ...sharedQuestion(args), @@ -236,7 +237,7 @@ export const Logic: Story = { elements: [ { title: 'Dropdown', - type: 'dropdown', + type: QuestionType.DROPDOWN, name: 'question1', description: 'Question 2 only will appears if the selected option is Item 1', @@ -245,7 +246,7 @@ export const Logic: Story = { }, { title: 'Date', - type: 'text', + type: QuestionType.TEXT, name: 'question2', inputType: 'date', visible: false, @@ -283,7 +284,7 @@ export const DefaultValue: Story = { { title: 'Number', defaultValue: 10, - type: 'text', + type: QuestionType.TEXT, name: 'question1', inputType: 'number', ...sharedQuestion(args), @@ -291,7 +292,7 @@ export const DefaultValue: Story = { { title: 'Text', defaultValue: 'Default value', - type: 'text', + type: QuestionType.TEXT, name: 'question2', inputType: 'text', ...sharedQuestion(args), diff --git a/libs/shared/src/lib/components/form/stories/inputs/form-dropdown.stories.ts b/libs/shared/src/lib/components/form/stories/inputs/form-dropdown.stories.ts index bfb40424b5..a8d39499b7 100644 --- a/libs/shared/src/lib/components/form/stories/inputs/form-dropdown.stories.ts +++ b/libs/shared/src/lib/components/form/stories/inputs/form-dropdown.stories.ts @@ -1,3 +1,4 @@ +import { QuestionType } from '../../../../services/form-helper/form-helper.service'; import { FormInputStoryMeta, DefaultFormInputStory, @@ -14,7 +15,7 @@ const questionName = 'Dropdown question'; /** Base question */ const baseQuestion = { - type: 'dropdown', + type: QuestionType.DROPDOWN, choices: ['Item 1', 'Item 2', 'Item 3'], }; diff --git a/libs/shared/src/lib/components/ui/aggregation-builder/series-mapping/series-mapping.stories.ts b/libs/shared/src/lib/components/ui/aggregation-builder/series-mapping/series-mapping.stories.ts index 4a631f741d..2ff8ba241d 100644 --- a/libs/shared/src/lib/components/ui/aggregation-builder/series-mapping/series-mapping.stories.ts +++ b/libs/shared/src/lib/components/ui/aggregation-builder/series-mapping/series-mapping.stories.ts @@ -6,6 +6,10 @@ import { SeriesMappingModule } from './series-mapping.module'; import { StorybookTranslateModule } from '../../../storybook-translate/storybook-translate-module'; import { createMappingForm } from '../aggregation-builder-forms'; import { delay } from 'rxjs/operators'; +import { + InputType, + QuestionType, +} from '../../../../services/form-helper/form-helper.service'; export default { component: SeriesMappingComponent, @@ -31,7 +35,7 @@ export default { */ const DEFAULT_FIELDS = [ { - type: 'tagbox', + type: QuestionType.TAGBOX, name: 'affected_countriees', isRequired: false, readOnly: false, @@ -44,7 +48,7 @@ const DEFAULT_FIELDS = [ }, }, { - type: 'tagbox', + type: QuestionType.TAGBOX, name: 'regions', isRequired: false, readOnly: false, @@ -52,7 +56,7 @@ const DEFAULT_FIELDS = [ choices: ['AFR', 'AMR', 'WMR', 'EUR', 'SEAR', 'WPR'], }, { - type: 'dropdown', + type: QuestionType.DROPDOWN, name: 'disease', isRequired: false, readOnly: false, @@ -65,21 +69,21 @@ const DEFAULT_FIELDS = [ }, }, { - type: 'text', + type: QuestionType.TEXT, name: 'title', isRequired: false, readOnly: false, isCore: true, }, { - type: 'text', + type: QuestionType.TEXT, name: 'description', isRequired: false, readOnly: false, isCore: true, }, { - type: 'resources', + type: QuestionType.RESOURCES, name: 'sources', isRequired: false, readOnly: false, @@ -125,20 +129,20 @@ const DEFAULT_FIELDS = [ }, }, { - type: 'date', + type: InputType.DATE, name: 'date', isRequired: false, readOnly: false, isCore: true, }, { - type: 'text', + type: QuestionType.TEXT, name: 'follow_comment', isCore: true, generated: true, }, { - type: 'radiogroup', + type: QuestionType.RADIO_GROUP, name: 'follow', isRequired: false, readOnly: false, diff --git a/libs/shared/src/lib/components/ui/core-grid/grid/grid.component.html b/libs/shared/src/lib/components/ui/core-grid/grid/grid.component.html index 9f0e3f352e..afb74916af 100644 --- a/libs/shared/src/lib/components/ui/core-grid/grid/grid.component.html +++ b/libs/shared/src/lib/components/ui/core-grid/grid/grid.component.html @@ -151,7 +151,7 @@ field.type !== 'JSON' && (!field.meta || (field.meta.type !== 'referenceData' && - field.meta.type !== 'editor')) + field.meta.type !== QuestionType.EDITOR)) " [field]="field.name" [title]="field.title" @@ -168,7 +168,11 @@ - +
 
@@ -466,7 +477,11 @@ #refSpan kendoGridCellTemplate let-dataItem="dataItem" - *ngIf="['dropdown', 'radiogroup'].includes(field.meta.type)" + *ngIf=" + [QuestionType.DROPDOWN, QuestionType.RADIO_GROUP].includes( + field.meta.type + ) + " >
- + - + - +