Skip to content

Commit f3f2d1c

Browse files
committed
Add users and apps inner search and add HeaderMenu cancel
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
1 parent 8ab2d5a commit f3f2d1c

4 files changed

Lines changed: 61 additions & 28 deletions

File tree

apps/settings/src/components/UserList.vue

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,16 @@
241241
</template>
242242

243243
<script>
244-
import userRow from './UserList/UserRow'
245-
import { Multiselect, Actions, ActionButton } from '@nextcloud/vue'
244+
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
246245
import InfiniteLoading from 'vue-infinite-loading'
247246
import Vue from 'vue'
248247
248+
import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
249+
import Actions from '@nextcloud/vue/dist/Components/Actions'
250+
import ActionButton from '@nextcloud/vue/dist/Components/ActionButton'
251+
252+
import userRow from './UserList/UserRow'
253+
249254
const unlimitedQuota = {
250255
id: 'none',
251256
label: t('settings', 'Unlimited'),
@@ -407,6 +412,7 @@ export default {
407412
}
408413
},
409414
},
415+
410416
mounted() {
411417
if (!this.settings.canChangePassword) {
412418
OC.Notification.showTemporary(t('settings', 'Password change is disabled because the master key is disabled'))
@@ -420,13 +426,19 @@ export default {
420426
/**
421427
* Register search
422428
*/
423-
this.userSearch = new OCA.Search(this.search, this.resetSearch)
429+
subscribe('nextcloud:unified-search:search', this.search)
430+
subscribe('nextcloud:unified-search:reset', this.resetSearch)
424431
425432
/**
426433
* If disabled group but empty, redirect
427434
*/
428435
this.redirectIfDisabled()
429436
},
437+
beforeDestroy() {
438+
unsubscribe('nextcloud:unified-search:search', this.search)
439+
unsubscribe('nextcloud:unified-search:reset', this.resetSearch)
440+
},
441+
430442
methods: {
431443
onScroll(event) {
432444
this.scrolled = event.target.scrollTo > 0
@@ -465,13 +477,13 @@ export default {
465477
},
466478
467479
/* SEARCH */
468-
search(query) {
480+
search({ query }) {
469481
this.searchQuery = query
470482
this.$store.commit('resetUsers')
471483
this.$refs.infiniteLoading.stateChanger.reset()
472484
},
473485
resetSearch() {
474-
this.search('')
486+
this.search({ query: '' })
475487
},
476488
477489
resetForm() {

apps/settings/src/views/Apps.vue

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@
141141
</template>
142142

143143
<script>
144+
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
145+
import Vue from 'vue'
146+
import VueLocalStorage from 'vue-localstorage'
147+
144148
import AppContent from '@nextcloud/vue/dist/Components/AppContent'
145149
import AppNavigation from '@nextcloud/vue/dist/Components/AppNavigation'
146150
import AppNavigationCounter from '@nextcloud/vue/dist/Components/AppNavigationCounter'
@@ -149,8 +153,6 @@ import AppNavigationSpacer from '@nextcloud/vue/dist/Components/AppNavigationSpa
149153
import AppSidebar from '@nextcloud/vue/dist/Components/AppSidebar'
150154
import AppSidebarTab from '@nextcloud/vue/dist/Components/AppSidebarTab'
151155
import Content from '@nextcloud/vue/dist/Components/Content'
152-
import Vue from 'vue'
153-
import VueLocalStorage from 'vue-localstorage'
154156
155157
import AppList from '../components/AppList'
156158
import AppDetails from '../components/AppDetails'
@@ -276,20 +278,24 @@ export default {
276278
this.$store.dispatch('getGroups', { offset: 0, limit: 5 })
277279
this.$store.commit('setUpdateCount', this.$store.getters.getServerData.updateCount)
278280
},
281+
279282
mounted() {
280-
/**
281-
* Register search
282-
*/
283-
this.appSearch = new OCA.Search(this.setSearch, this.resetSearch)
283+
subscribe('nextcloud:unified-search:search', this.setSearch)
284+
subscribe('nextcloud:unified-search:reset', this.resetSearch)
285+
},
286+
beforeDestroy() {
287+
unsubscribe('nextcloud:unified-search:search', this.setSearch)
288+
unsubscribe('nextcloud:unified-search:reset', this.resetSearch)
284289
},
285290
286291
methods: {
287-
setSearch(query) {
292+
setSearch({ query }) {
288293
this.searchQuery = query
289294
},
290295
resetSearch() {
291-
this.setSearch('')
296+
this.searchQuery = ''
292297
},
298+
293299
hideAppDetails() {
294300
this.$router.push({
295301
name: 'apps-category',

core/src/components/HeaderMenu.vue

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
<script>
4545
import { directive as ClickOutside } from 'v-click-outside'
46-
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
4746
import excludeClickOutsideClasses from '@nextcloud/vue/dist/Mixins/excludeClickOutsideClasses'
4847
4948
export default {
@@ -94,15 +93,8 @@ export default {
9493
mounted() {
9594
document.addEventListener('keydown', this.onKeyDown)
9695
},
97-
98-
beforeMount() {
99-
subscribe(`header-menu-${this.id}-close`, this.closeMenu)
100-
subscribe(`header-menu-${this.id}-open`, this.openMenu)
101-
},
102-
10396
beforeDestroy() {
104-
unsubscribe(`header-menu-${this.id}-close`, this.closeMenu)
105-
unsubscribe(`header-menu-${this.id}-open`, this.openMenu)
97+
document.removeEventListener('keydown', this.onKeyDown)
10698
},
10799
108100
methods: {
@@ -129,7 +121,6 @@ export default {
129121
this.opened = false
130122
this.$emit('close')
131123
this.$emit('update:open', false)
132-
emit(`header-menu-${this.id}-close`)
133124
},
134125
135126
/**
@@ -143,14 +134,19 @@ export default {
143134
this.opened = true
144135
this.$emit('open')
145136
this.$emit('update:open', true)
146-
emit(`header-menu-${this.id}-open`)
147137
},
148138
149139
onKeyDown(event) {
150140
// If opened and escape pressed, close
151141
if (event.key === 'Escape' && this.opened) {
152142
event.preventDefault()
153-
this.closeMenu()
143+
144+
/** user cancelled the menu by pressing escape */
145+
this.$emit('cancel')
146+
147+
/** we do NOT fire a close event to differentiate cancel and close */
148+
this.opened = false
149+
this.$emit('update:open', false)
154150
}
155151
},
156152
},

core/src/views/UnifiedSearch.vue

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
type="search"
4040
:placeholder="t('core', 'Search {types} …', { types: typesNames.join(', ').toLowerCase() })"
4141
@input="onInputDebounced"
42-
@keypress.enter.prevent.stop="onInputEnter">
42+
@keypress.enter.prevent.stop="onInputEnter"
43+
@search="onSearch">
4344
<!-- Search filters -->
4445
<Actions v-if="availableFilters.length > 1" class="unified-search__filters" placement="bottom">
4546
<ActionButton v-for="type in availableFilters"
@@ -288,11 +289,17 @@ export default {
288289
this.types = await getTypes()
289290
},
290291
onClose() {
291-
this.resetState()
292-
this.query = ''
293292
emit('nextcloud:unified-search:close')
294293
},
295294
295+
/**
296+
* Reset the search state
297+
*/
298+
resetSearch() {
299+
emit('nextcloud:unified-search:reset')
300+
this.query = ''
301+
this.resetState()
302+
},
296303
resetState() {
297304
this.cursors = {}
298305
this.limits = {}
@@ -312,6 +319,18 @@ export default {
312319
})
313320
},
314321
322+
/**
323+
* Watch the search event on the input
324+
* Used to detect the reset button press
325+
* @param {Event} event the search event
326+
*/
327+
onSearch(event) {
328+
// If value is empty, the reset button has been pressed
329+
if (event.target.value === '') {
330+
this.resetSearch()
331+
}
332+
},
333+
315334
/**
316335
* If we have results already, open first one
317336
* If not, trigger the search again

0 commit comments

Comments
 (0)