Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
feat: user new package manager api
Browse files Browse the repository at this point in the history
Change-Id: I37f012cd8778aa7ccbb52ec8bc86331da36cf974
  • Loading branch information
myml committed Dec 4, 2018
1 parent e016e96 commit ed005d5
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 118 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { first, switchMap } from 'rxjs/operators';
import { AppService } from 'app/services/app.service';
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { AppVersion } from '../../models/app-version';
Expand Down Expand Up @@ -29,26 +30,41 @@ export class JobButtonComponent implements OnInit {
e.stopPropagation();
switch (this.openType) {
case 'desktop':
this.storeService.openApp(this.appName);
this.appService
.getApp(this.appName)
.pipe(first())
.subscribe(app => this.storeService.openApp(app));
break;
}
}

installApp(e: Event) {
e.stopPropagation();
console.log(this.version);
this.storeService.installPackage(this.appName, this.localName).subscribe(job => {
this.disabled = true;
this.start.emit(job);
});
this.appService
.getApp(this.appName)
.pipe(
first(),
switchMap(app => this.storeService.installPackages([app])),
)
.subscribe(job => {
this.disabled = true;
this.start.emit(job);
});
}

updateApp(e: Event) {
e.stopPropagation();
this.storeService.updatePackage(this.appName, this.localName).subscribe(job => {
this.disabled = true;
this.start.emit(job);
});
this.appService
.getApp(this.appName)
.pipe(
first(),
switchMap(app => this.storeService.updatePackages([app])),
)
.subscribe(job => {
this.disabled = true;
this.start.emit(job);
});
}
}

Expand Down
122 changes: 70 additions & 52 deletions src/web/src/app/modules/client/services/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export class StoreService {
return this.execWithCallback('storeDaemon.isDBusConnected');
}

fixError(errorType: string): Observable<string> {
return this.execWithCallback('storeDaemon.fixError', errorType);
}

getJobList(): Observable<string[]> {
return this.execWithCallback('storeDaemon.jobList');
}
Expand All @@ -24,8 +28,8 @@ export class StoreService {
return this.execWithCallback('storeDaemon.getJobInfo', jobPath);
}

