Skip to content

Commit

Permalink
#51. Partial fix to prevent crashing in studies list
Browse files Browse the repository at this point in the history
  • Loading branch information
dschreij committed Feb 5, 2021
1 parent 432dd1b commit 567ee7a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
10 changes: 1 addition & 9 deletions resources/components/Studies/CurrentStudies/CurrentStudies.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,7 @@ export default {
async loadStudies () {
this.loading = true
try {
const response = await this.Study.fetch()
// Attach studies to local representation of logged in user.
this.User.insertOrUpdate({
where: this.$auth.user.id,
data: {
id: this.$auth.user.id,
studies: response.entities.studies
}
})
await this.Study.fetch()
} catch (e) {
processErrors(e, this.notify)
} finally {
Expand Down
27 changes: 15 additions & 12 deletions resources/components/Studies/StudiesList/StudiesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@
<v-list-item-title v-text="item.name" />
<v-list-item-subtitle v-text="item.description" />
</v-list-item-content>
<v-list-item-action v-if="!userIsOwner(item.id)" class="align-self-center">
<v-tooltip bottom>
<template #activator="{on, attrs}">
<v-icon color="primary" v-bind="attrs" v-on="on">
mdi-share-variant
</v-icon>
</template>
{{ $t('studies.list.shared_by') }} {{ studyOwners[item.id].name }}
</v-tooltip>
</v-list-item-action>
<v-fab-transition>
<v-list-item-action v-show="!userIsOwner(item.id)" class="align-self-center">
<v-tooltip bottom>
<template #activator="{on, attrs}">
<v-icon color="primary" v-bind="attrs" v-on="on">
mdi-share-variant
</v-icon>
</template>
{{ $t('studies.list.shared_by') }} {{
studyOwners[item.id] && studyOwners[item.id].name
}}
</v-tooltip>
</v-list-item-action>
</v-fab-transition>
</v-list-item>
<v-divider />
</template>
Expand Down Expand Up @@ -73,15 +77,14 @@ export default {
computed: {
studyOwners () {
return this.studies.reduce((result, study) => {
console.log(study.id, study.users)
result[study.id] = study?.users.find(user => user.pivot.is_owner)
return result
}, {})
}
},
methods: {
userIsOwner (studyID) {
console.log(this.studyOwners)
if (!this.studyOwners[studyID]) { return true }
return this.$auth.user.id === this.studyOwners[studyID].id
}
}
Expand Down
9 changes: 4 additions & 5 deletions resources/pages/dashboard/studies/_id/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const defaultPagination = {
}
export default {
name: 'Study',
name: 'StudyPage',
components: {
StudyActions,
StudyTitle: () => import('@/components/Studies/page/StudyTitle'),
Expand Down Expand Up @@ -244,10 +244,9 @@ export default {
async fetchStudy (studyID, options) {
try {
await this.Study.fetchById(studyID, {
/* Below breaks the studies list, if studies are shared */
// persistOptions: {
// create: ['users']
// },
persistOptions: {
create: ['users']
},
...options
})
} catch (e) {
Expand Down
6 changes: 6 additions & 0 deletions resources/pages/dashboard/studies/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@
</v-row>
</v-container>
</template>

<script>
export default {
name: 'StudyDefaultPage'
}
</script>

0 comments on commit 567ee7a

Please sign in to comment.