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,
"year": yearFilter,
"recently_played": recentlyPlayedFilter,
"starred": booleanFilter,
}
return r
@ -313,5 +314,22 @@ func (r *albumRepository) NewInstance() interface{} {
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.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) {
mf := entity.(*model.Artist)
err := r.Put(mf)
return mf.ID, err
artist := entity.(*model.Artist)
err := r.Put(artist)
return artist.ID, err
}
func (r artistRepository) Update(entity interface{}, cols ...string) error {
mf := entity.(*model.Artist)
return r.Put(mf)
artist := entity.(*model.Artist)
return r.Put(artist)
}
var _ model.ArtistRepository = (*artistRepository)(nil)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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