MOBILE-3924 licenses: Add filter license and update
parent
80f1b96f61
commit
4be4912864
2226
licenses.json
2226
licenses.json
File diff suppressed because it is too large
Load Diff
|
@ -9,6 +9,9 @@
|
|||
</ion-header>
|
||||
<ion-content>
|
||||
<core-loading [hideUntil]="loaded">
|
||||
<ion-searchbar [(ngModel)]="textFilter" (ionInput)="filterChanged($event.target)" (ionCancel)="filterChanged($event.target)"
|
||||
[placeholder]="'core.filter' | translate">
|
||||
</ion-searchbar>
|
||||
<ion-list>
|
||||
<ion-item button *ngIf="error" class="ion-text-wrap" [href]="licensesUrl" core-link auto-login="no">
|
||||
<ion-label>
|
||||
|
@ -21,8 +24,7 @@
|
|||
<ion-item *ngFor="let license of licenses" class="ion-text-wrap">
|
||||
<ion-label>
|
||||
<p class="item-heading">
|
||||
<a *ngIf="license.repository" [href]="license.repository" core-link
|
||||
auto-login="no">{{ license.name }}</a>
|
||||
<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 }}
|
||||
</p>
|
||||
<p class="item-heading" *ngIf="license.publisher">
|
||||
|
@ -31,10 +33,10 @@
|
|||
<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"
|
||||
[showBrowserWarning]="false">{{ license.email }}</a></p>
|
||||
[showBrowserWarning]="false">{{ 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-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>
|
||||
</ion-list>
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { CoreConstants } from '@/core/constants';
|
||||
import { Http } from '@singletons';
|
||||
import { IonSearchbar } from '@ionic/angular';
|
||||
|
||||
/**
|
||||
* Defines license info
|
||||
|
@ -22,7 +23,7 @@ import { Http } from '@singletons';
|
|||
interface CoreSettingsLicense {
|
||||
name: string;
|
||||
version: string;
|
||||
licenses: string;
|
||||
licenses: string | string[];
|
||||
repository?: string;
|
||||
publisher?: string;
|
||||
url?: string;
|
||||
|
@ -44,39 +45,48 @@ export class CoreSettingsLicensesPage implements OnInit {
|
|||
loaded = false;
|
||||
licenses: CoreSettingsLicense[] = [];
|
||||
error = false;
|
||||
textFilter = '';
|
||||
appLicenseVersion: string;
|
||||
|
||||
protected allLicenses: CoreSettingsLicense[] = [];
|
||||
|
||||
constructor() {
|
||||
let version = 'v' + CoreConstants.CONFIG.versionname;
|
||||
if (version.indexOf('-') > 0) {
|
||||
version = 'integration';
|
||||
}
|
||||
this.appLicenseVersion = CoreConstants.CONFIG.versionname.indexOf('-') > 0
|
||||
? 'integration'
|
||||
: 'v' + CoreConstants.CONFIG.versionname;
|
||||
|
||||
this.licensesUrl = 'https://raw.githubusercontent.com/moodlehq/moodleapp/' + version + '/licenses.json';
|
||||
this.licensesUrl = 'https://raw.githubusercontent.com/moodlehq/moodleapp/' + this.appLicenseVersion + '/licenses.json';
|
||||
}
|
||||
|
||||
/**
|
||||
* View loaded.
|
||||
* @inheritdoc
|
||||
*/
|
||||
async ngOnInit(): Promise<void> {
|
||||
try {
|
||||
const licenses = await Http.get(this.licensesUrl).toPromise();
|
||||
this.licenses = Object.keys(licenses).map((name) => {
|
||||
this.allLicenses = 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 (Array.isArray(license.licenses)) {
|
||||
license.licenses = license.licenses.join(', ');
|
||||
}
|
||||
|
||||
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;
|
||||
const version = license.name == 'moodlemobile' ? this.appLicenseVersion : license.version;
|
||||
license.licenseUrl = license.repository + '/blob/' + version + '/' + license.licenseFile;
|
||||
}
|
||||
}
|
||||
|
||||
return license;
|
||||
});
|
||||
|
||||
this.filterLicenses();
|
||||
|
||||
this.error = false;
|
||||
} catch {
|
||||
this.error = true;
|
||||
|
@ -85,4 +95,36 @@ export class CoreSettingsLicensesPage implements OnInit {
|
|||
this.loaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter licenses using filter text.
|
||||
*/
|
||||
filterLicenses(): void {
|
||||
const filter = this.textFilter.trim().toLowerCase();
|
||||
|
||||
if (filter == '') {
|
||||
this.licenses = this.allLicenses;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.licenses = this.allLicenses.filter((license) => license.name.toLowerCase().indexOf(filter) >=0 ||
|
||||
license.version.toLowerCase().indexOf(filter) >=0 ||
|
||||
typeof license.licenses == 'string' && license.licenses.toLowerCase().indexOf(filter) >=0 ||
|
||||
license.repository && license.repository.toLowerCase().indexOf(filter) >=0 ||
|
||||
license.publisher && license.publisher.toLowerCase().indexOf(filter) >=0 ||
|
||||
license.url && license.url.toLowerCase().indexOf(filter) >=0 ||
|
||||
license.email && license.email.toLowerCase().indexOf(filter) >=0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Text filter changed.
|
||||
*
|
||||
* @param target Searchbar element.
|
||||
*/
|
||||
filterChanged(target: IonSearchbar): void {
|
||||
this.textFilter = target.value || '';
|
||||
|
||||
this.filterLicenses();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue