Skip to content

Commit

Permalink
chore(server): update layer for appearance support in beta (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyshx committed Sep 18, 2023
1 parent b77db4d commit eb82a83
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 41 deletions.
45 changes: 43 additions & 2 deletions server/e2e/gql_nlslayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func removeNLSLayer(e *httpexpect.Expect, layerId string) (GraphQLRequest, *http
func updateNLSLayer(e *httpexpect.Expect, layerId string) (GraphQLRequest, *httpexpect.Value) {
requestBody := GraphQLRequest{
OperationName: "UpdateNLSLayer",
Query: `mutation UpdateNLSLayer($layerId: ID!, $name: String, $visible: Boolean) {
updateNLSLayer(input: {layerId: $layerId, name: $name, visible: $visible}) {
Query: `mutation UpdateNLSLayer($layerId: ID!, $name: String, $visible: Boolean, $config: JSON) {
updateNLSLayer(input: {layerId: $layerId, name: $name, visible: $visible, config: $config}) {
layer {
id
__typename
Expand All @@ -114,6 +114,37 @@ func updateNLSLayer(e *httpexpect.Expect, layerId string) (GraphQLRequest, *http
"layerId": layerId,
"name": "Updated Layer",
"visible": true,
"config": map[string]any{
"data": map[string]any{
"type": "ExampleType",
"url": "https://example.com/data",
"value": "secondSampleValue",
"layers": "sampleLayerData",
"jsonProperties": []string{"prop1", "prop2"},
"updateInterval": 10,
"parameters": map[string]any{
"sampleKey": "sampleValue",
},
"time": map[string]any{
"property": "time",
"interval": 5,
"updateClockOnLoad": true,
},
"csv": map[string]any{
"idColumn": "id",
"latColumn": "latitude",
"lngColumn": "longitude",
"heightColumn": "height",
"noHeader": false,
"disableTypeConversion": true,
},
},
"properties": "sampleProperties",
"defines": map[string]string{
"defineKey": "defineValue",
},
"events": "sampleEvents",
},
},
}

Expand Down Expand Up @@ -198,6 +229,16 @@ func TestNLSLayerCRUD(t *testing.T) {
// Update NLSLayer
_, _ = updateNLSLayer(e, layerId)

_, res3 := fetchSceneForNewLayers(e, sId)

res3.Object().
Value("data").Object().
Value("node").Object().
Value("newLayers").Array().First().Object().
Value("config").Object().
Value("data").Object().
Value("value").Equal("secondSampleValue")

// Remove NLSLayer
_, _ = removeNLSLayer(e, layerId)
}
6 changes: 1 addition & 5 deletions server/gql/newlayer.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ input UpdateNLSLayerInput {
layerId: ID!
name: String
visible: Boolean
config: JSON
}

# Payload
Expand All @@ -71,11 +72,6 @@ type UpdateNLSLayerPayload {
layer: NLSLayer!
}

# TODO
# extend type Query{
# newLayer(id: ID!): NLSLayer
# }

extend type Mutation {
addNLSLayerSimple(input: AddNLSLayerSimpleInput!): AddNLSLayerSimplePayload!
removeNLSLayer(input: RemoveNLSLayerInput!): RemoveNLSLayerPayload!
Expand Down
4 changes: 2 additions & 2 deletions server/gql/style.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ input AddStyleInput {
input UpdateStyleInput {
StyleId: ID!
sceneId: ID!
name: String!
value: JSON!
name: String
value: JSON
}

input RemoveStyleInput {
Expand Down
24 changes: 14 additions & 10 deletions server/internal/adapter/gql/generated.go

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

9 changes: 5 additions & 4 deletions server/internal/adapter/gql/gqlmodel/models_gen.go

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

1 change: 1 addition & 0 deletions server/internal/adapter/gql/resolver_mutation_nlslayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (r *mutationResolver) UpdateNLSLayer(ctx context.Context, input gqlmodel.Up
LayerID: lid,
Name: input.Name,
Visible: input.Visible,
Config: gqlmodel.ToNLSConfig(input.Config),
}, getOperator(ctx))
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions server/internal/usecase/interactor/nlslayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ func (i *NLSLayer) Update(ctx context.Context, inp interfaces.UpdateNLSLayerInpu
layer.SetVisible(*inp.Visible)
}

if inp.Config != nil {
layer.UpdateConfig(inp.Config)
}

err = i.nlslayerRepo.Save(ctx, layer)
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion server/internal/usecase/interactor/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,9 @@ func (i *Scene) UpdateStyle(ctx context.Context, param interfaces.UpdateStyleInp
return nil, nil, rerror.ErrNotFound
}

style.Rename(param.Name)
if param.Name != nil {
style.Rename(*param.Name)
}

if param.Value != nil {
style.UpdateValue(param.Value)
Expand Down
1 change: 1 addition & 0 deletions server/internal/usecase/interfaces/nlslayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type UpdateNLSLayerInput struct {
LayerID id.NLSLayerID
Name *string
Visible *bool
Config *nlslayer.Config
}

type NLSLayer interface {
Expand Down
2 changes: 1 addition & 1 deletion server/internal/usecase/interfaces/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ type AddStyleInput struct {
type UpdateStyleInput struct {
StyleID id.StyleID
SceneID id.SceneID
Name string
Name *string
Value *scene.StyleValue
}
8 changes: 0 additions & 8 deletions server/pkg/nlslayer/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
type NLSLayerGroup struct {
layerBase
children *IDList
config *Config
root bool
}

Expand Down Expand Up @@ -123,16 +122,9 @@ func (l *NLSLayerGroup) Clone() Cloner {
clonedChildren = l.children.Clone()
}

var clonedConfig *Config
if l.config != nil {
clonedConfigItem := l.config.Clone()
clonedConfig = &clonedConfigItem
}

return &NLSLayerGroup{
layerBase: *clonedBase,
children: clonedChildren,
config: clonedConfig,
root: l.root,
}
}
20 changes: 20 additions & 0 deletions server/pkg/nlslayer/nlslayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type NLSLayer interface {
ID() ID
LayerType() LayerType
Scene() SceneID
Config() *Config
Title() string
IsVisible() bool
SetVisible(bool)
Expand All @@ -17,6 +18,7 @@ type NLSLayer interface {
SetInfobox(*pl.Infobox)
Tags() *pl.TagList
Rename(string)
UpdateConfig(*Config)
}

func ToNLSLayerGroup(l NLSLayer) *NLSLayerGroup {
Expand Down Expand Up @@ -63,6 +65,7 @@ type layerBase struct {
visible bool
infobox *pl.Infobox
tags *pl.TagList
config *Config
}

func (l *layerBase) ID() ID {
Expand All @@ -87,6 +90,10 @@ func (l *layerBase) Scene() SceneID {
return l.scene
}

func (l *layerBase) Config() *Config {
return l.config
}

func (l *layerBase) Title() string {
if l == nil {
return ""
Expand Down Expand Up @@ -136,17 +143,30 @@ func (l *layerBase) Rename(name string) {
l.title = name
}

func (l *layerBase) UpdateConfig(newConfig *Config) {
if l == nil || newConfig == nil {
return
}
l.config = newConfig
}

func (l *layerBase) Clone() *layerBase {
if l == nil {
return nil
}
var clonedConfig *Config
if l.config != nil {
clonedConfigItem := l.config.Clone()
clonedConfig = &clonedConfigItem
}

cloned := &layerBase{
id: l.id,
layerType: l.layerType,
scene: l.scene,
title: l.title,
visible: l.visible,
config: clonedConfig,
}

if l.infobox != nil {
Expand Down
8 changes: 0 additions & 8 deletions server/pkg/nlslayer/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

type NLSLayerSimple struct {
layerBase
config *Config
}

func (l *NLSLayerSimple) ID() ID {
Expand Down Expand Up @@ -103,14 +102,7 @@ func (l *NLSLayerSimple) Clone() Cloner {

clonedBase := l.layerBase.Clone()

var clonedConfig *Config
if l.config != nil {
clonedConfigItem := l.config.Clone()
clonedConfig = &clonedConfigItem
}

return &NLSLayerSimple{
layerBase: *clonedBase,
config: clonedConfig,
}
}

0 comments on commit eb82a83

Please sign in to comment.