From 19625470ee3d55ec24ac7e1c27e9927b97efb427 Mon Sep 17 00:00:00 2001 From: Alfonso Salces Date: Thu, 20 Apr 2023 15:33:07 +0200 Subject: [PATCH 1/3] MOBILE-4248 actionsmenu: Create actions menu component --- scripts/langindex.json | 1 + .../components/actionsmenu/actionsmenu.html | 9 ++++ .../components/actionsmenu/actionsmenu.ts | 45 +++++++++++++++++++ .../mod/data/components/components.module.ts | 3 ++ 4 files changed, 58 insertions(+) create mode 100644 src/addons/mod/data/components/actionsmenu/actionsmenu.html create mode 100644 src/addons/mod/data/components/actionsmenu/actionsmenu.ts diff --git a/scripts/langindex.json b/scripts/langindex.json index a52826bd3..1af7a1f3c 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -524,6 +524,7 @@ "addon.mod_choice.savemychoice": "choice", "addon.mod_choice.userchoosethisoption": "choice", "addon.mod_choice.yourselection": "choice", + "addon.mod_data.actions": "data", "addon.mod_data.addentries": "data", "addon.mod_data.advancedsearch": "data", "addon.mod_data.alttext": "data", diff --git a/src/addons/mod/data/components/actionsmenu/actionsmenu.html b/src/addons/mod/data/components/actionsmenu/actionsmenu.html new file mode 100644 index 000000000..177470dcd --- /dev/null +++ b/src/addons/mod/data/components/actionsmenu/actionsmenu.html @@ -0,0 +1,9 @@ + + + +

{{ item.text | translate }}

