forked from CIT/Vmeda.Online
		
	MOBILE-3565 settings: Add licenses page
This commit is contained in:
		
							parent
							
								
									f09c3f9210
								
							
						
					
					
						commit
						51fba1f5d8
					
				@ -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()) {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										41
									
								
								src/app/core/settings/pages/licenses/licenses.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/app/core/settings/pages/licenses/licenses.html
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
			
		||||
<ion-header>
 | 
			
		||||
    <ion-toolbar>
 | 
			
		||||
        <ion-buttons slot="start">
 | 
			
		||||
            <ion-back-button [attr.aria-label]="'core.back' | translate"></ion-back-button>
 | 
			
		||||
        </ion-buttons>
 | 
			
		||||
 | 
			
		||||
        <ion-title>{{ 'core.settings.opensourcelicenses' | translate }}</ion-title>
 | 
			
		||||
    </ion-toolbar>
 | 
			
		||||
</ion-header>
 | 
			
		||||
<ion-content>
 | 
			
		||||
    <core-loading [hideUntil]="loaded">
 | 
			
		||||
        <ion-item button *ngIf="error" class="ion-text-wrap" [href]="licensesUrl" core-link auto-login="no">
 | 
			
		||||
            <ion-label>
 | 
			
		||||
                {{ 'core.settings.opensourcelicenses' | translate }}
 | 
			
		||||
            </ion-label>
 | 
			
		||||
            <ion-button [href]="licensesUrl" target="_blank" fill="clear" slot="end" core-link auto-login="no">
 | 
			
		||||
                {{ 'core.view' | translate }}</ion-button>
 | 
			
		||||
        </ion-item>
 | 
			
		||||
 | 
			
		||||
        <ng-container *ngIf="!error">
 | 
			
		||||
            <ion-item *ngFor="let license of licenses" class="ion-text-wrap">
 | 
			
		||||
                <ion-label>
 | 
			
		||||
                    <h2>
 | 
			
		||||
                        <a *ngIf="license.repository" [href]="license.repository" core-link
 | 
			
		||||
                            auto-login="no">{{ license.name }}</a>
 | 
			
		||||
                        <ng-container *ngIf="!license.repository">{{ license.name }}</ng-container> - {{ license.version }}
 | 
			
		||||
                    </h2>
 | 
			
		||||
                    <h3 *ngIf="license.publisher">
 | 
			
		||||
                        {{ 'core.settings.publisher' | translate }}{{ 'core.labelsep' | translate }} {{ license.publisher }}
 | 
			
		||||
                    </h3>
 | 
			
		||||
                    <p>{{ 'core.settings.license' | translate }}{{ 'core.labelsep' | translate }} {{ license.licenses }}</p>
 | 
			
		||||
                    <p><a *ngIf="license.url" [href]="license.url" core-link auto-login="no">{{ license.url }}</a></p>
 | 
			
		||||
                    <p><a *ngIf="license.email" [href]="'mailto:' + license.email" core-link
 | 
			
		||||
                            auto-login="no">{{ license.email }}</a></p>
 | 
			
		||||
                </ion-label>
 | 
			
		||||
                <ion-button *ngIf="license.licenseUrl" [href]="license.licenseUrl" target="_blank"
 | 
			
		||||
                    fill="clear" slot="end" core-link auto-login="no">{{ 'core.view' | translate }}</ion-button>
 | 
			
		||||
            </ion-item>
 | 
			
		||||
        </ng-container>
 | 
			
		||||
    </core-loading>
 | 
			
		||||
</ion-content>
 | 
			
		||||
							
								
								
									
										48
									
								
								src/app/core/settings/pages/licenses/licenses.page.module.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/app/core/settings/pages/licenses/licenses.page.module.ts
									
									
									
									
									
										Normal file
									
								
							@ -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 {}
 | 
			
		||||
							
								
								
									
										88
									
								
								src/app/core/settings/pages/licenses/licenses.page.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								src/app/core/settings/pages/licenses/licenses.page.ts
									
									
									
									
									
										Normal file
									
								
							@ -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<void> {
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -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),
 | 
			
		||||
 | 
			
		||||
@ -44,7 +44,7 @@ export class CoreFaIconDirective implements OnChanges {
 | 
			
		||||
    /**
 | 
			
		||||
     * Detect icon name and use svg.
 | 
			
		||||
     */
 | 
			
		||||
    setIcon(): void {
 | 
			
		||||
    async setIcon(): Promise<void> {
 | 
			
		||||
        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');
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user