MOBILE-2921 feedback: Support feedback push clicks

main
Dani Palou 2019-03-18 12:48:49 +01:00
parent 6536ffecad
commit 17ff0ec01a
4 changed files with 128 additions and 39 deletions

View File

@ -17,6 +17,7 @@ import { CoreCronDelegate } from '@providers/cron';
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate'; import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate'; import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate'; import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate';
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
import { AddonModFeedbackComponentsModule } from './components/components.module'; import { AddonModFeedbackComponentsModule } from './components/components.module';
import { AddonModFeedbackModuleHandler } from './providers/module-handler'; import { AddonModFeedbackModuleHandler } from './providers/module-handler';
import { AddonModFeedbackProvider } from './providers/feedback'; import { AddonModFeedbackProvider } from './providers/feedback';
@ -29,6 +30,7 @@ import { AddonModFeedbackPrintLinkHandler } from './providers/print-link-handler
import { AddonModFeedbackListLinkHandler } from './providers/list-link-handler'; import { AddonModFeedbackListLinkHandler } from './providers/list-link-handler';
import { AddonModFeedbackHelperProvider } from './providers/helper'; import { AddonModFeedbackHelperProvider } from './providers/helper';
import { AddonModFeedbackPrefetchHandler } from './providers/prefetch-handler'; import { AddonModFeedbackPrefetchHandler } from './providers/prefetch-handler';
import { AddonModFeedbackPushClickHandler } from './providers/push-click-handler';
import { AddonModFeedbackSyncProvider } from './providers/sync'; import { AddonModFeedbackSyncProvider } from './providers/sync';
import { AddonModFeedbackSyncCronHandler } from './providers/sync-cron-handler'; import { AddonModFeedbackSyncCronHandler } from './providers/sync-cron-handler';
import { AddonModFeedbackOfflineProvider } from './providers/offline'; import { AddonModFeedbackOfflineProvider } from './providers/offline';
@ -62,7 +64,8 @@ export const ADDON_MOD_FEEDBACK_PROVIDERS: any[] = [
AddonModFeedbackCompleteLinkHandler, AddonModFeedbackCompleteLinkHandler,
AddonModFeedbackPrintLinkHandler, AddonModFeedbackPrintLinkHandler,
AddonModFeedbackListLinkHandler, AddonModFeedbackListLinkHandler,
AddonModFeedbackSyncCronHandler AddonModFeedbackSyncCronHandler,
AddonModFeedbackPushClickHandler
] ]
}) })
export class AddonModFeedbackModule { export class AddonModFeedbackModule {
@ -74,7 +77,8 @@ export class AddonModFeedbackModule {
showEntriesLinkHandler: AddonModFeedbackShowEntriesLinkHandler, showEntriesLinkHandler: AddonModFeedbackShowEntriesLinkHandler,
showNonRespondentsLinkHandler: AddonModFeedbackShowNonRespondentsLinkHandler, showNonRespondentsLinkHandler: AddonModFeedbackShowNonRespondentsLinkHandler,
completeLinkHandler: AddonModFeedbackCompleteLinkHandler, completeLinkHandler: AddonModFeedbackCompleteLinkHandler,
printLinkHandler: AddonModFeedbackPrintLinkHandler, listLinkHandler: AddonModFeedbackListLinkHandler) { printLinkHandler: AddonModFeedbackPrintLinkHandler, listLinkHandler: AddonModFeedbackListLinkHandler,
pushNotificationsDelegate: CorePushNotificationsDelegate, pushClickHandler: AddonModFeedbackPushClickHandler) {
moduleDelegate.registerHandler(moduleHandler); moduleDelegate.registerHandler(moduleHandler);
prefetchDelegate.registerHandler(prefetchHandler); prefetchDelegate.registerHandler(prefetchHandler);
@ -86,6 +90,7 @@ export class AddonModFeedbackModule {
contentLinksDelegate.registerHandler(printLinkHandler); contentLinksDelegate.registerHandler(printLinkHandler);
contentLinksDelegate.registerHandler(listLinkHandler); contentLinksDelegate.registerHandler(listLinkHandler);
cronDelegate.register(syncHandler); cronDelegate.register(syncHandler);
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
// Allow migrating the tables from the old app to the new schema. // Allow migrating the tables from the old app to the new schema.
updateManager.registerSiteTableMigration({ updateManager.registerSiteTableMigration({

View File

@ -16,6 +16,10 @@ import { Injectable } from '@angular/core';
import { NavController, ViewController } from 'ionic-angular'; import { NavController, ViewController } from 'ionic-angular';
import { AddonModFeedbackProvider } from './feedback'; import { AddonModFeedbackProvider } from './feedback';
import { CoreUserProvider } from '@core/user/providers/user'; 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 { CoreTextUtilsProvider } from '@providers/utils/text';
import { CoreTimeUtilsProvider } from '@providers/utils/time'; import { CoreTimeUtilsProvider } from '@providers/utils/time';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
@ -32,7 +36,9 @@ export class AddonModFeedbackHelperProvider {
constructor(protected feedbackProvider: AddonModFeedbackProvider, protected userProvider: CoreUserProvider, constructor(protected feedbackProvider: AddonModFeedbackProvider, protected userProvider: CoreUserProvider,
protected textUtils: CoreTextUtilsProvider, protected translate: TranslateService, 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<any>} Promise resolved when done.
*/
handleShowEntriesLink(navCtrl: NavController, params: any, siteId?: string): Promise<any> {
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 * Add Image profile url field on attempts
* *

View File

@ -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<boolean> {
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<any>} Promise resolved when done.
*/
handleClick(notification: any): Promise<any> {
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);
}
}
}

View File

@ -15,10 +15,8 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler'; import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate'; import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
import { AddonModFeedbackProvider } from './feedback'; import { AddonModFeedbackProvider } from './feedback';
import { CoreCourseProvider } from '@core/course/providers/course'; import { AddonModFeedbackHelperProvider } from './helper';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
/** /**
* Content links handler for feedback show entries questions. * Content links handler for feedback show entries questions.
@ -30,8 +28,7 @@ export class AddonModFeedbackShowEntriesLinkHandler extends CoreContentLinksHand
featureName = 'CoreCourseModuleDelegate_AddonModFeedback'; featureName = 'CoreCourseModuleDelegate_AddonModFeedback';
pattern = /\/mod\/feedback\/show_entries\.php.*([\?\&](id|showcompleted)=\d+)/; pattern = /\/mod\/feedback\/show_entries\.php.*([\?\&](id|showcompleted)=\d+)/;
constructor(private linkHelper: CoreContentLinksHelperProvider, private feedbackProvider: AddonModFeedbackProvider, constructor(private feedbackProvider: AddonModFeedbackProvider, private feedbackHelper: AddonModFeedbackHelperProvider) {
private courseProvider: CoreCourseProvider, private domUtils: CoreDomUtilsProvider) {
super(); super();
} }
@ -48,37 +45,7 @@ export class AddonModFeedbackShowEntriesLinkHandler extends CoreContentLinksHand
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> { CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
return [{ return [{
action: (siteId, navCtrl?): void => { action: (siteId, navCtrl?): void => {
const modal = this.domUtils.showModalLoading(), this.feedbackHelper.handleShowEntriesLink(navCtrl, params, siteId);
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();
});
} }
}]; }];
} }