MOBILE-3924 licenses: Add filter license and update

main
Pau Ferrer Ocaña 2021-11-15 17:42:11 +01:00
parent 80f1b96f61
commit 4be4912864
3 changed files with 1123 additions and 1175 deletions

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,9 @@
</ion-header> </ion-header>
<ion-content> <ion-content>
<core-loading [hideUntil]="loaded"> <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-list>
<ion-item button *ngIf="error" class="ion-text-wrap" [href]="licensesUrl" core-link auto-login="no"> <ion-item button *ngIf="error" class="ion-text-wrap" [href]="licensesUrl" core-link auto-login="no">
<ion-label> <ion-label>
@ -21,8 +24,7 @@
<ion-item *ngFor="let license of licenses" class="ion-text-wrap"> <ion-item *ngFor="let license of licenses" class="ion-text-wrap">
<ion-label> <ion-label>
<p class="item-heading"> <p class="item-heading">
<a *ngIf="license.repository" [href]="license.repository" core-link <a *ngIf="license.repository" [href]="license.repository" core-link auto-login="no">{{ license.name }}</a>
auto-login="no">{{ license.name }}</a>
<ng-container *ngIf="!license.repository">{{ license.name }}</ng-container> - {{ license.version }} <ng-container *ngIf="!license.repository">{{ license.name }}</ng-container> - {{ license.version }}
</p> </p>
<p class="item-heading" *ngIf="license.publisher"> <p class="item-heading" *ngIf="license.publisher">
@ -31,10 +33,10 @@
<p>{{ 'core.settings.license' | translate }}{{ 'core.labelsep' | translate }} {{ license.licenses }}</p> <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.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" <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-label>
<ion-button *ngIf="license.licenseUrl" [href]="license.licenseUrl" target="_blank" <ion-button *ngIf="license.licenseUrl" [href]="license.licenseUrl" target="_blank" fill="clear" slot="end" core-link
fill="clear" slot="end" core-link auto-login="no">{{ 'core.view' | translate }}</ion-button> auto-login="no">{{ 'core.view' | translate }}</ion-button>
</ion-item> </ion-item>
</ng-container> </ng-container>
</ion-list> </ion-list>

View File

@ -15,6 +15,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { CoreConstants } from '@/core/constants'; import { CoreConstants } from '@/core/constants';
import { Http } from '@singletons'; import { Http } from '@singletons';
import { IonSearchbar } from '@ionic/angular';
/** /**
* Defines license info * Defines license info
@ -22,7 +23,7 @@ import { Http } from '@singletons';
interface CoreSettingsLicense { interface CoreSettingsLicense {
name: string; name: string;
version: string; version: string;
licenses: string; licenses: string | string[];
repository?: string; repository?: string;
publisher?: string; publisher?: string;
url?: string; url?: string;
@ -44,39 +45,48 @@ export class CoreSettingsLicensesPage implements OnInit {
loaded = false; loaded = false;
licenses: CoreSettingsLicense[] = []; licenses: CoreSettingsLicense[] = [];
error = false; error = false;
textFilter = '';
appLicenseVersion: string;
protected allLicenses: CoreSettingsLicense[] = [];
constructor() { constructor() {
let version = 'v' + CoreConstants.CONFIG.versionname; this.appLicenseVersion = CoreConstants.CONFIG.versionname.indexOf('-') > 0
if (version.indexOf('-') > 0) { ? 'integration'
version = '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> { async ngOnInit(): Promise<void> {
try { try {
const licenses = await Http.get(this.licensesUrl).toPromise(); 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 license = licenses[name];
const nameSplit = name.lastIndexOf('@'); const nameSplit = name.lastIndexOf('@');
license.name = name.substring(0, nameSplit); license.name = name.substring(0, nameSplit);
license.version = name.substring(nameSplit + 1); license.version = name.substring(nameSplit + 1);
if (Array.isArray(license.licenses)) {
license.licenses = license.licenses.join(', ');
}
if (license.repository) { if (license.repository) {
license.repository = license.repository.replace('git://', 'https://'); license.repository = license.repository.replace('git://', 'https://');
if (license.repository.indexOf('github.com') > 0) { 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; return license;
}); });
this.filterLicenses();
this.error = false; this.error = false;
} catch { } catch {
this.error = true; this.error = true;
@ -85,4 +95,36 @@ export class CoreSettingsLicensesPage implements OnInit {
this.loaded = true; 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();
}
} }