MOBILE-2975 comments: Allow disable comments

main
Dani Palou 2019-04-26 15:36:43 +02:00
parent 8723e5b684
commit 65c202c998
9 changed files with 77 additions and 10 deletions

View File

@ -29,7 +29,7 @@
</ion-item> </ion-item>
<ion-card-content> <ion-card-content>
<core-format-text [text]="entry.summary" [component]="this.component" [componentId]="entry.id"></core-format-text> <core-format-text [text]="entry.summary" [component]="this.component" [componentId]="entry.id"></core-format-text>
<ion-item> <ion-item *ngIf="commentsEnabled">
<core-comments [component]="this.component" [itemId]="entry.id" area="format_blog" [instanceId]="entry.userid" contextLevel="user"></core-comments> <core-comments [component]="this.component" [itemId]="entry.id" area="format_blog" [instanceId]="entry.userid" contextLevel="user"></core-comments>
</ion-item> </ion-item>
<core-file *ngFor="let file of entry.attachmentfiles" [file]="file" [component]="this.component" [componentId]="entry.id"></core-file> <core-file *ngFor="let file of entry.attachmentfiles" [file]="file" [component]="this.component" [componentId]="entry.id"></core-file>

View File

@ -18,6 +18,7 @@ import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreSitesProvider } from '@providers/sites'; import { CoreSitesProvider } from '@providers/sites';
import { CoreUserProvider } from '@core/user/providers/user'; import { CoreUserProvider } from '@core/user/providers/user';
import { AddonBlogProvider } from '../../providers/blog'; import { AddonBlogProvider } from '../../providers/blog';
import { CoreCommentsProvider } from '@core/comments/providers/comments';
/** /**
* Component that displays the blog entries. * Component that displays the blog entries.
@ -47,9 +48,11 @@ export class AddonBlogEntriesComponent implements OnInit {
showMyIssuesToggle = false; showMyIssuesToggle = false;
onlyMyEntries = false; onlyMyEntries = false;
component = AddonBlogProvider.COMPONENT; component = AddonBlogProvider.COMPONENT;
commentsEnabled: boolean;
constructor(protected blogProvider: AddonBlogProvider, protected domUtils: CoreDomUtilsProvider, constructor(protected blogProvider: AddonBlogProvider, protected domUtils: CoreDomUtilsProvider,
protected userProvider: CoreUserProvider, sitesProvider: CoreSitesProvider) { protected userProvider: CoreUserProvider, sitesProvider: CoreSitesProvider,
protected commentsProvider: CoreCommentsProvider) {
this.currentUserId = sitesProvider.getCurrentSiteUserId(); this.currentUserId = sitesProvider.getCurrentSiteUserId();
} }
@ -81,6 +84,8 @@ export class AddonBlogEntriesComponent implements OnInit {
this.filter['tagid'] = this.tagId; this.filter['tagid'] = this.tagId;
} }
this.commentsEnabled = !this.commentsProvider.areCommentsDisabledInSite();
this.fetchEntries().then(() => { this.fetchEntries().then(() => {
this.blogProvider.logView(this.filter).catch(() => { this.blogProvider.logView(this.filter).catch(() => {
// Ignore errors. // Ignore errors.

View File

@ -1,4 +1,4 @@
<a ion-item text-wrap (click)="showComments()" detail-none> <a *ngIf="commentsEnabled" ion-item text-wrap (click)="showComments()" detail-none>
<h2>{{plugin.name}}</h2> <h2>{{plugin.name}}</h2>
<core-comments contextLevel="module" [instanceId]="assign.cmid" component="assignsubmission_comments" [itemId]="submission.id" area="submission_comments" [title]="plugin.name"></core-comments> <core-comments contextLevel="module" [instanceId]="assign.cmid" component="assignsubmission_comments" [itemId]="submission.id" area="submission_comments" [title]="plugin.name"></core-comments>
</a> </a>

View File

@ -27,8 +27,12 @@ import { AddonModAssignSubmissionPluginComponent } from '../../../classes/submis
export class AddonModAssignSubmissionCommentsComponent extends AddonModAssignSubmissionPluginComponent { export class AddonModAssignSubmissionCommentsComponent extends AddonModAssignSubmissionPluginComponent {
@ViewChild(CoreCommentsCommentsComponent) commentsComponent: CoreCommentsCommentsComponent; @ViewChild(CoreCommentsCommentsComponent) commentsComponent: CoreCommentsCommentsComponent;
commentsEnabled: boolean;
constructor(protected commentsProvider: CoreCommentsProvider) { constructor(protected commentsProvider: CoreCommentsProvider) {
super(); super();
this.commentsEnabled = !commentsProvider.areCommentsDisabledInSite();
} }
/** /**

View File

@ -31,7 +31,7 @@
<core-rating-rate *ngIf="data && entry && ratingInfo && (!data.approval || entry.approved)" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="data.coursemodule" [itemId]="entry.id" [itemSetId]="0" [courseId]="courseId" [aggregateMethod]="data.assessed" [scaleId]="data.scale" [userId]="entry.userid" (onLoading)="setLoadingRating($event)" (onUpdate)="ratingUpdated()"></core-rating-rate> <core-rating-rate *ngIf="data && entry && ratingInfo && (!data.approval || entry.approved)" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="data.coursemodule" [itemId]="entry.id" [itemSetId]="0" [courseId]="courseId" [aggregateMethod]="data.assessed" [scaleId]="data.scale" [userId]="entry.userid" (onLoading)="setLoadingRating($event)" (onUpdate)="ratingUpdated()"></core-rating-rate>
<core-rating-aggregate *ngIf="data && entry && ratingInfo" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="data.coursemodule" [itemId]="entry.id" [courseId]="courseId" [aggregateMethod]="data.assessed" [scaleId]="data.scale"></core-rating-aggregate> <core-rating-aggregate *ngIf="data && entry && ratingInfo" [ratingInfo]="ratingInfo" contextLevel="module" [instanceId]="data.coursemodule" [itemId]="entry.id" [courseId]="courseId" [aggregateMethod]="data.assessed" [scaleId]="data.scale"></core-rating-aggregate>
<ion-item *ngIf="data && entry && entry.id > 0"> <ion-item *ngIf="data && entry && entry.id > 0 && commentsEnabled">
<core-comments contextLevel="module" [instanceId]="data.coursemodule" component="mod_data" [itemId]="entry.id" area="database_entry" [displaySpinner]="false" (onLoading)="setLoadingComments($event)"></core-comments> <core-comments contextLevel="module" [instanceId]="data.coursemodule" component="mod_data" [itemId]="entry.id" area="database_entry" [displaySpinner]="false" (onLoading)="setLoadingComments($event)"></core-comments>
</ion-item> </ion-item>

View File

@ -26,6 +26,7 @@ import { AddonModDataHelperProvider } from '../../providers/helper';
import { AddonModDataSyncProvider } from '../../providers/sync'; import { AddonModDataSyncProvider } from '../../providers/sync';
import { AddonModDataFieldsDelegate } from '../../providers/fields-delegate'; import { AddonModDataFieldsDelegate } from '../../providers/fields-delegate';
import { AddonModDataComponentsModule } from '../../components/components.module'; import { AddonModDataComponentsModule } from '../../components/components.module';
import { CoreCommentsProvider } from '@core/comments/providers/comments';
/** /**
* Page that displays the view entry page. * Page that displays the view entry page.
@ -68,13 +69,14 @@ export class AddonModDataEntryPage implements OnDestroy {
jsData; jsData;
ratingInfo: CoreRatingInfo; ratingInfo: CoreRatingInfo;
isPullingToRefresh = false; // Whether the last fetching of data was started by a pull-to-refresh action isPullingToRefresh = false; // Whether the last fetching of data was started by a pull-to-refresh action
commentsEnabled: boolean;
constructor(params: NavParams, protected utils: CoreUtilsProvider, protected groupsProvider: CoreGroupsProvider, constructor(params: NavParams, protected utils: CoreUtilsProvider, protected groupsProvider: CoreGroupsProvider,
protected domUtils: CoreDomUtilsProvider, protected fieldsDelegate: AddonModDataFieldsDelegate, protected domUtils: CoreDomUtilsProvider, protected fieldsDelegate: AddonModDataFieldsDelegate,
protected courseProvider: CoreCourseProvider, protected dataProvider: AddonModDataProvider, protected courseProvider: CoreCourseProvider, protected dataProvider: AddonModDataProvider,
protected dataHelper: AddonModDataHelperProvider, protected dataHelper: AddonModDataHelperProvider,
sitesProvider: CoreSitesProvider, protected navCtrl: NavController, protected eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider, protected navCtrl: NavController, protected eventsProvider: CoreEventsProvider,
private cdr: ChangeDetectorRef) { private cdr: ChangeDetectorRef, protected commentsProvider: CoreCommentsProvider) {
this.module = params.get('module') || {}; this.module = params.get('module') || {};
this.entryId = params.get('entryId') || null; this.entryId = params.get('entryId') || null;
this.courseId = params.get('courseId'); this.courseId = params.get('courseId');
@ -91,6 +93,7 @@ export class AddonModDataEntryPage implements OnDestroy {
* View loaded. * View loaded.
*/ */
ionViewDidLoad(): void { ionViewDidLoad(): void {
this.commentsEnabled = !this.commentsProvider.areCommentsDisabledInSite();
this.fetchEntryData(); this.fetchEntryData();
// Refresh data if this discussion is synchronized automatically. // Refresh data if this discussion is synchronized automatically.

View File

@ -12,9 +12,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChange } from '@angular/core'; import { Component, EventEmitter, Input, OnChanges, OnDestroy, Output, SimpleChange } from '@angular/core';
import { NavController } from 'ionic-angular'; import { NavController } from 'ionic-angular';
import { CoreCommentsProvider } from '../../providers/comments'; import { CoreCommentsProvider } from '../../providers/comments';
import { CoreEventsProvider } from '@providers/events';
import { CoreSitesProvider } from '@providers/sites';
/** /**
* Component that displays the count of comments. * Component that displays the count of comments.
@ -23,7 +25,7 @@ import { CoreCommentsProvider } from '../../providers/comments';
selector: 'core-comments', selector: 'core-comments',
templateUrl: 'core-comments.html', templateUrl: 'core-comments.html',
}) })
export class CoreCommentsCommentsComponent implements OnChanges { export class CoreCommentsCommentsComponent implements OnChanges, OnDestroy {
@Input() contextLevel: string; @Input() contextLevel: string;
@Input() instanceId: number; @Input() instanceId: number;
@Input() component: string; @Input() component: string;
@ -36,9 +38,26 @@ export class CoreCommentsCommentsComponent implements OnChanges {
commentsLoaded = false; commentsLoaded = false;
commentsCount: number; commentsCount: number;
disabled = false;
constructor(private navCtrl: NavController, private commentsProvider: CoreCommentsProvider) { protected updateSiteObserver;
constructor(private navCtrl: NavController, private commentsProvider: CoreCommentsProvider,
sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider) {
this.onLoading = new EventEmitter<boolean>(); this.onLoading = new EventEmitter<boolean>();
this.disabled = this.commentsProvider.areCommentsDisabledInSite();
// Update visibility if current site info is updated.
this.updateSiteObserver = eventsProvider.on(CoreEventsProvider.SITE_UPDATED, () => {
const wasDisabled = this.disabled;
this.disabled = this.commentsProvider.areCommentsDisabledInSite();
if (wasDisabled && !this.disabled) {
this.fetchData();
}
}, sitesProvider.getCurrentSiteId());
} }
/** /**
@ -59,6 +78,10 @@ export class CoreCommentsCommentsComponent implements OnChanges {
} }
protected fetchData(): void { protected fetchData(): void {
if (this.disabled) {
return;
}
this.commentsLoaded = false; this.commentsLoaded = false;
this.onLoading.emit(true); this.onLoading.emit(true);
@ -77,7 +100,7 @@ export class CoreCommentsCommentsComponent implements OnChanges {
* Opens the comments page. * Opens the comments page.
*/ */
openComments(): void { openComments(): void {
if (this.commentsCount > 0) { if (!this.disabled && this.commentsCount > 0) {
// Open a new state with the interpolated contents. // Open a new state with the interpolated contents.
this.navCtrl.push('CoreCommentsViewerPage', { this.navCtrl.push('CoreCommentsViewerPage', {
contextLevel: this.contextLevel, contextLevel: this.contextLevel,
@ -90,4 +113,11 @@ export class CoreCommentsCommentsComponent implements OnChanges {
}); });
} }
} }
/**
* Component destroyed.
*/
ngOnDestroy(): void {
this.updateSiteObserver && this.updateSiteObserver.off();
}
} }