+
+ +
+
diff --git a/src/addons/mod/data/components/actionsmenu/actionsmenu.ts b/src/addons/mod/data/components/actionsmenu/actionsmenu.ts new file mode 100644 index 000000000..921a0f787 --- /dev/null +++ b/src/addons/mod/data/components/actionsmenu/actionsmenu.ts @@ -0,0 +1,45 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { Component, Input } from '@angular/core'; +import { PopoverController } from '@singletons'; + +/** + * Component that displays the actionsmenu. + */ +@Component({ + selector: 'addon-mod-data-actionsmenu', + templateUrl: 'actionsmenu.html', +}) +export class AddonModDataActionsMenuComponent { + + @Input() items: AddonModDataActionsMenuItem[] = []; + + /** + * Execute item action and dismiss the popover. + * + * @param item item from which the action will be executed. + */ + async onItemClick(item: AddonModDataActionsMenuItem): Promise { + item.action(); + await PopoverController.dismiss(); + } + +} + +export interface AddonModDataActionsMenuItem { + text: string; + icon: string; + action: () => void; +}; diff --git a/src/addons/mod/data/components/components.module.ts b/src/addons/mod/data/components/components.module.ts index 36d2812b9..5d3021daf 100644 --- a/src/addons/mod/data/components/components.module.ts +++ b/src/addons/mod/data/components/components.module.ts @@ -18,11 +18,13 @@ import { CoreCourseComponentsModule } from '@features/course/components/componen import { AddonModDataIndexComponent } from './index'; import { AddonModDataSearchComponent } from './search/search'; import { CoreCompileHtmlComponentModule } from '@features/compile/components/compile-html/compile-html.module'; +import { AddonModDataActionsMenuComponent } from './actionsmenu/actionsmenu'; @NgModule({ declarations: [ AddonModDataIndexComponent, AddonModDataSearchComponent, + AddonModDataActionsMenuComponent, ], imports: [ CoreSharedModule, @@ -32,6 +34,7 @@ import { CoreCompileHtmlComponentModule } from '@features/compile/components/com exports: [ AddonModDataIndexComponent, AddonModDataSearchComponent, + AddonModDataActionsMenuComponent, ], }) export class AddonModDataComponentsModule {} From 01561748d760f5f4dcb517d421fe376077ffd616 Mon Sep 17 00:00:00 2001 From: Alfonso Salces Date: Thu, 20 Apr 2023 15:33:54 +0200 Subject: [PATCH 2/3] MOBILE-4248 mod-data-action: Add actions menu to action --- scripts/langindex.json | 1 + .../mod/data/components/action/action.ts | 66 +++++++++++++++++++ .../action/addon-mod-data-action.html | 8 ++- src/addons/mod/data/components/index/index.ts | 4 +- src/addons/mod/data/lang.json | 2 + src/addons/mod/data/pages/entry/entry.ts | 4 +- src/addons/mod/data/services/data-helper.ts | 11 +++- src/addons/mod/data/services/data.ts | 1 + 8 files changed, 91 insertions(+), 6 deletions(-) diff --git a/scripts/langindex.json b/scripts/langindex.json index 1af7a1f3c..eff2a8188 100644 --- a/scripts/langindex.json +++ b/scripts/langindex.json @@ -568,6 +568,7 @@ "addon.mod_data.search": "data", "addon.mod_data.searchbytagsnotsupported": "local_moodlemobileapp", "addon.mod_data.selectedrequired": "data", + "addon.mod_data.showmore": "data", "addon.mod_data.single": "data", "addon.mod_data.tagarea_data_records": "data", "addon.mod_data.timeadded": "data", diff --git a/src/addons/mod/data/components/action/action.ts b/src/addons/mod/data/components/action/action.ts index 16653ad46..bb865ac19 100644 --- a/src/addons/mod/data/components/action/action.ts +++ b/src/addons/mod/data/components/action/action.ts @@ -23,12 +23,15 @@ import { AddonModDataAction, AddonModDataData, AddonModDataEntry, + AddonModDataGetDataAccessInformationWSResponse, AddonModDataProvider, AddonModDataTemplateMode, } from '../../services/data'; import { AddonModDataHelper } from '../../services/data-helper'; import { AddonModDataOffline } from '../../services/data-offline'; import { AddonModDataModuleHandlerService } from '../../services/handlers/module'; +import { CoreDomUtils } from '@services/utils/dom'; +import { AddonModDataActionsMenuComponent, AddonModDataActionsMenuItem } from '../actionsmenu/actionsmenu'; /** * Component that displays a database action. @@ -39,6 +42,7 @@ import { AddonModDataModuleHandlerService } from '../../services/handlers/module }) export class AddonModDataActionComponent implements OnInit { + @Input() access?: AddonModDataGetDataAccessInformationWSResponse; // Access info. @Input() mode!: AddonModDataTemplateMode; // The render mode. @Input() action!: AddonModDataAction; // The field to render. @Input() entry!: AddonModDataEntry; // The value of the field. @@ -139,4 +143,66 @@ export class AddonModDataActionComponent implements OnInit { CoreEvents.trigger(AddonModDataProvider.ENTRY_CHANGED, { dataId: dataId, entryId: entryId }, this.siteId); } + /** + * Open actions menu popover. + */ + async actionsMenu(): Promise { + const items: AddonModDataActionsMenuItem[] = []; + + if (this.entry.canmanageentry) { + items.push( + this.entry.deleted + ? { + action: () => this.undoDelete(), + text: 'core.restore', + icon: 'fas-rotate-left', + } + : { + action: () => this.deleteEntry(), + text: 'core.delete', + icon: 'fas-trash', + }, + ); + + if (!this.entry.deleted) { + items.unshift({ + action: () => this.editEntry(), + text: 'core.edit', + icon: 'fas-pen', + }); + } + } + + if (this.database.approval && this.access?.canapprove && !this.entry.deleted) { + items.push( + !this.entry.approved + ? { + action: () => this.approveEntry(), + text: 'addon.mod_data.approve', + icon: 'fas-thumbs-up', + } + : { + action: () => this.disapproveEntry(), + text: 'addon.mod_data.disapprove', + icon: 'far-thumbs-down', + }, + ); + } + + if (this.mode === AddonModDataTemplateMode.LIST) { + items.unshift({ + action: () => this.viewEntry(), + text: 'addon.mod_data.showmore', + icon: 'fas-magnifying-glass-plus', + }); + } + + await CoreDomUtils.openPopover({ + component: AddonModDataActionsMenuComponent, + componentProps: { items }, + showBackdrop: true, + id: 'actionsmenu-popover', + }); + } + } diff --git a/src/addons/mod/data/components/action/addon-mod-data-action.html b/src/addons/mod/data/components/action/addon-mod-data-action.html index e8688a7ac..cf233c3fa 100644 --- a/src/addons/mod/data/components/action/addon-mod-data-action.html +++ b/src/addons/mod/data/components/action/addon-mod-data-action.html @@ -1,4 +1,10 @@ - + + + + + diff --git a/src/addons/mod/data/components/index/index.ts b/src/addons/mod/data/components/index/index.ts index 2cdac62c5..64e0ca22e 100644 --- a/src/addons/mod/data/components/index/index.ts +++ b/src/addons/mod/data/components/index/index.ts @@ -95,6 +95,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp database: AddonModDataData; title: string; group: number; + access: AddonModDataGetDataAccessInformationWSResponse | undefined; gotoEntry: (entryId: number) => void; }; @@ -348,7 +349,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp this.entries.forEach((entry, index) => { entriesById[entry.id] = entry; - const actions = AddonModDataHelper.getActions(this.database!, this.access!, entry); + const actions = AddonModDataHelper.getActions(this.database!, this.access!, entry, AddonModDataTemplateMode.LIST); const options: AddonModDatDisplayFieldsOptions = {}; if (!this.search.searching) { options.offset = this.search.page * AddonModDataProvider.PER_PAGE + index - numOfflineEntries; @@ -375,6 +376,7 @@ export class AddonModDataIndexComponent extends CoreCourseModuleMainActivityComp database: this.database!, title: this.module.name, group: this.selectedGroup, + access: this.access, gotoEntry: (entryId) => this.gotoEntry(entryId), }; } else if (!this.search.searching) { diff --git a/src/addons/mod/data/lang.json b/src/addons/mod/data/lang.json index 6e28a0dfe..e77e2fcd1 100644 --- a/src/addons/mod/data/lang.json +++ b/src/addons/mod/data/lang.json @@ -1,4 +1,5 @@ { + "actions": "Actions menu", "addentries": "Add entries", "advancedsearch": "Advanced search", "alttext": "Alternative text", @@ -42,6 +43,7 @@ "search": "Search", "searchbytagsnotsupported": "Sorry, searching by tags is not supported by the app.", "selectedrequired": "All selected required", + "showmore": "Show more", "single": "View single", "tagarea_data_records": "Data records", "timeadded": "Time added", diff --git a/src/addons/mod/data/pages/entry/entry.ts b/src/addons/mod/data/pages/entry/entry.ts index cb6d43cfe..681ffbda0 100644 --- a/src/addons/mod/data/pages/entry/entry.ts +++ b/src/addons/mod/data/pages/entry/entry.ts @@ -86,6 +86,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { database: AddonModDataData; title: string; group: number; + access: AddonModDataGetDataAccessInformationWSResponse | undefined; }; ratingInfo?: CoreRatingInfo; @@ -187,7 +188,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { this.selectedGroup = CoreGroups.validateGroupId(this.selectedGroup, this.groupInfo); - const actions = AddonModDataHelper.getActions(this.database, this.access, this.entry!); + const actions = AddonModDataHelper.getActions(this.database, this.access, this.entry!, AddonModDataTemplateMode.SHOW); const template = AddonModDataHelper.getTemplate(this.database, AddonModDataTemplateType.SINGLE, this.fieldsArray); this.entryHtml = AddonModDataHelper.displayShowFields( @@ -215,6 +216,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { database: this.database, title: this.title, group: this.selectedGroup, + access: this.access, }; if (this.logAfterFetch) { diff --git a/src/addons/mod/data/services/data-helper.ts b/src/addons/mod/data/services/data-helper.ts index 40751a9c5..6de9d53f8 100644 --- a/src/addons/mod/data/services/data-helper.ts +++ b/src/addons/mod/data/services/data-helper.ts @@ -234,7 +234,7 @@ export class AddonModDataHelperProvider { render = Translate.instant('addon.mod_data.' + (entry.approved ? 'approved' : 'notapproved')); } else { render = ` { return { add: false, // Not directly used on entries. @@ -426,6 +427,10 @@ export class AddonModDataHelperProvider { approvalstatus: database.approval, comments: database.comments, + actionsmenu: entry.canmanageentry + || (database.approval && accessInfo.canapprove && !entry.deleted) + || mode === AddonModDataTemplateMode.LIST, + // Unsupported actions. delcheck: false, export: false, @@ -497,7 +502,7 @@ export class AddonModDataHelperProvider { html.push( '', '', - '##edit## ##more## ##delete## ##approve## ##disapprove## ##export##', + '##actionsmenu## ##edit## ##more## ##delete## ##approve## ##disapprove## ##export##', '', '', ); @@ -505,7 +510,7 @@ export class AddonModDataHelperProvider { html.push( '', '', - '##edit## ##delete## ##approve## ##disapprove## ##export##', + '##actionsmenu## ##edit## ##delete## ##approve## ##disapprove## ##export##', '', '', ); diff --git a/src/addons/mod/data/services/data.ts b/src/addons/mod/data/services/data.ts index c4b0f18c3..0ff632a17 100644 --- a/src/addons/mod/data/services/data.ts +++ b/src/addons/mod/data/services/data.ts @@ -62,6 +62,7 @@ export enum AddonModDataAction { APPROVALSTATUS = 'approvalstatus', DELCHECK = 'delcheck', // Unused. EXPORT = 'export', // Unused. + ACTIONSMENU = 'actionsmenu', } export enum AddonModDataTemplateType { From c36ba604803dd5ec3c25fb1314854f9b40b451aa Mon Sep 17 00:00:00 2001 From: Alfonso Salces Date: Mon, 24 Apr 2023 15:32:10 +0200 Subject: [PATCH 3/3] MOBILE-4248 tests: Fix data basic_usage and entries tests --- src/addons/mod/data/tests/behat/entries.feature | 8 ++++---- .../features/comments/tests/behat/basic_usage.feature | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/addons/mod/data/tests/behat/entries.feature b/src/addons/mod/data/tests/behat/entries.feature index bd6707cdf..f252cdd40 100644 --- a/src/addons/mod/data/tests/behat/entries.feature +++ b/src/addons/mod/data/tests/behat/entries.feature @@ -52,7 +52,7 @@ Feature: Users can manage entries in database activities | URL | https://moodlecloud.com/ | | Description | Moodle Cloud | And I press "Save" near "Web links" in the app - And I press "More" near "Moodle community site" in the app + And I press "Show more" near "Moodle community site" in the app Then I should find "Moodle community site" in the app And I should be able to press "Previous" in the app But I should not be able to press "Next" in the app @@ -81,7 +81,7 @@ Feature: Users can manage entries in database activities When I press "Web links" near "General" in the app Then "Edit" "link" should not exist And "Delete" "link" should not exist - And I press "More" in the app + And I press "Show more" in the app And "Edit" "link" should not exist And "Delete" "link" should not exist @@ -122,7 +122,7 @@ Feature: Users can manage entries in database activities And I press "Save" near "Web links" in the app # Edit the entry from single view. - When I press "More" in the app + When I press "Show more" in the app And I press "Edit" in the app And I set the following fields to these values in the app: | URL | https://moodlecloud.com/ | @@ -184,7 +184,7 @@ Feature: Users can manage entries in database activities And I should not find "Moodle Cloud" in the app # Edit the entry from single view. - When I press "More" in the app + When I press "Show more" in the app And I should find "https://telegram.org/" in the app And I should find "Telegram" in the app And I press "Edit" in the app diff --git a/src/core/features/comments/tests/behat/basic_usage.feature b/src/core/features/comments/tests/behat/basic_usage.feature index bd6d90a43..40b6ef738 100644 --- a/src/core/features/comments/tests/behat/basic_usage.feature +++ b/src/core/features/comments/tests/behat/basic_usage.feature @@ -32,7 +32,7 @@ Feature: Test basic usage of comments in app And I press "Add entries" in the app And I set the field "Test field name" to "Test" in the app And I press "Save" in the app - And I press "More" in the app + And I press "Show more" in the app And I press "Comments (0)" in the app And I set the field "Add a comment..." to "comment test teacher" in the app And I press "Send" in the app @@ -44,7 +44,7 @@ Feature: Test basic usage of comments in app # Create and delete comments as a student Given I entered the data activity "Data" on course "Course 1" as "student1" in the app - And I press "More" in the app + And I press "Show more" in the app And I press "Comments (1)" in the app And I set the field "Add a comment..." to "comment test student" in the app And I press "Send" in the app @@ -69,7 +69,7 @@ Feature: Test basic usage of comments in app And I press "Add entries" in the app And I set the field "Test field name" to "Test" in the app And I press "Save" in the app - And I press "More" in the app + And I press "Show more" in the app And I press "Comments (0)" in the app And I switch network connection to offline And I set the field "Add a comment..." to "comment test" in the app