MOBILE-2486 forum: Invalidate discussion when a rating is updated

main
Albert Gasset 2019-03-05 10:59:02 +01:00
parent f6c2babd77
commit 8fe3e09e9b
3 changed files with 15 additions and 3 deletions

View File

@ -23,7 +23,7 @@
</ng-container>
</div>
</ion-card-content>
<core-rating-rate *ngIf="forum && ratingInfo" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="componentId" [itemId]="post.id" [itemSetId]="discussionId" [courseId]="courseId" [aggregateMethod]="forum.assessed" [scaleId]="forum.scale" [userId]="post.userid"></core-rating-rate>
<core-rating-rate *ngIf="forum && ratingInfo" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="componentId" [itemId]="post.id" [itemSetId]="discussionId" [courseId]="courseId" [aggregateMethod]="forum.assessed" [scaleId]="forum.scale" [userId]="post.userid" (onUpdate)="ratingUpdated()"></core-rating-rate>
<core-rating-aggregate *ngIf="forum && ratingInfo" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="componentId" [itemId]="post.id" [courseId]="courseId" [aggregateMethod]="forum.assessed" [scaleId]="forum.scale"></core-rating-aggregate>
<ion-item no-padding text-end *ngIf="post.id && post.canreply" class="addon-forum-reply-button">
<button ion-button icon-left clear small (click)="showReply()" [attr.aria-controls]="'addon-forum-reply-edit-form-' + uniqueId" [attr.aria-expanded]="replyData.replyingTo === post.id">

View File

@ -307,6 +307,13 @@ export class AddonModForumPostComponent implements OnInit, OnDestroy {
});
}
/**
* Function called when rating is updated online.
*/
ratingUpdated(): void {
this.forumProvider.invalidateDiscussionPosts(this.discussionId);
}
/**
* Component being destroyed.
*/

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component, Input, OnChanges, SimpleChange } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChange } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { CoreRatingProvider, CoreRatingInfo, CoreRatingInfoItem, CoreRatingScale } from '@core/rating/providers/rating';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
@ -35,13 +35,16 @@ export class CoreRatingRateComponent implements OnChanges {
@Input() aggregateMethod: number;
@Input() scaleId: number;
@Input() userId: number;
@Output() onUpdate: EventEmitter<void>; // Event emitted when the rating is updated online.
item: CoreRatingInfoItem;
scale: CoreRatingScale;
rating: number;
constructor(private domUtils: CoreDomUtilsProvider, private translate: TranslateService,
private ratingProvider: CoreRatingProvider, private ratingOffline: CoreRatingOfflineProvider) {}
private ratingProvider: CoreRatingProvider, private ratingOffline: CoreRatingOfflineProvider) {
this.onUpdate = new EventEmitter<void>();
}
/**
* Detect changes on input properties.
@ -96,6 +99,8 @@ export class CoreRatingRateComponent implements OnChanges {
.then((response) => {
if (response == null) {
this.domUtils.showToast('core.datastoredoffline', true, 3000);
} else {
this.onUpdate.emit();
}
}).catch((error) => {
this.domUtils.showErrorModal(error);