~emersion/drmdb

2fbcdd24115a756372c397d8fb99bea838d4a004 — Simon Ser 7 months ago 927757d
Add format/modifier filters on format page
2 files changed, 64 insertions(+), 10 deletions(-)

M public/formats.html
M server.go
M public/formats.html => public/formats.html +15 -3
@@ 5,7 5,7 @@

  <p><a href="/">Back to index</a></p>

  {{if or .DriverFilter .PlaneFilter}}
  {{if or .DriverFilter .PlaneFilter .FormatFilter .ModifierFilter}}
  <p>
      Filters:
      {{with .DriverFilter}}


@@ 20,6 20,18 @@
          <a href="/formats" title="Clear filter">×</a>
      </span>
      {{end}}
      {{with .FormatFilter}}
      <span class="filter">
          {{.Name}}
          <a href="/formats" title="Clear filter">×</a>
      </span>
      {{end}}
      {{with .ModifierFilter}}
      <span class="filter">
          {{.Name}}
          <a href="/formats" title="Clear filter">×</a>
      </span>
      {{end}}
  </p>
  {{end}}



@@ 56,8 68,8 @@
          {{range .Formats}}
          <tr>
              {{$row := .}}
              <td class="pre" title="{{drmModifierHex .Modifier}}">{{.Modifier.Name}}</td>
              <td class="pre" title="{{drmFormatHex .Format}}">{{.Format.Name}}</td>
              <td class="pre" title="{{drmModifierHex .Modifier}}"><a href="?modifier={{printf "%d" .Modifier}}">{{.Modifier.Name}}</a></td>
              <td class="pre" title="{{drmFormatHex .Format}}"><a href="?format={{printf "%d" .Format}}">{{.Format.Name}}</a></td>
              {{range $plane, $total := $.Planes}}
              {{template "pct-cell" (pct (index $row.Planes $plane) $total)}}
              {{end}}

M server.go => server.go +49 -7
@@ 573,6 573,24 @@ func New() *echo.Echo {
		}
		driverFilter := c.QueryParam("driver")

		formatFilter := drm.FormatINVALID
		if s := c.QueryParam("format"); s != "" {
			if u, err := strconv.ParseUint(s, 0, 32); err != nil {
				return c.String(http.StatusBadRequest, "invalid format")
			} else {
				formatFilter = drm.Format(u)
			}
		}

		modifierFilter := drm.ModifierINVALID
		if s := c.QueryParam("modifier"); s != "" {
			if u, err := strconv.ParseUint(s, 0, 64); err != nil {
				return c.String(http.StatusBadRequest, "invalid modifier")
			} else {
				modifierFilter = drm.Modifier(u)
			}
		}

		// For each (modifier, format) pair, build two tables by walking each
		// device:
		// - Number of devices supporting it by plane type (max: number of


@@ 604,7 622,15 @@ func New() *echo.Echo {

				inFormats := plane.InFormats()
				for _, mod := range inFormats {
					if modifierFilter != drm.ModifierINVALID && mod.Modifier != modifierFilter {
						continue
					}

					for _, fmt := range mod.Formats {
						if formatFilter != drm.FormatINVALID && fmt != formatFilter {
							continue
						}

						k := modifierAndFormat{mod.Modifier, fmt}
						if _, ok := formats[k]; !ok {
							formats[k] = formatData{


@@ 633,19 659,35 @@ func New() *echo.Echo {
			return err
		}

		var planeFilterPtr *drm.PlaneType
		var (
			planeFilterPtr    *drm.PlaneType
			modifierFilterPtr *drm.Modifier
		)
		if planeFilter >= 0 {
			pt := drm.PlaneType(planeFilter)
			planeFilterPtr = &pt
		}
		if modifierFilter != drm.ModifierINVALID {
			modifierFilterPtr = &modifierFilter
		}

		return c.Render(http.StatusOK, "formats.html", struct {
			PlaneFilter  *drm.PlaneType
			DriverFilter string
			Planes       map[drm.PlaneType]int
			Drivers      map[string]int
			Formats      map[modifierAndFormat]formatData
		}{planeFilterPtr, driverFilter, planes, drivers, formats})
			PlaneFilter    *drm.PlaneType
			DriverFilter   string
			FormatFilter   drm.Format
			ModifierFilter *drm.Modifier
			Planes         map[drm.PlaneType]int
			Drivers        map[string]int
			Formats        map[modifierAndFormat]formatData
		}{
			PlaneFilter:    planeFilterPtr,
			DriverFilter:   driverFilter,
			FormatFilter:   formatFilter,
			ModifierFilter: modifierFilterPtr,
			Planes:         planes,
			Drivers:        drivers,
			Formats:        formats,
		})
	})

	e.Static("/assets", PublicDir+"/assets")