aboutsummaryrefslogtreecommitdiffstats
path: root/lib/agent/project-st.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-24 01:14:30 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-24 01:37:24 +0100
commit4d843d2bde236ec23810d0904dfb8aebbc53a37b (patch)
tree84c01452f01620cedb7bf6bcb608a0eade82161b /lib/agent/project-st.go
parent38c0c21a969e621c725245ce91c78e77076c5ce7 (diff)
New dashboard improvements.
- add build buttons - add build settings support and backup into project clientData - improved async alert - fixed project dropdown Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/agent/project-st.go')
-rw-r--r--lib/agent/project-st.go33
1 files changed, 25 insertions, 8 deletions
diff --git a/lib/agent/project-st.go b/lib/agent/project-st.go
index e2cd3cb..c4e8fce 100644
--- a/lib/agent/project-st.go
+++ b/lib/agent/project-st.go
@@ -1,6 +1,8 @@
package agent
import (
+ "fmt"
+
"github.com/iotbzh/xds-agent/lib/apiv1"
st "github.com/iotbzh/xds-agent/lib/syncthing"
)
@@ -56,8 +58,8 @@ func (p *STProject) Add(cfg apiv1.ProjectConfig) (*apiv1.ProjectConfig, error) {
p.Log.Errorf("Project ID in XDSServer and local ST differ: %s != %s", svrPrj.ID, locPrj.ID)
}
- // Use Update function to setup remains fields
- return p.UpdateProject(*svrPrj)
+ // Use Setup function to setup remains fields
+ return p.Setup(*svrPrj)
}
// Delete a project
@@ -77,16 +79,16 @@ func (p *STProject) GetProject() *apiv1.ProjectConfig {
return &prj
}
-// UpdateProject Update project config
-func (p *STProject) UpdateProject(prj apiv1.ProjectConfig) (*apiv1.ProjectConfig, error) {
+// Setup Setup local project config
+func (p *STProject) Setup(prj apiv1.ProjectConfig) (*apiv1.ProjectConfig, error) {
// Update folder
p.folder = p.server.ProjectToFolder(prj)
svrPrj := p.GetProject()
// Register events to update folder status
// Register to XDS Server events
- p.server.EventOn("event:FolderStateChanged", "", p._cbServerFolderChanged)
- if err := p.server.EventRegister("FolderStateChanged", svrPrj.ID); err != nil {
+ p.server.EventOn("event:folder-state-change", "", p._cbServerFolderChanged)
+ if err := p.server.EventRegister("folder-state-change", svrPrj.ID); err != nil {
p.Log.Warningf("XDS Server EventRegister failed: %v", err)
return svrPrj, err
}
@@ -103,6 +105,21 @@ func (p *STProject) UpdateProject(prj apiv1.ProjectConfig) (*apiv1.ProjectConfig
return svrPrj, nil
}
+// Update Update some field of a project
+func (p *STProject) Update(prj apiv1.ProjectConfig) (*apiv1.ProjectConfig, error) {
+
+ if p.folder.ID != prj.ID {
+ return nil, fmt.Errorf("Invalid id")
+ }
+
+ err := p.server.FolderUpdate(p.server.ProjectToFolder(prj), p.folder)
+ if err != nil {
+ return nil, err
+ }
+
+ return p.GetProject(), nil
+}
+
// GetServer Get the XdsServer that holds this project
func (p *STProject) GetServer() *XdsServer {
return p.server
@@ -142,7 +159,7 @@ func (p *STProject) _cbServerFolderChanged(pData interface{}, data interface{})
p.folder.DataCloudSync.STSvrIsInSync = evt.Folder.IsInSync
p.folder.DataCloudSync.STSvrStatus = evt.Folder.Status
- if err := p.events.Emit(apiv1.EVTProjectChange, p.server.FolderToProject(*p.folder)); err != nil {
+ if err := p.events.Emit(apiv1.EVTProjectChange, p.server.FolderToProject(*p.folder), ""); err != nil {
p.Log.Warningf("Cannot notify project change (from server): %v", err)
}
}
@@ -181,7 +198,7 @@ func (p *STProject) _cbLocalSTEvents(ev st.Event, data *st.EventsCBData) {
p.folder.DataCloudSync.STLocIsInSync = inSync
p.folder.DataCloudSync.STLocStatus = sts
- if err := p.events.Emit(apiv1.EVTProjectChange, p.server.FolderToProject(*p.folder)); err != nil {
+ if err := p.events.Emit(apiv1.EVTProjectChange, p.server.FolderToProject(*p.folder), ""); err != nil {
p.Log.Warningf("Cannot notify project change (local): %v", err)
}
}