MOBILE-3320 core: Extract core and addons modules
parent
7d1dcd3c23
commit
06ac2f7edf
|
@ -0,0 +1,24 @@
|
|||
// (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 { AddonPrivateFilesInitModule } from './privatefiles/privatefiles-init.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
AddonPrivateFilesInitModule,
|
||||
],
|
||||
})
|
||||
export class AddonsModule {}
|
|
@ -12,65 +12,22 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { NgModule, Injector } from '@angular/core';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { RouteReuseStrategy } from '@angular/router';
|
||||
import { HttpClient, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||
|
||||
import { IonicModule, IonicRouteStrategy, Platform } from '@ionic/angular';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
import { CoreInterceptor } from '@classes/interceptor';
|
||||
|
||||
// Import core services.
|
||||
import { CoreAppProvider } from '@services/app';
|
||||
import { CoreConfigProvider } from '@services/config';
|
||||
import { CoreCronDelegate } from '@services/cron';
|
||||
import { CoreDbProvider } from '@services/db';
|
||||
import { CoreFileHelperProvider } from '@services/file-helper';
|
||||
import { CoreFileSessionProvider } from '@services/file-session';
|
||||
import { CoreFileProvider, CoreFile } from '@services/file';
|
||||
import { CoreFilepoolProvider } from '@services/filepool';
|
||||
import { CoreGeolocationProvider } from '@services/geolocation';
|
||||
import { CoreGroupsProvider } from '@services/groups';
|
||||
import { CoreInitDelegate, CoreInit } from '@services/init';
|
||||
import { CoreLangProvider } from '@services/lang';
|
||||
import { CoreLocalNotificationsProvider } from '@services/local-notifications';
|
||||
import { CorePluginFileDelegate } from '@services/plugin-file.delegate';
|
||||
import { CoreSitesProvider, CoreSites } from '@services/sites';
|
||||
import { CoreSyncProvider } from '@services/sync';
|
||||
import { CoreUpdateManagerProvider, CoreUpdateManager } from '@services/update-manager';
|
||||
import { CoreWSProvider } from '@services/ws';
|
||||
import { CoreDomUtilsProvider } from '@services/utils/dom';
|
||||
import { CoreIframeUtilsProvider } from '@services/utils/iframe';
|
||||
import { CoreMimetypeUtilsProvider } from '@services/utils/mimetype';
|
||||
import { CoreTextUtilsProvider } from '@services/utils/text';
|
||||
import { CoreTimeUtilsProvider } from '@services/utils/time';
|
||||
import { CoreUrlUtilsProvider } from '@services/utils/url';
|
||||
import { CoreUtilsProvider } from '@services/utils/utils';
|
||||
|
||||
// Import init DB functions of core services.
|
||||
import { initCoreFilepoolDB } from '@services/filepool.db';
|
||||
import { initCoreSitesDB } from '@services/sites.db';
|
||||
import { initCoreSyncDB } from '@services/sync.db';
|
||||
import { initCoreSearchHistoryDB } from '@features/search/services/search.history.db';
|
||||
|
||||
// Import core modules.
|
||||
import { CoreEmulatorModule } from '@features/emulator/emulator.module';
|
||||
import { CoreLoginModule } from '@features/login/login.module';
|
||||
import { CoreCoursesModule } from '@features/courses/courses.module';
|
||||
import { CoreSettingsInitModule } from '@features/settings/settings-init.module';
|
||||
import { CoreFileUploaderInitModule } from '@features/fileuploader/fileuploader-init.module';
|
||||
|
||||
// Import addons init modules.
|
||||
import { AddonPrivateFilesInitModule } from '@/addons/privatefiles/privatefiles-init.module';
|
||||
|
||||
import { setSingletonsInjector } from '@singletons/core.singletons';
|
||||
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
||||
|
||||
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
|
||||
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
||||
|
||||
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
|
||||
|
||||
import { CoreModule } from '@/core/core.module';
|
||||
import { AddonsModule } from '@/addons/addons.module';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
import { AppRoutingModule } from './app-routing.module';
|
||||
|
||||
// For translate loader. AoT requires an exported function for factories.
|
||||
export function createTranslateLoader(http: HttpClient): TranslateHttpLoader {
|
||||
return new TranslateHttpLoader(http, './assets/lang/', '.json');
|
||||
|
@ -91,93 +48,12 @@ export function createTranslateLoader(http: HttpClient): TranslateHttpLoader {
|
|||
},
|
||||
}),
|
||||
AppRoutingModule,
|
||||
CoreEmulatorModule,
|
||||
CoreLoginModule,
|
||||
CoreCoursesModule,
|
||||
CoreSettingsInitModule,
|
||||
CoreFileUploaderInitModule,
|
||||
AddonPrivateFilesInitModule,
|
||||
CoreModule,
|
||||
AddonsModule,
|
||||
],
|
||||
providers: [
|
||||
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: CoreInterceptor, multi: true },
|
||||
CoreAppProvider,
|
||||
CoreConfigProvider,
|
||||
CoreCronDelegate,
|
||||
CoreDbProvider,
|
||||
CoreFileHelperProvider,
|
||||
CoreFileSessionProvider,
|
||||
CoreFileProvider,
|
||||
CoreFilepoolProvider,
|
||||
CoreGeolocationProvider,
|
||||
CoreGroupsProvider,
|
||||
CoreInitDelegate,
|
||||
CoreLangProvider,
|
||||
CoreLocalNotificationsProvider,
|
||||
CorePluginFileDelegate,
|
||||
CoreSitesProvider,
|
||||
CoreSyncProvider,
|
||||
CoreUpdateManagerProvider,
|
||||
CoreWSProvider,
|
||||
CoreDomUtilsProvider,
|
||||
CoreIframeUtilsProvider,
|
||||
CoreMimetypeUtilsProvider,
|
||||
CoreTextUtilsProvider,
|
||||
CoreTimeUtilsProvider,
|
||||
CoreUrlUtilsProvider,
|
||||
CoreUtilsProvider,
|
||||
],
|
||||
bootstrap: [AppComponent],
|
||||
})
|
||||
export class AppModule {
|
||||
|
||||
constructor(injector: Injector, platform: Platform) {
|
||||
// Set the injector.
|
||||
setSingletonsInjector(injector);
|
||||
|
||||
this.initCoreServicesDB();
|
||||
|
||||
// Register a handler for platform ready.
|
||||
CoreInit.instance.registerProcess({
|
||||
name: 'CorePlatformReady',
|
||||
priority: CoreInitDelegate.MAX_RECOMMENDED_PRIORITY + 400,
|
||||
blocking: true,
|
||||
load: async () => {
|
||||
await platform.ready();
|
||||
},
|
||||
});
|
||||
|
||||
// Register the update manager as an init process.
|
||||
CoreInit.instance.registerProcess(CoreUpdateManager.instance);
|
||||
|
||||
// Restore the user's session during the init process.
|
||||
CoreInit.instance.registerProcess({
|
||||
name: 'CoreRestoreSession',
|
||||
priority: CoreInitDelegate.MAX_RECOMMENDED_PRIORITY + 200,
|
||||
blocking: false,
|
||||
load: CoreSites.instance.restoreSession.bind(CoreSites.instance),
|
||||
});
|
||||
|
||||
// Register clear app tmp folder.
|
||||
CoreInit.instance.registerProcess({
|
||||
name: 'CoreClearTmpFolder',
|
||||
priority: CoreInitDelegate.MAX_RECOMMENDED_PRIORITY + 150,
|
||||
blocking: false,
|
||||
load: CoreFile.instance.clearTmpFolder.bind(CoreFile.instance),
|
||||
});
|
||||
|
||||
// Execute the init processes.
|
||||
CoreInit.instance.executeInitProcesses();
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the DB of core services.
|
||||
*/
|
||||
protected initCoreServicesDB(): void {
|
||||
initCoreFilepoolDB();
|
||||
initCoreSitesDB();
|
||||
initCoreSyncDB();
|
||||
initCoreSearchHistoryDB();
|
||||
}
|
||||
|
||||
}
|
||||
export class AppModule {}
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
// (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 { HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||
import { Injector, NgModule } from '@angular/core';
|
||||
|
||||
import { Platform } from '@ionic/angular';
|
||||
|
||||
import { CoreFeaturesModule } from './features/features.module';
|
||||
import { CoreFile } from './services/file';
|
||||
import { CoreInit, CoreInitDelegate } from './services/init';
|
||||
import { CoreInterceptor } from './classes/interceptor';
|
||||
import { CoreSites, CORE_SITE_SCHEMAS } from './services/sites';
|
||||
import { CoreUpdateManager } from './services/update-manager';
|
||||
import { setSingletonsInjector } from './singletons/core.singletons';
|
||||
import { SITE_SCHEMA as FILEPOOL_SITE_SCHEMA } from './services/filepool-db';
|
||||
import { SITE_SCHEMA as SITES_SITE_SCHEMA } from './services/sites-db';
|
||||
import { SITE_SCHEMA as SYNC_SITE_SCHEMA } from './services/sync-db';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CoreFeaturesModule,
|
||||
],
|
||||
providers: [
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: CoreInterceptor, multi: true },
|
||||
{
|
||||
provide: CORE_SITE_SCHEMAS,
|
||||
useValue: [
|
||||
FILEPOOL_SITE_SCHEMA,
|
||||
SITES_SITE_SCHEMA,
|
||||
SYNC_SITE_SCHEMA,
|
||||
],
|
||||
multi: true,
|
||||
},
|
||||
],
|
||||
})
|
||||
export class CoreModule {
|
||||
|
||||
constructor(platform: Platform, injector: Injector) {
|
||||
// Set the injector.
|
||||
setSingletonsInjector(injector);
|
||||
|
||||
// Register a handler for platform ready.
|
||||
CoreInit.instance.registerProcess({
|
||||
name: 'CorePlatformReady',
|
||||
priority: CoreInitDelegate.MAX_RECOMMENDED_PRIORITY + 400,
|
||||
blocking: true,
|
||||
load: async () => {
|
||||
await platform.ready();
|
||||
},
|
||||
});
|
||||
|
||||
// Register the update manager as an init process.
|
||||
CoreInit.instance.registerProcess(CoreUpdateManager.instance);
|
||||
|
||||
// Restore the user's session during the init process.
|
||||
CoreInit.instance.registerProcess({
|
||||
name: 'CoreRestoreSession',
|
||||
priority: CoreInitDelegate.MAX_RECOMMENDED_PRIORITY + 200,
|
||||
blocking: false,
|
||||
load: CoreSites.instance.restoreSession.bind(CoreSites.instance),
|
||||
});
|
||||
|
||||
// Register clear app tmp folder.
|
||||
CoreInit.instance.registerProcess({
|
||||
name: 'CoreClearTmpFolder',
|
||||
priority: CoreInitDelegate.MAX_RECOMMENDED_PRIORITY + 150,
|
||||
blocking: false,
|
||||
load: CoreFile.instance.clearTmpFolder.bind(CoreFile.instance),
|
||||
});
|
||||
|
||||
// Execute the init processes.
|
||||
CoreInit.instance.executeInitProcesses();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
// (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 { CoreCoursesModule } from './courses/courses.module';
|
||||
import { CoreEmulatorModule } from './emulator/emulator.module';
|
||||
import { CoreFileUploaderInitModule } from './fileuploader/fileuploader-init.module';
|
||||
import { CoreLoginModule } from './login/login.module';
|
||||
import { CoreSettingsInitModule } from './settings/settings-init.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CoreEmulatorModule,
|
||||
CoreLoginModule,
|
||||
CoreCoursesModule,
|
||||
CoreSettingsInitModule,
|
||||
CoreFileUploaderInitModule,
|
||||
],
|
||||
})
|
||||
export class CoreFeaturesModule {}
|
|
@ -19,7 +19,7 @@ import { CoreDomUtils } from '@services/utils/dom';
|
|||
import { CoreUtils } from '@services/utils/utils';
|
||||
import { CoreSearchHistory } from '../../services/search-history';
|
||||
import { Translate } from '@singletons/core.singletons';
|
||||
import { CoreSearchHistoryDBRecord } from '../../services/search.history.db';
|
||||
import { CoreSearchHistoryDBRecord } from '../../services/search-history-db';
|
||||
|
||||
/**
|
||||
* Component to display a "search box".
|
||||
|
|
|
@ -13,7 +13,11 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
import { CORE_SITE_SCHEMAS } from '@services/sites';
|
||||
|
||||
import { CoreSearchComponentsModule } from './components/components.module';
|
||||
import { SITE_SCHEMA } from './services/search-history-db';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
@ -23,6 +27,7 @@ import { CoreSearchComponentsModule } from './components/components.module';
|
|||
],
|
||||
providers: [
|
||||
CoreSearchComponentsModule,
|
||||
{ provide: CORE_SITE_SCHEMAS, useValue: [SITE_SCHEMA], multi: true },
|
||||
],
|
||||
})
|
||||
export class CoreSearchModule {}
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { CoreSiteSchema, registerSiteSchema } from '@services/sites';
|
||||
import { CoreSiteSchema } from '@services/sites';
|
||||
|
||||
/**
|
||||
* Database variables for CoreSearchHistory service.
|
||||
*/
|
||||
export const SEARCH_HISTORY_TABLE_NAME = 'seach_history';
|
||||
const SITE_SCHEMA: CoreSiteSchema = {
|
||||
export const SITE_SCHEMA: CoreSiteSchema = {
|
||||
name: 'CoreSearchHistoryProvider',
|
||||
version: 1,
|
||||
tables: [
|
||||
|
@ -60,7 +60,3 @@ export type CoreSearchHistoryDBRecord = {
|
|||
searchedtext: string; // Text of the performed search.
|
||||
times: number; // Times search has been performed (if previously in history).
|
||||
};
|
||||
|
||||
export const initCoreSearchHistoryDB = (): void => {
|
||||
registerSiteSchema(SITE_SCHEMA);
|
||||
};
|
|
@ -16,7 +16,7 @@ import { Injectable } from '@angular/core';
|
|||
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { SQLiteDB } from '@classes/sqlitedb';
|
||||
import { CoreSearchHistoryDBRecord, SEARCH_HISTORY_TABLE_NAME } from './search.history.db';
|
||||
import { CoreSearchHistoryDBRecord, SEARCH_HISTORY_TABLE_NAME } from './search-history-db';
|
||||
import { makeSingleton } from '@singletons/core.singletons';
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,7 @@ import { DBNAME, SCHEMA_VERSIONS_TABLE_NAME, SCHEMA_VERSIONS_TABLE_SCHEMA, Schem
|
|||
* }
|
||||
* ```
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreAppProvider {
|
||||
|
||||
protected db: SQLiteDB;
|
||||
|
|
|
@ -23,7 +23,7 @@ import { CONFIG_TABLE_NAME, APP_SCHEMA, ConfigDBEntry } from '@services/config.d
|
|||
* Factory to provide access to dynamic and permanent config and settings.
|
||||
* It should not be abused into a temporary storage.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreConfigProvider {
|
||||
|
||||
protected appDB: SQLiteDB;
|
||||
|
|
|
@ -28,7 +28,7 @@ import { APP_SCHEMA, CRON_TABLE_NAME, CronDBEntry } from '@services/cron.db';
|
|||
/*
|
||||
* Service to handle cron processes. The registered processes will be executed every certain time.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreCronDelegate {
|
||||
|
||||
// Constants.
|
||||
|
|
|
@ -21,7 +21,7 @@ import { makeSingleton, SQLite, Platform } from '@singletons/core.singletons';
|
|||
/**
|
||||
* This service allows interacting with the local database to store and retrieve data.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreDbProvider {
|
||||
|
||||
protected dbInstances: {[name: string]: SQLiteDB} = {};
|
||||
|
|
|
@ -30,7 +30,7 @@ import { makeSingleton, Translate } from '@singletons/core.singletons';
|
|||
/**
|
||||
* Provider to provide some helper functions regarding files and packages.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreFileHelperProvider {
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,7 @@ import { makeSingleton } from '@singletons/core.singletons';
|
|||
* Every component can provide a File area identifier to indentify every file list on the session.
|
||||
* This value can be the activity id or a mix of name and numbers.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreFileSessionProvider {
|
||||
|
||||
protected files: {[siteId: string]: {[component: string]: {[id: string]: (CoreWSExternalFile | FileEntry)[]}}} = {};
|
||||
|
|
|
@ -66,7 +66,7 @@ export const enum CoreFileFormat {
|
|||
/**
|
||||
* Factory to interact with the file system.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreFileProvider {
|
||||
|
||||
// Formats to read a file.
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { CoreAppSchema } from '@services/app';
|
||||
import { CoreSiteSchema, registerSiteSchema } from '@services/sites';
|
||||
import { CoreSiteSchema } from '@services/sites';
|
||||
|
||||
/**
|
||||
* Database variables for CoreFilepool service.
|
||||
|
@ -361,7 +361,3 @@ export type CoreFilepoolLinksRecord = {
|
|||
component: string; // Component name.
|
||||
componentId: number | string; // Component Id.
|
||||
};
|
||||
|
||||
export const initCoreFilepoolDB = (): void => {
|
||||
registerSiteSchema(SITE_SCHEMA);
|
||||
};
|
|
@ -46,7 +46,7 @@ import {
|
|||
CoreFilepoolPackageEntry,
|
||||
CoreFilepoolQueueEntry,
|
||||
CoreFilepoolQueueDBEntry,
|
||||
} from '@services/filepool.db';
|
||||
} from '@services/filepool-db';
|
||||
|
||||
/*
|
||||
* Factory for handling downloading files and retrieve downloaded files.
|
||||
|
@ -57,7 +57,7 @@ import {
|
|||
* The two main goals of this is to keep the content available offline, and improve the user experience by caching
|
||||
* the content locally.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreFilepoolProvider {
|
||||
|
||||
// Constants.
|
||||
|
|
|
@ -19,7 +19,7 @@ import { CoreApp } from '@services/app';
|
|||
import { CoreError } from '@classes/errors/error';
|
||||
import { Geolocation, Diagnostic, makeSingleton } from '@singletons/core.singletons';
|
||||
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreGeolocationProvider {
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,7 +24,7 @@ import { CoreCourseBase } from '@/types/global';
|
|||
/*
|
||||
* Service to handle groups.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreGroupsProvider {
|
||||
|
||||
// Group mode constants.
|
||||
|
|
|
@ -48,7 +48,7 @@ export type CoreInitHandler = {
|
|||
/*
|
||||
* Provider for initialisation mechanisms.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreInitDelegate {
|
||||
|
||||
static readonly DEFAULT_PRIORITY = 100; // Default priority for init processes.
|
||||
|
|
|
@ -25,7 +25,7 @@ import * as moment from 'moment';
|
|||
/*
|
||||
* Service to handle language features, like changing the current language.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreLangProvider {
|
||||
|
||||
protected fallbackLanguage = 'en'; // Always use English as fallback language since it contains all strings.
|
||||
|
|
|
@ -39,7 +39,7 @@ import {
|
|||
/**
|
||||
* Service to handle local notifications.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreLocalNotificationsProvider {
|
||||
|
||||
protected logger: CoreLogger;
|
||||
|
|
|
@ -24,7 +24,7 @@ import { makeSingleton } from '@singletons/core.singletons';
|
|||
/**
|
||||
* Delegate to register pluginfile information handlers.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CorePluginFileDelegate extends CoreDelegate<CorePluginFileHandler> {
|
||||
|
||||
protected handlerNameProperty = 'component';
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
import { CoreAppSchema } from '@services/app';
|
||||
import { CoreSiteSchema, registerSiteSchema } from '@services/sites';
|
||||
import { CoreSiteSchema } from '@services/sites';
|
||||
import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb';
|
||||
import { CoreSite } from '@classes/site';
|
||||
|
||||
|
@ -227,7 +227,3 @@ export type SchemaVersionsDBEntry = {
|
|||
name: string;
|
||||
version: number;
|
||||
};
|
||||
|
||||
export const initCoreSitesDB = (): void => {
|
||||
registerSiteSchema(SITE_SCHEMA);
|
||||
};
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
|
||||
import { Md5 } from 'ts-md5/dist/md5';
|
||||
import { timeout } from 'rxjs/operators';
|
||||
|
||||
|
@ -47,25 +47,17 @@ import {
|
|||
SiteDBEntry,
|
||||
CurrentSiteDBEntry,
|
||||
SchemaVersionsDBEntry,
|
||||
} from '@services/sites.db';
|
||||
} from '@services/sites-db';
|
||||
import { CoreArray } from '../singletons/array';
|
||||
|
||||
|
||||
// Schemas for site tables. Other providers can add schemas in here using the registerSiteSchema function.
|
||||
const siteSchemas: { [name: string]: CoreRegisteredSiteSchema } = {};
|
||||
export const registerSiteSchema = (schema: CoreSiteSchema): void => {
|
||||
siteSchemas[schema.name] = schema;
|
||||
};
|
||||
export const CORE_SITE_SCHEMAS = new InjectionToken('CORE_SITE_SCHEMAS');
|
||||
|
||||
/*
|
||||
* Service to manage and interact with sites.
|
||||
* It allows creating tables in the databases of all sites. Each service or component should be responsible of creating
|
||||
* their own database tables. Example:
|
||||
*
|
||||
* import { registerSiteSchema } from '@services/sites';
|
||||
*
|
||||
* registerSiteSchema(tableSchema);
|
||||
* their own database tables calling the registerCoreSiteSchema method.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreSitesProvider {
|
||||
|
||||
// Constants to validate a site version.
|
||||
|
@ -84,11 +76,19 @@ export class CoreSitesProvider {
|
|||
protected appDB: SQLiteDB;
|
||||
protected dbReady: Promise<void>; // Promise resolved when the app DB is initialized.
|
||||
protected siteSchemasMigration: { [siteId: string]: Promise<void> } = {};
|
||||
protected siteSchemas: { [name: string]: CoreRegisteredSiteSchema } = {};
|
||||
protected pluginsSiteSchemas: { [name: string]: CoreRegisteredSiteSchema } = {};
|
||||
|
||||
constructor() {
|
||||
constructor(@Optional() @Inject(CORE_SITE_SCHEMAS) siteSchemas: CoreSiteSchema[][] = []) {
|
||||
this.logger = CoreLogger.getInstance('CoreSitesProvider');
|
||||
this.siteSchemas = CoreArray.flatten(siteSchemas).reduce(
|
||||
(siteSchemas, schema) => {
|
||||
siteSchemas[schema.name] = schema;
|
||||
|
||||
return siteSchemas;
|
||||
},
|
||||
this.siteSchemas,
|
||||
);
|
||||
this.appDB = CoreApp.instance.getDB();
|
||||
this.dbReady = CoreApp.instance.createTablesFromSchema(APP_SCHEMA).catch(() => {
|
||||
// Ignore errors.
|
||||
|
@ -1446,7 +1446,7 @@ export class CoreSitesProvider {
|
|||
/**
|
||||
* Register a site schema in current site.
|
||||
* This function is meant for site plugins to create DB tables in current site. Tables created from within the app
|
||||
* whould use the registerSiteSchema function exported in this same file.
|
||||
* should use the registerCoreSiteSchema method instead.
|
||||
*
|
||||
* @param schema The schema to register.
|
||||
* @return Promise resolved when done.
|
||||
|
@ -1489,7 +1489,7 @@ export class CoreSitesProvider {
|
|||
|
||||
// First create tables not registerd with name/version.
|
||||
const promise = site.getDb().createTableFromSchema(SCHEMA_VERSIONS_TABLE_SCHEMA)
|
||||
.then(() => this.applySiteSchemas(site, siteSchemas));
|
||||
.then(() => this.applySiteSchemas(site, this.siteSchemas));
|
||||
|
||||
this.siteSchemasMigration[site.id] = promise;
|
||||
|
||||
|
@ -1602,7 +1602,7 @@ export class CoreSitesProvider {
|
|||
*/
|
||||
getSiteTableSchemasToClear(site: CoreSite): string[] {
|
||||
let reset: string[] = [];
|
||||
const schemas = Object.values(siteSchemas).concat(Object.values(this.pluginsSiteSchemas));
|
||||
const schemas = Object.values(this.siteSchemas).concat(Object.values(this.pluginsSiteSchemas));
|
||||
|
||||
schemas.forEach((schema) => {
|
||||
if (schema.canBeCleared && (!schema.siteId || site.getId() == schema.siteId)) {
|
||||
|
|
|
@ -12,13 +12,13 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { CoreSiteSchema, registerSiteSchema } from '@services/sites';
|
||||
import { CoreSiteSchema } from '@services/sites';
|
||||
|
||||
/**
|
||||
* Database variables for CoreSync service.
|
||||
*/
|
||||
export const SYNC_TABLE_NAME = 'sync';
|
||||
const SITE_SCHEMA: CoreSiteSchema = {
|
||||
export const SITE_SCHEMA: CoreSiteSchema = {
|
||||
name: 'CoreSyncProvider',
|
||||
version: 1,
|
||||
tables: [
|
||||
|
@ -55,7 +55,3 @@ export type CoreSyncRecord = {
|
|||
time: number;
|
||||
warnings: string;
|
||||
};
|
||||
|
||||
export const initCoreSyncDB = (): void => {
|
||||
registerSiteSchema(SITE_SCHEMA);
|
||||
};
|
|
@ -16,12 +16,12 @@ import { Injectable } from '@angular/core';
|
|||
import { CoreEvents } from '@singletons/events';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { makeSingleton } from '@singletons/core.singletons';
|
||||
import { SYNC_TABLE_NAME, CoreSyncRecord } from '@services/sync.db';
|
||||
import { SYNC_TABLE_NAME, CoreSyncRecord } from '@services/sync-db';
|
||||
|
||||
/*
|
||||
* Service that provides some features regarding synchronization.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreSyncProvider {
|
||||
|
||||
// Store blocked sync objects.
|
||||
|
|
|
@ -27,7 +27,7 @@ const VERSION_APPLIED = 'version_applied';
|
|||
*
|
||||
* This service handles processes that need to be run when updating the app, like migrate Ionic 1 database data to Ionic 3.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreUpdateManagerProvider implements CoreInitHandler {
|
||||
|
||||
// Data for init delegate.
|
||||
|
|
|
@ -38,7 +38,7 @@ import { CoreLogger } from '@singletons/logger';
|
|||
/*
|
||||
* "Utils" service with helper functions for UI, DOM elements and HTML code.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreDomUtilsProvider {
|
||||
|
||||
protected readonly INSTANCE_ID_ATTR_NAME = 'core-instance-id';
|
||||
|
|
|
@ -42,7 +42,7 @@ type CoreFrameElement = (HTMLIFrameElement | HTMLFrameElement | HTMLObjectElemen
|
|||
/*
|
||||
* "Utils" service with helper functions for iframes, embed and similar.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreIframeUtilsProvider {
|
||||
|
||||
static readonly FRAME_TAGS = ['iframe', 'frame', 'object', 'embed'];
|
||||
|
|
|
@ -44,7 +44,7 @@ const EXTENSION_REGEX = /^[a-z0-9]+$/;
|
|||
/*
|
||||
* "Utils" service with helper functions for mimetypes and extensions.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreMimetypeUtilsProvider {
|
||||
|
||||
protected logger: CoreLogger;
|
||||
|
|
|
@ -37,7 +37,7 @@ export type CoreTextErrorObject = {
|
|||
/*
|
||||
* "Utils" service with helper functions for text.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreTextUtilsProvider {
|
||||
|
||||
// List of regular expressions to convert the old nomenclature to new nomenclature for disabled features.
|
||||
|
|
|
@ -21,7 +21,7 @@ import { makeSingleton, Translate } from '@singletons/core.singletons';
|
|||
/*
|
||||
* "Utils" service with helper functions for date and time.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreTimeUtilsProvider {
|
||||
|
||||
protected static readonly FORMAT_REPLACEMENTS = { // To convert PHP strf format to Moment format.
|
||||
|
|
|
@ -23,7 +23,7 @@ import { CoreUrl } from '@singletons/url';
|
|||
/*
|
||||
* "Utils" service with helper functions for URLs.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreUrlUtilsProvider {
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,7 +36,7 @@ type TreeNode<T> = T & { children: TreeNode<T>[] };
|
|||
/*
|
||||
* "Utils" service with helper functions.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreUtilsProvider {
|
||||
|
||||
protected readonly DONT_CLONE = ['[object FileEntry]', '[object DirectoryEntry]', '[object DOMFileSystem]'];
|
||||
|
|
|
@ -40,7 +40,7 @@ import { CoreAjaxWSError } from '@classes/errors/ajaxwserror';
|
|||
/**
|
||||
* This service allows performing WS calls and download/upload files.
|
||||
*/
|
||||
@Injectable()
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CoreWSProvider {
|
||||
|
||||
protected logger: CoreLogger;
|
||||
|
|
Loading…
Reference in New Issue