diff --git a/src/addon/mod/feedback/feedback.module.ts b/src/addon/mod/feedback/feedback.module.ts index ded66de7e..7811fc5cd 100644 --- a/src/addon/mod/feedback/feedback.module.ts +++ b/src/addon/mod/feedback/feedback.module.ts @@ -17,6 +17,7 @@ import { CoreCronDelegate } from '@providers/cron'; import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate'; import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate'; import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate'; +import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate'; import { AddonModFeedbackComponentsModule } from './components/components.module'; import { AddonModFeedbackModuleHandler } from './providers/module-handler'; import { AddonModFeedbackProvider } from './providers/feedback'; @@ -29,6 +30,7 @@ import { AddonModFeedbackPrintLinkHandler } from './providers/print-link-handler import { AddonModFeedbackListLinkHandler } from './providers/list-link-handler'; import { AddonModFeedbackHelperProvider } from './providers/helper'; import { AddonModFeedbackPrefetchHandler } from './providers/prefetch-handler'; +import { AddonModFeedbackPushClickHandler } from './providers/push-click-handler'; import { AddonModFeedbackSyncProvider } from './providers/sync'; import { AddonModFeedbackSyncCronHandler } from './providers/sync-cron-handler'; import { AddonModFeedbackOfflineProvider } from './providers/offline'; @@ -62,7 +64,8 @@ export const ADDON_MOD_FEEDBACK_PROVIDERS: any[] = [ AddonModFeedbackCompleteLinkHandler, AddonModFeedbackPrintLinkHandler, AddonModFeedbackListLinkHandler, - AddonModFeedbackSyncCronHandler + AddonModFeedbackSyncCronHandler, + AddonModFeedbackPushClickHandler ] }) export class AddonModFeedbackModule { @@ -74,7 +77,8 @@ export class AddonModFeedbackModule { showEntriesLinkHandler: AddonModFeedbackShowEntriesLinkHandler, showNonRespondentsLinkHandler: AddonModFeedbackShowNonRespondentsLinkHandler, completeLinkHandler: AddonModFeedbackCompleteLinkHandler, - printLinkHandler: AddonModFeedbackPrintLinkHandler, listLinkHandler: AddonModFeedbackListLinkHandler) { + printLinkHandler: AddonModFeedbackPrintLinkHandler, listLinkHandler: AddonModFeedbackListLinkHandler, + pushNotificationsDelegate: CorePushNotificationsDelegate, pushClickHandler: AddonModFeedbackPushClickHandler) { moduleDelegate.registerHandler(moduleHandler); prefetchDelegate.registerHandler(prefetchHandler); @@ -86,6 +90,7 @@ export class AddonModFeedbackModule { contentLinksDelegate.registerHandler(printLinkHandler); contentLinksDelegate.registerHandler(listLinkHandler); cronDelegate.register(syncHandler); + pushNotificationsDelegate.registerClickHandler(pushClickHandler); // Allow migrating the tables from the old app to the new schema. updateManager.registerSiteTableMigration({ diff --git a/src/addon/mod/feedback/providers/helper.ts b/src/addon/mod/feedback/providers/helper.ts index 538dde0c2..45c7b8a3a 100644 --- a/src/addon/mod/feedback/providers/helper.ts +++ b/src/addon/mod/feedback/providers/helper.ts @@ -16,6 +16,10 @@ import { Injectable } from '@angular/core'; import { NavController, ViewController } from 'ionic-angular'; import { AddonModFeedbackProvider } from './feedback'; import { CoreUserProvider } from '@core/user/providers/user'; +import { CoreCourseProvider } from '@core/course/providers/course'; +import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; +import { CoreSitesProvider } from '@providers/sites'; +import { CoreDomUtilsProvider } from '@providers/utils/dom'; import { CoreTextUtilsProvider } from '@providers/utils/text'; import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { TranslateService } from '@ngx-translate/core'; @@ -32,7 +36,9 @@ export class AddonModFeedbackHelperProvider { constructor(protected feedbackProvider: AddonModFeedbackProvider, protected userProvider: CoreUserProvider, protected textUtils: CoreTextUtilsProvider, protected translate: TranslateService, - protected timeUtils: CoreTimeUtilsProvider) { + protected timeUtils: CoreTimeUtilsProvider, protected domUtils: CoreDomUtilsProvider, + protected courseProvider: CoreCourseProvider, protected linkHelper: CoreContentLinksHelperProvider, + protected sitesProvider: CoreSitesProvider) { } /** @@ -193,6 +199,48 @@ export class AddonModFeedbackHelperProvider { }); } + /** + * Handle a show entries link. + * + * @param {NavController} navCtrl Nav controller to use to navigate. Can be undefined/null. + * @param {any} params URL params. + * @param {string} [siteId] Site ID. If not defined, current site. + * @return {Promise} Promise resolved when done. + */ + handleShowEntriesLink(navCtrl: NavController, params: any, siteId?: string): Promise { + siteId = siteId || this.sitesProvider.getCurrentSiteId(); + + const modal = this.domUtils.showModalLoading(), + moduleId = params.id; + + return this.courseProvider.getModuleBasicInfo(moduleId, siteId).then((module) => { + let stateParams; + + if (typeof params.showcompleted == 'undefined') { + // Param showcompleted not defined. Show entry list. + stateParams = { + module: module, + courseId: module.course + }; + + return this.linkHelper.goInSite(navCtrl, 'AddonModFeedbackRespondentsPage', stateParams, siteId); + } + + return this.feedbackProvider.getAttempt(module.instance, params.showcompleted, true, siteId).then((attempt) => { + stateParams = { + moduleId: module.id, + attempt: attempt, + feedbackId: module.instance, + courseId: module.course + }; + + return this.linkHelper.goInSite(navCtrl, 'AddonModFeedbackAttemptPage', stateParams, siteId); + }); + }).finally(() => { + modal.dismiss(); + }); + } + /** * Add Image profile url field on attempts * diff --git a/src/addon/mod/feedback/providers/push-click-handler.ts b/src/addon/mod/feedback/providers/push-click-handler.ts new file mode 100644 index 000000000..675e7d0dd --- /dev/null +++ b/src/addon/mod/feedback/providers/push-click-handler.ts @@ -0,0 +1,69 @@ +// (C) Copyright 2015 Martin Dougiamas +// +// 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 { CoreUrlUtilsProvider } from '@providers/utils/url'; +import { CoreUtilsProvider } from '@providers/utils/utils'; +import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate'; +import { CoreCourseHelperProvider } from '@core/course/providers/helper'; +import { AddonModFeedbackProvider } from './feedback'; +import { AddonModFeedbackHelperProvider } from './helper'; + +/** + * Handler for feedback push notifications clicks. + */ +@Injectable() +export class AddonModFeedbackPushClickHandler implements CorePushNotificationsClickHandler { + name = 'AddonModFeedbackPushClickHandler'; + priority = 200; + featureName = 'CoreCourseModuleDelegate_AddonModFeedback'; + + constructor(private utils: CoreUtilsProvider, private feedbackHelper: AddonModFeedbackHelperProvider, + private urlUtils: CoreUrlUtilsProvider, private courseHelper: CoreCourseHelperProvider, + private feedbackProvider: AddonModFeedbackProvider) {} + + /** + * Check if a notification click is handled by this handler. + * + * @param {any} notification The notification to check. + * @return {boolean} Whether the notification click is handled by this handler + */ + handles(notification: any): boolean | Promise { + if (this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_feedback' && + (notification.name == 'submission' || notification.name == 'message')) { + + return this.feedbackProvider.isPluginEnabled(notification.site); + } + + return false; + } + + /** + * Handle the notification click. + * + * @param {any} notification The notification to check. + * @return {Promise} Promise resolved when done. + */ + handleClick(notification: any): Promise { + const contextUrlParams = this.urlUtils.extractUrlParams(notification.contexturl), + courseId = Number(notification.courseid), + moduleId = Number(contextUrlParams.id); + + if (notification.name == 'submission') { + return this.feedbackHelper.handleShowEntriesLink(undefined, contextUrlParams, notification.site); + } else { + return this.courseHelper.navigateToModule(moduleId, notification.site, courseId); + } + } +} diff --git a/src/addon/mod/feedback/providers/show-entries-link-handler.ts b/src/addon/mod/feedback/providers/show-entries-link-handler.ts index d10c156da..498703386 100644 --- a/src/addon/mod/feedback/providers/show-entries-link-handler.ts +++ b/src/addon/mod/feedback/providers/show-entries-link-handler.ts @@ -15,10 +15,8 @@ import { Injectable } from '@angular/core'; import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler'; import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; -import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper'; import { AddonModFeedbackProvider } from './feedback'; -import { CoreCourseProvider } from '@core/course/providers/course'; -import { CoreDomUtilsProvider } from '@providers/utils/dom'; +import { AddonModFeedbackHelperProvider } from './helper'; /** * Content links handler for feedback show entries questions. @@ -30,8 +28,7 @@ export class AddonModFeedbackShowEntriesLinkHandler extends CoreContentLinksHand featureName = 'CoreCourseModuleDelegate_AddonModFeedback'; pattern = /\/mod\/feedback\/show_entries\.php.*([\?\&](id|showcompleted)=\d+)/; - constructor(private linkHelper: CoreContentLinksHelperProvider, private feedbackProvider: AddonModFeedbackProvider, - private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider) { + constructor(private feedbackProvider: AddonModFeedbackProvider, private feedbackHelper: AddonModFeedbackHelperProvider) { super(); } @@ -48,37 +45,7 @@ export class AddonModFeedbackShowEntriesLinkHandler extends CoreContentLinksHand CoreContentLinksAction[] | Promise { return [{ action: (siteId, navCtrl?): void => { - const modal = this.domUtils.showModalLoading(), - moduleId = params.id; - - this.courseProvider.getModuleBasicInfo(moduleId, siteId).then((module) => { - let stateParams; - - if (typeof params.showcompleted == 'undefined') { - // Param showcompleted not defined. Show entry list. - stateParams = { - moduleId: module.id, - module: module, - courseId: module.course - }; - - return this.linkHelper.goInSite(navCtrl, 'AddonModFeedbackRespondentsPage', stateParams, siteId); - } - - return this.feedbackProvider.getAttempt(module.instance, params.showcompleted, true, siteId).then((attempt) => { - stateParams = { - moduleId: module.id, - attempt: attempt, - attemptId: attempt.id, - feedbackId: module.instance, - courseId: module.course - }; - - return this.linkHelper.goInSite(navCtrl, 'AddonModFeedbackAttemptPage', stateParams, siteId); - }); - }).finally(() => { - modal.dismiss(); - }); + this.feedbackHelper.handleShowEntriesLink(navCtrl, params, siteId); } }]; }