Add stars to Albums

This commit is contained in:
Deluan 2020-08-14 13:35:28 -04:00
parent f2ebbd26fa
commit c2e03c8162
8 changed files with 56 additions and 8 deletions

View file

@ -41,6 +41,7 @@ func NewAlbumRepository(ctx context.Context, o orm.Ormer) model.AlbumRepository
"artist_id": artistFilter, "artist_id": artistFilter,
"year": yearFilter, "year": yearFilter,
"recently_played": recentlyPlayedFilter, "recently_played": recentlyPlayedFilter,
"starred": booleanFilter,
} }
return r return r
@ -313,5 +314,22 @@ func (r *albumRepository) NewInstance() interface{} {
return &model.Album{} return &model.Album{}
} }
func (r albumRepository) Delete(id string) error {
return r.delete(Eq{"id": id})
}
func (r albumRepository) Save(entity interface{}) (string, error) {
mf := entity.(*model.Artist)
id, err := r.put(mf.ID, mf)
return id, err
}
func (r albumRepository) Update(entity interface{}, cols ...string) error {
mf := entity.(*model.Artist)
_, err := r.put(mf.ID, mf)
return err
}
var _ model.AlbumRepository = (*albumRepository)(nil) var _ model.AlbumRepository = (*albumRepository)(nil)
var _ model.ResourceRepository = (*albumRepository)(nil) var _ model.ResourceRepository = (*albumRepository)(nil)
var _ rest.Persistable = (*albumRepository)(nil)

View file

@ -203,14 +203,14 @@ func (r artistRepository) Delete(id string) error {
} }
func (r artistRepository) Save(entity interface{}) (string, error) { func (r artistRepository) Save(entity interface{}) (string, error) {
mf := entity.(*model.Artist) artist := entity.(*model.Artist)
err := r.Put(mf) err := r.Put(artist)
return mf.ID, err return artist.ID, err
} }
func (r artistRepository) Update(entity interface{}, cols ...string) error { func (r artistRepository) Update(entity interface{}, cols ...string) error {
mf := entity.(*model.Artist) artist := entity.(*model.Artist)
return r.Put(mf) return r.Put(artist)
} }
var _ model.ArtistRepository = (*artistRepository)(nil) var _ model.ArtistRepository = (*artistRepository)(nil)

View file

@ -53,6 +53,7 @@
"lists": { "lists": {
"all": "Todos", "all": "Todos",
"random": "Aleatório", "random": "Aleatório",
"starred": "Favoritos",
"recentlyAdded": "Recém-adicionados", "recentlyAdded": "Recém-adicionados",
"recentlyPlayed": "Recém-tocados", "recentlyPlayed": "Recém-tocados",
"mostPlayed": "Mais tocados" "mostPlayed": "Mais tocados"

View file

@ -12,8 +12,9 @@ import {
useTranslate, useTranslate,
useListParams, useListParams,
} from 'react-admin' } from 'react-admin'
import { List, Title, useAlbumsPerPage } from '../common' import StarIcon from '@material-ui/icons/Star'
import { withWidth } from '@material-ui/core' import { withWidth } from '@material-ui/core'
import { List, QuickFilter, Title, useAlbumsPerPage } from '../common'
import AlbumListActions from './AlbumListActions' import AlbumListActions from './AlbumListActions'
import AlbumListView from './AlbumListView' import AlbumListView from './AlbumListView'
import AlbumGridView from './AlbumGridView' import AlbumGridView from './AlbumGridView'
@ -37,6 +38,11 @@ const AlbumFilter = (props) => {
</ReferenceInput> </ReferenceInput>
<NullableBooleanInput source="compilation" /> <NullableBooleanInput source="compilation" />
<NumberInput source="year" /> <NumberInput source="year" />
<QuickFilter
source="starred"
label={<StarIcon fontSize={'small'} />}
defaultValue={true}
/>
</Filter> </Filter>
) )
} }

View file

