Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace horizon.utils with an angular one
Horizon utilitaries are now fully integrated into the angular application. The object horizon.utils is still available in the application in order to keep the compatibility, it is a link to the angular constant object. Change-Id: I3d44c5c281a8e61e93f4d1b7c3b8b61c128e36ea Implements: blueprint horizon-angular
- Loading branch information
Maxime Vidori
committed
Feb 17, 2014
1 parent
2d591be
commit 1356315
Showing
6 changed files
with
74 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
var horizonApp = angular.module('hz', ['hz.conf']) | ||
var horizonApp = angular.module('hz', ['hz.conf', 'hz.utils']) | ||
.config(['$interpolateProvider', function ($interpolateProvider) { | ||
$interpolateProvider.startSymbol('{$'); | ||
$interpolateProvider.endSymbol('$}'); | ||
}]) | ||
.run(['hzConfig', 'hzUtils', function (hzConfig, hzUtils) { | ||
//expose the configuration for horizon legacy variable | ||
horizon.conf = hzConfig; | ||
horizon.utils = hzUtils; | ||
}]); | ||
|
64 changes: 64 additions & 0 deletions
64
horizon/static/horizon/js/angular/services/horizon.utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*global angular*/ | ||
(function () { | ||
'use strict'; | ||
function utils(hzConfig, $log, $rootScope, $compile) { | ||
return { | ||
/* | ||
Use the log levels of http://docs.angularjs.org/api/ng.$log | ||
default to log level. | ||
*/ | ||
log: function (msg, lvl) { | ||
if (hzConfig.debug) { | ||
($log[lvl] || $log.log)(msg); | ||
} | ||
}, | ||
capitalize: function (string) { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
}, | ||
/* | ||
Adds commas to any integer or numbers within a string for human display. | ||
EG: | ||
horizon.utils.humanizeNumbers(1234); -> "1,234" | ||
horizon.utils.humanizeNumbers("My Total: 1234"); -> "My Total: 1,234" | ||
*/ | ||
humanizeNumbers: function (number) { | ||
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); | ||
}, | ||
|
||
/* | ||
Truncate a string at the desired length. Optionally append an ellipsis | ||
to the end of the string. | ||
EG: | ||
horizon.utils.truncate("String that is too long.", 18, true); -> | ||
"String that is too…" | ||
*/ | ||
truncate: function (string, size, includeEllipsis) { | ||
if (string.length > size) { | ||
if (includeEllipsis) { | ||
return string.substring(0, (size - 3)) + "…"; | ||
} | ||
|
||
return string.substring(0, size); | ||
} | ||
|
||
return string; | ||
}, | ||
loadAngular: function (element) { | ||
try { | ||
$compile(element)($rootScope); | ||
$rootScope.$apply(); | ||
} catch (err) {} | ||
/* | ||
Compilation fails when it could not find a directive, | ||
fails silently on this, it is an angular behaviour. | ||
*/ | ||
|
||
} | ||
}; | ||
} | ||
|
||
angular.module('hz.utils', ['hz.conf']) | ||
.service('hzUtils', ['hzConfig', '$log', '$rootScope', '$compile', utils]); | ||
}()); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters