From cf3b5ee206235e218374ae0bebcaf976d102738a Mon Sep 17 00:00:00 2001 From: sakethsram888 Date: Sun, 10 May 2026 19:18:28 +1000 Subject: [PATCH 1/2] feat: migrate utilService from CoffeeScript to TypeScript --- .../vendor-dependencies.ts | 31 ++++++++++++ src/app/doubtfire-angularjs.module.ts | 4 +- src/common/utilService/utilService.ts | 47 +++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 src/app/config/vendor-dependencies/vendor-dependencies.ts create mode 100644 src/common/utilService/utilService.ts diff --git a/src/app/config/vendor-dependencies/vendor-dependencies.ts b/src/app/config/vendor-dependencies/vendor-dependencies.ts new file mode 100644 index 0000000000..5b8c7436b5 --- /dev/null +++ b/src/app/config/vendor-dependencies/vendor-dependencies.ts @@ -0,0 +1,31 @@ +// Use this module to define all third-party dependencies +// that are used in Doubtfire + +import * as angular from 'angular'; + +export const vendorDependencies = angular.module('doubtfire.config.vendor-dependencies', [ + // ng* + 'ngCsv', + 'ngSanitize', + + // templates + 'templates-app', + + // ui.* + 'ui.router', + 'ui.router.upgrade', + 'ui.bootstrap', + 'ui.codemirror', + + // other libraries + 'angular.filter', + 'localization', + 'markdown', + 'nvd3', + 'xeditable', + 'angular-md5', + + // analytics + 'angulartics', + 'angulartics.google.analytics', +]); diff --git a/src/app/doubtfire-angularjs.module.ts b/src/app/doubtfire-angularjs.module.ts index ca57426fd2..d8c7505960 100644 --- a/src/app/doubtfire-angularjs.module.ts +++ b/src/app/doubtfire-angularjs.module.ts @@ -55,7 +55,7 @@ import 'build/src/app/config/runtime/runtime.js'; import 'build/src/app/config/config.js'; import 'build/src/app/config/root-controller/root-controller.js'; import 'build/src/app/config/routing/routing.js'; -import 'build/src/app/config/vendor-dependencies/vendor-dependencies.js'; +import './config/vendor-dependencies/vendor-dependencies'; import 'build/src/app/config/analytics/analytics.js'; import 'build/src/app/config/debug/debug.js'; import 'build/src/app/projects/projects.js'; @@ -129,7 +129,7 @@ import 'build/src/app/errors/errors.js'; import 'build/src/app/errors/states/unauthorised/unauthorised.js'; import 'build/src/app/errors/states/timeout/timeout.js'; import 'build/src/app/errors/states/states.js'; -import 'build/src/common/utilService/utilService.js'; +import '../common/utilService/utilService'; import 'build/src/common/i18n/localize.js'; import 'build/src/i18n/resources-locale_default.js'; import 'build/src/i18n/resources-locale_en-US.js'; diff --git a/src/common/utilService/utilService.ts b/src/common/utilService/utilService.ts new file mode 100644 index 0000000000..7622360d9b --- /dev/null +++ b/src/common/utilService/utilService.ts @@ -0,0 +1,47 @@ +// Use this module to define utility filters and directives +// that are used throughout Doubtfire + +import * as angular from 'angular'; +import moment from 'moment'; +import * as _ from 'lodash'; + +export const utilService = angular.module('utilService', []) + + // Returns a human-readable "time ago" string from a date + .filter('fromNow', () => { + return (date: string) => { + return moment(new Date(date)).fromNow(); + }; + }) + + // Converts text to title case + .filter('titleize', () => { + return (input: string) => { + return _.startCase(_.toLower(input)); + }; + }) + + // Converts text to a human-readable format + .filter('humanize', () => { + return (input: string) => { + return _.startCase(input); + }; + }) + + // A directive to ensure browser form auto-fill works, + // since Angular doesn't support it. + // See: http://stackoverflow.com/a/14966711 + .directive('autoFillSync', ($timeout: angular.ITimeoutService) => { + return { + require: 'ngModel', + link: (scope: angular.IScope, elem: any, attrs: any, ngModel: any) => { + const origVal = elem.val(); + $timeout(() => { + const newVal = elem.val(); + if (ngModel.$pristine && origVal !== newVal) { + ngModel.$setViewValue(newVal); + } + }, 500); + }, + }; + }); From 881c701168c3076c9a52b76a9e7343ac598d1118 Mon Sep 17 00:00:00 2001 From: sakethsram888 Date: Sun, 10 May 2026 19:29:59 +1000 Subject: [PATCH 2/2] fix: resolve TypeScript type errors in utilService --- src/common/utilService/utilService.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/utilService/utilService.ts b/src/common/utilService/utilService.ts index 7622360d9b..45ebecb0dd 100644 --- a/src/common/utilService/utilService.ts +++ b/src/common/utilService/utilService.ts @@ -31,10 +31,16 @@ export const utilService = angular.module('utilService', []) // A directive to ensure browser form auto-fill works, // since Angular doesn't support it. // See: http://stackoverflow.com/a/14966711 + // eslint-disable-next-line @typescript-eslint/no-explicit-any .directive('autoFillSync', ($timeout: angular.ITimeoutService) => { return { require: 'ngModel', - link: (scope: angular.IScope, elem: any, attrs: any, ngModel: any) => { + link: ( + _scope: angular.IScope, + elem: angular.IAugmentedJQuery, + _attrs: angular.IAttributes, + ngModel: angular.INgModelController + ) => { const origVal = elem.val(); $timeout(() => { const newVal = elem.val();