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

adds utility.js as facade to generic javascript utility functions #7738

4 changes: 2 additions & 2 deletions src/Umbraco.Web.UI.Client/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"tinyMCE": false,
"FileReader": false,
"Umbraco": false,
"Utilities": false,
"window": false,
"LazyLoad": false,
"ActiveXObject": false,
"Bloodhound": false
}

}
}
4 changes: 2 additions & 2 deletions src/Umbraco.Web.UI.Client/gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/utilities.js"], out: "umbraco.services.js" },
security: { files: "./src/common/interceptors/**/*.js", out: "umbraco.interceptors.js" },

//the controllers for views
controllers: {
files: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: Utilities.noop,
$removeControl: Utilities.noop,
$setValidity: Utilities.noop,
$setDirty: Utilities.noop,
$setPristine: Utilities.noop,
$name: formName
};
}
Expand Down
11 changes: 5 additions & 6 deletions src/Umbraco.Web.UI.Client/src/main.controller.js
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down
86 changes: 86 additions & 0 deletions src/Umbraco.Web.UI.Client/src/utilities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* 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 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) {

/**
* Equivalent to angular.noop
*/
const noop = () => { };

/**
* Facade to angular.copy
*/
const copy = val => angular.copy(val);

/**
* Equivalent to angular.isArray
*/
const isArray = val => Array.isArray(val) || val instanceof Array;

/**
* 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
*/
const isFunction = val => typeof val === 'function';

/**
* Equivalent to angular.isUndefined
*/
const isUndefined = val => typeof val === 'undefined';

/**
* Equivalent to angular.isDefined. Inverts result of const isUndefined
*/
const isDefined = val => !isUndefined(val);

/**
* Equivalent to angular.isString
*/
const isString = val => typeof val === 'string';

/**
* Equivalent to angular.isNumber
*/
const isNumber = val => typeof val === 'number';

/**
* Equivalent to angular.isObject
*/
const isObject = val => val !== null && typeof val === 'object';

let _utilities = {
noop: noop,
copy: copy,
isArray: isArray,
equals: equals,
extend: extend,
isFunction: isFunction,
isUndefined: isUndefined,
isDefined: isDefined,
isString: isString,
isNumber: isNumber,
isObject: isObject
};

if (typeof (window.Utilities) === 'undefined') {
window.Utilities = _utilities;
}
})(window);
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
/* ---------- SAVE ---------- */

function save() {
saveInternal().then(angular.noop, angular.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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

packageResource.getAllCreated().then(createdPackages => {
vm.createdPackages = createdPackages;
}, angular.noop);
}, Utilities.noop);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
activate: false
});
completeSave(saved);
}, angular.noop);
}, Utilities.noop);


} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
extendedSave(saved).then(function(result) {
//if all is good, then reset the form
formHelper.resetForm({ scope: $scope });
}, angular.noop);
}, Utilities.noop);

vm.user = _.omit(saved, "navigation");
//restore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
userGroupsResource.deleteUserGroups(_.pluck(vm.selection, "id")).then(function (data) {
clearSelection();
onInit();
}, angular.noop);
}, Utilities.noop);
overlayService.close();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
vm.selectedBulkUserGroups = [];
editorService.close();
clearSelection();
}, angular.noop);
}, Utilities.noop);
},
close: function () {
vm.selectedBulkUserGroups = [];
Expand Down