mirror of
https://github.com/navidrome/navidrome.git
synced 2026-05-03 06:51:16 +00:00
Merge a3013a2750e5ac111d3e7e06dff0310e180b2d1d into 12d08985855353681c02d9eb9448cd69dc5f69bf
This commit is contained in:
commit
9993984e4e
@ -0,0 +1,7 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
ALTER TABLE annotation ADD COLUMN rated_at datetime;
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
|
||||
@ -6,6 +6,7 @@ type Annotations struct {
|
||||
PlayCount int64 `structs:"play_count" json:"playCount,omitempty"`
|
||||
PlayDate *time.Time `structs:"play_date" json:"playDate,omitempty" `
|
||||
Rating int `structs:"rating" json:"rating,omitempty" `
|
||||
RatedAt *time.Time `structs:"rated_at" json:"ratedAt,omitempty" `
|
||||
Starred bool `structs:"starred" json:"starred,omitempty" `
|
||||
StarredAt *time.Time `structs:"starred_at" json:"starredAt,omitempty"`
|
||||
}
|
||||
|
||||
@ -44,6 +44,7 @@ var fieldMap = map[string]*mappedField{
|
||||
"loved": {field: "COALESCE(annotation.starred, false)"},
|
||||
"dateloved": {field: "annotation.starred_at"},
|
||||
"lastplayed": {field: "annotation.play_date"},
|
||||
"daterated": {field: "annotation.rated_at"},
|
||||
"playcount": {field: "COALESCE(annotation.play_count, 0)"},
|
||||
"rating": {field: "COALESCE(annotation.rating, 0)"},
|
||||
"mbz_album_id": {field: "media_file.mbz_album_id"},
|
||||
|
||||
@ -388,6 +388,7 @@ func (r *playlistRepository) loadTracks(sel SelectBuilder, id string) (model.Pla
|
||||
"coalesce(play_count, 0) as play_count",
|
||||
"play_date",
|
||||
"coalesce(rating, 0) as rating",
|
||||
"rated_at",
|
||||
"f.*",
|
||||
"playlist_tracks.*",
|
||||
"library.path as library_path",
|
||||
|
||||
@ -97,6 +97,7 @@ func (r *playlistTrackRepository) Read(id string) (interface{}, error) {
|
||||
"coalesce(rating, 0) as rating",
|
||||
"starred_at",
|
||||
"play_date",
|
||||
"rated_at",
|
||||
"f.*",
|
||||
"playlist_tracks.*",
|
||||
).
|
||||
|
||||
@ -28,6 +28,7 @@ func (r sqlRepository) withAnnotation(query SelectBuilder, idField string) Selec
|
||||
"coalesce(rating, 0) as rating",
|
||||
"starred_at",
|
||||
"play_date",
|
||||
"rated_at",
|
||||
)
|
||||
if conf.Server.AlbumPlayCountMode == consts.AlbumPlayCountModeNormalized && r.tableName == "album" {
|
||||
query = query.Columns(
|
||||
@ -77,7 +78,8 @@ func (r sqlRepository) SetStar(starred bool, ids ...string) error {
|
||||
}
|
||||
|
||||
func (r sqlRepository) SetRating(rating int, itemID string) error {
|
||||
return r.annUpsert(map[string]interface{}{"rating": rating}, itemID)
|
||||
ratedAt := time.Now()
|
||||
return r.annUpsert(map[string]interface{}{"rating": rating, "rated_at": ratedAt}, itemID)
|
||||
}
|
||||
|
||||
func (r sqlRepository) IncPlayCount(itemID string, ts time.Time) error {
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import React from 'react'
|
||||
import { isDateSet } from '../utils/validations'
|
||||
import { DateField as RADateField } from 'react-admin'
|
||||
|
||||
export const DateField = (props) => {
|
||||
const { record, source } = props
|
||||
const value = record?.[source]
|
||||
if (value === '0001-01-01T00:00:00Z' || value === null) return null
|
||||
if (!isDateSet(value)) return null
|
||||
return <RADateField {...props} />
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import { makeStyles } from '@material-ui/core/styles'
|
||||
import { useToggleLove } from './useToggleLove'
|
||||
import { useRecordContext } from 'react-admin'
|
||||
import config from '../config'
|
||||
import { isDateSet } from '../utils/validations'
|
||||
|
||||
const useStyles = makeStyles({
|
||||
love: {
|
||||
@ -46,8 +47,13 @@ export const LoveButton = ({
|
||||
<Button
|
||||
onClick={handleToggleLove}
|
||||
size={'small'}
|
||||
disabled={disabled || loading || record?.missing}
|
||||
disabled={disabled || loading || record.missing}
|
||||
className={classes.love}
|
||||
title={
|
||||
isDateSet(record.starredAt)
|
||||
? new Date(record.starredAt).toLocaleString()
|
||||
: undefined
|
||||
}
|
||||
{...rest}
|
||||
>
|
||||
{record.starred ? (
|
||||
|
||||
@ -2,6 +2,7 @@ import React, { useCallback } from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import Rating from '@material-ui/lab/Rating'
|
||||
import { makeStyles } from '@material-ui/core/styles'
|
||||
import { isDateSet } from '../utils/validations'
|
||||
import StarBorderIcon from '@material-ui/icons/StarBorder'
|
||||
import clsx from 'clsx'
|
||||
import { useRating } from './useRating'
|
||||
@ -45,7 +46,14 @@ export const RatingField = ({
|
||||
)
|
||||
|
||||
return (
|
||||
<span onClick={(e) => stopPropagation(e)}>
|
||||
<span
|
||||
onClick={(e) => stopPropagation(e)}
|
||||
title={
|
||||
isDateSet(record.ratedAt)
|
||||
? new Date(record.ratedAt).toLocaleString()
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<Rating
|
||||
name={record.mediaFileId || record.id}
|
||||
className={clsx(
|
||||
|
||||
@ -10,3 +10,16 @@ export const urlValidate = (value) => {
|
||||
return 'ra.validation.url'
|
||||
}
|
||||
}
|
||||
|
||||
export function isDateSet(date) {
|
||||
if (!date) {
|
||||
return false
|
||||
}
|
||||
if (typeof date === 'string') {
|
||||
return date !== '0001-01-01T00:00:00Z'
|
||||
}
|
||||
if (date instanceof Date) {
|
||||
return date.toISOString() !== '0001-01-01T00:00:00Z'
|
||||
}
|
||||
return !!date
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user