marketplace updates

This commit is contained in:
Drew Ansbacher
2021-07-16 12:46:27 -06:00
committed by Aiden McClelland
parent 301a19d644
commit 203eff7758
14 changed files with 164 additions and 99 deletions

View File

@@ -8,10 +8,10 @@
</ion-header>
<ion-content>
<ion-spinner *ngIf="!marketplaceService.pkgs[pkgId]; else loaded" class="center" name="lines" color="warning"></ion-spinner>
<ion-spinner *ngIf="!marketplaceService.releaseNotes[pkgId]; else loaded" class="center" name="lines" color="warning"></ion-spinner>
<ng-template #loaded>
<div *ngFor="let note of marketplaceService.pkgs[pkgId]['release-notes'] | keyvalue : asIsOrder">
<div *ngFor="let note of marketplaceService.releaseNotes[pkgId] | keyvalue : asIsOrder">
<ion-button (click)="setSelected(note.key)" expand="full" color="light" style="height: 50px;" >
<p style="position: absolute; left: 10px;">{{ note.key | displayEmver }}</p>
</ion-button>

View File

@@ -20,9 +20,8 @@ export class AppReleaseNotes {
ngOnInit () {
this.pkgId = this.route.snapshot.paramMap.get('pkgId')
const version = this.route.snapshot.paramMap.get('version')
if (!this.marketplaceService.pkgs[this.pkgId]?.['release-notes']) {
this.marketplaceService.getPkg(this.pkgId, version)
if (!this.marketplaceService.releaseNotes[this.pkgId]) {
this.marketplaceService.getReleaseNotes(this.pkgId)
}
}

View File

@@ -20,7 +20,7 @@ export class MarketplaceListPage {
pageLoading = true
pkgsLoading = true
category = 'all'
category = 'featured'
query: string
data: MarketplaceData
@@ -47,15 +47,19 @@ export class MarketplaceListPage {
async ngOnInit () {
try {
const [data, eos, pkgs] = await Promise.all([
const [data, eos] = await Promise.all([
this.marketplaceApiService.getMarketplaceData({ }),
this.marketplaceApiService.getEos({ }),
this.getPkgs(),
])
this.data = data
this.data.categories.unshift(this.category)
this.data.categories.push(this.category)
this.data.categories.unshift('updates')
if (data.categories.includes(this.category)) {
data.categories = data.categories.filter(cat => this.category !== cat)
}
data.categories.unshift(this.category)
this.eos = eos
this.pkgs = pkgs
} catch (e) {
console.error(e)
this.errToast.present(e.message)
@@ -74,8 +78,7 @@ export class MarketplaceListPage {
}
async doInfinite (e: any): Promise<void> {
const pkgs = await this.getPkgs()
this.pkgs = this.pkgs.concat(pkgs)
await this.getPkgs(true)
e.target.complete()
}
@@ -83,7 +86,7 @@ export class MarketplaceListPage {
this.query = e.target.value || undefined
this.page = 1
this.pkgsLoading = true
this.pkgs = await this.getPkgs()
await this.getPkgs()
}
async updateEos (): Promise<void> {
@@ -97,17 +100,26 @@ export class MarketplaceListPage {
)
}
private async getPkgs (): Promise<MarketplacePkg[]> {
private async getPkgs (doInfinite = false): Promise<void> {
try {
const pkgs = await this.marketplaceService.getPkgs(
this.category !== 'all' ? this.category : undefined,
this.query,
this.page,
this.perPage,
)
this.needInfinite = pkgs.length >= this.perPage
this.page++
return pkgs
if (this.category === 'updates') {
this.pkgs = this.marketplaceService.updates
if (this.pkgs.length) {
this.pkgsLoading = false
}
await this.marketplaceService.getUpdates(this.patch.data['package-data'])
this.pkgs = this.marketplaceService.updates
} else {
const pkgs = await this.marketplaceService.getPkgs(
this.category !== 'all' ? this.category : undefined,
this.query,
this.page,
this.perPage,
)
this.needInfinite = pkgs.length >= this.perPage
this.page++
this.pkgs = doInfinite ? this.pkgs.concat(pkgs) : pkgs
}
} catch (e) {
console.error(e)
this.errToast.present(e.message)
@@ -117,9 +129,10 @@ export class MarketplaceListPage {
}
async switchCategory (category: string): Promise<void> {
this.pkgs = []
this.category = category
this.pkgsLoading = true
this.page = 1
this.pkgs = await this.getPkgs()
await this.getPkgs()
}
}

View File

@@ -1,20 +1,41 @@
import { Injectable } from '@angular/core'
import { MarketplacePkg } from 'src/app/services/api/api.types'
import { MarketplaceApiService } from 'src/app/services/api/marketplace/marketplace-api.service'
import { Emver } from 'src/app/services/emver.service'
import { PackageDataEntry } from 'src/app/services/patch-db/data-model'
@Injectable({
providedIn: 'root',
})
export class MarketplaceService {
pkgs: { [id: string]: MarketplacePkg } = { }
updates: MarketplacePkg[] = null
releaseNotes: { [id: string]: {
[version: string]: string
} }
constructor (
private readonly marketplaceApiService: MarketplaceApiService,
private readonly emver: Emver,
) { }
async getUpdates (pkgData: { [id: string]: PackageDataEntry}) : Promise<MarketplacePkg[]> {
const idAndCurrentVersions = Object.keys(pkgData).map(key => ({ id: key, version: pkgData[key].manifest.version }))
console.log(JSON.stringify(idAndCurrentVersions))
const latestPkgs = (await this.marketplaceApiService.getMarketplacePkgs({
ids: idAndCurrentVersions,
}))
const updates = latestPkgs.filter(latestPkg => {
const latestVersion = latestPkg.manifest.version
const curVersion = pkgData[latestPkg.manifest.id]?.manifest.version
return !!curVersion && this.emver.compare(latestVersion, curVersion) === 1
})
this.updates = updates
return updates
}
async getPkgs (category: string, query: string, page: number, perPage: number) : Promise<MarketplacePkg[]> {
const pkgs = await this.marketplaceApiService.getMarketplacePkgs({
category: category !== 'all' ? category : undefined,
@@ -30,7 +51,7 @@ export class MarketplaceService {
}
async getPkg (id: string, version?: string): Promise<void> {
const pkg = (await this.marketplaceApiService.getMarketplacePkgs({ id, version }))[0]
const pkg = (await this.marketplaceApiService.getMarketplacePkgs({ ids: [{ id, version }]}))[0]
if (pkg) {
this.pkgs[id] = pkg
} else {

View File

@@ -15,20 +15,20 @@
<ion-label>Use Tor</ion-label>
<ion-note slot="end">{{ patch.data['server-info']['eos-marketplace'] === config.start9Marketplace.tor }}</ion-note>
</ion-item>
<ion-item button (click)="presentModalValueEdit('packageMarketplace', patch.data['server-info']['package-marketplace'])">
<!-- <ion-item button (click)="presentModalValueEdit('packageMarketplace', patch.data['server-info']['package-marketplace'])">
<ion-label>Package Marketplace</ion-label>
<ion-note slot="end">{{ patch.data['server-info']['package-marketplace'] }}</ion-note>
</ion-item>
</ion-item> -->
<ion-item button (click)="presentModalValueEdit('autoCheckUpdates', patch.data.ui['auto-check-updates'])">
<ion-label>Auto Check for Updates</ion-label>
<ion-note slot="end">{{ patch.data.ui['auto-check-updates'] }}</ion-note>
</ion-item>
<ion-item-divider></ion-item-divider>
<!-- <ion-item-divider></ion-item-divider>
<ion-item button (click)="presentModalValueEdit('password')">
<ion-label>Change Password</ion-label>
<ion-note slot="end">********</ion-note>
</ion-item>
</ion-item> -->
</ion-item-group>
</ion-content>