~emersion/drmdb

6f22b95e0ea72fba0c6fa24cbc3516f640f209de — Simon Ser 2 years ago f521d82
Add object type to prop URLs
3 files changed, 14 insertions(+), 7 deletions(-)

M public/properties.html
M public/property.html
M server.go
M public/properties.html => public/properties.html +3 -1
@@ 18,7 18,9 @@
    <tbody>
        {{range $name, $prop := .Properties}}
        <tr>
            <td class="pre"><a href="/properties/{{$name}}">{{$name}}</a></td>
            <td class="pre">
                <a href="/properties/{{printf "%d" ($prop.ObjectType)}}/{{$name}}">{{$name}}</a>
            </td>
            <td>{{$prop.Type}}</td>
            <td>{{$prop.ObjectType}}</td>
            {{range $drv, $_ := $.Drivers}}

M public/property.html => public/property.html +2 -2
@@ 1,6 1,6 @@
{{template "head" (printf "Property: %s" .Name)}}

<h1>DRM database property: {{.Name}}</h1>
<h1>DRM database property: <code>{{.Name}}</code></h1>

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



@@ 8,7 8,7 @@

<dl>
    <dt>Name</dt>
    <dd>{{.Name}}</dd>
    <dd><code>{{.Name}}</code></dd>

    <dt>Flags</dt>
    {{if len .Flags}}

M server.go => server.go +9 -4
@@ 389,24 389,29 @@ func New() *echo.Echo {
		}{drivers, props})
	})

	e.GET("/properties/:name", func(c echo.Context) error {
	e.GET("/properties/:obj/:name", func(c echo.Context) error {
		var objectType drm.ObjectType
		if i, err := strconv.Atoi(c.Param("obj")); err != nil {
			return c.String(http.StatusBadRequest, "invalid object type")
		} else {
			objectType = drm.ObjectType(i)
		}
		propertyName := c.Param("name")

		found := false;
		var property drmtree.Property
		var objectType drm.ObjectType

		drivers := make(map[string]bool)
		err := walk(func(k string, n *drmtree.Node) error {
			drivers[n.Driver.Name] = false

			return walkNodeProps(n, func(obj drm.AnyID, name string, p *drmtree.Property) error {
				if name != propertyName {
				if obj.Type() != objectType || name != propertyName {
					return nil
				}
				drivers[n.Driver.Name] = true
				found = true
				property = *p
				objectType = obj.Type()
				return nil
			})
		})