From b476a794e85f03000e3f6c9b194e19a4175073c5 Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Sat, 29 Feb 2020 16:15:17 +1000 Subject: [PATCH 01/10] adds utility.js, includes it in JsIntialize.js --- src/Umbraco.Web.UI.Client/.eslintrc | 4 +- src/Umbraco.Web.UI.Client/src/utility.js | 62 ++++++++++++++++++++++ src/Umbraco.Web/JavaScript/JsInitialize.js | 1 + 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/utility.js diff --git a/src/Umbraco.Web.UI.Client/.eslintrc b/src/Umbraco.Web.UI.Client/.eslintrc index 1bfa081b9a7a..97581229428b 100644 --- a/src/Umbraco.Web.UI.Client/.eslintrc +++ b/src/Umbraco.Web.UI.Client/.eslintrc @@ -19,10 +19,10 @@ "tinyMCE": false, "FileReader": false, "Umbraco": false, + "umb": false, "window": false, "LazyLoad": false, "ActiveXObject": false, "Bloodhound": false } - -} \ No newline at end of file +} diff --git a/src/Umbraco.Web.UI.Client/src/utility.js b/src/Umbraco.Web.UI.Client/src/utility.js new file mode 100644 index 000000000000..036adc8952fb --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/utility.js @@ -0,0 +1,62 @@ +/** + * A friendly utility collection to replace AngularJs' ng-functions + * If it doesn't exist here, it's probably available as vanilla JS + * + * Still carries a dependency on lodash, but if usages of lodash from + * elsewhere in the codebase can instead use these methods, the lodash + * dependency will be nicely abstracted and can be removed/swapped later + */ + +var umb = umb || {}; + +/** + * Equivalent to angular.noop + */ +umb.noop = () => {}; + +/** + * Equivalent to angular.copy + * Abstraction of lodasd.cloneDeep + */ +umb.copy = val => _.clone(val); + +/** + * Equivalent to angular.isArray + */ +umb.isArray = val => Array.isArray(val) || val instanceof Array; + +/** + * Equivalent to angular.equals + * Abstraction of lodash.isEqual + */ +umb.equals = (a, b) => _.isEqual(a, b); + +/** + * Equivalent to angular.isFunction + */ +umb.isFunction = val => typeof val === 'function'; + +/** + * Equivalent to angular.isUndefined + */ +umb.isUndefined = val => typeof val === 'undefined'; + +/** + * Equivalent to angular.isDefined. Inverts result of umb.isUndefined + */ +umb.isDefined = val => !umb.isUndefined(val); + +/** + * Equivalent to angular.isString + */ +umb.isString = val => typeof val === 'string'; + +/** + * Equivalent to angular.isNumber + */ +umb.isNumber = val => typeof val === 'number'; + +/** + * Equivalent to angular.isObject + */ +umb.isObject = val => val !== null && typeof val === 'object'; \ No newline at end of file diff --git a/src/Umbraco.Web/JavaScript/JsInitialize.js b/src/Umbraco.Web/JavaScript/JsInitialize.js index 4b0a457b64af..30243867f43b 100644 --- a/src/Umbraco.Web/JavaScript/JsInitialize.js +++ b/src/Umbraco.Web/JavaScript/JsInitialize.js @@ -33,6 +33,7 @@ 'lib/umbraco/NamespaceManager.js', 'lib/umbraco/LegacySpeechBubble.js', + 'js/utility.js', 'js/app.js', 'js/umbraco.resources.js', From ed6dc796ed79eed704fa25f4576821824fd44892 Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Sat, 29 Feb 2020 16:25:27 +1000 Subject: [PATCH 02/10] replaces all instances of angular.noop with shiny new dependency-free umb.noop --- .../src/common/services/angularhelper.service.js | 10 +++++----- src/Umbraco.Web.UI.Client/src/main.controller.js | 13 +++++++------ .../src/views/documenttypes/edit.controller.js | 2 +- .../src/views/packages/views/created.controller.js | 2 +- .../src/views/partialviewmacros/edit.controller.js | 2 +- .../src/views/users/user.controller.js | 2 +- .../views/users/views/groups/groups.controller.js | 2 +- .../src/views/users/views/users/users.controller.js | 2 +- .../test/lib/angular/angular-mocks.js | 8 ++++---- 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js index 455857c1e1f8..806c31e3a8c9 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js @@ -178,11 +178,11 @@ function angularHelper($q) { $valid: true, $submitted: false, $pending: undefined, - $addControl: angular.noop, - $removeControl: angular.noop, - $setValidity: angular.noop, - $setDirty: angular.noop, - $setPristine: angular.noop, + $addControl: umb.noop, + $removeControl: umb.noop, + $setValidity: umb.noop, + $setDirty: umb.noop, + $setPristine: umb.noop, $name: formName }; } diff --git a/src/Umbraco.Web.UI.Client/src/main.controller.js b/src/Umbraco.Web.UI.Client/src/main.controller.js index 883907d1dc8d..7ea2b8c540d1 100644 --- a/src/Umbraco.Web.UI.Client/src/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/main.controller.js @@ -1,19 +1,18 @@ - -/** +/** * @ngdoc controller - * @name Umbraco.MainController + * @name Umbraco.MainController * @function * - * @description + * @description * The main application controller * */ function MainController($scope, $location, appState, treeService, notificationsService, userService, historyService, updateChecker, navigationService, eventsService, tmhDynamicLocale, localStorageService, editorService, overlayService, assetsService, tinyMceAssets) { - + //the null is important because we do an explicit bool check on this in the view - $scope.authenticated = null; + $scope.authenticated = null; $scope.touchDevice = appState.getGlobalState("touchDevice"); $scope.infiniteMode = false; $scope.overlay = {}; @@ -22,6 +21,8 @@ function MainController($scope, $location, appState, treeService, notificationsS $scope.login = {}; $scope.tabbingActive = false; + console.log(umb.equals(1, 3)); + // Load TinyMCE assets ahead of time in the background for the user // To help with first load of the RTE tinyMceAssets.forEach(function (tinyJsAsset) { diff --git a/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js index b04cccbc0d51..ff3d71954104 100644 --- a/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js @@ -325,7 +325,7 @@ /* ---------- SAVE ---------- */ function save() { - saveInternal().then(angular.noop, angular.noop); + saveInternal().then(umb.noop, umb.noop); } /** This internal save method performs the actual saving and returns a promise, not to be bound to any buttons but used by other bound methods */ diff --git a/src/Umbraco.Web.UI.Client/src/views/packages/views/created.controller.js b/src/Umbraco.Web.UI.Client/src/views/packages/views/created.controller.js index 295057e60945..0b59494f79bd 100644 --- a/src/Umbraco.Web.UI.Client/src/views/packages/views/created.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/packages/views/created.controller.js @@ -15,7 +15,7 @@ packageResource.getAllCreated().then(createdPackages => { vm.createdPackages = createdPackages; - }, angular.noop); + }, umb.noop); } diff --git a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js index aa37a9191923..4847831a0130 100644 --- a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js @@ -80,7 +80,7 @@ activate: false }); completeSave(saved); - }, angular.noop); + }, umb.noop); } else { diff --git a/src/Umbraco.Web.UI.Client/src/views/users/user.controller.js b/src/Umbraco.Web.UI.Client/src/views/users/user.controller.js index 9534eea9fd2e..02df0e20f89b 100644 --- a/src/Umbraco.Web.UI.Client/src/views/users/user.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/users/user.controller.js @@ -168,7 +168,7 @@ extendedSave(saved).then(function(result) { //if all is good, then reset the form formHelper.resetForm({ scope: $scope }); - }, angular.noop); + }, umb.noop); vm.user = _.omit(saved, "navigation"); //restore diff --git a/src/Umbraco.Web.UI.Client/src/views/users/views/groups/groups.controller.js b/src/Umbraco.Web.UI.Client/src/views/users/views/groups/groups.controller.js index 984866dca16d..2e05d88eec5f 100644 --- a/src/Umbraco.Web.UI.Client/src/views/users/views/groups/groups.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/users/views/groups/groups.controller.js @@ -112,7 +112,7 @@ userGroupsResource.deleteUserGroups(_.pluck(vm.selection, "id")).then(function (data) { clearSelection(); onInit(); - }, angular.noop); + }, umb.noop); overlayService.close(); } }; diff --git a/src/Umbraco.Web.UI.Client/src/views/users/views/users/users.controller.js b/src/Umbraco.Web.UI.Client/src/views/users/views/users/users.controller.js index f3c28fdb9d36..db4381186b81 100644 --- a/src/Umbraco.Web.UI.Client/src/views/users/views/users/users.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/users/views/users/users.controller.js @@ -386,7 +386,7 @@ vm.selectedBulkUserGroups = []; editorService.close(); clearSelection(); - }, angular.noop); + }, umb.noop); }, close: function () { vm.selectedBulkUserGroups = []; diff --git a/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js b/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js index b4a3fb9ed6c2..d488d6bfb4bf 100644 --- a/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js +++ b/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js @@ -43,8 +43,8 @@ angular.mock.$Browser = function () { self.pollFns = []; // TODO(vojta): remove this temporary api - self.$$completeOutstandingRequest = angular.noop; - self.$$incOutstandingRequestCount = angular.noop; + self.$$completeOutstandingRequest = umb.noop; + self.$$incOutstandingRequestCount = umb.noop; // register url polling fn @@ -1440,7 +1440,7 @@ function MockXhr() { return lines.join('\n'); }; - this.abort = angular.noop; + this.abort = umb.noop; } @@ -1873,7 +1873,7 @@ window.jstestdriver && (function (window) { } for (var i = 0, ii = blockFns.length; i < ii; i++) { try { - injector.invoke(blockFns[i] || angular.noop, this); + injector.invoke(blockFns[i] || umb.noop, this); } catch (e) { if (e.stack && errorForStack) e.stack += '\n' + errorForStack.stack; throw e; From 8de25f73d2921ebeb8e1dfd0226a1d969d65c259 Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Sat, 29 Feb 2020 18:23:22 +1000 Subject: [PATCH 03/10] remove leftover bit --- src/Umbraco.Web.UI.Client/src/main.controller.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/main.controller.js b/src/Umbraco.Web.UI.Client/src/main.controller.js index 7ea2b8c540d1..198ac132c13a 100644 --- a/src/Umbraco.Web.UI.Client/src/main.controller.js +++ b/src/Umbraco.Web.UI.Client/src/main.controller.js @@ -21,8 +21,6 @@ function MainController($scope, $location, appState, treeService, notificationsS $scope.login = {}; $scope.tabbingActive = false; - console.log(umb.equals(1, 3)); - // Load TinyMCE assets ahead of time in the background for the user // To help with first load of the RTE tinyMceAssets.forEach(function (tinyJsAsset) { From 3fb99309a0f68644821094f5bbce31e7b7b23e31 Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Sat, 29 Feb 2020 18:27:04 +1000 Subject: [PATCH 04/10] leave mocks alone --- .../test/lib/angular/angular-mocks.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js b/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js index d488d6bfb4bf..c1d82ecb08f5 100644 --- a/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js +++ b/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js @@ -43,8 +43,8 @@ angular.mock.$Browser = function () { self.pollFns = []; // TODO(vojta): remove this temporary api - self.$$completeOutstandingRequest = umb.noop; - self.$$incOutstandingRequestCount = umb.noop; + self.$$completeOutstandingRequest = anuglar.noop; + self.$$incOutstandingRequestCount = angular.noop; // register url polling fn @@ -1440,7 +1440,7 @@ function MockXhr() { return lines.join('\n'); }; - this.abort = umb.noop; + this.abort = angular.noop; } @@ -1873,7 +1873,7 @@ window.jstestdriver && (function (window) { } for (var i = 0, ii = blockFns.length; i < ii; i++) { try { - injector.invoke(blockFns[i] || umb.noop, this); + injector.invoke(blockFns[i] || angular.noop, this); } catch (e) { if (e.stack && errorForStack) e.stack += '\n' + errorForStack.stack; throw e; From 4bb4d2a636e25d1d1ecbc0fe755e2437c0b06d47 Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Sat, 29 Feb 2020 18:52:12 +1000 Subject: [PATCH 05/10] make it testable --- src/Umbraco.Web.UI.Client/gulp/config.js | 4 +- .../common/services/angularhelper.service.js | 2 +- src/Umbraco.Web.UI.Client/src/utility.js | 107 ++++++++++-------- src/Umbraco.Web/JavaScript/JsInitialize.js | 1 - 4 files changed, 65 insertions(+), 49 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/gulp/config.js b/src/Umbraco.Web.UI.Client/gulp/config.js index 59e8bf6c05f1..c7801f72b553 100755 --- a/src/Umbraco.Web.UI.Client/gulp/config.js +++ b/src/Umbraco.Web.UI.Client/gulp/config.js @@ -28,9 +28,9 @@ module.exports = { installer: { files: "./src/installer/**/*.js", out: "umbraco.installer.js" }, filters: { files: "./src/common/filters/**/*.js", out: "umbraco.filters.js" }, resources: { files: "./src/common/resources/**/*.js", out: "umbraco.resources.js" }, - services: { files: "./src/common/services/**/*.js", out: "umbraco.services.js" }, + services: { files: ["./src/common/services/**/*.js", "./src/utility.js"], out: "umbraco.services.js" }, security: { files: "./src/common/interceptors/**/*.js", out: "umbraco.interceptors.js" }, - + //the controllers for views controllers: { files: [ diff --git a/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js index 806c31e3a8c9..9bffee092efc 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js @@ -179,7 +179,7 @@ function angularHelper($q) { $submitted: false, $pending: undefined, $addControl: umb.noop, - $removeControl: umb.noop, + $removeControl: umb.noop, $setValidity: umb.noop, $setDirty: umb.noop, $setPristine: umb.noop, diff --git a/src/Umbraco.Web.UI.Client/src/utility.js b/src/Umbraco.Web.UI.Client/src/utility.js index 036adc8952fb..332e995e4c29 100644 --- a/src/Umbraco.Web.UI.Client/src/utility.js +++ b/src/Umbraco.Web.UI.Client/src/utility.js @@ -2,61 +2,78 @@ * A friendly utility collection to replace AngularJs' ng-functions * If it doesn't exist here, it's probably available as vanilla JS * - * Still carries a dependency on lodash, but if usages of lodash from - * elsewhere in the codebase can instead use these methods, the lodash + * Still carries a dependency on underscore, but if usages of underscore from + * elsewhere in the codebase can instead use these methods, the underscore * dependency will be nicely abstracted and can be removed/swapped later */ +(function (window) { -var umb = umb || {}; + /** + * Equivalent to angular.noop + */ + const noop = () => { }; -/** - * Equivalent to angular.noop - */ -umb.noop = () => {}; + /** + * Equivalent to angular.copy + * Abstraction of underscore.clone + */ + const copy = val => _.clone(val); -/** - * Equivalent to angular.copy - * Abstraction of lodasd.cloneDeep - */ -umb.copy = val => _.clone(val); + /** + * Equivalent to angular.isArray + */ + const isArray = val => Array.isArray(val) || val instanceof Array; -/** - * Equivalent to angular.isArray - */ -umb.isArray = val => Array.isArray(val) || val instanceof Array; + /** + * Equivalent to angular.equals + * Abstraction of underscore.isEqual + */ + const equals = (a, b) => _.isEqual(a, b); -/** - * Equivalent to angular.equals - * Abstraction of lodash.isEqual - */ -umb.equals = (a, b) => _.isEqual(a, b); + /** + * Equivalent to angular.isFunction + */ + const isFunction = val => typeof val === 'function'; -/** - * Equivalent to angular.isFunction - */ -umb.isFunction = val => typeof val === 'function'; + /** + * Equivalent to angular.isUndefined + */ + const isUndefined = val => typeof val === 'undefined'; -/** - * Equivalent to angular.isUndefined - */ -umb.isUndefined = val => typeof val === 'undefined'; + /** + * Equivalent to angular.isDefined. Inverts result of const isUndefined + */ + const isDefined = val => !isUndefined(val); -/** - * Equivalent to angular.isDefined. Inverts result of umb.isUndefined - */ -umb.isDefined = val => !umb.isUndefined(val); + /** + * Equivalent to angular.isString + */ + const isString = val => typeof val === 'string'; -/** - * Equivalent to angular.isString - */ -umb.isString = val => typeof val === 'string'; + /** + * Equivalent to angular.isNumber + */ + const isNumber = val => typeof val === 'number'; -/** - * Equivalent to angular.isNumber - */ -umb.isNumber = val => typeof val === 'number'; + /** + * Equivalent to angular.isObject + */ + const isObject = val => val !== null && typeof val === 'object'; -/** - * Equivalent to angular.isObject - */ -umb.isObject = val => val !== null && typeof val === 'object'; \ No newline at end of file + let _umb = { + noop: noop, + copy: copy, + isArray: isArray, + equals: equals, + isFunction: isFunction, + isUndefined: isUndefined, + isDefined: isDefined, + isString: isString, + isNumber: isNumber, + isObject: isObject + }; + + if (typeof (window.umb) === 'undefined') { + window.umb = _umb; + } +})(window); \ No newline at end of file diff --git a/src/Umbraco.Web/JavaScript/JsInitialize.js b/src/Umbraco.Web/JavaScript/JsInitialize.js index 30243867f43b..4b0a457b64af 100644 --- a/src/Umbraco.Web/JavaScript/JsInitialize.js +++ b/src/Umbraco.Web/JavaScript/JsInitialize.js @@ -33,7 +33,6 @@ 'lib/umbraco/NamespaceManager.js', 'lib/umbraco/LegacySpeechBubble.js', - 'js/utility.js', 'js/app.js', 'js/umbraco.resources.js', From dde27535c9682c532c2b2eb19dc509bdb913587a Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Sat, 29 Feb 2020 18:59:01 +1000 Subject: [PATCH 06/10] anuglar => angular --- src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js b/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js index c1d82ecb08f5..b4a3fb9ed6c2 100644 --- a/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js +++ b/src/Umbraco.Web.UI.Client/test/lib/angular/angular-mocks.js @@ -43,7 +43,7 @@ angular.mock.$Browser = function () { self.pollFns = []; // TODO(vojta): remove this temporary api - self.$$completeOutstandingRequest = anuglar.noop; + self.$$completeOutstandingRequest = angular.noop; self.$$incOutstandingRequestCount = angular.noop; From ad48ae6baa2d78e6eced28998ee0afa830865b6a Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Tue, 3 Mar 2020 08:47:39 +1000 Subject: [PATCH 07/10] update utility naming from `umb` to `Utility` because it makes sense. Updated umb.noop examples to Utility.noop --- .../src/common/services/angularhelper.service.js | 10 +++++----- src/Umbraco.Web.UI.Client/src/utility.js | 8 +++++--- .../src/views/documenttypes/edit.controller.js | 2 +- .../src/views/packages/views/created.controller.js | 2 +- .../src/views/partialviewmacros/edit.controller.js | 2 +- .../src/views/users/user.controller.js | 2 +- .../src/views/users/views/groups/groups.controller.js | 2 +- .../src/views/users/views/users/users.controller.js | 2 +- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js index 9bffee092efc..8cba83328f48 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/angularhelper.service.js @@ -178,11 +178,11 @@ function angularHelper($q) { $valid: true, $submitted: false, $pending: undefined, - $addControl: umb.noop, - $removeControl: umb.noop, - $setValidity: umb.noop, - $setDirty: umb.noop, - $setPristine: umb.noop, + $addControl: Utilities.noop, + $removeControl: Utilities.noop, + $setValidity: Utilities.noop, + $setDirty: Utilities.noop, + $setPristine: Utilities.noop, $name: formName }; } diff --git a/src/Umbraco.Web.UI.Client/src/utility.js b/src/Umbraco.Web.UI.Client/src/utility.js index 332e995e4c29..fb58d6120cf0 100644 --- a/src/Umbraco.Web.UI.Client/src/utility.js +++ b/src/Umbraco.Web.UI.Client/src/utility.js @@ -5,6 +5,8 @@ * Still carries a dependency on underscore, but if usages of underscore from * elsewhere in the codebase can instead use these methods, the underscore * dependency will be nicely abstracted and can be removed/swapped later + * + * This collection is open to extension... */ (function (window) { @@ -60,7 +62,7 @@ */ const isObject = val => val !== null && typeof val === 'object'; - let _umb = { + let _utilities = { noop: noop, copy: copy, isArray: isArray, @@ -73,7 +75,7 @@ isObject: isObject }; - if (typeof (window.umb) === 'undefined') { - window.umb = _umb; + if (typeof (window.Utilities) === 'undefined') { + window.Utilities = _utilities; } })(window); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js index ff3d71954104..21eb77b1e997 100644 --- a/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js @@ -325,7 +325,7 @@ /* ---------- SAVE ---------- */ function save() { - saveInternal().then(umb.noop, umb.noop); + saveInternal().then(Utilities.noop, Utilities.noop); } /** This internal save method performs the actual saving and returns a promise, not to be bound to any buttons but used by other bound methods */ diff --git a/src/Umbraco.Web.UI.Client/src/views/packages/views/created.controller.js b/src/Umbraco.Web.UI.Client/src/views/packages/views/created.controller.js index 0b59494f79bd..503d85fe8d0b 100644 --- a/src/Umbraco.Web.UI.Client/src/views/packages/views/created.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/packages/views/created.controller.js @@ -15,7 +15,7 @@ packageResource.getAllCreated().then(createdPackages => { vm.createdPackages = createdPackages; - }, umb.noop); + }, Utilities.noop); } diff --git a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js index 4847831a0130..2f7d879607be 100644 --- a/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/partialviewmacros/edit.controller.js @@ -80,7 +80,7 @@ activate: false }); completeSave(saved); - }, umb.noop); + }, Utilities.noop); } else { diff --git a/src/Umbraco.Web.UI.Client/src/views/users/user.controller.js b/src/Umbraco.Web.UI.Client/src/views/users/user.controller.js index 02df0e20f89b..56d01a860474 100644 --- a/src/Umbraco.Web.UI.Client/src/views/users/user.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/users/user.controller.js @@ -168,7 +168,7 @@ extendedSave(saved).then(function(result) { //if all is good, then reset the form formHelper.resetForm({ scope: $scope }); - }, umb.noop); + }, Utilities.noop); vm.user = _.omit(saved, "navigation"); //restore diff --git a/src/Umbraco.Web.UI.Client/src/views/users/views/groups/groups.controller.js b/src/Umbraco.Web.UI.Client/src/views/users/views/groups/groups.controller.js index 2e05d88eec5f..31c52a344bef 100644 --- a/src/Umbraco.Web.UI.Client/src/views/users/views/groups/groups.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/users/views/groups/groups.controller.js @@ -112,7 +112,7 @@ userGroupsResource.deleteUserGroups(_.pluck(vm.selection, "id")).then(function (data) { clearSelection(); onInit(); - }, umb.noop); + }, Utilities.noop); overlayService.close(); } }; diff --git a/src/Umbraco.Web.UI.Client/src/views/users/views/users/users.controller.js b/src/Umbraco.Web.UI.Client/src/views/users/views/users/users.controller.js index db4381186b81..4ac385921ed5 100644 --- a/src/Umbraco.Web.UI.Client/src/views/users/views/users/users.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/users/views/users/users.controller.js @@ -386,7 +386,7 @@ vm.selectedBulkUserGroups = []; editorService.close(); clearSelection(); - }, umb.noop); + }, Utilities.noop); }, close: function () { vm.selectedBulkUserGroups = []; From 9ac96f5f1d7f59c851feafafa8360d60f0c90f50 Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Tue, 10 Mar 2020 17:53:33 +1000 Subject: [PATCH 08/10] consistent naming - Utilities --- src/Umbraco.Web.UI.Client/.eslintrc | 2 +- src/Umbraco.Web.UI.Client/gulp/config.js | 2 +- src/Umbraco.Web.UI.Client/src/{utility.js => utilities.js} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/Umbraco.Web.UI.Client/src/{utility.js => utilities.js} (100%) diff --git a/src/Umbraco.Web.UI.Client/.eslintrc b/src/Umbraco.Web.UI.Client/.eslintrc index 97581229428b..a4010917fb0c 100644 --- a/src/Umbraco.Web.UI.Client/.eslintrc +++ b/src/Umbraco.Web.UI.Client/.eslintrc @@ -19,7 +19,7 @@ "tinyMCE": false, "FileReader": false, "Umbraco": false, - "umb": false, + "Utilities": false, "window": false, "LazyLoad": false, "ActiveXObject": false, diff --git a/src/Umbraco.Web.UI.Client/gulp/config.js b/src/Umbraco.Web.UI.Client/gulp/config.js index c7801f72b553..39dc9bb2a46b 100755 --- a/src/Umbraco.Web.UI.Client/gulp/config.js +++ b/src/Umbraco.Web.UI.Client/gulp/config.js @@ -28,7 +28,7 @@ module.exports = { installer: { files: "./src/installer/**/*.js", out: "umbraco.installer.js" }, filters: { files: "./src/common/filters/**/*.js", out: "umbraco.filters.js" }, resources: { files: "./src/common/resources/**/*.js", out: "umbraco.resources.js" }, - services: { files: ["./src/common/services/**/*.js", "./src/utility.js"], out: "umbraco.services.js" }, + services: { files: ["./src/common/services/**/*.js", "./src/utilities.js"], out: "umbraco.services.js" }, security: { files: "./src/common/interceptors/**/*.js", out: "umbraco.interceptors.js" }, //the controllers for views diff --git a/src/Umbraco.Web.UI.Client/src/utility.js b/src/Umbraco.Web.UI.Client/src/utilities.js similarity index 100% rename from src/Umbraco.Web.UI.Client/src/utility.js rename to src/Umbraco.Web.UI.Client/src/utilities.js From 3b74fcdec649170a3a3e7ab6e8dc7e16bcbdfafc Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Tue, 10 Mar 2020 19:05:36 +1000 Subject: [PATCH 09/10] copy and equals are now facades to angular methods. can deal with these later. --- src/Umbraco.Web.UI.Client/src/utilities.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/utilities.js b/src/Umbraco.Web.UI.Client/src/utilities.js index fb58d6120cf0..9a0475af1c3b 100644 --- a/src/Umbraco.Web.UI.Client/src/utilities.js +++ b/src/Umbraco.Web.UI.Client/src/utilities.js @@ -16,10 +16,9 @@ const noop = () => { }; /** - * Equivalent to angular.copy - * Abstraction of underscore.clone + * Facade to angular.copy */ - const copy = val => _.clone(val); + const copy = val => angular.copy(val); /** * Equivalent to angular.isArray @@ -27,10 +26,9 @@ const isArray = val => Array.isArray(val) || val instanceof Array; /** - * Equivalent to angular.equals - * Abstraction of underscore.isEqual + * Facade to angular.equals */ - const equals = (a, b) => _.isEqual(a, b); + const equals = (a, b) => angular.equals(a, b); /** * Equivalent to angular.isFunction From 7c8d90682b8c885b87c60430223cb79446253373 Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Tue, 10 Mar 2020 20:28:58 +1000 Subject: [PATCH 10/10] facade to angular.extend --- src/Umbraco.Web.UI.Client/src/utilities.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Umbraco.Web.UI.Client/src/utilities.js b/src/Umbraco.Web.UI.Client/src/utilities.js index 9a0475af1c3b..bd12506358d7 100644 --- a/src/Umbraco.Web.UI.Client/src/utilities.js +++ b/src/Umbraco.Web.UI.Client/src/utilities.js @@ -29,6 +29,12 @@ * Facade to angular.equals */ const equals = (a, b) => angular.equals(a, b); + + /** + * Facade to angular.extend + * Use this with Angular objects, for vanilla JS objects, use Object.assign() + */ + const extend = (dst, src) => angular.extend(dst, src); /** * Equivalent to angular.isFunction @@ -65,6 +71,7 @@ copy: copy, isArray: isArray, equals: equals, + extend: extend, isFunction: isFunction, isUndefined: isUndefined, isDefined: isDefined,