MOBILE-3651 quiz: Implement missing handlers

main
Dani Palou 2021-02-19 12:47:16 +01:00
parent b405614cb6
commit 33003da29d
12 changed files with 331 additions and 21 deletions

View File

@ -6,7 +6,7 @@
<div *ngFor="let item of items"> <div *ngFor="let item of items">
<ion-card> <ion-card>
<ion-item class="core-course-module-handler item-media ion-text-wrap" detail="false" (click)="action($event, item)" <ion-item class="core-course-module-handler item-media ion-text-wrap" detail="false" (click)="action($event, item)"
[title]="item.name"> [title]="item.name" button>
<img slot="start" [src]="item.iconUrl" alt="" role="presentation" *ngIf="item.iconUrl" class="core-module-icon"> <img slot="start" [src]="item.iconUrl" alt="" role="presentation" *ngIf="item.iconUrl" class="core-module-icon">
<ion-label> <ion-label>
<h2> <h2>

View File

@ -14,16 +14,25 @@
import { APP_INITIALIZER, NgModule } from '@angular/core'; import { APP_INITIALIZER, NgModule } from '@angular/core';
import { Routes } from '@angular/router'; import { Routes } from '@angular/router';
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate'; import { CoreCourseModuleDelegate } from '@features/course/services/module-delegate';
import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '@features/course/services/module-prefetch-delegate';
import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module'; import { CoreMainMenuTabRoutingModule } from '@features/mainmenu/mainmenu-tab-routing.module';
import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate';
import { CoreCronDelegate } from '@services/cron';
import { CORE_SITE_SCHEMAS } from '@services/sites'; import { CORE_SITE_SCHEMAS } from '@services/sites';
import { AddonModQuizAccessRulesModule } from './accessrules/accessrules.module'; import { AddonModQuizAccessRulesModule } from './accessrules/accessrules.module';
import { AddonModQuizComponentsModule } from './components/components.module'; import { AddonModQuizComponentsModule } from './components/components.module';
import { SITE_SCHEMA } from './services/database/quiz'; import { SITE_SCHEMA } from './services/database/quiz';
import { AddonModQuizGradeLinkHandler } from './services/handlers/grade-link';
import { AddonModQuizIndexLinkHandler } from './services/handlers/index-link';
import { AddonModQuizListLinkHandler } from './services/handlers/list-link';
import { AddonModQuizModuleHandler, AddonModQuizModuleHandlerService } from './services/handlers/module'; import { AddonModQuizModuleHandler, AddonModQuizModuleHandlerService } from './services/handlers/module';
import { AddonModQuizPrefetchHandler } from './services/handlers/prefetch'; import { AddonModQuizPrefetchHandler } from './services/handlers/prefetch';
import { AddonModQuizPushClickHandler } from './services/handlers/push-click';
import { AddonModQuizReviewLinkHandler } from './services/handlers/review-link';
import { AddonModQuizSyncCronHandler } from './services/handlers/sync-cron';
const routes: Routes = [ const routes: Routes = [
{ {
@ -51,6 +60,12 @@ const routes: Routes = [
useFactory: () => () => { useFactory: () => () => {
CoreCourseModuleDelegate.instance.registerHandler(AddonModQuizModuleHandler.instance); CoreCourseModuleDelegate.instance.registerHandler(AddonModQuizModuleHandler.instance);
CoreCourseModulePrefetchDelegate.instance.registerHandler(AddonModQuizPrefetchHandler.instance); CoreCourseModulePrefetchDelegate.instance.registerHandler(AddonModQuizPrefetchHandler.instance);
CoreContentLinksDelegate.instance.registerHandler(AddonModQuizGradeLinkHandler.instance);
CoreContentLinksDelegate.instance.registerHandler(AddonModQuizIndexLinkHandler.instance);
CoreContentLinksDelegate.instance.registerHandler(AddonModQuizListLinkHandler.instance);
CoreContentLinksDelegate.instance.registerHandler(AddonModQuizReviewLinkHandler.instance);
CorePushNotificationsDelegate.instance.registerClickHandler(AddonModQuizPushClickHandler.instance);
CoreCronDelegate.instance.register(AddonModQuizSyncCronHandler.instance);
}, },
}, },
], ],

View File

@ -0,0 +1,35 @@
// (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 { Injectable } from '@angular/core';
import { CoreContentLinksModuleGradeHandler } from '@features/contentlinks/classes/module-grade-handler';
import { makeSingleton } from '@singletons';
/**
* Handler to treat links to quiz grade.
*/
@Injectable({ providedIn: 'root' })
export class AddonModQuizGradeLinkHandlerService extends CoreContentLinksModuleGradeHandler {
name = 'AddonModQuizGradeLinkHandler';
canReview = false;
constructor() {
super('AddonModQuiz', 'quiz');
}
}
export class AddonModQuizGradeLinkHandler extends makeSingleton(AddonModQuizGradeLinkHandlerService) {}

View File

@ -0,0 +1,34 @@
// (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 { Injectable } from '@angular/core';
import { CoreContentLinksModuleIndexHandler } from '@features/contentlinks/classes/module-index-handler';
import { makeSingleton } from '@singletons';
/**
* Handler to treat links to quiz index.
*/
@Injectable({ providedIn: 'root' })
export class AddonModQuizIndexLinkHandlerService extends CoreContentLinksModuleIndexHandler {
name = 'AddonModQuizIndexLinkHandler';
constructor() {
super('AddonModQuiz', 'quiz', 'q');
}
}
export class AddonModQuizIndexLinkHandler extends makeSingleton(AddonModQuizIndexLinkHandlerService) {}

View File

@ -0,0 +1,34 @@
// (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 { Injectable } from '@angular/core';
import { CoreContentLinksModuleListHandler } from '@features/contentlinks/classes/module-list-handler';
import { makeSingleton } from '@singletons';
/**
* Handler to treat links to quiz list page.
*/
@Injectable({ providedIn: 'root' })
export class AddonModQuizListLinkHandlerService extends CoreContentLinksModuleListHandler {
name = 'AddonModQuizListLinkHandler';
constructor() {
super('AddonModQuiz', 'quiz');
}
}
export class AddonModQuizListLinkHandler extends makeSingleton(AddonModQuizListLinkHandlerService) {}

View File

@ -254,7 +254,7 @@ export class AddonModQuizPrefetchHandlerService extends CoreCourseActivityPrefet
* @return A boolean, or a promise resolved with a boolean, indicating if the handler is enabled. * @return A boolean, or a promise resolved with a boolean, indicating if the handler is enabled.
*/ */
async isEnabled(): Promise<boolean> { async isEnabled(): Promise<boolean> {
return AddonModQuiz.instance.isPluginEnabled(); return true;
} }
/** /**

View File

@ -0,0 +1,86 @@
// (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 { Injectable } from '@angular/core';
import { CoreCourseHelper } from '@features/course/services/course-helper';
import { CorePushNotificationsClickHandler } from '@features/pushnotifications/services/push-delegate';
import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications';
import { CoreUrlUtils } from '@services/utils/url';
import { CoreUtils } from '@services/utils/utils';
import { makeSingleton } from '@singletons';
import { AddonModQuiz } from '../quiz';
import { AddonModQuizHelper } from '../quiz-helper';
/**
* Handler for quiz push notifications clicks.
*/
@Injectable({ providedIn: 'root' })
export class AddonModQuizPushClickHandlerService implements CorePushNotificationsClickHandler {
name = 'AddonModQuizPushClickHandler';
priority = 200;
featureName = 'CoreCourseModuleDelegate_AddonModQuiz';
protected readonly SUPPORTED_NAMES = ['submission', 'confirmation', 'attempt_overdue'];
/**
* Check if a notification click is handled by this handler.
*
* @param notification The notification to check.
* @return Whether the notification click is handled by this handler
*/
async handles(notification: AddonModQuizPushNotificationData): Promise<boolean> {
return CoreUtils.instance.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_quiz' &&
this.SUPPORTED_NAMES.indexOf(notification.name!) != -1;
}
/**
* Handle the notification click.
*
* @param notification The notification to check.
* @return Promise resolved when done.
*/
async handleClick(notification: AddonModQuizPushNotificationData): Promise<void> {
const contextUrlParams = CoreUrlUtils.instance.extractUrlParams(notification.contexturl || '');
const data = notification.customdata || {};
const courseId = Number(notification.courseid);
if (notification.name == 'submission') {
// A student made a submission, go to view the attempt.
return AddonModQuizHelper.instance.handleReviewLink(
Number(contextUrlParams.attempt),
Number(contextUrlParams.page),
courseId,
Number(data.instance),
notification.site,
);
}
// Open the activity.
const moduleId = Number(contextUrlParams.id);
await CoreUtils.instance.ignoreErrors(AddonModQuiz.instance.invalidateContent(moduleId, courseId, notification.site));
return CoreCourseHelper.instance.navigateToModule(moduleId, notification.site, courseId);
}
}
export class AddonModQuizPushClickHandler extends makeSingleton(AddonModQuizPushClickHandlerService) {}
type AddonModQuizPushNotificationData = CorePushNotificationsNotificationBasicData & {
contexturl?: string;
courseid?: number | string;
};

View File

@ -0,0 +1,66 @@
// (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 { Injectable } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
import { makeSingleton } from '@singletons';
import { AddonModQuizHelper } from '../quiz-helper';
/**
* Handler to treat links to quiz review.
*/
@Injectable({ providedIn: 'root' })
export class AddonModQuizReviewLinkHandlerService extends CoreContentLinksHandlerBase {
name = 'AddonModQuizReviewLinkHandler';
featureName = 'CoreCourseModuleDelegate_AddonModQuiz';
pattern = /\/mod\/quiz\/review\.php.*([&?]attempt=\d+)/;
/**
* Get the list of actions for a link (url).
*
* @param siteIds List of sites the URL belongs to.
* @param url The URL to treat.
* @param params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
* @param courseId Course ID related to the URL. Optional but recommended.
* @param data Extra data to handle the URL.
* @return List of (or promise resolved with list of) actions.
*/
getActions(
siteIds: string[],
url: string,
params: Record<string, string>,
courseId?: number,
data?: Record<string, unknown>,
): CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
courseId = Number(courseId || params.courseid || params.cid);
data = data || {};
return [{
action: (siteId): void => {
const attemptId = parseInt(params.attempt, 10);
const page = parseInt(params.page, 10);
const quizId = data!.instance ? Number(data!.instance) : undefined;
AddonModQuizHelper.instance.handleReviewLink(attemptId, page, courseId, quizId, siteId);
},
}];
}
}
export class AddonModQuizReviewLinkHandler extends makeSingleton(AddonModQuizReviewLinkHandlerService) {}

