From 087f8fb21c3934f226d485880456fa7db4966c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Tikvi=C4=87?= Date: Wed, 18 Apr 2018 10:00:04 +0200 Subject: [PATCH] expanded list config with live graph --- json_utility.go | 14 +++++++------ list_config.go | 62 +++++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 21 deletions(-) diff --git a/json_utility.go b/json_utility.go index 2fbeb45..7af4abf 100644 --- a/json_utility.go +++ b/json_utility.go @@ -243,16 +243,16 @@ func UpdateEntityModels(command string) (total, upd, add int, err error) { total = len(updateQue) - forUpdate := make([]string, 0) - forAdd := make([]string, 0) + toUpdate := make([]string, 0) + toAdd := make([]string, 0) for k, _ := range updateQue { if _, exists := metadata[k]; exists { if command == "force" { - forUpdate = append(forUpdate, k) + toUpdate = append(toUpdate, k) } } else { - forAdd = append(forAdd, k) + toAdd = append(toAdd, k) } } @@ -268,7 +268,9 @@ func UpdateEntityModels(command string) (total, upd, add int, err error) { return } } - for _, k := range forUpdate { + for _, k := range toUpdate { + //fmt.Printf("Updating: %s\n", k) + //fmt.Printf("New model: %s\n", updateQue[k]) _, err = uStmt.Exec(string(updateQue[k]), k) if err != nil { logger.Log("webutility: %v\n", err) @@ -290,7 +292,7 @@ func UpdateEntityModels(command string) (total, upd, add int, err error) { return } } - for _, k := range forAdd { + for _, k := range toAdd { _, err = iStmt.Exec(activeProject, string(blankPayload), k, string(updateQue[k])) if err != nil { logger.Log("webutility: %v\n", err) diff --git a/list_config.go b/list_config.go index 5b03e2f..941f1b9 100644 --- a/list_config.go +++ b/list_config.go @@ -42,12 +42,13 @@ type ListGraph struct { } type ListActions struct { - Create bool `json:"create"` - Update bool `json:"update"` - Delete bool `json:"delete"` - Export bool `json:"export"` - Print bool `json:"print"` - Graph bool `json:"graph"` + Create bool `json:"create"` + Update bool `json:"update"` + Delete bool `json:"delete"` + Export bool `json:"export"` + Print bool `json:"print"` + Graph bool `json:"graph"` + LiveGraph bool `json:"liveGraph"` } type ListNavNode struct { @@ -79,6 +80,12 @@ type ListDetails struct { SingleDetail bool `json:"singleDetail"` } +type ListLiveGraph struct { + ObjectType string `json:"objectType"` + ValueFields string `json:"valueFields"` + LabelFields string `json:"labelFields"` +} + type ListConfig struct { ObjectType string `json:"objectType"` Title string `json:"title"` @@ -92,6 +99,7 @@ type ListConfig struct { Navigation []ListNavNode `json:"navigation"` Pivots []ListPivot `json:"pivots"` Details ListDetails `json:"details"` + LiveGraph ListLiveGraph `json:"liveGraphs"` } // GetListConfig returns list configuration for the provided object type for the front-end application @@ -109,6 +117,7 @@ func GetListConfig(db *sql.DB, objType string) (ListConfig, error) { resp.Graphs, err = getListGraph(db, objType) resp.Pivots, err = getListPivot(db, objType) resp.Details, err = getListDetails(db, objType) + resp.LiveGraph, err = getListLiveGraph(db, objType) if err != nil { return ListConfig{}, err @@ -157,12 +166,13 @@ func newDefaultList(objType string) ListConfig { }, Filters: nil, Actions: ListActions{ - Create: false, - Update: false, - Delete: false, - Export: false, - Print: false, - Graph: false, + Create: false, + Update: false, + Delete: false, + Export: false, + Print: false, + Graph: false, + LiveGraph: false, }, Parent: nil, Navigation: nil, @@ -233,7 +243,7 @@ func getListActions(db *sql.DB, objType string) (ListActions, error) { var resp ListActions rows, err := db.Query(`SELECT ACTION_CREATE, ACTION_UPDATE, ACTION_DELETE, ACTION_EXPORT, - ACTION_PRINT, ACTION_GRAPH + ACTION_PRINT, ACTION_GRAPH, ACTION_LIVE_GRAPH FROM LIST_CONFIG WHERE OBJECT_TYPE = ` + fmt.Sprintf("'%s'", objType)) if err != nil { @@ -241,15 +251,16 @@ func getListActions(db *sql.DB, objType string) (ListActions, error) { } defer rows.Close() - var create, update, delete, export, print, graph uint32 + var create, update, delete, export, print, graph, liveGraph uint32 if rows.Next() { - rows.Scan(&create, &update, &delete, &export, &print, &graph) + rows.Scan(&create, &update, &delete, &export, &print, &graph, &liveGraph) resp.Create = create != 0 resp.Update = update != 0 resp.Delete = delete != 0 resp.Export = export != 0 resp.Print = print != 0 resp.Graph = graph != 0 + resp.LiveGraph = liveGraph != 0 } if rows.Err() != nil { return ListActions{}, rows.Err() @@ -502,3 +513,24 @@ func getListDetails(db *sql.DB, objType string) (ListDetails, error) { return resp, nil } + +// getListLiveGraph returns live graph for the provided object type. +func getListLiveGraph(db *sql.DB, objType string) (ListLiveGraph, error) { + var resp ListLiveGraph + rows, err := db.Query(`SELECT + OBJECT_TYPE, VALUE_FIELDS, LABEL_FIELDS + FROM LIST_LIVE_GRAPH + WHERE OBJECT_TYPE = ` + fmt.Sprintf("'%s'", objType)) + if err != nil { + return resp, err + } + defer rows.Close() + if rows.Next() { + rows.Scan(&resp.ObjectType, &resp.ValueFields, &resp.LabelFields) + } + if rows.Err() != nil { + return resp, rows.Err() + } + + return resp, nil +} -- 1.8.1.2