From 1d15216b9f343f522b92286a63402e95e8fad4a7 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 15 May 2024 16:33:08 +0200 Subject: [PATCH] MOBILE-4470 assign: Implement action link handler This is necessary to handle links in timeline block. We'll need to do this in more situations, but for now it seems like assign is the only one with special actions. See MDL-81912. --- src/addons/mod/assign/pages/index/index.ts | 28 +++++++++++++++++-- .../assign/services/handlers/index-link.ts | 12 ++++++++ .../courses/tests/behat/basic_usage.feature | 11 ++++++-- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/addons/mod/assign/pages/index/index.ts b/src/addons/mod/assign/pages/index/index.ts index 1d4321208..03b810c1a 100644 --- a/src/addons/mod/assign/pages/index/index.ts +++ b/src/addons/mod/assign/pages/index/index.ts @@ -12,9 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, ViewChild } from '@angular/core'; +import { AfterViewInit, Component, ViewChild } from '@angular/core'; import { CoreCourseModuleMainActivityPage } from '@features/course/classes/main-activity-page'; import { AddonModAssignIndexComponent } from '../../components/index/index'; +import { CoreNavigator } from '@services/navigator'; +import { CoreUtils } from '@services/utils/utils'; /** * Page that displays an assign. @@ -23,8 +25,30 @@ import { AddonModAssignIndexComponent } from '../../components/index/index'; selector: 'page-addon-mod-assign-index', templateUrl: 'index.html', }) -export class AddonModAssignIndexPage extends CoreCourseModuleMainActivityPage { +export class AddonModAssignIndexPage extends CoreCourseModuleMainActivityPage + implements AfterViewInit { + + private action?: string; @ViewChild(AddonModAssignIndexComponent) activityComponent?: AddonModAssignIndexComponent; + constructor() { + super(); + + this.action = CoreNavigator.getRouteParam('action'); + } + + /** + * @inheritdoc + */ + async ngAfterViewInit(): Promise { + switch (this.action) { + case 'editsubmission': + await CoreUtils.waitFor(() => !!this.activityComponent?.submissionComponent, { timeout: 5000 }); + await this.activityComponent?.submissionComponent?.goToEdit(); + + break; + } + } + } diff --git a/src/addons/mod/assign/services/handlers/index-link.ts b/src/addons/mod/assign/services/handlers/index-link.ts index 3162d8d15..b3f93af53 100644 --- a/src/addons/mod/assign/services/handlers/index-link.ts +++ b/src/addons/mod/assign/services/handlers/index-link.ts @@ -14,6 +14,7 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksModuleIndexHandler } from '@features/contentlinks/classes/module-index-handler'; +import { CoreNavigationOptions } from '@services/navigator'; import { makeSingleton } from '@singletons'; /** @@ -28,5 +29,16 @@ export class AddonModAssignIndexLinkHandlerService extends CoreContentLinksModul super('AddonModAssign', 'assign'); } + /** + * @inheritdoc + */ + getModNavOptions(url: string, params: Record): CoreNavigationOptions { + if (!params.action) { + return {}; + } + + return { params: { action: params.action } }; + } + } export const AddonModAssignIndexLinkHandler = makeSingleton(AddonModAssignIndexLinkHandlerService); diff --git a/src/core/features/courses/tests/behat/basic_usage.feature b/src/core/features/courses/tests/behat/basic_usage.feature index bc23c6f41..860d27def 100755 --- a/src/core/features/courses/tests/behat/basic_usage.feature +++ b/src/core/features/courses/tests/behat/basic_usage.feature @@ -119,14 +119,21 @@ Feature: Test basic usage of courses in app Scenario: Links to actions in Timeline work for teachers/students # Submit assignment as student Given I entered the app as "student1" - When I press "Add submission" in the app + When I press "assignment" in the app Then the header should be "assignment" in the app And I should find "Test assignment description" in the app And I should find "No attempt" in the app And I should find "Due:" in the app When I press "Add submission" in the app - And I set the field "Online text submissions" to "test" in the app + Then I should find "Online text submissions" in the app + + When I press the back button in the app + And I press the back button in the app + And I press "Add submission" in the app + Then I should find "Online text submissions" in the app + + When I set the field "Online text submissions" to "test" in the app And I press "Save" in the app And I press "Submit assignment" in the app And I press "OK" in the app