Skip to content

Commit

Permalink
feat(plugin-store): Get rid of the button
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Aug 27, 2023
1 parent f627254 commit 4f839af
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@
.metadata-item {
flex-basis: 50%;
}

.highlight-link {
color: #007BFF;
text-decoration: underline;
cursor: pointer;
transition: color 0.3s;
}

.highlight-link:hover {
color: #0056b3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,20 @@ <h2 id="title">Plugin information</h2>
</div>
</form>
</mat-card>
<h2 id="title">Plugin template preview</h2>
<mat-card>
<div class="flex-space-between">
<span> Currently used template: </span>
<button
mat-raised-button
color="primary"
id="reload"
(click)="refreshPluginContent()"
>
<mat-icon>refresh</mat-icon> Reload from remote
</button>
</div>
<div id="fetched-result">
<pre>{{
this.peekContent ||
prettifyYAML((pluginStoreService.plugin | async)?.content)
}}</pre>
<pre *ngIf="!shouldShowLink(this.peekContent)">{{ this.peekContent }}</pre>
<div *ngIf="shouldShowLink(this.peekContent)">
Invalid YAML. Check your provided URL, it should link to raw content of a
YAML template.
<a
href="https://raw.githubusercontent.com/DSD-DBS/capella-collab-manager/plugins-store/backend/tests/data/mbse-works-plugin.yml"
target="_blank"
rel="noopener noreferrer"
class="highlight-link"
>This is an example.</a
>
</div>
</div>
</mat-card>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy';
import { ToastService } from 'src/app/helpers/toast/toast.service';
import { filter } from 'rxjs';
import { filter, debounceTime } from 'rxjs';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { Plugin, PluginStoreService } from '../service/plugin-store.service';
import * as yaml from 'js-yaml';
Expand Down Expand Up @@ -37,6 +37,14 @@ export class PluginDetailsComponent {
this.plugin = plugin;
this.editPluginForm.patchValue(plugin);
});
this.editPluginForm.controls['remote'].valueChanges
.pipe(
debounceTime(500),
untilDestroyed(this)
)
.subscribe(() => {
this.refreshPluginContent();
});
}

editPluginForm = new FormGroup({
Expand Down Expand Up @@ -66,13 +74,15 @@ export class PluginDetailsComponent {
}

prettifyYAML(content: any): string {
try {
return yaml.dump(content);
} catch (error) {
console.error('Failed to convert content to YAML:', content);
return '';
if (content == undefined) {
return 'Invalid YAML. Check your provided URL, it should link to raw content of a YAML template. This is an example.';
}
}
return yaml.dump(content);
}

shouldShowLink(content: string): boolean {
return content ? content.includes('This is an example.') : false;
}

deletePlugin(): void {
if (
Expand Down

0 comments on commit 4f839af

Please sign in to comment.