diff --git a/core/src/logger.js b/core/src/logger.js index 4a9c8623a7..bd01f58a41 100644 --- a/core/src/logger.js +++ b/core/src/logger.js @@ -1,4 +1,4 @@ -/* +/** * @copyright 2019 Christoph Wurst * * @author 2019 Christoph Wurst diff --git a/core/src/login.js b/core/src/login.js index bfcfabf169..a7d738ee9e 100644 --- a/core/src/login.js +++ b/core/src/login.js @@ -1,4 +1,4 @@ -/* +/** * @copyright 2019 Christoph Wurst * * @author 2019 Christoph Wurst diff --git a/core/src/maintenance.js b/core/src/maintenance.js index de4315d32a..3abc20ea8f 100644 --- a/core/src/maintenance.js +++ b/core/src/maintenance.js @@ -1,4 +1,4 @@ -/* +/** * @copyright 2019 Christoph Wurst * * @author 2019 Christoph Wurst diff --git a/core/src/recommendedapps.js b/core/src/recommendedapps.js index aea105a842..ef9071eb42 100644 --- a/core/src/recommendedapps.js +++ b/core/src/recommendedapps.js @@ -1,4 +1,4 @@ -/* +/** * @copyright 2019 Christoph Wurst * * @author 2019 Christoph Wurst diff --git a/core/src/session-heartbeat.js b/core/src/session-heartbeat.js index aab30c2c4c..9902bef882 100644 --- a/core/src/session-heartbeat.js +++ b/core/src/session-heartbeat.js @@ -1,4 +1,4 @@ -/* +/** * @copyright 2019 Christoph Wurst * * @author 2019 Christoph Wurst diff --git a/core/src/unified-search.js b/core/src/unified-search.js index ba975d7856..0d97738358 100644 --- a/core/src/unified-search.js +++ b/core/src/unified-search.js @@ -19,8 +19,9 @@ * along with this program. If not, see . */ -import { getRequestToken } from '@nextcloud/auth' import { generateFilePath } from '@nextcloud/router' +import { getLoggerBuilder } from '@nextcloud/logger' +import { getRequestToken } from '@nextcloud/auth' import { translate as t, translatePlural as n } from '@nextcloud/l10n' import Vue from 'vue' @@ -32,7 +33,17 @@ __webpack_nonce__ = btoa(getRequestToken()) // eslint-disable-next-line camelcase __webpack_public_path__ = generateFilePath('core', '', 'js/') +const logger = getLoggerBuilder() + .setApp('unified-search') + .detectUser() + .build() + Vue.mixin({ + data() { + return { + logger, + } + }, methods: { t, n, diff --git a/core/src/views/UnifiedSearch.vue b/core/src/views/UnifiedSearch.vue index c721689537..b68051de90 100644 --- a/core/src/views/UnifiedSearch.vue +++ b/core/src/views/UnifiedSearch.vue @@ -57,7 +57,7 @@ - + {{ t('core', 'No results for {query}', {query}) }} @@ -116,6 +116,7 @@ import Magnify from 'vue-material-design-icons/Magnify' import HeaderMenu from '../components/HeaderMenu' import SearchResult from '../components/UnifiedSearch/SearchResult' import SearchResultPlaceholders from '../components/UnifiedSearch/SearchResultPlaceholders' +import { showError } from '@nextcloud/dialogs' export default { name: 'UnifiedSearch', @@ -255,7 +256,7 @@ export default { async created() { this.types = await getTypes() - console.debug('Unified Search initialized with the following providers', this.types) + this.logger.debug('Unified Search initialized with the following providers', this.types) }, mounted() { @@ -372,42 +373,49 @@ export default { // Remove any filters from the query query = query.replace(regexFilterIn, '').replace(regexFilterNot, '') - console.debug('Searching', query, 'in', types) + this.logger.debug(`Searching ${query} in`, types) // Reset search if the query changed this.resetState() types.forEach(async type => { - this.$set(this.loading, type, true) - const request = await search(type, query) + try { + this.$set(this.loading, type, true) + const request = await search(type, query) + + // Process results + if (request.data.ocs.data.entries.length > 0) { + this.$set(this.results, type, request.data.ocs.data.entries) + } else { + this.$delete(this.results, type) + } + + // Save cursor if any + if (request.data.ocs.data.cursor) { + this.$set(this.cursors, type, request.data.ocs.data.cursor) + } else if (!request.data.ocs.data.isPaginated) { + // If no cursor and no pagination, we save the default amount + // provided by server's initial state `defaultLimit` + this.$set(this.limits, type, this.defaultLimit) + } + + // Check if we reached end of pagination + if (request.data.ocs.data.entries.length < this.defaultLimit) { + this.$set(this.reached, type, true) + } + + // If none already focused, focus the first rendered result + if (this.focused === null) { + this.focused = 0 + } + } catch (error) { + this.logger.error(`Error searching for ${this.typesMap[type]}`, error) + showError(this.t('core', 'An error occurred while looking for {type}', { type: this.typesMap[type] })) - // Process results - if (request.data.ocs.data.entries.length > 0) { - this.$set(this.results, type, request.data.ocs.data.entries) - } else { this.$delete(this.results, type) + } finally { + this.$set(this.loading, type, false) } - - // Save cursor if any - if (request.data.ocs.data.cursor) { - this.$set(this.cursors, type, request.data.ocs.data.cursor) - } else if (!request.data.ocs.data.isPaginated) { - // If no cursor and no pagination, we save the default amount - // provided by server's initial state `defaultLimit` - this.$set(this.limits, type, this.defaultLimit) - } - - // Check if we reached end of pagination - if (request.data.ocs.data.entries.length < this.defaultLimit) { - this.$set(this.reached, type, true) - } - - // If none already focused, focus the first rendered result - if (this.focused === null) { - this.focused = 0 - } - - this.$set(this.loading, type, false) }) }, onInputDebounced: debounce(function(e) {