Пример #1
0
        private static string AddQueryStringParameters(string url, IList <ParameterApiDescriptionModel> actionParameters)
        {
            var queryStringParameters = actionParameters
                                        .Where(p => p.BindingSourceId.IsIn(ParameterBindingSources.ModelBinding, ParameterBindingSources.Query))
                                        .ToArray();

            if (!queryStringParameters.Any())
            {
                return(url);
            }

            if (!url.Contains("?"))
            {
                url += "?";
            }

            for (var i = 0; i < queryStringParameters.Length; i++)
            {
                var parameterInfo = queryStringParameters[i];

                if (i > 0)
                {
                    url += "&";
                }

                url += (parameterInfo.Name.ToCamelCase() + "=' + escape(" + ProxyScriptingJsFuncHelper.GetParamNameInJsFunc(parameterInfo) + ") + '");
            }

            return(url);
        }
        private static void AddActionScript(StringBuilder script, ControllerApiDescriptionModel controller, ActionApiDescriptionModel action)
        {
            var actionName    = ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(action.Name.ToCamelCase());
            var parameterList = ProxyScriptingJsFuncHelper.GenerateJsFuncParameterList(action, "ajaxParams");

            script.AppendLine($"    serviceNamespace{actionName} = function({parameterList}) {{");
            script.AppendLine("        return site.ajax(site.utils.extend({");

            AddAjaxCallParameters(script, controller, action);

            script.AppendLine("        }, ajaxParams));");
            script.AppendLine("    };");
        }
Пример #3
0
        public static string GenerateFormPostData(ActionApiDescriptionModel action, int indent = 0)
        {
            var parameters = action
                             .Parameters
                             .Where(p => p.BindingSourceId == ParameterBindingSources.Form)
                             .ToArray();

            if (!parameters.Any())
            {
                return(null);
            }

            return(ProxyScriptingJsFuncHelper.CreateJsObjectLiteral(parameters, indent));
        }
Пример #4
0
        private static string ReplacePathVariables(string url, IList <ParameterApiDescriptionModel> actionParameters)
        {
            var pathParameters = actionParameters
                                 .Where(p => p.BindingSourceId == ParameterBindingSources.Path)
                                 .ToArray();

            if (!pathParameters.Any())
            {
                return(url);
            }

            foreach (var pathParameter in pathParameters)
            {
                url = url.Replace($"{{{pathParameter.Name}}}", $"' + {ProxyScriptingJsFuncHelper.GetParamNameInJsFunc(pathParameter)} + '");
            }

            return(url);
        }
Пример #5
0
        public static string GenerateBody(ActionApiDescriptionModel action)
        {
            var parameters = action
                             .Parameters
                             .Where(p => p.BindingSourceId == ParameterBindingSources.Body)
                             .ToArray();

            if (parameters.Length <= 0)
            {
                return(null);
            }

            if (parameters.Length > 1)
            {
                throw new AbpException(
                          $"Only one complex type allowed as argument to a controller action that's binding source is 'Body'. But {action.Name} ({action.Url}) contains more than one!"
                          );
            }

            return(ProxyScriptingJsFuncHelper.GetParamNameInJsFunc(parameters[0]));
        }
Пример #6
0
        private static string AddQueryStringParameters(string url, IList <ParameterApiDescriptionModel> actionParameters)
        {
            var queryStringParameters = actionParameters
                                        .Where(p => p.BindingSourceId.IsIn(ParameterBindingSources.ModelBinding, ParameterBindingSources.Query))
                                        .ToArray();

            if (!queryStringParameters.Any())
            {
                return(url);
            }

            var qsBuilderParams = queryStringParameters
                                  .Select(p => $"{{ name: '{p.Name.ToCamelCase()}', value: {ProxyScriptingJsFuncHelper.GetParamNameInJsFunc(p)} }}")
                                  .JoinAsString(", ");

            return(url + $"' + abp.utils.buildQueryString([{qsBuilderParams}]) + '");
        }