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

refactor: replace $resource in angularjs form-api.client.factory.js with typescript FormService #1947

Merged
merged 37 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6be39f3
refactor: replace object with typescript FormService
chowyiyin May 21, 2021
aa0198e
test: add test for FormService
chowyiyin May 21, 2021
d70036f
refactor: edit calls to fit new function signature and remove angularjs
chowyiyin May 21, 2021
caed806
rfix: add missing parameter in transferOwner and cfix reading error m…
chowyiyin May 21, 2021
f18448f
refactor: add .when to all FormApi calls
chowyiyin May 25, 2021
ce9f9c1
refactor: extract interceptors from FormService and replace original …
chowyiyin May 25, 2021
3dc5a0b
test: remove interceptor from FormService tests
chowyiyin May 25, 2021
9349573
refactor: add .when to FormApi calls
chowyiyin May 25, 2021
958a378
docs: add documentation and reaname some functions
chowyiyin May 27, 2021
998b810
refactor: edit calls to fit new function signature and remove angularjs
chowyiyin May 21, 2021
e990310
refactor: add .when to all FormApi calls
chowyiyin May 25, 2021
f552dc1
refactor: add .when to FormApi calls
chowyiyin May 25, 2021
664d2c1
refactor: rename getDashboardViews to getDashboardView
chowyiyin May 27, 2021
6174d5b
fix: rename getDashboardViews in form-api.client.factory.js
chowyiyin May 27, 2021
0785673
refactor: remove headers for IE11 support
chowyiyin Jun 1, 2021
ff083f9
refactor: split FormService into different services
chowyiyin Jun 2, 2021
a298378
split test into relevant files
chowyiyin Jun 2, 2021
573858d
refactor: update other files after rename of AdminFormService
chowyiyin Jun 2, 2021
7f91895
refactor: change services and rename formapi functions
chowyiyin Jun 2, 2021
ab47c52
refactor: remove outdated comment
chowyiyin Jun 2, 2021
93c4003
refactor: remove unnecessary
chowyiyin Jun 2, 2021
64b069a
docs: update jsdocs regarding AdminFormService
chowyiyin Jun 2, 2021
c2dcf39
refactor: remove unnecessary q.when
chowyiyin Jun 2, 2021
d24f569
refactor: change from absolute to relative import in AdminViewFormSer…
chowyiyin Jun 2, 2021
984b9d6
refactor: shift deleteForm to UpdateFormService
chowyiyin Jun 2, 2021
2f8880a
fix: change service deleteForm
chowyiyin Jun 2, 2021
f08d3d6
refactor: make tcalls to transformations explicit
chowyiyin Jun 2, 2021
4b7a009
test: edit tests to improve readability
chowyiyin Jun 2, 2021
6f8293b
refactor: update imports
chowyiyin Jun 4, 2021
b2994ff
test: fix imports in tests
chowyiyin Jun 7, 2021
10eb342
style: fix eslint style in tests
chowyiyin Jun 7, 2021
8d9b9a6
style: fix prettier errors
chowyiyin Jun 7, 2021
cc82973
fix: resolve merge conflict
chowyiyin Jun 8, 2021
256d882
fix: fix import statement in AdminSubmissionService
chowyiyin Jun 8, 2021
85d7388
fix: fix import statement in test
chowyiyin Jun 8, 2021
3bde847
fix: replace formApi.template with formApi.queryTemplate
chowyiyin Jun 9, 2021
5f640e3
fix: fix incorrect endpoint for query and use of template
chowyiyin Jun 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { LogicType } = require('../../../../../types')
const AdminFormService = require('../../../../services/AdminFormService')
const UpdateFormService = require('../../../../services/UpdateFormService')

