~emersion/drmdb

1d13a4f645119c1a8b44a904010336323f122f3a — Simon Ser 6 months ago 4fe82e0
Add object type filter to properties list
2 files changed, 15 insertions(+), 1 deletions(-)

M public/properties.html
M server.go
M public/properties.html => public/properties.html +3 -1
@@ 23,7 23,9 @@
                  <a href="/properties/{{printf "%d" ($prop.ObjectType)}}/{{$name}}">{{$name}}</a>
              </td>
              <td>{{$prop.Type}}</td>
              <td>{{$prop.ObjectType}}</td>
              <td><a href="?object-type={{printf "%d" $prop.ObjectType}}" title="Filter by object type">
                  {{$prop.ObjectType}}
              </a></td>
              {{range $drv, $_ := $.Drivers}}
              {{if index $prop.Drivers $drv}}
              <td class="status-supported">✓</td>

M server.go => server.go +12 -0
@@ 270,6 270,15 @@ func New() *echo.Echo {
			Drivers    map[string]bool
		}

		var objectType drm.ObjectType
		if s := c.QueryParam("object-type"); s != "" {
			if i, err := strconv.Atoi(s); err != nil {
				return c.String(http.StatusBadRequest, "invalid object type")
			} else {
				objectType = drm.ObjectType(i)
			}
		}

		drivers := make(map[string]struct{})
		props := make(map[string]propertyData)
		err := database.Walk(func(k string, n *drmtree.Node) error {


@@ 277,6 286,9 @@ func New() *echo.Echo {
			drivers[drv] = struct{}{}

			return walkNodeProps(n, func(obj drm.AnyID, name string, prop *drmtree.Property) error {
				if objectType != drm.ObjectAny && obj.Type() != objectType {
					return nil
				}
				if _, ok := props[name]; !ok {
					props[name] = propertyData{
						Type:       prop.Type,