getJobsInfo(jobs: string[]): Observable<StoreJobInfo[]> {
return this.execWithCallback('storeDaemon.getJobsInfo', jobs);
getJobsInfo(jobPaths: string[]): Observable<StoreJobInfo[]> {
return this.execWithCallback('storeDaemon.getJobsInfo', jobPaths);
}

jobListChange(): Observable<string[]> {
Expand All @@ -44,71 +48,67 @@ export class StoreService {
Channel.exec('storeDaemon.startJob', job);
}

installPackage(appName: string, localName: string): Observable<string> {
this.downloadTotalService.installed(appName);
return this.execWithCallback('storeDaemon.installPackage', appName, localName);
openApp(app: App): void {
Channel.exec('storeDaemon.openApp', this.toQuery(app));
}

updatePackage(appName: string, localName: string): Observable<string> {
this.downloadTotalService.installed(appName);
return this.execWithCallback('storeDaemon.updatePackage', appName, localName);
installPackages(apps: App[]): Observable<string> {
apps.forEach(app => this.downloadTotalService.installed(app.name));
return this.execWithCallback('storeDaemon.installPackages', apps.map(this.toQuery));
}

removePackage(appName: string, localName: string): Observable<string> {
return this.execWithCallback('storeDaemon.removePackage', appName, localName);
updatePackages(apps: App[]): Observable<string> {
apps.forEach(app => this.downloadTotalService.installed(app.name));
return this.execWithCallback('storeDaemon.updatePackages', apps.map(this.toQuery));
}

appInstallable(appName: string): Observable<boolean> {
return this.execWithCallback('storeDaemon.packageInstallable', appName);
removePackages(apps: App[]): Observable<string> {
return this.execWithCallback('storeDaemon.removePackages', apps.map(this.toQuery));
}

InstalledPackages(): Observable<string[]> {
return this.execWithCallback<string[]>('storeDaemon.installedPackages');
InstalledPackages() {
interface InstalledPackage {
packageURI: string;
size: number;
}
return this.execWithCallback<InstalledPackage[]>('storeDaemon.installedPackages').pipe(
map(result =>
result.reduce((m, pkg) => m.set(pkg.packageURI, pkg), new Map<string, InstalledPackage>()),
),
);
}

fixError(errorType: string): Observable<string> {
return this.execWithCallback('storeDaemon.fixError', errorType);
toQuery(app: App) {
return {
name: app.name,
localName: app.localInfo.description.name,
packages: app.packageURI.map(packageURI => ({ packageURI })),
};
}

openApp(appName: string): void {
Channel.exec('storeDaemon.openApp', appName);
queryDownloadSize(apps: App[]) {
return this.execWithCallback<QueryResult>(
'storeDaemon.queryDownloadSize',
apps.map(this.toQuery),
).pipe(
map(result => {
const arr = Object.values(result)
.filter(Boolean)
.filter(r => r.packages && r.packages.length > 0)
.map(r => [r.name, r.packages[0].downloadSize] as [string, number]);
return new Map(arr);
}),
);
}

queryPackage(apps: App[]) {
interface AppPackage {
appName: string;
packageName: string;
packageURI: string;
localVersion: string;
remoteVersion: string;
upgradable: boolean;
installedTime: number;
packageSize: number;
downloadSize: number;
}
interface Result {
[key: string]: {
name: string;
packages: AppPackage[];
};
}
const query = apps.map(app => {
return {
name: app.name,
packages: app.packageURI.map(url => {
return { packageURI: url };
}),
};
});
return this.execWithCallback<Result>('storeDaemon.query', query).pipe(
return this.execWithCallback<QueryResult>('storeDaemon.query', apps.map(this.toQuery)).pipe(
map(result => {
const pkg = new Map<string, AppPackage>();
for (const r of Object.values(result)) {
if (r.packages.length > 0) {
pkg.set(r.name, r.packages[0]);
}
}
return pkg;
const arr = Object.values(result)
.filter(Boolean)
.map(r => r.packages.find(pkg => Boolean(pkg.appName)))
.filter(Boolean)
.map(pkg => [pkg.appName, pkg] as [string, AppPackage]);
return new Map(arr);
}),
);
}
Expand All @@ -131,3 +131,21 @@ class StoreResponse {
errorMsg: string;
result: any;
}

interface QueryResult {
[key: string]: {
name: string;
packages: AppPackage[];
};
}
interface AppPackage {
appName: string;
packageName: string;
packageURI: string;
localVersion: string;
remoteVersion: string;
upgradable: boolean;
installedTime: number;
downloadSize: number;
packageSize: number;
}
13 changes: 10 additions & 3 deletions src/web/src/app/modules/details/app-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,16 @@
<ng-container *ngIf="app.version">
<div>{{ app.version.remoteVersion || app.version.localVersion }}</div>
<div>
<ng-container *ngIf="app.version.downloadSize;else downloaded">{{ app.version.downloadSize | sizeHuman }}</ng-container>
<ng-template #downloaded
i18n>Downloaded</ng-template>
<ng-container *ngIf="(size$|async)?.get(app.name) as size;else calculating">
{{ size | sizeHuman }}
</ng-container>
<ng-template #calculating
let-size>
<ng-container *ngIf="size===null"
i18n>Calculating</ng-container>
<ng-container *ngIf="size===0"
i18n>Downloaded</ng-container>
</ng-template>
</div>
</ng-container>
<div>
Expand Down
8 changes: 7 additions & 1 deletion src/web/src/app/modules/details/app-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component, OnInit, ViewChild, ElementRef, OnDestroy } from '@angular/co
import { DomSanitizer } from '@angular/platform-browser';
import { ActivatedRoute } from '@angular/router';
import { Observable, timer, of, iif, forkJoin, merge, combineLatest } from 'rxjs';
import { flatMap, map, tap, share, switchMap, startWith, first, shareReplay } from 'rxjs/operators';
import { flatMap, publishReplay, tap, publish, refCount, switchMap, share } from 'rxjs/operators';

import { App, AppService } from 'app/services/app.service';
import { BaseService } from 'app/dstore/services/base.service';
Expand Down Expand Up @@ -51,7 +51,13 @@ export class AppDetailComponent implements OnInit {
start = this.storeService.resumeJob;

app$ = this.route.paramMap.pipe(
tap(() => console.log('test')),
switchMap(param => this.appService.getApp(param.get('appName'))),
publishReplay(1),
refCount(),
);
size$ = this.app$.pipe(
switchMap(app => this.storeService.queryDownloadSize([app])),
share(),
);
job$ = this.app$.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
</div>
</ng-template>


<div class="list"
*ngIf="loaded; else: loading">
*ngIf="result$|async as result; else: loading">
<div class="title"
i18n>Processing {{ jobs.length }} {jobs.length, plural,=0 {task} =1 {task} other {tasks}}</div>

<table>
<ng-container *ngFor="let job of jobs">
<ng-container *ngFor="let appName of job.names">
<tr *ngIf="appName|appInfo|async as $app"
@flyInOut>
<ng-container *ngFor="let r of result">
<ng-container *ngIf="r.job as job">
<tr *ngIf="r.app as $app">
<td><img class="icon"
[src]="$app.icon"
[routerLink]="$app.name" /></td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, OnDestroy } from '@angular/core';
import { trigger, state, style, animate, transition } from '@angular/animations';
import { Observable, of, forkJoin, timer, iif, merge, Subscription } from 'rxjs';
import { switchMap, map, tap, filter } from 'rxjs/operators';
import { switchMap, map, tap, filter, publishReplay, refCount } from 'rxjs/operators';

import { AppService, App } from 'app/services/app.service';
import { StoreService } from 'app/modules/client/services/store.service';
Expand Down Expand Up @@ -43,38 +43,52 @@ export class DownloadComponent implements OnInit, OnDestroy {
pause = this.storeService.pauseJob;

loaded = false;
result$ = this.jobService.jobsInfo().pipe(
map(jobs => {
return jobs
.filter(job => job.type === StoreJobType.download || job.type === StoreJobType.install)
.sort((a, b) => b.createTime - a.createTime);
}),
switchMap(
jobs => {
const names = [].concat(...jobs.map(job => job.names));
return this.appService.getApps(names);
},
(jobs, apps) => {
return apps.map(app => ({ app, job: jobs.find(job => job.names.includes(app.name)) }));
},
),
);

apps = new Map<string, App>();
jobs: StoreJobInfo[] = [];
cancels = new Set<string>();
jobs$: Subscription;
fixing = false;

ngOnInit() {
this.jobs$ = this.jobService.jobsInfo().subscribe(jobs => {
jobs = jobs.filter(
job => job.type === StoreJobType.download || job.type === StoreJobType.install,
);
const list = jobs.map(job => job.id);
this.jobs.forEach((job, index) => {
if (!list.includes(job.id)) {
this.jobs.splice(index, 1);
}
});
jobs.forEach(job => {
const old = this.jobs.find(j => j.id === job.id);
if (old) {
Object.assign(old, job);
} else {
this.jobs.unshift(job);
}
});
this.loaded = true;
});
// this.jobs$ = this.jobService.jobsInfo().subscribe(jobs => {
// jobs = jobs.filter(
// job => job.type === StoreJobType.download || job.type === StoreJobType.install,
// );
// const list = jobs.map(job => job.id);
// this.jobs.forEach((job, index) => {
// if (!list.includes(job.id)) {
// this.jobs.splice(index, 1);
// }
// });
// jobs.forEach(job => {
// const old = this.jobs.find(j => j.id === job.id);
// if (old) {
// Object.assign(old, job);
// } else {
// this.jobs.unshift(job);
// }
// });
// this.loaded = true;
// });
}

ngOnDestroy() {
this.jobs$.unsubscribe();
}
ngOnDestroy() {}
retry(job: StoreJobInfo) {
let err: StoreJobError;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ export class BatchInstallComponent implements OnInit {
}

installAll() {
console.log(this.batchInstall);
this.remoteAppService.installApps([...this.batchInstall.values()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,6 @@
<ng-template #install>
<button i18n>Install</button>
</ng-template>
<!-- <button i18n
*ngIf="remoteApp.app.version.upgradable;">Update</button>
<ng-template #Installed>
<button i18n
*ngSwitchCase="remoteApp.app.version.localVersion!=''">Installed</button>
</ng-template>
<button i18n
*ngSwitchCase="remoteApp.app.version.upgradable">Update</button>
<button i18n
*ngSwitchCase="remoteApp.app.version.localVersion!=''">Installed</button>
<button i18n
*ngSwitchDefault>Install</button> -->
</div>
</ng-container>
<ng-template #noVersionError>
Expand Down
Loading

0 comments on commit ed005d5

Please sign in to comment.