Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
rename widget system and plugin system
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Jan 17, 2022
1 parent bbe13d8 commit ddc1928
Show file tree
Hide file tree
Showing 17 changed files with 221 additions and 223 deletions.
4 changes: 2 additions & 2 deletions internal/adapter/gql/gqlmodel/convert_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ToScene(scene *scene.Scene) *Scene {
return nil
}

sceneWidgets := scene.WidgetSystem().Widgets()
sceneWidgets := scene.Widgets().Widgets()
widgets := make([]*SceneWidget, 0, len(sceneWidgets))
for _, w := range sceneWidgets {
widgets = append(widgets, ToSceneWidget(w))
Expand All @@ -55,7 +55,7 @@ func ToScene(scene *scene.Scene) *Scene {
clusters = append(clusters, ToCluster(c))
}

scenePlugins := scene.PluginSystem().Plugins()
scenePlugins := scene.Plugins().Plugins()
plugins := make([]*ScenePlugin, 0, len(scenePlugins))
for _, sp := range scenePlugins {
plugins = append(plugins, ToScenePlugin(sp))
Expand Down
4 changes: 2 additions & 2 deletions internal/adapter/gql/resolver_mutation_scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (r *mutationResolver) UploadPlugin(ctx context.Context, input gqlmodel.Uplo
return &gqlmodel.UploadPluginPayload{
Plugin: gqlmodel.ToPlugin(p),
Scene: gqlmodel.ToScene(s),
ScenePlugin: gqlmodel.ToScenePlugin(s.PluginSystem().Plugin(p.ID())),
ScenePlugin: gqlmodel.ToScenePlugin(s.Plugins().Plugin(p.ID())),
}, nil
}

Expand Down Expand Up @@ -192,7 +192,7 @@ func (r *mutationResolver) UpgradePlugin(ctx context.Context, input gqlmodel.Upg

return &gqlmodel.UpgradePluginPayload{
Scene: gqlmodel.ToScene(s),
ScenePlugin: gqlmodel.ToScenePlugin(s.PluginSystem().Plugin(input.ToPluginID)),
ScenePlugin: gqlmodel.ToScenePlugin(s.Plugins().Plugin(input.ToPluginID)),
}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions internal/infrastructure/mongo/mongodoc/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func (c *SceneIDConsumer) Consume(raw bson.Raw) error {
}

func NewScene(scene *scene.Scene) (*SceneDocument, string) {
widgets := scene.WidgetSystem().Widgets()
plugins := scene.PluginSystem().Plugins()
widgets := scene.Widgets().Widgets()
plugins := scene.Plugins().Plugins()
clusters := scene.Clusters().Clusters()

widgetsDoc := make([]SceneWidgetDocument, 0, len(widgets))
Expand Down Expand Up @@ -223,9 +223,9 @@ func (d *SceneDocument) Model() (*scene.Scene, error) {
Team(tid).
RootLayer(lid).
Clusters(cl).
WidgetSystem(scene.NewWidgetSystem(ws)).
Widgets(scene.NewWidgets(ws)).
WidgetAlignSystem(d.AlignSystem.Model()).
PluginSystem(scene.NewPluginSystem(ps)).
Plugins(scene.NewPlugins(ps)).
UpdatedAt(d.UpdateAt).
Property(prid).
Build()
Expand Down
2 changes: 1 addition & 1 deletion internal/usecase/interactor/plugin_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (i *Plugin) Delete(ctx context.Context, pid id.PluginID, operator *usecase.
return interfaces.ErrOperationDenied
}

if s.PluginSystem().HasPlugin(p.ID()) {
if s.Plugins().HasPlugin(p.ID()) {
return interfaces.ErrCannotDeleteUsedPlugin
}

Expand Down
2 changes: 1 addition & 1 deletion internal/usecase/interactor/plugin_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (i *Plugin) installPlugin(ctx context.Context, p *pluginpack.Package, s *sc
return err
}
}
s.PluginSystem().Add(scene.NewPlugin(p.Manifest.Plugin.ID(), ppid))
s.Plugins().Add(scene.NewPlugin(p.Manifest.Plugin.ID(), ppid))

if pp != nil {
if err := i.propertyRepo.Save(ctx, pp); err != nil {
Expand Down
18 changes: 9 additions & 9 deletions internal/usecase/interactor/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (i *Scene) Create(ctx context.Context, pid id.ProjectID, operator *usecase.
return nil, err
}

ps := scene.NewPluginSystem([]*scene.Plugin{
ps := scene.NewPlugins([]*scene.Plugin{
scene.NewPlugin(id.OfficialPluginID, nil),
})

Expand All @@ -119,7 +119,7 @@ func (i *Scene) Create(ctx context.Context, pid id.ProjectID, operator *usecase.
Team(prj.Team()).
Property(p.ID()).
RootLayer(rootLayer.ID()).
PluginSystem(ps).
Plugins(ps).
Build()

if err != nil {
Expand Down Expand Up @@ -216,7 +216,7 @@ func (i *Scene) AddWidget(ctx context.Context, sid id.SceneID, pid id.PluginID,
return nil, nil, err
}

s.WidgetSystem().Add(widget)
s.Widgets().Add(widget)

if !floating {
var loc scene.WidgetLocation
Expand Down Expand Up @@ -278,7 +278,7 @@ func (i *Scene) UpdateWidget(ctx context.Context, param interfaces.UpdateWidgetP
return nil, nil, err
}

widget := scene.WidgetSystem().Widget(param.WidgetID)
widget := scene.Widgets().Widget(param.WidgetID)
if widget == nil {
return nil, nil, rerror.ErrNotFound
}
Expand Down Expand Up @@ -406,7 +406,7 @@ func (i *Scene) RemoveWidget(ctx context.Context, id id.SceneID, wid id.WidgetID
return nil, err
}

ws := scene.WidgetSystem()
ws := scene.Widgets()

widget := ws.Widget(wid)
if widget == nil {
Expand Down Expand Up @@ -458,7 +458,7 @@ func (i *Scene) InstallPlugin(ctx context.Context, sid id.SceneID, pid id.Plugin
return nil, pid, nil, err2
}

if s.PluginSystem().HasPlugin(pid) {
if s.Plugins().HasPlugin(pid) {
return nil, pid, nil, interfaces.ErrPluginAlreadyInstalled
}

Expand Down Expand Up @@ -486,7 +486,7 @@ func (i *Scene) InstallPlugin(ctx context.Context, sid id.SceneID, pid id.Plugin
propertyID = &prid
}

s.PluginSystem().Add(scene.NewPlugin(pid, propertyID))
s.Plugins().Add(scene.NewPlugin(pid, propertyID))

if p != nil {
if err := i.propertyRepo.Save(ctx, p); err != nil {
Expand Down Expand Up @@ -539,7 +539,7 @@ func (i *Scene) UninstallPlugin(ctx context.Context, sid id.SceneID, pid id.Plug
return nil, err
}

ps := scene.PluginSystem()
ps := scene.Plugins()
if !ps.Has(pid) {
return nil, interfaces.ErrPluginNotInstalled
}
Expand All @@ -553,7 +553,7 @@ func (i *Scene) UninstallPlugin(ctx context.Context, sid id.SceneID, pid id.Plug
ps.Remove(pid)

// remove widgets
removedProperties = append(removedProperties, scene.WidgetSystem().RemoveAllByPlugin(pid)...)
removedProperties = append(removedProperties, scene.Widgets().RemoveAllByPlugin(pid)...)

// remove layers
res, err := layerops.Processor{
Expand Down
18 changes: 8 additions & 10 deletions pkg/scene/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ func (b *Builder) Build() (*Scene, error) {
if b.scene.rootLayer.ID().IsNil() {
return nil, ErrInvalidID
}
if b.scene.widgetSystem == nil {
b.scene.widgetSystem = NewWidgetSystem(nil)
if b.scene.widgets == nil {
b.scene.widgets = NewWidgets(nil)
}
if b.scene.widgetAlignSystem == nil {
b.scene.widgetAlignSystem = NewWidgetAlignSystem()
}
if b.scene.pluginSystem == nil {
b.scene.pluginSystem = NewPluginSystem(nil)
if b.scene.plugins == nil {
b.scene.plugins = NewPlugins(nil)
}
if b.scene.updatedAt.IsZero() {
b.scene.updatedAt = b.scene.CreatedAt()
Expand Down Expand Up @@ -70,9 +70,8 @@ func (b *Builder) UpdatedAt(updatedAt time.Time) *Builder {
return b
}

func (b *Builder) WidgetSystem(widgetSystem *WidgetSystem) *Builder {
widgetSystem2 := *widgetSystem
b.scene.widgetSystem = &widgetSystem2
func (b *Builder) Widgets(widgets *Widgets) *Builder {
b.scene.widgets = widgets
return b
}

Expand All @@ -86,9 +85,8 @@ func (b *Builder) RootLayer(rootLayer LayerID) *Builder {
return b
}

func (b *Builder) PluginSystem(pluginSystem *PluginSystem) *Builder {
pluginSystem2 := *pluginSystem
b.scene.pluginSystem = &pluginSystem2
func (b *Builder) Plugins(plugins *Plugins) *Builder {
b.scene.plugins = plugins
return b
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/scene/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ func TestSceneBuilder(t *testing.T) {
Project(scene.NewProjectID()).
Team(scene.NewTeamID()).
Property(scenep.ID()).
WidgetSystem(scene.NewWidgetSystem([]*scene.Widget{
Widgets(scene.NewWidgets([]*scene.Widget{
sceneWidget1, sceneWidget2,
})).
PluginSystem(scene.NewPluginSystem([]*scene.Plugin{scenePlugin1})).
Plugins(scene.NewPlugins([]*scene.Plugin{scenePlugin1})).
RootLayer(rootLayer.ID()).
MustBuild()

Expand Down
4 changes: 2 additions & 2 deletions pkg/scene/builder/scene.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (b *Builder) scene(ctx context.Context, s *scene.Scene, publishedAt time.Ti
}

func (b *Builder) plugins(ctx context.Context, s *scene.Scene, p []*property.Property) map[string]propertyJSON {
scenePlugins := s.PluginSystem().Plugins()
scenePlugins := s.Plugins().Plugins()
res := map[string]propertyJSON{}
for _, sp := range scenePlugins {
if sp == nil {
Expand All @@ -49,7 +49,7 @@ func (b *Builder) plugins(ctx context.Context, s *scene.Scene, p []*property.Pro
}

func (b *Builder) widgets(ctx context.Context, s *scene.Scene, p []*property.Property) []*widgetJSON {
sceneWidgets := s.WidgetSystem().Widgets()
sceneWidgets := s.Widgets().Widgets()
res := make([]*widgetJSON, 0, len(sceneWidgets))
for _, w := range sceneWidgets {
if !w.Enabled() {
Expand Down
Loading

0 comments on commit ddc1928

Please sign in to comment.