koel/resources/assets/js/components/main-wrapper/main-content/settings.vue

119 lines
2.9 KiB
Vue
Raw Normal View History

2015-12-13 04:42:28 +00:00
<template>
2016-06-25 16:05:24 +00:00
<section id="settingsWrapper">
<h1 class="heading">
<span>Settings</span>
</h1>
2015-12-13 04:42:28 +00:00
<form @submit.prevent="confirmThenSave" class="main-scroll-wrap">
2016-06-25 16:05:24 +00:00
<div class="form-row">
<label for="inputSettingsPath">Media Path</label>
<p class="help">
The <em>absolute</em> path to the server directory containing your media.
Koel will scan this directory for songs and extract any available information.<br>
Scanning may take a while, especially if you have a lot of songs, so be patient.
</p>
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
<input type="text" v-model="state.settings.media_path" id="inputSettingsPath">
</div>
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
<div class="form-row">
<button type="submit">Scan</button>
</div>
</form>
</section>
2015-12-13 04:42:28 +00:00
</template>
<script>
2016-08-11 02:55:54 +00:00
import swal from 'sweetalert';
import { settingStore, sharedStore } from '../../../stores';
2016-06-25 16:05:24 +00:00
import { parseValidationError, forceReloadWindow, event, showOverlay, hideOverlay } from '../../../utils';
2016-07-10 17:55:20 +00:00
import router from '../../../router';
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
export default {
data() {
return {
state: settingStore.state,
sharedState: sharedStore.state,
2016-06-25 16:05:24 +00:00
};
},
2015-12-13 04:42:28 +00:00
computed: {
/**
* Determine if we should warn the user upon saving.
2016-09-23 10:03:33 +00:00
*
* @return {boolean}
*/
shouldWarn() {
// Warn the user if the media path is not empty and about to change.
return this.sharedState.originalMediaPath &&
this.sharedState.originalMediaPath !== this.state.settings.media_path.trim();
},
2016-08-11 02:55:54 +00:00
},
2016-06-25 16:05:24 +00:00
methods: {
confirmThenSave() {
if (this.shouldWarn) {
swal({
title: 'Be careful!',
text: 'Changing the media path will essentially remove all existing data songs, artists, \
albums, favorites, everything and empty your playlists!',
type: 'warning',
showCancelButton: true,
confirmButtonText: 'I know. Go ahead.',
confirmButtonColor: '#c34848',
}, this.save);
} else {
this.save();
}
},
2016-06-25 16:05:24 +00:00
/**
* Save the settings.
*/
save() {
showOverlay();
settingStore.update().then(() => {
// Make sure we're back to home first.
router.go('home');
forceReloadWindow();
}).catch(r => {
let msg = 'Unknown error.';
if (r.status === 422) {
msg = parseValidationError(r.responseJSON)[0];
}
hideOverlay();
swal({
title: 'Something went wrong',
text: msg,
type: 'error',
allowOutsideClick: true,
2016-08-11 02:55:54 +00:00
});
2016-06-25 16:05:24 +00:00
});
},
},
};
2015-12-13 04:42:28 +00:00
</script>
<style lang="sass">
2016-06-25 16:05:24 +00:00
@import "../../../../sass/partials/_vars.scss";
@import "../../../../sass/partials/_mixins.scss";
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
#settingsWrapper {
input[type="text"] {
width: 384px;
margin-top: 12px;
}
2015-12-13 04:42:28 +00:00
2016-06-25 16:05:24 +00:00
@media only screen and (max-width : 667px) {
input[type="text"] {
width: 100%;
2015-12-13 04:42:28 +00:00
}
2016-06-25 16:05:24 +00:00
}
}
2015-12-13 04:42:28 +00:00
</style>