Exemplo n.º 1
0
// nxnJSONHandler calculates the NxN diffs of all the digests that match
// the incoming query and returns the data in a format appropriate for
// handling in d3.
func nxnJSONHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	digestsInfo, _, _, err := search.Search(queryFromRequest(r), storages, tallies, blamer, paramsetSum)
	if err != nil {
		util.ReportError(w, r, err, "Search for digests failed.")
	}
	// Sort the digests so they are displayed with untriaged last, which means
	// they will be displayed 'on top', because in SVG document order is z-order.
	sort.Sort(SearchDigestSlice(digestsInfo))

	digests := []string{}
	for _, digest := range digestsInfo {
		digests = append(digests, digest.Digest)
	}

	digestIndex := map[string]int{}
	for i, d := range digests {
		digestIndex[d] = i
	}

	d3 := D3{
		Nodes:     []Node{},
		Links:     []Link{},
		Paramsets: map[string]map[string][]string{},
		Paramset:  map[string][]string{},
	}
	for i, d := range digestsInfo {
		d3.Nodes = append(d3.Nodes, Node{
			Name:   d.Digest,
			Status: d.Status,
		})
		remaining := digests[i:len(digests)]
		diffs, err := storages.DiffStore.Get(d.Digest, remaining)
		if err != nil {
			glog.Errorf("Failed to calculate differences: %s", err)
			continue
		}
		for otherDigest, diff := range diffs {
			d3.Links = append(d3.Links, Link{
				Source: digestIndex[d.Digest],
				Target: digestIndex[otherDigest],
				Value:  diff.PixelDiffPercent,
			})
		}
		d3.Paramsets[d.Digest] = paramsetSum.Get(d.Test, d.Digest, false)
		for _, p := range d3.Paramsets[d.Digest] {
			sort.Strings(p)
		}
		d3.Paramset = util.AddParamSetToParamSet(d3.Paramset, d3.Paramsets[d.Digest])
	}

	for _, p := range d3.Paramset {
		sort.Strings(p)
	}

	sendJsonResponse(w, d3)
}
Exemplo n.º 2
0
// TODO(stephan): Replace all other search handlers with  search3JSONHandler.
func search3JSONHandler(w http.ResponseWriter, r *http.Request) {
	digests, numMatches, commits, err := search.Search(queryFromRequest(r), storages, tallies, blamer, paramsetSum)
	if err != nil {
		util.ReportError(w, r, err, "Search for digests failed.")
		return
	}

	result := SearchResult{
		Digests:    digests,
		Commits:    commits,
		NumMatches: numMatches,
	}
	sendJsonResponse(w, &result)
}
Exemplo n.º 3
0
func search2Handler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html")
	if *local {
		loadTemplates()
	}
	digests, numMatches, commits, err := search.Search(queryFromRequest(r), storages, tallies, blamer, paramsetSum)
	if err != nil {
		util.ReportError(w, r, err, "Search for digests failed.")
	}
	js, err := json.MarshalIndent(digests, "", "  ")
	if err != nil {
		util.ReportError(w, r, err, "Failed to encode response data.")
		return
	}
	commitsjs, err := json.MarshalIndent(commits, "", "  ")
	if err != nil {
		util.ReportError(w, r, err, "Failed to encode commits.")
		return
	}

	context := struct {
		Digests    []*search.Digest
		JS         template.JS
		CommitsJS  template.JS
		NumMatches int
	}{
		Digests:    digests,
		JS:         template.JS(string(js)),
		CommitsJS:  template.JS(string(commitsjs)),
		NumMatches: numMatches,
	}

	if err := templates.ExecuteTemplate(w, "search2.html", context); err != nil {
		glog.Errorln("Failed to expand template:", err)
	}
}