fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

indexserver: new root page (#505)

The repos are now hidden by default. If visible they are rendered as
html table instead of buttons inside a form.

+63 -62
+62 -61
cmd/zoekt-sourcegraph-indexserver/main.go
··· 659 659 mux.Handle("/debug/host", http.HandlerFunc(s.handleHost)) 660 660 } 661 661 662 - var repoTmpl = template.Must(template.New("name").Parse(` 663 - <html><body> 664 - <a href="debug">Debug</a><br> 665 - <a href="debug/requests">Traces</a><br> 666 - {{.IndexMsg}}<br /> 667 - <br /> 668 - <h3>Re-index repository</h3> 669 - <form action="." method="post"> 670 - {{range .Repos}} 671 - <button type="submit" name="repo" value="{{ .ID }}" />{{ .Name }}</button><br /> 672 - {{end}} 673 - </form> 674 - </body></html> 675 - `)) 676 - 677 662 func (s *Server) handleHost(w http.ResponseWriter, r *http.Request) { 678 663 if r.Method != "GET" { 679 664 w.Header().Set("Allow", "GET") ··· 697 682 w.Write(b) 698 683 } 699 684 700 - func (s *Server) handleRoot(w http.ResponseWriter, r *http.Request) { 701 - renderRoot := func(indexMsg string) { 702 - type Repo struct { 703 - ID uint32 704 - Name string 705 - } 706 - var data struct { 707 - Repos []Repo 708 - IndexMsg string 709 - } 710 - 711 - data.IndexMsg = indexMsg 685 + var rootTmpl = template.Must(template.New("name").Parse(` 686 + <html> 687 + <body> 688 + <a href="debug">Debug</a><br /> 689 + <a href="debug/requests">Traces</a><br /> 690 + {{.IndexMsg}}<br /> 691 + <br /> 692 + <h3>Reindex</h3> 693 + {{if .Repos}} 694 + <a href="/?show_repos=false">hide repos</a><br /> 695 + <table style="margin-top: 20px"> 696 + <th style="text-align:left">Name</th> 697 + <th style="text-align:left">ID</th> 698 + {{range .Repos}} 699 + <tr> 700 + <td>{{.Name}}</td> 701 + <td><a href="/?id={{.ID}}&show_repos=true">{{.ID}}</a></id> 702 + </tr> 703 + {{end}} 704 + </table> 705 + {{else}} 706 + <a href="/?show_repos=true">show repos</a><br /> 707 + {{end}} 708 + </body> 709 + </html> 710 + `)) 712 711 713 - s.queue.Iterate(func(opts *IndexOptions) { 714 - data.Repos = append(data.Repos, Repo{ 715 - ID: opts.RepoID, 716 - Name: opts.Name, 717 - }) 718 - }) 719 - 720 - _ = repoTmpl.Execute(w, data) 712 + func (s *Server) handleRoot(w http.ResponseWriter, r *http.Request) { 713 + if r.Method != "GET" { 714 + w.Header().Set("Allow", "GET") 715 + w.WriteHeader(http.StatusMethodNotAllowed) 716 + return 721 717 } 722 718 723 - switch r.Method { 724 - case "GET": 725 - renderRoot("") 726 - case "POST": 727 - err := r.ParseForm() 728 - if err != nil { 729 - http.Error(w, err.Error(), http.StatusBadRequest) 730 - return 731 - } 719 + values := r.URL.Query() 732 720 733 - id, err := strconv.Atoi(r.Form.Get("repo")) 721 + // ?id= 722 + indexMsg := "" 723 + if v := values.Get("id"); v != "" { 724 + id, err := strconv.Atoi(v) 734 725 if err != nil { 735 726 http.Error(w, err.Error(), http.StatusBadRequest) 736 727 return 737 728 } 729 + indexMsg, _ = s.forceIndex(uint32(id)) 730 + } 738 731 739 - indexMsg, err := s.forceIndex(uint32(id)) 732 + // ?show_repos= 733 + showRepos := false 734 + if v := values.Get("show_repos"); v != "" { 735 + showRepos, _ = strconv.ParseBool(v) 736 + } 740 737 741 - // TODO: we won't need "headless" once Sourcegraph calls 742 - // "/debug/handleReindex". 738 + type Repo struct { 739 + ID uint32 740 + Name string 741 + } 742 + var data struct { 743 + Repos []Repo 744 + IndexMsg string 745 + } 743 746 744 - // ?headless 745 - if _, ok := r.URL.Query()["headless"]; ok { 746 - if err != nil { 747 - http.Error(w, indexMsg, http.StatusInternalServerError) 748 - return 749 - } 750 - w.Write([]byte(indexMsg)) 751 - return 752 - } 747 + data.IndexMsg = indexMsg 753 748 754 - renderRoot(indexMsg) 755 - default: 756 - w.Header().Set("Allow", "GET, POST") 757 - w.WriteHeader(http.StatusMethodNotAllowed) 749 + if showRepos { 750 + s.queue.Iterate(func(opts *IndexOptions) { 751 + data.Repos = append(data.Repos, Repo{ 752 + ID: opts.RepoID, 753 + Name: opts.Name, 754 + }) 755 + }) 756 + sort.Slice(data.Repos, func(i, j int) bool { return data.Repos[i].Name < data.Repos[j].Name }) 758 757 } 758 + 759 + _ = rootTmpl.Execute(w, data) 759 760 } 760 761 761 762 // handleReindex triggers a reindex asynocronously. If a reindex was triggered
+1 -1
debugserver/debug.go
··· 28 28 </style> 29 29 </head> 30 30 <body> 31 - /debug<br> 31 + <a href="/">/<a/><span style="margin:2px">debug</span><br> 32 32 <br> 33 33 <a class="debug-page" href="vars">Vars</a><br> 34 34 {{if .EnablePprof}}<a class="debug-page" href="debug/pprof/">PProf</a>{{else}}PProf disabled{{end}}<br>