MOBILE-4081 forum: Display selectors if loading discussions fail
parent
f230c16b94
commit
6b0fbbeaa5
|
@ -639,6 +639,8 @@
|
|||
"addon.mod_forum.erroremptysubject": "forum",
|
||||
"addon.mod_forum.errorgetforum": "local_moodlemobileapp",
|
||||
"addon.mod_forum.errorgetgroups": "local_moodlemobileapp",
|
||||
"addon.mod_forum.errorloadingsortingorder": "local_moodlemobileapp",
|
||||
"addon.mod_forum.errorloadingsortingorderdetails": "local_moodlemobileapp",
|
||||
"addon.mod_forum.errorposttoallgroups": "local_moodlemobileapp",
|
||||
"addon.mod_forum.favourites": "forum",
|
||||
"addon.mod_forum.favouriteupdated": "forum",
|
||||
|
|
|
@ -44,6 +44,7 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource
|
|||
groupInfo?: CoreGroupInfo;
|
||||
allPartsPermissions?: AddonModForumCanAddDiscussion;
|
||||
canAddDiscussionToGroup = true;
|
||||
errorLoadingDiscussions = false;
|
||||
|
||||
constructor(courseId: number, cmId: number, discussionsPathPrefix: string) {
|
||||
super();
|
||||
|
@ -222,13 +223,27 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource
|
|||
throw new Error('Can\'t load discussions without a forum or selected sort order');
|
||||
}
|
||||
|
||||
const response = await AddonModForum.getDiscussions(this.forum.id, {
|
||||
cmId: this.forum.cmid,
|
||||
sortOrder: this.selectedSortOrder.value,
|
||||
page,
|
||||
groupId: this.groupId,
|
||||
});
|
||||
let discussions = response.discussions;
|
||||
let discussions: AddonModForumDiscussion[] = [];
|
||||
let canLoadMore = false;
|
||||
try {
|
||||
const response = await AddonModForum.getDiscussions(this.forum.id, {
|
||||
cmId: this.forum.cmid,
|
||||
sortOrder: this.selectedSortOrder.value,
|
||||
page,
|
||||
groupId: this.groupId,
|
||||
});
|
||||
|
||||
discussions = response.discussions;
|
||||
canLoadMore = response.canLoadMore;
|
||||
this.errorLoadingDiscussions = false;
|
||||
} catch (error) {
|
||||
if (page > 0 || CoreUtils.isWebServiceError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Error loading first discussions, use an empty list.
|
||||
this.errorLoadingDiscussions = true;
|
||||
}
|
||||
|
||||
if (this.usesGroups) {
|
||||
discussions = await AddonModForum.formatDiscussionsGroups(this.forum.cmid, discussions);
|
||||
|
@ -254,7 +269,7 @@ export class AddonModForumDiscussionsSource extends CoreRoutedItemsManagerSource
|
|||
}
|
||||
}
|
||||
|
||||
return { discussions, canLoadMore: response.canLoadMore };
|
||||
return { discussions, canLoadMore };
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -54,17 +54,22 @@
|
|||
</ion-card>
|
||||
|
||||
<ng-container *ngIf="forum">
|
||||
<core-empty-box *ngIf="!discussions || !discussions.hasDiscussions" icon="far-comments"
|
||||
[message]="'addon.mod_forum.forumnodiscussionsyet' | translate">
|
||||
</core-empty-box>
|
||||
|
||||
<div *ngIf="discussions?.hasDiscussions && sortingAvailable && selectedSortOrder" class="ion-text-wrap">
|
||||
<div *ngIf="discussions && sortingAvailable && selectedSortOrder" class="ion-text-wrap">
|
||||
<core-combobox [modalOptions]="sortOrderSelectorModalOptions" listboxId="addon-mod-forum-sort-selector"
|
||||
[label]="('core.sort' | translate)" (onChange)="setSortOrder($event)" [selection]="selectedSortOrder.label | translate"
|
||||
interface="modal">
|
||||
</core-combobox>
|
||||
</div>
|
||||
|
||||
<core-empty-box *ngIf="!discussions || (!discussions.hasDiscussions && !errorLoadingDiscussions)" icon="far-comments"
|
||||
[message]="'addon.mod_forum.forumnodiscussionsyet' | translate">
|
||||
</core-empty-box>
|
||||
|
||||
<core-empty-box *ngIf="errorLoadingDiscussions" icon="fas-exclamation-triangle"
|
||||
[message]="'addon.mod_forum.errorloadingsortingorder' | translate">
|
||||
<p>{{ 'addon.mod_forum.errorloadingsortingorderdetails' | translate }}</p>
|
||||
</core-empty-box>
|
||||
|
||||
<ion-item *ngFor="let discussion of discussionsItems" class="addon-mod-forum-discussion" detail="true"
|
||||
[lines]="discussion.groupname && 'none'" [attr.aria-current]="discussions?.getItemAriaCurrent(discussion)"
|
||||
(click)="discussions?.select(discussion)" button>
|
||||
|
|
|
@ -152,6 +152,10 @@ export class AddonModForumIndexComponent extends CoreCourseModuleMainActivityCom
|
|||
return !!(this.forum && this.canAddDiscussion && this.discussions?.getSource().canAddDiscussionToGroup);
|
||||
}
|
||||
|
||||
get errorLoadingDiscussions(): boolean {
|
||||
return !!this.discussions?.getSource().errorLoadingDiscussions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a discussion is online.
|
||||
*
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
"erroremptysubject": "Post subject cannot be empty.",
|
||||
"errorgetforum": "Error getting forum data.",
|
||||
"errorgetgroups": "Error getting group settings.",
|
||||
"errorloadingsortingorder": "Forum not available in this sorting order",
|
||||
"errorloadingsortingorderdetails": "Try changing the sorting order or going online to view this forum.",
|
||||
"errorposttoallgroups": "Could not create new discussion in all groups.",
|
||||
"favourites": "Starred",
|
||||
"favouriteupdated": "Your star option has been updated.",
|
||||
|
|
Loading…
Reference in New Issue