diff --git a/src/app/core/settings/pages/app/app.page.ts b/src/app/core/settings/pages/app/app.page.ts index 7caeb0245..5f2306a07 100644 --- a/src/app/core/settings/pages/app/app.page.ts +++ b/src/app/core/settings/pages/app/app.page.ts @@ -13,14 +13,14 @@ // limitations under the License. import { CoreApp } from '@services/app'; -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Params, Router } from '@angular/router'; @Component({ selector: 'app-settings', templateUrl: 'app.html', }) -export class CoreSettingsAppPage { +export class CoreSettingsAppPage implements OnInit { // @ViewChild(CoreSplitViewComponent) splitviewCtrl?: CoreSplitViewComponent; @@ -42,7 +42,7 @@ export class CoreSettingsAppPage { /** * View loaded. */ - ionViewDidLoad(): void { + ngOnInit(): void { if (this.selectedPage) { this.openSettings(this.selectedPage); } /* else if (this.splitviewCtrl!.isOn()) { diff --git a/src/app/core/settings/pages/licenses/licenses.html b/src/app/core/settings/pages/licenses/licenses.html new file mode 100644 index 000000000..a59e71b46 --- /dev/null +++ b/src/app/core/settings/pages/licenses/licenses.html @@ -0,0 +1,41 @@ + + + + + + + {{ 'core.settings.opensourcelicenses' | translate }} + + + + + + + {{ 'core.settings.opensourcelicenses' | translate }} + + + {{ 'core.view' | translate }} + + + + + +

+ {{ license.name }} + {{ license.name }} - {{ license.version }} +

+

+ {{ 'core.settings.publisher' | translate }}{{ 'core.labelsep' | translate }} {{ license.publisher }} +

+

{{ 'core.settings.license' | translate }}{{ 'core.labelsep' | translate }} {{ license.licenses }}

+

{{ license.url }}

+

{{ license.email }}

+
+ {{ 'core.view' | translate }} +
+
+
+
diff --git a/src/app/core/settings/pages/licenses/licenses.page.module.ts b/src/app/core/settings/pages/licenses/licenses.page.module.ts new file mode 100644 index 000000000..82d17b9ed --- /dev/null +++ b/src/app/core/settings/pages/licenses/licenses.page.module.ts @@ -0,0 +1,48 @@ +// (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 { TranslateModule } from '@ngx-translate/core'; +import { RouterModule, Routes } from '@angular/router'; +import { CommonModule } from '@angular/common'; +import { IonicModule } from '@ionic/angular'; + +import { CoreComponentsModule } from '@components/components.module'; +import { CoreDirectivesModule } from '@directives/directives.module'; +import { CorePipesModule } from '@pipes/pipes.module'; + +import { CoreSettingsLicensesPage } from './licenses.page'; + +const routes: Routes = [ + { + path: '', + component: CoreSettingsLicensesPage, + }, +]; + +@NgModule({ + declarations: [ + CoreSettingsLicensesPage, + ], + imports: [ + RouterModule.forChild(routes), + CommonModule, + IonicModule, + TranslateModule.forChild(), + CoreComponentsModule, + CoreDirectivesModule, + CorePipesModule, + ], +}) +export class CoreSettingsLicensesPageModule {} diff --git a/src/app/core/settings/pages/licenses/licenses.page.ts b/src/app/core/settings/pages/licenses/licenses.page.ts new file mode 100644 index 000000000..1a20ec763 --- /dev/null +++ b/src/app/core/settings/pages/licenses/licenses.page.ts @@ -0,0 +1,88 @@ +// (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, OnInit } from '@angular/core'; +import { CoreConstants } from '@core/constants'; +import { Http } from '@/app/singletons/core.singletons'; + +/** + * Defines license info + */ +interface CoreSettingsLicense { + name: string; + version: string; + licenses: string; + repository?: string; + publisher?: string; + url?: string; + email?: string; + licenseUrl?: string; + licenseFile?: string; +} + +/** + * Page that displays the open source licenses information. + */ +@Component({ + selector: 'page-core-settings-licenses', + templateUrl: 'licenses.html', +}) +export class CoreSettingsLicensesPage implements OnInit { + + licensesUrl: string; + loaded = false; + licenses: CoreSettingsLicense[] = []; + error = false; + + constructor() { + let version = 'v' + CoreConstants.CONFIG.versionname; + if (version.indexOf('-') > 0) { + version = 'integration'; + } + + this.licensesUrl = 'https://raw.githubusercontent.com/moodlehq/moodleapp/' + version + '/licenses.json'; + } + + /** + * View loaded. + */ + async ngOnInit(): Promise { + try { + const licenses = await Http.instance.get(this.licensesUrl).toPromise(); + this.licenses = Object.keys(licenses).map((name) => { + const license = licenses[name]; + + const nameSplit = name.lastIndexOf('@'); + license.name = name.substring(0, nameSplit); + license.version = name.substring(nameSplit + 1); + + if (license.repository) { + license.repository = license.repository.replace('git://', 'https://'); + if (license.repository.indexOf('github.com') > 0) { + license.licenseUrl = license.repository + '/blob/' + license.version + '/' + license.licenseFile; + } + } + + return license; + }); + + this.error = false; + } catch { + this.error = true; + } + + this.loaded = true; + } + +} diff --git a/src/app/core/settings/settings-routing.module.ts b/src/app/core/settings/settings-routing.module.ts index aa46c4a83..a8349e0e8 100644 --- a/src/app/core/settings/settings-routing.module.ts +++ b/src/app/core/settings/settings-routing.module.ts @@ -24,6 +24,10 @@ const routes: Routes = [ path: 'general', loadChildren: () => import('./pages/general/general.page.module').then( m => m.CoreSettingsGeneralPageModule), }, + { + path: 'licenses', + loadChildren: () => import('./pages/licenses/licenses.page.module').then( m => m.CoreSettingsLicensesPageModule), + }, { path: '', loadChildren: () => import('./pages/app/app.page.module').then( m => m.CoreSettingsAppPageModule), diff --git a/src/app/directives/fa-icon.ts b/src/app/directives/fa-icon.ts index f2f60c509..ba6df3247 100644 --- a/src/app/directives/fa-icon.ts +++ b/src/app/directives/fa-icon.ts @@ -44,7 +44,7 @@ export class CoreFaIconDirective implements OnChanges { /** * Detect icon name and use svg. */ - setIcon(): void { + async setIcon(): Promise { let library = 'ionic'; let iconName = this.name; const parts = iconName.split('-', 2); @@ -73,13 +73,11 @@ export class CoreFaIconDirective implements OnChanges { this.element.setAttribute('src', src); if (CoreConstants.BUILD.isDevelopment || CoreConstants.BUILD.isTesting) { - Http.instance.get(src).subscribe(() => { - // Ignore. - }, (error) => { - if (error.status != 200) { - this.logger.error(`Icon ${this.name} not found`); - } - }); + try { + await Http.instance.get(src, { responseType: 'text' }).toPromise(); + } catch (error) { + this.logger.error(`Icon ${this.name} not found`); + } } } else { this.element.removeAttribute('src');