Skip to content

Commit

Permalink
Add an app configuration
Browse files Browse the repository at this point in the history
Fixes nextcloud#1067

Move the AppNavigationSettings from the sidebar to a AppSettingsDialog
modal that covers the screen.

Signed-off-by: Marcel Robitaille <mail@marcelrobitaille.me>
  • Loading branch information
MarcelRobitaille committed Nov 1, 2022
1 parent 1a97322 commit 66dd071
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 76 deletions.
3 changes: 3 additions & 0 deletions src/components/AppMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/>
</NcAppContent>
<dialogs-wrapper></dialogs-wrapper>
<SettingsDialog />
</NcContent>
</template>

Expand All @@ -26,13 +27,15 @@ import NcContent from "@nextcloud/vue/dist/Components/NcContent"
import AppControls from "cookbook/components/AppControls/AppControls.vue"
import { emit, subscribe, unsubscribe } from "@nextcloud/event-bus"
import AppNavi from "./AppNavi.vue"
import SettingsDialog from "./SettingsDialog.vue"
export default {
name: "AppMain",
components: {
NcAppContent,
AppControls,
AppNavi,
SettingsDialog,
// eslint-disable-next-line vue/no-reserved-component-names
NcContent,
},
Expand Down
51 changes: 11 additions & 40 deletions src/components/AppNavi.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@
</template>

<template slot="footer">
<AppSettings
:scanning-library="scanningLibrary"
@reindex="reindex"
<AppNavigationNew
:text="t('cookbook', 'Cookbook settings')"
:button-class="['create', 'icon-settings']"
@click="handleOpenSettings"
/>
</template>
</NcAppNavigation>
</template>

<script>
import { emit } from "@nextcloud/event-bus"
import NcActionInput from "@nextcloud/vue/dist/Components/NcActionInput"
import NcAppNavigation from "@nextcloud/vue/dist/Components/NcAppNavigation"
import NcAppNavigationItem from "@nextcloud/vue/dist/Components/NcAppNavigationItem"
Expand All @@ -96,7 +99,7 @@ import api from "cookbook/js/api-interface"
import helpers from "cookbook/js/helper"
import { showSimpleAlertModal } from "cookbook/js/modals"
import AppSettings from "./AppSettings.vue"
import { SHOW_SETTINGS_EVENT } from "./SettingsDialog.vue"
import AppNavigationCaption from "./AppNavigationCaption.vue"
export default {
Expand All @@ -107,7 +110,6 @@ export default {
NcAppNavigationItem,
NcAppNavigationNew,
NcCounterBubble,
AppSettings,
AppNavigationCaption,
PlusIcon,
},
Expand All @@ -118,7 +120,6 @@ export default {
downloading: false,
isCategoryUpdating: [],
loading: { categories: true },
scanningLibrary: false,
uncatRecipes: 0,
}
},
Expand Down Expand Up @@ -344,40 +345,6 @@ export default {
}
},
/**
* Reindex all recipes
*/
reindex() {
this.$log.debug("Calling reindex")
const $this = this
if (this.scanningLibrary) {
// No repeat clicks until we're done
return
}
this.scanningLibrary = true
api.recipes
.reindex()
.then(() => {
$this.scanningLibrary = false
// eslint-disable-next-line no-console
console.log("Library reindexing complete")
if (
["index", "search"].indexOf(this.$store.state.page) > -1
) {
// This refreshes the current router view in case items in it changed during reindex
$this.$router.go()
} else {
this.$log.debug("Calling getCategories from reindex")
$this.getCategories()
}
})
.catch(() => {
$this.scanningLibrary = false
// eslint-disable-next-line no-console
console.log("Library reindexing failed!")
})
},
/**
* Set loading recipe index to show the loading icon
*/
Expand All @@ -393,6 +360,10 @@ export default {
isVisible: !this.$store.state.appNavigation.visible,
})
},
handleOpenSettings() {
emit(SHOW_SETTINGS_EVENT)
},
},
}
</script>
Expand Down
141 changes: 105 additions & 36 deletions src/components/AppSettings.vue → src/components/SettingsDialog.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<template>
<NcAppNavigationSettings :open="true">
<div id="app-settings">
<NcAppSettingsDialog
:open.sync="isOpen"
:title="t('cookbook', 'Cookbook settings')"
:show-navigation="true"
first-selected-section="keyboard shortcuts"
>
<NcAppSettingsSection
:title="t('cookbook', 'Recipe folder')"
class="app-settings-section"
>
<fieldset>
<ul>
<li>
<NcActionButton
class="button"
:icon="
scanningLibrary
? 'icon-loading-small'
: 'icon-history'
"
:title="t('cookbook', 'Rescan library')"
@click="$emit('reindex')"
/>
<NcButton @click="$emit('reindex')">
<template #icon>
<LoadingIcon v-if="scanningLibrary" />
<ReloadIcon v-else />
</template>
{{ t("cookbook", "Rescan library") }}
</NcButton>
</li>
<li>
<label class="settings-input">{{
Expand All @@ -37,6 +42,15 @@
placeholder="0"
/>
</li>
</ul>
</fieldset>
</NcAppSettingsSection>
<NcAppSettingsSection
:title="t('cookbook', 'Recipe display settings')"
class="app-settings-section"
>
<fieldset>
<ul>
<li>
<input
id="recipe-print-image"
Expand Down Expand Up @@ -64,36 +78,42 @@
</li>
</ul>
</fieldset>
</div>
</NcAppNavigationSettings>
</NcAppSettingsSection>
</NcAppSettingsDialog>
</template>

<script>
import NcActionButton from "@nextcloud/vue/dist/Components/NcActionButton"
import NcAppNavigationSettings from "@nextcloud/vue/dist/Components/NcAppNavigationSettings"
import { subscribe, unsubscribe } from "@nextcloud/event-bus"
import NcAppSettingsDialog from "@nextcloud/vue/dist/Components/NcAppSettingsDialog"
import NcAppSettingsSection from "@nextcloud/vue/dist/Components/NcAppSettingsSection"
import NcButton from "@nextcloud/vue/dist/Components/NcButton"
import LoadingIcon from "icons/Loading.vue"
import ReloadIcon from "icons/Cached.vue"
import api from "cookbook/js/api-interface"
import { showSimpleAlertModal } from "cookbook/js/modals"
export const SHOW_SETTINGS_EVENT = "show-settings"
export default {
name: "AppSettings",
name: "SettingsDialog",
components: {
NcActionButton,
NcAppNavigationSettings,
},
props: {
scanningLibrary: {
type: Boolean,
default: false,
},
NcButton,
NcAppSettingsDialog,
NcAppSettingsSection,
LoadingIcon,
ReloadIcon,
},
data() {
return {
isOpen: false,
printImage: false,
recipeFolder: "",
resetPrintImage: true,
showTagCloudInRecipeList: true,
resetTagCloud: true,
scanningLibrary: false,
// By setting the reset value initially to true, it will skip one watch event
// (the one when config is loaded at page load)
resetInterval: true,
Expand Down Expand Up @@ -150,8 +170,14 @@ export default {
},
mounted() {
this.setup()
subscribe(SHOW_SETTINGS_EVENT, this.handleShowSettings)
},
methods: {
handleShowSettings() {
this.isOpen = true
},
/**
* Select a recipe folder using the Nextcloud file picker
*/
Expand Down Expand Up @@ -209,27 +235,70 @@ export default {
)
}
},
/**
* Reindex all recipes
*/
reindex() {
const $this = this
if (this.scanningLibrary) {
// No repeat clicks until we're done
return
}
this.scanningLibrary = true
api.recipes
.reindex()
.then(() => {
$this.scanningLibrary = false
// eslint-disable-next-line no-console
console.log("Library reindexing complete")
if (
["index", "search"].indexOf(this.$store.state.page) > -1
) {
// This refreshes the current router view in case items in it changed during reindex
$this.$router.go()
} else {
$this.getCategories()
}
})
.catch(() => {
$this.scanningLibrary = false
// eslint-disable-next-line no-console
console.log("Library reindexing failed!")
})
},
beforeDestroy() {
unsubscribe(SHOW_SETTINGS_EVENT, this.handleShowSettings)
},
},
}
</script>

<style scoped>
.material-design-icon.loading-icon ::v-deep svg {
animation: rotate var(--animation-duration, 0.8s) linear infinite;
color: var(--color-loading-dark);
}
</style>

<style>
#app-settings input[type="text"],
#app-settings input[type="number"],
#app-settings .button {
#app-settings .button.disable {
display: block;
width: 100%;
}
#app-settings .button {
z-index: 2;
height: 44px;
padding: 0;
border-radius: var(--border-radius);
}
/* #app-settings .button { */
/* z-index: 2; */
/* height: 44px; */
/* padding: 0; */
/* border-radius: var(--border-radius); */
/* } */
#app-settings .button p {
margin: auto;
font-size: 13px;
}
/* #app-settings .button p { */
/* margin: auto; */
/* font-size: 13px; */
/* } */
</style>

0 comments on commit 66dd071

Please sign in to comment.