Initial support for album browsing from UI

This commit is contained in:
Deluan 2020-01-22 12:32:31 -05:00
parent 3a8124a1de
commit ea30b4c2d9
6 changed files with 94 additions and 28 deletions

@ -12,20 +12,20 @@ import (
)
type album struct {
ID string `orm:"pk;column(id)"`
Name string `orm:"index"`
ArtistID string `orm:"column(artist_id);index"`
CoverArtPath string ``
CoverArtId string ``
Artist string `orm:"index"`
AlbumArtist string ``
Year int `orm:"index"`
Compilation bool ``
SongCount int ``
Duration int ``
Genre string `orm:"index"`
CreatedAt time.Time `orm:"null"`
UpdatedAt time.Time `orm:"null"`
ID string `json:"id" orm:"pk;column(id)"`
Name string `json:"name" orm:"index"`
ArtistID string `json:"artistId" orm:"column(artist_id);index"`
CoverArtPath string `json:"-"`
CoverArtId string `json:"-"`
Artist string `json:"artist" orm:"index"`
AlbumArtist string `json:"albumArtist"`
Year int `json:"year" orm:"index"`
Compilation bool `json:"compilation"`
SongCount int `json:"songCount"`
Duration int `json:"duration"`
Genre string `json:"genre" orm:"index"`
CreatedAt time.Time `json:"createdAt" orm:"null"`
UpdatedAt time.Time `json:"updatedAt" orm:"null"`
}
type albumRepository struct {

@ -50,25 +50,25 @@ func (app *Router) routes() http.Handler {
// Add User resource
r.Use(jwtauth.Verifier(TokenAuth))
r.Use(Authenticator)
R(r, "/user", func(ctx context.Context) rest.Repository {
return app.ds.Resource(model.User{})
})
R(r, "/song", func(ctx context.Context) rest.Repository {
return app.ds.Resource(model.MediaFile{})
})
app.R(r, "/user", model.User{})
app.R(r, "/song", model.MediaFile{})
app.R(r, "/album", model.Album{})
})
return r
}
func R(r chi.Router, pathPrefix string, newRepository rest.RepositoryConstructor) {
func (app *Router) R(r chi.Router, pathPrefix string, model interface{}) {
constructor := func(ctx context.Context) rest.Repository {
return app.ds.Resource(model)
}
r.Route(pathPrefix, func(r chi.Router) {
r.Get("/", rest.GetAll(newRepository))
r.Post("/", rest.Post(newRepository))
r.Get("/", rest.GetAll(constructor))
r.Post("/", rest.Post(constructor))
r.Route("/{id:[0-9a-f\\-]+}", func(r chi.Router) {
r.Use(UrlParams)
r.Get("/", rest.Get(newRepository))
r.Put("/", rest.Put(newRepository))
r.Delete("/", rest.Delete(newRepository))
r.Get("/", rest.Get(constructor))
r.Put("/", rest.Put(constructor))
r.Delete("/", rest.Delete(constructor))
})
})
}

@ -6,6 +6,7 @@ import authProvider from './authProvider'
import { Login } from './layout'
import user from './user'
import song from './song'
import album from './album'
const App = () => (
<Admin
@ -14,6 +15,7 @@ const App = () => (
loginPage={Login}
>
<Resource name="song" {...song} />
<Resource name="album" {...album} />
<Resource name="user" {...user} />
</Admin>
)

57
ui/src/album/AlbumList.js Normal file

@ -0,0 +1,57 @@
import React from 'react'
import {
BooleanField,
Datagrid,
DateField,
Filter,
List,
NumberField,
SearchInput,
TextInput,
Show,
SimpleShowLayout,
TextField
} from 'react-admin'
import { BitrateField, DurationField, Title } from '../common'
const AlbumFilter = (props) => (
<Filter {...props}>
<SearchInput source="name" alwaysOn />
<TextInput source="artist" />
</Filter>
)
const AlbumDetails = (props) => {
return (
<Show {...props} title=" ">
<SimpleShowLayout>
<TextField label="Album Artist" source="albumArtist" />
<TextField source="genre" />
<BooleanField source="compilation" />
<DateField source="updatedAt" showTime />
</SimpleShowLayout>
</Show>
)
}
const AlbumList = (props) => (
<List
{...props}
title={<Title subTitle={'Albums'} />}
sort={{ field: 'name', order: 'ASC' }}
exporter={false}
bulkActionButtons={false}
filters={<AlbumFilter />}
perPage={15}
>
<Datagrid expand={<AlbumDetails />}>
<TextField source="name" />
<TextField source="artist" />
<NumberField source="songCount" />
<TextField source="year" />
<DurationField label="Time" source="duration" />
</Datagrid>
</List>
)
export default AlbumList

7
ui/src/album/index.js Normal file

@ -0,0 +1,7 @@
import AlbumIcon from '@material-ui/icons/Album'
import AlbumList from './AlbumList'
export default {
list: AlbumList,
icon: AlbumIcon
}

@ -1,7 +1,7 @@
import MusicNote from '@material-ui/icons/MusicNote'
import MusicNoteIcon from '@material-ui/icons/MusicNote'
import SongList from './SongList'
export default {
list: SongList,
icon: MusicNote
icon: MusicNoteIcon
}