Comment out unneeded resource translations

This commit is contained in:
Tomaž Jerman
2021-09-22 11:33:37 +02:00
parent db6d173786
commit e49b04f37c
11 changed files with 68 additions and 241 deletions
+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)