From 22a7c37cbce75321387a856f510ff394f3d5f2dc Mon Sep 17 00:00:00 2001 From: chowyiyin Date: Mon, 24 May 2021 10:40:24 +0800 Subject: [PATCH 1/4] refactor: replace service with typescript enums --- .../edit-fields-modal.client.controller.js | 9 ++++----- src/types/form.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/public/modules/forms/admin/controllers/edit-fields-modal.client.controller.js b/src/public/modules/forms/admin/controllers/edit-fields-modal.client.controller.js index 1b6480d756..aa94e81a03 100644 --- a/src/public/modules/forms/admin/controllers/edit-fields-modal.client.controller.js +++ b/src/public/modules/forms/admin/controllers/edit-fields-modal.client.controller.js @@ -13,7 +13,8 @@ const { uploadImage } = require('../../../../services/FileHandlerService') const { DateSelectedValidation: DateValidationOptions, } = require('../../../../../shared/constants') - +const { Rating } = require('../../../../../types/form') +const { RatingShape } = require('../../../../../types/field/ratingField') const CancelToken = axios.CancelToken const EMAIL_MODE_ALLOWED_SIZES = ['1', '2', '3', '7'] @@ -25,7 +26,6 @@ angular '$uibModalInstance', 'externalScope', 'responseModeEnum', - 'Rating', 'Attachment', 'FormFields', '$q', @@ -41,7 +41,6 @@ function EditFieldsModalController( $uibModalInstance, externalScope, responseModeEnum, - Rating, Attachment, FormFields, $q, @@ -162,8 +161,8 @@ function EditFieldsModalController( } } - vm.ratingSteps = Rating.steps - vm.ratingShapes = Rating.shapes + vm.ratingSteps = Object.values(Rating) + vm.ratingShapes = Object.values(RatingShape) vm.showDuplicateOptionsError = function (field) { // This function assumes that the txt file option for dropdown automatically removes duplicates diff --git a/src/types/form.ts b/src/types/form.ts index afd77fcdf7..2168fc93e5 100644 --- a/src/types/form.ts +++ b/src/types/form.ts @@ -36,6 +36,19 @@ export enum Colors { Grey = 'grey', } +export enum Rating { + One = 1, + Two = 2, + Three = 3, + Four = 4, + Five = 5, + Six = 6, + Seven = 7, + Eight = 8, + Nine = 9, + Ten = 10, +} + export enum ResponseMode { Encrypt = 'encrypt', Email = 'email', From 3102037a0995b28cb1768b26128af6b0d83b4612 Mon Sep 17 00:00:00 2001 From: chowyiyin Date: Mon, 24 May 2021 10:40:55 +0800 Subject: [PATCH 2/4] refactor: remove rating client service --- src/public/main.js | 1 - src/public/modules/forms/services/rating.client.service.js | 6 ------ 2 files changed, 7 deletions(-) delete mode 100644 src/public/modules/forms/services/rating.client.service.js diff --git a/src/public/main.js b/src/public/main.js index 03ba90fb4d..209e78ddd2 100644 --- a/src/public/main.js +++ b/src/public/main.js @@ -265,7 +265,6 @@ require('./modules/forms/services/spcp-session.client.factory.js') require('./modules/forms/services/submissions.client.factory.js') require('./modules/forms/services/toastr.client.factory.js') require('./modules/forms/services/attachment.client.service.js') -require('./modules/forms/services/rating.client.service.js') require('./modules/forms/services/betas.client.factory.js') require('./modules/forms/services/captcha.client.service.js') require('./modules/forms/services/mailto.client.factory.js') diff --git a/src/public/modules/forms/services/rating.client.service.js b/src/public/modules/forms/services/rating.client.service.js deleted file mode 100644 index fe5cd0fb62..0000000000 --- a/src/public/modules/forms/services/rating.client.service.js +++ /dev/null @@ -1,6 +0,0 @@ -angular.module('forms').service('Rating', [Rating]) - -function Rating() { - this.steps = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] - this.shapes = ['Heart', 'Star'] -} From a9cf6569742019256ec2ce28f8d20bca34ce9361 Mon Sep 17 00:00:00 2001 From: chowyiyin Date: Mon, 24 May 2021 14:02:10 +0800 Subject: [PATCH 3/4] refactor: change rating from enum to list of numbers --- .../edit-fields-modal.client.controller.js | 5 ++-- src/types/form.ts | 28 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/public/modules/forms/admin/controllers/edit-fields-modal.client.controller.js b/src/public/modules/forms/admin/controllers/edit-fields-modal.client.controller.js index aa94e81a03..baea64ef3d 100644 --- a/src/public/modules/forms/admin/controllers/edit-fields-modal.client.controller.js +++ b/src/public/modules/forms/admin/controllers/edit-fields-modal.client.controller.js @@ -13,8 +13,7 @@ const { uploadImage } = require('../../../../services/FileHandlerService') const { DateSelectedValidation: DateValidationOptions, } = require('../../../../../shared/constants') -const { Rating } = require('../../../../../types/form') -const { RatingShape } = require('../../../../../types/field/ratingField') +const { Rating, RatingShape } = require('../../../../../types') const CancelToken = axios.CancelToken const EMAIL_MODE_ALLOWED_SIZES = ['1', '2', '3', '7'] @@ -161,7 +160,7 @@ function EditFieldsModalController( } } - vm.ratingSteps = Object.values(Rating) + vm.ratingSteps = Rating vm.ratingShapes = Object.values(RatingShape) vm.showDuplicateOptionsError = function (field) { diff --git a/src/types/form.ts b/src/types/form.ts index 2168fc93e5..5fda829a39 100644 --- a/src/types/form.ts +++ b/src/types/form.ts @@ -1,3 +1,4 @@ +import _ from 'lodash' import { Document, LeanDocument, Model, ToObjectOptions, Types } from 'mongoose' import { Merge, SetRequired } from 'type-fest' @@ -36,24 +37,25 @@ export enum Colors { Grey = 'grey', } -export enum Rating { - One = 1, - Two = 2, - Three = 3, - Four = 4, - Five = 5, - Six = 6, - Seven = 7, - Eight = 8, - Nine = 9, - Ten = 10, -} - export enum ResponseMode { Encrypt = 'encrypt', Email = 'email', } +export const Rating = _.range(1, 11) + +export enum RatingEnum { + One = 1, + Two, + Three, + Four, + Five, + Six, + Seven, + Eight, + Nine, + Ten, +} // Typings // Make sure this is kept in sync with form.server.model#FORM_PUBLIC_FIELDS. export type PublicFormValues = Pick< From 8c73bf591ccc13a1e2df5a668d8d22d4674b110c Mon Sep 17 00:00:00 2001 From: chowyiyin Date: Mon, 24 May 2021 14:51:31 +0800 Subject: [PATCH 4/4] refactor: edit import statement and remove rating enum --- src/types/form.ts | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/types/form.ts b/src/types/form.ts index 5fda829a39..2af5e60737 100644 --- a/src/types/form.ts +++ b/src/types/form.ts @@ -1,4 +1,4 @@ -import _ from 'lodash' +import range from 'lodash/range' import { Document, LeanDocument, Model, ToObjectOptions, Types } from 'mongoose' import { Merge, SetRequired } from 'type-fest' @@ -42,20 +42,8 @@ export enum ResponseMode { Email = 'email', } -export const Rating = _.range(1, 11) - -export enum RatingEnum { - One = 1, - Two, - Three, - Four, - Five, - Six, - Seven, - Eight, - Nine, - Ten, -} +export const Rating = range(1, 11).map(String) + // Typings // Make sure this is kept in sync with form.server.model#FORM_PUBLIC_FIELDS. export type PublicFormValues = Pick<