AlbumStudio and ArtistEditor Fixes

pull/110/head
Qstick 7 years ago
parent 49309125b6
commit 70cc2ed8a5

@ -4,6 +4,7 @@ import { createSelector } from 'reselect';
import connectSection from 'Store/connectSection';
import createClientSideCollectionSelector from 'Store/Selectors/createClientSideCollectionSelector';
import { setAlbumStudioSort, setAlbumStudioFilter, saveAlbumStudio } from 'Store/Actions/albumStudioActions';
import { fetchEpisodes, clearEpisodes } from 'Store/Actions/episodeActions';
import AlbumStudio from './AlbumStudio';
function createMapStateToProps() {
@ -18,6 +19,8 @@ function createMapStateToProps() {
}
const mapDispatchToProps = {
fetchEpisodes,
clearEpisodes,
setAlbumStudioSort,
setAlbumStudioFilter,
saveAlbumStudio
@ -25,6 +28,28 @@ const mapDispatchToProps = {
class AlbumStudioConnector extends Component {
//
// Lifecycle
componentDidMount() {
this.populate();
}
componentWillUnmount() {
this.unpopulate();
}
//
// Control
populate = () => {
this.props.fetchEpisodes();
}
unpopulate = () => {
this.props.clearEpisodes();
}
//
// Listeners
@ -58,6 +83,8 @@ class AlbumStudioConnector extends Component {
AlbumStudioConnector.propTypes = {
setAlbumStudioSort: PropTypes.func.isRequired,
setAlbumStudioFilter: PropTypes.func.isRequired,
fetchEpisodes: PropTypes.func.isRequired,
clearEpisodes: PropTypes.func.isRequired,
saveAlbumStudio: PropTypes.func.isRequired
};

@ -10,16 +10,22 @@ import AlbumStudioRow from './AlbumStudioRow';
function createMapStateToProps() {
return createSelector(
(state) => state.episodes,
createArtistSelector(),
(artist) => {
return _.pick(artist, [
'status',
'nameSlug',
'artistName',
'monitored',
'albums',
'isSaving'
]);
(episodes, artist) => {
const albumsInArtist = _.filter(episodes.items, { artistId: artist.id });
const sortedAlbums = _.orderBy(albumsInArtist, 'releaseDate', 'desc');
return {
...artist,
artistId: artist.id,
artistName: artist.artistName,
nameSlug: artist.nameSlug,
monitored: artist.monitored,
status: artist.status,
isSaving: artist.isSaving,
albums: sortedAlbums
};
}
);
}
@ -50,7 +56,7 @@ class AlbumStudioRowConnector extends Component {
onAlbumMonitoredPress = (albumId, monitored) => {
this.props.toggleEpisodeMonitored({
albumId,
monitored: !monitored
monitored
});
}

@ -135,7 +135,7 @@ class AlbumRow extends Component {
return (
<TableRowCell key={name}>
{
statistics.trackCount
statistics.totalTrackCount
}
</TableRowCell>
);

@ -66,7 +66,7 @@ class ArtistEditorFooter extends Component {
case 'monitored':
this.props.onSaveSelected({ [name]: value === 'monitored' });
break;
case 'seasonFolder':
case 'albumFolder':
this.props.onSaveSelected({ [name]: value === 'yes' });
break;
default:

@ -16,7 +16,7 @@ class ArtistEditorRow extends Component {
//
// Listeners
onSeasonFolderChange = () => {
onAlbumFolderChange = () => {
// Mock handler to satisfy `onChange` being required for `CheckInput`.
//
}
@ -77,7 +77,7 @@ class ArtistEditorRow extends Component {
name="albumFolder"
value={albumFolder}
isDisabled={true}
onChange={this.onSeasonFolderChange}
onChange={this.onAlbumFolderChange}
/>
</TableRowCell>

@ -71,9 +71,9 @@ export const BULK_DELETE_ARTIST = 'BULK_DELETE_ARTIST';
//
// Season Pass
export const SET_SEASON_PASS_SORT = 'SET_SEASON_PASS_SORT';
export const SET_SEASON_PASS_FILTER = 'SET_SEASON_PASS_FILTER';
export const SAVE_SEASON_PASS = 'SAVE_SEASON_PASS';
export const SET_ALBUM_STUDIO_SORT = 'SET_ALBUM_STUDIO_SORT';
export const SET_ALBUM_STUDIO_FILTER = 'SET_ALBUM_STUDIO_FILTER';
export const SAVE_ALBUM_STUDIO = 'SAVE_ALBUM_STUDIO';
//
// Episodes

@ -8,7 +8,7 @@ import { fetchArtist } from './artistActions';
const section = 'albumStudio';
const albumStudioActionHandlers = {
[types.SAVE_SEASON_PASS]: function(payload) {
[types.SAVE_ALBUM_STUDIO]: function(payload) {
return function(dispatch, getState) {
const {
artistIds,
@ -30,15 +30,15 @@ const albumStudioActionHandlers = {
if (monitor) {
const {
seasons,
albums,
options: artistMonitoringOptions
} = getMonitoringOptions(_.cloneDeep(s.seasons), monitor);
} = getMonitoringOptions(_.cloneDeep(s.albums), monitor);
if (!monitoringOptions) {
monitoringOptions = artistMonitoringOptions;
}
artistToUpdate.seasons = seasons;
artistToUpdate.albums = albums;
}
artist.push(artistToUpdate);

@ -2,6 +2,6 @@ import { createAction } from 'redux-actions';
import * as types from './actionTypes';
import albumStudioActionHandlers from './albumStudioActionHandlers';
export const setAlbumStudioSort = createAction(types.SET_SEASON_PASS_SORT);
export const setAlbumStudioFilter = createAction(types.SET_SEASON_PASS_FILTER);
export const saveAlbumStudio = albumStudioActionHandlers[types.SAVE_SEASON_PASS];
export const setAlbumStudioSort = createAction(types.SET_ALBUM_STUDIO_SORT);
export const setAlbumStudioFilter = createAction(types.SET_ALBUM_STUDIO_FILTER);
export const saveAlbumStudio = albumStudioActionHandlers[types.SAVE_ALBUM_STUDIO];

@ -14,7 +14,7 @@ const episodeActionHandlers = {
[types.TOGGLE_EPISODE_MONITORED]: function(payload) {
return function(dispatch, getState) {
const {
albumId: id,
albumId,
episodeEntity = episodeEntities.EPISODES,
monitored
} = payload;
@ -22,13 +22,13 @@ const episodeActionHandlers = {
const episodeSection = _.last(episodeEntity.split('.'));
dispatch(updateItem({
id,
id: albumId,
section: episodeSection,
isSaving: true
}));
const promise = $.ajax({
url: `/album/${id}`,
url: `/album/${albumId}`,
method: 'PUT',
data: JSON.stringify({ monitored }),
dataType: 'json'
@ -36,7 +36,7 @@ const episodeActionHandlers = {
promise.done((data) => {
dispatch(updateItem({
id,
id: albumId,
section: episodeSection,
isSaving: false,
monitored
@ -45,7 +45,7 @@ const episodeActionHandlers = {
promise.fail((xhr) => {
dispatch(updateItem({
id,
id: albumId,
section: episodeSection,
isSaving: false
}));

@ -31,8 +31,8 @@ const albumStudioReducers = handleActions({
[types.SET]: createSetReducer(reducerSection),
[types.SET_SEASON_PASS_SORT]: createSetClientSideCollectionSortReducer(reducerSection),
[types.SET_SEASON_PASS_FILTER]: createSetClientSideCollectionFilterReducer(reducerSection)
[types.SET_ALBUM_STUDIO_SORT]: createSetClientSideCollectionSortReducer(reducerSection),
[types.SET_ALBUM_STUDIO_FILTER]: createSetClientSideCollectionFilterReducer(reducerSection)
}, defaultState);

@ -10,10 +10,10 @@ function monitorSeasons(seasons, startingSeason) {
});
}
function getMonitoringOptions(seasons, monitor) {
if (!seasons.length) {
function getMonitoringOptions(albums, monitor) {
if (!albums.length) {
return {
seasons: [],
albums: [],
options: {
ignoreEpisodesWithFiles: false,
ignoreEpisodesWithoutFiles: false
@ -21,10 +21,10 @@ function getMonitoringOptions(seasons, monitor) {
};
}
const firstSeason = _.minBy(_.reject(seasons, { seasonNumber: 0 }), 'seasonNumber').seasonNumber;
const lastSeason = _.maxBy(seasons, 'seasonNumber').seasonNumber;
const firstSeason = _.minBy(_.reject(albums, { seasonNumber: 0 }), 'seasonNumber').seasonNumber;
const lastSeason = _.maxBy(albums, 'seasonNumber').seasonNumber;
monitorSeasons(seasons, firstSeason);
monitorSeasons(albums, firstSeason);
const monitoringOptions = {
ignoreEpisodesWithFiles: false,
@ -37,11 +37,11 @@ function getMonitoringOptions(seasons, monitor) {
monitoringOptions.ignoreEpisodesWithoutFiles = true;
break;
case 'latest':
monitorSeasons(seasons, lastSeason);
monitorSeasons(albums, lastSeason);
break;
case 'first':
monitorSeasons(seasons, lastSeason + 1);
_.find(seasons, { seasonNumber: firstSeason }).monitored = true;
monitorSeasons(albums, lastSeason + 1);
_.find(albums, { seasonNumber: firstSeason }).monitored = true;
break;
case 'missing':
monitoringOptions.ignoreEpisodesWithFiles = true;
@ -50,14 +50,14 @@ function getMonitoringOptions(seasons, monitor) {
monitoringOptions.ignoreEpisodesWithoutFiles = true;
break;
case 'none':
monitorSeasons(seasons, lastSeason + 1);
monitorSeasons(albums, lastSeason + 1);
break;
default:
break;
}
return {
seasons: _.map(seasons, (season) => {
seasons: _.map(albums, (season) => {
return _.pick(season, [
'seasonNumber',
'monitored'

@ -32,7 +32,7 @@ namespace Lidarr.Api.V3.Albums
if (!Request.Query.ArtistId.HasValue && !albumIdsQuery.HasValue)
{
throw new BadRequestException("artistId or albumIds must be provided");
return MapToResource(_albumService.GetAllAlbums(), false);
}
if (artistIdQuery.HasValue)

@ -15,7 +15,7 @@ namespace Lidarr.Api.V3.Artist
{
_artistService = artistService;
Put["/"] = artist => SaveAll();
Delete["/"] = artist => DeleteSeries();
Delete["/"] = artist => DeleteArtist();
}
private Response SaveAll()
@ -70,7 +70,7 @@ namespace Lidarr.Api.V3.Artist
.AsResponse(HttpStatusCode.Accepted);
}
private Response DeleteSeries()
private Response DeleteArtist()
{
var resource = Request.Body.FromJson<ArtistEditorResource>();

@ -99,7 +99,7 @@ namespace Lidarr.Api.V3.Artist
var resource = artist.ToResource();
MapCoversToLocal(resource);
MapAlbums(resource);
//MapAlbums(resource);
FetchAndLinkArtistStatistics(resource);
//PopulateAlternateTitles(resource);
@ -112,7 +112,7 @@ namespace Lidarr.Api.V3.Artist
var artistsResources = _artistService.GetAllArtists().ToResource();
MapCoversToLocal(artistsResources.ToArray());
MapAlbums(artistsResources.ToArray());
//MapAlbums(artistsResources.ToArray());
LinkArtistStatistics(artistsResources, artistStats);
//PopulateAlternateTitles(seriesResources);

@ -164,12 +164,28 @@ namespace NzbDrone.Core.Music
var album = _albumRepository.Get(albumId);
_albumRepository.SetMonitoredFlat(album, monitored);
var tracks = _trackService.GetTracksByAlbum(albumId);
foreach (var track in tracks)
{
track.Monitored = monitored;
}
_trackService.UpdateTracks(tracks);
_logger.Debug("Monitored flag for Album:{0} was set to {1}", albumId, monitored);
}
public void SetMonitored(IEnumerable<int> ids, bool monitored)
{
_albumRepository.SetMonitored(ids, monitored);
foreach (var id in ids)
{
var tracks = _trackService.GetTracksByAlbum(id);
foreach (var track in tracks)
{
track.Monitored = monitored;
}
_trackService.UpdateTracks(tracks);
}
}
public List<Album> UpdateAlbums(List<Album> album)

Loading…
Cancel
Save