diff --git a/config.xml b/config.xml index 0946d1ed6..5fa06d260 100644 --- a/config.xml +++ b/config.xml @@ -35,6 +35,7 @@ + @@ -90,8 +91,6 @@ - - @@ -124,4 +123,7 @@ + + + diff --git a/package.json b/package.json index c82f02d62..daeb780fa 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,9 @@ "rxjs": "5.5.11", "sw-toolbox": "3.6.0", "ts-md5": "^1.2.2", - "zone.js": "0.8.26" + "zone.js": "0.8.26", + "cordova-android": "6.1.2", + "cordova-ios": "4.3.1" }, "devDependencies": { "@ionic/app-scripts": "3.1.9", @@ -97,5 +99,11 @@ }, "browser": { "electron": false + }, + "cordova": { + "platforms": [ + "android", + "ios" + ] } -} +} \ No newline at end of file diff --git a/src/addon/calendar/calendar.module.ts b/src/addon/calendar/calendar.module.ts index f82454173..85aa71eb2 100644 --- a/src/addon/calendar/calendar.module.ts +++ b/src/addon/calendar/calendar.module.ts @@ -58,7 +58,7 @@ export class AddonCalendarModule { return; } - loginHelper.redirect('AddonCalendarListPage', {eventid: data.eventid}, data.siteId); + loginHelper.redirect('AddonCalendarListPage', {eventId: data.eventid}, data.siteId); }); }); } diff --git a/src/addon/calendar/pages/list/list.ts b/src/addon/calendar/pages/list/list.ts index 8f82a3258..4fe69c33e 100644 --- a/src/addon/calendar/pages/list/list.ts +++ b/src/addon/calendar/pages/list/list.ts @@ -78,7 +78,7 @@ export class AddonCalendarListPage implements OnDestroy { }, sitesProvider.getCurrentSiteId()); } - this.eventId = navParams.get('eventid') || false; + this.eventId = navParams.get('eventId') || false; } /** diff --git a/src/addon/mod/assign/providers/assign-sync.ts b/src/addon/mod/assign/providers/assign-sync.ts index a2576b465..ae518eb4b 100644 --- a/src/addon/mod/assign/providers/assign-sync.ts +++ b/src/addon/mod/assign/providers/assign-sync.ts @@ -52,7 +52,6 @@ export interface AddonModAssignSyncResult { export class AddonModAssignSyncProvider extends CoreSyncBaseProvider { static AUTO_SYNCED = 'addon_mod_assign_autom_synced'; - static SYNC_TIME = 300000; protected componentTranslate: string; diff --git a/src/addon/mod/assign/providers/sync-cron-handler.ts b/src/addon/mod/assign/providers/sync-cron-handler.ts index 9cc969259..fe68ccddd 100644 --- a/src/addon/mod/assign/providers/sync-cron-handler.ts +++ b/src/addon/mod/assign/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModAssignSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return 600000; // 10 minutes. + return this.assignSync.syncInterval; } } diff --git a/src/addon/mod/choice/providers/sync-cron-handler.ts b/src/addon/mod/choice/providers/sync-cron-handler.ts index c123021f8..af6cb8e81 100644 --- a/src/addon/mod/choice/providers/sync-cron-handler.ts +++ b/src/addon/mod/choice/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModChoiceSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return 600000; // 10 minutes. + return this.choiceSync.syncInterval; } } diff --git a/src/addon/mod/choice/providers/sync.ts b/src/addon/mod/choice/providers/sync.ts index fb86705b3..03d72e5cd 100644 --- a/src/addon/mod/choice/providers/sync.ts +++ b/src/addon/mod/choice/providers/sync.ts @@ -77,7 +77,7 @@ export class AddonModChoiceSyncProvider extends CoreSyncBaseProvider { // Sync all responses. responses.forEach((response) => { - promises.push(this.syncChoice(response.choiceid, response.userid, siteId).then((result) => { + promises.push(this.syncChoiceIfNeeded(response.choiceid, response.userid, siteId).then((result) => { if (result && result.updated) { // Sync successful, send event. this.eventsProvider.trigger(AddonModChoiceSyncProvider.AUTO_SYNCED, { @@ -91,6 +91,24 @@ export class AddonModChoiceSyncProvider extends CoreSyncBaseProvider { }); } + /** + * Sync an choice only if a certain time has passed since the last time. + * + * @param {number} choiceId Choice ID to be synced. + * @param {number} userId User the answers belong to. + * @param {string} [siteId] Site ID. If not defined, current site. + * @return {Promise} Promise resolved when the choice is synced or it doesn't need to be synced. + */ + syncChoiceIfNeeded(choiceId: number, userId: number, siteId?: string): Promise { + const syncId = this.getSyncId(choiceId, userId); + + return this.isSyncNeeded(syncId, siteId).then((needed) => { + if (needed) { + return this.syncChoice(choiceId, userId, siteId); + } + }); + } + /** * Synchronize a choice. * diff --git a/src/addon/mod/data/providers/sync-cron-handler.ts b/src/addon/mod/data/providers/sync-cron-handler.ts index 2560e571b..31a3db30a 100644 --- a/src/addon/mod/data/providers/sync-cron-handler.ts +++ b/src/addon/mod/data/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModDataSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return 600000; // 10 minutes. + return this.dataSync.syncInterval; } } diff --git a/src/addon/mod/feedback/providers/sync-cron-handler.ts b/src/addon/mod/feedback/providers/sync-cron-handler.ts index e1c93fc95..6ace28013 100644 --- a/src/addon/mod/feedback/providers/sync-cron-handler.ts +++ b/src/addon/mod/feedback/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModFeedbackSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return 600000; // 10 minutes. + return this.feedbackSync.syncInterval; } } diff --git a/src/addon/mod/forum/providers/sync-cron-handler.ts b/src/addon/mod/forum/providers/sync-cron-handler.ts index 3ce2fcbc5..860368b25 100644 --- a/src/addon/mod/forum/providers/sync-cron-handler.ts +++ b/src/addon/mod/forum/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModForumSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return AddonModForumSyncProvider.SYNC_TIME; + return this.forumSync.syncInterval; } } diff --git a/src/addon/mod/forum/providers/sync.ts b/src/addon/mod/forum/providers/sync.ts index 0a201a5f1..64b95f369 100644 --- a/src/addon/mod/forum/providers/sync.ts +++ b/src/addon/mod/forum/providers/sync.ts @@ -36,7 +36,6 @@ export class AddonModForumSyncProvider extends CoreSyncBaseProvider { static AUTO_SYNCED = 'addon_mod_forum_autom_synced'; static MANUAL_SYNCED = 'addon_mod_forum_manual_synced'; - static SYNC_TIME = 600000; protected componentTranslate: string; diff --git a/src/addon/mod/glossary/providers/sync-cron-handler.ts b/src/addon/mod/glossary/providers/sync-cron-handler.ts index fdc3d5921..77ea930d8 100644 --- a/src/addon/mod/glossary/providers/sync-cron-handler.ts +++ b/src/addon/mod/glossary/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModGlossarySyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return AddonModGlossarySyncProvider.SYNC_TIME; + return this.glossarySync.syncInterval; } } diff --git a/src/addon/mod/glossary/providers/sync.ts b/src/addon/mod/glossary/providers/sync.ts index aa82f859a..c78e8920e 100644 --- a/src/addon/mod/glossary/providers/sync.ts +++ b/src/addon/mod/glossary/providers/sync.ts @@ -35,7 +35,6 @@ import { AddonModGlossaryOfflineProvider } from './offline'; export class AddonModGlossarySyncProvider extends CoreSyncBaseProvider { static AUTO_SYNCED = 'addon_mod_glossary_autom_synced'; - static SYNC_TIME = 600000; // 10 minutes. protected componentTranslate: string; diff --git a/src/addon/mod/lesson/providers/lesson-sync.ts b/src/addon/mod/lesson/providers/lesson-sync.ts index 87ddd520b..acefccfe8 100644 --- a/src/addon/mod/lesson/providers/lesson-sync.ts +++ b/src/addon/mod/lesson/providers/lesson-sync.ts @@ -53,7 +53,6 @@ export interface AddonModLessonSyncResult { export class AddonModLessonSyncProvider extends CoreSyncBaseProvider { static AUTO_SYNCED = 'addon_mod_lesson_autom_synced'; - static SYNC_TIME = 300000; protected componentTranslate: string; diff --git a/src/addon/mod/lesson/providers/sync-cron-handler.ts b/src/addon/mod/lesson/providers/sync-cron-handler.ts index a88968db2..0ede470f1 100644 --- a/src/addon/mod/lesson/providers/sync-cron-handler.ts +++ b/src/addon/mod/lesson/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModLessonSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return 600000; + return this.lessonSync.syncInterval; } } diff --git a/src/addon/mod/quiz/accessrules/offlineattempts/providers/handler.ts b/src/addon/mod/quiz/accessrules/offlineattempts/providers/handler.ts index 3d5b38a24..5b7988b06 100644 --- a/src/addon/mod/quiz/accessrules/offlineattempts/providers/handler.ts +++ b/src/addon/mod/quiz/accessrules/offlineattempts/providers/handler.ts @@ -26,7 +26,7 @@ export class AddonModQuizAccessOfflineAttemptsHandler implements AddonModQuizAcc name = 'AddonModQuizAccessOfflineAttempts'; ruleName = 'quizaccess_offlineattempts'; - constructor() { + constructor(protected quizSync: AddonModQuizSyncProvider) { // Nothing to do. } @@ -86,6 +86,6 @@ export class AddonModQuizAccessOfflineAttemptsHandler implements AddonModQuizAcc } // Show warning if last sync was a while ago. - return Date.now() - AddonModQuizSyncProvider.SYNC_TIME > quiz.syncTime; + return Date.now() - this.quizSync.syncInterval > quiz.syncTime; } } diff --git a/src/addon/mod/quiz/providers/quiz-sync.ts b/src/addon/mod/quiz/providers/quiz-sync.ts index 901850d1c..67aca51a6 100644 --- a/src/addon/mod/quiz/providers/quiz-sync.ts +++ b/src/addon/mod/quiz/providers/quiz-sync.ts @@ -52,7 +52,6 @@ export interface AddonModQuizSyncResult { export class AddonModQuizSyncProvider extends CoreSyncBaseProvider { static AUTO_SYNCED = 'addon_mod_quiz_autom_synced'; - static SYNC_TIME = 300000; protected componentTranslate: string; diff --git a/src/addon/mod/quiz/providers/sync-cron-handler.ts b/src/addon/mod/quiz/providers/sync-cron-handler.ts index d25c2d30b..2866f3a08 100644 --- a/src/addon/mod/quiz/providers/sync-cron-handler.ts +++ b/src/addon/mod/quiz/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModQuizSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return AddonModQuizSyncProvider.SYNC_TIME; + return this.quizSync.syncInterval; } } diff --git a/src/addon/mod/scorm/providers/scorm-sync.ts b/src/addon/mod/scorm/providers/scorm-sync.ts index 832508473..ae6281365 100644 --- a/src/addon/mod/scorm/providers/scorm-sync.ts +++ b/src/addon/mod/scorm/providers/scorm-sync.ts @@ -57,7 +57,6 @@ export interface AddonModScormSyncResult { export class AddonModScormSyncProvider extends CoreSyncBaseProvider { static AUTO_SYNCED = 'addon_mod_scorm_autom_synced'; - static SYNC_TIME = 600000; protected componentTranslate: string; diff --git a/src/addon/mod/scorm/providers/sync-cron-handler.ts b/src/addon/mod/scorm/providers/sync-cron-handler.ts index 0d3acecd5..797eeb4bb 100644 --- a/src/addon/mod/scorm/providers/sync-cron-handler.ts +++ b/src/addon/mod/scorm/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModScormSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return AddonModScormSyncProvider.SYNC_TIME; + return this.scormSync.syncInterval; } } diff --git a/src/addon/mod/survey/providers/sync-cron-handler.ts b/src/addon/mod/survey/providers/sync-cron-handler.ts index d26a67561..1949d9e14 100644 --- a/src/addon/mod/survey/providers/sync-cron-handler.ts +++ b/src/addon/mod/survey/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModSurveySyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return 600000; // 10 minutes. + return this.surveySync.syncInterval; } } diff --git a/src/addon/mod/wiki/providers/sync-cron-handler.ts b/src/addon/mod/wiki/providers/sync-cron-handler.ts index ed5fa443f..ce1fa6980 100644 --- a/src/addon/mod/wiki/providers/sync-cron-handler.ts +++ b/src/addon/mod/wiki/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModWikiSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return 600000; // 10 minutes. + return this.wikiSync.syncInterval; } } diff --git a/src/addon/mod/wiki/providers/wiki-sync.ts b/src/addon/mod/wiki/providers/wiki-sync.ts index 186c75ac5..e402174ae 100644 --- a/src/addon/mod/wiki/providers/wiki-sync.ts +++ b/src/addon/mod/wiki/providers/wiki-sync.ts @@ -96,7 +96,6 @@ export class AddonModWikiSyncProvider extends CoreSyncBaseProvider { static AUTO_SYNCED = 'addon_mod_wiki_autom_synced'; static MANUAL_SYNCED = 'addon_mod_wiki_manual_synced'; - static SYNC_TIME = 300000; protected componentTranslate: string; diff --git a/src/addon/mod/workshop/providers/sync-cron-handler.ts b/src/addon/mod/workshop/providers/sync-cron-handler.ts index 86bf07017..05f6a011f 100644 --- a/src/addon/mod/workshop/providers/sync-cron-handler.ts +++ b/src/addon/mod/workshop/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonModWorkshopSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return AddonModWorkshopSyncProvider.SYNC_TIME; + return this.workshopSync.syncInterval; } } diff --git a/src/addon/mod/workshop/providers/sync.ts b/src/addon/mod/workshop/providers/sync.ts index 8c1e6fb15..2b3990e70 100644 --- a/src/addon/mod/workshop/providers/sync.ts +++ b/src/addon/mod/workshop/providers/sync.ts @@ -35,7 +35,6 @@ export class AddonModWorkshopSyncProvider extends CoreSyncBaseProvider { static AUTO_SYNCED = 'addon_mod_workshop_autom_synced'; static MANUAL_SYNCED = 'addon_mod_workshop_manual_synced'; - static SYNC_TIME = 300000; protected componentTranslate: string; diff --git a/src/addon/notes/providers/sync-cron-handler.ts b/src/addon/notes/providers/sync-cron-handler.ts index b0e1e5da1..25d5d2c24 100644 --- a/src/addon/notes/providers/sync-cron-handler.ts +++ b/src/addon/notes/providers/sync-cron-handler.ts @@ -42,6 +42,6 @@ export class AddonNotesSyncCronHandler implements CoreCronHandler { * @return {number} Time between consecutive executions (in ms). */ getInterval(): number { - return 600000; // 10 minutes. + return 300000; // 5 minutes. } } diff --git a/src/addon/qtype/calculated/component/addon-qtype-calculated.html b/src/addon/qtype/calculated/component/addon-qtype-calculated.html index 4f100766f..db25e4f4b 100644 --- a/src/addon/qtype/calculated/component/addon-qtype-calculated.html +++ b/src/addon/qtype/calculated/component/addon-qtype-calculated.html @@ -18,7 +18,7 @@ - + @@ -40,7 +40,7 @@ - + {{option.label}} @@ -56,7 +56,7 @@

{{option.text}}

- + diff --git a/src/addon/qtype/shortanswer/component/addon-qtype-shortanswer.html b/src/addon/qtype/shortanswer/component/addon-qtype-shortanswer.html index bbf7f47bf..550e65863 100644 --- a/src/addon/qtype/shortanswer/component/addon-qtype-shortanswer.html +++ b/src/addon/qtype/shortanswer/component/addon-qtype-shortanswer.html @@ -2,6 +2,6 @@

- + diff --git a/src/components/attachments/core-attachments.html b/src/components/attachments/core-attachments.html index 7343fc4f5..9131826d2 100644 --- a/src/components/attachments/core-attachments.html +++ b/src/components/attachments/core-attachments.html @@ -1,10 +1,10 @@ {{ 'core.maxsizeandattachments' | translate:{$a: {size: maxSizeReadable, attachments: maxSubmissionsReadable} } }} - +

{{ 'core.fileuploader.filesofthesetypes' | translate }}

    -
  • +
  • {{typeInfo.name}} {{typeInfo.extlist}}
diff --git a/src/components/tabs/tab.ts b/src/components/tabs/tab.ts index fe5ef6fc3..b4d8cbae9 100644 --- a/src/components/tabs/tab.ts +++ b/src/components/tabs/tab.ts @@ -47,7 +47,19 @@ export class CoreTabComponent implements OnInit, OnDestroy { @Input() badge?: string; // A badge to add in the tab. @Input() badgeStyle?: string; // The badge color. @Input() enabled = true; // Whether the tab is enabled. - @Input() show = true; // Whether the tab should be shown. + @Input() set show(val: boolean) { // Whether the tab should be shown. Use a setter to detect changes on the value. + if (typeof val != 'undefined') { + const hasChanged = this._show != val; + this._show = val; + + if (this.initialized && hasChanged) { + this.tabs.tabVisibilityChanged(); + } + } + } + get show(): boolean { // Getter to be able to access "_show" just using .show. + return this._show; + } @Input() id?: string; // An ID to identify the tab. @Output() ionSelect: EventEmitter = new EventEmitter(); @@ -56,6 +68,8 @@ export class CoreTabComponent implements OnInit, OnDestroy { element: HTMLElement; // The core-tab element. loaded = false; + initialized = false; + _show = true; constructor(protected tabs: CoreTabsComponent, element: ElementRef, protected domUtils: CoreDomUtilsProvider) { this.element = element.nativeElement; @@ -66,6 +80,7 @@ export class CoreTabComponent implements OnInit, OnDestroy { */ ngOnInit(): void { this.tabs.addTab(this); + this.initialized = true; } /** diff --git a/src/components/tabs/tabs.ts b/src/components/tabs/tabs.ts index 2629763ae..2d772fcd7 100644 --- a/src/components/tabs/tabs.ts +++ b/src/components/tabs/tabs.ts @@ -237,10 +237,13 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges { }, 0); this.slidesShown = Math.min(this.maxSlides, this.numTabsShown); - this.slides.update(); - this.slides.resize(); this.slideChanged(); + + setTimeout(() => { + this.slides.update(); + this.slides.resize(); + }); } protected calculateMaxSlides(): void { @@ -357,4 +360,11 @@ export class CoreTabsComponent implements OnInit, AfterViewInit, OnChanges { this.tabs = newTabs; } } + + /** + * Function to call when the visibility of a tab has changed. + */ + tabVisibilityChanged(): void { + this.updateSlides(); + } } diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts index ef2460cb0..844c446fa 100644 --- a/src/core/login/providers/helper.ts +++ b/src/core/login/providers/helper.ts @@ -160,11 +160,13 @@ export class CoreLoginHelperProvider { return false; } - const modal = this.domUtils.showModalLoading('core.login.authenticating', true); - let siteData: CoreLoginSSOData; + let siteData: CoreLoginSSOData, + modal; // Wait for app to be ready. this.initDelegate.ready().then(() => { + modal = this.domUtils.showModalLoading('core.login.authenticating', true); + return this.validateBrowserSSOLogin(url); }).then((data) => { siteData = data; diff --git a/src/core/mainmenu/pages/menu/menu.ts b/src/core/mainmenu/pages/menu/menu.ts index 043cf3965..a2393ed8a 100644 --- a/src/core/mainmenu/pages/menu/menu.ts +++ b/src/core/mainmenu/pages/menu/menu.ts @@ -89,8 +89,10 @@ export class CoreMainMenuPage implements OnDestroy { this.initialTab = 0; for (let i = 0; i < this.tabs.length; i++) { - if (this.tabs[i].page == this.redirectPage) { + const tab = this.tabs[i]; + if (tab.page == this.redirectPage) { this.initialTab = i + 1; + tab.pageParams = Object.assign(tab.pageParams || {}, this.redirectParams); break; } } diff --git a/src/core/question/classes/base-question-component.ts b/src/core/question/classes/base-question-component.ts index 8b79eb23b..49642e774 100644 --- a/src/core/question/classes/base-question-component.ts +++ b/src/core/question/classes/base-question-component.ts @@ -291,10 +291,12 @@ export class CoreQuestionBaseComponent { }; // Check if question is marked as correct. - if (input.className.indexOf('incorrect') >= 0) { - this.question.input.isCorrect = 0; - } else if (input.className.indexOf('correct') >= 0) { - this.question.input.isCorrect = 1; + if (input.classList.contains('incorrect')) { + this.question.input.correctClass = 'core-question-incorrect'; + } else if (input.classList.contains('correct')) { + this.question.input.correctClass = 'core-question-correct'; + } else if (input.classList.contains('partiallycorrect')) { + this.question.input.correctClass = 'core-question-partiallycorrect'; } } diff --git a/src/providers/file.ts b/src/providers/file.ts index 9677ab62f..15ac2513a 100644 --- a/src/providers/file.ts +++ b/src/providers/file.ts @@ -609,7 +609,17 @@ export class CoreFileProvider { return this.file.moveFile(commonPath, originalPath, commonPath, newPath); } else { - return this.file.moveFile(this.basePath, originalPath, this.basePath, newPath); + return this.file.moveFile(this.basePath, originalPath, this.basePath, newPath).catch((error) => { + // The move can fail if the path has encoded characters. Try again if that's the case. + const decodedOriginal = decodeURI(originalPath), + decodedNew = decodeURI(newPath); + + if (decodedOriginal != originalPath || decodedNew != newPath) { + return this.file.moveFile(this.basePath, decodedOriginal, this.basePath, decodedNew); + } else { + return Promise.reject(error); + } + }); } }); } @@ -645,7 +655,17 @@ export class CoreFileProvider { return this.file.copyFile(fromDir, fromFileAndDir.name, toDir, toFileAndDir.name); } else { - return this.file.copyFile(this.basePath, from, this.basePath, to); + return this.file.copyFile(this.basePath, from, this.basePath, to).catch((error) => { + // The copy can fail if the path has encoded characters. Try again if that's the case. + const decodedFrom = decodeURI(from), + decodedTo = decodeURI(to); + + if (from != decodedFrom || to != decodedTo) { + return this.file.copyFile(this.basePath, decodedFrom, this.basePath, decodedTo); + } else { + return Promise.reject(error); + } + }); } }); } diff --git a/src/providers/local-notifications.ts b/src/providers/local-notifications.ts index 7afa1db58..4002a066d 100644 --- a/src/providers/local-notifications.ts +++ b/src/providers/local-notifications.ts @@ -18,6 +18,7 @@ import { LocalNotifications, ILocalNotification } from '@ionic-native/local-noti import { TranslateService } from '@ngx-translate/core'; import { CoreAppProvider } from './app'; import { CoreConfigProvider } from './config'; +import { CoreEventsProvider } from './events'; import { CoreLoggerProvider } from './logger'; import { CoreTextUtilsProvider } from './utils/text'; import { CoreUtilsProvider } from './utils/utils'; @@ -117,10 +118,31 @@ export class CoreLocalNotificationsProvider { constructor(logger: CoreLoggerProvider, private localNotifications: LocalNotifications, private platform: Platform, private appProvider: CoreAppProvider, private utils: CoreUtilsProvider, private configProvider: CoreConfigProvider, - private textUtils: CoreTextUtilsProvider, private translate: TranslateService, private alertCtrl: AlertController) { + private textUtils: CoreTextUtilsProvider, private translate: TranslateService, private alertCtrl: AlertController, + eventsProvider: CoreEventsProvider) { + this.logger = logger.getInstance('CoreLocalNotificationsProvider'); this.appDB = appProvider.getDB(); this.appDB.createTablesFromSchema(this.tablesSchema); + + localNotifications.on('trigger', (notification, state) => { + this.trigger(notification); + }); + + localNotifications.on('click', (notification, state) => { + if (notification && notification.data) { + this.logger.debug('Notification clicked: ', notification.data); + + const data = textUtils.parseJSON(notification.data); + this.notifyClick(data); + } + }); + + eventsProvider.on(CoreEventsProvider.SITE_DELETED, (site) => { + if (site) { + this.cancelSiteNotifications(site.id); + } + }); } /**