@ -10,14 +10,24 @@ import {
SimpleShowLayout, SimpleShowLayout,
TextField, TextField,
} from 'react-admin' } from 'react-admin'
import { useMediaQuery } from '@material-ui/core'
import StarBorderIcon from '@material-ui/icons/StarBorder'
import { import {
ArtistLinkField, ArtistLinkField,
DurationField, DurationField,
RangeField, RangeField,
SimpleList, SimpleList,
} from '../common' } from '../common'
import { useMediaQuery } from '@material-ui/core'
import { AlbumContextMenu } from '../common' import { AlbumContextMenu } from '../common'
import { makeStyles } from '@material-ui/core/styles'
const useStyles = makeStyles({
columnIcon: {
marginLeft: '3px',
marginTop: '-2px',
verticalAlign: 'text-top',
},
})
const AlbumDetails = (props) => { const AlbumDetails = (props) => {
return ( return (
@ -64,6 +74,7 @@ const AlbumDatagrid = (props) => (
) )
const AlbumListView = ({ hasShow, hasEdit, hasList, ...rest }) => { const AlbumListView = ({ hasShow, hasEdit, hasList, ...rest }) => {
const classes = useStyles()
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md')) const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('md'))
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs')) const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
return isXsmall ? ( return isXsmall ? (
@ -88,7 +99,11 @@ const AlbumListView = ({ hasShow, hasEdit, hasList, ...rest }) => {
{isDesktop && <NumberField source="playCount" sortByOrder={'DESC'} />} {isDesktop && <NumberField source="playCount" sortByOrder={'DESC'} />}
<RangeField source={'year'} sortBy={'maxYear'} sortByOrder={'DESC'} /> <RangeField source={'year'} sortBy={'maxYear'} sortByOrder={'DESC'} />
{isDesktop && <DurationField source="duration" />} {isDesktop && <DurationField source="duration" />}
<AlbumContextMenu /> <AlbumContextMenu
label={
<StarBorderIcon fontSize={'small'} className={classes.columnIcon} />
}
/>
</AlbumDatagrid> </AlbumDatagrid>
) )
} }

View file

@ -3,6 +3,7 @@ import LibraryAddIcon from '@material-ui/icons/LibraryAdd'
import VideoLibraryIcon from '@material-ui/icons/VideoLibrary' import VideoLibraryIcon from '@material-ui/icons/VideoLibrary'
import RepeatIcon from '@material-ui/icons/Repeat' import RepeatIcon from '@material-ui/icons/Repeat'
import AlbumIcon from '@material-ui/icons/Album' import AlbumIcon from '@material-ui/icons/Album'
import StarIcon from '@material-ui/icons/Star'
export default { export default {
all: { all: {
@ -10,6 +11,10 @@ export default {
params: 'sort=name&order=ASC', params: 'sort=name&order=ASC',
}, },
random: { icon: ShuffleIcon, params: 'sort=random' }, random: { icon: ShuffleIcon, params: 'sort=random' },
starred: {
icon: StarIcon,
params: 'sort=starred_at&order=DESC&filter={"starred":true}',
},
recentlyAdded: { recentlyAdded: {
icon: LibraryAddIcon, icon: LibraryAddIcon,
params: 'sort=created_at&order=DESC', params: 'sort=created_at&order=DESC',

View file

@ -201,10 +201,12 @@ AlbumContextMenu.propTypes = {
discNumber: PropTypes.number, discNumber: PropTypes.number,
visible: PropTypes.bool, visible: PropTypes.bool,
color: PropTypes.string, color: PropTypes.string,
showStar: PropTypes.bool,
} }
AlbumContextMenu.defaultProps = { AlbumContextMenu.defaultProps = {
visible: true, visible: true,
showStar: true,
addLabel: true, addLabel: true,
} }

View file

@ -54,6 +54,7 @@
"lists": { "lists": {
"all": "All", "all": "All",
"random": "Random", "random": "Random",
"starred": "Starred",
"recentlyAdded": "Recently Added", "recentlyAdded": "Recently Added",
"recentlyPlayed": "Recently Played", "recentlyPlayed": "Recently Played",
"mostPlayed": "Most Played" "mostPlayed": "Most Played"