From 4ed0f0fb389eb1144367a06d64903a5c7f356bf2 Mon Sep 17 00:00:00 2001 From: LoneRifle Date: Mon, 14 Jun 2021 15:48:17 +0800 Subject: [PATCH] refactor(angularjs): remove angular-moment As we have no need for the AngularJS filters and directives that angular-moment provides, remove it completely, referencing moment as a CommonJS module instead --- package-lock.json | 8 -------- package.json | 1 - src/public/main.js | 5 ----- .../admin/controllers/admin-form.client.controller.js | 3 +-- .../admin/controllers/list-forms.client.controller.js | 4 ++-- .../admin/controllers/view-responses.client.controller.js | 4 ++-- .../forms/base/components/end-page.client.component.js | 6 ++++-- 7 files changed, 9 insertions(+), 22 deletions(-) diff --git a/package-lock.json b/package-lock.json index e33559f1f1..6cb6e8da55 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7306,14 +7306,6 @@ "resolved": "https://registry.npmjs.org/angular-messages/-/angular-messages-1.8.2.tgz", "integrity": "sha512-M1qNh/30cLJi4yJJ+3YB8saPonRcavz5Dquqz0T/aUySKJhIkUoeCkmF+BcLH4SJ5PBp04yy4CZUUeNRVi7jZA==" }, - "angular-moment": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/angular-moment/-/angular-moment-1.3.0.tgz", - "integrity": "sha512-KG8rvO9MoaBLwtGnxTeUveSyNtrL+RNgGl1zqWN36+HDCCVGk2DGWOzqKWB6o+eTTbO3Opn4hupWKIElc8XETA==", - "requires": { - "moment": ">=2.8.0 <3.0.0" - } - }, "angular-permission": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/angular-permission/-/angular-permission-1.1.1.tgz", diff --git a/package.json b/package.json index b96b97902a..b1602f139c 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,6 @@ "angular-cookies": "~1.8.2", "angular-drag-scroll": "^0.2.1", "angular-messages": "^1.8.2", - "angular-moment": "~1.3.0", "angular-permission": "~1.1.1", "angular-resource": "^1.8.2", "angular-sanitize": "^1.8.2", diff --git a/src/public/main.js b/src/public/main.js index bcd27611b4..4fc9487249 100644 --- a/src/public/main.js +++ b/src/public/main.js @@ -13,7 +13,6 @@ const moduleDependencies = [ 'ngResource', 'ui.router', 'ui.bootstrap', - 'angularMoment', 'vcRecaptcha', 'users', 'ngFileUpload', @@ -55,7 +54,6 @@ require('angular-permission/dist/angular-permission') require('@opengovsg/angular-recaptcha-fallback') require('angular-resource') require('angular-sanitize') -require('angular-moment') require('angular-messages') require('angular-ui-bootstrap') @@ -85,9 +83,6 @@ const appName = 'FormSG' // Add module dependencies const app = angular.module(appName, moduleDependencies) -// Override moment using Angular's dependency injection -app.constant('moment', require('moment-timezone')) - // Setting HTML5 Location Mode angular.module(appName).config([ '$locationProvider', diff --git a/src/public/modules/forms/admin/controllers/admin-form.client.controller.js b/src/public/modules/forms/admin/controllers/admin-form.client.controller.js index 9efd6f5912..08f65a289b 100644 --- a/src/public/modules/forms/admin/controllers/admin-form.client.controller.js +++ b/src/public/modules/forms/admin/controllers/admin-form.client.controller.js @@ -2,6 +2,7 @@ const { StatusCodes } = require('http-status-codes') const get = require('lodash/get') +const moment = require('moment-timezone') const { LogicType } = require('../../../../../types') const UpdateFormService = require('../../../../services/UpdateFormService') const UserService = require('../../../../services/UserService') @@ -43,7 +44,6 @@ angular '$uibModal', 'FormData', 'FormFields', - 'moment', 'Toastr', '$state', '$window', @@ -58,7 +58,6 @@ function AdminFormController( $uibModal, FormData, FormFields, - moment, Toastr, $state, $window, diff --git a/src/public/modules/forms/admin/controllers/list-forms.client.controller.js b/src/public/modules/forms/admin/controllers/list-forms.client.controller.js index ece7565ded..659443cb53 100644 --- a/src/public/modules/forms/admin/controllers/list-forms.client.controller.js +++ b/src/public/modules/forms/admin/controllers/list-forms.client.controller.js @@ -1,6 +1,8 @@ 'use strict' const get = require('lodash/get') +const moment = require('moment-timezone') + const BetaService = require('../../../../services/BetaService') const UserService = require('../../../../services/UserService') @@ -12,7 +14,6 @@ angular '$scope', 'FormApi', '$uibModal', - 'moment', '$state', '$timeout', '$window', @@ -25,7 +26,6 @@ function ListFormsController( $scope, FormApi, $uibModal, - moment, $state, $timeout, $window, diff --git a/src/public/modules/forms/admin/controllers/view-responses.client.controller.js b/src/public/modules/forms/admin/controllers/view-responses.client.controller.js index e351cd218f..cef7955405 100644 --- a/src/public/modules/forms/admin/controllers/view-responses.client.controller.js +++ b/src/public/modules/forms/admin/controllers/view-responses.client.controller.js @@ -1,5 +1,7 @@ 'use strict' +const moment = require('moment-timezone') + const { processDecryptedContent, } = require('../../helpers/process-decrypted-content') @@ -24,7 +26,6 @@ angular '$timeout', '$location', '$anchorScroll', - 'moment', ViewResponsesController, ]) @@ -39,7 +40,6 @@ function ViewResponsesController( $timeout, $location, $anchorScroll, - moment, ) { const vm = this diff --git a/src/public/modules/forms/base/components/end-page.client.component.js b/src/public/modules/forms/base/components/end-page.client.component.js index 5bc67e6192..f750ab3516 100644 --- a/src/public/modules/forms/base/components/end-page.client.component.js +++ b/src/public/modules/forms/base/components/end-page.client.component.js @@ -1,5 +1,7 @@ 'use strict' +const moment = require('moment-timezone') + angular.module('forms').component('endPageComponent', { templateUrl: 'modules/forms/base/componentViews/end-page.html', bindings: { @@ -13,11 +15,11 @@ angular.module('forms').component('endPageComponent', { colorTheme: '@', submissionId: '@', }, - controller: ['SpcpSession', '$window', 'moment', endPageController], + controller: ['SpcpSession', '$window', endPageController], controllerAs: 'vm', }) -function endPageController(SpcpSession, $window, moment) { +function endPageController(SpcpSession, $window) { const vm = this vm.timestamp = moment().format('D MMM YYYY, HH:mm')