diff --git a/spotify/__init__.py b/spotify/__init__.py index 47073c8..715a525 100644 --- a/spotify/__init__.py +++ b/spotify/__init__.py @@ -7,14 +7,13 @@ logger = logging.getLogger(__name__) logger.setLevel('DEBUG') if os.environ.get('DEPLOY_DESTINATION', None) == 'PROD': - from google.cloud.logging.handlers import CloudLoggingHandler from google.cloud import logging as glogging log_format = '%(funcName)s - %(message)s' formatter = logging.Formatter(log_format) client = glogging.Client() - handler = CloudLoggingHandler(client, name='playlist-manager') + handler = client.get_default_handler() handler.setFormatter(formatter) diff --git a/src/js/Playlist/PlaylistView.js b/src/js/Playlist/PlaylistView.js index 0f86f17..e9edd66 100644 --- a/src/js/Playlist/PlaylistView.js +++ b/src/js/Playlist/PlaylistView.js @@ -3,6 +3,36 @@ const axios = require('axios'); import showMessage from "../Toast.js" +var thisMonth = [ + 'january', + 'february', + 'march', + 'april', + 'may', + 'june', + 'july', + 'august', + 'septempber', + 'october', + 'november', + 'december' +]; + +var lastMonth = [ + 'december', + 'january', + 'february', + 'march', + 'april', + 'may', + 'june', + 'july', + 'august', + 'septempber', + 'october', + 'november' +]; + class PlaylistView extends Component{ constructor(props){ @@ -18,21 +48,25 @@ class PlaylistView extends Component{ day_boundary: '', recommendation_sample: '', newPlaylistName: '', - newPlaylistReference: '', + newReferenceName: '', shuffle: false, - include_recommendations: false + include_recommendations: false, + add_this_month: false, + add_last_month: false } this.handleAddPart = this.handleAddPart.bind(this); this.handleAddReference = this.handleAddReference.bind(this); this.handleInputChange = this.handleInputChange.bind(this); - this.handleRemoveRow = this.handleRemoveRow.bind(this); - this.handleRemoveRefRow = this.handleRemoveRefRow.bind(this); + this.handleRemovePart = this.handleRemovePart.bind(this); + this.handleRemoveReference = this.handleRemoveReference.bind(this); this.handleRun = this.handleRun.bind(this); this.handleShuffleChange = this.handleShuffleChange.bind(this); - this.handleRecChange = this.handleRecChange.bind(this); + this.handleIncludeRecommendationsChange = this.handleIncludeRecommendationsChange.bind(this); + this.handleThisMonthChange = this.handleThisMonthChange.bind(this); + this.handleLastMonthChange = this.handleLastMonthChange.bind(this); } componentDidMount(){ @@ -56,7 +90,7 @@ class PlaylistView extends Component{ this.setState(info.data); this.setState({ playlists: playlists.data.playlists, - newPlaylistReference: filteredPlaylists.length > 0 ? filteredPlaylists[0].name : '' + newReferenceName: filteredPlaylists.length > 0 ? filteredPlaylists[0].name : '' }); })) .catch((error) => { @@ -82,7 +116,7 @@ class PlaylistView extends Component{ this.handleDayBoundaryChange(event.target.value); } if(event.target.name == 'recommendation_sample'){ - this.handleRecSampleChange(event.target.value); + this.handleRecommendationsSampleChange(event.target.value); } if(event.target.name == 'type'){ this.handleTypeChange(event.target.value); @@ -90,6 +124,12 @@ class PlaylistView extends Component{ } handleDayBoundaryChange(boundary) { + if(boundary == ''){ + boundary = 0; + this.setState({ + day_boundary: 0 + }); + } axios.post('/api/playlist', { name: this.state.name, day_boundary: parseInt(boundary) @@ -98,7 +138,13 @@ class PlaylistView extends Component{ }); } - handleRecSampleChange(sample){ + handleRecommendationsSampleChange(sample){ + if(sample == ''){ + sample = 0; + this.setState({ + recommendation_sample: 0 + }); + } axios.post('/api/playlist', { name: this.state.name, recommendation_sample: parseInt(sample) @@ -128,7 +174,31 @@ class PlaylistView extends Component{ }); } - handleRecChange(event) { + handleThisMonthChange(event) { + this.setState({ + add_this_month: event.target.checked + }); + axios.post('/api/playlist', { + name: this.state.name, + add_this_month: event.target.checked + }).catch((error) => { + showMessage(`error updating add this month (${error.response.status})`); + }); + } + + handleLastMonthChange(event) { + this.setState({ + add_last_month: event.target.checked + }); + axios.post('/api/playlist', { + name: this.state.name, + add_last_month: event.target.checked + }).catch((error) => { + showMessage(`error updating add last month (${error.response.status})`); + }); + } + + handleIncludeRecommendationsChange(event) { this.setState({ include_recommendations: event.target.checked }); @@ -177,13 +247,13 @@ class PlaylistView extends Component{ handleAddReference(event){ - if(this.state.newPlaylistReference.length != 0){ + if(this.state.newReferenceName.length != 0){ - var check = this.state.playlist_references.includes(this.state.newPlaylistReference); + var check = this.state.playlist_references.includes(this.state.newReferenceName); if(check == false) { var playlist_references = this.state.playlist_references.slice(); - playlist_references.push(this.state.newPlaylistReference); + playlist_references.push(this.state.newReferenceName); playlist_references.sort(function(a, b){ if(a < b) { return -1; } @@ -195,7 +265,7 @@ class PlaylistView extends Component{ this.setState({ playlist_references: playlist_references, - newPlaylistReference: filteredPlaylists.length > 0 ? filteredPlaylists[0].name : '' + newReferenceName: filteredPlaylists.length > 0 ? filteredPlaylists[0].name : '' }); axios.post('/api/playlist', { name: this.state.name, @@ -213,7 +283,7 @@ class PlaylistView extends Component{ } } - handleRemoveRow(id, event){ + handleRemovePart(id, event){ var parts = this.state.parts; parts = parts.filter(e => e !== id); this.setState({ @@ -232,7 +302,7 @@ class PlaylistView extends Component{ }); } - handleRemoveRefRow(id, event){ + handleRemoveReference(id, event){ var playlist_references = this.state.playlist_references; playlist_references = playlist_references.filter(e => e !== id); this.setState({ @@ -276,6 +346,8 @@ class PlaylistView extends Component{ render(){ + var date = new Date(); + const table = (
{ this.state.name } |
- { this.state.playlist_references.length > 0 && |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -306,9 +378,9 @@ class PlaylistView extends Component{ | |||||||||||||||
- | |||||||||||||||
+ include {thisMonth[date.getMonth()]} playlist + | ++ + | +||||||||||||||
+ include {lastMonth[date.getMonth()]} playlist + | ++ + | +||||||||||||||
playlist type @@ -379,15 +475,6 @@ class PlaylistView extends Component{ | |||||||||||||||
- 'recents' playlists search for and include this months and last months playlists when named in the format - [month] [year] - e.g july 19 (lowercase) - |
- |||||||||||||||
diff --git a/src/js/Playlist/ScratchView.js b/src/js/Playlist/ScratchView.js
index 532860e..09f33a8 100644
--- a/src/js/Playlist/ScratchView.js
+++ b/src/js/Playlist/ScratchView.js
@@ -3,6 +3,36 @@ const axios = require('axios');
import showMessage from "../Toast.js"
+var thisMonth = [
+ 'january',
+ 'february',
+ 'march',
+ 'april',
+ 'may',
+ 'june',
+ 'july',
+ 'august',
+ 'septempber',
+ 'october',
+ 'november',
+ 'december'
+];
+
+var lastMonth = [
+ 'december',
+ 'january',
+ 'february',
+ 'march',
+ 'april',
+ 'may',
+ 'june',
+ 'july',
+ 'august',
+ 'septempber',
+ 'october',
+ 'november'
+];
+
class ScratchView extends Component{
constructor(props){
@@ -18,21 +48,25 @@ class ScratchView extends Component{
day_boundary: 5,
recommendation_sample: 5,
newPlaylistName: '',
- newPlaylistReference: '',
+ newReferenceName: '',
shuffle: false,
- include_recommendations: false
+ include_recommendations: false,
+ add_this_month: false,
+ add_last_month: false
}
this.handleAddPart = this.handleAddPart.bind(this);
this.handleAddReference = this.handleAddReference.bind(this);
this.handleInputChange = this.handleInputChange.bind(this);
- this.handleRemoveRow = this.handleRemoveRow.bind(this);
- this.handleRemoveRefRow = this.handleRemoveRefRow.bind(this);
+ this.handleRemovePart = this.handleRemovePart.bind(this);
+ this.handleRemoveReference = this.handleRemoveReference.bind(this);
this.handleRun = this.handleRun.bind(this);
this.handleShuffleChange = this.handleShuffleChange.bind(this);
- this.handleRecChange = this.handleRecChange.bind(this);
+ this.handleIncludeRecommendationsChange = this.handleIncludeRecommendationsChange.bind(this);
+ this.handleThisMonthChange = this.handleThisMonthChange.bind(this);
+ this.handleLastMonthChange = this.handleLastMonthChange.bind(this);
}
componentDidMount(){
@@ -48,7 +82,7 @@ class ScratchView extends Component{
this.setState({
playlists: response.data.playlists,
- newPlaylistReference: filteredPlaylists.length > 0 ? filteredPlaylists[0].name : ''
+ newReferenceName: filteredPlaylists.length > 0 ? filteredPlaylists[0].name : ''
});
})
.catch((error) => {
@@ -62,22 +96,25 @@ class ScratchView extends Component{
});
}
- handleTypeChange(sample){
- axios.post('/api/playlist', {
- name: this.state.name,
- type: sample
- }).catch((error) => {
- showMessage(`error updating type (${error.response.status})`);
- });
- }
-
handleShuffleChange(event) {
this.setState({
shuffle: event.target.checked
});
}
- handleRecChange(event) {
+ handleThisMonthChange(event) {
+ this.setState({
+ add_this_month: event.target.checked
+ });
+ }
+
+ handleLastMonthChange(event) {
+ this.setState({
+ add_last_month: event.target.checked
+ });
+ }
+
+ handleIncludeRecommendationsChange(event) {
this.setState({
include_recommendations: event.target.checked
});
@@ -114,13 +151,13 @@ class ScratchView extends Component{
handleAddReference(event){
- if(this.state.newPlaylistReference.length != 0){
+ if(this.state.newReferenceName.length != 0){
- var check = this.state.playlist_references.includes(this.state.newPlaylistReference);
+ var check = this.state.playlist_references.includes(this.state.newReferenceName);
if(check == false) {
var playlist_references = this.state.playlist_references.slice();
- playlist_references.push(this.state.newPlaylistReference);
+ playlist_references.push(this.state.newReferenceName);
playlist_references.sort(function(a, b){
if(a < b) { return -1; }
@@ -132,7 +169,7 @@ class ScratchView extends Component{
this.setState({
playlist_references: playlist_references,
- newPlaylistReference: filteredPlaylists.length > 0 ? filteredPlaylists[0].name : ''
+ newReferenceName: filteredPlaylists.length > 0 ? filteredPlaylists[0].name : ''
});
}else{
@@ -144,7 +181,7 @@ class ScratchView extends Component{
}
}
- handleRemoveRow(id, event){
+ handleRemovePart(id, event){
var parts = this.state.parts;
parts = parts.filter(e => e !== id);
this.setState({
@@ -156,7 +193,7 @@ class ScratchView extends Component{
}
}
- handleRemoveRefRow(id, event){
+ handleRemoveReference(id, event){
var playlist_references = this.state.playlist_references;
playlist_references = playlist_references.filter(e => e !== id);
this.setState({
@@ -176,7 +213,9 @@ class ScratchView extends Component{
include_recommendations: this.state.include_recommendations,
recommendation_sample: this.state.recommendation_sample,
day_boundary: this.state.day_boundary,
- playlist_type: this.state.type
+ playlist_type: this.state.type,
+ add_this_month: this.state.add_this_month,
+ add_last_month: this.state.add_last_month
})
.then((reponse) => {
showMessage(`played`);
@@ -197,6 +236,8 @@ class ScratchView extends Component{
render(){
+ var date = new Date();
+
const table = (
|