added playlist_references
This commit is contained in:
parent
2b0b094cf1
commit
c50a666a4d
@ -73,6 +73,7 @@ def playlist():
|
|||||||
|
|
||||||
playlist_name = request_json['name']
|
playlist_name = request_json['name']
|
||||||
playlist_parts = request_json.get('parts', None)
|
playlist_parts = request_json.get('parts', None)
|
||||||
|
playlist_references = request_json.get('playlist_references', None)
|
||||||
playlist_id = request_json.get('id', None)
|
playlist_id = request_json.get('id', None)
|
||||||
playlist_shuffle = request_json.get('shuffle', None)
|
playlist_shuffle = request_json.get('shuffle', None)
|
||||||
playlist_type = request_json.get('type', None)
|
playlist_type = request_json.get('type', None)
|
||||||
@ -92,7 +93,8 @@ def playlist():
|
|||||||
|
|
||||||
to_add = {
|
to_add = {
|
||||||
'name': playlist_name,
|
'name': playlist_name,
|
||||||
'parts': playlist_parts,
|
'parts': playlist_parts if not None else [],
|
||||||
|
'playlist_references': playlist_references if not None else [],
|
||||||
'playlist_id': None,
|
'playlist_id': None,
|
||||||
'shuffle': playlist_shuffle,
|
'shuffle': playlist_shuffle,
|
||||||
'type': playlist_type
|
'type': playlist_type
|
||||||
@ -118,6 +120,7 @@ def playlist():
|
|||||||
return jsonify({'error': "multiple playlists exist"}), 500
|
return jsonify({'error': "multiple playlists exist"}), 500
|
||||||
|
|
||||||
if playlist_parts is None and \
|
if playlist_parts is None and \
|
||||||
|
playlist_references is None and \
|
||||||
playlist_id is None and \
|
playlist_id is None and \
|
||||||
playlist_shuffle is None and \
|
playlist_shuffle is None and \
|
||||||
playlist_day_boundary is None:
|
playlist_day_boundary is None:
|
||||||
@ -133,6 +136,12 @@ def playlist():
|
|||||||
else:
|
else:
|
||||||
dic['parts'] = playlist_parts
|
dic['parts'] = playlist_parts
|
||||||
|
|
||||||
|
if playlist_references is not None:
|
||||||
|
if playlist_references == -1:
|
||||||
|
dic['playlist_references'] = []
|
||||||
|
else:
|
||||||
|
dic['playlist_references'] = playlist_references
|
||||||
|
|
||||||
if playlist_id:
|
if playlist_id:
|
||||||
dic['playlist_id'] = playlist_id
|
dic['playlist_id'] = playlist_id
|
||||||
|
|
||||||
@ -336,7 +345,7 @@ def execute_user(username):
|
|||||||
database.get_user_playlists_collection(database.get_user_query_stream(username)[0].id).stream()]
|
database.get_user_playlists_collection(database.get_user_query_stream(username)[0].id).stream()]
|
||||||
|
|
||||||
for iterate_playlist in playlists:
|
for iterate_playlist in playlists:
|
||||||
if len(iterate_playlist['parts']) > 0:
|
if len(iterate_playlist['parts']) > 0 or len(iterate_playlist['playlist_references']) > 0:
|
||||||
if iterate_playlist.get('playlist_id'):
|
if iterate_playlist.get('playlist_id'):
|
||||||
execute_playlist(username, iterate_playlist['name'])
|
execute_playlist(username, iterate_playlist['name'])
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ class NewPlaylist extends Component {
|
|||||||
axios.put('/api/playlist', {
|
axios.put('/api/playlist', {
|
||||||
name: this.state.name,
|
name: this.state.name,
|
||||||
parts: [],
|
parts: [],
|
||||||
|
playlist_references: [],
|
||||||
shuffle: false,
|
shuffle: false,
|
||||||
type: this.state.type,
|
type: this.state.type,
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
|
@ -8,18 +8,22 @@ class PlaylistView extends Component{
|
|||||||
this.state = {
|
this.state = {
|
||||||
name: this.props.match.params.name,
|
name: this.props.match.params.name,
|
||||||
parts: [],
|
parts: [],
|
||||||
|
playlist_references: [],
|
||||||
type: null,
|
type: null,
|
||||||
error: false,
|
error: false,
|
||||||
error_text: null,
|
error_text: null,
|
||||||
|
|
||||||
day_boundary: '',
|
day_boundary: '',
|
||||||
newPlaylistName: '',
|
newPlaylistName: '',
|
||||||
|
newPlaylistReference: '',
|
||||||
|
|
||||||
shuffle: false
|
shuffle: false
|
||||||
}
|
}
|
||||||
this.handleAddPart = this.handleAddPart.bind(this);
|
this.handleAddPart = this.handleAddPart.bind(this);
|
||||||
|
this.handleAddReference = this.handleAddReference.bind(this);
|
||||||
this.handleInputChange = this.handleInputChange.bind(this);
|
this.handleInputChange = this.handleInputChange.bind(this);
|
||||||
this.handleRemoveRow = this.handleRemoveRow.bind(this);
|
this.handleRemoveRow = this.handleRemoveRow.bind(this);
|
||||||
|
this.handleRemoveRefRow = this.handleRemoveRefRow.bind(this);
|
||||||
|
|
||||||
this.handleRun = this.handleRun.bind(this);
|
this.handleRun = this.handleRun.bind(this);
|
||||||
|
|
||||||
@ -74,18 +78,61 @@ class PlaylistView extends Component{
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleAddPart(event){
|
handleAddPart(event){
|
||||||
var parts = this.state.parts;
|
|
||||||
parts.push(this.state.newPlaylistName);
|
var check = this.state.parts.filter((e) => {
|
||||||
this.setState({
|
return e == event.target.value;
|
||||||
parts: parts,
|
|
||||||
add_part_value: ''
|
|
||||||
});
|
});
|
||||||
axios.post('/api/playlist', {
|
|
||||||
name: this.state.name,
|
if(check.length == 0) {
|
||||||
parts: parts
|
var parts = this.state.parts.slice();
|
||||||
}).catch((error) => {
|
parts.push(this.state.newPlaylistName);
|
||||||
console.log(error);
|
|
||||||
|
parts.sort(function(a, b){
|
||||||
|
if(a < b) { return -1; }
|
||||||
|
if(a > b) { return 1; }
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
parts: parts,
|
||||||
|
newPlaylistName: ''
|
||||||
|
});
|
||||||
|
axios.post('/api/playlist', {
|
||||||
|
name: this.state.name,
|
||||||
|
parts: parts
|
||||||
|
}).catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleAddReference(event){
|
||||||
|
|
||||||
|
var check = this.state.playlist_references.filter((e) => {
|
||||||
|
return e == event.target.value;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(check.length == 0) {
|
||||||
|
var playlist_references = this.state.playlist_references.slice();
|
||||||
|
playlist_references.push(this.state.newPlaylistReference);
|
||||||
|
|
||||||
|
playlist_references.sort(function(a, b){
|
||||||
|
if(a < b) { return -1; }
|
||||||
|
if(a > b) { return 1; }
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
playlist_references: playlist_references,
|
||||||
|
newPlaylistReference: ''
|
||||||
|
});
|
||||||
|
axios.post('/api/playlist', {
|
||||||
|
name: this.state.name,
|
||||||
|
playlist_references: playlist_references
|
||||||
|
}).catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRemoveRow(id, event){
|
handleRemoveRow(id, event){
|
||||||
@ -107,6 +154,25 @@ class PlaylistView extends Component{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleRemoveRefRow(id, event){
|
||||||
|
var playlist_references = this.state.playlist_references;
|
||||||
|
playlist_references = playlist_references.filter(e => e !== id);
|
||||||
|
this.setState({
|
||||||
|
playlist_references: playlist_references
|
||||||
|
});
|
||||||
|
|
||||||
|
if(playlist_references.length == 0) {
|
||||||
|
playlist_references = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
axios.post('/api/playlist', {
|
||||||
|
name: this.state.name,
|
||||||
|
playlist_references: playlist_references
|
||||||
|
}).catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
handleRun(event){
|
handleRun(event){
|
||||||
axios.get('/api/playlist/run', {params: {name: this.state.name}})
|
axios.get('/api/playlist/run', {params: {name: this.state.name}})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -123,8 +189,9 @@ class PlaylistView extends Component{
|
|||||||
<th colSpan="2"><h1 className="text-no-select">{ this.state.name }</h1></th>
|
<th colSpan="2"><h1 className="text-no-select">{ this.state.name }</h1></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
{ this.state.playlist_references.length > 0 && <ListBlock name="managed" handler={this.handleRemoveRefRow} list={this.state.playlist_references}/> }
|
||||||
|
{ this.state.parts.length > 0 && <ListBlock name="spotify" handler={this.handleRemoveRow} list={this.state.parts}/> }
|
||||||
<tbody>
|
<tbody>
|
||||||
{ this.state.parts.map((part) => <Row part={ part } key={ part } handler={this.handleRemoveRow}/>) }
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<input type="text"
|
<input type="text"
|
||||||
@ -132,12 +199,25 @@ class PlaylistView extends Component{
|
|||||||
className="full-width"
|
className="full-width"
|
||||||
value={this.state.newPlaylistName}
|
value={this.state.newPlaylistName}
|
||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
placeholder="new playlist"></input>
|
placeholder="spotify playlist"></input>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<button className="button full-width" onClick={this.handleAddPart}>add</button>
|
<button className="button full-width" onClick={this.handleAddPart}>add</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input type="text"
|
||||||
|
name="newPlaylistReference"
|
||||||
|
className="full-width"
|
||||||
|
value={this.state.newPlaylistReference}
|
||||||
|
onChange={this.handleInputChange}
|
||||||
|
placeholder="managed playlist"></input>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button className="button full-width" onClick={this.handleAddReference}>add</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td className="center-text ui-text text-no-select">
|
<td className="center-text ui-text text-no-select">
|
||||||
shuffle output?
|
shuffle output?
|
||||||
@ -163,7 +243,7 @@ class PlaylistView extends Component{
|
|||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2">
|
<td colSpan="2">
|
||||||
<button className="button full-width" onClick={this.handleRun}>run</button>
|
<button className="button full-width" onClick={this.handleRun}>run</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -178,6 +258,15 @@ class PlaylistView extends Component{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ListBlock(props) {
|
||||||
|
return (
|
||||||
|
<tbody>
|
||||||
|
<tr><td colSpan="2" className="ui-text center-text text-no-select" style={{fontStyle: 'italic'}}>{props.name}</td></tr>
|
||||||
|
{ props.list.map((part) => <Row part={ part } key={ part } handler={props.handler}/>) }
|
||||||
|
</tbody>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function Row (props) {
|
function Row (props) {
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -19,8 +19,17 @@ class PlaylistsView extends Component {
|
|||||||
var self = this;
|
var self = this;
|
||||||
axios.get('/api/playlists')
|
axios.get('/api/playlists')
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|
||||||
|
var playlists = response.data.playlists.slice();
|
||||||
|
|
||||||
|
playlists.sort(function(a, b){
|
||||||
|
if(a.name < b.name) { return -1; }
|
||||||
|
if(a.name > b.name) { return 1; }
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
|
||||||
self.setState({
|
self.setState({
|
||||||
playlists: response.data.playlists,
|
playlists: playlists,
|
||||||
isLoading: false
|
isLoading: false
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user