From b19a1f8fe1551d151c326953d62f7b91b322e03f Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 5 Jun 2018 08:11:40 +0200 Subject: [PATCH 1/8] MOBILE-2428 update: Implement calendar update task --- src/addon/calendar/providers/calendar.ts | 35 ++++++++++++++++--- src/components/split-view/split-view.ts | 1 - src/providers/update-manager.ts | 43 ++++++++++++++---------- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/addon/calendar/providers/calendar.ts b/src/addon/calendar/providers/calendar.ts index 226fde369..794818ff7 100644 --- a/src/addon/calendar/providers/calendar.ts +++ b/src/addon/calendar/providers/calendar.ts @@ -31,9 +31,9 @@ export class AddonCalendarProvider { static DAYS_INTERVAL = 30; static COMPONENT = 'AddonCalendarEvents'; static DEFAULT_NOTIFICATION_TIME_CHANGED = 'AddonCalendarDefaultNotificationTimeChangedEvent'; - protected DEFAULT_NOTIFICATION_TIME_SETTING = 'mmaCalendarDefaultNotifTime'; + static DEFAULT_NOTIFICATION_TIME_SETTING = 'mmaCalendarDefaultNotifTime'; + static DEFAULT_NOTIFICATION_TIME = 60; protected ROOT_CACHE_KEY = 'mmaCalendar:'; - protected DEFAULT_NOTIFICATION_TIME = 60; // Variables for database. static EVENTS_TABLE = 'addon_calendar_events'; @@ -136,6 +136,18 @@ export class AddonCalendarProvider { this.sitesProvider.createTablesFromSchema(this.tablesSchema); } + /** + * Get all calendar events from local Db. + * + * @param {string} [siteId] ID of the site the event belongs to. If not defined, use current site. + * @return {Promise} Promise resolved with all the events. + */ + getAllEventsFromLocalDb(siteId?: string): Promise { + return this.sitesProvider.getSite(siteId).then((site) => { + return site.getDb().getAllRecords(AddonCalendarProvider.EVENTS_TABLE); + }); + } + /** * Get the configured default notification time. * @@ -145,9 +157,9 @@ export class AddonCalendarProvider { getDefaultNotificationTime(siteId?: string): Promise { siteId = siteId || this.sitesProvider.getCurrentSiteId(); - const key = this.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId; + const key = AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId; - return this.configProvider.get(key, this.DEFAULT_NOTIFICATION_TIME); + return this.configProvider.get(key, AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME); } /** @@ -496,11 +508,24 @@ export class AddonCalendarProvider { setDefaultNotificationTime(time: number, siteId?: string): Promise { siteId = siteId || this.sitesProvider.getCurrentSiteId(); - const key = this.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId; + const key = AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME_SETTING + '#' + siteId; return this.configProvider.set(key, time); } + /** + * Store an event in local DB as it is. + * + * @param {any} event Event to store. + * @param {string} [siteId] ID of the site the event belongs to. If not defined, use current site. + * @return {Promise} Promise resolved when stored. + */ + storeEventInLocalDb(event: any, siteId?: string): Promise { + return this.sitesProvider.getSite(siteId).then((site) => { + return site.getDb().insertRecord(AddonCalendarProvider.EVENTS_TABLE, event); + }); + } + /** * Store events in local DB. * diff --git a/src/components/split-view/split-view.ts b/src/components/split-view/split-view.ts index e585a0ee2..eb866c36a 100644 --- a/src/components/split-view/split-view.ts +++ b/src/components/split-view/split-view.ts @@ -41,7 +41,6 @@ import { NavController, Nav } from 'ionic-angular'; templateUrl: 'core-split-view.html' }) export class CoreSplitViewComponent implements OnInit { - // @todo Mix both panels header buttons @ViewChild('detailNav') detailNav: Nav; @Input() when?: string | boolean = 'md'; diff --git a/src/providers/update-manager.ts b/src/providers/update-manager.ts index 183d1b32b..350cb6104 100644 --- a/src/providers/update-manager.ts +++ b/src/providers/update-manager.ts @@ -22,6 +22,7 @@ import { CoreLoggerProvider } from './logger'; import { CoreSitesProvider } from './sites'; import { CoreUtilsProvider } from './utils/utils'; import { CoreConfigConstants } from '../configconstants'; +import { AddonCalendarProvider } from '@addon/calendar/providers/calendar'; import { SQLiteDB } from '@classes/sqlitedb'; /** @@ -323,7 +324,8 @@ export class CoreUpdateManagerProvider implements CoreInitHandler { constructor(logger: CoreLoggerProvider, private configProvider: CoreConfigProvider, private sitesProvider: CoreSitesProvider, private filepoolProvider: CoreFilepoolProvider, private notifProvider: CoreLocalNotificationsProvider, - private utils: CoreUtilsProvider, private appProvider: CoreAppProvider) { + private utils: CoreUtilsProvider, private appProvider: CoreAppProvider, + private calendarProvider: AddonCalendarProvider) { this.logger = logger.getInstance('CoreUpdateManagerProvider'); } @@ -358,9 +360,8 @@ export class CoreUpdateManagerProvider implements CoreInitHandler { promises.push(this.setSitesConfig()); } - if (versionCode >= 2018 && versionApplied < 2018 && versionApplied > 0) { - promises.push(this.adaptForumOfflineStores()); - } + // In version 2018 we adapted the forum offline stores to match a new schema. + // However, due to the migration of data to SQLite we can no longer do that. return Promise.all(promises).then(() => { return this.configProvider.set(this.VERSION_APPLIED, versionCode); @@ -567,8 +568,27 @@ export class CoreUpdateManagerProvider implements CoreInitHandler { return Promise.resolve(); } - // @todo: Implement it once Calendar addon is implemented. - return Promise.resolve(); + return this.sitesProvider.getSitesIds().then((siteIds) => { + + const promises = []; + siteIds.forEach((siteId) => { + // Get stored events. + promises.push(this.calendarProvider.getAllEventsFromLocalDb(siteId).then((events) => { + const eventPromises = []; + + events.forEach((event) => { + if (event.notificationtime == AddonCalendarProvider.DEFAULT_NOTIFICATION_TIME) { + event.notificationtime = -1; + eventPromises.push(this.calendarProvider.storeEventInLocalDb(event, siteId)); + } + }); + + return Promise.all(eventPromises); + })); + }); + + return Promise.all(promises); + }); } /** @@ -626,15 +646,4 @@ export class CoreUpdateManagerProvider implements CoreInitHandler { }); }); } - - /** - * The data stored for offline discussions and posts changed its format. Adapt the entries already stored. - * Since it can be slow, we'll only block migrating the db of current site, the rest will be in background. - * - * @return {Promise} Promise resolved when the db is migrated. - */ - protected adaptForumOfflineStores(): Promise { - // @todo: Implement it once Forum addon is implemented. - return Promise.resolve(); - } } From 7c08fb4b77443495316adeb3579c6a0f418110e4 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 6 Jun 2018 09:49:10 +0200 Subject: [PATCH 2/8] MOBILE-2428 addon: Fix todo in glossary and wiki --- src/addon/mod/glossary/pages/edit/edit.html | 4 +--- src/addon/mod/wiki/pages/edit/edit.html | 4 +++- src/addon/mod/wiki/pages/edit/edit.scss | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 src/addon/mod/wiki/pages/edit/edit.scss diff --git a/src/addon/mod/glossary/pages/edit/edit.html b/src/addon/mod/glossary/pages/edit/edit.html index f42d75b3e..928efecdd 100644 --- a/src/addon/mod/glossary/pages/edit/edit.html +++ b/src/addon/mod/glossary/pages/edit/edit.html @@ -15,9 +15,7 @@ {{ 'addon.mod_glossary.definition' | translate }} - - + {{ 'addon.mod_glossary.categories' | translate }} diff --git a/src/addon/mod/wiki/pages/edit/edit.html b/src/addon/mod/wiki/pages/edit/edit.html index b8b029fb2..4acb53dc9 100644 --- a/src/addon/mod/wiki/pages/edit/edit.html +++ b/src/addon/mod/wiki/pages/edit/edit.html @@ -20,7 +20,9 @@ - {{ 'addon.mod_wiki.wrongversionlock' | translate }} + + {{ 'addon.mod_wiki.wrongversionlock' | translate }} + diff --git a/src/addon/mod/wiki/pages/edit/edit.scss b/src/addon/mod/wiki/pages/edit/edit.scss new file mode 100644 index 000000000..ccb35ae13 --- /dev/null +++ b/src/addon/mod/wiki/pages/edit/edit.scss @@ -0,0 +1,5 @@ +page-addon-mod-wiki-edit { + .addon-mod_wiki-wrongversionlock .label { + margin: 0; + } +} From d61a2e597ca6fd5240b579d456f2353824a7307a Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 6 Jun 2018 13:17:18 +0200 Subject: [PATCH 3/8] MOBILE-2428 core: Fix and complete input errors --- .../component/addon-user-profile-field-checkbox.html | 6 ++++-- .../component/addon-user-profile-field-datetime.html | 1 + .../menu/component/addon-user-profile-field-menu.html | 1 + .../text/component/addon-user-profile-field-text.html | 1 + .../component/addon-user-profile-field-textarea.html | 5 ++++- src/components/input-errors/core-input-errors.html | 10 +++++++++- src/components/input-errors/input-errors.ts | 4 +++- src/components/rich-text-editor/rich-text-editor.ts | 7 +++++++ src/core/login/pages/email-signup/email-signup.html | 6 ++++-- 9 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/addon/userprofilefield/checkbox/component/addon-user-profile-field-checkbox.html b/src/addon/userprofilefield/checkbox/component/addon-user-profile-field-checkbox.html index 41170009e..086d5534f 100644 --- a/src/addon/userprofilefield/checkbox/component/addon-user-profile-field-checkbox.html +++ b/src/addon/userprofilefield/checkbox/component/addon-user-profile-field-checkbox.html @@ -10,8 +10,10 @@ - {{ field.name }} + + {{ field.name }} + + - \ No newline at end of file diff --git a/src/addon/userprofilefield/datetime/component/addon-user-profile-field-datetime.html b/src/addon/userprofilefield/datetime/component/addon-user-profile-field-datetime.html index 5f7a554a0..34423ce92 100644 --- a/src/addon/userprofilefield/datetime/component/addon-user-profile-field-datetime.html +++ b/src/addon/userprofilefield/datetime/component/addon-user-profile-field-datetime.html @@ -7,4 +7,5 @@ {{ field.name }} + \ No newline at end of file diff --git a/src/addon/userprofilefield/menu/component/addon-user-profile-field-menu.html b/src/addon/userprofilefield/menu/component/addon-user-profile-field-menu.html index ce81fe385..351812d26 100644 --- a/src/addon/userprofilefield/menu/component/addon-user-profile-field-menu.html +++ b/src/addon/userprofilefield/menu/component/addon-user-profile-field-menu.html @@ -10,4 +10,5 @@ {{ 'core.choosedots' | translate }} {{option}} + diff --git a/src/addon/userprofilefield/text/component/addon-user-profile-field-text.html b/src/addon/userprofilefield/text/component/addon-user-profile-field-text.html index 8701248f2..1ca1a727d 100644 --- a/src/addon/userprofilefield/text/component/addon-user-profile-field-text.html +++ b/src/addon/userprofilefield/text/component/addon-user-profile-field-text.html @@ -7,4 +7,5 @@ {{ field.name }} + diff --git a/src/addon/userprofilefield/textarea/component/addon-user-profile-field-textarea.html b/src/addon/userprofilefield/textarea/component/addon-user-profile-field-textarea.html index 4921c3675..4a993015b 100644 --- a/src/addon/userprofilefield/textarea/component/addon-user-profile-field-textarea.html +++ b/src/addon/userprofilefield/textarea/component/addon-user-profile-field-textarea.html @@ -5,6 +5,9 @@ - {{ field.name }} + + {{ field.name }} + + \ No newline at end of file diff --git a/src/components/input-errors/core-input-errors.html b/src/components/input-errors/core-input-errors.html index 390ad0ce0..e960807e8 100644 --- a/src/components/input-errors/core-input-errors.html +++ b/src/components/input-errors/core-input-errors.html @@ -1,7 +1,15 @@ - + diff --git a/src/core/login/pages/init/init.ts b/src/core/login/pages/init/init.ts index 2770bcf4e..9d58eb521 100644 --- a/src/core/login/pages/init/init.ts +++ b/src/core/login/pages/init/init.ts @@ -14,6 +14,7 @@ import { Component } from '@angular/core'; import { IonicPage, NavController } from 'ionic-angular'; +import { SplashScreen } from '@ionic-native/splash-screen'; import { CoreAppProvider } from '@providers/app'; import { CoreInitDelegate } from '@providers/init'; import { CoreSitesProvider } from '@providers/sites'; @@ -31,7 +32,8 @@ import { CoreLoginHelperProvider } from '../../providers/helper'; export class CoreLoginInitPage { constructor(private navCtrl: NavController, private appProvider: CoreAppProvider, private initDelegate: CoreInitDelegate, - private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider) { } + private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider, + private splashScreen: SplashScreen) { } /** * View loaded. @@ -51,11 +53,11 @@ export class CoreLoginInitPage { // The redirect is pointing to a site, load it. return this.sitesProvider.loadSite(redirectData.siteId).then(() => { if (!this.loginHelper.isSiteLoggedOut(redirectData.page, redirectData.params)) { - this.navCtrl.setRoot(redirectData.page, redirectData.params, { animate: false }); + return this.navCtrl.setRoot(redirectData.page, redirectData.params, { animate: false }); } }).catch(() => { // Site doesn't exist. - this.loadPage(); + return this.loadPage(); }); } else { // No site to load, just open the state. @@ -64,24 +66,37 @@ export class CoreLoginInitPage { } } - this.loadPage(); + return this.loadPage(); + }).then(() => { + // If we hide the splash screen now, the init view is still seen for an instant. Wait a bit to make sure it isn't seen. + setTimeout(() => { + this.splashScreen.hide(); + }, 100); }); } /** * Load the right page. + * + * @return {Promise} Promise resolved when done. */ - protected loadPage(): void { + protected loadPage(): Promise { if (this.sitesProvider.isLoggedIn()) { if (!this.loginHelper.isSiteLoggedOut()) { - this.loginHelper.goToSiteInitialPage(); + // User is logged in, go to site initial page. + return this.loginHelper.goToSiteInitialPage(); + } else { + // The site is marked as logged out. Logout and try again. + return this.sitesProvider.logout().then(() => { + return this.loadPage(); + }); } } else { - this.sitesProvider.hasSites().then((hasSites) => { + return this.sitesProvider.hasSites().then((hasSites) => { if (hasSites) { - this.navCtrl.setRoot('CoreLoginSitesPage'); + return this.navCtrl.setRoot('CoreLoginSitesPage'); } else { - this.loginHelper.goToAddSite(true); + return this.loginHelper.goToAddSite(true); } }); } diff --git a/src/core/login/pages/reconnect/reconnect.html b/src/core/login/pages/reconnect/reconnect.html index f2b454762..47bfdf501 100644 --- a/src/core/login/pages/reconnect/reconnect.html +++ b/src/core/login/pages/reconnect/reconnect.html @@ -33,7 +33,7 @@
- + diff --git a/src/core/login/pages/site/site.html b/src/core/login/pages/site/site.html index a23e975ff..3b13f0698 100644 --- a/src/core/login/pages/site/site.html +++ b/src/core/login/pages/site/site.html @@ -19,7 +19,7 @@

{{ 'core.login.newsitedescription' | translate }}

- +
diff --git a/src/core/login/pages/site/site.ts b/src/core/login/pages/site/site.ts index 77bb3eb2c..dcd6752fb 100644 --- a/src/core/login/pages/site/site.ts +++ b/src/core/login/pages/site/site.ts @@ -13,7 +13,7 @@ // limitations under the License. import { Component } from '@angular/core'; -import { IonicPage, NavController, ModalController } from 'ionic-angular'; +import { IonicPage, NavController, ModalController, NavParams } from 'ionic-angular'; import { CoreAppProvider } from '@providers/app'; import { CoreSitesProvider } from '@providers/sites'; import { CoreDomUtilsProvider } from '@providers/utils/dom'; @@ -33,10 +33,14 @@ export class CoreLoginSitePage { siteForm: FormGroup; fixedSites: any[]; displayAsButtons = false; + showKeyboard = false; - constructor(private navCtrl: NavController, fb: FormBuilder, private appProvider: CoreAppProvider, + constructor(navParams: NavParams, private navCtrl: NavController, fb: FormBuilder, private appProvider: CoreAppProvider, private sitesProvider: CoreSitesProvider, private loginHelper: CoreLoginHelperProvider, private modalCtrl: ModalController, private domUtils: CoreDomUtilsProvider) { + + this.showKeyboard = !!navParams.get('showKeyboard'); + let url = ''; // Load fixed sites if they're set. diff --git a/src/core/login/pages/sites/sites.ts b/src/core/login/pages/sites/sites.ts index 7e659e9c6..a1706e522 100644 --- a/src/core/login/pages/sites/sites.ts +++ b/src/core/login/pages/sites/sites.ts @@ -67,7 +67,7 @@ export class CoreLoginSitesPage { * Go to the page to add a site. */ add(): void { - this.loginHelper.goToAddSite(false); + this.loginHelper.goToAddSite(false, true); } /** @@ -91,7 +91,7 @@ export class CoreLoginSitesPage { // If there are no sites left, go to add site. this.sitesProvider.hasSites().then((hasSites) => { if (!hasSites) { - this.loginHelper.goToAddSite(true); + this.loginHelper.goToAddSite(true, true); } }); }).catch((error) => { diff --git a/src/core/login/providers/helper.ts b/src/core/login/providers/helper.ts index 15db817c6..942fb37da 100644 --- a/src/core/login/providers/helper.ts +++ b/src/core/login/providers/helper.ts @@ -380,9 +380,10 @@ export class CoreLoginHelperProvider { * If a fixed URL is configured, go to credentials instead. * * @param {boolean} [setRoot] True to set the new page as root, false to add it to the stack. + * @param {boolean} [showKeyboard] Whether to show keyboard in the new page. Only if no fixed URL set. * @return {Promise} Promise resolved when done. */ - goToAddSite(setRoot?: boolean): Promise { + goToAddSite(setRoot?: boolean, showKeyboard?: boolean): Promise { let pageName, params; @@ -395,6 +396,9 @@ export class CoreLoginHelperProvider { params = { siteUrl: url }; } else { pageName = 'CoreLoginSitePage'; + params = { + showKeyboard: showKeyboard + }; } if (setRoot) {