func (bbp *BuildBaronPlugin) GetPanelConfig() (*plugin.PanelConfig, error) {
	root := plugin.StaticWebRootFromSourceFile()
	panelHTML, err := ioutil.ReadFile(root + "/partials/ng_include_task_build_baron.html")
	if err != nil {
		return nil, fmt.Errorf("Can't load panel html file, %v, %v",
			root+"/partials/ng_include_task_build_baron.html", err)
	}

	includeJS, err := ioutil.ReadFile(root + "/partials/script_task_build_baron_js.html")
	if err != nil {
		return nil, fmt.Errorf("Can't load panel html file, %v, %v",
			root+"/partials/script_task_build_baron_js.html", err)
	}

	includeCSS, err := ioutil.ReadFile(root +
		"/partials/link_task_build_baron_css.html")
	if err != nil {
		return nil, fmt.Errorf("Can't load panel html file, %v, %v",
			root+"/partials/link_task_build_baron_css.html", err)
	}

	return &plugin.PanelConfig{
		StaticRoot: plugin.StaticWebRootFromSourceFile(),
		Panels: []plugin.UIPanel{
			{
				Page:      plugin.TaskPage,
				Position:  plugin.PageRight,
				PanelHTML: template.HTML(panelHTML),
				Includes:  []template.HTML{template.HTML(includeCSS), template.HTML(includeJS)},
			},
		},
	}, nil
}
Example #2
0
File: perf.go Project: 3rf/perf
func (pp *PerfPlugin) GetPanelConfig() (*plugin.PanelConfig, error) {
	root := plugin.StaticWebRootFromSourceFile()
	panelHTML, err := ioutil.ReadFile(root + "/task_perf_data.html")
	if err != nil {
		return nil, fmt.Errorf("Can't load panel html file: %v", err)
	}

	return &plugin.PanelConfig{
		StaticRoot: plugin.StaticWebRootFromSourceFile(),
		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
}
// GetPanelConfig returns a pointer to a plugin's UI configuration.
// or an error, if an error occur while trying to generate the config
// A nil pointer represents a plugin without a UI presence, and is
// not an error.
// GetPanelConfig returns a plugin.PanelConfig struct representing panels
// that will be added to the Version page.
func (m *ManifestPlugin) GetPanelConfig() (*plugin.PanelConfig, error) {
	return &plugin.PanelConfig{
		StaticRoot: plugin.StaticWebRootFromSourceFile(),
		Panels: []plugin.UIPanel{
			{
				Page:      plugin.VersionPage,
				Position:  plugin.PageRight,
				PanelHTML: "<div ng-include=\"'/plugin/manifest/static/partials/version_manifest_panel.html'\"></div>",
				DataFunc: func(context plugin.UIContext) (interface{}, error) {
					if context.Version == nil {
						return nil, nil
					}
					currentManifest, err := manifest.FindOne(manifest.ById(context.Version.Id))
					if err != nil {
						return nil, err
					}
					if currentManifest == nil {
						return nil, nil
					}
					prettyManifest, err := json.MarshalIndent(currentManifest, "", "  ")
					if err != nil {
						return nil, err
					}
					return string(prettyManifest), nil
				},
			},
		},
	}, nil
}
Example #4
0
func TestStaticWebRootHelper(t *testing.T) {
	Convey("With a call to the web root function", t, func() {
		path := plugin.StaticWebRootFromSourceFile()
		So(path, ShouldNotBeBlank)

		Convey("this source folder should be present in the returned path", func() {
			So(path, ShouldContainSubstring, "plugin/static")
		})
	})
}
Example #5
0
File: json.go Project: sr527/json
// GetPanelConfig is required to fulfill the Plugin interface. This plugin
// does not have any UI hooks.
func (jsp *JSONPlugin) GetPanelConfig() (*plugin.PanelConfig, error) {
	return &plugin.PanelConfig{
		StaticRoot: plugin.StaticWebRootFromSourceFile(),
		Panels: []plugin.UIPanel{
			{
				Page:      plugin.TaskPage,
				Position:  plugin.PageCenter,
				PanelHTML: "<!--hello world!-->",
				DataFunc: func(context plugin.UIContext) (interface{}, error) {
					return map[string]interface{}{}, nil
				},
			},
		},
	}, nil

	return nil, nil
}
Example #6
0
// GetPanelConfig returns a plugin.PanelConfig struct representing panels
// that will be added to the Task and Build pages.
func (self *AttachPlugin) GetPanelConfig() (*plugin.PanelConfig, error) {
	return &plugin.PanelConfig{
		StaticRoot: plugin.StaticWebRootFromSourceFile(),
		Panels: []plugin.UIPanel{
			{
				Page:     plugin.TaskPage,
				Position: plugin.PageCenter,
				PanelHTML: "<div ng-include=\"'/plugin/attach/static/partials/task_files_panel.html'\" " +
					"ng-init='files=plugins.attach' ng-show='plugins.attach.length'></div>",
				DataFunc: func(context plugin.UIContext) (interface{}, error) {
					if context.Task == nil {
						return nil, nil
					}
					artifactEntry, err := artifact.FindOne(artifact.ByTaskId(context.Task.Id))
					if err != nil {
						return nil, fmt.Errorf("error finding artifact files for task: %v", err)
					}
					if artifactEntry == nil {
						return nil, nil
					}
					return stripHiddenFiles(artifactEntry.Files, context.User), nil
				},
			},
			{
				Page:     plugin.BuildPage,
				Position: plugin.PageLeft,
				PanelHTML: "<div ng-include=\"'/plugin/attach/static/partials/build_files_panel.html'\" " +
					"ng-init='filesByTask=plugins.attach' ng-show='plugins.attach.length'></div>",
				DataFunc: func(context plugin.UIContext) (interface{}, error) {
					if context.Build == nil {
						return nil, nil
					}
					taskArtifactFiles, err := artifact.FindAll(artifact.ByBuildId(context.Build.Id))
					if err != nil {
						return nil, fmt.Errorf("error finding artifact files for build: %v", err)
					}
					for i := range taskArtifactFiles {
						// remove hidden files if the user isn't logged in
						taskArtifactFiles[i].Files = stripHiddenFiles(taskArtifactFiles[i].Files, context.User)
					}
					return taskArtifactFiles, nil
				},
			},
		},
	}, nil
}