8000 Fix issue with plugin's log updating by DmitryAstafyev · Pull Request #2298 · esrlabs/chipmunk · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix issue with plugin's log updating #2298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions application/client/src/app/ui/tabs/plugins/details/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,32 @@ export class Details extends ChangesDetector implements AfterViewInit, AfterCont
}
public readme: SafeHtml = '';
public logs: ParsedLogMessage[] = [];
public loading: boolean = false;
public loading: {
readme: boolean;
logs: boolean;
} = {
readme: false,
logs: false,
};
public tab: Tab = Tab.ReadMe;
public stats: {
errors: number;
warns: number;
} = {
errors: 0,
warns: 0,
};

protected async load(): Promise<void> {
protected async fetchReadMe(): Promise<void> {
const drop = () => {
this.loading = false;
this.loading.readme = false;
this.readme = '';
this.detectChanges();
};
this.loading = true;
if (this.loading.readme) {
return;
}
this.loading.readme = true;
this.links().unbind();
this.detectChanges();
if (!this.plugin.path) {
Expand All @@ -83,7 +99,7 @@ export class Details extends ChangesDetector implements AfterViewInit, AfterCont
this.readme = '';
})
.finally(() => {
this.loading = false;
this.loading.readme = false;
this.detectChanges();
});
} else {
Expand All @@ -92,14 +108,21 @@ export class Details extends ChangesDetector implements AfterViewInit, AfterCont
}

protected fetchRunData() {
this.loading = true;
if (this.loading.logs) {
return;
}
this.loading.logs = true;
this.logs = [];
this.detectChanges();
this.provider
.getRunData(this.plugin.getPath())
.then((rd: PluginRunData | undefined) => {
if (rd !== undefined) {
this.stats.errors = 0;
this.stats.warns = 0;
this.logs = rd.logs.map((log) => {
this.stats.errors += log.level === 'Err' ? 1 : 0;
this.stats.warns += log.level === 'Warn' ? 1 : 0;
return {
msg: log.msg,
level: log.level,
Expand All @@ -112,7 +135,7 @@ export class Details extends ChangesDetector implements AfterViewInit, AfterCont
this.log().error(`Fail fetch run data: ${err.message}`);
})
.finally(() => {
this.loading = false;
this.loading.logs = false;
this.detectChanges();
});
}
Expand Down Expand Up @@ -150,15 +173,18 @@ export class Details extends ChangesDetector implements AfterViewInit, AfterCont
}

protected safeLoad(): void {
this.load()
this.fetchReadMe()
.catch((err: Error) => {
this.log().error(`Fail to load plugin's details: ${err.message}`);
})
.finally(() => {
if (!this.plugin.isValid()) {
this.goto().inspect();
} else {
this.goto().readme();
}
});
this.fetchRunData();
}

protected redirect(event: MouseEvent): void {
Expand Down Expand Up @@ -186,6 +212,10 @@ export class Details extends ChangesDetector implements AfterViewInit, AfterCont
this.links().unbind();
}

public isLoading(): boolean {
return this.loading.logs || this.loading.readme;
}

public goto(): { readme(): void; inspect(): void } {
return {
readme: (): void => {
Expand Down
15 changes: 15 additions & 0 deletions application/client/src/app/ui/tabs/plugins/details/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@
background-color: @scheme-color-accent;
}
}
& button {
& span.stats {
position: relative;
display: inline-block;
font-size: 12px;
line-height: 0px;
margin: -8px 0 0 6px;
&.err {
color: @scheme-color-error;
}
&.warns {
color: @scheme-color-warning;
}
}
}
& button[disabled] {
&:hover {
background: none;
Expand Down
12 changes: 10 additions & 2 deletions application/client/src/app/ui/tabs/plugins/details/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,29 @@
(click)="goto().inspect()"
>
Inspect
<span
*ngIf="stats.errors + stats.warns > 0"
[attr.class]="'stats ' + (stats.errors > 0 ? 'err' : 'warns')"
>({{stats.errors + stats.warns}})</span
>
</button>
<button
class="flat-codicon-button"
[disabled]="loading || provider.isBusy()"
[disabled]="isLoading() || provider.isBusy()"
(click)="removePlugin()"
>
Remove
</button>
</div>
<div class="readme">
<ng-container *ngIf="loading">
<ng-container *ngIf="isLoading()">
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</ng-container>
<ng-container *ngIf="tab == Tab.ReadMe">
<div #content class="markdown" [innerHTML]="readme"></div>
<p class="t-normal color-scheme-2" *ngIf="(readme === '')">
Seems this plugins doesn't have yet any kind of description.
</p>
</ng-container>
<ng-container *ngIf="tab == Tab.Inspecting">
<ul class="logs">
Expand Down
17 changes: 9 additions & 8 deletions application/client/src/app/ui/tabs/plugins/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export class Provider {
public subjects: Subjects<{
load: Subject<void>;
state: Subject<void>;
selected: Subject<string>;
selected: Subject<string | undefined>;
// true - add starting; false - finished
add: Subject<boolean>;
// true - add starting; false - finished
remove: Subject<boolean>;
}> = new Subjects({
load: new Subject<void>(),
state: new Subject<void>(),
selected: new Subject<string>(),
selected: new Subject<string | undefined>(),
add: new Subject<boolean>(),
remove: new Subject<boolean>(),
});
Expand All @@ -55,6 +55,7 @@ export class Provider {
if (this.state.loading) {
return Promise.resolve();
}
this.select(undefined);
this.state.loading = true;
if (reload) {
await plugins
Expand Down Expand Up @@ -128,12 +129,12 @@ export class Provider {
public getRunData(path: string): Promise<PluginRunData | undefined> {
return plugins.getPluginRunData(path);
}
public select(path: string) {
this.selected = [
...this.plugins.installed,
...this.plugins.available,
...this.plugins.invalid,
].find((pl) => pl.entity.dir_path === path);
public select(path: string | undefined) {
this.selected = !path
? undefined
: [...this.plugins.installed, ...this.plugins.available, ...this.plugins.invalid].find(
(pl) => pl.entity.dir_path === path,
);
this.subjects.get().selected.emit(path);
}
public addPlugin(pluginPath: string): Promise<void> {
Expand Down
6 changes: 1 addition & 5 deletions application/client/src/app/ui/tabs/plugins/template.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<div class="preset-container">
<div class="preset-container-content">
<div class="left">
<mat-card class="fill sticky">
<ng-container *ngIf="!provider.selected ">
<p class="t-normal color-scheme-2">Select plugin to see details</p>
</ng-container>
<mat-card class="fill sticky" *ngIf="provider.selected">
<app-plugins-manager-details
*ngIf="provider.selected "
[plugin]="provider.selected"
[provider]="provider"
></app-plugins-manager-details>
Expand Down
Loading
0