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.
main
Noel De Martin 2024-05-15 16:33:08 +02:00
parent b83f900690
commit 1d15216b9f
3 changed files with 47 additions and 4 deletions

View File

@ -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<AddonModAssignIndexComponent> {
export class AddonModAssignIndexPage extends CoreCourseModuleMainActivityPage<AddonModAssignIndexComponent>
implements AfterViewInit {
private action?: string;
@ViewChild(AddonModAssignIndexComponent) activityComponent?: AddonModAssignIndexComponent;
constructor() {
super();
this.action = CoreNavigator.getRouteParam('action');
}
/**
* @inheritdoc
*/
async ngAfterViewInit(): Promise<void> {
switch (this.action) {
case 'editsubmission':
await CoreUtils.waitFor(() => !!this.activityComponent?.submissionComponent, { timeout: 5000 });
await this.activityComponent?.submissionComponent?.goToEdit();
break;
}
}
}

View File

@ -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<string, string>): CoreNavigationOptions {
if (!params.action) {
return {};
}
return { params: { action: params.action } };
}
}
export const AddonModAssignIndexLinkHandler = makeSingleton(AddonModAssignIndexLinkHandlerService);

View File

@ -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