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

Commit

Permalink
feat: use query package api
Browse files Browse the repository at this point in the history
Change-Id: I83bc1e00925065e9253e3c2f918bed654e788fbc
  • Loading branch information
myml committed Nov 28, 2018
1 parent 384edbf commit 5564970
Show file tree
Hide file tree
Showing 31 changed files with 294 additions and 454 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<ng-template #controlBtn>
<div #ctlBtn>
<dstore-job-button [version]="versions.get($app.name)"
<dstore-job-button [version]="$app.version"
[appName]="$app.name"
[localName]="$app.localInfo.description.name"
[openType]="$app.extra['open']"
Expand Down
41 changes: 0 additions & 41 deletions src/web/src/app/dstore/components/assemble/assemble.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class AssembleComponent implements OnInit, OnDestroy {
categoryList: { [key: string]: Category };

// data
versions = new Map<string, AppVersion>();
jobs: { [key: string]: StoreJobInfo } = {};
jobsNames = new Set<string>();
jobs$: Subscription;
Expand All @@ -65,20 +64,11 @@ export class AssembleComponent implements OnInit, OnDestroy {
this.categoryList = cs;
});
this.jobs$ = this.getJobs();
this.version$ = this.getVersions();
}
ngOnDestroy() {
if (this.jobs$) {
this.jobs$.unsubscribe();
}
if (this.version$) {
this.version$.unsubscribe();
}
}

async filter(apps: SectionApp[]) {
const versionMap = await this.storeService.getVersionMap(apps.map(app => app.name)).toPromise();
return apps.filter(app => versionMap.has(app.name));
}

getJobs() {
Expand All @@ -93,35 +83,4 @@ export class AssembleComponent implements OnInit, OnDestroy {
this.jobs = jobs;
});
}

getVersions() {
const apps = [].concat(
...this.assembleList.map(assemble =>
assemble.apps.filter(app => app.show).map(app => app.name),
),
);
return this.jobService
.jobList()
.pipe(
flatMap(() => {
return this.storeService.getVersion(apps);
}),
)
.subscribe(vs => {
this.loaded.emit(true);
this.versions = new Map(vs.map(v => [v.name, v] as [string, AppVersion]));
});
}

installApp(app: App) {
this.storeService.installPackage(app.name, app.localInfo.description.name).subscribe();
}
updateApp(app: App) {
this.storeService.updatePackage(app.name, app.localInfo.description.name).subscribe();
}

// Show 'open' button only if app open method is 'desktop'.
appOpenable(app: App): boolean {
return app.extra.open === 'desktop';
}
}
64 changes: 31 additions & 33 deletions src/web/src/app/dstore/components/cover/cover.component.html
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
<dstore-title [title]="section.title | fitLanguage" [more]="moreNav">
<dstore-title [title]="section.title | fitLanguage"
[more]="moreNav">
<a href="/"></a>
</dstore-title>
<div class="list">
<div class="list"
*ngIf="apps$|async as $apps">
<ng-container *ngFor="let $index of (section.rowSpan * section.colSpan | range)">
<div
class="item"
[class.client]="isNative"
[class.job]="jobs[$app.name] || jobsNames.has($app.name)"
[routerLink]="['app', $app.name]"
*ngIf="appList[$index] as $app; else: $empty"
>
<div class="item"
[class.client]="isNative"
[class.job]="jobs[$app.name] || jobsNames.has($app.name)"
[routerLink]="['app', $app.name]"
*ngIf="$apps[$index] as $app; else: $empty">
<div class="cover">
<img
[src]="
<img [src]="
server + '/' + ([$app.localInfo.images.cover, $app.localInfo.images.coverHD] | fitImage)
"
/>
" />
</div>
<div class="info">
<div class="appTitle">{{ $app.localInfo.description.name }}</div>
<div>
<span class="subtitle" [routerLink]="['/category', $app.category]">{{
<span class="subtitle"
[routerLink]="['/category', $app.category]">{{
$app.localCategory
}}</span>
<dstore-star class="star" [rate]="$app.rate"></dstore-star>
}}</span>
<dstore-star class="star"
[rate]="$app.rate"></dstore-star>
</div>
</div>
<div class="hover">
<div>
<div class="appTitle">{{ $app.localInfo.description.name }}</div>
<span class="subtitle" [routerLink]="['/category', $app.category]">{{
<span class="subtitle"
[routerLink]="['/category', $app.category]">{{
$app.localCategory
}}</span>
}}</span>
</div>
<div>
<ng-container *ngIf="jobs[$app.name] as job; else: controlBtn">
<dstore-circle-button
[running]="
<dstore-circle-button [running]="
[StoreJobStatus.running, StoreJobStatus.ready, StoreJobStatus.end].includes(
job.status
)
"
[progress]="job.progress"
[disabled]="!job.cancelable"
(runningChange)="$event ? start(job.job) : pause(job.job)"
></dstore-circle-button>
[progress]="job.progress"
[disabled]="!job.cancelable"
(runningChange)="$event ? start(job.job) : pause(job.job)"></dstore-circle-button>
</ng-container>

