|
|
@ -17,11 +17,11 @@ namespace Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations; |
|
|
[ApiExplorerSettings(IgnoreApi = true)] |
|
|
[ApiExplorerSettings(IgnoreApi = true)] |
|
|
public class AbpApplicationConfigurationScriptController : AbpController |
|
|
public class AbpApplicationConfigurationScriptController : AbpController |
|
|
{ |
|
|
{ |
|
|
private readonly AbpApplicationConfigurationAppService _configurationAppService; |
|
|
protected readonly AbpApplicationConfigurationAppService ConfigurationAppService; |
|
|
private readonly IJsonSerializer _jsonSerializer; |
|
|
protected readonly IJsonSerializer JsonSerializer; |
|
|
private readonly AbpAspNetCoreMvcOptions _options; |
|
|
protected readonly AbpAspNetCoreMvcOptions Options; |
|
|
private readonly IJavascriptMinifier _javascriptMinifier; |
|
|
protected readonly IJavascriptMinifier JavascriptMinifier; |
|
|
private readonly IAbpAntiForgeryManager _antiForgeryManager; |
|
|
protected readonly IAbpAntiForgeryManager AntiForgeryManager; |
|
|
|
|
|
|
|
|
public AbpApplicationConfigurationScriptController( |
|
|
public AbpApplicationConfigurationScriptController( |
|
|
AbpApplicationConfigurationAppService configurationAppService, |
|
|
AbpApplicationConfigurationAppService configurationAppService, |
|
|
@ -30,42 +30,42 @@ public class AbpApplicationConfigurationScriptController : AbpController |
|
|
IJavascriptMinifier javascriptMinifier, |
|
|
IJavascriptMinifier javascriptMinifier, |
|
|
IAbpAntiForgeryManager antiForgeryManager) |
|
|
IAbpAntiForgeryManager antiForgeryManager) |
|
|
{ |
|
|
{ |
|
|
_configurationAppService = configurationAppService; |
|
|
ConfigurationAppService = configurationAppService; |
|
|
_jsonSerializer = jsonSerializer; |
|
|
JsonSerializer = jsonSerializer; |
|
|
_options = options.Value; |
|
|
Options = options.Value; |
|
|
_javascriptMinifier = javascriptMinifier; |
|
|
JavascriptMinifier = javascriptMinifier; |
|
|
_antiForgeryManager = antiForgeryManager; |
|
|
AntiForgeryManager = antiForgeryManager; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[HttpGet] |
|
|
[HttpGet] |
|
|
[Produces(MimeTypes.Application.Javascript, MimeTypes.Text.Plain)] |
|
|
[Produces(MimeTypes.Application.Javascript, MimeTypes.Text.Plain)] |
|
|
public async Task<ActionResult> Get() |
|
|
public virtual async Task<ActionResult> Get() |
|
|
{ |
|
|
{ |
|
|
var script = CreateAbpExtendScript( |
|
|
var script = CreateAbpExtendScript( |
|
|
await _configurationAppService.GetAsync( |
|
|
await ConfigurationAppService.GetAsync( |
|
|
new ApplicationConfigurationRequestOptions { |
|
|
new ApplicationConfigurationRequestOptions { |
|
|
IncludeLocalizationResources = false |
|
|
IncludeLocalizationResources = false |
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
_antiForgeryManager.SetCookie(); |
|
|
AntiForgeryManager.SetCookie(); |
|
|
|
|
|
|
|
|
return Content( |
|
|
return Content( |
|
|
_options.MinifyGeneratedScript == true |
|
|
Options.MinifyGeneratedScript == true |
|
|
? _javascriptMinifier.Minify(script) |
|
|
? JavascriptMinifier.Minify(script) |
|
|
: script, |
|
|
: script, |
|
|
MimeTypes.Application.Javascript |
|
|
MimeTypes.Application.Javascript |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private string CreateAbpExtendScript(ApplicationConfigurationDto config) |
|
|
protected virtual string CreateAbpExtendScript(ApplicationConfigurationDto config) |
|
|
{ |
|
|
{ |
|
|
var script = new StringBuilder(); |
|
|
var script = new StringBuilder(); |
|
|
|
|
|
|
|
|
script.AppendLine("(function(){"); |
|
|
script.AppendLine("(function(){"); |
|
|
script.AppendLine(); |
|
|
script.AppendLine(); |
|
|
script.AppendLine($"$.extend(true, abp, {_jsonSerializer.Serialize(config, indented: true)})"); |
|
|
script.AppendLine($"$.extend(true, abp, {JsonSerializer.Serialize(config, indented: true)})"); |
|
|
script.AppendLine(); |
|
|
script.AppendLine(); |
|
|
script.AppendLine("abp.event.trigger('abp.configurationInitialized');"); |
|
|
script.AppendLine("abp.event.trigger('abp.configurationInitialized');"); |
|
|
script.AppendLine(); |
|
|
script.AppendLine(); |
|
|
|