From 9b0e4f0f0e998461d8220f78bbe181e8200a3cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 18 Mar 2021 14:53:23 +0100 Subject: [PATCH 01/10] MOBILE-3640 typings: Change wrong module type names --- src/addons/mod/assign/services/assign.ts | 4 ++-- src/addons/mod/lesson/services/lesson.ts | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/addons/mod/assign/services/assign.ts b/src/addons/mod/assign/services/assign.ts index f575c07ee..237703ab4 100644 --- a/src/addons/mod/assign/services/assign.ts +++ b/src/addons/mod/assign/services/assign.ts @@ -467,7 +467,7 @@ export class AddonModAssignProvider { ): Promise<{ canviewsubmissions: boolean; submissions?: AddonModAssignSubmission[] }> { const site = await CoreSites.getSite(options.siteId); - const params: ModAssignGetSubmissionsWSParams = { + const params: AddonModAssignGetSubmissionsWSParams = { assignmentids: [assignId], }; const preSets: CoreSiteWSPreSets = { @@ -1681,7 +1681,7 @@ export type AddonModAssignGetAssignmentsWSResponse = { /** * Params of mod_assign_get_submissions WS. */ -type ModAssignGetSubmissionsWSParams = { +type AddonModAssignGetSubmissionsWSParams = { assignmentids: number[]; // 1 or more assignment ids. status?: string; // Status. since?: number; // Submitted since. diff --git a/src/addons/mod/lesson/services/lesson.ts b/src/addons/mod/lesson/services/lesson.ts index 5bff0aceb..4fa222b27 100644 --- a/src/addons/mod/lesson/services/lesson.ts +++ b/src/addons/mod/lesson/services/lesson.ts @@ -2165,7 +2165,7 @@ export class AddonModLessonProvider { const site = await CoreSites.getSite(options.siteId); const userId = options.userId || site.getUserId(); - const params: ModLessonGetUserTimersWSParams = { + const params: AddonModLessonGetUserTimersWSParams = { lessonid: lessonId, userid: userId, }; @@ -2176,7 +2176,7 @@ export class AddonModLessonProvider { ...CoreSites.getReadingStrategyPreSets(options.readingStrategy), // Include reading strategy preSets. }; - const response = await site.read('mod_lesson_get_user_timers', params, preSets); + const response = await site.read('mod_lesson_get_user_timers', params, preSets); return response.timers; } @@ -4027,7 +4027,7 @@ export type AddonModLessonAttemptsOverviewsAttemptWSData = { /** * Params of mod_lesson_get_user_timers WS. */ -export type ModLessonGetUserTimersWSParams = { +export type AddonModLessonGetUserTimersWSParams = { lessonid: number; // Lesson instance id. userid?: number; // The user id (empty for current user). }; @@ -4035,7 +4035,7 @@ export type ModLessonGetUserTimersWSParams = { /** * Data returned by mod_lesson_get_user_timers WS. */ -export type ModLessonGetUserTimersWSResponse = { +export type AddonModLessonGetUserTimersWSResponse = { timers: AddonModLessonUserTimerWSData[]; warnings?: CoreWSExternalWarning[]; }; From 2d53e954a05eac7ae69062e9e704518f3d8705ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Thu, 18 Mar 2021 16:01:05 +0100 Subject: [PATCH 02/10] MOBILE-3640 db: Migration db helper function --- .../calendar/services/database/calendar.ts | 15 +----- src/core/classes/sqlitedb.ts | 43 +++++++++++++++ .../features/h5p/services/database/h5p.ts | 20 ++----- src/core/services/database/sites.ts | 52 ++++--------------- 4 files changed, 56 insertions(+), 74 deletions(-) diff --git a/src/addons/calendar/services/database/calendar.ts b/src/addons/calendar/services/database/calendar.ts index 711239fbc..c6d3acd3d 100644 --- a/src/addons/calendar/services/database/calendar.ts +++ b/src/addons/calendar/services/database/calendar.ts @@ -201,7 +201,6 @@ export const CALENDAR_SITE_SCHEMA: CoreSiteSchema = { ], async migrate(db: SQLiteDB, oldVersion: number): Promise { if (oldVersion < 3) { - const newTable = EVENTS_TABLE; let oldTable = 'addon_calendar_events_2'; try { @@ -211,19 +210,7 @@ export const CALENDAR_SITE_SCHEMA: CoreSiteSchema = { oldTable = 'addon_calendar_events'; } - try { - await db.tableExists(oldTable); - - // Move the records from the old table. - const events = await db.getAllRecords(oldTable); - const promises = events.map((event) => db.insertRecord(newTable, event)); - - await Promise.all(promises); - - db.dropTable(oldTable); - } catch { - // Old table does not exist, ignore. - } + await db.migrateTable(oldTable, EVENTS_TABLE); } }, }; diff --git a/src/core/classes/sqlitedb.ts b/src/core/classes/sqlitedb.ts index 4aa39378c..4c1deb91b 100644 --- a/src/core/classes/sqlitedb.ts +++ b/src/core/classes/sqlitedb.ts @@ -856,6 +856,49 @@ export class SQLiteDB { await this.execute(`INSERT INTO ${table} SELECT ${fields} FROM ${source} ${select}`, params); } + /** + * Helper migration function for tables. + * It will check if old table exists and drop it when finished. + * + * @param oldTable Old table name. + * @param newTable New table name. + * @param mapCallback Mapping callback to migrate each record. + * @return Resolved when done. + */ + async migrateTable( + oldTable: string, + newTable: string, + mapCallback?: (record: SQLiteDBRecordValues) => SQLiteDBRecordValues, + ): Promise { + try { + await this.tableExists(oldTable); + } catch (error) { + // Old table does not exist, ignore. + return; + } + + // Move the records from the old table. + if (mapCallback) { + const records = await this.getAllRecords(oldTable); + const promises = records.map((record) => { + record = mapCallback(record); + + return this.insertRecord(newTable, record); + }); + + await Promise.all(promises); + } else { + // No changes needed. + await this.insertRecordsFrom(newTable, oldTable); + } + + try { + await this.dropTable(oldTable); + } catch (error) { + // Error deleting old table, ignore. + } + } + /** * Ensures that limit params are numeric and positive integers, to be passed to the database. * We explicitly treat null, '' and -1 as 0 in order to provide compatibility with how limit diff --git a/src/core/features/h5p/services/database/h5p.ts b/src/core/features/h5p/services/database/h5p.ts index f6605d529..a324a1ae2 100644 --- a/src/core/features/h5p/services/database/h5p.ts +++ b/src/core/features/h5p/services/database/h5p.ts @@ -244,27 +244,13 @@ export const SITE_SCHEMA: CoreSiteSchema = { ], }, ], - // eslint-disable-next-line @typescript-eslint/no-unused-vars - async migrate(db: SQLiteDB, oldVersion: number, siteId: string): Promise { + async migrate(db: SQLiteDB, oldVersion: number): Promise { if (oldVersion >= 2) { return; } - const newTable = LIBRARIES_TABLE_NAME; - const oldTable = 'h5p_libraries'; - - try { - await db.tableExists(oldTable); - - // Move the records from the old table. - const entries = await db.getAllRecords(oldTable); - - await Promise.all(entries.map((entry) => db.insertRecord(newTable, entry))); - - await db.dropTable(oldTable); - } catch { - // Old table does not exist, ignore. - } + // Move the records from the old table. + await db.migrateTable('h5p_libraries', LIBRARIES_TABLE_NAME); }, }; diff --git a/src/core/services/database/sites.ts b/src/core/services/database/sites.ts index 653db3620..4f4968ec6 100644 --- a/src/core/services/database/sites.ts +++ b/src/core/services/database/sites.ts @@ -87,28 +87,7 @@ export const APP_SCHEMA: CoreAppSchema = { ], async migrate(db: SQLiteDB, oldVersion: number): Promise { if (oldVersion < 2) { - const newTable = SITES_TABLE_NAME; - const oldTable = 'sites'; - - try { - // Check if V1 table exists. - await db.tableExists(oldTable); - - // Move the records from the old table. - const sites = await db.getAllRecords(oldTable); - const promises: Promise[] = []; - - sites.forEach((site) => { - promises.push(db.insertRecord(newTable, site)); - }); - - await Promise.all(promises); - - // Data moved, drop the old table. - await db.dropTable(oldTable); - } catch (error) { - // Old table does not exist, ignore. - } + await db.migrateTable('sites', SITES_TABLE_NAME); } }, }; @@ -166,27 +145,14 @@ export const SITE_SCHEMA: CoreSiteSchema = { ], async migrate(db: SQLiteDB, oldVersion: number): Promise { if (oldVersion && oldVersion < 2) { - const newTable = CoreSite.WS_CACHE_TABLE; - const oldTable = 'wscache'; - - try { - await db.tableExists(oldTable); - } catch (error) { - // Old table does not exist, ignore. - return; - } - // Cannot use insertRecordsFrom because there are extra fields, so manually code INSERT INTO. - await db.execute( - 'INSERT INTO ' + newTable + ' ' + - 'SELECT id, data, key, expirationTime, NULL as component, NULL as componentId ' + - 'FROM ' + oldTable, - ); - - try { - await db.dropTable(oldTable); - } catch (error) { - // Error deleting old table, ignore. - } + await db.migrateTable('wscache', CoreSite.WS_CACHE_TABLE, (record) => ({ + id: record.id, + data: record.data, + key: record.key, + expirationTime: record.expirationTime, + component: null, + componentId: null, + })); } }, }; From 19cd851d77729b6331634879aed56ee696aec231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 31 Mar 2021 09:17:14 +0200 Subject: [PATCH 03/10] MOBILE-3640 styles: CSS Fixes on var names and maps --- .../core-download-refresh.html | 2 +- .../features/grades/pages/course/course.scss | 2 +- src/theme/globals.mixins.ionic.scss | 25 +++++++++++++++++++ src/theme/globals.variables.scss | 17 ++++++++----- src/theme/theme.dark.scss | 4 +-- src/theme/theme.light.scss | 21 ++++++++-------- 6 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/core/components/download-refresh/core-download-refresh.html b/src/core/components/download-refresh/core-download-refresh.html index c70f87a0e..4c9c00db2 100644 --- a/src/core/components/download-refresh/core-download-refresh.html +++ b/src/core/components/download-refresh/core-download-refresh.html @@ -8,7 +8,7 @@ + [attr.aria-label]="(statusTranslatable || 'core.refresh') | translate"> diff --git a/src/core/features/grades/pages/course/course.scss b/src/core/features/grades/pages/course/course.scss index 107b3972b..b1d430403 100644 --- a/src/core/features/grades/pages/course/course.scss +++ b/src/core/features/grades/pages/course/course.scss @@ -124,7 +124,7 @@ core-split-view.menu-and-content .core-grades-table .ion-hide-md-down { opacity: 0; } -@media (min-width: $breakpoint-md) { +@include media-breakpoint-down(md) { .core-grades-table td { font-size: 0.85em; diff --git a/src/theme/globals.mixins.ionic.scss b/src/theme/globals.mixins.ionic.scss index 56a82a054..c2d1d23fb 100644 --- a/src/theme/globals.mixins.ionic.scss +++ b/src/theme/globals.mixins.ionic.scss @@ -6,6 +6,31 @@ * https://github.com/ionic-team/ionic-framework/blob/master/core/src/themes/ionic.mixins.scss */ +// Responsive Mixins +// -------------------------------------------------- +// Creates a fixed width for the grid based on the screen size +// --------------------------------------------------------------------------------- +@mixin make-grid-widths($widths: $grid-widths, $breakpoints: $screen-breakpoints) { + @each $breakpoint, $width in $widths { + @include media-breakpoint-up($breakpoint, $breakpoints) { + width: $width; + } + } + + max-width: 100%; +} + +// Adds padding to the element based on breakpoints +// --------------------------------------------------------------------------------- +@mixin make-breakpoint-padding($paddings) { + @each $breakpoint in map-keys($paddings) { + @include media-breakpoint-up($breakpoint) { + $padding: map-get($paddings, $breakpoint); + + @include padding($padding); + } + } +} // Gets the active color's css variable from a variation. Alpha is optional. // -------------------------------------------------------------------------------------------- diff --git a/src/theme/globals.variables.scss b/src/theme/globals.variables.scss index 1b31a84fd..c0c8e0eb4 100644 --- a/src/theme/globals.variables.scss +++ b/src/theme/globals.variables.scss @@ -149,10 +149,15 @@ $core-dd-question-colors: $white, $blue-light, #DCDCDC, #D8BFD8, #87CEFA, #DAA52 * https://ionicframework.com/docs/layout/grid#default-breakpoints */ -$breakpoint-xs: 0px !default; -$breakpoint-sm: 576px !default; -$breakpoint-md: 768px !default; -$breakpoint-lg: 992px !default; -$breakpoint-xl: 1200px !default; +// The minimum dimensions at which your layout will change, +// adapting to different screen sizes, for use in media queries +$screen-breakpoints: ( + xs: 0, + sm: 576px, + md: 768px, + lg: 992px, + tablet: 992px, + xl: 1200px +) !default; -$breakpoint-tablet: $breakpoint-lg !default; +$breakpoint-tablet: map-get($screen-breakpoints, tablet), !default; diff --git a/src/theme/theme.dark.scss b/src/theme/theme.dark.scss index 141723271..c8ab76fec 100644 --- a/src/theme/theme.dark.scss +++ b/src/theme/theme.dark.scss @@ -34,8 +34,8 @@ --ion-color-step-900: #e7e7e7; --ion-color-step-950: #f3f3f3; - --light: var(--black); - --dark: var(--gray-lighter); + --light: #{$dark}; + --dark: #{$light}; @each $color-name, $value in $colors-dark { @include generate-color($color-name); diff --git a/src/theme/theme.light.scss b/src/theme/theme.light.scss index 9170acbe9..1e7ca7425 100644 --- a/src/theme/theme.light.scss +++ b/src/theme/theme.light.scss @@ -47,16 +47,16 @@ --core-online-color: #{$core-online-color}; // Named Color Variables - --primary: var(--primary); - --secondary: var(--secondary); - --tertiary: var(--tertiary); - --success: var(--success); - --danger: var(--danger); - --warning: var(--warning); - --info: var(--info); - --light: var(--gray-lighter); - --dark: var(--black); - --medium: var(--gray-light); + --primary: #{$primary}; + --secondary: #{$secondary}; + --tertiary: #{$tertiary}; + --success: #{$success}; + --danger: #{$danger}; + --warning: #{$warning}; + --info: #{$info}; + --light: #{$light}; + --dark: #{$dark}; + --medium: #{$medium}; @each $color-name, $value in $colors { @include generate-color($color-name); @@ -65,6 +65,7 @@ --ion-text-color: #{$text-color}; --ion-text-color-rgb: 58,58,58; --ion-card-color: var(--ion-text-color); + --ion-item-background: var(--white); --text-hightlight-background-color: var(--custom-text-hightlight-background-color, #99c1ed); From 880a5cf4b8076a6e60036717556df0e13151ba6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 31 Mar 2021 09:19:27 +0200 Subject: [PATCH 04/10] MOBILE-3640 components: Add style component --- src/core/components/components.module.ts | 3 + src/core/components/style/style.ts | 77 ++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/core/components/style/style.ts diff --git a/src/core/components/components.module.ts b/src/core/components/components.module.ts index e6f72957f..33596bb6b 100644 --- a/src/core/components/components.module.ts +++ b/src/core/components/components.module.ts @@ -54,6 +54,7 @@ import { CoreLocalFileComponent } from './local-file/local-file'; import { CoreBSTooltipComponent } from './bs-tooltip/bs-tooltip'; import { CoreSitePickerComponent } from './site-picker/site-picker'; import { CoreChartComponent } from './chart/chart'; +import { CoreStyleComponent } from './style/style'; @NgModule({ declarations: [ @@ -69,6 +70,7 @@ import { CoreChartComponent } from './chart/chart'; CoreRecaptchaModalComponent, CoreShowPasswordComponent, CoreSplitViewComponent, + CoreStyleComponent, CoreEmptyBoxComponent, CoreTabsComponent, CoreTabComponent, @@ -112,6 +114,7 @@ import { CoreChartComponent } from './chart/chart'; CoreRecaptchaModalComponent, CoreShowPasswordComponent, CoreSplitViewComponent, + CoreStyleComponent, CoreEmptyBoxComponent, CoreTabsComponent, CoreTabComponent, diff --git a/src/core/components/style/style.ts b/src/core/components/style/style.ts new file mode 100644 index 000000000..da497ffdd --- /dev/null +++ b/src/core/components/style/style.ts @@ -0,0 +1,77 @@ +// (C) Copyright 2015 Moodle Pty Ltd. +// +// 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 { Component, ElementRef, Input, OnChanges } from '@angular/core'; + +/** + * Component to add a