<ng-template #controlBtn>
<div #ctlBtn>
<dstore-job-button
[version]="$app.version"
[appName]="$app.name"
[localName]="$app.localInfo.description.name"
[openType]="$app.extra['open']"
(start)="ctlBtn.hidden = true"
></dstore-job-button>
<dstore-job-button [version]="$app.version"
[appName]="$app.name"
[localName]="$app.localInfo.description.name"
[openType]="$app.extra['open']"
(start)="ctlBtn.hidden = true"></dstore-job-button>
</div>
<dstore-circle-button [running]="true" *ngIf="ctlBtn.hidden"></dstore-circle-button>
<dstore-circle-button [running]="true"
*ngIf="ctlBtn.hidden"></dstore-circle-button>
</ng-template>
</div>
</div>
Expand All @@ -70,4 +68,4 @@
</div>
</ng-template>
</ng-container>
</div>
</div>
37 changes: 9 additions & 28 deletions src/web/src/app/dstore/components/cover/cover.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class CoverComponent implements OnInit, OnDestroy {
appFilter: AppFilterFunc = Allowed;
// data
moreNav: any[];
appList: App[] = [];
apps$: Observable<App[]>;
jobs: { [key: string]: StoreJobInfo } = {};
jobsNames = new Set<string>();
jobs$: Subscription;
Expand All @@ -57,22 +57,15 @@ export class CoverComponent implements OnInit, OnDestroy {
pause = this.storeService.pauseJob;
openApp = this.storeService.openApp;
ngOnInit() {
this.jobService
.jobList()
.pipe(
flatMap(() =>
this.appService.getApps(this.apps.filter(app => app.show).map(app => app.name)),
),
)
.subscribe(appList => {
this.appList = appList;
this.moreNav = [
'./apps',
{ title: this.section.title, apps: appList.map(app => app.name) },
];
this.loaded.emit(true);
});
this.getJobs();
this.apps$ = this.appService
.getApps(this.apps.filter(app => app.show).map(app => app.name))
.pipe(
tap(apps => {
this.moreNav = ['./apps', { title: this.section.title, apps: apps.map(app => app.name) }];
this.loaded.emit(true);
}),
);
}
getJobs() {
return this.jobService.jobsInfo().subscribe(jobInfos => {
Expand All @@ -91,16 +84,4 @@ export class CoverComponent implements OnInit, OnDestroy {
this.jobs$.unsubscribe();
}
}

installApp(app: App) {
this.storeService.installPackage(app.name, app.localInfo.description.name).subscribe();
}
updateApp(app: App) {
this.storeService.updatePackage(app.name, app.localInfo.description.name).subscribe();
}

// Show 'open' button only if app open method is 'desktop'.
appOpenable(app: App): boolean {
return app.extra.open === 'desktop';
}
}
11 changes: 0 additions & 11 deletions src/web/src/app/dstore/components/icon/icon.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,4 @@ export class IconComponent implements OnInit, OnDestroy {
this.jobs$.unsubscribe();
}
}
installApp(app: App) {
this.storeService.installPackage(app.name, app.localInfo.description.name).subscribe();
}
updateApp(app: App) {
this.storeService.updatePackage(app.name, app.localInfo.description.name).subscribe();
}

// Show 'open' button only if app open method is 'desktop'.
appOpenable(app: App): boolean {
return app.extra.open === 'desktop';
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<dstore-title [title]="section.title | fitLanguage"
[more]="moreNav"></dstore-title>
<div class="list">
<div class="list"
*ngIf="apps$|async as $apps">
<ng-container *ngFor="let $index of (section.colSpan * section.rowSpan | range)">
<div class="item"
[class.job]="jobs[$app.name] || jobsNames.has($app.name)"
[routerLink]="['app', $app.name]"
*ngIf="appList[$index] as $app; else: $empty">
*ngIf="$apps[$index] as $app; else: $empty">
<div><img class="icon"
[src]="$app.icon" /></div>
<div class="info">
Expand Down
36 changes: 7 additions & 29 deletions src/web/src/app/dstore/components/phrase/phrase.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class PhraseComponent implements OnInit, OnDestroy {

// data
moreNav: any[] = [];
appList: App[] = [];
apps$: Observable<App[]>;
jobs: { [key: string]: StoreJobInfo } = {};
jobsNames = new Set<string>();
jobs$: Subscription;
Expand All @@ -60,23 +60,13 @@ export class PhraseComponent implements OnInit, OnDestroy {
openApp = this.storeService.openApp;

ngOnInit() {
this.jobService
.jobList()
.pipe(
flatMap(() => {
return this.appService.getApps(
this.phraseList.filter(app => app.show).map(app => app.name),
);
}),
)
.subscribe(appList => {
this.appList = appList;
this.moreNav = [
'./apps',
{ title: this.section.title, apps: appList.map(app => app.name) },
];
const appNameList = this.phraseList.filter(app => app.show).map(app => app.name);
this.apps$ = this.appService.getApps(appNameList).pipe(
tap(apps => {
this.moreNav = ['./apps', { title: this.section.title, apps: apps.map(app => app.name) }];
this.loaded.emit(true);
});
}),
);
this.getJobs();
}

Expand All @@ -98,16 +88,4 @@ export class PhraseComponent implements OnInit, OnDestroy {
this.jobs$.unsubscribe();
}
}

installApp(app: App) {
this.storeService.installPackage(app.name, app.localInfo.description.name).subscribe();
}
updateApp(app: App) {
this.storeService.updatePackage(app.name, app.localInfo.description.name).subscribe();
}

// Show 'open' button only if app open method is 'desktop'.
appOpenable(app: App): boolean {
return app.extra.open === 'desktop';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[more]="'/ranking'"></dstore-title>

<div class="rankingList"
*ngIf="appList as $apps">
*ngIf="apps$|async as $apps">
<ng-container *ngFor="let $index of (this.section.ranking.count | range)">
<div class="ranking"
[routerLink]="['app', $app.name]"
Expand Down
Loading

0 comments on commit 5564970

Please sign in to comment.