mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-14 21:18:06 +00:00
Installation flow control
This commit is contained in:
@ -41,7 +41,8 @@ async function downloadFile(resource, softwarePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ipcMain.on('installed-software-install', async function (event, software) {
|
ipcMain.on('installed-software-install', async function (event, software) {
|
||||||
const softwarePath = path.join(app.getAppPath(), software.binary);
|
const softwarePath = path.join(app.getPath('temp'), software.binary);
|
||||||
|
const responseChannel = `installed-software-installed-${software.name}`;
|
||||||
|
|
||||||
if (software.type == 'web') {
|
if (software.type == 'web') {
|
||||||
const exists = fs.existsSync(softwarePath);
|
const exists = fs.existsSync(softwarePath);
|
||||||
@ -53,7 +54,7 @@ ipcMain.on('installed-software-install', async function (event, software) {
|
|||||||
try {
|
try {
|
||||||
await downloadFile(software.resource, softwarePath);
|
await downloadFile(software.resource, softwarePath);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
event.sender.send('installed-software-installed', {
|
event.sender.send(responseChannel, {
|
||||||
success: false,
|
success: false,
|
||||||
message: error.message
|
message: error.message
|
||||||
});
|
});
|
||||||
@ -82,7 +83,7 @@ ipcMain.on('installed-software-install', async function (event, software) {
|
|||||||
|
|
||||||
child.stdin.end();
|
child.stdin.end();
|
||||||
|
|
||||||
event.sender.send('installed-software-installed', {
|
event.sender.send(responseChannel, {
|
||||||
success: true
|
success: true
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -86,6 +86,7 @@ import { InterfaceLabelDraggedComponent } from './components/drawings-listeners/
|
|||||||
import { ToolsService } from './services/tools.service';
|
import { ToolsService } from './services/tools.service';
|
||||||
import { TextAddedComponent } from './components/drawings-listeners/text-added/text-added.component';
|
import { TextAddedComponent } from './components/drawings-listeners/text-added/text-added.component';
|
||||||
import { DrawingAddedComponent } from './components/drawings-listeners/drawing-added/drawing-added.component';
|
import { DrawingAddedComponent } from './components/drawings-listeners/drawing-added/drawing-added.component';
|
||||||
|
import { InstallSoftwareComponent } from './components/installed-software/install-software/install-software.component';
|
||||||
|
|
||||||
|
|
||||||
if (environment.production) {
|
if (environment.production) {
|
||||||
@ -138,7 +139,8 @@ if (environment.production) {
|
|||||||
NodeLabelDraggedComponent,
|
NodeLabelDraggedComponent,
|
||||||
DrawingDraggedComponent,
|
DrawingDraggedComponent,
|
||||||
LinkCreatedComponent,
|
LinkCreatedComponent,
|
||||||
InterfaceLabelDraggedComponent
|
InterfaceLabelDraggedComponent,
|
||||||
|
InstallSoftwareComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
<button mat-button color="primary" (click)="install()" [disabled]="disabled">
|
||||||
|
<ng-container *ngIf="readyToInstall">{{ buttonText }}</ng-container>
|
||||||
|
</button>
|
@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { InstallSoftwareComponent } from './install-software.component';
|
||||||
|
|
||||||
|
describe('InstallSoftwareComponent', () => {
|
||||||
|
let component: InstallSoftwareComponent;
|
||||||
|
let fixture: ComponentFixture<InstallSoftwareComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ InstallSoftwareComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(InstallSoftwareComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,57 @@
|
|||||||
|
import { Component, OnInit, Output, EventEmitter, Input, OnDestroy } from '@angular/core';
|
||||||
|
import { ElectronService } from 'ngx-electron';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-install-software',
|
||||||
|
templateUrl: './install-software.component.html',
|
||||||
|
styleUrls: ['./install-software.component.scss']
|
||||||
|
})
|
||||||
|
export class InstallSoftwareComponent implements OnInit, OnDestroy {
|
||||||
|
@Input('software')
|
||||||
|
software: any;
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
installedChanged = new EventEmitter();
|
||||||
|
|
||||||
|
public disabled = false;
|
||||||
|
public readyToInstall = true;
|
||||||
|
public buttonText: string;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private electronService: ElectronService
|
||||||
|
) { }
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.electronService.ipcRenderer.on(this.responseChannel, (event, data) => {
|
||||||
|
this.updateButton();
|
||||||
|
this.installedChanged.emit(data);
|
||||||
|
});
|
||||||
|
this.updateButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.electronService.ipcRenderer.removeAllListeners(this.responseChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
install() {
|
||||||
|
this.disabled = true;
|
||||||
|
this.buttonText = "Installing";
|
||||||
|
this.electronService.ipcRenderer.send('installed-software-install', this.software);
|
||||||
|
}
|
||||||
|
|
||||||
|
private get responseChannel() {
|
||||||
|
return `installed-software-installed-${this.software.name}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateButton() {
|
||||||
|
this.disabled = this.software.installed;
|
||||||
|
|
||||||
|
if (this.software.installed) {
|
||||||
|
this.buttonText = "Installed";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.buttonText = "Install";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,10 +14,12 @@
|
|||||||
<ng-container matColumnDef="actions">
|
<ng-container matColumnDef="actions">
|
||||||
<mat-header-cell *matHeaderCellDef></mat-header-cell>
|
<mat-header-cell *matHeaderCellDef></mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row;" style="text-align: right">
|
<mat-cell *matCellDef="let row;" style="text-align: right">
|
||||||
<button mat-button color="primary" (click)="install(row)" [disabled]="row.installed">
|
<app-install-software [software]="row" (installedChanged)="onInstalled($event)"></app-install-software>
|
||||||
|
|
||||||
|
<!-- <button *ngIf="row.installed" mat-button color="primary" (click)="install(row)" [disabled]="row.installed">
|
||||||
<ng-container *ngIf="row.installed">Installed</ng-container>
|
<ng-container *ngIf="row.installed">Installed</ng-container>
|
||||||
<ng-container *ngIf="!row.installed">Install</ng-container>
|
<ng-container *ngIf="!row.installed">Install</ng-container>
|
||||||
</button>
|
</button> -->
|
||||||
</mat-cell>
|
</mat-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { InstalledSoftwareService } from '../../services/installed-software.service';
|
import { InstalledSoftwareService } from '../../services/installed-software.service';
|
||||||
import { DataSource } from '@angular/cdk/table';
|
import { DataSource } from '@angular/cdk/table';
|
||||||
import { Observable, of } from 'rxjs';
|
import { Observable, of, BehaviorSubject } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-installed-software',
|
selector: 'app-installed-software',
|
||||||
@ -20,21 +20,27 @@ export class InstalledSoftwareComponent implements OnInit {
|
|||||||
this.dataSource = new InstalledSoftwareDataSource(this.installedSoftwareService);
|
this.dataSource = new InstalledSoftwareDataSource(this.installedSoftwareService);
|
||||||
}
|
}
|
||||||
|
|
||||||
install(software) {
|
onInstalled(event) {
|
||||||
this.installedSoftwareService.install(software);
|
this.dataSource.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class InstalledSoftwareDataSource extends DataSource<any> {
|
export class InstalledSoftwareDataSource extends DataSource<any> {
|
||||||
|
installed = new BehaviorSubject([]);
|
||||||
|
|
||||||
constructor(private installedSoftwareService: InstalledSoftwareService) {
|
constructor(private installedSoftwareService: InstalledSoftwareService) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(): Observable<any[]> {
|
connect(): Observable<any[]> {
|
||||||
const installed = this.installedSoftwareService.list();
|
this.refresh();
|
||||||
return of(installed);
|
return this.installed;
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {}
|
disconnect() {}
|
||||||
|
|
||||||
|
refresh() {
|
||||||
|
this.installed.next(this.installedSoftwareService.list());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,7 @@ export class InstalledSoftwareService {
|
|||||||
constructor(
|
constructor(
|
||||||
private electronService: ElectronService
|
private electronService: ElectronService
|
||||||
) {
|
) {
|
||||||
this.electronService.ipcRenderer.on('installed-software-installed', (event, data) => {
|
}
|
||||||
console.log("installed", data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
list() {
|
list() {
|
||||||
const installedSoftware = this.electronService.remote.require('./installed-software.js')
|
const installedSoftware = this.electronService.remote.require('./installed-software.js')
|
||||||
@ -47,7 +44,4 @@ export class InstalledSoftwareService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
install(software) {
|
|
||||||
this.electronService.ipcRenderer.send('installed-software-install', software);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user