func (t *DataSourceController) GetDataSourceSelector(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := map[string]interface{}{} err := r.GetPayload(&payload) // fmt.Println(payload["item"].([]interface{})) // payload := map[string]string{} // err := r.GetForms(&payload) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } _id := payload["_id"].(string) dsType := "" path := "" if _, ok := payload["type"]; !ok { data, err := t.getDataSourceMetaData(_id) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } dsType = data["type"].(string) path = data["path"].(string) } ds, err := helper.FetchDataSource(_id, dsType, path) sds, err := helper.FetchQuerySelector(ds, payload) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } return helper.Result(true, sds, "") }
func (t *DataSourceController) GetDataSource(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := map[string]string{} err := r.GetForms(&payload) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } _id := payload["_id"] dsType := payload["type"] path := payload["path"] if _, ok := payload["type"]; !ok { data, err := t.getDataSourceMetaData(_id) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } dsType = data["type"].(string) path = data["path"].(string) } ds, err := helper.FetchDataSource(_id, dsType, path) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } return helper.Result(true, ds, "") }
func (t *ChartController) GetChartConfig(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := map[string]string{} err := r.GetForms(&payload) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } filename := fmt.Sprintf("chart-%s.json", payload["_id"]) isWithDataSource, err := strconv.ParseBool(payload["isWithDataSource"]) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } fileContent, err := ioutil.ReadFile(t.AppViewsPath + "data/chart/" + filename) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } data := map[string]interface{}{} err = json.Unmarshal(fileContent, &data) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } if isWithDataSource { dataSourceID := data["outsider"].(map[string]interface{})["dataSourceKey"].(string) connection, err := helper.LoadConfig(t.AppViewsPath + "data/datasource.json") if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } defer connection.Close() cursor, err := connection.NewQuery().Where(dbox.Eq("_id", dataSourceID)).Cursor(nil) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } defer cursor.Close() res := []toolkit.M{} err = cursor.Fetch(&res, 0, false) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } if len(res) == 0 { return helper.Result(false, nil, "No data found") } dsID := res[0].GetString("_id") dsType := res[0].GetString("type") dsPath := res[0].GetString("path") dataSource, _ := helper.FetchDataSource(dsID, dsType, dsPath) data["dataSource"] = map[string]interface{}{"data": dataSource} } return helper.Result(true, data, "") }
func (t *DataSourceController) GetDataSourceFields(r *knot.WebContext) interface{} { r.Config.OutputType = knot.OutputJson payload := map[string]string{} err := r.GetForms(&payload) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } _id := payload["_id"] meta, err := t.getDataSourceMetaData(_id) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } dsType := meta["type"].(string) path := meta["path"].(string) data, err := helper.FetchDataSource(_id, dsType, path) if !helper.HandleError(err) { return helper.Result(false, nil, err.Error()) } fields := []string{} holder := map[string]bool{} for _, each := range data[:len(data)] { for key, _ := range each { if _, ok := holder[key]; !ok { fields = append(fields, key) holder[key] = true } } } return helper.Result(true, fields, "") }