|
1 | 1 | <template> |
2 | | - <NcAppNavigationSettings :open="true"> |
3 | | - <div id="app-settings"> |
| 2 | + <NcAppSettingsDialog |
| 3 | + :open.sync="isOpen" |
| 4 | + :title="t('cookbook', 'Cookbook settings')" |
| 5 | + :show-navigation="true" |
| 6 | + first-selected-section="keyboard shortcuts" |
| 7 | + > |
| 8 | + <NcAppSettingsSection |
| 9 | + id="settings-recipe-folder" |
| 10 | + :title="t('cookbook', 'Recipe folder')" |
| 11 | + class="app-settings-section" |
| 12 | + > |
4 | 13 | <fieldset> |
5 | 14 | <ul> |
6 | 15 | <li> |
7 | | - <NcActionButton |
8 | | - class="button" |
9 | | - :icon=" |
10 | | - scanningLibrary |
11 | | - ? 'icon-loading-small' |
12 | | - : 'icon-history' |
13 | | - " |
14 | | - :title="t('cookbook', 'Rescan library')" |
15 | | - @click="$emit('reindex')" |
16 | | - /> |
| 16 | + <NcButton @click="reindex"> |
| 17 | + <template #icon> |
| 18 | + <LoadingIcon v-if="scanningLibrary" /> |
| 19 | + <ReloadIcon v-else /> |
| 20 | + </template> |
| 21 | + {{ t("cookbook", "Rescan library") }} |
| 22 | + </NcButton> |
17 | 23 | </li> |
18 | 24 | <li> |
19 | 25 | <label class="settings-input">{{ |
|
37 | 43 | placeholder="0" |
38 | 44 | /> |
39 | 45 | </li> |
| 46 | + </ul> |
| 47 | + </fieldset> |
| 48 | + </NcAppSettingsSection> |
| 49 | + <NcAppSettingsSection |
| 50 | + id="settings-recipe-display" |
| 51 | + :title="t('cookbook', 'Recipe display settings')" |
| 52 | + class="app-settings-section" |
| 53 | + > |
| 54 | + <fieldset> |
| 55 | + <ul> |
40 | 56 | <li> |
41 | 57 | <input |
42 | 58 | id="recipe-print-image" |
|
64 | 80 | </li> |
65 | 81 | </ul> |
66 | 82 | </fieldset> |
67 | | - </div> |
68 | | - </NcAppNavigationSettings> |
| 83 | + </NcAppSettingsSection> |
| 84 | + </NcAppSettingsDialog> |
69 | 85 | </template> |
70 | 86 |
|
71 | 87 | <script> |
72 | | -import NcActionButton from "@nextcloud/vue/dist/Components/NcActionButton" |
73 | | -import NcAppNavigationSettings from "@nextcloud/vue/dist/Components/NcAppNavigationSettings" |
| 88 | +import { subscribe, unsubscribe } from "@nextcloud/event-bus" |
| 89 | +
|
| 90 | +import NcAppSettingsDialog from "@nextcloud/vue/dist/Components/NcAppSettingsDialog" |
| 91 | +import NcAppSettingsSection from "@nextcloud/vue/dist/Components/NcAppSettingsSection" |
| 92 | +import NcButton from "@nextcloud/vue/dist/Components/NcButton" |
| 93 | +import LoadingIcon from "icons/Loading.vue" |
| 94 | +import ReloadIcon from "icons/Cached.vue" |
74 | 95 |
|
75 | 96 | import api from "cookbook/js/api-interface" |
76 | 97 | import { showSimpleAlertModal } from "cookbook/js/modals" |
77 | 98 |
|
| 99 | +export const SHOW_SETTINGS_EVENT = "show-settings" |
| 100 | +
|
78 | 101 | export default { |
79 | | - name: "AppSettings", |
| 102 | + name: "SettingsDialog", |
80 | 103 | components: { |
81 | | - NcActionButton, |
82 | | - NcAppNavigationSettings, |
83 | | - }, |
84 | | - props: { |
85 | | - scanningLibrary: { |
86 | | - type: Boolean, |
87 | | - default: false, |
88 | | - }, |
| 104 | + NcButton, |
| 105 | + NcAppSettingsDialog, |
| 106 | + NcAppSettingsSection, |
| 107 | + LoadingIcon, |
| 108 | + ReloadIcon, |
89 | 109 | }, |
90 | 110 | data() { |
91 | 111 | return { |
| 112 | + isOpen: false, |
92 | 113 | printImage: false, |
93 | 114 | recipeFolder: "", |
94 | 115 | resetPrintImage: true, |
95 | 116 | showTagCloudInRecipeList: true, |
96 | 117 | resetTagCloud: true, |
| 118 | + scanningLibrary: false, |
97 | 119 | // By setting the reset value initially to true, it will skip one watch event |
98 | 120 | // (the one when config is loaded at page load) |
99 | 121 | resetInterval: true, |
@@ -150,8 +172,14 @@ export default { |
150 | 172 | }, |
151 | 173 | mounted() { |
152 | 174 | this.setup() |
| 175 | +
|
| 176 | + subscribe(SHOW_SETTINGS_EVENT, this.handleShowSettings) |
153 | 177 | }, |
154 | 178 | methods: { |
| 179 | + handleShowSettings() { |
| 180 | + this.isOpen = true |
| 181 | + }, |
| 182 | +
|
155 | 183 | /** |
156 | 184 | * Select a recipe folder using the Nextcloud file picker |
157 | 185 | */ |
@@ -209,27 +237,72 @@ export default { |
209 | 237 | ) |
210 | 238 | } |
211 | 239 | }, |
| 240 | +
|
| 241 | + /** |
| 242 | + * Reindex all recipes |
| 243 | + */ |
| 244 | + reindex() { |
| 245 | + const $this = this |
| 246 | + if (this.scanningLibrary) { |
| 247 | + // No repeat clicks until we're done |
| 248 | + return |
| 249 | + } |
| 250 | + this.scanningLibrary = true |
| 251 | + api.recipes |
| 252 | + .reindex() |
| 253 | + .then(() => { |
| 254 | + $this.scanningLibrary = false |
| 255 | + // eslint-disable-next-line no-console |
| 256 | + console.log("Library reindexing complete") |
| 257 | + if ( |
| 258 | + ["index", "search"].indexOf(this.$store.state.page) > -1 |
| 259 | + ) { |
| 260 | + // This refreshes the current router view in case items in it changed during reindex |
| 261 | + $this.$router.go() |
| 262 | + } else { |
| 263 | + $this.getCategories() |
| 264 | + } |
| 265 | + }) |
| 266 | + .catch(() => { |
| 267 | + $this.scanningLibrary = false |
| 268 | + // eslint-disable-next-line no-console |
| 269 | + console.log("Library reindexing failed!") |
| 270 | + }) |
| 271 | + }, |
| 272 | +
|
| 273 | + beforeDestroy() { |
| 274 | + unsubscribe(SHOW_SETTINGS_EVENT, this.handleShowSettings) |
| 275 | + }, |
212 | 276 | }, |
213 | 277 | } |
214 | 278 | </script> |
215 | 279 |
|
| 280 | +<style scoped> |
| 281 | +/* TODO: Use @nextcloud/vue LoadingIcon once we update to 7.0.0 and we won't |
| 282 | + * have to do this */ |
| 283 | +.material-design-icon.loading-icon:deep(svg) { |
| 284 | + animation: rotate var(--animation-duration, 0.8s) linear infinite; |
| 285 | + color: var(--color-loading-dark); |
| 286 | +} |
| 287 | +</style> |
| 288 | + |
216 | 289 | <style> |
217 | 290 | #app-settings input[type="text"], |
218 | 291 | #app-settings input[type="number"], |
219 | | -#app-settings .button { |
| 292 | +#app-settings .button.disable { |
220 | 293 | display: block; |
221 | 294 | width: 100%; |
222 | 295 | } |
223 | 296 |
|
224 | | -#app-settings .button { |
225 | | - z-index: 2; |
226 | | - height: 44px; |
227 | | - padding: 0; |
228 | | - border-radius: var(--border-radius); |
229 | | -} |
| 297 | +/* #app-settings .button { */ |
| 298 | +/* z-index: 2; */ |
| 299 | +/* height: 44px; */ |
| 300 | +/* padding: 0; */ |
| 301 | +/* border-radius: var(--border-radius); */ |
| 302 | +/* } */ |
230 | 303 |
|
231 | | -#app-settings .button p { |
232 | | - margin: auto; |
233 | | - font-size: 13px; |
234 | | -} |
| 304 | +/* #app-settings .button p { */ |
| 305 | +/* margin: auto; */ |
| 306 | +/* font-size: 13px; */ |
| 307 | +/* } */ |
235 | 308 | </style> |
0 commit comments