Use full namespace for js proxies.

pull/122/head
Halil İbrahim Kalkan 7 years ago
parent 29a7cfe9b2
commit b6f23379db

@ -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(".");
}
}
}

@ -133,7 +133,7 @@ namespace Volo.Abp.Http.ProxyScripting.Generators
public static string GenerateJsFuncParameterList(ActionApiDescriptionModel action, string ajaxParametersName)
{
var methodParamNames = action.Parameters.Select(p => p.NameOnMethod).Distinct().ToList();
var methodParamNames = action.ParametersOnMethod.Select(p => p.Name).Distinct().ToList();
methodParamNames.Add(ajaxParametersName);
return methodParamNames.Select(prmName => NormalizeJsVariableName(prmName.ToCamelCase())).JoinAsString(", ");
}

@ -35,5 +35,12 @@ namespace Volo.Abp.Identity
{
return 43;
}
[HttpPost]
[Route("{id}")]
public int Post(int id)
{
return id;
}
}
}

@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.ApiVersioning;
using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Mvc;
namespace Volo.Abp.Identity.V4
{
//TODO: This is just a test controller and will be removed later
[ApiVersion("4.0")]
[Route("api/v{api-version:apiVersion}/identity/fixture")]
public class FixtureController : AbpController, IRemoteService
{
private readonly IRequestedApiVersion _requestedApiVersion;
public FixtureController(IRequestedApiVersion requestedApiVersion)
{
_requestedApiVersion = requestedApiVersion;
}
[HttpGet]
public string Get()
{
return 41 + " - " + _requestedApiVersion.Current;
}
}
}
Loading…
Cancel
Save