Basically completed compilation feature

This commit is contained in:
An Phan 2016-05-19 23:21:27 +08:00
parent 22b228f338
commit fd0defc059
5 changed files with 33 additions and 26 deletions

View file

@ -21,7 +21,6 @@ class Album extends Model
protected $guarded = ['id'];
protected $hidden = ['created_at', 'updated_at'];
protected $casts = ['is_compilation' => 'bool'];
public function artist()
{
@ -57,7 +56,6 @@ class Album extends Model
return self::firstOrCreate([
'artist_id' => $artist->id,
'name' => $name ?: self::UNKNOWN_NAME,
'is_compilation' => $isCompilation,
]);
}
@ -112,20 +110,6 @@ class Album extends Model
$this->writeCoverFile($cover['data'], $extension);
}
/**
* Set album as a compilation (or not).
*
* @param bool $state
*
* @return self
*/
public function setCompilationState($state)
{
$this->save(['is_compilation' => $state]);
return $this;
}
/**
* Write a cover image file with binary data and update the Album with the new cover file.
*

View file

@ -261,6 +261,15 @@
this.$broadcast('koel:teardown');
});
},
/**
* Force reloading window regardless of "Confirm before reload" setting.
* This is handy for certain cases, for example Last.fm connect/disconnect.
*/
forceReloadWindow() {
window.onbeforeunload = function() {};
window.location.reload();
},
},
events: {

View file

@ -182,7 +182,7 @@
// - Nope. Users should be grown-ass adults who take responsibilty of their actions.
// But one of my users is my new born kid!
// - Then? Kids will fuck things up anyway.
http.delete('lastfm/disconnect', {}, () => window.location.reload());
http.delete('lastfm/disconnect', {}, () => this.$root.forceReloadWindow());
},
},
};

View file

@ -46,9 +46,12 @@
</div>
<div class="form-row">
<label class="small">
<input type="checkbox" @change="setCompilationState" v-el:compilation-state-chk />
<input type="checkbox" @change="changeCompilationState" v-el:compilation-state-chk />
Album is a compilation of songs by various artists
</label>
<label class="small warning" v-if="needsReload">
Koel will reload after saving.
</label>
</div>
<div class="form-row" v-show="editSingle">
<label>Track</label>
@ -98,6 +101,7 @@
songs: [],
currentView: '',
loading: false,
needsReload: false,
artistState: artistStore.state,
artistTypeaheadOptions: {
@ -216,6 +220,7 @@
this.shown = true;
this.songs = songs;
this.currentView = 'details';
this.needsReload = false;
if (this.editSingle) {
this.formData.title = this.songs[0].title;
@ -231,25 +236,25 @@
this.loading = false;
this.formData.lyrics = br2nl(this.songs[0].lyrics);
this.formData.track = this.songs[0].track;
this.setAlbumCompilationState();
this.initCompilationStateCheckbox();
});
} else {
this.formData.lyrics = br2nl(this.songs[0].lyrics);
this.formData.track = this.songs[0].track;
this.setAlbumCompilationState();
this.initCompilationStateCheckbox();
}
} else {
this.formData.albumName = this.inSameAlbum ? this.songs[0].album.name : '';
this.formData.artistName = this.bySameArtist ? this.songs[0].artist.name : '';
this.loading = false;
this.setAlbumCompilationState();
this.initCompilationStateCheckbox();
}
},
/**
* Set the compilation state of the editing songs' album(s).
* Initialize the compilation state's checkbox of the editing songs' album(s).
*/
setAlbumCompilationState() {
initCompilationStateCheckbox() {
// This must be wrapped in a $nextTick callback, because the form is dynamically
// attached into DOM in conjunction with `this.loading` data binding.
this.$nextTick(() => {
@ -278,8 +283,9 @@
* Also, following iTunes style, we don't support circular switching of the states -
* once the user clicks the checkbox, there's no going back to indeterminate state.
*/
setCompilationState(e) {
changeCompilationState(e) {
this.formData.compilationState = e.target.checked ? COMPILATION_STATES.ALL : COMPILATION_STATES.NONE;
this.needsReload = true;
},
/**
@ -299,6 +305,9 @@
songStore.update(this.songs, this.formData, () => {
this.loading = false;
this.close();
if (this.needsReload) {
this.$root.forceReloadWindow();
}
}, () => {
this.loading = false;
});
@ -359,6 +368,10 @@
}
}
.warning {
color: #f00;
}
textarea {
min-height: 192px;
}

View file

@ -6,11 +6,12 @@
</head>
<body>
<h3>Perfecto!</h3>
<p>Koel has successfully connected to your Last.fm account and is now restarting for the exciting features.</p>
<p>This window will automatically close in 3 seconds.</p>
<script>
window.opener.onbeforeunload = function () {};
window.opener.location.reload(false);
window.setTimeout(function () {