View File

@ -0,0 +1,52 @@
// (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 { Injectable } from '@angular/core';
import { CoreCronHandler } from '@services/cron';
import { makeSingleton } from '@singletons';
import { AddonModQuizSync } from '../quiz-sync';
/**
* Synchronization cron handler.
*/
@Injectable({ providedIn: 'root' })
export class AddonModQuizSyncCronHandlerService implements CoreCronHandler {
name = 'AddonModQuizSyncCronHandler';
/**
* Execute the process.
* Receives the ID of the site affected, undefined for all sites.
*
* @param siteId ID of the site affected, undefined for all sites.
* @param force Wether the execution is forced (manual sync).
* @return Promise resolved when done, rejected if failure.
*/
execute(siteId?: string, force?: boolean): Promise<void> {
return AddonModQuizSync.instance.syncAllQuizzes(siteId, force);
}
/**
* Get the time between consecutive executions.
*
* @return Time between consecutive executions (in ms).
*/
getInterval(): number {
return AddonModQuizSync.instance.syncInterval;
}
}
export class AddonModQuizSyncCronHandler extends makeSingleton(AddonModQuizSyncCronHandlerService) {}

View File

@ -237,14 +237,12 @@ export class AddonModQuizHelperProvider {
} }
// Go to the review page. // Go to the review page.
const pageParams = { await CoreNavigator.instance.navigateToSitePath(`mod_quiz/review/${courseId}/${quizId}/${attemptId}`, {
quizId, params: {
attemptId, page: page == undefined || isNaN(page) ? -1 : page,
courseId, },
page: page == undefined || isNaN(page) ? -1 : page, siteId,
}; });
await CoreNavigator.instance.navigateToSitePath('@todo AddonModQuizReviewPage', { params: pageParams, siteId });
} catch (error) { } catch (error) {
CoreDomUtils.instance.showErrorModalDefault(error, 'An error occurred while loading the required data.'); CoreDomUtils.instance.showErrorModalDefault(error, 'An error occurred while loading the required data.');
} finally { } finally {

View File

@ -1496,16 +1496,6 @@ export class AddonModQuizProvider {
return quiz.navmethod == 'sequential'; return quiz.navmethod == 'sequential';
} }
/**
* Return whether or not the plugin is enabled in a certain site. Plugin is enabled if the quiz WS are available.
*
* @return Whether the plugin is enabled.
*/
isPluginEnabled(): boolean {
// Quiz WebServices were introduced in 3.1, it will always be enabled.
return true;
}
/** /**
* Check if a question is blocked. * Check if a question is blocked.
* *

View File

@ -14,7 +14,7 @@
<ion-item *ngIf="!section.hiddenbynumsections && section.id != stealthModulesSectionId" class="ion-text-wrap" <ion-item *ngIf="!section.hiddenbynumsections && section.id != stealthModulesSectionId" class="ion-text-wrap"
(click)="selectSection(section)" [class.core-selected-item]="selected?.id == section.id" (click)="selectSection(section)" [class.core-selected-item]="selected?.id == section.id"
[class.item-dimmed]="section.visible === 0 || section.uservisible === false" detail="false" role="menuitem" [class.item-dimmed]="section.visible === 0 || section.uservisible === false" detail="false" role="menuitem"
[attr.aria-hidden]="section.uservisible === false"> [attr.aria-hidden]="section.uservisible === false" button>
<ion-icon name="fas-folder" slot="start"></ion-icon> <ion-icon name="fas-folder" slot="start"></ion-icon>
<ion-label> <ion-label>