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
+14 -14
View File
@@ -12,20 +12,20 @@ import (
) )
type album struct { type album struct {
ID string `orm:"pk;column(id)"` ID string `json:"id" orm:"pk;column(id)"`
Name string `orm:"index"` Name string `json:"name" orm:"index"`
ArtistID string `orm:"column(artist_id);index"` ArtistID string `json:"artistId" orm:"column(artist_id);index"`
CoverArtPath string `` CoverArtPath string `json:"-"`
CoverArtId string `` CoverArtId string `json:"-"`
Artist string `orm:"index"` Artist string `json:"artist" orm:"index"`
AlbumArtist string `` AlbumArtist string `json:"albumArtist"`
Year int `orm:"index"` Year int `json:"year" orm:"index"`
Compilation bool `` Compilation bool `json:"compilation"`
SongCount int `` SongCount int `json:"songCount"`
Duration int `` Duration int `json:"duration"`
Genre string `orm:"index"` Genre string `json:"genre" orm:"index"`
CreatedAt time.Time `orm:"null"` CreatedAt time.Time `json:"createdAt" orm:"null"`
UpdatedAt time.Time `orm:"null"` UpdatedAt time.Time `json:"updatedAt" orm:"null"`
} }
type albumRepository struct { type albumRepository struct {
+12 -12
View File
@@ -50,25 +50,25 @@ func (app *Router) routes() http.Handler {
// Add User resource // Add User resource
r.Use(jwtauth.Verifier(TokenAuth)) r.Use(jwtauth.Verifier(TokenAuth))
r.Use(Authenticator) r.Use(Authenticator)
R(r, "/user", func(ctx context.Context) rest.Repository { app.R(r, "/user", model.User{})
return app.ds.Resource(model.User{}) app.R(r, "/song", model.MediaFile{})
}) app.R(r, "/album", model.Album{})
R(r, "/song", func(ctx context.Context) rest.Repository {
return app.ds.Resource(model.MediaFile{})
})
}) })
return r 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.Route(pathPrefix, func(r chi.Router) {
r.Get("/", rest.GetAll(newRepository)) r.Get("/", rest.GetAll(constructor))
r.Post("/", rest.Post(newRepository)) r.Post("/", rest.Post(constructor))
r.Route("/{id:[0-9a-f\\-]+}", func(r chi.Router) { r.Route("/{id:[0-9a-f\\-]+}", func(r chi.Router) {
r.Use(UrlParams) r.Use(UrlParams)
r.Get("/", rest.Get(newRepository)) r.Get("/", rest.Get(constructor))
r.Put("/", rest.Put(newRepository)) r.Put("/", rest.Put(constructor))
r.Delete("/", rest.Delete(newRepository)) r.Delete("/", rest.Delete(constructor))
}) })
}) })
} }
+2
View File
@@ -6,6 +6,7 @@ import authProvider from './authProvider'
import { Login } from './layout' import { Login } from './layout'
import user from './user' import user from './user'
import song from './song' import song from './song'
import album from './album'
const App = () => ( const App = () => (
<Admin <Admin
@@ -14,6 +15,7 @@ const App = () => (
loginPage={Login} loginPage={Login}
> >
<Resource name="song" {...song} /> <Resource name="song" {...song} />
<Resource name="album" {...album} />
<Resource name="user" {...user} /> <Resource name="user" {...user} />
</Admin> </Admin>
) )
+57
View 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
View File
@@ -0,0 +1,7 @@
import AlbumIcon from '@material-ui/icons/Album'
import AlbumList from './AlbumList'
export default {
list: AlbumList,
icon: AlbumIcon
}
+2 -2
View File
@@ -1,7 +1,7 @@
import MusicNote from '@material-ui/icons/MusicNote' import MusicNoteIcon from '@material-ui/icons/MusicNote'
import SongList from './SongList' import SongList from './SongList'
export default { export default {
list: SongList, list: SongList,
icon: MusicNote icon: MusicNoteIcon
} }