MOBILE-2877 comments: Add button

main
Pau Ferrer Ocaña 2019-07-01 15:38:14 +02:00
parent 5c4872288c
commit 9e91cf14e6
10 changed files with 57 additions and 15 deletions

View File

@ -1266,6 +1266,11 @@
"core.clicktoseefull": "local_moodlemobileapp", "core.clicktoseefull": "local_moodlemobileapp",
"core.close": "repository", "core.close": "repository",
"core.comments": "moodle", "core.comments": "moodle",
"core.comments.addcomment": "moodle",
"core.comments.comments": "moodle",
"core.comments.commentscount": "moodle",
"core.comments.commentsnotworking": "local_moodlemobileapp",
"core.comments.nocomments": "moodle",
"core.commentscount": "moodle", "core.commentscount": "moodle",
"core.commentsnotworking": "local_moodlemobileapp", "core.commentsnotworking": "local_moodlemobileapp",
"core.completion-alt-auto-fail": "completion", "core.completion-alt-auto-fail": "completion",

View File

@ -1265,9 +1265,11 @@
"core.clicktohideshow": "Click to expand or collapse", "core.clicktohideshow": "Click to expand or collapse",
"core.clicktoseefull": "Click to see full contents.", "core.clicktoseefull": "Click to see full contents.",
"core.close": "Close", "core.close": "Close",
"core.comments": "Comments", "core.comments.addcomment": "Add a comment...",
"core.commentscount": "Comments ({{$a}})", "core.comments.comments": "Comments",
"core.commentsnotworking": "Comments cannot be retrieved", "core.comments.commentscount": "Comments ({{$a}})",
"core.comments.commentsnotworking": "Comments cannot be retrieved",
"core.comments.nocomments": "No comments",
"core.completion-alt-auto-fail": "Completed: {{$a}} (did not achieve pass grade)", "core.completion-alt-auto-fail": "Completed: {{$a}} (did not achieve pass grade)",
"core.completion-alt-auto-n": "Not completed: {{$a}}", "core.completion-alt-auto-n": "Not completed: {{$a}}",
"core.completion-alt-auto-n-override": "Not completed: {{$a.modname}} (set by {{$a.overrideuser}})", "core.completion-alt-auto-n-override": "Not completed: {{$a.modname}} (set by {{$a.overrideuser}})",
@ -1618,7 +1620,6 @@
"core.never": "Never", "core.never": "Never",
"core.next": "Next", "core.next": "Next",
"core.no": "No", "core.no": "No",
"core.nocomments": "No comments",
"core.nograde": "No grade", "core.nograde": "No grade",
"core.none": "None", "core.none": "None",
"core.nopasswordchangeforced": "You cannot proceed without changing your password.", "core.nopasswordchangeforced": "You cannot proceed without changing your password.",

View File

@ -0,0 +1,4 @@
core-comments .core-comments-clickable {
pointer-events: auto;
cursor: pointer;
}

View File

