Skip to content

Commit

Permalink
feat(webui): add server settings configuration screen, add remember-m…
Browse files Browse the repository at this point in the history
…e checkbox for login
  • Loading branch information
gotson committed Sep 25, 2023
1 parent 0364621 commit 505b54c
Show file tree
Hide file tree
Showing 12 changed files with 347 additions and 83 deletions.
7 changes: 7 additions & 0 deletions komga-webui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"collections": "Collections",
"create": "Create",
"delete": "Delete",
"discard": "Discard",
"disk_space": "Disk space",
"dismiss": "Dismiss",
"download": "Download",
Expand Down Expand Up @@ -239,6 +240,7 @@
"read_on": "Read on {date}",
"readlist": "Read List",
"readlists": "Read Lists",
"remember-me": "Remember me",
"required": "Required",
"reset_filters": "Reset filters",
"roles": "Roles",
Expand Down Expand Up @@ -842,6 +844,10 @@
"tab_title": "Server"
},
"server_settings": {
"label_delete_empty_collections": "Delete empty collections after scan",
"label_delete_empty_readlists": "Delete empty read lists after scan",
"label_rememberme_duration": "Remember me duration (in days)",
"requires_restart": "Requires restart to take effect",
"server_settings": "Server Settings"
},
"settings_user": {
Expand Down Expand Up @@ -895,6 +901,7 @@
"users": "Users"
},
"validation": {
"one_or_more": "Must be 1 or more",
"zero_or_more": "Must be 0 or more"
},
"welcome": {
Expand Down
2 changes: 2 additions & 0 deletions komga-webui/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import komgaPageHashes from './plugins/komga-pagehashes.plugin'
import komgaMetrics from './plugins/komga-metrics.plugin'
import komgaHistory from './plugins/komga-history.plugin'
import komgaAnnouncements from './plugins/komga-announcements.plugin'
import komgaSettings from './plugins/komga-settings.plugin'
import vuetify from './plugins/vuetify'
import logger from './plugins/logger.plugin'
import './public-path'
Expand Down Expand Up @@ -74,6 +75,7 @@ Vue.use(komgaPageHashes, {http: Vue.prototype.$http})
Vue.use(komgaMetrics, {http: Vue.prototype.$http})
Vue.use(komgaHistory, {http: Vue.prototype.$http})
Vue.use(komgaAnnouncements, {http: Vue.prototype.$http})
Vue.use(komgaSettings, {http: Vue.prototype.$http})

Vue.config.productionTip = false

Expand Down
17 changes: 17 additions & 0 deletions komga-webui/src/plugins/komga-settings.plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {AxiosInstance} from 'axios'
import _Vue from 'vue'
import KomgaSettingsService from '@/services/komga-settings.service'

export default {
install(
Vue: typeof _Vue,
{http}: { http: AxiosInstance }) {
Vue.prototype.$komgaSettings = new KomgaSettingsService(http)
},
}

declare module 'vue/types/vue' {
interface Vue {
$komgaSettings: KomgaSettingsService;
}
}
8 changes: 6 additions & 2 deletions komga-webui/src/plugins/komga-users.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ const vuexModule: Module<any, any> = {
},
},
actions: {
async getMeWithAuth ({ commit }, { login, password }: { login: string, password: string }) {
commit('setMe', await service.getMeWithAuth(login, password))
async getMeWithAuth({commit}, {login, password, rememberMe}: {
login: string,
password: string,
rememberMe: boolean
}) {
commit('setMe', await service.getMeWithAuth(login, password, rememberMe))
},
async logout ({ commit }) {
try {
Expand Down
4 changes: 4 additions & 0 deletions komga-webui/src/plugins/persisted-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const persistedModule: Module<any, any> = {
},
importPath: '',
duplicatesNewPageSize: 10,
rememberMe: false,
},
getters: {
getLocaleFirstDay: (state) => () => {
Expand Down Expand Up @@ -128,5 +129,8 @@ export const persistedModule: Module<any, any> = {
setDuplicatesNewPageSize(state, val) {
state.duplicatesNewPageSize = val
},
setRememberMe(state, val) {
state.rememberMe = val
},
},
}
36 changes: 36 additions & 0 deletions komga-webui/src/services/komga-settings.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {AxiosInstance} from 'axios'
import {SettingsDto, SettingsUpdateDto} from '@/types/komga-settings'

const API_SETTINGS = '/api/v1/settings'

export default class KomgaSettingsService {
private http: AxiosInstance

constructor(http: AxiosInstance) {
this.http = http
}

async getSettings(): Promise<SettingsDto> {
try {
return (await this.http.get(API_SETTINGS)).data
} catch (e) {
let msg = 'An error occurred while trying to retrieve settings'
if (e.response.data.message) {
msg += `: ${e.response.data.message}`
}
throw new Error(msg)
}
}

async updateSettings(settings: SettingsUpdateDto) {
try {
await this.http.patch(API_SETTINGS, settings)
} catch (e) {
let msg = 'An error occurred while trying to update settings'
if (e.response.data.message) {
msg += `: ${e.response.data.message}`
}
throw new Error(msg)
}
}
}
5 changes: 4 additions & 1 deletion komga-webui/src/services/komga-users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class KomgaUsersService {
this.http = http
}

async getMeWithAuth(login: string, password: string): Promise<UserDto> {
async getMeWithAuth(login: string, password: string, rememberMe: boolean): Promise<UserDto> {
try {
return (await this.http.get(
`${API_USERS}/me`,
Expand All @@ -27,6 +27,9 @@ export default class KomgaUsersService {
username: login,
password: password,
},
params: {
'remember-me': rememberMe,
},
},
)).data
} catch (e) {
Expand Down
12 changes: 12 additions & 0 deletions komga-webui/src/types/komga-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface SettingsDto {
deleteEmptyCollections: boolean,
deleteEmptyReadLists: boolean,
rememberMeDurationDays: number,
}

export interface SettingsUpdateDto {
deleteEmptyCollections?: boolean,
deleteEmptyReadLists?: boolean,
rememberMeDurationDays?: number,
renewRememberMeKey?: boolean,
}
20 changes: 20 additions & 0 deletions komga-webui/src/views/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@
</v-col>
</v-row>

<v-row>
<v-col>
<v-checkbox v-model="rememberMe"
:label="$t('common.remember-me')"
hide-details
class="mt-0"
/>
</v-col>
</v-row>

<v-row>
<v-col cols="auto">
<v-btn color="primary"
Expand Down Expand Up @@ -183,6 +193,15 @@ export default Vue.extend({
},
},
rememberMe: {
get: function (): boolean {
return this.$store.state.persistedState.rememberMe
},
set: function (value: boolean): void {
this.$store.commit('setRememberMe', value)
},
},
themes(): object[] {
return [
{text: this.$i18n.t(Theme.LIGHT), value: Theme.LIGHT},
Expand Down Expand Up @@ -260,6 +279,7 @@ export default Vue.extend({
{
login: this.form.login,
password: this.form.password,
rememberMe: this.rememberMe,
})
await this.$store.dispatch('getLibraries')
Expand Down
101 changes: 101 additions & 0 deletions komga-webui/src/views/ServerManagement.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<template>
<v-container fluid class="pa-6">
<v-row>
<v-col><span class="text-h5">{{ $t('server.server_management.section_title') }}</span></v-col>
</v-row>
<v-row>
<v-col cols="auto">
<v-btn @click="scanAllLibraries(false)">{{ $t('server.server_management.button_scan_libraries') }}</v-btn>
</v-col>
<v-col cols="auto">
<v-btn @click="scanAllLibraries(true)"
color="warning"
>{{ $t('server.server_management.button_scan_libraries_deep') }}
</v-btn>
</v-col>
<v-col cols="auto">
<v-btn @click="confirmEmptyTrash = true">{{ $t('server.server_management.button_empty_trash') }}</v-btn>
</v-col>
<v-col cols="auto">
<v-btn @click="cancelAllTasks"
color="warning"
>{{ $t('server.server_management.button_cancel_all_tasks') }}
</v-btn>
</v-col>
<v-col cols="auto">
<v-btn @click="modalStopServer = true"
color="error"
>{{ $t('server.server_management.button_shutdown') }}
</v-btn>
</v-col>
</v-row>

<confirmation-dialog
v-model="confirmEmptyTrash"
:title="$t('dialog.empty_trash.title')"
:body="$t('dialog.empty_trash.body')"
:button-confirm="$t('dialog.empty_trash.button_confirm')"
@confirm="emptyTrash"
/>

<confirmation-dialog
v-model="modalStopServer"
:title="$t('dialog.server_stop.dialog_title')"
:body="$t('dialog.server_stop.confirmation_message')"
:button-confirm="$t('dialog.server_stop.button_confirm')"
button-confirm-color="error"
@confirm="stopServer"
/>

</v-container>
</template>

<script lang="ts">
import Vue from 'vue'
import ConfirmationDialog from '@/components/dialogs/ConfirmationDialog.vue'
import {ERROR, ErrorEvent, NOTIFICATION, NotificationEvent} from '@/types/events'
import {LibraryDto} from '@/types/komga-libraries'
export default Vue.extend({
name: 'ServerManagement',
components: {ConfirmationDialog},
data: () => ({
modalStopServer: false,
confirmEmptyTrash: false,
}),
computed: {
libraries(): LibraryDto[] {
return this.$store.state.komgaLibraries.libraries
},
},
methods: {
emptyTrash() {
this.libraries.forEach(library => {
this.$komgaLibraries.emptyTrash(library)
})
},
scanAllLibraries(scanDeep: boolean) {
this.libraries.forEach(library => {
this.$komgaLibraries.scanLibrary(library, scanDeep)
})
},
async cancelAllTasks() {
const count = await this.$komgaTasks.deleteAllTasks()
this.$eventHub.$emit(NOTIFICATION, {
message: this.$tc('server.server_management.notification_tasks_cancelled', count),
} as NotificationEvent)
},
async stopServer() {
try {
await this.$actuator.shutdown()
} catch (e) {
this.$eventHub.$emit(ERROR, {message: e.message} as ErrorEvent)
}
},
},
})
</script>

<style scoped>
</style>
Loading

0 comments on commit 505b54c

Please sign in to comment.