Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VT template generation fixes #4

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions generators/vt-template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export default [{{range $model := .Entities}}
breadcrumbs: ["dashboard", "{{.JSName}}List"]
}
},
{{if not .ReadOnly}}
{
{{if not .ReadOnly}}{
name: "{{.JSName}}Edit",
path: "/{{.TerminalPath}}/:id/edit",
component: () =>
Expand Down Expand Up @@ -73,8 +72,7 @@ const listTemplate = `<template>
: ""
}}
</v-btn>
[[if not .ReadOnly]]
<v-btn small dark color="success" :to="{ name: '[[.JSName]]Add' }">
[[if not .ReadOnly]]<v-btn small dark color="success" :to="{ name: '[[.JSName]]Add' }">
<v-icon>add</v-icon>
{{ $t("common.list.addNewLabel") }}
</v-btn>
Expand Down Expand Up @@ -232,26 +230,21 @@ export default class List extends EntityList {

get headers() {
return [ [[range $i, $e := .ListColumns]][[if ne $i 0]]
},
[[end]][[if eq .JSName "statusId"]]
{
},
[[end]]{[[if eq .JSName "statusId"]]
text: this.$t("[[$.JSName]].list.headers.status"),
value: "status",
sortable: false
[[else]]
{
[[else]]
text: this.$t("[[$.JSName]].list.headers.[[.JSName]]"),
value: "[[.JSName]]"[[if eq $i 0]],
align: "left"[[end]][[if not .IsSortable]],
sortable: false[[end]][[end]][[end]][[if $.ReadOnly]]
}[[else]]
},
sortable: false[[end]][[end]][[end]][[if $.ReadOnly]]}[[else]]},
{
text: this.$t("[[$.JSName]].list.headers.actions"),
value: "id",
sortable: false
}
[[end]]
}[[end]]
];
}
}
Expand Down
8 changes: 6 additions & 2 deletions generators/vt-template/vt_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ func PackEntity(vtEntity mfd.VTEntity) EntityData {
JSName: mfd.VarName(pk.Name),
})
}
quickFilter := ""
if title := vtEntity.Entity.TitleAttribute(); title != nil {
quickFilter = mfd.VarName(title.Name)
}

tmpl := EntityData{
Name: vtEntity.Name,
JSName: mfd.VarName(vtEntity.Name),
HasQuickFilter: false, // TODO remove
TitleField: "", // TODO remove
HasQuickFilter: quickFilter != "", // TODO remove
TitleField: quickFilter, // TODO remove
PKs: pks,
ReadOnly: vtEntity.Mode == mfd.ModeReadOnlyWithTemplates,
}
Expand Down
9 changes: 9 additions & 0 deletions mfd/map.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mfd

import (
"encoding/json"
"encoding/xml"
"io"
)
Expand All @@ -26,6 +27,14 @@ func NewXMLMap(init map[string]string) *XMLMap {
return xmlMap
}

func (m XMLMap) MarshalJSON() ([]byte, error) {
jsM := make(map[string]interface{})
for _, i := range m.elements {
jsM[i.XMLName.Local] = i.Value
}
return json.Marshal(jsM)
}

func (m *XMLMap) Append(key, value string) {
if m.elements == nil {
m.elements = []xmlMapElement{{
Expand Down