Merge pull request #2652 from NoelDeMartin/MOBILE-3320

MOBILE-3320: Tweaks
main
Dani Palou 2020-12-15 16:28:36 +01:00 committed by GitHub
commit b2ac70175b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 170 additions and 102 deletions

22
.vscode/moodle.code-snippets vendored 100644
View File

@ -0,0 +1,22 @@
{
"[Moodle] Service Singleton": {
"scope": "typescript",
"prefix": "massingleton",
"body": [
"import { Injectable } from '@angular/core';",
"import { makeSingleton } from '@singletons';",
"",
"@Injectable({ providedIn: 'root' })",
"export class ${1:${TM_FILENAME_BASE}}Service {",
"",
" $0",
"",
"}",
"",
"export class ${1:${TM_FILENAME_BASE}} extends makeSingleton(${1:${TM_FILENAME_BASE}}Service) {}",
""
],
"description": "[Moodle] Create a Service Singleton"
}
}

View File

@ -33,9 +33,7 @@ const mainMenuHomeSiblingRoutes: Routes = [
@NgModule({
imports: [
CoreMainMenuTabRoutingModule.forChild({
siblings: mainMenuHomeSiblingRoutes,
}),
CoreMainMenuTabRoutingModule.forChild(mainMenuHomeSiblingRoutes),
],
providers: [
{

View File

@ -22,13 +22,27 @@ function buildAppRoutes(injector: Injector): Routes {
}
export type ModuleRoutes = { children: Routes; siblings: Routes };
export type ModuleRoutesConfig = Routes | Partial<ModuleRoutes>;
export function resolveModuleRoutes(injector: Injector, token: InjectionToken<Partial<ModuleRoutes>[]>): ModuleRoutes {
const routes = injector.get(token, []);
export function resolveModuleRoutes(injector: Injector, token: InjectionToken<ModuleRoutesConfig[]>): ModuleRoutes {
const configs = injector.get(token, []);
const routes = configs.map(config => {
if (Array.isArray(config)) {
return {
children: [],
siblings: config,
};
}
return {
children: config.children || [],
siblings: config.siblings || [],
};
});
return {
children: CoreArray.flatten(routes.map(r => r.children || [])),
siblings: CoreArray.flatten(routes.map(r => r.siblings || [])),
children: CoreArray.flatten(routes.map(r => r.children)),
siblings: CoreArray.flatten(routes.map(r => r.siblings)),
};
}

View File

@ -1,65 +0,0 @@
// (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 { trigger, style, transition, animate, keyframes } from '@angular/animations';
export const coreShowHideAnimation = trigger('coreShowHideAnimation', [
transition(':enter', [
style({ opacity: 0 }),
animate('500ms ease-in-out', style({ opacity: 1 })),
]),
transition(':leave', [
style({ opacity: 1 }),
animate('500ms ease-in-out', style({ opacity: 0 })),
]),
]);
export const coreSlideInOut = trigger('coreSlideInOut', [
// Enter animation.
transition('void => fromLeft', [
style({ transform: 'translateX(0)', opacity: 1 }),
animate(300, keyframes([
style({ opacity: 0, transform: 'translateX(-100%)', offset: 0 }),
style({ opacity: 1, transform: 'translateX(5%)', offset: 0.7 }),
style({ opacity: 1, transform: 'translateX(0)', offset: 1.0 }),
])),
]),
// Leave animation.
transition('fromLeft => void', [
style({ transform: 'translateX(-100%)', opacity: 0 }),
animate(300, keyframes([
style({ opacity: 1, transform: 'translateX(0)', offset: 0 }),
style({ opacity: 1, transform: 'translateX(5%)', offset: 0.3 }),
style({ opacity: 0, transform: 'translateX(-100%)', offset: 1.0 }),
])),
]),
// Enter animation.
transition('void => fromRight', [
style({ transform: 'translateX(0)', opacity: 1 }),
animate(300, keyframes([
style({ opacity: 0, transform: 'translateX(100%)', offset: 0 }),
style({ opacity: 1, transform: 'translateX(-5%)', offset: 0.7 }),
style({ opacity: 1, transform: 'translateX(0)', offset: 1.0 }),
])),
]),
// Leave animation.
transition('fromRight => void', [
style({ transform: 'translateX(-100%)', opacity: 0 }),
animate(300, keyframes([
style({ opacity: 1, transform: 'translateX(0)', offset: 0 }),
style({ opacity: 1, transform: 'translateX(-5%)', offset: 0.3 }),
style({ opacity: 0, transform: 'translateX(100%)', offset: 1.0 }),
])),
]),
]);

View File

@ -0,0 +1,72 @@
// (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 { trigger, style, transition, animate, keyframes } from '@angular/animations';
/**
* Defines core animations.
*/
export class CoreAnimations {
static readonly SHOW_HIDE = trigger('coreShowHideAnimation', [
transition(':enter', [
style({ opacity: 0 }),
animate('500ms ease-in-out', style({ opacity: 1 })),
]),
transition(':leave', [
style({ opacity: 1 }),
animate('500ms ease-in-out', style({ opacity: 0 })),
]),
]);
static readonly SLIDE_IN_OUT = trigger('coreSlideInOut', [
// Enter animation.
transition('void => fromLeft', [
style({ transform: 'translateX(0)', opacity: 1 }),
animate(300, keyframes([
style({ opacity: 0, transform: 'translateX(-100%)', offset: 0 }),
style({ opacity: 1, transform: 'translateX(5%)', offset: 0.7 }),
style({ opacity: 1, transform: 'translateX(0)', offset: 1.0 }),
])),
]),
// Leave animation.
transition('fromLeft => void', [
style({ transform: 'translateX(-100%)', opacity: 0 }),
animate(300, keyframes([
style({ opacity: 1, transform: 'translateX(0)', offset: 0 }),
style({ opacity: 1, transform: 'translateX(5%)', offset: 0.3 }),
style({ opacity: 0, transform: 'translateX(-100%)', offset: 1.0 }),
])),
]),
// Enter animation.
transition('void => fromRight', [
style({ transform: 'translateX(0)', opacity: 1 }),
animate(300, keyframes([
style({ opacity: 0, transform: 'translateX(100%)', offset: 0 }),
style({ opacity: 1, transform: 'translateX(-5%)', offset: 0.7 }),
style({ opacity: 1, transform: 'translateX(0)', offset: 1.0 }),
])),
]),
// Leave animation.
transition('fromRight => void', [
style({ transform: 'translateX(-100%)', opacity: 0 }),
animate(300, keyframes([
style({ opacity: 1, transform: 'translateX(0)', offset: 0 }),
style({ opacity: 1, transform: 'translateX(-5%)', offset: 0.3 }),
style({ opacity: 0, transform: 'translateX(100%)', offset: 1.0 }),
])),
]),
]);
}

View File

@ -14,7 +14,7 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { CoreConstants } from '@/core/constants';
import { coreShowHideAnimation } from '@classes/animations';
import { CoreAnimations } from '@components/animations';
/**
* Component to show a download button with refresh option, the spinner and the status of it.
@ -26,7 +26,7 @@ import { coreShowHideAnimation } from '@classes/animations';
selector: 'core-download-refresh',
templateUrl: 'core-download-refresh.html',
styleUrls: ['download-refresh.scss'],
animations: [coreShowHideAnimation],
animations: [CoreAnimations.SHOW_HIDE],
})
export class CoreDownloadRefreshComponent {

View File

@ -16,7 +16,7 @@ import { Component, Input, OnInit, OnChanges, SimpleChange, ViewChild, ElementRe
import { CoreEventLoadingChangedData, CoreEvents } from '@singletons/events';
import { CoreUtils } from '@services/utils/utils';
import { coreShowHideAnimation } from '@classes/animations';
import { CoreAnimations } from '@components/animations';
import { Translate } from '@singletons';
/**
@ -43,7 +43,7 @@ import { Translate } from '@singletons';
selector: 'core-loading',
templateUrl: 'core-loading.html',
styleUrls: ['loading.scss'],
animations: [coreShowHideAnimation],
animations: [CoreAnimations.SHOW_HIDE],
})
export class CoreLoadingComponent implements OnInit, OnChanges, AfterViewInit {

View File

@ -14,14 +14,14 @@
import { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core';
import { ModuleRoutes } from '@/app/app-routing.module';
import { ModuleRoutesConfig } from '@/app/app-routing.module';
export const MAIN_MENU_ROUTES = new InjectionToken('MAIN_MENU_ROUTES');
@NgModule()
export class CoreMainMenuRoutingModule {
static forChild(routes: Partial<ModuleRoutes>): ModuleWithProviders<CoreMainMenuRoutingModule> {
static forChild(routes: ModuleRoutesConfig): ModuleWithProviders<CoreMainMenuRoutingModule> {
return {
ngModule: CoreMainMenuRoutingModule,
providers: [

View File

@ -15,7 +15,7 @@
import { InjectionToken, Injector, ModuleWithProviders, NgModule } from '@angular/core';
import { Route, Routes } from '@angular/router';
import { ModuleRoutes, resolveModuleRoutes } from '@/app/app-routing.module';
import { ModuleRoutesConfig, resolveModuleRoutes } from '@/app/app-routing.module';
export const MAIN_MENU_TAB_ROUTES = new InjectionToken('MAIN_MENU_TAB_ROUTES');
@ -35,7 +35,7 @@ export function buildTabMainRoutes(injector: Injector, mainRoute: Route): Routes
@NgModule()
export class CoreMainMenuTabRoutingModule {
static forChild(routes: Partial<ModuleRoutes>): ModuleWithProviders<CoreMainMenuTabRoutingModule> {
static forChild(routes: ModuleRoutesConfig): ModuleWithProviders<CoreMainMenuTabRoutingModule> {
return {
ngModule: CoreMainMenuTabRoutingModule,
providers: [

View File

@ -14,14 +14,14 @@
import { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core';
import { ModuleRoutes } from '@/app/app-routing.module';
import { ModuleRoutesConfig } from '@/app/app-routing.module';
export const MAIN_MENU_HOME_ROUTES = new InjectionToken('MAIN_MENU_HOME_ROUTES');
@NgModule()
export class CoreMainMenuHomeRoutingModule {
static forChild(routes: Partial<ModuleRoutes>): ModuleWithProviders<CoreMainMenuHomeRoutingModule> {
static forChild(routes: ModuleRoutesConfig): ModuleWithProviders<CoreMainMenuHomeRoutingModule> {
return {
ngModule: CoreMainMenuHomeRoutingModule,
providers: [

View File

@ -41,7 +41,7 @@ const mainMenuMoreRoutes: Routes = [
@NgModule({
imports: [
AppRoutingModule.forChild(appRoutes),
CoreMainMenuTabRoutingModule.forChild({ siblings: mainMenuMoreRoutes }),
CoreMainMenuTabRoutingModule.forChild(mainMenuMoreRoutes),
],
providers: [
{

View File

@ -37,7 +37,7 @@ const routes: Routes = [
@NgModule({
imports: [
CoreMainMenuTabRoutingModule.forChild({ siblings: routes }),
CoreMainMenuTabRoutingModule.forChild(routes),
CoreUserComponentsModule,
],
providers: [

View File

@ -21,11 +21,11 @@ import { CoreSites } from '@services/sites';
export default async function(): Promise<void> {
await Promise.all([
CoreApp.instance.initialiseDatabase(),
CoreConfig.instance.initialiseDatabase(),
CoreCronDelegate.instance.initialiseDatabase(),
CoreFilepool.instance.initialiseDatabase(),
CoreLocalNotifications.instance.initialiseDatabase(),
CoreSites.instance.initialiseDatabase(),
CoreApp.instance.initializeDatabase(),
CoreConfig.instance.initializeDatabase(),
CoreCronDelegate.instance.initializeDatabase(),
CoreFilepool.instance.initializeDatabase(),
CoreLocalNotifications.instance.initializeDatabase(),
CoreSites.instance.initializeDatabase(),
]);
}

View File

@ -85,9 +85,9 @@ export class CoreAppProvider {
}
/**
* Initialise database.
* Initialize database.
*/
async initialiseDatabase(): Promise<void> {
async initializeDatabase(): Promise<void> {
await this.db.createTableFromSchema(SCHEMA_VERSIONS_TABLE_SCHEMA);
this.resolveSchemaVersionsManager({

View File

@ -34,9 +34,9 @@ export class CoreConfigProvider {
}
/**
* Initialise database.
* Initialize database.
*/
async initialiseDatabase(): Promise<void> {
async initializeDatabase(): Promise<void> {
try {
await CoreApp.instance.createTablesFromSchema(APP_SCHEMA);
} catch (e) {

View File

@ -58,9 +58,9 @@ export class CoreCronDelegateService {
}
/**
* Initialise database.
* Initialize database.
*/
async initialiseDatabase(): Promise<void> {
async initializeDatabase(): Promise<void> {
try {
await CoreApp.instance.createTablesFromSchema(APP_SCHEMA);
} catch (e) {

View File

@ -101,9 +101,9 @@ export class CoreFilepoolProvider {
}
/**
* Initialise database.
* Initialize database.
*/
async initialiseDatabase(): Promise<void> {
async initializeDatabase(): Promise<void> {
try {
await CoreApp.instance.createTablesFromSchema(APP_SCHEMA);
} catch (e) {

View File

@ -69,9 +69,9 @@ export class CoreLocalNotificationsProvider {
}
/**
* Initialise database.
* Initialize database.
*/
async initialiseDatabase(): Promise<void> {
async initializeDatabase(): Promise<void> {
try {
await CoreApp.instance.createTablesFromSchema(APP_SCHEMA);
} catch (e) {

View File

@ -94,9 +94,9 @@ export class CoreSitesProvider {
}
/**
* Initialise database.
* Initialize database.
*/
async initialiseDatabase(): Promise<void> {
async initializeDatabase(): Promise<void> {
try {
await CoreApp.instance.createTablesFromSchema(APP_SCHEMA);
} catch (e) {

View File

@ -0,0 +1,27 @@
// (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 { NgModule } from '@angular/core';
import { CoreComponentsModule } from '@components/components.module';
import { CoreDirectivesModule } from '@directives/directives.module';
import { CorePipesModule } from '@pipes/pipes.module';
@NgModule({
imports: [
CoreComponentsModule,
CoreDirectivesModule,
CorePipesModule,
],
})
export class CoreSharedModule {}