Example #1
0
func (w *WidgetController) FetchDataSources(ids string) (toolkit.Ms, error) {
	widgetData := toolkit.Ms{}
	_ids := strings.Split(ids, ",")
	for _, _id := range _ids {
		data, err := helper.FetchDataFromDS(_id, 0)
		if err != nil {
			return nil, err
		}
		datasourcewidget := toolkit.M{}
		datasourcewidget.Set("Data", data)
		widgetData = append(widgetData, datasourcewidget)
	}

	return widgetData, nil
}
Example #2
0
func (p *PageController) LoadWidgetPageData(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := toolkit.M{}

	if err := r.GetPayload(&payload); err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	result := toolkit.M{}

	for namespace, dsID := range payload {
		data, err := helper.FetchDataFromDS(dsID.(string), 0)
		if err != nil {
			return helper.CreateResult(false, nil, err.Error())
		}

		result.Set(namespace, data)
	}

	return helper.CreateResult(true, result, "")
}