Skip to content

Commit

Permalink
Merge pull request #3852 from nextcloud/enh/resources-error
Browse files Browse the repository at this point in the history
  • Loading branch information
Pytal authored Mar 16, 2023
2 parents 4821f4a + 4e9d20f commit 79f7d30
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion l10n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ msgstr ""
msgid "Enter link"
msgstr ""

msgid "Error getting related resources"
msgid "Error getting related resources. Please contact your system administrator if you have any questions."
msgstr ""

msgid "External documentation for {title}"
Expand Down
33 changes: 27 additions & 6 deletions src/components/NcRelatedResourcesPanel/NcRelatedResourcesPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default {
<div v-if="appEnabled && isVisible" class="related-resources">
<div class="related-resources__header">
<h5>{{ headerTranslated }}</h5>
<p>{{ descriptionTranslated }}</p>
<p>{{ description }}</p>
</div>

<NcResource v-for="resource in resources"
Expand All @@ -64,11 +64,11 @@ export default {
<script>
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { showError } from '@nextcloud/dialogs'
import { t } from '../../l10n.js'

import NcResource from './NcResource.vue'

import { t } from '../../l10n.js'

export default {
name: 'NcRelatedResourcesPanel',

Expand Down Expand Up @@ -103,22 +103,33 @@ export default {
},

emits: [
'has-error',
'has-resources',
],

data() {
return {
appEnabled: OC?.appswebroots?.related_resources !== undefined,
headerTranslated: t('Related resources'),
descriptionTranslated: t('Anything shared with the same group of people will show up here'),
loading: false,
error: null,
resources: [],
}
},

computed: {
isVisible() {
return !this.loading && this.resources.length > 0
if (this.loading) {
return false
}
return this.error ?? this.resources.length > 0
},

description() {
if (this.error) {
return t('Error getting related resources. Please contact your system administrator if you have any questions.')
}
return t('Anything shared with the same group of people will show up here')
},

hasResourceInfo() {
Expand Down Expand Up @@ -164,6 +175,14 @@ export default {
fileInfo() {
this.fetchRelatedResources()
},
error(error) {
/**
* Emitted when the error value changes
*
* @type {boolean}
*/
this.$emit('has-error', Boolean(error))
},
resources(resources) {
/**
* Emitted when the resources value changes
Expand All @@ -179,19 +198,21 @@ export default {
},

methods: {
t,
async fetchRelatedResources() {
if (!this.appEnabled || !this.hasResourceInfo) {
return
}

this.loading = true
this.error = null
this.resources = []
try {
const response = await axios.get(this.url)
this.resources = response.data.ocs?.data
} catch (e) {
this.error = e
console.error(e)
showError(t('Error getting related resources'))
} finally {
this.loading = false
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/NcRelatedResourcesPanel/NcResource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<script>
import NcButton from '../NcButton/index.js'
import Tooltip from '../../directives/Tooltip/index.js'

import { t } from '../../l10n.js'

export default {
Expand Down Expand Up @@ -80,6 +81,10 @@ export default {
labelTranslated: t('Open link to "{resourceTitle}"', { resourceTitle: this.title }),
}
},

methods: {
t,
},
}
</script>

Expand Down

0 comments on commit 79f7d30

Please sign in to comment.