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.close": "repository",
"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.commentsnotworking": "local_moodlemobileapp",
"core.completion-alt-auto-fail": "completion",

View File

@ -1265,9 +1265,11 @@
"core.clicktohideshow": "Click to expand or collapse",
"core.clicktoseefull": "Click to see full contents.",
"core.close": "Close",
"core.comments": "Comments",
"core.commentscount": "Comments ({{$a}})",
"core.commentsnotworking": "Comments cannot be retrieved",
"core.comments.addcomment": "Add a comment...",
"core.comments.comments": "Comments",
"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-n": "Not completed: {{$a}}",
"core.completion-alt-auto-n-override": "Not completed: {{$a.modname}} (set by {{$a.overrideuser}})",
@ -1618,7 +1620,6 @@
"core.never": "Never",
"core.next": "Next",
"core.no": "No",
"core.nocomments": "No comments",
"core.nograde": "No grade",
"core.none": "None",
"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.
*/
openComments(): void {
if (!this.disabled && this.commentsCount > 0) {
if (!this.disabled && this.commentsCount >= 0) {
// Open a new state with the interpolated contents.
this.navCtrl.push('CoreCommentsViewerPage', {
contextLevel: this.contextLevel,

View File

@ -1,8 +1,8 @@
<core-loading *ngIf="!disabled" [hideUntil]="commentsLoaded || !displaySpinner">
<div (click)="openComments()" *ngIf="commentsCount >= 0">
{{ 'core.commentscount' | translate : {'$a': commentsCount} }}
<div (click)="openComments()" *ngIf="commentsCount >= 0" [class.core-comments-clickable]="!disabled">
{{ 'core.comments.commentscount' | translate : {'$a': commentsCount} }}
</div>
<div *ngIf="commentsCount < 0">
{{ 'core.commentsnotworking' | translate }}
{{ 'core.comments.commentsnotworking' | translate }}
</div>
</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>
<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-item text-wrap>
@ -21,4 +21,10 @@
</ion-item>
</ion-card>
</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>

View File

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

View File

@ -25,9 +25,6 @@
"clicktohideshow": "Click to expand or collapse",
"clicktoseefull": "Click to see full contents.",
"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-n": "Not completed: {{$a}}",
"completion-alt-auto-n-override": "Not completed: {{$a.modname}} (set by {{$a.overrideuser}})",
@ -168,7 +165,6 @@
"never": "Never",
"next": "Next",
"no": "No",
"nocomments": "No comments",
"nograde": "No grade",
"none": "None",
"nopasswordchangeforced": "You cannot proceed without changing your password.",