|
|
|
@ -1,5 +1,8 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Volo.Abp.Application.Services;
|
|
|
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
|
using Volo.Abp.Http.Modeling;
|
|
|
|
|
|
|
|
|
@ -20,8 +23,6 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
|
|
|
|
|
|
|
|
|
|
script.AppendLine("/* This file is automatically generated by ABP framework to use MVC Controllers from javascript. */");
|
|
|
|
|
script.AppendLine();
|
|
|
|
|
script.AppendLine("var abp = abp || {};");
|
|
|
|
|
script.AppendLine("abp.services = abp.services || {};");
|
|
|
|
|
|
|
|
|
|
foreach (var module in model.Modules.Values)
|
|
|
|
|
{
|
|
|
|
@ -37,9 +38,9 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
|
|
|
|
|
//TODO: Eleminate repeating module.RootPath.Replace("/", ".").ToCamelCase() !
|
|
|
|
|
//TODO: Remove illegal chars (like '-') from module/controller names!
|
|
|
|
|
|
|
|
|
|
script.AppendLine($"// module '{module.RootPath.ToCamelCase()}'");
|
|
|
|
|
script.AppendLine($"// module {module.RootPath.ToCamelCase()}");
|
|
|
|
|
script.AppendLine();
|
|
|
|
|
script.AppendLine("(function(){");
|
|
|
|
|
script.AppendLine($"abp.utils.createNamespace(abp, 'services.{module.RootPath.Replace("/", ".").ToCamelCase()}');");
|
|
|
|
|
|
|
|
|
|
foreach (var controller in module.Controllers.Values)
|
|
|
|
|
{
|
|
|
|
@ -53,28 +54,30 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
|
|
|
|
|
|
|
|
|
|
private static void AddControllerScript(StringBuilder script, ModuleApiDescriptionModel module, ControllerApiDescriptionModel controller)
|
|
|
|
|
{
|
|
|
|
|
script.AppendLine($" // controller '{controller.ControllerName.ToCamelCase()}'");
|
|
|
|
|
var controllerName = GetNormalizedTypeName(controller.TypeAsString);
|
|
|
|
|
|
|
|
|
|
script.AppendLine($" // controller {controllerName}");
|
|
|
|
|
script.AppendLine();
|
|
|
|
|
script.AppendLine(" (function(){");
|
|
|
|
|
script.AppendLine();
|
|
|
|
|
|
|
|
|
|
script.AppendLine($" abp.services.{module.RootPath.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()} = abp.services.{module.RootPath.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()} || {{}};");
|
|
|
|
|
script.AppendLine($" abp.utils.createNamespace(window, '{controllerName}');");
|
|
|
|
|
|
|
|
|
|
foreach (var action in controller.Actions.Values)
|
|
|
|
|
{
|
|
|
|
|
script.AppendLine();
|
|
|
|
|
AddActionScript(script, module, controller, action);
|
|
|
|
|
AddActionScript(script, module, controllerName, controller, action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
script.AppendLine();
|
|
|
|
|
script.AppendLine(" })();");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void AddActionScript(StringBuilder script, ModuleApiDescriptionModel module, ControllerApiDescriptionModel controller, ActionApiDescriptionModel action)
|
|
|
|
|
private static void AddActionScript(StringBuilder script, ModuleApiDescriptionModel module, string controllerName, ControllerApiDescriptionModel controller, ActionApiDescriptionModel action)
|
|
|
|
|
{
|
|
|
|
|
var parameterList = ProxyScriptingJsFuncHelper.GenerateJsFuncParameterList(action, "ajaxParams");
|
|
|
|
|
|
|
|
|
|
script.AppendLine($" // action '{action.Name.ToCamelCase()}'");
|
|
|
|
|
script.AppendLine($" abp.services.{module.RootPath.Replace("/", ".").ToCamelCase()}.{controller.ControllerName.ToCamelCase()}{ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(action.Name.RemovePostFix("Async").ToCamelCase())} = function({parameterList}) {{");
|
|
|
|
|
script.AppendLine($" {controllerName}{ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(action.Name.RemovePostFix("Async").ToCamelCase())} = function({parameterList}) {{");
|
|
|
|
|
script.AppendLine(" return abp.ajax($.extend(true, {");
|
|
|
|
|
|
|
|
|
|
AddAjaxCallParameters(script, controller, action);
|
|
|
|
@ -121,5 +124,20 @@ namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
|
|
|
|
|
|
|
|
|
|
script.AppendLine();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetNormalizedTypeName(string typeWithAssemblyName)
|
|
|
|
|
{
|
|
|
|
|
return CamelCaseWithNamespace(
|
|
|
|
|
typeWithAssemblyName.Split(",")[0]
|
|
|
|
|
.Trim()
|
|
|
|
|
.RemovePostFix(ApplicationService.CommonPostfixes)
|
|
|
|
|
.RemovePostFix("Controller")
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string CamelCaseWithNamespace(string name)
|
|
|
|
|
{
|
|
|
|
|
return name.Split('.').Select(n => n.ToCamelCase()).JoinAsString(".");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|