Esempio n. 1
0
// GetPluginHandler returns a handler function given the template route and data to go to that page.
func (uis *UIServer) GetPluginHandler(uiPage *plugin.UIPage, pluginName string) func(http.ResponseWriter, *http.Request) {
	return func(w http.ResponseWriter, r *http.Request) {
		projCtx := MustHaveProjectContext(r)
		u := GetUser(r)
		pluginCtx := plugin.UIContext{
			Settings:   uis.Settings,
			User:       u,
			Task:       projCtx.Task,
			Build:      projCtx.Build,
			Version:    projCtx.Version,
			Patch:      projCtx.Patch,
			Project:    projCtx.Project,
			ProjectRef: projCtx.ProjectRef,
			Request:    r,
		}
		pluginData, err := uiPage.DataFunc(pluginCtx)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		data := struct {
			Data        interface{}
			User        *user.DBUser
			ProjectData projectContext
		}{pluginData, u, projCtx}

		pluginTemplatePath := filepath.Join(plugin.TemplateRoot(pluginName), uiPage.TemplatePath)
		uis.PluginWriteHTML(w, http.StatusOK, data, "base", pluginName, pluginTemplatePath, "base_angular.html", "menu.html")
	}
}
Esempio n. 2
0
func (pp *PerfPlugin) GetPanelConfig() (*plugin.PanelConfig, error) {
	panelHTML, err := ioutil.ReadFile(filepath.Join(plugin.TemplateRoot(pp.Name()), "task_perf_data.html"))
	if err != nil {
		return nil, fmt.Errorf("Can't load panel html file: %v", err)
	}

	return &plugin.PanelConfig{
		Panels: []plugin.UIPanel{
			{
				Includes:  includes,
				Page:      plugin.TaskPage,
				Position:  plugin.PageCenter,
				PanelHTML: template.HTML(panelHTML),
				DataFunc: func(context plugin.UIContext) (interface{}, error) {
					return struct {
						Enabled bool `json:"enabled"`
					}{util.SliceContains(pp.Projects, context.ProjectRef.Identifier)}, nil
				},
			},
		},
	}, nil
	return nil, nil
}