From 9e91cf14e62f240225d81c2112bed2930950080f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Mon, 1 Jul 2019 15:38:14 +0200 Subject: [PATCH] MOBILE-2877 comments: Add button --- scripts/langindex.json | 5 +++++ src/assets/lang/en.json | 9 +++++---- .../comments/components/comments/comments.scss | 4 ++++ .../comments/components/comments/comments.ts | 2 +- .../components/comments/core-comments.html | 6 +++--- src/core/comments/lang/en.json | 7 +++++++ src/core/comments/pages/viewer/viewer.html | 8 +++++++- src/core/comments/pages/viewer/viewer.ts | 9 +++++++-- src/core/comments/providers/comments.ts | 18 ++++++++++++++++++ src/lang/en.json | 4 ---- 10 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 src/core/comments/components/comments/comments.scss create mode 100644 src/core/comments/lang/en.json diff --git a/scripts/langindex.json b/scripts/langindex.json index 5351ef509..9056e7451 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -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", diff --git a/src/assets/lang/en.json b/src/assets/lang/en.json index 21810db95..42b0102c1 100644 --- a/src/assets/lang/en.json +++ b/src/assets/lang/en.json @@ -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.", diff --git a/src/core/comments/components/comments/comments.scss b/src/core/comments/components/comments/comments.scss new file mode 100644 index 000000000..cd7b0655a --- /dev/null +++ b/src/core/comments/components/comments/comments.scss @@ -0,0 +1,4 @@ +core-comments .core-comments-clickable { + pointer-events: auto; + cursor: pointer; +} \ No newline at end of file diff --git a/src/core/comments/components/comments/comments.ts b/src/core/comments/components/comments/comments.ts index 6538a0874..fed935d1d 100644 --- a/src/core/comments/components/comments/comments.ts +++ b/src/core/comments/components/comments/comments.ts @@ -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, diff --git a/src/core/comments/components/comments/core-comments.html b/src/core/comments/components/comments/core-comments.html index e7b71e041..8642ffbb0 100644 --- a/src/core/comments/components/comments/core-comments.html +++ b/src/core/comments/components/comments/core-comments.html @@ -1,8 +1,8 @@ -
- {{ 'core.commentscount' | translate : {'$a': commentsCount} }} +
+ {{ 'core.comments.commentscount' | translate : {'$a': commentsCount} }}
- {{ 'core.commentsnotworking' | translate }} + {{ 'core.comments.commentsnotworking' | translate }}
diff --git a/src/core/comments/lang/en.json b/src/core/comments/lang/en.json new file mode 100644 index 000000000..0eb280877 --- /dev/null +++ b/src/core/comments/lang/en.json @@ -0,0 +1,7 @@ +{ + "addcomment": "Add a comment...", + "comments": "Comments", + "commentscount": "Comments ({{$a}})", + "commentsnotworking": "Comments cannot be retrieved", + "nocomments": "No comments" +} \ No newline at end of file diff --git a/src/core/comments/pages/viewer/viewer.html b/src/core/comments/pages/viewer/viewer.html index bcd909ecd..41e56725e 100644 --- a/src/core/comments/pages/viewer/viewer.html +++ b/src/core/comments/pages/viewer/viewer.html @@ -8,7 +8,7 @@ - + @@ -21,4 +21,10 @@ + + + + diff --git a/src/core/comments/pages/viewer/viewer.ts b/src/core/comments/pages/viewer/viewer.ts index 6652b879b..e9533a7d2 100644 --- a/src/core/comments/pages/viewer/viewer.ts +++ b/src/core/comments/pages/viewer/viewer.ts @@ -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'); } diff --git a/src/core/comments/providers/comments.ts b/src/core/comments/providers/comments.ts index 9808a0c83..cd671d84d 100644 --- a/src/core/comments/providers/comments.ts +++ b/src/core/comments/providers/comments.ts @@ -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} Promise resolved with true if available, resolved with false or rejected otherwise. + * @since 3.8 + */ + isAddCommentsAvailable(siteId?: string): Promise { + 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. * diff --git a/src/lang/en.json b/src/lang/en.json index c4111f1be..3aceb76c7 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -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.",