commit
3f3e9d3d25
|
@ -17,8 +17,10 @@ import { AddonBadgesProvider } from './providers/badges';
|
|||
import { AddonBadgesUserHandler } from './providers/user-handler';
|
||||
import { AddonBadgesMyBadgesLinkHandler } from './providers/mybadges-link-handler';
|
||||
import { AddonBadgesBadgeLinkHandler } from './providers/badge-link-handler';
|
||||
import { AddonBadgesPushClickHandler } from './providers/push-click-handler';
|
||||
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
||||
import { CoreUserDelegate } from '@core/user/providers/user-delegate';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
|
||||
// List of providers (without handlers).
|
||||
export const ADDON_BADGES_PROVIDERS: any[] = [
|
||||
|
@ -34,16 +36,19 @@ export const ADDON_BADGES_PROVIDERS: any[] = [
|
|||
AddonBadgesProvider,
|
||||
AddonBadgesUserHandler,
|
||||
AddonBadgesMyBadgesLinkHandler,
|
||||
AddonBadgesBadgeLinkHandler
|
||||
AddonBadgesBadgeLinkHandler,
|
||||
AddonBadgesPushClickHandler
|
||||
]
|
||||
})
|
||||
export class AddonBadgesModule {
|
||||
constructor(userDelegate: CoreUserDelegate, userHandler: AddonBadgesUserHandler,
|
||||
contentLinksDelegate: CoreContentLinksDelegate, myBadgesLinkHandler: AddonBadgesMyBadgesLinkHandler,
|
||||
badgeLinkHandler: AddonBadgesBadgeLinkHandler) {
|
||||
badgeLinkHandler: AddonBadgesBadgeLinkHandler,
|
||||
pushNotificationsDelegate: CorePushNotificationsDelegate, pushClickHandler: AddonBadgesPushClickHandler) {
|
||||
|
||||
userDelegate.registerHandler(userHandler);
|
||||
contentLinksDelegate.registerHandler(myBadgesLinkHandler);
|
||||
contentLinksDelegate.registerHandler(badgeLinkHandler);
|
||||
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
// (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 { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate';
|
||||
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||
import { AddonBadgesProvider } from './badges';
|
||||
|
||||
/**
|
||||
* Handler for badges push notifications clicks.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonBadgesPushClickHandler implements CorePushNotificationsClickHandler {
|
||||
name = 'AddonBadgesPushClickHandler';
|
||||
priority = 200;
|
||||
featureName = 'CoreUserDelegate_AddonBadges';
|
||||
|
||||
constructor(private utils: CoreUtilsProvider, private badgesProvider: AddonBadgesProvider,
|
||||
private loginHelper: CoreLoginHelperProvider) {}
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
// @todo: Support 'badgecreatornotice' once we receive the hash or contexturl.
|
||||
if (this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'moodle' &&
|
||||
notification.name == 'badgerecipientnotice') {
|
||||
return this.badgesProvider.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> {
|
||||
// @todo: Go to the badge page once we receive the hash or contexturl.
|
||||
|
||||
return this.badgesProvider.invalidateUserBadges(0, Number(notification.usertoid), notification.site).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
return this.loginHelper.redirect('AddonBadgesUserBadgesPage', {}, notification.site);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -18,10 +18,17 @@ import { AddonCompetencyHelperProvider } from './providers/helper';
|
|||
import { AddonCompetencyCourseOptionHandler } from './providers/course-option-handler';
|
||||
import { AddonCompetencyMainMenuHandler } from './providers/mainmenu-handler';
|
||||
import { AddonCompetencyUserHandler } from './providers/user-handler';
|
||||
import { AddonCompetencyCompetencyLinkHandler } from './providers/competency-link-handler';
|
||||
import { AddonCompetencyPlanLinkHandler } from './providers/plan-link-handler';
|
||||
import { AddonCompetencyPlansLinkHandler } from './providers/plans-link-handler';
|
||||
import { AddonCompetencyUserCompetencyLinkHandler } from './providers/user-competency-link-handler';
|
||||
import { AddonCompetencyPushClickHandler } from './providers/push-click-handler';
|
||||
import { AddonCompetencyComponentsModule } from './components/components.module';
|
||||
import { CoreCourseOptionsDelegate } from '@core/course/providers/options-delegate';
|
||||
import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
|
||||
import { CoreUserDelegate } from '@core/user/providers/user-delegate';
|
||||
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
|
||||
// List of providers (without handlers).
|
||||
export const ADDON_COMPETENCY_PROVIDERS: any[] = [
|
||||
|
@ -40,16 +47,30 @@ export const ADDON_COMPETENCY_PROVIDERS: any[] = [
|
|||
AddonCompetencyHelperProvider,
|
||||
AddonCompetencyCourseOptionHandler,
|
||||
AddonCompetencyMainMenuHandler,
|
||||
AddonCompetencyUserHandler
|
||||
AddonCompetencyUserHandler,
|
||||
AddonCompetencyCompetencyLinkHandler,
|
||||
AddonCompetencyPlanLinkHandler,
|
||||
AddonCompetencyPlansLinkHandler,
|
||||
AddonCompetencyUserCompetencyLinkHandler,
|
||||
AddonCompetencyPushClickHandler
|
||||
]
|
||||
})
|
||||
export class AddonCompetencyModule {
|
||||
constructor(mainMenuDelegate: CoreMainMenuDelegate, mainMenuHandler: AddonCompetencyMainMenuHandler,
|
||||
courseOptionsDelegate: CoreCourseOptionsDelegate, courseOptionHandler: AddonCompetencyCourseOptionHandler,
|
||||
userDelegate: CoreUserDelegate, userHandler: AddonCompetencyUserHandler) {
|
||||
userDelegate: CoreUserDelegate, userHandler: AddonCompetencyUserHandler,
|
||||
contentLinksDelegate: CoreContentLinksDelegate, competencyLinkHandler: AddonCompetencyCompetencyLinkHandler,
|
||||
planLinkHandler: AddonCompetencyPlanLinkHandler, plansLinkHandler: AddonCompetencyPlansLinkHandler,
|
||||
userComptencyLinkHandler: AddonCompetencyUserCompetencyLinkHandler,
|
||||
pushNotificationsDelegate: CorePushNotificationsDelegate, pushClickHandler: AddonCompetencyPushClickHandler) {
|
||||
|
||||
mainMenuDelegate.registerHandler(mainMenuHandler);
|
||||
courseOptionsDelegate.registerHandler(courseOptionHandler);
|
||||
userDelegate.registerHandler(userHandler);
|
||||
contentLinksDelegate.registerHandler(competencyLinkHandler);
|
||||
contentLinksDelegate.registerHandler(planLinkHandler);
|
||||
contentLinksDelegate.registerHandler(plansLinkHandler);
|
||||
contentLinksDelegate.registerHandler(userComptencyLinkHandler);
|
||||
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
// (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 { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
import { AddonCompetencyProvider } from './competency';
|
||||
|
||||
/**
|
||||
* Handler to treat links to a competency in a plan or in a course.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonCompetencyCompetencyLinkHandler extends CoreContentLinksHandlerBase {
|
||||
name = 'AddonCompetencyCompetencyLinkHandler';
|
||||
pattern = /\/admin\/tool\/lp\/(user_competency_in_course|user_competency_in_plan)\.php/;
|
||||
|
||||
constructor(private linkHelper: CoreContentLinksHelperProvider, private competencyProvider: AddonCompetencyProvider) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of actions for a link (url).
|
||||
*
|
||||
* @param {string[]} siteIds List of sites the URL belongs to.
|
||||
* @param {string} url The URL to treat.
|
||||
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
|
||||
*/
|
||||
getActions(siteIds: string[], url: string, params: any, courseId?: number):
|
||||
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||
courseId = courseId || params.courseid || params.cid;
|
||||
|
||||
return [{
|
||||
action: (siteId, navCtrl?): void => {
|
||||
this.linkHelper.goInSite(navCtrl, 'AddonCompetencyCompetencyPage', {
|
||||
planId: params.planid,
|
||||
competencyId: params.competencyid,
|
||||
courseId: courseId,
|
||||
userId: params.userid
|
||||
}, siteId);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||
* If not defined, defaults to true.
|
||||
*
|
||||
* @param {string} siteId The site ID.
|
||||
* @param {string} url The URL to treat.
|
||||
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||
* @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site.
|
||||
*/
|
||||
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
|
||||
// Handler is disabled if all competency features are disabled.
|
||||
return this.competencyProvider.allCompetenciesDisabled(siteId).then((disabled) => {
|
||||
return !disabled;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -42,6 +42,20 @@ export class AddonCompetencyProvider {
|
|||
this.logger = loggerProvider.getInstance('AddonCompetencyProvider');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if all competencies features are disabled.
|
||||
*
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<boolean>} Promise resolved with boolean: whether all competency features are disabled.
|
||||
*/
|
||||
allCompetenciesDisabled(siteId?: string): Promise<boolean> {
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
return site.isFeatureDisabled('CoreMainMenuDelegate_AddonCompetency') &&
|
||||
site.isFeatureDisabled('CoreCourseOptionsDelegate_AddonCompetency') &&
|
||||
site.isFeatureDisabled('CoreUserDelegate_AddonCompetency');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache key for user learning plans data WS calls.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
// (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 { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
import { AddonCompetencyProvider } from './competency';
|
||||
|
||||
/**
|
||||
* Handler to treat links to a plan.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonCompetencyPlanLinkHandler extends CoreContentLinksHandlerBase {
|
||||
name = 'AddonCompetencyPlanLinkHandler';
|
||||
pattern = /\/admin\/tool\/lp\/plan\.php.*([\?\&]id=\d+)/;
|
||||
|
||||
constructor(private linkHelper: CoreContentLinksHelperProvider, private competencyProvider: AddonCompetencyProvider) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of actions for a link (url).
|
||||
*
|
||||
* @param {string[]} siteIds List of sites the URL belongs to.
|
||||
* @param {string} url The URL to treat.
|
||||
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
|
||||
*/
|
||||
getActions(siteIds: string[], url: string, params: any, courseId?: number):
|
||||
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||
|
||||
return [{
|
||||
action: (siteId, navCtrl?): void => {
|
||||
this.linkHelper.goInSite(navCtrl, 'AddonCompetencyPlanPage', { planId: params.id }, siteId);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||
* If not defined, defaults to true.
|
||||
*
|
||||
* @param {string} siteId The site ID.
|
||||
* @param {string} url The URL to treat.
|
||||
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||
* @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site.
|
||||
*/
|
||||
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
|
||||
// Handler is disabled if all competency features are disabled.
|
||||
return this.competencyProvider.allCompetenciesDisabled(siteId).then((disabled) => {
|
||||
return !disabled;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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 { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||
import { AddonCompetencyProvider } from './competency';
|
||||
|
||||
/**
|
||||
* Handler to treat links to user plans.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonCompetencyPlansLinkHandler extends CoreContentLinksHandlerBase {
|
||||
name = 'AddonCompetencyPlansLinkHandler';
|
||||
pattern = /\/admin\/tool\/lp\/plans\.php/;
|
||||
|
||||
constructor(private loginHelper: CoreLoginHelperProvider, private competencyProvider: AddonCompetencyProvider) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of actions for a link (url).
|
||||
*
|
||||
* @param {string[]} siteIds List of sites the URL belongs to.
|
||||
* @param {string} url The URL to treat.
|
||||
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
|
||||
*/
|
||||
getActions(siteIds: string[], url: string, params: any, courseId?: number):
|
||||
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||
|
||||
return [{
|
||||
action: (siteId, navCtrl?): void => {
|
||||
// Always use redirect to make it the new history root (to avoid "loops" in history).
|
||||
this.loginHelper.redirect('AddonCompetencyPlanListPage', { userId: params.userid }, siteId);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||
* If not defined, defaults to true.
|
||||
*
|
||||
* @param {string} siteId The site ID.
|
||||
* @param {string} url The URL to treat.
|
||||
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||
* @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site.
|
||||
*/
|
||||
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
|
||||
// Handler is disabled if all competency features are disabled.
|
||||
return this.competencyProvider.allCompetenciesDisabled(siteId).then((disabled) => {
|
||||
return !disabled;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
// (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 { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||
import { AddonCompetencyProvider } from './competency';
|
||||
|
||||
/**
|
||||
* Handler for competencies push notifications clicks.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonCompetencyPushClickHandler implements CorePushNotificationsClickHandler {
|
||||
name = 'AddonCompetencyPushClickHandler';
|
||||
priority = 200;
|
||||
|
||||
constructor(private utils: CoreUtilsProvider, private urlUtils: CoreUrlUtilsProvider,
|
||||
private competencyProvider: AddonCompetencyProvider, private loginHelper: CoreLoginHelperProvider) {}
|
||||
|
||||
/**
|
||||
* 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 == 'moodle' &&
|
||||
(notification.name == 'competencyplancomment' || notification.name == 'competencyusercompcomment')) {
|
||||
// If all competency features are disabled, don't handle the click.
|
||||
return this.competencyProvider.allCompetenciesDisabled(notification.site).then((disabled) => {
|
||||
return !disabled;
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (notification.name == 'competencyplancomment') {
|
||||
// Open the learning plan.
|
||||
const planId = Number(contextUrlParams.id);
|
||||
|
||||
return this.competencyProvider.invalidateLearningPlan(planId, notification.site).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
return this.loginHelper.redirect('AddonCompetencyPlanPage', { planId: planId }, notification.site);
|
||||
});
|
||||
} else {
|
||||
|
||||
if (notification.contexturl && notification.contexturl.indexOf('user_competency_in_plan.php') != -1) {
|
||||
// Open the competency.
|
||||
const courseId = Number(notification.course),
|
||||
competencyId = Number(contextUrlParams.competencyid),
|
||||
planId = Number(contextUrlParams.planid),
|
||||
userId = Number(contextUrlParams.userid);
|
||||
|
||||
return this.competencyProvider.invalidateCompetencyInPlan(planId, competencyId, notification.site).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
return this.loginHelper.redirect('AddonCompetencyCompetencyPage', {
|
||||
planId: planId,
|
||||
competencyId: competencyId,
|
||||
courseId: courseId,
|
||||
userId: userId
|
||||
}, notification.site);
|
||||
});
|
||||
} else {
|
||||
// Open the list of plans.
|
||||
const userId = Number(contextUrlParams.userid);
|
||||
|
||||
return this.competencyProvider.invalidateLearningPlans(userId, notification.site).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
return this.loginHelper.redirect('AddonCompetencyPlanListPage', { userId: userId }, notification.site);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
// (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 { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
import { AddonCompetencyProvider } from './competency';
|
||||
|
||||
/**
|
||||
* Handler to treat links to a usr competency.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonCompetencyUserCompetencyLinkHandler extends CoreContentLinksHandlerBase {
|
||||
name = 'AddonCompetencyUserCompetencyLinkHandler';
|
||||
pattern = /\/admin\/tool\/lp\/user_competency\.php.*([\?\&]id=\d+)/;
|
||||
|
||||
constructor(private linkHelper: CoreContentLinksHelperProvider, private competencyProvider: AddonCompetencyProvider) {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of actions for a link (url).
|
||||
*
|
||||
* @param {string[]} siteIds List of sites the URL belongs to.
|
||||
* @param {string} url The URL to treat.
|
||||
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
|
||||
*/
|
||||
getActions(siteIds: string[], url: string, params: any, courseId?: number):
|
||||
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||
|
||||
return [{
|
||||
action: (siteId, navCtrl?): void => {
|
||||
this.linkHelper.goInSite(navCtrl, 'AddonCompetencyCompetencySummaryPage', { competencyId: params.id }, siteId);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||
* If not defined, defaults to true.
|
||||
*
|
||||
* @param {string} siteId The site ID.
|
||||
* @param {string} url The URL to treat.
|
||||
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||
* @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site.
|
||||
*/
|
||||
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
|
||||
// Handler is disabled if all competency features are disabled.
|
||||
return this.competencyProvider.allCompetenciesDisabled(siteId).then((disabled) => {
|
||||
return !disabled;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
import { Component, OnDestroy } from '@angular/core';
|
||||
import { IonicPage } from 'ionic-angular';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications';
|
||||
import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications';
|
||||
import { AddonMessageOutputAirnotifierProvider } from '../../providers/airnotifier';
|
||||
|
||||
/**
|
||||
|
@ -34,7 +34,7 @@ export class AddonMessageOutputAirnotifierDevicesPage implements OnDestroy {
|
|||
protected updateTimeout: any;
|
||||
|
||||
constructor(private domUtils: CoreDomUtilsProvider, private airnotifierProivder: AddonMessageOutputAirnotifierProvider,
|
||||
private pushNotificationsProvider: AddonPushNotificationsProvider ) {
|
||||
private pushNotificationsProvider: CorePushNotificationsProvider ) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,7 +21,7 @@ import { AddonMessagesProvider } from '../../providers/messages';
|
|||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreAppProvider } from '@providers/app';
|
||||
import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
|
||||
/**
|
||||
* Component that displays the list of discussions.
|
||||
|
@ -54,7 +54,7 @@ export class AddonMessagesDiscussionsComponent implements OnDestroy {
|
|||
constructor(private eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider, translate: TranslateService,
|
||||
private messagesProvider: AddonMessagesProvider, private domUtils: CoreDomUtilsProvider, navParams: NavParams,
|
||||
private appProvider: CoreAppProvider, platform: Platform, private utils: CoreUtilsProvider,
|
||||
pushNotificationsDelegate: AddonPushNotificationsDelegate) {
|
||||
pushNotificationsDelegate: CorePushNotificationsDelegate) {
|
||||
|
||||
this.search.loading = translate.instant('core.searching');
|
||||
this.loadingMessages = translate.instant('core.loading');
|
||||
|
|
|
@ -29,13 +29,14 @@ import { AddonMessagesContactRequestLinkHandler } from './providers/contact-requ
|
|||
import { AddonMessagesDiscussionLinkHandler } from './providers/discussion-link-handler';
|
||||
import { AddonMessagesIndexLinkHandler } from './providers/index-link-handler';
|
||||
import { AddonMessagesSyncCronHandler } from './providers/sync-cron-handler';
|
||||
import { AddonMessagesPushClickHandler } from './providers/push-click-handler';
|
||||
import { CoreAppProvider } from '@providers/app';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
import { CoreSettingsDelegate } from '@core/settings/providers/delegate';
|
||||
import { AddonMessagesSettingsHandler } from './providers/settings-handler';
|
||||
import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreUpdateManagerProvider } from '@providers/update-manager';
|
||||
|
||||
|
@ -63,7 +64,8 @@ export const ADDON_MESSAGES_PROVIDERS: any[] = [
|
|||
AddonMessagesDiscussionLinkHandler,
|
||||
AddonMessagesIndexLinkHandler,
|
||||
AddonMessagesSyncCronHandler,
|
||||
AddonMessagesSettingsHandler
|
||||
AddonMessagesSettingsHandler,
|
||||
AddonMessagesPushClickHandler
|
||||
]
|
||||
})
|
||||
export class AddonMessagesModule {
|
||||
|
@ -75,9 +77,9 @@ export class AddonMessagesModule {
|
|||
localNotifications: CoreLocalNotificationsProvider, messagesProvider: AddonMessagesProvider,
|
||||
sitesProvider: CoreSitesProvider, linkHelper: CoreContentLinksHelperProvider, updateManager: CoreUpdateManagerProvider,
|
||||
settingsHandler: AddonMessagesSettingsHandler, settingsDelegate: CoreSettingsDelegate,
|
||||
pushNotificationsDelegate: AddonPushNotificationsDelegate, utils: CoreUtilsProvider,
|
||||
pushNotificationsDelegate: CorePushNotificationsDelegate, utils: CoreUtilsProvider,
|
||||
addContactHandler: AddonMessagesAddContactUserHandler, blockContactHandler: AddonMessagesBlockContactUserHandler,
|
||||
contactRequestLinkHandler: AddonMessagesContactRequestLinkHandler) {
|
||||
contactRequestLinkHandler: AddonMessagesContactRequestLinkHandler, pushClickHandler: AddonMessagesPushClickHandler) {
|
||||
// Register handlers.
|
||||
mainMenuDelegate.registerHandler(mainmenuHandler);
|
||||
contentLinksDelegate.registerHandler(indexLinkHandler);
|
||||
|
@ -89,6 +91,7 @@ export class AddonMessagesModule {
|
|||
cronDelegate.register(syncHandler);
|
||||
cronDelegate.register(mainmenuHandler);
|
||||
settingsDelegate.registerHandler(settingsHandler);
|
||||
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
|
||||
|
||||
// Sync some discussions when device goes online.
|
||||
network.onConnect().subscribe(() => {
|
||||
|
@ -134,18 +137,6 @@ export class AddonMessagesModule {
|
|||
localNotifications.registerClick(AddonMessagesProvider.PUSH_SIMULATION_COMPONENT, notificationClicked);
|
||||
}
|
||||
|
||||
// Register push notification clicks.
|
||||
pushNotificationsDelegate.on('click').subscribe((notification) => {
|
||||
if (utils.isFalseOrZero(notification.notif)) {
|
||||
// Execute the callback in the Angular zone, so change detection doesn't stop working.
|
||||
zone.run(() => {
|
||||
notificationClicked(notification);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// Allow migrating the table from the old app to the new schema.
|
||||
updateManager.registerSiteTableMigration({
|
||||
name: 'mma_messages_offline_messages',
|
||||
|
|
|
@ -21,7 +21,7 @@ import { AddonMessagesProvider } from '../../providers/messages';
|
|||
import { AddonMessagesOfflineProvider } from '../../providers/messages-offline';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
import { CoreSplitViewComponent } from '@components/split-view/split-view';
|
||||
import { CoreUserProvider } from '@core/user/providers/user';
|
||||
|
||||
|
@ -84,7 +84,7 @@ export class AddonMessagesGroupConversationsPage implements OnInit, OnDestroy {
|
|||
constructor(eventsProvider: CoreEventsProvider, sitesProvider: CoreSitesProvider, translate: TranslateService,
|
||||
private messagesProvider: AddonMessagesProvider, private domUtils: CoreDomUtilsProvider, navParams: NavParams,
|
||||
private navCtrl: NavController, platform: Platform, private utils: CoreUtilsProvider,
|
||||
pushNotificationsDelegate: AddonPushNotificationsDelegate, private messagesOffline: AddonMessagesOfflineProvider,
|
||||
pushNotificationsDelegate: CorePushNotificationsDelegate, private messagesOffline: AddonMessagesOfflineProvider,
|
||||
private userProvider: CoreUserProvider) {
|
||||
|
||||
this.loadingString = translate.instant('core.loading');
|
||||
|
|
|
@ -22,8 +22,8 @@ import { CoreAppProvider } from '@providers/app';
|
|||
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
|
||||
import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications';
|
||||
import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate';
|
||||
import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
import { CoreEmulatorHelperProvider } from '@core/emulator/providers/helper';
|
||||
|
||||
/**
|
||||
|
@ -50,8 +50,8 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr
|
|||
constructor(private messagesProvider: AddonMessagesProvider, private sitesProvider: CoreSitesProvider,
|
||||
eventsProvider: CoreEventsProvider, private appProvider: CoreAppProvider,
|
||||
private localNotificationsProvider: CoreLocalNotificationsProvider, private textUtils: CoreTextUtilsProvider,
|
||||
private pushNotificationsProvider: AddonPushNotificationsProvider, utils: CoreUtilsProvider,
|
||||
pushNotificationsDelegate: AddonPushNotificationsDelegate, private emulatorHelper: CoreEmulatorHelperProvider) {
|
||||
private pushNotificationsProvider: CorePushNotificationsProvider, utils: CoreUtilsProvider,
|
||||
pushNotificationsDelegate: CorePushNotificationsDelegate, private emulatorHelper: CoreEmulatorHelperProvider) {
|
||||
|
||||
eventsProvider.on(AddonMessagesProvider.UNREAD_CONVERSATION_COUNTS_EVENT, (data) => {
|
||||
this.unreadCount = data.favourites + data.individual + data.group;
|
||||
|
@ -76,7 +76,8 @@ export class AddonMessagesMainMenuHandler implements CoreMainMenuHandler, CoreCr
|
|||
// If a message push notification is received, refresh the count.
|
||||
pushNotificationsDelegate.on('receive').subscribe((notification) => {
|
||||
// New message received. If it's from current site, refresh the data.
|
||||
if (utils.isFalseOrZero(notification.notif) && this.sitesProvider.isCurrentSite(notification.site)) {
|
||||
const isMessage = utils.isFalseOrZero(notification.notif) || notification.name == 'messagecontactrequests';
|
||||
if (isMessage && this.sitesProvider.isCurrentSite(notification.site)) {
|
||||
this.refreshBadge(notification.site);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1863,16 +1863,19 @@ export class AddonMessagesProvider {
|
|||
/**
|
||||
* Mark message as read.
|
||||
*
|
||||
* @param {number} messageId ID of message to mark as read
|
||||
* @param {number} messageId ID of message to mark as read
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @returns {Promise<any>} Promise resolved with boolean marking success or not.
|
||||
*/
|
||||
markMessageRead(messageId: number): Promise<any> {
|
||||
const params = {
|
||||
messageid: messageId,
|
||||
timeread: this.timeUtils.timestamp()
|
||||
};
|
||||
markMessageRead(messageId: number, siteId?: string): Promise<any> {
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
const params = {
|
||||
messageid: messageId,
|
||||
timeread: this.timeUtils.timestamp()
|
||||
};
|
||||
|
||||
return this.sitesProvider.getCurrentSite().write('core_message_mark_message_read', params);
|
||||
return site.write('core_message_mark_message_read', params);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
// (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 { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate';
|
||||
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||
import { AddonMessagesProvider } from './messages';
|
||||
|
||||
/**
|
||||
* Handler for messaging push notifications clicks.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonMessagesPushClickHandler implements CorePushNotificationsClickHandler {
|
||||
name = 'AddonMessagesPushClickHandler';
|
||||
priority = 200;
|
||||
featureName = 'CoreMainMenuDelegate_AddonMessages';
|
||||
|
||||
constructor(private utils: CoreUtilsProvider, private messagesProvider: AddonMessagesProvider,
|
||||
private loginHelper: CoreLoginHelperProvider) {}
|
||||
|
||||
/**
|
||||
* 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.name != 'messagecontactrequests') {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that messaging is enabled.
|
||||
return this.messagesProvider.isPluginEnabled(notification.site);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the notification click.
|
||||
*
|
||||
* @param {any} notification The notification to check.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
handleClick(notification: any): Promise<any> {
|
||||
return this.messagesProvider.invalidateDiscussionsCache(notification.site).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
// Check if group messaging is enabled, to determine which page should be loaded.
|
||||
return this.messagesProvider.isGroupMessagingEnabledInSite(notification.site).then((enabled) => {
|
||||
const pageParams: any = {};
|
||||
let pageName = 'AddonMessagesIndexPage';
|
||||
if (enabled) {
|
||||
pageName = 'AddonMessagesGroupConversationsPage';
|
||||
}
|
||||
|
||||
// Check if we have enough information to open the conversation.
|
||||
if (notification.convid && enabled) {
|
||||
pageParams.conversationId = Number(notification.convid);
|
||||
} else if (notification.userfromid) {
|
||||
pageParams.discussionUserId = Number(notification.userfromid);
|
||||
}
|
||||
|
||||
return this.loginHelper.redirect(pageName, pageParams, notification.site);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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 { AddonModAssignProvider } from './providers/assign';
|
||||
import { AddonModAssignOfflineProvider } from './providers/assign-offline';
|
||||
import { AddonModAssignSyncProvider } from './providers/assign-sync';
|
||||
|
@ -30,6 +31,7 @@ import { AddonModAssignPrefetchHandler } from './providers/prefetch-handler';
|
|||
import { AddonModAssignSyncCronHandler } from './providers/sync-cron-handler';
|
||||
import { AddonModAssignIndexLinkHandler } from './providers/index-link-handler';
|
||||
import { AddonModAssignListLinkHandler } from './providers/list-link-handler';
|
||||
import { AddonModAssignPushClickHandler } from './providers/push-click-handler';
|
||||
import { AddonModAssignSubmissionModule } from './submission/submission.module';
|
||||
import { AddonModAssignFeedbackModule } from './feedback/feedback.module';
|
||||
import { CoreUpdateManagerProvider } from '@providers/update-manager';
|
||||
|
@ -64,7 +66,8 @@ export const ADDON_MOD_ASSIGN_PROVIDERS: any[] = [
|
|||
AddonModAssignPrefetchHandler,
|
||||
AddonModAssignSyncCronHandler,
|
||||
AddonModAssignIndexLinkHandler,
|
||||
AddonModAssignListLinkHandler
|
||||
AddonModAssignListLinkHandler,
|
||||
AddonModAssignPushClickHandler
|
||||
]
|
||||
})
|
||||
export class AddonModAssignModule {
|
||||
|
@ -72,13 +75,15 @@ export class AddonModAssignModule {
|
|||
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModAssignPrefetchHandler,
|
||||
cronDelegate: CoreCronDelegate, syncHandler: AddonModAssignSyncCronHandler, updateManager: CoreUpdateManagerProvider,
|
||||
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModAssignIndexLinkHandler,
|
||||
listLinkHandler: AddonModAssignListLinkHandler) {
|
||||
listLinkHandler: AddonModAssignListLinkHandler, pushNotificationsDelegate: CorePushNotificationsDelegate,
|
||||
pushClickHandler: AddonModAssignPushClickHandler) {
|
||||
|
||||
moduleDelegate.registerHandler(moduleHandler);
|
||||
prefetchDelegate.registerHandler(prefetchHandler);
|
||||
cronDelegate.register(syncHandler);
|
||||
contentLinksDelegate.registerHandler(linkHandler);
|
||||
contentLinksDelegate.registerHandler(listLinkHandler);
|
||||
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
|
||||
|
||||
// Allow migrating the tables from the old app to the new schema.
|
||||
updateManager.registerSiteTablesMigration([
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
// (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 { AddonModAssignProvider } from './assign';
|
||||
|
||||
/**
|
||||
* Handler for assign push notifications clicks.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonModAssignPushClickHandler implements CorePushNotificationsClickHandler {
|
||||
name = 'AddonModAssignPushClickHandler';
|
||||
priority = 200;
|
||||
featureName = 'CoreCourseModuleDelegate_AddonModAssign';
|
||||
|
||||
constructor(private utils: CoreUtilsProvider, private assignProvider: AddonModAssignProvider,
|
||||
private urlUtils: CoreUrlUtilsProvider, private courseHelper: CoreCourseHelperProvider) {}
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
return this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_assign' &&
|
||||
notification.name == 'assign_notification';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
return this.assignProvider.invalidateContent(moduleId, courseId, notification.site).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
return this.courseHelper.navigateToModule(moduleId, notification.site, courseId);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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({
|
||||
|
|
|
@ -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<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
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<CoreContentLinksAction[]> {
|
||||
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);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import { CoreCronDelegate } from '@providers/cron';
|
|||
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
|
||||
import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate';
|
||||
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
import { AddonModForumProvider } from './providers/forum';
|
||||
import { AddonModForumOfflineProvider } from './providers/offline';
|
||||
import { AddonModForumHelperProvider } from './providers/helper';
|
||||
|
@ -27,6 +28,7 @@ import { AddonModForumSyncCronHandler } from './providers/sync-cron-handler';
|
|||
import { AddonModForumIndexLinkHandler } from './providers/index-link-handler';
|
||||
import { AddonModForumDiscussionLinkHandler } from './providers/discussion-link-handler';
|
||||
import { AddonModForumListLinkHandler } from './providers/list-link-handler';
|
||||
import { AddonModForumPushClickHandler } from './providers/push-click-handler';
|
||||
import { AddonModForumComponentsModule } from './components/components.module';
|
||||
import { CoreUpdateManagerProvider } from '@providers/update-manager';
|
||||
|
||||
|
@ -54,7 +56,8 @@ export const ADDON_MOD_FORUM_PROVIDERS: any[] = [
|
|||
AddonModForumSyncCronHandler,
|
||||
AddonModForumIndexLinkHandler,
|
||||
AddonModForumListLinkHandler,
|
||||
AddonModForumDiscussionLinkHandler
|
||||
AddonModForumDiscussionLinkHandler,
|
||||
AddonModForumPushClickHandler
|
||||
]
|
||||
})
|
||||
export class AddonModForumModule {
|
||||
|
@ -62,7 +65,8 @@ export class AddonModForumModule {
|
|||
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModForumPrefetchHandler,
|
||||
cronDelegate: CoreCronDelegate, syncHandler: AddonModForumSyncCronHandler, linksDelegate: CoreContentLinksDelegate,
|
||||
indexHandler: AddonModForumIndexLinkHandler, discussionHandler: AddonModForumDiscussionLinkHandler,
|
||||
updateManager: CoreUpdateManagerProvider, listLinkHandler: AddonModForumListLinkHandler) {
|
||||
updateManager: CoreUpdateManagerProvider, listLinkHandler: AddonModForumListLinkHandler,
|
||||
pushNotificationsDelegate: CorePushNotificationsDelegate, pushClickHandler: AddonModForumPushClickHandler) {
|
||||
|
||||
moduleDelegate.registerHandler(moduleHandler);
|
||||
prefetchDelegate.registerHandler(prefetchHandler);
|
||||
|
@ -70,6 +74,7 @@ export class AddonModForumModule {
|
|||
linksDelegate.registerHandler(indexHandler);
|
||||
linksDelegate.registerHandler(discussionHandler);
|
||||
linksDelegate.registerHandler(listLinkHandler);
|
||||
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
|
||||
|
||||
// Allow migrating the tables from the old app to the new schema.
|
||||
updateManager.registerSiteTablesMigration([
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
// (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 { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
import { AddonModForumProvider } from './forum';
|
||||
|
||||
/**
|
||||
* Handler for forum push notifications clicks.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonModForumPushClickHandler implements CorePushNotificationsClickHandler {
|
||||
name = 'AddonModForumPushClickHandler';
|
||||
priority = 200;
|
||||
featureName = 'CoreCourseModuleDelegate_AddonModForum';
|
||||
|
||||
constructor(private utils: CoreUtilsProvider, private forumProvider: AddonModForumProvider,
|
||||
private urlUtils: CoreUrlUtilsProvider, private linkHelper: CoreContentLinksHelperProvider) {}
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
return this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_forum' &&
|
||||
notification.name == 'posts';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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),
|
||||
pageParams: any = {
|
||||
courseId: Number(notification.courseid),
|
||||
discussionId: Number(contextUrlParams.d),
|
||||
};
|
||||
|
||||
if (contextUrlParams.urlHash) {
|
||||
pageParams.postId = Number(contextUrlParams.urlHash.replace('p', ''));
|
||||
}
|
||||
|
||||
return this.forumProvider.invalidateDiscussionPosts(pageParams.discussionId, notification.site).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
return this.linkHelper.goInSite(undefined, 'AddonModForumDiscussionPage', pageParams, notification.site);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ import { CoreCronDelegate } from '@providers/cron';
|
|||
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
|
||||
import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate';
|
||||
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
import { AddonModLessonComponentsModule } from './components/components.module';
|
||||
import { AddonModLessonProvider } from './providers/lesson';
|
||||
import { AddonModLessonOfflineProvider } from './providers/lesson-offline';
|
||||
|
@ -29,6 +30,7 @@ import { AddonModLessonIndexLinkHandler } from './providers/index-link-handler';
|
|||
import { AddonModLessonGradeLinkHandler } from './providers/grade-link-handler';
|
||||
import { AddonModLessonReportLinkHandler } from './providers/report-link-handler';
|
||||
import { AddonModLessonListLinkHandler } from './providers/list-link-handler';
|
||||
import { AddonModLessonPushClickHandler } from './providers/push-click-handler';
|
||||
import { CoreUpdateManagerProvider } from '@providers/update-manager';
|
||||
|
||||
// List of providers (without handlers).
|
||||
|
@ -56,7 +58,8 @@ export const ADDON_MOD_LESSON_PROVIDERS: any[] = [
|
|||
AddonModLessonIndexLinkHandler,
|
||||
AddonModLessonGradeLinkHandler,
|
||||
AddonModLessonReportLinkHandler,
|
||||
AddonModLessonListLinkHandler
|
||||
AddonModLessonListLinkHandler,
|
||||
AddonModLessonPushClickHandler
|
||||
]
|
||||
})
|
||||
export class AddonModLessonModule {
|
||||
|
@ -65,7 +68,8 @@ export class AddonModLessonModule {
|
|||
cronDelegate: CoreCronDelegate, syncHandler: AddonModLessonSyncCronHandler, linksDelegate: CoreContentLinksDelegate,
|
||||
indexHandler: AddonModLessonIndexLinkHandler, gradeHandler: AddonModLessonGradeLinkHandler,
|
||||
reportHandler: AddonModLessonReportLinkHandler, updateManager: CoreUpdateManagerProvider,
|
||||
listLinkHandler: AddonModLessonListLinkHandler) {
|
||||
listLinkHandler: AddonModLessonListLinkHandler, pushNotificationsDelegate: CorePushNotificationsDelegate,
|
||||
pushClickHandler: AddonModLessonPushClickHandler) {
|
||||
|
||||
moduleDelegate.registerHandler(moduleHandler);
|
||||
prefetchDelegate.registerHandler(prefetchHandler);
|
||||
|
@ -74,6 +78,7 @@ export class AddonModLessonModule {
|
|||
linksDelegate.registerHandler(gradeHandler);
|
||||
linksDelegate.registerHandler(reportHandler);
|
||||
linksDelegate.registerHandler(listLinkHandler);
|
||||
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
|
||||
|
||||
// Allow migrating the tables from the old app to the new schema.
|
||||
updateManager.registerSiteTablesMigration([
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
// (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 { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate';
|
||||
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
import { CoreGradesProvider } from '@core/grades/providers/grades';
|
||||
import { AddonModLessonProvider } from './lesson';
|
||||
|
||||
/**
|
||||
* Handler for lesson push notifications clicks.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonModLessonPushClickHandler implements CorePushNotificationsClickHandler {
|
||||
name = 'AddonModLessonPushClickHandler';
|
||||
priority = 200;
|
||||
featureName = 'CoreCourseModuleDelegate_AddonModLesson';
|
||||
|
||||
constructor(private utils: CoreUtilsProvider, private lessonProvider: AddonModLessonProvider,
|
||||
private loginHelper: CoreLoginHelperProvider, private domUtils: CoreDomUtilsProvider,
|
||||
private courseHelper: CoreCourseHelperProvider, private gradesProvider: CoreGradesProvider) {}
|
||||
|
||||
/**
|
||||
* 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_lesson' &&
|
||||
notification.name == 'graded_essay') {
|
||||
|
||||
return this.lessonProvider.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 data = notification.customdata || {},
|
||||
courseId = Number(notification.courseid),
|
||||
moduleId = Number(data.cmid),
|
||||
modal = this.domUtils.showModalLoading();
|
||||
let promise;
|
||||
|
||||
if (moduleId) {
|
||||
// Try to open the module grade directly. Check if it's possible.
|
||||
promise = this.gradesProvider.isGradeItemsAvalaible(notification.site).catch(() => {
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
promise = Promise.resolve(false);
|
||||
}
|
||||
|
||||
return promise.then((getGrades) => {
|
||||
|
||||
if (getGrades) {
|
||||
return this.gradesProvider.getGradeItems(courseId, undefined, undefined, notification.site).then((items) => {
|
||||
// Find the item of th module.
|
||||
const item = items.find((item) => {
|
||||
return moduleId == item.cmid;
|
||||
});
|
||||
|
||||
if (item) {
|
||||
// Open the item directly.
|
||||
const pageParams: any = {
|
||||
courseId: courseId,
|
||||
gradeId: item.id
|
||||
};
|
||||
|
||||
this.loginHelper.redirect('CoreGradesGradePage', pageParams, notification.site);
|
||||
}
|
||||
|
||||
return Promise.reject(null);
|
||||
});
|
||||
} else {
|
||||
return Promise.reject(null);
|
||||
}
|
||||
|
||||
}).catch(() => {
|
||||
// Cannot get grade items or there's no need to. Open the course with the grades tab selected.
|
||||
return this.courseHelper.getCourse(courseId, notification.site).then((result) => {
|
||||
const pageParams: any = {
|
||||
course: result.course,
|
||||
selectedTab: 'CoreGrades'
|
||||
};
|
||||
|
||||
this.loginHelper.redirect('CoreCourseSectionPage', pageParams, notification.site);
|
||||
});
|
||||
}).catch(() => {
|
||||
// Cannot get course for some reason, just open the grades page.
|
||||
return this.loginHelper.redirect('CoreGradesCoursePage', {course: {id: courseId}}, notification.site);
|
||||
}).finally(() => {
|
||||
modal.dismiss();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -13,13 +13,16 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ModalController } from 'ionic-angular';
|
||||
import { ModalController, NavController } from 'ionic-angular';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { AddonModQuizProvider } from './quiz';
|
||||
import { AddonModQuizOfflineProvider } from './quiz-offline';
|
||||
import { AddonModQuizAccessRuleDelegate } from './access-rules-delegate';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
|
||||
/**
|
||||
* Helper service that provides some features for quiz.
|
||||
|
@ -29,7 +32,9 @@ export class AddonModQuizHelperProvider {
|
|||
|
||||
constructor(private domUtils: CoreDomUtilsProvider, private translate: TranslateService, private utils: CoreUtilsProvider,
|
||||
private accessRuleDelegate: AddonModQuizAccessRuleDelegate, private quizProvider: AddonModQuizProvider,
|
||||
private modalCtrl: ModalController, private quizOfflineProvider: AddonModQuizOfflineProvider) { }
|
||||
private modalCtrl: ModalController, private quizOfflineProvider: AddonModQuizOfflineProvider,
|
||||
private courseHelper: CoreCourseHelperProvider, private sitesProvider: CoreSitesProvider,
|
||||
private linkHelper: CoreContentLinksHelperProvider) { }
|
||||
|
||||
/**
|
||||
* Validate a preflight data or show a modal to input the preflight data if required.
|
||||
|
@ -156,6 +161,76 @@ export class AddonModQuizHelperProvider {
|
|||
return this.domUtils.getContentsOfElement(element, '.grade');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a quiz ID by attempt ID.
|
||||
*
|
||||
* @param {number} attemptId Attempt ID.
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<number>} Promise resolved with the quiz ID.
|
||||
*/
|
||||
getQuizIdByAttemptId(attemptId: number, siteId?: string): Promise<number> {
|
||||
// Use getAttemptReview to retrieve the quiz ID.
|
||||
return this.quizProvider.getAttemptReview(attemptId, undefined, false, siteId).then((reviewData) => {
|
||||
if (reviewData.attempt && reviewData.attempt.quiz) {
|
||||
return reviewData.attempt.quiz;
|
||||
}
|
||||
|
||||
return Promise.reject(null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a review link.
|
||||
*
|
||||
* @param {NavController} navCtrl Nav controller, can be undefined/null.
|
||||
* @param {number} attemptId Attempt ID.
|
||||
* @param {number} [page] Page to load, -1 to all questions in same page.
|
||||
* @param {number} [courseId] Course ID.
|
||||
* @param {number} [quizId] Quiz ID.
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
handleReviewLink(navCtrl: NavController, attemptId: number, page?: number, courseId?: number, quizId?: number,
|
||||
siteId?: string): Promise<any> {
|
||||
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
||||
|
||||
const modal = this.domUtils.showModalLoading();
|
||||
let promise;
|
||||
|
||||
if (quizId) {
|
||||
promise = Promise.resolve(quizId);
|
||||
} else {
|
||||
// Retrieve the quiz ID using the attempt ID.
|
||||
promise = this.getQuizIdByAttemptId(attemptId);
|
||||
}
|
||||
|
||||
return promise.then((id) => {
|
||||
quizId = id;
|
||||
|
||||
// Get the courseId if we don't have it.
|
||||
if (courseId) {
|
||||
return courseId;
|
||||
} else {
|
||||
return this.courseHelper.getModuleCourseIdByInstance(quizId, 'quiz', siteId);
|
||||
}
|
||||
}).then((courseId) => {
|
||||
// Go to the review page.
|
||||
const pageParams = {
|
||||
quizId: quizId,
|
||||
attemptId: attemptId,
|
||||
courseId: courseId,
|
||||
page: isNaN(page) ? -1 : page
|
||||
};
|
||||
|
||||
return this.linkHelper.goInSite(navCtrl, 'AddonModQuizReviewPage', pageParams, siteId);
|
||||
}).catch((error) => {
|
||||
|
||||
this.domUtils.showErrorModalDefault(error, 'An error occurred while loading the required data.');
|
||||
}).finally(() => {
|
||||
modal.dismiss();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some calculated data to the attempt.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
// (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 { AddonModQuizProvider } from './quiz';
|
||||
import { AddonModQuizHelperProvider } from './helper';
|
||||
|
||||
/**
|
||||
* Handler for quiz push notifications clicks.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonModQuizPushClickHandler implements CorePushNotificationsClickHandler {
|
||||
name = 'AddonModQuizPushClickHandler';
|
||||
priority = 200;
|
||||
featureName = 'CoreCourseModuleDelegate_AddonModQuiz';
|
||||
|
||||
protected SUPPORTED_NAMES = ['submission', 'confirmation', 'attempt_overdue'];
|
||||
|
||||
constructor(private utils: CoreUtilsProvider, private quizProvider: AddonModQuizProvider,
|
||||
private urlUtils: CoreUrlUtilsProvider, private courseHelper: CoreCourseHelperProvider,
|
||||
private quizHelper: AddonModQuizHelperProvider) {}
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
return this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'mod_quiz' &&
|
||||
this.SUPPORTED_NAMES.indexOf(notification.name) != -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
if (notification.name == 'submission') {
|
||||
// A student made a submission, go to view the attempt.
|
||||
return this.quizHelper.handleReviewLink(undefined, Number(contextUrlParams.attempt), Number(contextUrlParams.page),
|
||||
courseId, undefined, notification.site);
|
||||
} else {
|
||||
// Open the activity.
|
||||
const moduleId = Number(contextUrlParams.id);
|
||||
|
||||
return this.quizProvider.invalidateContent(moduleId, courseId, notification.site).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
return this.courseHelper.navigateToModule(moduleId, notification.site, courseId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,12 +13,10 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
import { AddonModQuizProvider } from './quiz';
|
||||
import { AddonModQuizHelperProvider } from './helper';
|
||||
|
||||
/**
|
||||
* Handler to treat links to quiz review.
|
||||
|
@ -29,8 +27,7 @@ export class AddonModQuizReviewLinkHandler extends CoreContentLinksHandlerBase {
|
|||
featureName = 'CoreCourseModuleDelegate_AddonModQuiz';
|
||||
pattern = /\/mod\/quiz\/review\.php.*([\&\?]attempt=\d+)/;
|
||||
|
||||
constructor(protected domUtils: CoreDomUtilsProvider, protected quizProvider: AddonModQuizProvider,
|
||||
protected courseHelper: CoreCourseHelperProvider, protected linkHelper: CoreContentLinksHelperProvider) {
|
||||
constructor(protected quizProvider: AddonModQuizProvider, protected quizHelper: AddonModQuizHelperProvider) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
@ -50,56 +47,13 @@ export class AddonModQuizReviewLinkHandler extends CoreContentLinksHandlerBase {
|
|||
|
||||
return [{
|
||||
action: (siteId, navCtrl?): void => {
|
||||
// Retrieve the quiz ID using the attempt ID.
|
||||
const modal = this.domUtils.showModalLoading(),
|
||||
attemptId = parseInt(params.attempt, 10),
|
||||
const attemptId = parseInt(params.attempt, 10),
|
||||
page = parseInt(params.page, 10);
|
||||
let quizId;
|
||||
|
||||
this.getQuizIdByAttemptId(attemptId).then((id) => {
|
||||
quizId = id;
|
||||
|
||||
// Get the courseId if we don't have it.
|
||||
if (courseId) {
|
||||
return courseId;
|
||||
} else {
|
||||
return this.courseHelper.getModuleCourseIdByInstance(quizId, 'quiz', siteId);
|
||||
}
|
||||
}).then((courseId) => {
|
||||
// Go to the review page.
|
||||
const pageParams = {
|
||||
quizId: quizId,
|
||||
attemptId: attemptId,
|
||||
courseId: courseId,
|
||||
page: params.showall ? -1 : (isNaN(page) ? -1 : page)
|
||||
};
|
||||
|
||||
this.linkHelper.goInSite(navCtrl, 'AddonModQuizReviewPage', pageParams, siteId);
|
||||
}).catch((error) => {
|
||||
|
||||
this.domUtils.showErrorModalDefault(error, 'An error occurred while loading the required data.');
|
||||
}).finally(() => {
|
||||
modal.dismiss();
|
||||
});
|
||||
this.quizHelper.handleReviewLink(navCtrl, attemptId, page, courseId, undefined, siteId);
|
||||
}
|
||||
}];
|
||||
}
|
||||
/**
|
||||
* Get a quiz ID by attempt ID.
|
||||
*
|
||||
* @param {number} attemptId Attempt ID.
|
||||
* @return {Promise<number>} Promise resolved with the quiz ID.
|
||||
*/
|
||||
protected getQuizIdByAttemptId(attemptId: number): Promise<number> {
|
||||
// Use getAttemptReview to retrieve the quiz ID.
|
||||
return this.quizProvider.getAttemptReview(attemptId).then((reviewData) => {
|
||||
if (reviewData.attempt && reviewData.attempt.quiz) {
|
||||
return reviewData.attempt.quiz;
|
||||
}
|
||||
|
||||
return Promise.reject(null);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||
|
|
|
@ -17,6 +17,7 @@ import { CoreCronDelegate } from '@providers/cron';
|
|||
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
|
||||
import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate';
|
||||
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
import { AddonModQuizAccessRuleDelegate } from './providers/access-rules-delegate';
|
||||
import { AddonModQuizProvider } from './providers/quiz';
|
||||
import { AddonModQuizOfflineProvider } from './providers/quiz-offline';
|
||||
|
@ -29,6 +30,7 @@ import { AddonModQuizIndexLinkHandler } from './providers/index-link-handler';
|
|||
import { AddonModQuizGradeLinkHandler } from './providers/grade-link-handler';
|
||||
import { AddonModQuizReviewLinkHandler } from './providers/review-link-handler';
|
||||
import { AddonModQuizListLinkHandler } from './providers/list-link-handler';
|
||||
import { AddonModQuizPushClickHandler } from './providers/push-click-handler';
|
||||
import { AddonModQuizComponentsModule } from './components/components.module';
|
||||
import { CoreUpdateManagerProvider } from '@providers/update-manager';
|
||||
|
||||
|
@ -79,7 +81,8 @@ export const ADDON_MOD_QUIZ_PROVIDERS: any[] = [
|
|||
AddonModQuizIndexLinkHandler,
|
||||
AddonModQuizGradeLinkHandler,
|
||||
AddonModQuizReviewLinkHandler,
|
||||
AddonModQuizListLinkHandler
|
||||
AddonModQuizListLinkHandler,
|
||||
AddonModQuizPushClickHandler
|
||||
]
|
||||
})
|
||||
export class AddonModQuizModule {
|
||||
|
@ -88,7 +91,8 @@ export class AddonModQuizModule {
|
|||
cronDelegate: CoreCronDelegate, syncHandler: AddonModQuizSyncCronHandler, linksDelegate: CoreContentLinksDelegate,
|
||||
indexHandler: AddonModQuizIndexLinkHandler, gradeHandler: AddonModQuizGradeLinkHandler,
|
||||
reviewHandler: AddonModQuizReviewLinkHandler, updateManager: CoreUpdateManagerProvider,
|
||||
listLinkHandler: AddonModQuizListLinkHandler) {
|
||||
listLinkHandler: AddonModQuizListLinkHandler,
|
||||
pushNotificationsDelegate: CorePushNotificationsDelegate, pushClickHandler: AddonModQuizPushClickHandler) {
|
||||
|
||||
moduleDelegate.registerHandler(moduleHandler);
|
||||
prefetchDelegate.registerHandler(prefetchHandler);
|
||||
|
@ -97,6 +101,7 @@ export class AddonModQuizModule {
|
|||
linksDelegate.registerHandler(gradeHandler);
|
||||
linksDelegate.registerHandler(reviewHandler);
|
||||
linksDelegate.registerHandler(listLinkHandler);
|
||||
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
|
||||
|
||||
// Allow migrating the tables from the old app to the new schema.
|
||||
updateManager.registerSiteTableMigration({
|
||||
|
|
|
@ -17,6 +17,7 @@ import { AddonNotificationsProvider } from './providers/notifications';
|
|||
import { AddonNotificationsMainMenuHandler } from './providers/mainmenu-handler';
|
||||
import { AddonNotificationsSettingsHandler } from './providers/settings-handler';
|
||||
import { AddonNotificationsCronHandler } from './providers/cron-handler';
|
||||
import { AddonNotificationsPushClickHandler } from './providers/push-click-handler';
|
||||
import { CoreAppProvider } from '@providers/app';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
|
||||
|
@ -24,10 +25,8 @@ import { CoreSettingsDelegate } from '@core/settings/providers/delegate';
|
|||
import { CoreCronDelegate } from '@providers/cron';
|
||||
import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreUrlUtilsProvider } from '@providers/utils/url';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate';
|
||||
import { AddonModForumProvider } from '@addon/mod/forum/providers/forum';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
|
||||
// List of providers (without handlers).
|
||||
export const ADDON_NOTIFICATIONS_PROVIDERS: any[] = [
|
||||
|
@ -44,6 +43,7 @@ export const ADDON_NOTIFICATIONS_PROVIDERS: any[] = [
|
|||
AddonNotificationsMainMenuHandler,
|
||||
AddonNotificationsSettingsHandler,
|
||||
AddonNotificationsCronHandler,
|
||||
AddonNotificationsPushClickHandler
|
||||
]
|
||||
})
|
||||
export class AddonNotificationsModule {
|
||||
|
@ -52,44 +52,15 @@ export class AddonNotificationsModule {
|
|||
cronDelegate: CoreCronDelegate, cronHandler: AddonNotificationsCronHandler, zone: NgZone,
|
||||
appProvider: CoreAppProvider, utils: CoreUtilsProvider, sitesProvider: CoreSitesProvider,
|
||||
notificationsProvider: AddonNotificationsProvider, localNotifications: CoreLocalNotificationsProvider,
|
||||
linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: AddonPushNotificationsDelegate,
|
||||
urlUtils: CoreUrlUtilsProvider, forumProvider: AddonModForumProvider) {
|
||||
linkHelper: CoreContentLinksHelperProvider, pushNotificationsDelegate: CorePushNotificationsDelegate,
|
||||
pushClickHandler: AddonNotificationsPushClickHandler) {
|
||||
|
||||
mainMenuDelegate.registerHandler(mainMenuHandler);
|
||||
settingsDelegate.registerHandler(settingsHandler);
|
||||
cronDelegate.register(cronHandler);
|
||||
pushNotificationsDelegate.registerClickHandler(pushClickHandler);
|
||||
|
||||
const notificationClicked = (notification: any): void => {
|
||||
|
||||
// Temporary fix to make forum notifications work. This will be improved in next release.
|
||||
if (notification.moodlecomponent == 'mod_forum' && notification.name == 'posts') {
|
||||
sitesProvider.isFeatureDisabled('CoreCourseModuleDelegate_AddonModForum', notification.site).then((disabled) => {
|
||||
if (disabled) {
|
||||
// Forum is disabled, stop.
|
||||
return;
|
||||
}
|
||||
|
||||
const contextUrlParams = urlUtils.extractUrlParams(notification.contexturl),
|
||||
pageParams: any = {
|
||||
courseId: Number(notification.courseid),
|
||||
discussionId: Number(contextUrlParams.d),
|
||||
};
|
||||
|
||||
if (contextUrlParams.urlHash) {
|
||||
pageParams.postId = Number(contextUrlParams.urlHash.replace('p', ''));
|
||||
}
|
||||
|
||||
forumProvider.invalidateDiscussionPosts(pageParams.discussionId).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
linkHelper.goInSite(undefined, 'AddonModForumDiscussionPage', pageParams, notification.site);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
goToNotifications(notification);
|
||||
}
|
||||
};
|
||||
const goToNotifications = (notification: any): void => {
|
||||
sitesProvider.isFeatureDisabled('CoreMainMenuDelegate_AddonNotifications', notification.site).then((disabled) => {
|
||||
if (disabled) {
|
||||
// Notifications are disabled, stop.
|
||||
|
@ -106,17 +77,5 @@ export class AddonNotificationsModule {
|
|||
// Listen for clicks in simulated push notifications.
|
||||
localNotifications.registerClick(AddonNotificationsProvider.PUSH_SIMULATION_COMPONENT, notificationClicked);
|
||||
}
|
||||
|
||||
// Register push notification clicks.
|
||||
pushNotificationsDelegate.on('click').subscribe((notification) => {
|
||||
if (utils.isTrueOrOne(notification.notif)) {
|
||||
// Execute the callback in the Angular zone, so change detection doesn't stop working.
|
||||
zone.run(() => {
|
||||
notificationClicked(notification);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ import { CoreEventsProvider, CoreEventObserver } from '@providers/events';
|
|||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { AddonNotificationsProvider } from '../../providers/notifications';
|
||||
import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
|
||||
/**
|
||||
* Page that displays the list of notifications.
|
||||
|
@ -48,7 +48,7 @@ export class AddonNotificationsListPage {
|
|||
constructor(navParams: NavParams, private domUtils: CoreDomUtilsProvider, private eventsProvider: CoreEventsProvider,
|
||||
private sitesProvider: CoreSitesProvider, private textUtils: CoreTextUtilsProvider,
|
||||
private utils: CoreUtilsProvider, private notificationsProvider: AddonNotificationsProvider,
|
||||
private pushNotificationsDelegate: AddonPushNotificationsDelegate) {
|
||||
private pushNotificationsDelegate: CorePushNotificationsDelegate) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,8 +18,8 @@ import { CoreSitesProvider } from '@providers/sites';
|
|||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@core/mainmenu/providers/delegate';
|
||||
import { AddonNotificationsProvider } from './notifications';
|
||||
import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications';
|
||||
import { AddonPushNotificationsDelegate } from '@addon/pushnotifications/providers/delegate';
|
||||
import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
|
||||
/**
|
||||
* Handler to inject an option into main menu.
|
||||
|
@ -41,8 +41,8 @@ export class AddonNotificationsMainMenuHandler implements CoreMainMenuHandler {
|
|||
|
||||
constructor(eventsProvider: CoreEventsProvider, private sitesProvider: CoreSitesProvider,
|
||||
utils: CoreUtilsProvider, private notificationsProvider: AddonNotificationsProvider,
|
||||
private pushNotificationsProvider: AddonPushNotificationsProvider,
|
||||
pushNotificationsDelegate: AddonPushNotificationsDelegate) {
|
||||
private pushNotificationsProvider: CorePushNotificationsProvider,
|
||||
pushNotificationsDelegate: CorePushNotificationsDelegate) {
|
||||
|
||||
eventsProvider.on(AddonNotificationsProvider.READ_CHANGED_EVENT, (data) => {
|
||||
this.updateBadge(data.siteId);
|
||||
|
|
|
@ -262,23 +262,25 @@ export class AddonNotificationsProvider {
|
|||
* Mark a single notification as read.
|
||||
*
|
||||
* @param {number} notificationId ID of notification to mark as read
|
||||
* @param {string} [siteId] Site ID. If not defined, current site.
|
||||
* @returns {Promise<any>} Resolved when done.
|
||||
* @since 3.5
|
||||
*/
|
||||
markNotificationRead(notificationId: number): Promise<any> {
|
||||
const currentSite = this.sitesProvider.getCurrentSite();
|
||||
markNotificationRead(notificationId: number, siteId?: string): Promise<any> {
|
||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||
|
||||
if (currentSite.wsAvailable('core_message_mark_notification_read')) {
|
||||
const params = {
|
||||
notificationid: notificationId,
|
||||
timeread: this.timeUtils.timestamp()
|
||||
};
|
||||
if (site.wsAvailable('core_message_mark_notification_read')) {
|
||||
const params = {
|
||||
notificationid: notificationId,
|
||||
timeread: this.timeUtils.timestamp()
|
||||
};
|
||||
|
||||
return currentSite.write('core_message_mark_notification_read', params);
|
||||
} else {
|
||||
// Fallback for versions prior to 3.5.
|
||||
return this.messageProvider.markMessageRead(notificationId);
|
||||
}
|
||||
return site.write('core_message_mark_notification_read', params);
|
||||
} else {
|
||||
// Fallback for versions prior to 3.5.
|
||||
return this.messageProvider.markMessageRead(notificationId, site.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
// (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 { CoreEventsProvider } from '@providers/events';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
import { AddonNotificationsProvider } from './notifications';
|
||||
|
||||
/**
|
||||
* Handler for non-messaging push notifications clicks.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonNotificationsPushClickHandler implements CorePushNotificationsClickHandler {
|
||||
name = 'AddonNotificationsPushClickHandler';
|
||||
priority = 0; // Low priority so it's used as a fallback if no other handler treats the notification.
|
||||
featureName = 'CoreMainMenuDelegate_AddonNotifications';
|
||||
|
||||
constructor(private utils: CoreUtilsProvider, private notificationsProvider: AddonNotificationsProvider,
|
||||
private linkHelper: CoreContentLinksHelperProvider, private eventsProvider: CoreEventsProvider) {}
|
||||
|
||||
/**
|
||||
* 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 clicked, mark as read. Don't block for this.
|
||||
this.notificationsProvider.markNotificationRead(notification.savedmessageid, notification.site).then(() => {
|
||||
this.eventsProvider.trigger(AddonNotificationsProvider.READ_CHANGED_EVENT, null, notification.site);
|
||||
}).catch(() => {
|
||||
// Ignore errors.
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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> {
|
||||
return this.notificationsProvider.invalidateNotificationsList(notification.site).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
return this.linkHelper.goInSite(undefined, 'AddonNotificationsListPage', undefined, notification.site);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
// (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 { CoreLoggerProvider } from '@providers/logger';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
/**
|
||||
* Service to handle push notifications actions to perform when clicked and received.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonPushNotificationsDelegate {
|
||||
|
||||
protected logger;
|
||||
protected observables: { [s: string]: Subject<any> } = {};
|
||||
protected counterHandlers: { [s: string]: string } = {};
|
||||
|
||||
constructor(loggerProvider: CoreLoggerProvider) {
|
||||
this.logger = loggerProvider.getInstance('AddonPushNotificationsDelegate');
|
||||
this.observables['click'] = new Subject<any>();
|
||||
this.observables['receive'] = new Subject<any>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called when a push notification is clicked. Sends notification to handlers.
|
||||
*
|
||||
* @param {any} notification Notification clicked.
|
||||
*/
|
||||
clicked(notification: any): void {
|
||||
this.observables['click'].next(notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called when a push notification is received in foreground (cannot tell when it's received in background).
|
||||
* Sends notification to all handlers.
|
||||
*
|
||||
* @param {any} notification Notification received.
|
||||
*/
|
||||
received(notification: any): void {
|
||||
this.observables['receive'].next(notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a push notifications observable for click and receive notification event.
|
||||
* When a notification is clicked or received, the observable will receive a notification to treat.
|
||||
* let observer = pushNotificationsDelegate.on('click').subscribe((notification) => {
|
||||
* ...
|
||||
* observer.unsuscribe();
|
||||
*
|
||||
* @param {string} eventName Only click and receive are permitted.
|
||||
* @return {Subject<any>} Observer to subscribe.
|
||||
*/
|
||||
on(eventName: string): Subject<any> {
|
||||
if (typeof this.observables[eventName] == 'undefined') {
|
||||
const eventNames = Object.keys(this.observables).join(', ');
|
||||
this.logger.warn(`'${eventName}' event name is not allowed. Use one of the following: '${eventNames}'.`);
|
||||
|
||||
return new Subject<any>();
|
||||
}
|
||||
|
||||
return this.observables[eventName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a push notifications handler for update badge counter.
|
||||
*
|
||||
* @param {string} name Handler's name.
|
||||
*/
|
||||
registerCounterHandler(name: string): void {
|
||||
if (typeof this.counterHandlers[name] == 'undefined') {
|
||||
this.logger.debug(`Registered handler '${name}' as badge counter handler.`);
|
||||
this.counterHandlers[name] = name;
|
||||
} else {
|
||||
this.logger.log(`Handler '${name}' as badge counter handler already registered.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a counter handler is present.
|
||||
*
|
||||
* @param {string} name Handler's name.
|
||||
* @return {boolean} If handler name is present.
|
||||
*/
|
||||
isCounterHandlerRegistered(name: string): boolean {
|
||||
return typeof this.counterHandlers[name] != 'undefined';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all counter badge handlers.
|
||||
*
|
||||
* @return {any} with all the handler names.
|
||||
*/
|
||||
getCounterHandlers(): any {
|
||||
return this.counterHandlers;
|
||||
}
|
||||
}
|
|
@ -121,7 +121,7 @@ import { AddonMessageOutputModule } from '@addon/messageoutput/messageoutput.mod
|
|||
import { AddonMessageOutputAirnotifierModule } from '@addon/messageoutput/airnotifier/airnotifier.module';
|
||||
import { AddonMessagesModule } from '@addon/messages/messages.module';
|
||||
import { AddonNotesModule } from '../addon/notes/notes.module';
|
||||
import { AddonPushNotificationsModule } from '@addon/pushnotifications/pushnotifications.module';
|
||||
import { CorePushNotificationsModule } from '@core/pushnotifications/pushnotifications.module';
|
||||
import { AddonNotificationsModule } from '@addon/notifications/notifications.module';
|
||||
import { AddonRemoteThemesModule } from '@addon/remotethemes/remotethemes.module';
|
||||
import { AddonQbehaviourModule } from '@addon/qbehaviour/qbehaviour.module';
|
||||
|
@ -201,6 +201,7 @@ export const CORE_PROVIDERS: any[] = [
|
|||
CoreCommentsModule,
|
||||
CoreBlockModule,
|
||||
CoreRatingModule,
|
||||
CorePushNotificationsModule,
|
||||
AddonBadgesModule,
|
||||
AddonBlogModule,
|
||||
AddonCalendarModule,
|
||||
|
@ -241,7 +242,6 @@ export const CORE_PROVIDERS: any[] = [
|
|||
AddonMessagesModule,
|
||||
AddonNotesModule,
|
||||
AddonNotificationsModule,
|
||||
AddonPushNotificationsModule,
|
||||
AddonRemoteThemesModule,
|
||||
AddonQbehaviourModule,
|
||||
AddonQtypeModule
|
||||
|
|
|
@ -35,6 +35,7 @@ import { CORE_QUESTION_PROVIDERS } from '@core/question/question.module';
|
|||
import { CORE_SHAREDFILES_PROVIDERS } from '@core/sharedfiles/sharedfiles.module';
|
||||
import { CORE_SITEHOME_PROVIDERS } from '@core/sitehome/sitehome.module';
|
||||
import { CORE_USER_PROVIDERS } from '@core/user/user.module';
|
||||
import { CORE_PUSHNOTIFICATIONS_PROVIDERS } from '@core/pushnotifications/pushnotifications.module';
|
||||
import { IONIC_NATIVE_PROVIDERS } from '@core/emulator/emulator.module';
|
||||
|
||||
// Import only this provider to prevent circular dependencies.
|
||||
|
@ -114,7 +115,6 @@ import { ADDON_MOD_WIKI_PROVIDERS } from '@addon/mod/wiki/wiki.module';
|
|||
import { ADDON_MOD_WORKSHOP_PROVIDERS } from '@addon/mod/workshop/workshop.module';
|
||||
import { ADDON_NOTES_PROVIDERS } from '@addon/notes/notes.module';
|
||||
import { ADDON_NOTIFICATIONS_PROVIDERS } from '@addon/notifications/notifications.module';
|
||||
import { ADDON_PUSHNOTIFICATIONS_PROVIDERS } from '@addon/pushnotifications/pushnotifications.module';
|
||||
import { ADDON_REMOTETHEMES_PROVIDERS } from '@addon/remotethemes/remotethemes.module';
|
||||
|
||||
// Import some addon modules that define components, directives and pipes. Only import the important ones.
|
||||
|
@ -233,7 +233,7 @@ export class CoreCompileProvider {
|
|||
.concat(ADDON_MOD_QUIZ_PROVIDERS).concat(ADDON_MOD_RESOURCE_PROVIDERS).concat(ADDON_MOD_SCORM_PROVIDERS)
|
||||
.concat(ADDON_MOD_SURVEY_PROVIDERS).concat(ADDON_MOD_URL_PROVIDERS).concat(ADDON_MOD_WIKI_PROVIDERS)
|
||||
.concat(ADDON_MOD_WORKSHOP_PROVIDERS).concat(ADDON_NOTES_PROVIDERS).concat(ADDON_NOTIFICATIONS_PROVIDERS)
|
||||
.concat(ADDON_PUSHNOTIFICATIONS_PROVIDERS).concat(ADDON_REMOTETHEMES_PROVIDERS).concat(CORE_BLOCK_PROVIDERS);
|
||||
.concat(CORE_PUSHNOTIFICATIONS_PROVIDERS).concat(ADDON_REMOTETHEMES_PROVIDERS).concat(CORE_BLOCK_PROVIDERS);
|
||||
|
||||
// We cannot inject anything to this constructor. Use the Injector to inject all the providers into the instance.
|
||||
for (const i in providers) {
|
||||
|
|
|
@ -303,10 +303,10 @@ export class CoreCourseSectionPage implements OnDestroy {
|
|||
|
||||
// Load the course format options when course completion is enabled to show completion progress on sections.
|
||||
if (this.course.enablecompletion && this.coursesProvider.isGetCoursesByFieldAvailable()) {
|
||||
promises.push(this.coursesProvider.getCoursesByField('id', this.course.id).catch(() => {
|
||||
promises.push(this.coursesProvider.getCourseByField('id', this.course.id).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then((courses) => {
|
||||
courses && courses[0] && Object.assign(this.course, courses[0]);
|
||||
}).then((course) => {
|
||||
course && Object.assign(this.course, course);
|
||||
|
||||
if (this.course.courseformatoptions) {
|
||||
this.course.courseformatoptions = this.utils.objectToKeyValueMap(this.course.courseformatoptions,
|
||||
|
|
|
@ -113,10 +113,10 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler {
|
|||
return sections[0];
|
||||
} else {
|
||||
// Try to retrieve the marker.
|
||||
promise = this.coursesProvider.getCoursesByField('id', course.id).catch(() => {
|
||||
promise = this.coursesProvider.getCourseByField('id', course.id).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then((courses) => {
|
||||
return courses && courses[0] && courses[0].marker;
|
||||
}).then((course) => {
|
||||
return course && course.marker;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -156,10 +156,14 @@ export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler {
|
|||
*
|
||||
* @param {NavController} navCtrl The NavController instance to use.
|
||||
* @param {any} course The course to open. It should contain a "format" attribute.
|
||||
* @param {any} [params] Params to pass to the course page.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
openCourse(navCtrl: NavController, course: any): Promise<any> {
|
||||
return navCtrl.push('CoreCourseSectionPage', { course: course });
|
||||
openCourse(navCtrl: NavController, course: any, params?: any): Promise<any> {
|
||||
params = params || {};
|
||||
Object.assign(params, { course: course });
|
||||
|
||||
return navCtrl.push('CoreCourseSectionPage', params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,9 +92,10 @@ export interface CoreCourseFormatHandler extends CoreDelegateHandler {
|
|||
*
|
||||
* @param {NavController} navCtrl The NavController instance to use.
|
||||
* @param {any} course The course to open. It should contain a "format" attribute.
|
||||
* @param {any} [params] Params to pass to the course page.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
openCourse?(navCtrl: NavController, course: any): Promise<any>;
|
||||
openCourse?(navCtrl: NavController, course: any, params?: any): Promise<any>;
|
||||
|
||||
/**
|
||||
* Return the Component to use to display the course format instead of using the default one.
|
||||
|
@ -337,10 +338,11 @@ export class CoreCourseFormatDelegate extends CoreDelegate {
|
|||
*
|
||||
* @param {NavController} navCtrl The NavController instance to use.
|
||||
* @param {any} course The course to open. It should contain a "format" attribute.
|
||||
* @param {any} [params] Params to pass to the course page.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
openCourse(navCtrl: NavController, course: any): Promise<any> {
|
||||
return this.executeFunctionOnEnabled(course.format, 'openCourse', [navCtrl, course]);
|
||||
openCourse(navCtrl: NavController, course: any, params?: any): Promise<any> {
|
||||
return this.executeFunctionOnEnabled(course.format, 'openCourse', [navCtrl, course, params]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1401,22 +1401,35 @@ export class CoreCourseHelperProvider {
|
|||
*
|
||||
* @param {NavController} navCtrl The nav controller to use.
|
||||
* @param {any} course Course to open
|
||||
* @param {any} [params] Params to pass to the course page.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
openCourse(navCtrl: NavController, course: any): void {
|
||||
openCourse(navCtrl: NavController, course: any, params?: any): Promise<any> {
|
||||
if (this.sitePluginsProvider.sitePluginPromiseExists('format_' + course.format)) {
|
||||
// This course uses a custom format plugin, wait for the format plugin to finish loading.
|
||||
const loading = this.domUtils.showModalLoading();
|
||||
this.sitePluginsProvider.sitePluginLoaded('format_' + course.format).then(() => {
|
||||
|
||||
return this.sitePluginsProvider.sitePluginLoaded('format_' + course.format).then(() => {
|
||||
// The format loaded successfully, but the handlers wont be registered until all site plugins have loaded.
|
||||
if (this.sitePluginsProvider.sitePluginsFinishedLoading) {
|
||||
loading.dismiss();
|
||||
this.courseFormatDelegate.openCourse(navCtrl, course);
|
||||
|
||||
return this.courseFormatDelegate.openCourse(navCtrl, course, params);
|
||||
} else {
|
||||
const observer = this.eventsProvider.on(CoreEventsProvider.SITE_PLUGINS_LOADED, () => {
|
||||
loading.dismiss();
|
||||
this.courseFormatDelegate.openCourse(navCtrl, course);
|
||||
observer && observer.off();
|
||||
});
|
||||
// Wait for plugins to be loaded.
|
||||
const deferred = this.utils.promiseDefer(),
|
||||
observer = this.eventsProvider.on(CoreEventsProvider.SITE_PLUGINS_LOADED, () => {
|
||||
loading.dismiss();
|
||||
observer && observer.off();
|
||||
|
||||
this.courseFormatDelegate.openCourse(navCtrl, course, params).then((response) => {
|
||||
deferred.resolve(response);
|
||||
}).catch((error) => {
|
||||
deferred.reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
}).catch(() => {
|
||||
// The site plugin failed to load. The user needs to restart the app to try loading it again.
|
||||
|
@ -1425,7 +1438,7 @@ export class CoreCourseHelperProvider {
|
|||
});
|
||||
} else {
|
||||
// No custom format plugin. We don't need to wait for anything.
|
||||
this.courseFormatDelegate.openCourse(navCtrl, course);
|
||||
return this.courseFormatDelegate.openCourse(navCtrl, course, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,11 @@ import { CoreCoursesDashboardProvider } from './providers/dashboard';
|
|||
import { CoreCoursesCourseLinkHandler } from './providers/course-link-handler';
|
||||
import { CoreCoursesIndexLinkHandler } from './providers/courses-index-link-handler';
|
||||
import { CoreCoursesDashboardLinkHandler } from './providers/dashboard-link-handler';
|
||||
import { CoreCoursesEnrolPushClickHandler } from './providers/enrol-push-click-handler';
|
||||
import { CoreCoursesRequestPushClickHandler } from './providers/request-push-click-handler';
|
||||
import { CoreMainMenuDelegate } from '@core/mainmenu/providers/delegate';
|
||||
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
|
||||
import { CorePushNotificationsDelegate } from '@core/pushnotifications/providers/delegate';
|
||||
|
||||
// List of providers (without handlers).
|
||||
export const CORE_COURSES_PROVIDERS: any[] = [
|
||||
|
@ -41,18 +44,24 @@ export const CORE_COURSES_PROVIDERS: any[] = [
|
|||
CoreDashboardMainMenuHandler,
|
||||
CoreCoursesCourseLinkHandler,
|
||||
CoreCoursesIndexLinkHandler,
|
||||
CoreCoursesDashboardLinkHandler
|
||||
CoreCoursesDashboardLinkHandler,
|
||||
CoreCoursesEnrolPushClickHandler,
|
||||
CoreCoursesRequestPushClickHandler
|
||||
],
|
||||
exports: []
|
||||
})
|
||||
export class CoreCoursesModule {
|
||||
constructor(mainMenuDelegate: CoreMainMenuDelegate, contentLinksDelegate: CoreContentLinksDelegate,
|
||||
mainMenuHandler: CoreDashboardMainMenuHandler, courseLinkHandler: CoreCoursesCourseLinkHandler,
|
||||
indexLinkHandler: CoreCoursesIndexLinkHandler, dashboardLinkHandler: CoreCoursesDashboardLinkHandler) {
|
||||
indexLinkHandler: CoreCoursesIndexLinkHandler, dashboardLinkHandler: CoreCoursesDashboardLinkHandler,
|
||||
pushNotificationsDelegate: CorePushNotificationsDelegate, enrolPushClickHandler: CoreCoursesEnrolPushClickHandler,
|
||||
requestPushClickHandler: CoreCoursesRequestPushClickHandler) {
|
||||
mainMenuDelegate.registerHandler(mainMenuHandler);
|
||||
|
||||
contentLinksDelegate.registerHandler(courseLinkHandler);
|
||||
contentLinksDelegate.registerHandler(indexLinkHandler);
|
||||
contentLinksDelegate.registerHandler(dashboardLinkHandler);
|
||||
pushNotificationsDelegate.registerClickHandler(enrolPushClickHandler);
|
||||
pushNotificationsDelegate.registerClickHandler(requestPushClickHandler);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
// (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 { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||
|
||||
/**
|
||||
* Handler for enrol push notifications clicks.
|
||||
*/
|
||||
@Injectable()
|
||||
export class CoreCoursesEnrolPushClickHandler implements CorePushNotificationsClickHandler {
|
||||
name = 'CoreCoursesEnrolPushClickHandler';
|
||||
priority = 200;
|
||||
|
||||
constructor(private utils: CoreUtilsProvider, private domUtils: CoreDomUtilsProvider,
|
||||
private courseHelper: CoreCourseHelperProvider, private loginHelper: CoreLoginHelperProvider) {}
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
return this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent.indexOf('enrol_') === 0 &&
|
||||
notification.name == 'expiry_notification';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the notification click.
|
||||
*
|
||||
* @param {any} notification The notification to check.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
handleClick(notification: any): Promise<any> {
|
||||
const courseId = Number(notification.courseid),
|
||||
modal = this.domUtils.showModalLoading();
|
||||
|
||||
return this.courseHelper.getCourse(courseId, notification.site).then((result) => {
|
||||
const params: any = {
|
||||
course: result.course
|
||||
};
|
||||
let page;
|
||||
|
||||
if (notification.contexturl && notification.contexturl.indexOf('user/index.php') != -1) {
|
||||
// Open the participants tab.
|
||||
page = 'CoreCourseSectionPage';
|
||||
params.selectedTab = 'CoreUserParticipants';
|
||||
} else if (result.enrolled) {
|
||||
// User is still enrolled, open the course.
|
||||
page = 'CoreCourseSectionPage';
|
||||
} else {
|
||||
// User not enrolled anymore, open the preview page.
|
||||
page = 'CoreCoursesCoursePreviewPage';
|
||||
}
|
||||
|
||||
return this.loginHelper.redirect(page, params, notification.site);
|
||||
}).catch((error) => {
|
||||
this.domUtils.showErrorModalDefault(error, 'Error getting course.');
|
||||
}).finally(() => {
|
||||
modal.dismiss();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
// (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 { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CorePushNotificationsClickHandler } from '@core/pushnotifications/providers/delegate';
|
||||
import { CoreCoursesProvider } from '@core/courses/providers/courses';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||
|
||||
/**
|
||||
* Handler for course request push notifications clicks.
|
||||
*/
|
||||
@Injectable()
|
||||
export class CoreCoursesRequestPushClickHandler implements CorePushNotificationsClickHandler {
|
||||
name = 'CoreCoursesRequestPushClickHandler';
|
||||
priority = 200;
|
||||
|
||||
protected SUPPORTED_NAMES = ['courserequested', 'courserequestapproved', 'courserequestrejected'];
|
||||
|
||||
constructor(private utils: CoreUtilsProvider, private domUtils: CoreDomUtilsProvider, private sitesProvider: CoreSitesProvider,
|
||||
private courseHelper: CoreCourseHelperProvider, private loginHelper: CoreLoginHelperProvider,
|
||||
private textUtils: CoreTextUtilsProvider, private coursesProvider: CoreCoursesProvider) {}
|
||||
|
||||
/**
|
||||
* 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> {
|
||||
// Don't support 'courserequestrejected', that way the app will open the notifications page.
|
||||
return this.utils.isTrueOrOne(notification.notif) && notification.moodlecomponent == 'moodle' &&
|
||||
(notification.name == 'courserequested' || notification.name == 'courserequestapproved');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the notification click.
|
||||
*
|
||||
* @param {any} notification The notification to check.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
handleClick(notification: any): Promise<any> {
|
||||
const courseId = Number(notification.courseid);
|
||||
|
||||
if (notification.name == 'courserequested') {
|
||||
// Feature not supported in the app, open in browser.
|
||||
return this.sitesProvider.getSite(notification.site).then((site) => {
|
||||
const url = this.textUtils.concatenatePaths(site.getURL(), 'course/pending.php');
|
||||
|
||||
return site.openInBrowserWithAutoLogin(url);
|
||||
});
|
||||
} else {
|
||||
// Open the course.
|
||||
const modal = this.domUtils.showModalLoading();
|
||||
|
||||
return this.coursesProvider.invalidateUserCourses(notification.site).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
return this.courseHelper.getCourse(courseId, notification.site);
|
||||
}).then((result) => {
|
||||
const params: any = {
|
||||
course: result.course
|
||||
};
|
||||
let page;
|
||||
|
||||
if (result.enrolled) {
|
||||
// User is still enrolled, open the course.
|
||||
page = 'CoreCourseSectionPage';
|
||||
} else {
|
||||
// User not enrolled (shouldn't happen), open the preview page.
|
||||
page = 'CoreCoursesCoursePreviewPage';
|
||||
}
|
||||
|
||||
return this.loginHelper.redirect(page, params, notification.site);
|
||||
}).catch((error) => {
|
||||
this.domUtils.showErrorModalDefault(error, 'Error getting course.');
|
||||
}).finally(() => {
|
||||
modal.dismiss();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,7 +15,10 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreGradesProvider } from './grades';
|
||||
|
||||
/**
|
||||
|
@ -26,7 +29,9 @@ export class CoreGradesUserLinkHandler extends CoreContentLinksHandlerBase {
|
|||
name = 'CoreGradesUserLinkHandler';
|
||||
pattern = /\/grade\/report\/user\/index.php/;
|
||||
|
||||
constructor(private linkHelper: CoreContentLinksHelperProvider, private gradesProvider: CoreGradesProvider) {
|
||||
constructor(private linkHelper: CoreContentLinksHelperProvider, private gradesProvider: CoreGradesProvider,
|
||||
private domUtils: CoreDomUtilsProvider, private courseHelper: CoreCourseHelperProvider,
|
||||
private loginHelper: CoreLoginHelperProvider) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
@ -41,14 +46,39 @@ export class CoreGradesUserLinkHandler extends CoreContentLinksHandlerBase {
|
|||
*/
|
||||
getActions(siteIds: string[], url: string, params: any, courseId?: number):
|
||||
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||
courseId = courseId || params.id;
|
||||
|
||||
return [{
|
||||
action: (siteId, navCtrl?): void => {
|
||||
const pageParams = {
|
||||
course: {id: courseId},
|
||||
userId: params.userid ? parseInt(params.userid, 10) : false,
|
||||
};
|
||||
// Always use redirect to make it the new history root (to avoid "loops" in history).
|
||||
this.linkHelper.goInSite(navCtrl, 'CoreGradesCoursePage', pageParams, siteId);
|
||||
const userId = params.userid ? parseInt(params.userid, 10) : false;
|
||||
|
||||
if (userId) {
|
||||
// Open the grades page directly.
|
||||
const pageParams = {
|
||||
course: {id: courseId},
|
||||
userId: userId,
|
||||
};
|
||||
|
||||
this.linkHelper.goInSite(navCtrl, 'CoreGradesCoursePage', pageParams, siteId);
|
||||
} else {
|
||||
// No userid, open the course with the grades tab selected.
|
||||
const modal = this.domUtils.showModalLoading();
|
||||
|
||||
this.courseHelper.getCourse(courseId, siteId).then((result) => {
|
||||
const pageParams: any = {
|
||||
course: result.course,
|
||||
selectedTab: 'CoreGrades'
|
||||
};
|
||||
|
||||
// Use redirect to prevent loops in the navigation.
|
||||
return this.loginHelper.redirect('CoreCourseSectionPage', pageParams, siteId);
|
||||
}).catch(() => {
|
||||
// Cannot get course for some reason, just open the grades page.
|
||||
return this.linkHelper.goInSite(navCtrl, 'CoreGradesCoursePage', {course: {id: courseId}}, siteId);
|
||||
}).finally(() => {
|
||||
modal.dismiss();
|
||||
});
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
@ -64,10 +94,10 @@ export class CoreGradesUserLinkHandler extends CoreContentLinksHandlerBase {
|
|||
* @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site.
|
||||
*/
|
||||
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
|
||||
if (!courseId) {
|
||||
if (!courseId && !params.id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.gradesProvider.isPluginEnabledForCourse(courseId, siteId);
|
||||
return this.gradesProvider.isPluginEnabledForCourse(courseId || params.id, siteId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import { CoreLoggerProvider } from '@providers/logger';
|
|||
import { CoreSitesProvider, CoreSiteBasicInfo } from '@providers/sites';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
||||
import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications';
|
||||
import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications';
|
||||
import { CoreLoginHelperProvider } from '../../providers/helper';
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ export class CoreLoginSitesPage {
|
|||
|
||||
constructor(private domUtils: CoreDomUtilsProvider, private textUtils: CoreTextUtilsProvider,
|
||||
private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider, logger: CoreLoggerProvider,
|
||||
private translate: TranslateService, private pushNotificationsProvider: AddonPushNotificationsProvider) {
|
||||
private translate: TranslateService, private pushNotificationsProvider: CorePushNotificationsProvider) {
|
||||
this.logger = logger.getInstance('CoreLoginSitesPage');
|
||||
}
|
||||
|
||||
|
|
|
@ -591,26 +591,28 @@ export class CoreLoginHelperProvider {
|
|||
* @param {string} page Name of the page to load.
|
||||
* @param {any} params Params to pass to the page.
|
||||
* @param {string} siteId Site to load.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
protected loadSiteAndPage(page: string, params: any, siteId: string): void {
|
||||
protected loadSiteAndPage(page: string, params: any, siteId: string): Promise<any> {
|
||||
const navCtrl = this.appProvider.getRootNavController();
|
||||
|
||||
if (siteId == CoreConstants.NO_SITE_ID) {
|
||||
// Page doesn't belong to a site, just load the page.
|
||||
navCtrl.setRoot(page, params);
|
||||
return navCtrl.setRoot(page, params);
|
||||
} else {
|
||||
const modal = this.domUtils.showModalLoading();
|
||||
this.sitesProvider.loadSite(siteId, page, params).then((loggedIn) => {
|
||||
|
||||
return this.sitesProvider.loadSite(siteId, page, params).then((loggedIn) => {
|
||||
if (loggedIn) {
|
||||
// Due to DeepLinker, we need to remove the path from the URL before going to main menu.
|
||||
// IonTabs checks the URL to determine which path to load for deep linking, so we clear the URL.
|
||||
this.location.replaceState('');
|
||||
|
||||
navCtrl.setRoot('CoreMainMenuPage', { redirectPage: page, redirectParams: params });
|
||||
return navCtrl.setRoot('CoreMainMenuPage', { redirectPage: page, redirectParams: params });
|
||||
}
|
||||
}).catch((error) => {
|
||||
// Site doesn't exist.
|
||||
navCtrl.setRoot('CoreLoginSitesPage');
|
||||
return navCtrl.setRoot('CoreLoginSitesPage');
|
||||
}).finally(() => {
|
||||
modal.dismiss();
|
||||
});
|
||||
|
@ -794,8 +796,9 @@ export class CoreLoginHelperProvider {
|
|||
* @param {string} page Name of the page to load.
|
||||
* @param {any} params Params to pass to the page.
|
||||
* @param {string} [siteId] Site to load. If not defined, current site.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
redirect(page: string, params?: any, siteId?: string): void {
|
||||
redirect(page: string, params?: any, siteId?: string): Promise<any> {
|
||||
siteId = siteId || this.sitesProvider.getCurrentSiteId();
|
||||
|
||||
if (this.sitesProvider.isLoggedIn()) {
|
||||
|
@ -804,10 +807,11 @@ export class CoreLoginHelperProvider {
|
|||
if (this.sitePluginsProvider.hasSitePluginsLoaded) {
|
||||
// The site has site plugins so the app will be restarted. Store the data and logout.
|
||||
this.appProvider.storeRedirect(siteId, page, params);
|
||||
this.sitesProvider.logout();
|
||||
|
||||
return this.sitesProvider.logout();
|
||||
} else {
|
||||
this.sitesProvider.logout().then(() => {
|
||||
this.loadSiteAndPage(page, params, siteId);
|
||||
return this.sitesProvider.logout().then(() => {
|
||||
return this.loadSiteAndPage(page, params, siteId);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
@ -815,11 +819,13 @@ export class CoreLoginHelperProvider {
|
|||
}
|
||||
} else {
|
||||
if (siteId) {
|
||||
this.loadSiteAndPage(page, params, siteId);
|
||||
return this.loadSiteAndPage(page, params, siteId);
|
||||
} else {
|
||||
this.appProvider.getRootNavController().setRoot('CoreLoginSitesPage');
|
||||
return this.appProvider.getRootNavController().setRoot('CoreLoginSitesPage');
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,219 @@
|
|||
// (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 { CoreLoggerProvider } from '@providers/logger';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
/**
|
||||
* Interface that all click handlers must implement.
|
||||
*/
|
||||
export interface CorePushNotificationsClickHandler {
|
||||
/**
|
||||
* A name to identify the handler.
|
||||
* @type {string}
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Handler's priority. The highest priority is treated first.
|
||||
* @type {number}
|
||||
*/
|
||||
priority?: number;
|
||||
|
||||
/**
|
||||
* Name of the feature this handler is related to.
|
||||
* It will be used to check if the feature is disabled (@see CoreSite.isFeatureDisabled).
|
||||
* @type {string}
|
||||
*/
|
||||
featureName?: string;
|
||||
|
||||
/**
|
||||
* 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>;
|
||||
|
||||
/**
|
||||
* Handle the notification click.
|
||||
*
|
||||
* @param {any} notification The notification to check.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
handleClick(notification: any): Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service to handle push notifications actions to perform when clicked and received.
|
||||
*/
|
||||
@Injectable()
|
||||
export class CorePushNotificationsDelegate {
|
||||
|
||||
protected logger;
|
||||
protected observables: { [s: string]: Subject<any> } = {};
|
||||
protected clickHandlers: { [s: string]: CorePushNotificationsClickHandler } = {};
|
||||
protected counterHandlers: { [s: string]: string } = {};
|
||||
|
||||
constructor(loggerProvider: CoreLoggerProvider, private sitesProvider: CoreSitesProvider, private utils: CoreUtilsProvider) {
|
||||
this.logger = loggerProvider.getInstance('CorePushNotificationsDelegate');
|
||||
this.observables['receive'] = new Subject<any>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called when a push notification is clicked. Sends notification to handlers.
|
||||
*
|
||||
* @param {any} notification Notification clicked.
|
||||
* @return {Promise<any>} Promise resolved when done.
|
||||
*/
|
||||
clicked(notification: any): Promise<any> {
|
||||
if (!notification) {
|
||||
return;
|
||||
}
|
||||
|
||||
const promises = [];
|
||||
let handlers: CorePushNotificationsClickHandler[] = [];
|
||||
|
||||
for (const name in this.clickHandlers) {
|
||||
const handler = this.clickHandlers[name];
|
||||
|
||||
// Check if the handler is disabled for the site.
|
||||
promises.push(this.isFeatureDisabled(handler, notification.site).then((disabled) => {
|
||||
if (!disabled) {
|
||||
// Check if the handler handles the notification.
|
||||
return Promise.resolve(handler.handles(notification)).then((handles) => {
|
||||
if (handles) {
|
||||
handlers.push(handler);
|
||||
}
|
||||
});
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
return this.utils.allPromises(promises).catch(() => {
|
||||
// Ignore errors.
|
||||
}).then(() => {
|
||||
// Sort by priority.
|
||||
handlers = handlers.sort((a, b) => {
|
||||
return a.priority <= b.priority ? 1 : -1;
|
||||
});
|
||||
|
||||
if (handlers[0]) {
|
||||
// Execute the first one.
|
||||
handlers[0].handleClick(notification);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a handler's feature is disabled for a certain site.
|
||||
*
|
||||
* @param {CorePushNotificationsClickHandler} handler Handler to check.
|
||||
* @param {string} siteId The site ID to check.
|
||||
* @return {Promise<boolean>} Promise resolved with boolean: whether the handler feature is disabled.
|
||||
*/
|
||||
protected isFeatureDisabled(handler: CorePushNotificationsClickHandler, siteId: string): Promise<boolean> {
|
||||
if (handler.featureName) {
|
||||
// Check if the feature is disabled.
|
||||
return this.sitesProvider.isFeatureDisabled(handler.featureName, siteId);
|
||||
} else {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called when a push notification is received in foreground (cannot tell when it's received in background).
|
||||
* Sends notification to all handlers.
|
||||
*
|
||||
* @param {any} notification Notification received.
|
||||
*/
|
||||
received(notification: any): void {
|
||||
this.observables['receive'].next(notification);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a push notifications observable for a certain event. Right now, only receive is supported.
|
||||
* let observer = pushNotificationsDelegate.on('receive').subscribe((notification) => {
|
||||
* ...
|
||||
* observer.unsuscribe();
|
||||
*
|
||||
* @param {string} eventName Only receive is permitted.
|
||||
* @return {Subject<any>} Observer to subscribe.
|
||||
*/
|
||||
on(eventName: string): Subject<any> {
|
||||
if (typeof this.observables[eventName] == 'undefined') {
|
||||
const eventNames = Object.keys(this.observables).join(', ');
|
||||
this.logger.warn(`'${eventName}' event name is not allowed. Use one of the following: '${eventNames}'.`);
|
||||
|
||||
return new Subject<any>();
|
||||
}
|
||||
|
||||
return this.observables[eventName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a click handler.
|
||||
*
|
||||
* @param {CorePushNotificationsClickHandler} handler The handler to register.
|
||||
* @return {boolean} True if registered successfully, false otherwise.
|
||||
*/
|
||||
registerClickHandler(handler: CorePushNotificationsClickHandler): boolean {
|
||||
if (typeof this.clickHandlers[handler.name] !== 'undefined') {
|
||||
this.logger.log(`Addon '${handler.name}' already registered`);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
this.logger.log(`Registered addon '${handler.name}'`);
|
||||
this.clickHandlers[handler.name] = handler;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a push notifications handler for update badge counter.
|
||||
*
|
||||
* @param {string} name Handler's name.
|
||||
*/
|
||||
registerCounterHandler(name: string): void {
|
||||
if (typeof this.counterHandlers[name] == 'undefined') {
|
||||
this.logger.debug(`Registered handler '${name}' as badge counter handler.`);
|
||||
this.counterHandlers[name] = name;
|
||||
} else {
|
||||
this.logger.log(`Handler '${name}' as badge counter handler already registered.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a counter handler is present.
|
||||
*
|
||||
* @param {string} name Handler's name.
|
||||
* @return {boolean} If handler name is present.
|
||||
*/
|
||||
isCounterHandlerRegistered(name: string): boolean {
|
||||
return typeof this.counterHandlers[name] != 'undefined';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all counter badge handlers.
|
||||
*
|
||||
* @return {any} with all the handler names.
|
||||
*/
|
||||
getCounterHandlers(): any {
|
||||
return this.counterHandlers;
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ import { CoreInitDelegate } from '@providers/init';
|
|||
import { CoreLoggerProvider } from '@providers/logger';
|
||||
import { CoreSitesProvider, CoreSiteSchema } from '@providers/sites';
|
||||
import { CoreSitesFactoryProvider } from '@providers/sites-factory';
|
||||
import { AddonPushNotificationsDelegate } from './delegate';
|
||||
import { CorePushNotificationsDelegate } from './delegate';
|
||||
import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
|
||||
import { CoreUtilsProvider } from '@providers/utils/utils';
|
||||
import { CoreTextUtilsProvider } from '@providers/utils/text';
|
||||
|
@ -37,7 +37,7 @@ import { CoreSite } from '@classes/site';
|
|||
/**
|
||||
* Data needed to register a device in a Moodle site.
|
||||
*/
|
||||
export interface AddonPushNotificationsRegisterData {
|
||||
export interface CorePushNotificationsRegisterData {
|
||||
/**
|
||||
* App ID.
|
||||
* @type {string}
|
||||
|
@ -85,19 +85,19 @@ export interface AddonPushNotificationsRegisterData {
|
|||
* Service to handle push notifications.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonPushNotificationsProvider {
|
||||
export class CorePushNotificationsProvider {
|
||||
protected logger;
|
||||
protected pushID: string;
|
||||
protected appDB: SQLiteDB;
|
||||
static COMPONENT = 'AddonPushNotificationsProvider';
|
||||
static COMPONENT = 'CorePushNotificationsProvider';
|
||||
|
||||
// Variables for database.
|
||||
// Variables for database. The name still contains the name "addon" for backwards compatibility.
|
||||
static BADGE_TABLE = 'addon_pushnotifications_badge';
|
||||
static PENDING_UNREGISTER_TABLE = 'addon_pushnotifications_pending_unregister';
|
||||
static REGISTERED_DEVICES_TABLE = 'addon_pushnotifications_registered_devices';
|
||||
protected appTablesSchema: SQLiteDBTableSchema[] = [
|
||||
{
|
||||
name: AddonPushNotificationsProvider.BADGE_TABLE,
|
||||
name: CorePushNotificationsProvider.BADGE_TABLE,
|
||||
columns: [
|
||||
{
|
||||
name: 'siteid',
|
||||
|
@ -115,7 +115,7 @@ export class AddonPushNotificationsProvider {
|
|||
primaryKeys: ['siteid', 'addon']
|
||||
},
|
||||
{
|
||||
name: AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE,
|
||||
name: CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE,
|
||||
columns: [
|
||||
{
|
||||
name: 'siteid',
|
||||
|
@ -138,11 +138,11 @@ export class AddonPushNotificationsProvider {
|
|||
}
|
||||
];
|
||||
protected siteSchema: CoreSiteSchema = {
|
||||
name: 'AddonPushNotificationsProvider',
|
||||
name: 'AddonPushNotificationsProvider', // The name still contains "Addon" for backwards compatibility.
|
||||
version: 1,
|
||||
tables: [
|
||||
{
|
||||
name: AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE,
|
||||
name: CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE,
|
||||
columns: [
|
||||
{
|
||||
name: 'appid',
|
||||
|
@ -179,12 +179,12 @@ export class AddonPushNotificationsProvider {
|
|||
};
|
||||
|
||||
constructor(logger: CoreLoggerProvider, protected appProvider: CoreAppProvider, private initDelegate: CoreInitDelegate,
|
||||
protected pushNotificationsDelegate: AddonPushNotificationsDelegate, protected sitesProvider: CoreSitesProvider,
|
||||
protected pushNotificationsDelegate: CorePushNotificationsDelegate, protected sitesProvider: CoreSitesProvider,
|
||||
private badge: Badge, private localNotificationsProvider: CoreLocalNotificationsProvider,
|
||||
private utils: CoreUtilsProvider, private textUtils: CoreTextUtilsProvider, private push: Push,
|
||||
private configProvider: CoreConfigProvider, private device: Device, private zone: NgZone,
|
||||
private translate: TranslateService, private platform: Platform, private sitesFactory: CoreSitesFactoryProvider) {
|
||||
this.logger = logger.getInstance('AddonPushNotificationsProvider');
|
||||
this.logger = logger.getInstance('CorePushNotificationsProvider');
|
||||
this.appDB = appProvider.getDB();
|
||||
this.appDB.createTablesFromSchema(this.appTablesSchema);
|
||||
this.sitesProvider.registerSiteSchema(this.siteSchema);
|
||||
|
@ -207,7 +207,7 @@ export class AddonPushNotificationsProvider {
|
|||
* @return {Promise<any>} Resolved when done.
|
||||
*/
|
||||
cleanSiteCounters(siteId: string): Promise<any> {
|
||||
return this.appDB.deleteRecords(AddonPushNotificationsProvider.BADGE_TABLE, {siteid: siteId} ).finally(() => {
|
||||
return this.appDB.deleteRecords(CorePushNotificationsProvider.BADGE_TABLE, {siteid: siteId} ).finally(() => {
|
||||
this.updateAppCounter();
|
||||
});
|
||||
}
|
||||
|
@ -267,9 +267,9 @@ export class AddonPushNotificationsProvider {
|
|||
/**
|
||||
* Get data to register the device in Moodle.
|
||||
*
|
||||
* @return {AddonPushNotificationsRegisterData} Data.
|
||||
* @return {CorePushNotificationsRegisterData} Data.
|
||||
*/
|
||||
protected getRegisterData(): AddonPushNotificationsRegisterData {
|
||||
protected getRegisterData(): CorePushNotificationsRegisterData {
|
||||
return {
|
||||
appid: CoreConfigConstants.app_id,
|
||||
name: this.device.manufacturer || '',
|
||||
|
@ -338,7 +338,7 @@ export class AddonPushNotificationsProvider {
|
|||
}));
|
||||
|
||||
Promise.all(promises).then(() => {
|
||||
this.localNotificationsProvider.schedule(localNotif, AddonPushNotificationsProvider.COMPONENT, data.site);
|
||||
this.localNotificationsProvider.schedule(localNotif, CorePushNotificationsProvider.COMPONENT, data.site);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -381,11 +381,11 @@ export class AddonPushNotificationsProvider {
|
|||
const promises = [];
|
||||
|
||||
// Remove the device from the local DB.
|
||||
promises.push(site.getDb().deleteRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE,
|
||||
promises.push(site.getDb().deleteRecords(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE,
|
||||
this.getRegisterData()));
|
||||
|
||||
// Remove pending unregisters for this site.
|
||||
promises.push(this.appDB.deleteRecords(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: site.id}));
|
||||
promises.push(this.appDB.deleteRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: site.id}));
|
||||
|
||||
return Promise.all(promises).catch(() => {
|
||||
// Ignore errors.
|
||||
|
@ -397,7 +397,7 @@ export class AddonPushNotificationsProvider {
|
|||
}
|
||||
|
||||
// Store the pending unregister so it's retried again later.
|
||||
return this.appDB.insertRecord(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, {
|
||||
return this.appDB.insertRecord(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE, {
|
||||
siteid: site.id,
|
||||
siteurl: site.getURL(),
|
||||
token: site.getToken(),
|
||||
|
@ -587,7 +587,7 @@ export class AddonPushNotificationsProvider {
|
|||
// Now register the device.
|
||||
return site.write('core_user_add_user_device', this.utils.clone(data)).then((response) => {
|
||||
// Insert the device in the local DB.
|
||||
return site.getDb().insertRecord(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, data)
|
||||
return site.getDb().insertRecord(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, data)
|
||||
.catch((error) => {
|
||||
// Ignore errors.
|
||||
});
|
||||
|
@ -595,7 +595,7 @@ export class AddonPushNotificationsProvider {
|
|||
}
|
||||
}).finally(() => {
|
||||
// Remove pending unregisters for this site.
|
||||
this.appDB.deleteRecords(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: site.id}).catch(() => {
|
||||
this.appDB.deleteRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE, {siteid: site.id}).catch(() => {
|
||||
// Ignore errors.
|
||||
});
|
||||
});
|
||||
|
@ -609,7 +609,7 @@ export class AddonPushNotificationsProvider {
|
|||
* @return {Promise<any>} Promise resolved with the stored badge counter for the addon or site or 0 if none.
|
||||
*/
|
||||
protected getAddonBadge(siteId?: string, addon: string = 'site'): Promise<any> {
|
||||
return this.appDB.getRecord(AddonPushNotificationsProvider.BADGE_TABLE, {siteid: siteId, addon: addon}).then((entry) => {
|
||||
return this.appDB.getRecord(CorePushNotificationsProvider.BADGE_TABLE, {siteid: siteId, addon: addon}).then((entry) => {
|
||||
return (entry && entry.number) || 0;
|
||||
}).catch(() => {
|
||||
return 0;
|
||||
|
@ -627,10 +627,10 @@ export class AddonPushNotificationsProvider {
|
|||
|
||||
if (siteId) {
|
||||
// Check if the site has a pending unregister.
|
||||
promise = this.appDB.getRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, {siteid: siteId});
|
||||
promise = this.appDB.getRecords(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, {siteid: siteId});
|
||||
} else {
|
||||
// Get all pending unregisters.
|
||||
promise = this.appDB.getAllRecords(AddonPushNotificationsProvider.PENDING_UNREGISTER_TABLE);
|
||||
promise = this.appDB.getAllRecords(CorePushNotificationsProvider.PENDING_UNREGISTER_TABLE);
|
||||
}
|
||||
|
||||
return promise.then((results) => {
|
||||
|
@ -665,7 +665,7 @@ export class AddonPushNotificationsProvider {
|
|||
number: value
|
||||
};
|
||||
|
||||
return this.appDB.insertRecord(AddonPushNotificationsProvider.BADGE_TABLE, entry).then(() => {
|
||||
return this.appDB.insertRecord(CorePushNotificationsProvider.BADGE_TABLE, entry).then(() => {
|
||||
return value;
|
||||
});
|
||||
}
|
||||
|
@ -673,21 +673,21 @@ export class AddonPushNotificationsProvider {
|
|||
/**
|
||||
* Check if device should be registered (and unregistered first).
|
||||
*
|
||||
* @param {AddonPushNotificationsRegisterData} data Data of the device.
|
||||
* @param {CorePushNotificationsRegisterData} data Data of the device.
|
||||
* @param {CoreSite} site Site to use.
|
||||
* @return {Promise<{register: boolean, unregister: boolean}>} Promise resolved with booleans: whether to register/unregister.
|
||||
*/
|
||||
protected shouldRegister(data: AddonPushNotificationsRegisterData, site: CoreSite)
|
||||
protected shouldRegister(data: CorePushNotificationsRegisterData, site: CoreSite)
|
||||
: Promise<{register: boolean, unregister: boolean}> {
|
||||
|
||||
// Check if the device is already registered.
|
||||
return site.getDb().getRecords(AddonPushNotificationsProvider.REGISTERED_DEVICES_TABLE, {
|
||||
return site.getDb().getRecords(CorePushNotificationsProvider.REGISTERED_DEVICES_TABLE, {
|
||||
appid: data.appid,
|
||||
uuid: data.uuid
|
||||
}).catch(() => {
|
||||
// Ignore errors.
|
||||
return [];
|
||||
}).then((records: AddonPushNotificationsRegisterData[]) => {
|
||||
}).then((records: CorePushNotificationsRegisterData[]) => {
|
||||
let isStored = false,
|
||||
versionOrPushChanged = false;
|
||||
|
|
@ -14,16 +14,16 @@
|
|||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreCronHandler } from '@providers/cron';
|
||||
import { AddonPushNotificationsProvider } from './pushnotifications';
|
||||
import { CorePushNotificationsProvider } from './pushnotifications';
|
||||
|
||||
/**
|
||||
* Cron handler to force a register on a Moodle site when a site is manually synchronized.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonPushNotificationsRegisterCronHandler implements CoreCronHandler {
|
||||
name = 'AddonPushNotificationsRegisterCronHandler';
|
||||
export class CorePushNotificationsRegisterCronHandler implements CoreCronHandler {
|
||||
name = 'CorePushNotificationsRegisterCronHandler';
|
||||
|
||||
constructor(private pushNotificationsProvider: AddonPushNotificationsProvider) {}
|
||||
constructor(private pushNotificationsProvider: CorePushNotificationsProvider) {}
|
||||
|
||||
/**
|
||||
* Check whether the sync can be executed manually. Call isSync if not defined.
|
|
@ -14,16 +14,16 @@
|
|||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreCronHandler } from '@providers/cron';
|
||||
import { AddonPushNotificationsProvider } from './pushnotifications';
|
||||
import { CorePushNotificationsProvider } from './pushnotifications';
|
||||
|
||||
/**
|
||||
* Cron handler to retry pending unregisters.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AddonPushNotificationsUnregisterCronHandler implements CoreCronHandler {
|
||||
name = 'AddonPushNotificationsUnregisterCronHandler';
|
||||
export class CorePushNotificationsUnregisterCronHandler implements CoreCronHandler {
|
||||
name = 'CorePushNotificationsUnregisterCronHandler';
|
||||
|
||||
constructor(private pushNotificationsProvider: AddonPushNotificationsProvider) {}
|
||||
constructor(private pushNotificationsProvider: CorePushNotificationsProvider) {}
|
||||
|
||||
/**
|
||||
* Execute the process.
|
|
@ -14,10 +14,10 @@
|
|||
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Platform } from 'ionic-angular';
|
||||
import { AddonPushNotificationsProvider } from './providers/pushnotifications';
|
||||
import { AddonPushNotificationsDelegate } from './providers/delegate';
|
||||
import { AddonPushNotificationsRegisterCronHandler } from './providers/register-cron-handler';
|
||||
import { AddonPushNotificationsUnregisterCronHandler } from './providers/unregister-cron-handler';
|
||||
import { CorePushNotificationsProvider } from './providers/pushnotifications';
|
||||
import { CorePushNotificationsDelegate } from './providers/delegate';
|
||||
import { CorePushNotificationsRegisterCronHandler } from './providers/register-cron-handler';
|
||||
import { CorePushNotificationsUnregisterCronHandler } from './providers/unregister-cron-handler';
|
||||
import { CoreCronDelegate } from '@providers/cron';
|
||||
import { CoreEventsProvider } from '@providers/events';
|
||||
import { CoreLoggerProvider } from '@providers/logger';
|
||||
|
@ -25,9 +25,9 @@ import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
|
|||
import { CoreUpdateManagerProvider } from '@providers/update-manager';
|
||||
|
||||
// List of providers (without handlers).
|
||||
export const ADDON_PUSHNOTIFICATIONS_PROVIDERS: any[] = [
|
||||
AddonPushNotificationsProvider,
|
||||
AddonPushNotificationsDelegate
|
||||
export const CORE_PUSHNOTIFICATIONS_PROVIDERS: any[] = [
|
||||
CorePushNotificationsProvider,
|
||||
CorePushNotificationsDelegate
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
@ -36,20 +36,20 @@ export const ADDON_PUSHNOTIFICATIONS_PROVIDERS: any[] = [
|
|||
imports: [
|
||||
],
|
||||
providers: [
|
||||
AddonPushNotificationsProvider,
|
||||
AddonPushNotificationsDelegate,
|
||||
AddonPushNotificationsRegisterCronHandler,
|
||||
AddonPushNotificationsUnregisterCronHandler
|
||||
CorePushNotificationsProvider,
|
||||
CorePushNotificationsDelegate,
|
||||
CorePushNotificationsRegisterCronHandler,
|
||||
CorePushNotificationsUnregisterCronHandler
|
||||
]
|
||||
})
|
||||
export class AddonPushNotificationsModule {
|
||||
constructor(platform: Platform, pushNotificationsProvider: AddonPushNotificationsProvider, eventsProvider: CoreEventsProvider,
|
||||
export class CorePushNotificationsModule {
|
||||
constructor(platform: Platform, pushNotificationsProvider: CorePushNotificationsProvider, eventsProvider: CoreEventsProvider,
|
||||
localNotificationsProvider: CoreLocalNotificationsProvider, loggerProvider: CoreLoggerProvider,
|
||||
updateManager: CoreUpdateManagerProvider, cronDelegate: CoreCronDelegate,
|
||||
registerCronHandler: AddonPushNotificationsRegisterCronHandler,
|
||||
unregisterCronHandler: AddonPushNotificationsUnregisterCronHandler) {
|
||||
registerCronHandler: CorePushNotificationsRegisterCronHandler,
|
||||
unregisterCronHandler: CorePushNotificationsUnregisterCronHandler) {
|
||||
|
||||
const logger = loggerProvider.getInstance('AddonPushNotificationsModule');
|
||||
const logger = loggerProvider.getInstance('CorePushNotificationsModule');
|
||||
|
||||
// Register the handlers.
|
||||
cronDelegate.register(registerCronHandler);
|
||||
|
@ -80,13 +80,13 @@ export class AddonPushNotificationsModule {
|
|||
});
|
||||
|
||||
// Listen for local notification clicks (generated by the app).
|
||||
localNotificationsProvider.registerClick(AddonPushNotificationsProvider.COMPONENT,
|
||||
localNotificationsProvider.registerClick(CorePushNotificationsProvider.COMPONENT,
|
||||
pushNotificationsProvider.notificationClicked.bind(pushNotificationsProvider));
|
||||
|
||||
// Allow migrating the table from the old app to the new schema.
|
||||
updateManager.registerAppTableMigration({
|
||||
name: 'mma_pushnotifications_badge',
|
||||
newName: AddonPushNotificationsProvider.BADGE_TABLE,
|
||||
newName: CorePushNotificationsProvider.BADGE_TABLE,
|
||||
fields: [
|
||||
{
|
||||
name: 'siteid',
|
||||
|
@ -96,6 +96,6 @@ export class AddonPushNotificationsModule {
|
|||
});
|
||||
|
||||
// Migrate the component name.
|
||||
updateManager.registerLocalNotifComponentMigration('mmaPushNotifications', AddonPushNotificationsProvider.COMPONENT);
|
||||
updateManager.registerLocalNotifComponentMigration('mmaPushNotifications', CorePushNotificationsProvider.COMPONENT);
|
||||
}
|
||||
}
|
|
@ -22,7 +22,7 @@ import { CoreLangProvider } from '@providers/lang';
|
|||
import { CoreLocalNotificationsProvider } from '@providers/local-notifications';
|
||||
import { CoreSitesProvider } from '@providers/sites';
|
||||
import { CoreConfigConstants } from '../../../../configconstants';
|
||||
import { AddonPushNotificationsProvider } from '@addon/pushnotifications/providers/pushnotifications';
|
||||
import { CorePushNotificationsProvider } from '@core/pushnotifications/providers/pushnotifications';
|
||||
|
||||
/**
|
||||
* Page that displays the about settings.
|
||||
|
@ -58,7 +58,7 @@ export class CoreSettingsAboutPage {
|
|||
|
||||
constructor(platform: Platform, device: Device, appProvider: CoreAppProvider, fileProvider: CoreFileProvider,
|
||||
initDelegate: CoreInitDelegate, langProvider: CoreLangProvider, sitesProvider: CoreSitesProvider,
|
||||
localNotificationsProvider: CoreLocalNotificationsProvider, pushNotificationsProvider: AddonPushNotificationsProvider) {
|
||||
localNotificationsProvider: CoreLocalNotificationsProvider, pushNotificationsProvider: CorePushNotificationsProvider) {
|
||||
|
||||
const currentSite = sitesProvider.getCurrentSite();
|
||||
|
||||
|
|
|
@ -13,9 +13,12 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||
import { CoreContentLinksHandlerBase } from '@core/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||
import { CoreLoginHelperProvider } from '@core/login/providers/helper';
|
||||
import { CoreCourseHelperProvider } from '@core/course/providers/helper';
|
||||
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||
import { CoreUserProvider } from './user';
|
||||
|
||||
/**
|
||||
|
@ -27,7 +30,9 @@ export class CoreUserParticipantsLinkHandler extends CoreContentLinksHandlerBase
|
|||
featureName = 'CoreCourseOptionsDelegate_CoreUserParticipants';
|
||||
pattern = /\/user\/index\.php/;
|
||||
|
||||
constructor(private userProvider: CoreUserProvider, private loginHelper: CoreLoginHelperProvider) {
|
||||
constructor(private userProvider: CoreUserProvider, private loginHelper: CoreLoginHelperProvider,
|
||||
private courseHelper: CoreCourseHelperProvider, private domUtils: CoreDomUtilsProvider,
|
||||
private linkHelper: CoreContentLinksHelperProvider) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
@ -46,8 +51,22 @@ export class CoreUserParticipantsLinkHandler extends CoreContentLinksHandlerBase
|
|||
|
||||
return [{
|
||||
action: (siteId, navCtrl?): void => {
|
||||
// Always use redirect to make it the new history root (to avoid "loops" in history).
|
||||
this.loginHelper.redirect('CoreUserParticipantsPage', {courseId: courseId}, siteId);
|
||||
const modal = this.domUtils.showModalLoading();
|
||||
|
||||
this.courseHelper.getCourse(courseId, siteId).then((result) => {
|
||||
const params: any = {
|
||||
course: result.course,
|
||||
selectedTab: 'CoreUserParticipants'
|
||||
};
|
||||
|
||||
// Always use redirect to make it the new history root (to avoid "loops" in history).
|
||||
return this.loginHelper.redirect('CoreCourseSectionPage', params, siteId);
|
||||
}).catch(() => {
|
||||
// Cannot get course for some reason, just open the participants page.
|
||||
return this.linkHelper.goInSite(navCtrl, 'CoreUserParticipantsPage', {courseId: courseId}, siteId);
|
||||
}).finally(() => {
|
||||
modal.dismiss();
|
||||
});
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
This files describes API changes in the Moodle Mobile app,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 3.7.0 ===
|
||||
|
||||
- The pushnotifications addon has been moved to core. All imports of that addon need to be fixed to use the right path and name.
|
||||
|
||||
=== 3.6.1 ===
|
||||
|
||||
- The local notifications plugin was updated to its latest version. The new API has some breaking changes, so please check its documentation if you're using local notifications. Also, you need to run "npm install" to update the ionic-native library.
|
||||
|
|
Loading…
Reference in New Issue