angular.module('forms').component('editLogicComponent', {
templateUrl: 'modules/forms/admin/componentViews/edit-logic.client.view.html',
Expand Down Expand Up @@ -82,7 +82,7 @@ function editLogicComponentController($uibModal, FormFields, Toastr, $q) {

vm.deleteLogic = function (logicIndex) {
const logicIdToDelete = vm.myform.form_logics[logicIndex]._id
$q.when(AdminFormService.deleteFormLogic(vm.myform._id, logicIdToDelete))
$q.when(UpdateFormService.deleteFormLogic(vm.myform._id, logicIdToDelete))
.then(() => {
vm.myform.form_logics.splice(logicIndex, 1)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { StatusCodes } = require('http-status-codes')
const get = require('lodash/get')
const { LogicType } = require('../../../../../types')
const AdminFormService = require('../../../../services/AdminFormService')
const UpdateFormService = require('../../../../services/UpdateFormService')
const FieldFactory = require('../../helpers/field-factory')
const { UPDATE_FORM_TYPES } = require('../constants/update-form-types')

Expand Down Expand Up @@ -191,7 +191,9 @@ function AdminFormController(
case UPDATE_FORM_TYPES.CreateField: {
const { body } = update
return $q
.when(AdminFormService.createSingleFormField($scope.myform._id, body))
.when(
UpdateFormService.createSingleFormField($scope.myform._id, body),
)
.then((updatedFormField) => {
// !!! Convert retrieved form field objects into their class counterparts.
const updatedFieldClass =
Expand All @@ -210,7 +212,7 @@ function AdminFormController(
const { fieldId } = update
return $q
.when(
AdminFormService.deleteSingleFormField($scope.myform._id, fieldId),
UpdateFormService.deleteSingleFormField($scope.myform._id, fieldId),
)
.then(() => {
// Success, remove deleted form field
Expand All @@ -225,7 +227,7 @@ function AdminFormController(
const { fieldId, body } = update
return $q
.when(
AdminFormService.updateSingleFormField(
UpdateFormService.updateSingleFormField(
$scope.myform._id,
fieldId,
body,
Expand Down Expand Up @@ -253,7 +255,7 @@ function AdminFormController(
const { fieldId } = update
return $q
.when(
AdminFormService.duplicateSingleFormField(
UpdateFormService.duplicateSingleFormField(
$scope.myform._id,
fieldId,
),
Expand All @@ -277,7 +279,7 @@ function AdminFormController(

return $q
.when(
AdminFormService.reorderSingleFormField(
UpdateFormService.reorderSingleFormField(
$scope.myform._id,
fieldId,
newPosition,
Expand All @@ -295,8 +297,10 @@ function AdminFormController(
.catch(handleUpdateError)
}
default:
return FormApi.update({ formId: $scope.myform._id }, { form: update })
.$promise.then((savedForm) => {
// This block should not be reached. All updateForm calls should have an update type.
return $q
.when(FormApi.updateForm($scope.myform._id, update))
.then((savedForm) => {
// Updating this form updates lastModified
// and also updates myform if a formToUse is passed in
$scope.myform = savedForm
Expand All @@ -307,7 +311,7 @@ function AdminFormController(

$scope.updateFormEndPage = (newEndPage) => {
return $q
.when(AdminFormService.updateFormEndPage($scope.myform._id, newEndPage))
.when(UpdateFormService.updateFormEndPage($scope.myform._id, newEndPage))
.then((updatedEndPage) => {
$scope.myform.endPage = updatedEndPage
})
Expand All @@ -317,7 +321,7 @@ function AdminFormController(
$scope.updateFormStartPage = (newStartPage) => {
return $q
.when(
AdminFormService.updateFormStartPage($scope.myform._id, newStartPage),
UpdateFormService.updateFormStartPage($scope.myform._id, newStartPage),
)
.then((updatedStartPage) => {
$scope.myform.startPage = updatedStartPage
Expand All @@ -333,7 +337,7 @@ function AdminFormController(
$scope.updateFormSettings = (settingsToUpdate) => {
return $q
.when(
AdminFormService.updateFormSettings(
UpdateFormService.updateFormSettings(
$scope.myform._id,
settingsToUpdate,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { get } = require('lodash')
const { StatusCodes } = require('http-status-codes')
const AdminFormService = require('../../../../services/AdminFormService')
const UpdateFormService = require('../../../../services/UpdateFormService')

angular
.module('forms')
Expand Down Expand Up @@ -73,17 +73,14 @@ function CollaboratorModalController(
return
}

FormApi.transferOwner(
{ formId: $scope.myform._id },
{ email: $scope.transferOwnerEmail },
)
.$promise.then((res) => {
$q.when(FormApi.transferOwner($scope.myform._id, $scope.transferOwnerEmail))
.then((res) => {
$scope.myform = res.form
externalScope.refreshFormDataFromCollab($scope.myform)
Toastr.success('Form ownership transferred. You are now an Editor.')
})
.catch((err) => {
Toastr.error(err.data.message)
Toastr.error(err.response.data.message)
return
})
.finally(() => {
Expand All @@ -92,13 +89,16 @@ function CollaboratorModalController(
}

/**
* Calls AdminFormService to update the permission list (collaborators) of a form
* Calls UpdateFormService to update the permission list (collaborators) of a form
* @param {Array} permissionList - New permission list for the form
*/
$scope.updatePermissionList = (permissionList) => {
chowyiyin marked this conversation as resolved.
Show resolved Hide resolved
return $q
.when(
AdminFormService.updateCollaborators($scope.myform._id, permissionList),
UpdateFormService.updateCollaborators(
$scope.myform._id,
permissionList,
),
)
.then((updatedCollaborators) => {
$scope.myform.permissionList = updatedCollaborators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ angular
'FormSgSdk',
'externalScope',
'MailTo',
'$q',
CreateFormModalController,
])

Expand All @@ -61,6 +62,7 @@ function CreateFormModalController(
FormSgSdk,
externalScope,
MailTo,
$q,
) {
const vm = this

Expand Down Expand Up @@ -255,23 +257,23 @@ function CreateFormModalController(
const formMode = vm.mode
switch (formMode) {
case 'duplicate': {
FormFactory.generateForm(
formMode,
formParams,
FormToDuplicate._id,
).$promise.then((data) => {
$q.when(
FormFactory.generateForm(
formMode,
formParams,
FormToDuplicate._id,
),
).then((data) => {
vm.closeCreateModal()
externalScope.onDuplicateSuccess(data)
}, handleCreateFormError)
break
}
case 'useTemplate': {
const { form } = externalScope
FormFactory.generateForm(
formMode,
formParams,
form._id,
).$promise.then((data) => {
$q.when(
FormFactory.generateForm(formMode, formParams, form._id),
).then((data) => {
vm.closeCreateModal()
vm.goToWithId('viewForm', data._id + '')
GTag.examplesClickCreateNewForm(form)
Expand All @@ -281,7 +283,7 @@ function CreateFormModalController(
case 'createFromTemplate': {
// Create new form from template selected
const newForm = Object.assign({}, vm.template, formParams)
FormFactory.generateForm('create', newForm).$promise.then(
$q.when(FormFactory.generateForm('create', newForm)).then(
(data) => {
vm.closeCreateModal()
vm.goToWithId('viewForm', data._id + '')
Expand All @@ -291,7 +293,7 @@ function CreateFormModalController(
break
}
case 'create': // Create form
FormFactory.generateForm(formMode, formParams).$promise.then(
$q.when(FormFactory.generateForm(formMode, formParams)).then(
(data) => {
vm.closeCreateModal()
vm.goToWithId('viewForm', data._id + '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ angular
'$uibModalInstance',
'externalScope',
'FormApi',
'$q',
DeleteFormModalController,
])

function DeleteFormModalController($uibModalInstance, externalScope, FormApi) {
function DeleteFormModalController(
$uibModalInstance,
externalScope,
FormApi,
$q,
) {
const vm = this

vm.cancel = function () {
Expand All @@ -28,9 +34,7 @@ function DeleteFormModalController($uibModalInstance, externalScope, FormApi) {
}`,
)
}
FormApi.delete({
formId: vm.myforms[formIndex]._id,
}).$promise.then(
$q.when(FormApi.deleteForm(vm.myforms[formIndex]._id)).then(
function () {
vm.myforms.splice(formIndex, 1)
vm.cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { range } = require('lodash')
const { LogicType } = require('../../../../../types')
const FormLogic = require('../../services/form-logic/form-logic.client.service')
const AdminFormService = require('../../../../services/AdminFormService')
const UpdateFormService = require('../../../../services/UpdateFormService')

angular
.module('forms')
Expand Down Expand Up @@ -272,7 +272,7 @@ function EditLogicModalController(
}

vm.createNewLogic = function (newLogic) {
$q.when(AdminFormService.createFormLogic(vm.myform._id, newLogic))
$q.when(UpdateFormService.createFormLogic(vm.myform._id, newLogic))
.then((createdLogic) => {
vm.formLogics.push(createdLogic)
externalScope.myform.form_logics.push(createdLogic) // update global myform
Expand All @@ -290,7 +290,7 @@ function EditLogicModalController(
vm.updateExistingLogic = function (logicIndex, updatedLogic) {
const logicIdToUpdate = vm.formLogics[logicIndex]._id
$q.when(
AdminFormService.updateFormLogic(
UpdateFormService.updateFormLogic(
vm.myform._id,
logicIdToUpdate,
updatedLogic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ angular
'$timeout',
'$window',
'Toastr',
'$q',
ListFormsController,
])

Expand All @@ -29,6 +30,7 @@ function ListFormsController(
$timeout,
$window,
Toastr,
$q,
) {
const vm = this

Expand Down Expand Up @@ -74,7 +76,7 @@ function ListFormsController(
// Massage user email into a name
turnEmailToName()

FormApi.query(function (_forms) {
$q.when(FormApi.getDashboardView()).then((_forms) => {
vm.myforms = _forms
})
}
Expand Down Expand Up @@ -192,9 +194,9 @@ function ListFormsController(
resolve: {
FormToDuplicate: () => {
// Retrieve the form so that we can populate the modal with any existing email recipients
return FormApi.preview({
formId: vm.myforms[formIndex]._id,
}).$promise.then((res) => res.form)
return $q
.when(FormApi.previewForm(vm.myforms[formIndex]._id))
.then((res) => res.form)
},
createFormModalOptions: () => ({ mode: 'duplicate' }),
externalScope: () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const get = require('lodash/get')
const FieldVerificationService = require('../../../../services/FieldVerificationService')
const PublicFormAuthService = require('../../../../services/PublicFormAuthService')
const PublicFormService = require('../../../../services/PublicFormService')
const AdminFormService = require('../../../../services/AdminFormService')
const UpdateFormService = require('../../../../services/UpdateFormService')
const {
getVisibleFieldIds,
getLogicUnitPreventingSubmit,
Expand Down Expand Up @@ -324,7 +324,7 @@ function submitFormDirective(
const content = { responses: submissionContent.responses }

const submitFn = form.isPreview
? AdminFormService.submitEmailModeFormPreview
? UpdateFormService.submitEmailModeFormPreview
: PublicFormService.submitEmailModeForm

return $q
Expand All @@ -341,7 +341,7 @@ function submitFormDirective(
}
case responseModeEnum.ENCRYPT: {
const submitFn = form.isPreview
? AdminFormService.submitStorageModeFormPreview
? UpdateFormService.submitStorageModeFormPreview
: PublicFormService.submitStorageModeForm

return $q
Expand Down
Loading