Skip to content

Commit

Permalink
Added API callers for custom methods to the generated TS viewmodels f…
Browse files Browse the repository at this point in the history
…or Vue.
  • Loading branch information
ascott18 committed Nov 16, 2018
1 parent 470ddcc commit 70d5b18
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Coalesce.Web.Vue/Api/Generated/CaseDtoController.g.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions src/Coalesce.Web.Vue/src/metadata.g.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/Coalesce.Web.Vue/src/viewmodels.g.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using IntelliTect.Coalesce.CodeGeneration.Generation;
using IntelliTect.Coalesce.CodeGeneration.Vue.Utils;
using IntelliTect.Coalesce.TypeDefinition;
using IntelliTect.Coalesce.Utilities;
using System.Linq;
Expand Down Expand Up @@ -48,6 +49,19 @@ private static void WriteViewModel(TypeScriptCodeBuilder b, ClassViewModel model
// b.Line($"set {prop.JsVariable}(val) {{ this.$data.{prop.JsVariable} = val }}");
//}

foreach (var method in model.ClientMethods.Where(m => !m.IsStatic))
{
string signature =
string.Concat(method.ClientParameters.Select(f => $", {f.Name}: {new VueType(f.Type).TsType("$models")} | null"));

// "item" or "list"
var transportTypeSlug = method.TransportType.ToString().Replace("Result", "").ToLower();

b.Line($"public {method.JsVariable} = this.$apiClient.$makeCaller(\"{transportTypeSlug}\", ");
b.Indented($"(c{signature}) => c.{method.JsVariable}(this.$primaryKey{string.Concat(method.ClientParameters.Select(p => ", " + p.Name))}))");
b.Line();
}

using (b.Block($"constructor(initialData?: models.{name})"))
{
b.Line($"super({metadataName}, new apiClients.{name}ApiClient(), initialData)");
Expand Down

0 comments on commit 70d5b18

Please sign in to comment.