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
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { NgModule, Injector } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { RouteReuseStrategy } from '@angular/router';
|
import { RouteReuseStrategy } from '@angular/router';
|
||||||
import { HttpClient, HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
import { HttpClient, HttpClientModule } 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 { TranslateModule, TranslateLoader } from '@ngx-translate/core';
|
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
|
||||||
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
|
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.
|
// For translate loader. AoT requires an exported function for factories.
|
||||||
export function createTranslateLoader(http: HttpClient): TranslateHttpLoader {
|
export function createTranslateLoader(http: HttpClient): TranslateHttpLoader {
|
||||||
return new TranslateHttpLoader(http, './assets/lang/', '.json');
|
return new TranslateHttpLoader(http, './assets/lang/', '.json');
|
||||||
|
@ -91,93 +48,12 @@ export function createTranslateLoader(http: HttpClient): TranslateHttpLoader {
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
AppRoutingModule,
|
AppRoutingModule,
|
||||||
CoreEmulatorModule,
|
CoreModule,
|
||||||
CoreLoginModule,
|
AddonsModule,
|
||||||
CoreCoursesModule,
|
|
||||||
CoreSettingsInitModule,
|
|
||||||
CoreFileUploaderInitModule,
|
|
||||||
AddonPrivateFilesInitModule,
|
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
|
{ 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],
|
bootstrap: [AppComponent],
|
||||||
})
|
})
|
||||||
export class AppModule {
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -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 { CoreUtils } from '@services/utils/utils';
|
||||||
import { CoreSearchHistory } from '../../services/search-history';
|
import { CoreSearchHistory } from '../../services/search-history';
|
||||||
import { Translate } from '@singletons/core.singletons';
|
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".
|
* Component to display a "search box".
|
||||||
|
|
|
@ -13,7 +13,11 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
|
|
||||||
|
import { CORE_SITE_SCHEMAS } from '@services/sites';
|
||||||
|
|
||||||
import { CoreSearchComponentsModule } from './components/components.module';
|
import { CoreSearchComponentsModule } from './components/components.module';
|
||||||
|
import { SITE_SCHEMA } from './services/search-history-db';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -23,6 +27,7 @@ import { CoreSearchComponentsModule } from './components/components.module';
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
CoreSearchComponentsModule,
|
CoreSearchComponentsModule,
|
||||||
|
{ provide: CORE_SITE_SCHEMAS, useValue: [SITE_SCHEMA], multi: true },
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class CoreSearchModule {}
|
export class CoreSearchModule {}
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { CoreSiteSchema, registerSiteSchema } from '@services/sites';
|
import { CoreSiteSchema } from '@services/sites';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database variables for CoreSearchHistory service.
|
* Database variables for CoreSearchHistory service.
|
||||||
*/
|
*/
|
||||||
export const SEARCH_HISTORY_TABLE_NAME = 'seach_history';
|
export const SEARCH_HISTORY_TABLE_NAME = 'seach_history';
|
||||||
const SITE_SCHEMA: CoreSiteSchema = {
|
export const SITE_SCHEMA: CoreSiteSchema = {
|
||||||
name: 'CoreSearchHistoryProvider',
|
name: 'CoreSearchHistoryProvider',
|
||||||
version: 1,
|
version: 1,
|
||||||
tables: [
|
tables: [
|
||||||
|
@ -60,7 +60,3 @@ export type CoreSearchHistoryDBRecord = {
|
||||||
searchedtext: string; // Text of the performed search.
|
searchedtext: string; // Text of the performed search.
|
||||||
times: number; // Times search has been performed (if previously in history).
|
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 { CoreSites } from '@services/sites';
|
||||||
import { SQLiteDB } from '@classes/sqlitedb';
|
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';
|
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 {
|
export class CoreAppProvider {
|
||||||
|
|
||||||
protected db: SQLiteDB;
|
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.
|
* Factory to provide access to dynamic and permanent config and settings.
|
||||||
* It should not be abused into a temporary storage.
|
* It should not be abused into a temporary storage.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreConfigProvider {
|
export class CoreConfigProvider {
|
||||||
|
|
||||||
protected appDB: SQLiteDB;
|
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.
|
* Service to handle cron processes. The registered processes will be executed every certain time.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreCronDelegate {
|
export class CoreCronDelegate {
|
||||||
|
|
||||||
// Constants.
|
// 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.
|
* This service allows interacting with the local database to store and retrieve data.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreDbProvider {
|
export class CoreDbProvider {
|
||||||
|
|
||||||
protected dbInstances: {[name: string]: SQLiteDB} = {};
|
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.
|
* Provider to provide some helper functions regarding files and packages.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreFileHelperProvider {
|
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.
|
* 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.
|
* This value can be the activity id or a mix of name and numbers.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreFileSessionProvider {
|
export class CoreFileSessionProvider {
|
||||||
|
|
||||||
protected files: {[siteId: string]: {[component: string]: {[id: string]: (CoreWSExternalFile | FileEntry)[]}}} = {};
|
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.
|
* Factory to interact with the file system.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreFileProvider {
|
export class CoreFileProvider {
|
||||||
|
|
||||||
// Formats to read a file.
|
// Formats to read a file.
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { CoreAppSchema } from '@services/app';
|
import { CoreAppSchema } from '@services/app';
|
||||||
import { CoreSiteSchema, registerSiteSchema } from '@services/sites';
|
import { CoreSiteSchema } from '@services/sites';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database variables for CoreFilepool service.
|
* Database variables for CoreFilepool service.
|
||||||
|
@ -361,7 +361,3 @@ export type CoreFilepoolLinksRecord = {
|
||||||
component: string; // Component name.
|
component: string; // Component name.
|
||||||
componentId: number | string; // Component Id.
|
componentId: number | string; // Component Id.
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initCoreFilepoolDB = (): void => {
|
|
||||||
registerSiteSchema(SITE_SCHEMA);
|
|
||||||
};
|
|
|
@ -46,7 +46,7 @@ import {
|
||||||
CoreFilepoolPackageEntry,
|
CoreFilepoolPackageEntry,
|
||||||
CoreFilepoolQueueEntry,
|
CoreFilepoolQueueEntry,
|
||||||
CoreFilepoolQueueDBEntry,
|
CoreFilepoolQueueDBEntry,
|
||||||
} from '@services/filepool.db';
|
} from '@services/filepool-db';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Factory for handling downloading files and retrieve downloaded files.
|
* 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 two main goals of this is to keep the content available offline, and improve the user experience by caching
|
||||||
* the content locally.
|
* the content locally.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreFilepoolProvider {
|
export class CoreFilepoolProvider {
|
||||||
|
|
||||||
// Constants.
|
// Constants.
|
||||||
|
|
|
@ -19,7 +19,7 @@ import { CoreApp } from '@services/app';
|
||||||
import { CoreError } from '@classes/errors/error';
|
import { CoreError } from '@classes/errors/error';
|
||||||
import { Geolocation, Diagnostic, makeSingleton } from '@singletons/core.singletons';
|
import { Geolocation, Diagnostic, makeSingleton } from '@singletons/core.singletons';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreGeolocationProvider {
|
export class CoreGeolocationProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,7 @@ import { CoreCourseBase } from '@/types/global';
|
||||||
/*
|
/*
|
||||||
* Service to handle groups.
|
* Service to handle groups.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreGroupsProvider {
|
export class CoreGroupsProvider {
|
||||||
|
|
||||||
// Group mode constants.
|
// Group mode constants.
|
||||||
|
|
|
@ -48,7 +48,7 @@ export type CoreInitHandler = {
|
||||||
/*
|
/*
|
||||||
* Provider for initialisation mechanisms.
|
* Provider for initialisation mechanisms.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreInitDelegate {
|
export class CoreInitDelegate {
|
||||||
|
|
||||||
static readonly DEFAULT_PRIORITY = 100; // Default priority for init processes.
|
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.
|
* Service to handle language features, like changing the current language.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreLangProvider {
|
export class CoreLangProvider {
|
||||||
|
|
||||||
protected fallbackLanguage = 'en'; // Always use English as fallback language since it contains all strings.
|
protected fallbackLanguage = 'en'; // Always use English as fallback language since it contains all strings.
|
||||||
|
|
|
@ -39,7 +39,7 @@ import {
|
||||||
/**
|
/**
|
||||||
* Service to handle local notifications.
|
* Service to handle local notifications.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreLocalNotificationsProvider {
|
export class CoreLocalNotificationsProvider {
|
||||||
|
|
||||||
protected logger: CoreLogger;
|
protected logger: CoreLogger;
|
||||||
|
|
|
@ -24,7 +24,7 @@ import { makeSingleton } from '@singletons/core.singletons';
|
||||||
/**
|
/**
|
||||||
* Delegate to register pluginfile information handlers.
|
* Delegate to register pluginfile information handlers.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CorePluginFileDelegate extends CoreDelegate<CorePluginFileHandler> {
|
export class CorePluginFileDelegate extends CoreDelegate<CorePluginFileHandler> {
|
||||||
|
|
||||||
protected handlerNameProperty = 'component';
|
protected handlerNameProperty = 'component';
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { CoreAppSchema } from '@services/app';
|
import { CoreAppSchema } from '@services/app';
|
||||||
import { CoreSiteSchema, registerSiteSchema } from '@services/sites';
|
import { CoreSiteSchema } from '@services/sites';
|
||||||
import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb';
|
import { SQLiteDB, SQLiteDBTableSchema } from '@classes/sqlitedb';
|
||||||
import { CoreSite } from '@classes/site';
|
import { CoreSite } from '@classes/site';
|
||||||
|
|
||||||
|
@ -227,7 +227,3 @@ export type SchemaVersionsDBEntry = {
|
||||||
name: string;
|
name: string;
|
||||||
version: number;
|
version: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initCoreSitesDB = (): void => {
|
|
||||||
registerSiteSchema(SITE_SCHEMA);
|
|
||||||
};
|
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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 { Md5 } from 'ts-md5/dist/md5';
|
||||||
import { timeout } from 'rxjs/operators';
|
import { timeout } from 'rxjs/operators';
|
||||||
|
|
||||||
|
@ -47,25 +47,17 @@ import {
|
||||||
SiteDBEntry,
|
SiteDBEntry,
|
||||||
CurrentSiteDBEntry,
|
CurrentSiteDBEntry,
|
||||||
SchemaVersionsDBEntry,
|
SchemaVersionsDBEntry,
|
||||||
} from '@services/sites.db';
|
} from '@services/sites-db';
|
||||||
|
import { CoreArray } from '../singletons/array';
|
||||||
|
|
||||||
|
export const CORE_SITE_SCHEMAS = new InjectionToken('CORE_SITE_SCHEMAS');
|
||||||
// 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;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Service to manage and interact with sites.
|
* 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
|
* It allows creating tables in the databases of all sites. Each service or component should be responsible of creating
|
||||||
* their own database tables. Example:
|
* their own database tables calling the registerCoreSiteSchema method.
|
||||||
*
|
|
||||||
* import { registerSiteSchema } from '@services/sites';
|
|
||||||
*
|
|
||||||
* registerSiteSchema(tableSchema);
|
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreSitesProvider {
|
export class CoreSitesProvider {
|
||||||
|
|
||||||
// Constants to validate a site version.
|
// Constants to validate a site version.
|
||||||
|
@ -84,11 +76,19 @@ export class CoreSitesProvider {
|
||||||
protected appDB: SQLiteDB;
|
protected appDB: SQLiteDB;
|
||||||
protected dbReady: Promise<void>; // Promise resolved when the app DB is initialized.
|
protected dbReady: Promise<void>; // Promise resolved when the app DB is initialized.
|
||||||
protected siteSchemasMigration: { [siteId: string]: Promise<void> } = {};
|
protected siteSchemasMigration: { [siteId: string]: Promise<void> } = {};
|
||||||
|
protected siteSchemas: { [name: string]: CoreRegisteredSiteSchema } = {};
|
||||||
protected pluginsSiteSchemas: { [name: string]: CoreRegisteredSiteSchema } = {};
|
protected pluginsSiteSchemas: { [name: string]: CoreRegisteredSiteSchema } = {};
|
||||||
|
|
||||||
constructor() {
|
constructor(@Optional() @Inject(CORE_SITE_SCHEMAS) siteSchemas: CoreSiteSchema[][] = []) {
|
||||||
this.logger = CoreLogger.getInstance('CoreSitesProvider');
|
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.appDB = CoreApp.instance.getDB();
|
||||||
this.dbReady = CoreApp.instance.createTablesFromSchema(APP_SCHEMA).catch(() => {
|
this.dbReady = CoreApp.instance.createTablesFromSchema(APP_SCHEMA).catch(() => {
|
||||||
// Ignore errors.
|
// Ignore errors.
|
||||||
|
@ -1446,7 +1446,7 @@ export class CoreSitesProvider {
|
||||||
/**
|
/**
|
||||||
* Register a site schema in current site.
|
* 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
|
* 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.
|
* @param schema The schema to register.
|
||||||
* @return Promise resolved when done.
|
* @return Promise resolved when done.
|
||||||
|
@ -1489,7 +1489,7 @@ export class CoreSitesProvider {
|
||||||
|
|
||||||
// First create tables not registerd with name/version.
|
// First create tables not registerd with name/version.
|
||||||
const promise = site.getDb().createTableFromSchema(SCHEMA_VERSIONS_TABLE_SCHEMA)
|
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;
|
this.siteSchemasMigration[site.id] = promise;
|
||||||
|
|
||||||
|
@ -1602,7 +1602,7 @@ export class CoreSitesProvider {
|
||||||
*/
|
*/
|
||||||
getSiteTableSchemasToClear(site: CoreSite): string[] {
|
getSiteTableSchemasToClear(site: CoreSite): string[] {
|
||||||
let reset: 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) => {
|
schemas.forEach((schema) => {
|
||||||
if (schema.canBeCleared && (!schema.siteId || site.getId() == schema.siteId)) {
|
if (schema.canBeCleared && (!schema.siteId || site.getId() == schema.siteId)) {
|
||||||
|
|
|
@ -12,13 +12,13 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { CoreSiteSchema, registerSiteSchema } from '@services/sites';
|
import { CoreSiteSchema } from '@services/sites';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database variables for CoreSync service.
|
* Database variables for CoreSync service.
|
||||||
*/
|
*/
|
||||||
export const SYNC_TABLE_NAME = 'sync';
|
export const SYNC_TABLE_NAME = 'sync';
|
||||||
const SITE_SCHEMA: CoreSiteSchema = {
|
export const SITE_SCHEMA: CoreSiteSchema = {
|
||||||
name: 'CoreSyncProvider',
|
name: 'CoreSyncProvider',
|
||||||
version: 1,
|
version: 1,
|
||||||
tables: [
|
tables: [
|
||||||
|
@ -55,7 +55,3 @@ export type CoreSyncRecord = {
|
||||||
time: number;
|
time: number;
|
||||||
warnings: string;
|
warnings: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const initCoreSyncDB = (): void => {
|
|
||||||
registerSiteSchema(SITE_SCHEMA);
|
|
||||||
};
|
|
|
@ -16,12 +16,12 @@ import { Injectable } from '@angular/core';
|
||||||
import { CoreEvents } from '@singletons/events';
|
import { CoreEvents } from '@singletons/events';
|
||||||
import { CoreSites } from '@services/sites';
|
import { CoreSites } from '@services/sites';
|
||||||
import { makeSingleton } from '@singletons/core.singletons';
|
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.
|
* Service that provides some features regarding synchronization.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreSyncProvider {
|
export class CoreSyncProvider {
|
||||||
|
|
||||||
// Store blocked sync objects.
|
// 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.
|
* 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 {
|
export class CoreUpdateManagerProvider implements CoreInitHandler {
|
||||||
|
|
||||||
// Data for init delegate.
|
// 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.
|
* "Utils" service with helper functions for UI, DOM elements and HTML code.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreDomUtilsProvider {
|
export class CoreDomUtilsProvider {
|
||||||
|
|
||||||
protected readonly INSTANCE_ID_ATTR_NAME = 'core-instance-id';
|
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.
|
* "Utils" service with helper functions for iframes, embed and similar.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreIframeUtilsProvider {
|
export class CoreIframeUtilsProvider {
|
||||||
|
|
||||||
static readonly FRAME_TAGS = ['iframe', 'frame', 'object', 'embed'];
|
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.
|
* "Utils" service with helper functions for mimetypes and extensions.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreMimetypeUtilsProvider {
|
export class CoreMimetypeUtilsProvider {
|
||||||
|
|
||||||
protected logger: CoreLogger;
|
protected logger: CoreLogger;
|
||||||
|
|
|
@ -37,7 +37,7 @@ export type CoreTextErrorObject = {
|
||||||
/*
|
/*
|
||||||
* "Utils" service with helper functions for text.
|
* "Utils" service with helper functions for text.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreTextUtilsProvider {
|
export class CoreTextUtilsProvider {
|
||||||
|
|
||||||
// List of regular expressions to convert the old nomenclature to new nomenclature for disabled features.
|
// 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.
|
* "Utils" service with helper functions for date and time.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreTimeUtilsProvider {
|
export class CoreTimeUtilsProvider {
|
||||||
|
|
||||||
protected static readonly FORMAT_REPLACEMENTS = { // To convert PHP strf format to Moment format.
|
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.
|
* "Utils" service with helper functions for URLs.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreUrlUtilsProvider {
|
export class CoreUrlUtilsProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,7 +36,7 @@ type TreeNode<T> = T & { children: TreeNode<T>[] };
|
||||||
/*
|
/*
|
||||||
* "Utils" service with helper functions.
|
* "Utils" service with helper functions.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreUtilsProvider {
|
export class CoreUtilsProvider {
|
||||||
|
|
||||||
protected readonly DONT_CLONE = ['[object FileEntry]', '[object DirectoryEntry]', '[object DOMFileSystem]'];
|
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.
|
* This service allows performing WS calls and download/upload files.
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CoreWSProvider {
|
export class CoreWSProvider {
|
||||||
|
|
||||||
protected logger: CoreLogger;
|
protected logger: CoreLogger;
|
||||||
|
|
Loading…
Reference in New Issue