3
0

Comment out unneeded resource translations

This commit is contained in:
Tomaž Jerman
2021-09-22 11:33:13 +02:00
parent db6d173786
commit e49b04f37c
11 changed files with 68 additions and 241 deletions
-28
View File
@@ -7,7 +7,6 @@ package service
//
// Definitions file that controls how this file is generated:
// - compose.chart.yaml
// - compose.module.yaml
// - compose.namespace.yaml
// - compose.page.yaml
@@ -37,7 +36,6 @@ type (
}
ResourceTranslationsManagerService interface {
Chart(ctx context.Context, namespaceID uint64, ID uint64) (locale.ResourceTranslationSet, error)
Module(ctx context.Context, namespaceID uint64, ID uint64) (locale.ResourceTranslationSet, error)
Namespace(ctx context.Context, ID uint64) (locale.ResourceTranslationSet, error)
Page(ctx context.Context, namespaceID uint64, ID uint64) (locale.ResourceTranslationSet, error)
@@ -125,32 +123,6 @@ func (svc resourceTranslationsManager) Locale() locale.Resource {
return svc.locale
}
func (svc resourceTranslationsManager) Chart(ctx context.Context, namespaceID uint64, ID uint64) (locale.ResourceTranslationSet, error) {
var (
err error
out locale.ResourceTranslationSet
res *types.Chart
k types.LocaleKey
)
res, err = svc.loadChart(ctx, svc.store, namespaceID, ID)
if err != nil {
return nil, err
}
for _, tag := range svc.locale.Tags() {
k = types.LocaleKeyChartName
out = append(out, &locale.ResourceTranslation{
Resource: res.ResourceTranslation(),
Lang: tag.String(),
Key: k.Path,
Msg: svc.locale.TResourceFor(tag, res.ResourceTranslation(), k.Path),
})
}
return out, nil
}
func (svc resourceTranslationsManager) Module(ctx context.Context, namespaceID uint64, ID uint64) (locale.ResourceTranslationSet, error) {
var (
err error
-53
View File
@@ -7,7 +7,6 @@ package types
//
// Definitions file that controls how this file is generated:
// - compose.chart.yaml
// - compose.module-field.yaml
// - compose.module.yaml
// - compose.namespace.yaml
@@ -30,7 +29,6 @@ type (
// Types and stuff
const (
ChartResourceTranslationType = "compose:chart"
ModuleFieldResourceTranslationType = "compose:module-field"
ModuleResourceTranslationType = "compose:module"
NamespaceResourceTranslationType = "compose:namespace"
@@ -38,11 +36,6 @@ const (
)
var (
LocaleKeyChartName = LocaleKey{
Name: "name",
Resource: ChartResourceTranslationType,
Path: "name",
}
LocaleKeyModuleFieldLabel = LocaleKey{
Name: "label",
Resource: ModuleFieldResourceTranslationType,
@@ -125,52 +118,6 @@ var (
}
)
// ResourceTranslation returns string representation of Locale resource for Chart by calling ChartResourceTranslation fn
//
// Locale resource is in the compose:chart/... format
//
// This function is auto-generated
func (r Chart) ResourceTranslation() string {
return ChartResourceTranslation(r.NamespaceID, r.ID)
}
// ChartResourceTranslation returns string representation of Locale resource for Chart
//
// Locale resource is in the compose:chart/... format
//
// This function is auto-generated
func ChartResourceTranslation(namespaceID uint64, id uint64) string {
cpts := []interface{}{ChartResourceTranslationType}
cpts = append(cpts, strconv.FormatUint(namespaceID, 10), strconv.FormatUint(id, 10))
return fmt.Sprintf(ChartResourceTranslationTpl(), cpts...)
}
// @todo template
func ChartResourceTranslationTpl() string {
return "%s/%s/%s"
}
func (r *Chart) DecodeTranslations(tt locale.ResourceTranslationIndex) {
var aux *locale.ResourceTranslation
if aux = tt.FindByKey(LocaleKeyChartName.Path); aux != nil {
r.Name = aux.Msg
}
}
func (r *Chart) EncodeTranslations() (out locale.ResourceTranslationSet) {
out = locale.ResourceTranslationSet{}
if r.Name != "" {
out = append(out, &locale.ResourceTranslation{
Resource: r.ResourceTranslation(),
Key: LocaleKeyChartName.Path,
Msg: r.Name,
})
}
return out
}
// ResourceTranslation returns string representation of Locale resource for ModuleField by calling ModuleFieldResourceTranslation fn
//
// Locale resource is in the compose:module-field/... format
+6 -6
View File
@@ -15,9 +15,9 @@ rbac:
sessions.manage:
description: Manage workflow sessions
locale:
resource:
references: [ ID ]
keys:
- { path: name, field: "Meta.Name" }
- { path: description, field: "Meta.Description" }
# locale:
# resource:
# references: [ ID ]
# keys:
# - { path: name, field: "Meta.Name" }
# - { path: description, field: "Meta.Description" }
+5 -5
View File
@@ -10,8 +10,8 @@ rbac:
delete:
description: Delete chart
locale:
resource:
references: [ namespace, ID ]
keys:
- name
# locale:
# resource:
# references: [ namespace, ID ]
# keys:
# - name
+7 -7
View File
@@ -9,10 +9,10 @@ rbac:
run:
description: Run report
locale:
extended: true
keys:
- { path: name, field: "Meta.Name" }
- { path: description, field: "Meta.Description" }
- { name: projection title, path: "projection.{{projectionID}}.title", custom: true }
- { name: projection description, path: "projection.{{projectionID}}.description", custom: true }
# locale:
# extended: true
# keys:
# - { path: name, field: "Meta.Name" }
# - { path: description, field: "Meta.Description" }
# - { name: projection title, path: "projection.{{projectionID}}.title", custom: true }
# - { name: projection description, path: "projection.{{projectionID}}.description", custom: true }
+6 -7
View File
@@ -2,7 +2,6 @@ package resource
import (
"fmt"
"strconv"
"github.com/cortezaproject/corteza-server/compose/types"
)
@@ -48,13 +47,13 @@ func (r *ComposeChart) RBACPath() []*Ref {
return []*Ref{r.RefNs}
}
func (r *ComposeChart) ResourceTranslationParts() (resource string, ref *Ref, path []*Ref) {
ref = r.Ref()
path = []*Ref{r.RefNs}
resource = fmt.Sprintf(types.ChartResourceTranslationTpl(), types.ChartResourceTranslationType, r.RefNs.Identifiers.First(), firstOkString(strconv.FormatUint(r.Res.ID, 10), r.Res.Handle))
// func (r *ComposeChart) ResourceTranslationParts() (resource string, ref *Ref, path []*Ref) {
// ref = r.Ref()
// path = []*Ref{r.RefNs}
// resource = fmt.Sprintf(types.ChartResourceTranslationTpl(), types.ChartResourceTranslationType, r.RefNs.Identifiers.First(), firstOkString(strconv.FormatUint(r.Res.ID, 10), r.Res.Handle))
return
}
// return
// }
// FindComposeChart looks for the chart in the resources
func FindComposeChart(rr InterfaceSet, ii Identifiers) (ch *types.Chart) {
-38
View File
@@ -7,40 +7,15 @@ package resource
//
// Definitions file that controls how this file is generated:
// - automation.workflow.yaml
// - compose.chart.yaml
// - compose.module-field.yaml
// - compose.module.yaml
// - compose.namespace.yaml
// - compose.page.yaml
// - system.report.yaml
import (
systemTypes "github.com/cortezaproject/corteza-server/system/types"
)
func (r *AutomationWorkflow) EncodeTranslations() ([]*ResourceTranslation, error) {
out := make([]*ResourceTranslation, 0, 10)
rr := r.Res.EncodeTranslations()
rr.SetLanguage(defaultLanguage)
res, ref, pp := r.ResourceTranslationParts()
out = append(out, NewResourceTranslation(systemTypes.FromLocale(rr), res, ref, pp...))
return out, nil
}
func (r *ComposeChart) EncodeTranslations() ([]*ResourceTranslation, error) {
out := make([]*ResourceTranslation, 0, 10)
rr := r.Res.EncodeTranslations()
rr.SetLanguage(defaultLanguage)
res, ref, pp := r.ResourceTranslationParts()
out = append(out, NewResourceTranslation(systemTypes.FromLocale(rr), res, ref, pp...))
return out, nil
}
func (r *ComposeModuleField) EncodeTranslations() ([]*ResourceTranslation, error) {
out := make([]*ResourceTranslation, 0, 10)
@@ -88,16 +63,3 @@ func (r *ComposePage) EncodeTranslations() ([]*ResourceTranslation, error) {
return append(out, tmp...), err
}
func (r *Report) EncodeTranslations() ([]*ResourceTranslation, error) {
out := make([]*ResourceTranslation, 0, 10)
rr := r.Res.EncodeTranslations()
rr.SetLanguage(defaultLanguage)
res, ref, pp := r.ResourceTranslationParts()
out = append(out, NewResourceTranslation(systemTypes.FromLocale(rr), res, ref, pp...))
tmp, err := r.encodeTranslations()
return append(out, tmp...), err
}
-38
View File
@@ -7,19 +7,14 @@ package resource
//
// Definitions file that controls how this file is generated:
// - automation.workflow.yaml
// - compose.chart.yaml
// - compose.module-field.yaml
// - compose.module.yaml
// - compose.namespace.yaml
// - compose.page.yaml
// - system.report.yaml
import (
"fmt"
automationTypes "github.com/cortezaproject/corteza-server/automation/types"
composeTypes "github.com/cortezaproject/corteza-server/compose/types"
systemTypes "github.com/cortezaproject/corteza-server/system/types"
"strings"
)
@@ -58,29 +53,6 @@ func ParseResourceTranslation(res string) (string, *Ref, []*Ref, error) {
// make the resource provide the slice of parent resources we should nest under
switch resourceType {
case automationTypes.WorkflowResourceTranslationType:
if len(path) != 1 {
return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path))
}
ref, pp, err := AutomationWorkflowResourceTranslationReferences(
// workflow
path[0],
)
return automationTypes.WorkflowResourceTranslationType, ref, pp, err
case composeTypes.ChartResourceTranslationType:
if len(path) != 2 {
return "", nil, nil, fmt.Errorf("expecting 2 reference components in path, got %d", len(path))
}
ref, pp, err := ComposeChartResourceTranslationReferences(
// namespace
path[0],
// chart
path[1],
)
return composeTypes.ChartResourceTranslationType, ref, pp, err
case composeTypes.ModuleFieldResourceTranslationType:
if len(path) != 3 {
return "", nil, nil, fmt.Errorf("expecting 3 reference components in path, got %d", len(path))
@@ -133,16 +105,6 @@ func ParseResourceTranslation(res string) (string, *Ref, []*Ref, error) {
)
return composeTypes.PageResourceTranslationType, ref, pp, err
case systemTypes.ReportResourceTranslationType:
if len(path) != 1 {
return "", nil, nil, fmt.Errorf("expecting 1 reference components in path, got %d", len(path))
}
ref, pp, err := SystemReportResourceTranslationReferences(
// report
path[0],
)
return systemTypes.ReportResourceTranslationType, ref, pp, err
}
// return unhandled resource as-is
@@ -7,7 +7,6 @@ package resource
//
// Definitions file that controls how this file is generated:
// - compose.chart.yaml
// - compose.module-field.yaml
// - compose.module.yaml
// - compose.namespace.yaml
@@ -17,18 +16,6 @@ import (
"github.com/cortezaproject/corteza-server/compose/types"
)
// ComposeChartResourceTranslationReferences generates Locale references
//
// Resources with "envoy: false" are skipped
//
// This function is auto-generated
func ComposeChartResourceTranslationReferences(namespace string, chart string) (res *Ref, pp []*Ref, err error) {
pp = append(pp, &Ref{ResourceType: types.NamespaceResourceType, Identifiers: MakeIdentifiers(namespace)})
res = &Ref{ResourceType: types.ChartResourceType, Identifiers: MakeIdentifiers(chart)}
return
}
// ComposeModuleFieldResourceTranslationReferences generates Locale references
//
// Resources with "envoy: false" are skipped
+19 -20
View File
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
automationTypes "github.com/cortezaproject/corteza-server/automation/types"
composeTypes "github.com/cortezaproject/corteza-server/compose/types"
"github.com/cortezaproject/corteza-server/pkg/envoy/resource"
"github.com/cortezaproject/corteza-server/store"
@@ -125,14 +124,14 @@ func (n *resourceTranslation) makeResourceTranslation(pl *payload) (string, erro
_ = localeRes
switch n.refLocaleRes.ResourceType {
case automationTypes.WorkflowResourceType:
p1 := resource.FindAutomationWorkflow(pl.state.ParentResources, n.refLocaleRes.Identifiers)
if p1 == nil {
return "", resource.AutomationWorkflowErrUnresolved(n.refLocaleRes.Identifiers)
}
p1ID = p1.ID
// case automationTypes.WorkflowResourceType:
// p1 := resource.FindAutomationWorkflow(pl.state.ParentResources, n.refLocaleRes.Identifiers)
// if p1 == nil {
// return "", resource.AutomationWorkflowErrUnresolved(n.refLocaleRes.Identifiers)
// }
// p1ID = p1.ID
return automationTypes.WorkflowResourceTranslation(p1ID), nil
// return automationTypes.WorkflowResourceTranslation(p1ID), nil
case composeTypes.NamespaceResourceType:
p1 := resource.FindComposeNamespace(pl.state.ParentResources, n.refLocaleRes.Identifiers)
@@ -173,20 +172,20 @@ func (n *resourceTranslation) makeResourceTranslation(pl *payload) (string, erro
return composeTypes.PageResourceTranslation(p0ID, p1ID), nil
case composeTypes.ChartResourceType:
p0 := resource.FindComposeNamespace(pl.state.ParentResources, n.refPathRes[0].Identifiers)
if p0 == nil {
return "", resource.ComposeNamespaceErrUnresolved(n.refPathRes[0].Identifiers)
}
p0ID = p0.ID
// case composeTypes.ChartResourceType:
// p0 := resource.FindComposeNamespace(pl.state.ParentResources, n.refPathRes[0].Identifiers)
// if p0 == nil {
// return "", resource.ComposeNamespaceErrUnresolved(n.refPathRes[0].Identifiers)
// }
// p0ID = p0.ID
p1 := resource.FindComposeChart(pl.state.ParentResources, n.refLocaleRes.Identifiers)
if p1 == nil {
return "", resource.ComposeChartErrUnresolved(n.refLocaleRes.Identifiers)
}
p1ID = p1.ID
// p1 := resource.FindComposeChart(pl.state.ParentResources, n.refLocaleRes.Identifiers)
// if p1 == nil {
// return "", resource.ComposeChartErrUnresolved(n.refLocaleRes.Identifiers)
// }
// p1ID = p1.ID
return composeTypes.ChartResourceTranslation(p0ID, p1ID), nil
// return composeTypes.ChartResourceTranslation(p0ID, p1ID), nil
case composeTypes.ModuleFieldResourceType:
p0 := resource.FindComposeNamespace(pl.state.ParentResources, n.refPathRes[0].Identifiers)
+25 -26
View File
@@ -7,7 +7,6 @@ import (
"strconv"
"strings"
automationTypes "github.com/cortezaproject/corteza-server/automation/types"
composeTypes "github.com/cortezaproject/corteza-server/compose/types"
"github.com/cortezaproject/corteza-server/pkg/envoy"
"github.com/cortezaproject/corteza-server/pkg/envoy/resource"
@@ -163,35 +162,35 @@ func (r *resourceTranslation) makeResourceTranslationResource(state *envoy.Resou
return fmt.Sprintf(composeTypes.ModuleFieldResourceTranslationTpl(), composeTypes.ModuleFieldResourceTranslationType, p0ID, p1ID, p2ID), nil
case composeTypes.ChartResourceType:
if len(res.RefPath) > 0 {
p0 := resource.FindComposeNamespace(state.ParentResources, res.RefPath[0].Identifiers)
if p0 == nil {
return "", resource.ComposeNamespaceErrUnresolved(res.RefPath[0].Identifiers)
}
p0ID = p0.Slug
}
// case composeTypes.ChartResourceType:
// if len(res.RefPath) > 0 {
// p0 := resource.FindComposeNamespace(state.ParentResources, res.RefPath[0].Identifiers)
// if p0 == nil {
// return "", resource.ComposeNamespaceErrUnresolved(res.RefPath[0].Identifiers)
// }
// p0ID = p0.Slug
// }
if res.RefRes != nil {
p1 := resource.FindComposeChart(state.ParentResources, res.RefRes.Identifiers)
if p1 == nil {
return "", resource.ComposeChartErrUnresolved(res.RefRes.Identifiers)
}
p1ID = p1.Handle
}
// if res.RefRes != nil {
// p1 := resource.FindComposeChart(state.ParentResources, res.RefRes.Identifiers)
// if p1 == nil {
// return "", resource.ComposeChartErrUnresolved(res.RefRes.Identifiers)
// }
// p1ID = p1.Handle
// }
return fmt.Sprintf(composeTypes.ChartResourceTranslationTpl(), composeTypes.ChartResourceTranslationType, p0ID, p1ID), nil
// return fmt.Sprintf(composeTypes.ChartResourceTranslationTpl(), composeTypes.ChartResourceTranslationType, p0ID, p1ID), nil
case automationTypes.WorkflowResourceType:
if res.RefRes != nil {
p0 := resource.FindAutomationWorkflow(state.ParentResources, res.RefRes.Identifiers)
if p0 == nil {
return "", resource.AutomationWorkflowErrUnresolved(res.RefRes.Identifiers)
}
p0ID = p0.Handle
}
// case automationTypes.WorkflowResourceType:
// if res.RefRes != nil {
// p0 := resource.FindAutomationWorkflow(state.ParentResources, res.RefRes.Identifiers)
// if p0 == nil {
// return "", resource.AutomationWorkflowErrUnresolved(res.RefRes.Identifiers)
// }
// p0ID = p0.Handle
// }
return fmt.Sprintf(automationTypes.WorkflowResourceTranslationTpl(), automationTypes.WorkflowResourceTranslationType, p0ID), nil
// return fmt.Sprintf(automationTypes.WorkflowResourceTranslationTpl(), automationTypes.WorkflowResourceTranslationType, p0ID), nil
default:
return "", fmt.Errorf("unsupported resource type '%s' for locale resource YAML encode", r.refLocaleRes.ResourceType)