-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.go
73 lines (57 loc) · 2.06 KB
/
preview.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"launchpad.net/go-unityscopes/v2"
//"log"
)
type Preview struct {
}
func (p *Preview) AddPreviewResult(result *scopes.Result, metadata *scopes.ActionMetadata, reply *scopes.PreviewReply) error {
layout1col := scopes.NewColumnLayout(1)
layout2col := scopes.NewColumnLayout(2)
layout3col := scopes.NewColumnLayout(3)
// Single column layout
layout1col.AddColumn("image", "header", "actions", "summary")
// Two column layout
layout2col.AddColumn("image", "header", "actions")
layout2col.AddColumn("summary")
// Three cokumn layout
layout3col.AddColumn("image")
layout3col.AddColumn("header", "actions")
layout3col.AddColumn("summary")
// Register the layouts we just created
reply.RegisterLayout(layout1col, layout2col, layout3col)
header := scopes.NewPreviewWidget("header", "header")
// It has title and a subtitle properties
header.AddAttributeMapping("title", "title")
header.AddAttributeMapping("subtitle", "salePrice")
header.AddAttributeMapping("attributes", "completeAttributes")
// Define the image section
image := scopes.NewPreviewWidget("image", "image")
image.AddAttributeMapping("source", "bigArt")
// build variant map.
tuple1 := make(map[string]interface{})
tuple1["id"] = "open"
tuple1["label"] = "Go to Store"
tuple1["uri"] = result.URI()
//tuple2 := make(map[string]interface{})
//tuple1["id"] = "download"
//tuple1["label"] = "Download"
//tuple3 := make(map[string]interface{})
//tuple1["id"] = "hide"
//tuple1["label"] = "Hide"
actions := scopes.NewPreviewWidget("actions", "actions")
actions.AddAttributeValue("actions", []interface{}{tuple1})
// Define the summary section
description := scopes.NewPreviewWidget("summary", "text")
description.AddAttributeMapping("text", "description")
var scope_data string
metadata.ScopeData(scope_data)
if len(scope_data) > 0 {
extra := scopes.NewPreviewWidget("extra", "text")
extra.AddAttributeValue("text", "test Text")
reply.PushWidgets(header, image, description, actions, extra)
} else {
reply.PushWidgets(header, image, description, actions)
}
return nil
}