@ -100,7 +100,7 @@ export class CoreCommentsCommentsComponent implements OnChanges, OnDestroy {
* Opens the comments page. * Opens the comments page.
*/ */
openComments(): void { openComments(): void {
if (!this.disabled && 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,

View File

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

View File

@ -0,0 +1,7 @@
{
"addcomment": "Add a comment...",
"comments": "Comments",
"commentscount": "Comments ({{$a}})",
"commentsnotworking": "Comments cannot be retrieved",
"nocomments": "No comments"
}

View File

@ -8,7 +8,7 @@
<ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content> <ion-refresher-content pullingText="{{ 'core.pulltorefresh' | translate }}"></ion-refresher-content>
</ion-refresher> </ion-refresher>
<core-loading [hideUntil]="commentsLoaded"> <core-loading [hideUntil]="commentsLoaded">
<core-empty-box *ngIf="!comments || !comments.length" icon="chatbubbles" [message]="'core.nocomments' | translate"></core-empty-box> <core-empty-box *ngIf="!comments || !comments.length" icon="chatbubbles" [message]="'core.comments.nocomments' | translate"></core-empty-box>
<ion-card *ngFor="let comment of comments"> <ion-card *ngFor="let comment of comments">
<ion-item text-wrap> <ion-item text-wrap>
@ -21,4 +21,10 @@
</ion-item> </ion-item>
</ion-card> </ion-card>
</core-loading> </core-loading>
<ion-fab core-fab bottom end *ngIf="addCommentsAvailable">
<button ion-fab (click)="addComment()" [attr.aria-label]="'core.comments.addcomment' | translate">
<ion-icon name="add"></ion-icon>
</button>
</ion-fab>
</ion-content> </ion-content>

View File

@ -40,6 +40,7 @@ export class CoreCommentsViewerPage {
area: string; area: string;
page: number; page: number;
title: string; title: string;
addCommentsAvailable = false;
constructor(navParams: NavParams, sitesProvider: CoreSitesProvider, private userProvider: CoreUserProvider, constructor(navParams: NavParams, sitesProvider: CoreSitesProvider, private userProvider: CoreUserProvider,
private domUtils: CoreDomUtilsProvider, private translate: TranslateService, private domUtils: CoreDomUtilsProvider, private translate: TranslateService,
@ -51,13 +52,17 @@ export class CoreCommentsViewerPage {
this.itemId = navParams.get('itemId'); this.itemId = navParams.get('itemId');
this.area = navParams.get('area') || ''; this.area = navParams.get('area') || '';
this.page = navParams.get('page') || 0; this.page = navParams.get('page') || 0;
this.title = navParams.get('title') || this.translate.instant('core.comments'); this.title = navParams.get('title') || this.translate.instant('core.comments.comments');
} }
/** /**
* View loaded. * View loaded.
*/ */
ionViewDidLoad(): void { ionViewDidLoad(): void {
this.commentsProvider.isAddCommentsAvailable().then((enabled) => {
this.addCommentsAvailable = enabled;
});
this.fetchComments().finally(() => { this.fetchComments().finally(() => {
this.commentsLoaded = true; this.commentsLoaded = true;
}); });
@ -84,7 +89,7 @@ export class CoreCommentsViewerPage {
}); });
}).catch((error) => { }).catch((error) => {
if (error && this.component == 'assignsubmission_comments') { if (error && this.component == 'assignsubmission_comments') {
this.domUtils.showAlertTranslated('core.notice', 'core.commentsnotworking'); this.domUtils.showAlertTranslated('core.notice', 'core.comments.commentsnotworking');
} else { } else {
this.domUtils.showErrorModalDefault(error, this.translate.instant('core.error') + ': get_comments'); this.domUtils.showErrorModalDefault(error, this.translate.instant('core.error') + ': get_comments');
} }

View File

@ -50,6 +50,24 @@ export class CoreCommentsProvider {
}); });
} }
/**
* Returns whether WS to add/delete comments are available in site.
*
* @param {string} [siteId] Site ID. If not defined, current site.
* @return {Promise<boolean>} Promise resolved with true if available, resolved with false or rejected otherwise.
* @since 3.8
*/
isAddCommentsAvailable(siteId?: string): Promise<boolean> {
return this.sitesProvider.getSite(siteId).then((site) => {
// First check if it's disabled.
if (this.areCommentsDisabledInSite(site)) {
return false;
}
return site.wsAvailable('core_comment_add_comments');
});
}
/** /**
* Get cache key for get comments data WS calls. * Get cache key for get comments data WS calls.
* *

View File

@ -25,9 +25,6 @@
"clicktohideshow": "Click to expand or collapse", "clicktohideshow": "Click to expand or collapse",
"clicktoseefull": "Click to see full contents.", "clicktoseefull": "Click to see full contents.",
"close": "Close", "close": "Close",
"comments": "Comments",
"commentscount": "Comments ({{$a}})",
"commentsnotworking": "Comments cannot be retrieved",
"completion-alt-auto-fail": "Completed: {{$a}} (did not achieve pass grade)", "completion-alt-auto-fail": "Completed: {{$a}} (did not achieve pass grade)",
"completion-alt-auto-n": "Not completed: {{$a}}", "completion-alt-auto-n": "Not completed: {{$a}}",
"completion-alt-auto-n-override": "Not completed: {{$a.modname}} (set by {{$a.overrideuser}})", "completion-alt-auto-n-override": "Not completed: {{$a.modname}} (set by {{$a.overrideuser}})",
@ -168,7 +165,6 @@
"never": "Never", "never": "Never",
"next": "Next", "next": "Next",
"no": "No", "no": "No",
"nocomments": "No comments",
"nograde": "No grade", "nograde": "No grade",
"none": "None", "none": "None",
"nopasswordchangeforced": "You cannot proceed without changing your password.", "nopasswordchangeforced": "You cannot proceed without changing your password.",