Skip to content

Commit

Permalink
added clock & clockProvider scripts aspnetboilerplate#936
Browse files Browse the repository at this point in the history
  • Loading branch information
ismcagdas committed Apr 19, 2016
1 parent 4a2f7cd commit 31878d5
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/Abp.Web.Mvc/Web/Mvc/Controllers/AbpScriptsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Web.Mvc;
using Abp.Auditing;
using Abp.Extensions;
using Abp.Timing;
using Abp.Web.Authorization;
using Abp.Web.Features;
using Abp.Web.Localization;
Expand Down Expand Up @@ -34,10 +35,10 @@ public class AbpScriptsController : AbpController
/// </summary>
public AbpScriptsController(
IMultiTenancyScriptManager multiTenancyScriptManager,
ISettingScriptManager settingScriptManager,
INavigationScriptManager navigationScriptManager,
ILocalizationScriptManager localizationScriptManager,
IAuthorizationScriptManager authorizationScriptManager,
ISettingScriptManager settingScriptManager,
INavigationScriptManager navigationScriptManager,
ILocalizationScriptManager localizationScriptManager,
IAuthorizationScriptManager authorizationScriptManager,
IFeaturesScriptManager featuresScriptManager,
ISessionScriptManager sessionScriptManager)
{
Expand All @@ -58,7 +59,7 @@ public async Task<ActionResult> GetScripts(string culture = "")
{
if (!culture.IsNullOrEmpty())
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
}

var sb = new StringBuilder();
Expand All @@ -68,7 +69,7 @@ public async Task<ActionResult> GetScripts(string culture = "")

sb.AppendLine(_sessionScriptManager.GetScript());
sb.AppendLine();

sb.AppendLine(_localizationScriptManager.GetScript());
sb.AppendLine();

Expand All @@ -80,11 +81,13 @@ public async Task<ActionResult> GetScripts(string culture = "")

sb.AppendLine(await _navigationScriptManager.GetScriptAsync());
sb.AppendLine();

sb.AppendLine(await _settingScriptManager.GetScriptAsync());

sb.AppendLine(GetTriggerScript());

sb.AppendLine(GetClockProviderScript());

return Content(sb.ToString(), "application/x-javascript", Encoding.UTF8);
}

Expand All @@ -98,5 +101,16 @@ private static string GetTriggerScript()

return script.ToString();
}

private static string GetClockProviderScript()
{
var script = new StringBuilder();

script.AppendLine("(function(){");
script.AppendLine(" abp.clock.provider = abp.timing." + Clock.Provider.GetType().Name.ToCamelCase());
script.Append("})();");

return script.ToString();
}
}
}
92 changes: 92 additions & 0 deletions src/Abp.Web.Resources/Abp/Framework/scripts/abp.js
Original file line number Diff line number Diff line change
Expand Up @@ -570,4 +570,96 @@
return !!(obj && obj.constructor && obj.call && obj.apply);
};

/* TIMING *****************************************/
abp.timing = abp.timing || {};

abp.timing.utcClockProvider = (function () {

var toUtc = function (date) {
return Date.UTC(
date.getUTCFullYear()
, date.getUTCMonth()
, date.getUTCDate()
, date.getUTCHours()
, date.getUTCMinutes()
, date.getUTCSeconds()
, date.getUTCMilliseconds()
);
}

var now = function () {
return new Date();
};

var normalize = function (date) {
if (!date) {
return date;
}

return new Date(toUtc(date));
};

// Public interface ///////////////////////////////////////////////////

return {
now: now,
normalize: normalize
};
})();

abp.timing.localClockProvider = (function () {

var toLocal = function (date) {
return new Date(
date.getFullYear()
, date.getMonth()
, date.getDate()
, date.getHours()
, date.getMinutes()
, date.getSeconds()
, date.getMilliseconds()
);
}

var now = function () {
return toLocal(new Date());
}

var normalize = function (date) {
if (!date) {
return date;
}

return toLocal(date);
}

// Public interface ///////////////////////////////////////////////////

return {
now: now,
normalize: normalize
};
})();

/* CLOCK *****************************************/
abp.clock = abp.clock || {};

abp.clock.now = function () {
if (abp.clock.provider) {
return abp.clock.provider.now();
}

return new Date();
}

abp.clock.normalize = function (date) {
if (abp.clock.provider) {
return abp.clock.provider.normalize(date);
}

return date;
}

abp.clock.provider = abp.timing.utcClockProvider;

})(jQuery);

0 comments on commit 31878d5

Please sign in to comment.