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..45ebecb0dd --- /dev/null +++ b/src/common/utilService/utilService.ts @@ -0,0 +1,53 @@ +// 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 + // eslint-disable-next-line @typescript-eslint/no-explicit-any + .directive('autoFillSync', ($timeout: angular.ITimeoutService) => { + return { + require: 'ngModel', + link: ( + _scope: angular.IScope, + elem: angular.IAugmentedJQuery, + _attrs: angular.IAttributes, + ngModel: angular.INgModelController + ) => { + const origVal = elem.val(); + $timeout(() => { + const newVal = elem.val(); + if (ngModel.$pristine && origVal !== newVal) { + ngModel.$setViewValue(newVal); + } + }, 500); + }, + }; + });