Esempio n. 1
0
func getDashboardImportStatus(orgId int64, plugin *PluginBase, path string) (*PluginDashboardInfoDTO, error) {
	res := &PluginDashboardInfoDTO{}

	var dashboard *m.Dashboard
	var err error

	if dashboard, err = loadPluginDashboard(plugin, path); err != nil {
		return nil, err
	}

	res.Path = path
	res.PluginId = plugin.Id
	res.Title = dashboard.Title
	res.Revision = dashboard.GetString("revision", "1.0")

	query := m.GetDashboardQuery{OrgId: orgId, Slug: dashboard.Slug}

	if err := bus.Dispatch(&query); err != nil {
		if err != m.ErrDashboardNotFound {
			return nil, err
		}
	} else {
		res.Installed = true
		res.InstalledUri = "db/" + query.Result.Slug
		res.InstalledRevision = query.Result.GetString("revision", "1.0")
	}

	return res, nil
}
Esempio n. 2
0
func ImportDashboard(cmd *ImportDashboardCommand) error {
	plugin, exists := Plugins[cmd.PluginId]

	if !exists {
		return PluginNotFoundError{cmd.PluginId}
	}

	var dashboard *m.Dashboard
	var err error

	if dashboard, err = loadPluginDashboard(plugin, cmd.Path); err != nil {
		return err
	}

	evaluator := &DashTemplateEvaluator{
		template: dashboard.Data,
		inputs:   cmd.Inputs,
	}

	generatedDash, err := evaluator.Eval()
	if err != nil {
		return err
	}

	saveCmd := m.SaveDashboardCommand{
		Dashboard: generatedDash,
		OrgId:     cmd.OrgId,
		UserId:    cmd.UserId,
		Overwrite: cmd.Overwrite,
	}

	if err := bus.Dispatch(&saveCmd); err != nil {
		return err
	}

	cmd.Result = &PluginDashboardInfoDTO{
		PluginId:          cmd.PluginId,
		Title:             dashboard.Title,
		Path:              cmd.Path,
		Revision:          dashboard.GetString("revision", "1.0"),
		InstalledUri:      "db/" + saveCmd.Result.Slug,
		InstalledRevision: dashboard.GetString("revision", "1.0"),
		Installed:         true,
	}

	return nil
}