protected string GenerateAjaxCallParameters() { var ajaxParameters = AjaxParametersTemplate .Replace("{url}", ActionScriptingHelper.GenerateUrlWithParameters(_controllerInfo, _actionInfo)) .Replace("{type}", _actionInfo.Verb.ToString().ToUpperInvariant()) .Replace("{postData}", ActionScriptingHelper.GenerateBody(_actionInfo)); return(ajaxParameters); }
public virtual void WriteTo(StringBuilder script) { script.AppendLine(" this." + _actionInfo.ActionName.ToCamelCase() + " = function (" + ActionScriptingHelper.GenerateJsMethodParameterList(_actionInfo.Method, "httpParams") + ") {"); script.AppendLine(" return $http(angular.extend({"); script.AppendLine(" abp: true,"); script.AppendLine(" url: abp.appPath + '" + ActionScriptingHelper.GenerateUrlWithParameters(_controllerInfo, _actionInfo) + "',"); script.AppendLine(" method: '" + _actionInfo.Verb.ToString().ToUpper(CultureInfo.InvariantCulture) + "',"); script.AppendLine(" data: JSON.stringify(" + ActionScriptingHelper.GenerateBody(_actionInfo) + ")"); script.AppendLine(" }, httpParams));"); script.AppendLine(" };"); script.AppendLine(" "); }
public virtual string GenerateMethod() { var jsMethodName = _actionInfo.ActionName.ToCamelCase(); var jsMethodParameterList = ActionScriptingHelper.GenerateJsMethodParameterList(_actionInfo.Method, "ajaxParams"); var jsMethod = JsMethodTemplate .Replace("{jsMethodName}", jsMethodName) .Replace("{jsMethodParameterList}", jsMethodParameterList) .Replace("{ajaxCallParameters}", GenerateAjaxCallParameters()); return(jsMethod); }
public virtual string GenerateMethod() { var jsMethodName = actionInfo.ActionName.ToCamelCase(); var jsMethodParameterList = ActionScriptingHelper.GenerateJsMethodParameterList(actionInfo.Method, "ajaxParams"); var jsMethod = JsMethodTemplate .Replace("{jsMethodName}", ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(jsMethodName)) .Replace("{jsMethodParameterList}", jsMethodParameterList) .Replace("{ajaxCallParameters}", GenerateAjaxCallParameters()); return(jsMethod); }
protected string GenerateAjaxCallParameters() { var script = new StringBuilder(); script.AppendLine(" url: abp.appPath + '" + ActionScriptingHelper.GenerateUrlWithParameters(_controllerInfo, _actionInfo) + "',"); script.AppendLine(" type: '" + _actionInfo.Verb.ToString().ToUpperInvariant() + "',"); if (_actionInfo.Verb == HttpVerb.Get) { script.Append(" data: " + ActionScriptingHelper.GenerateBody(_actionInfo)); } else { script.Append(" data: JSON.stringify(" + ActionScriptingHelper.GenerateBody(_actionInfo) + ")"); } return(script.ToString()); }
public virtual void WriteTo(StringBuilder script) { script.AppendLine(" this" + ProxyScriptingJsFuncHelper.WrapWithBracketsOrWithDotPrefix(_actionInfo.ActionName.ToCamelCase()) + " = function (" + ActionScriptingHelper.GenerateJsMethodParameterList(_actionInfo.Method, "httpParams") + ") {"); script.AppendLine(" return $http(angular.extend({"); script.AppendLine(" url: CodeZero.appPath + '" + ActionScriptingHelper.GenerateUrlWithParameters(_controllerInfo, _actionInfo) + "',"); script.AppendLine(" method: '" + _actionInfo.Verb.ToString().ToUpper(CultureInfo.InvariantCulture) + "',"); if (_actionInfo.Verb == HttpVerb.Get) { script.AppendLine(" params: " + ActionScriptingHelper.GenerateBody(_actionInfo)); } else { script.AppendLine(" data: JSON.stringify(" + ActionScriptingHelper.GenerateBody(_actionInfo) + ")"); } script.AppendLine(" }, httpParams));"); script.AppendLine(" };"); script.AppendLine(" "); }
public string Generate(DynamicApiControllerInfo controllerInfo, string servicePrefix) { if (this.servicePrefix != servicePrefix) { //if there is a change in servicePrefix, we need to generate the types again this.servicePrefix = servicePrefix; typesToBeDone = new HashSet <Type>(); doneTypes = new HashSet <Type>(); } this.controllerInfo = controllerInfo; var script = new StringBuilder(); script.AppendLine(" export class " + this.controllerInfo.ServiceName.Substring(this.controllerInfo.ServiceName.IndexOf('/') + 1)); script.AppendLine(" {"); script.AppendLine(" static $inject = ['$http'];"); script.AppendLine(" constructor(private $http: ng.IHttpService){"); script.AppendLine(" }"); foreach (var methodInfo in this.controllerInfo.Actions.Values) { PrepareInputParameterTypes(methodInfo.Method); List <Type> newTypes = new List <Type>(); var returnType = TypeScriptHelper.GetTypeContractName(methodInfo.Method.ReturnType, newTypes); this.AddNewTypesIfRequired(newTypes.ToArray()); if (returnType == "void") { script.AppendLine(string.Format(" public {0} = function ({1}): studiox.IPromise ", methodInfo.ActionName.ToCamelCase(), GetMethodInputParameter(methodInfo.Method))); script.AppendLine("{"); script.AppendLine(" var self = this;"); script.AppendLine(" return self.$http(angular.extend({"); script.AppendLine(" studiox: true,"); script.AppendLine(" url: studiox.appPath + '" + ActionScriptingHelper.GenerateUrlWithParameters(this.controllerInfo, methodInfo) + "',"); script.AppendLine(" method: '" + methodInfo.Verb.ToString().ToUpper(CultureInfo.InvariantCulture) + "',"); if (methodInfo.Verb == HttpVerb.Get) { script.AppendLine(" params: " + ActionScriptingHelper.GenerateBody(methodInfo)); } else { script.AppendLine(" data: JSON.stringify(" + ActionScriptingHelper.GenerateBody(methodInfo) + ")"); } script.AppendLine(" }, httpParams));"); script.AppendLine("}"); } else { script.AppendLine(string.Format(" public {0} = function ({1}): studiox.IGenericPromise<{2}> ", methodInfo.ActionName.ToCamelCase(), GetMethodInputParameter(methodInfo.Method), returnType)); script.AppendLine("{"); script.AppendLine(" var self = this;"); script.AppendLine(" return self.$http(angular.extend({"); script.AppendLine(" studiox: true,"); script.AppendLine(" url: studiox.appPath + '" + ActionScriptingHelper.GenerateUrlWithParameters(this.controllerInfo, methodInfo) + "',"); script.AppendLine(" method: '" + methodInfo.Verb.ToString().ToUpper(CultureInfo.InvariantCulture) + "',"); if (methodInfo.Verb == HttpVerb.Get) { script.AppendLine(" params: " + ActionScriptingHelper.GenerateBody(methodInfo)); } else { script.AppendLine(" data: JSON.stringify(" + ActionScriptingHelper.GenerateBody(methodInfo) + ")"); } script.AppendLine(" }, httpParams));"); script.AppendLine("}"); } } script.AppendLine(" }"); script.AppendLine("angular.module('studiox').service('studiox.services." + this.controllerInfo.ServiceName.Replace("/", ".") + "', studiox.services." + this.controllerInfo.ServiceName.Replace("/", ".") + ");"); while (typesToBeDone != null && typesToBeDone.Count > 0) { Type type = typesToBeDone.First(); script.AppendLine(GenerateTypeScript(type)); doneTypes.Add(type); typesToBeDone.RemoveWhere(x => x == type); } return(script.ToString()); }