View File

@ -1,4 +1,4 @@
<core-loading [hideUntil]="commentsLoaded || !displaySpinner"> <core-loading *ngIf="!disabled" [hideUntil]="commentsLoaded || !displaySpinner">
<div (click)="openComments()" *ngIf="commentsCount >= 0"> <div (click)="openComments()" *ngIf="commentsCount >= 0">
{{ 'core.commentscount' | translate : {'$a': commentsCount} }} {{ 'core.commentscount' | translate : {'$a': commentsCount} }}
</div> </div>

View File

@ -14,6 +14,7 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreSitesProvider } from '@providers/sites'; import { CoreSitesProvider } from '@providers/sites';
import { CoreSite } from '@classes/site';
/** /**
* Service that provides some features regarding comments. * Service that provides some features regarding comments.
@ -25,6 +26,30 @@ export class CoreCommentsProvider {
constructor(private sitesProvider: CoreSitesProvider) {} constructor(private sitesProvider: CoreSitesProvider) {}
/**
* Check if Calendar is disabled in a certain site.
*
* @param {CoreSite} [site] Site. If not defined, use current site.
* @return {boolean} Whether it's disabled.
*/
areCommentsDisabledInSite(site?: CoreSite): boolean {
site = site || this.sitesProvider.getCurrentSite();
return site.isFeatureDisabled('NoDelegate_CoreComments');
}
/**
* Check if comments are disabled in a certain site.
*
* @param {string} [siteId] Site Id. If not defined, use current site.
* @return {Promise<boolean>} Promise resolved with true if disabled, rejected or resolved with false otherwise.
*/
areCommentsDisabled(siteId?: string): Promise<boolean> {
return this.sitesProvider.getSite(siteId).then((site) => {
return this.areCommentsDisabledInSite(site);
});
}
/** /**
* Get cache key for get comments data WS calls. * Get cache key for get comments data WS calls.
* *