From 77a47e8fd2dc4f991b77f599ae76d046dd33d0b6 Mon Sep 17 00:00:00 2001
From: ziajka <dominik@gns3.net>
Date: Wed, 9 Jan 2019 10:20:17 +0100
Subject: [PATCH] Installed software link in application menu when in electron

---
 src/app/app-routing.module.ts                 |  2 +
 src/app/app.module.ts                         |  4 +-
 .../installed-software.component.html         | 48 +++++++++++++++++++
 .../installed-software.component.scss         |  0
 .../installed-software.component.spec.ts      | 25 ++++++++++
 .../installed-software.component.ts           | 15 ++++++
 .../settings/settings.component.html          |  1 +
 .../default-layout.component.html             | 19 ++++++--
 .../default-layout.component.ts               |  7 ++-
 .../installed-software.service.spec.ts        | 12 +++++
 .../services/installed-software.service.ts    |  9 ++++
 11 files changed, 137 insertions(+), 5 deletions(-)
 create mode 100644 src/app/components/installed-software/installed-software.component.html
 create mode 100644 src/app/components/installed-software/installed-software.component.scss
 create mode 100644 src/app/components/installed-software/installed-software.component.spec.ts
 create mode 100644 src/app/components/installed-software/installed-software.component.ts
 create mode 100644 src/app/services/installed-software.service.spec.ts
 create mode 100644 src/app/services/installed-software.service.ts

diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts
index f1c33bd2..2ba47f18 100644
--- a/src/app/app-routing.module.ts
+++ b/src/app/app-routing.module.ts
@@ -7,6 +7,7 @@ import { ProjectsComponent } from "./components/projects/projects.component";
 import { DefaultLayoutComponent } from "./layouts/default-layout/default-layout.component";
 import { SettingsComponent } from "./components/settings/settings.component";
 import { LocalServerComponent } from "./components/local-server/local-server.component";
+import { InstalledSoftwareComponent } from './components/installed-software/installed-software.component';
 
 
 const routes: Routes = [
@@ -17,6 +18,7 @@ const routes: Routes = [
       { path: 'local', component: LocalServerComponent },
       { path: 'server/:server_id/projects', component: ProjectsComponent },
       { path: 'settings', component: SettingsComponent },
+      { path: 'installed-software', component: InstalledSoftwareComponent },
     ]
   },
   { path: 'server/:server_id/project/:project_id', component: ProjectMapComponent },
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 800cf781..5bae2cad 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -74,6 +74,7 @@ import { ProjectNameValidator } from './components/projects/models/projectNameVa
 import { MatSidenavModule } from '@angular/material';
 import { NodeSelectInterfaceComponent } from './components/project-map/node-select-interface/node-select-interface.component';
 import { DrawLinkToolComponent } from './components/project-map/draw-link-tool/draw-link-tool.component';
+import { InstalledSoftwareComponent } from './components/installed-software/installed-software.component';
 
 
 if (environment.production) {
@@ -116,7 +117,8 @@ if (environment.production) {
     ProgressComponent,
     ServerDiscoveryComponent,
     NodeSelectInterfaceComponent,
-    DrawLinkToolComponent
+    DrawLinkToolComponent,
+    InstalledSoftwareComponent
   ],
   imports: [
     BrowserModule,
diff --git a/src/app/components/installed-software/installed-software.component.html b/src/app/components/installed-software/installed-software.component.html
new file mode 100644
index 00000000..3413213a
--- /dev/null
+++ b/src/app/components/installed-software/installed-software.component.html
@@ -0,0 +1,48 @@
+<div class="content">
+    <div class="default-header">
+      <h1>Installed software</h1>
+    </div>
+    <div class="default-content">
+      <!-- <div class="example-container mat-elevation-z8">
+        <mat-table #table [dataSource]="dataSource">
+  
+          <ng-container matColumnDef="id">
+            <mat-header-cell *matHeaderCellDef> ID </mat-header-cell>
+            <mat-cell *matCellDef="let row;"> {{row.id}} </mat-cell>
+          </ng-container>
+  
+          <ng-container matColumnDef="name">
+            <mat-header-cell *matHeaderCellDef> Name </mat-header-cell>
+            <mat-cell *matCellDef="let row;"> <a [routerLink]="['/server', row.id, 'projects']" class="table-link">{{row.name}}</a></mat-cell>
+          </ng-container>
+  
+          <ng-container matColumnDef="ip">
+            <mat-header-cell *matHeaderCellDef> IP </mat-header-cell>
+            <mat-cell *matCellDef="let row;"> {{row.ip}} </mat-cell>
+          </ng-container>
+  
+          <ng-container matColumnDef="port">
+            <mat-header-cell *matHeaderCellDef> Port </mat-header-cell>
+            <mat-cell *matCellDef="let row;"> {{row.port}} </mat-cell>
+          </ng-container>
+  
+          <ng-container matColumnDef="actions">
+            <mat-header-cell *matHeaderCellDef> Actions </mat-header-cell>
+            <mat-cell *matCellDef="let row;" style="text-align: right">
+              <button mat-icon-button (click)="deleteServer(row)">
+                <mat-icon aria-label="Remove server">delete</mat-icon>
+              </button>
+            </mat-cell>
+          </ng-container>
+  
+          <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
+          <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
+        </mat-table>
+      </div>
+  
+      <div class="buttons-bar">
+        <button mat-raised-button color="primary" (click)="createModal()">Add server</button>
+      </div> -->
+    </div>
+  </div>
+  
\ No newline at end of file
diff --git a/src/app/components/installed-software/installed-software.component.scss b/src/app/components/installed-software/installed-software.component.scss
new file mode 100644
index 00000000..e69de29b
diff --git a/src/app/components/installed-software/installed-software.component.spec.ts b/src/app/components/installed-software/installed-software.component.spec.ts
new file mode 100644
index 00000000..488584ab
--- /dev/null
+++ b/src/app/components/installed-software/installed-software.component.spec.ts
@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { InstalledSoftwareComponent } from './installed-software.component';
+
+describe('InstalledSoftwareComponent', () => {
+  let component: InstalledSoftwareComponent;
+  let fixture: ComponentFixture<InstalledSoftwareComponent>;
+
+  beforeEach(async(() => {
+    TestBed.configureTestingModule({
+      declarations: [ InstalledSoftwareComponent ]
+    })
+    .compileComponents();
+  }));
+
+  beforeEach(() => {
+    fixture = TestBed.createComponent(InstalledSoftwareComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  });
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});
diff --git a/src/app/components/installed-software/installed-software.component.ts b/src/app/components/installed-software/installed-software.component.ts
new file mode 100644
index 00000000..a20d70b2
--- /dev/null
+++ b/src/app/components/installed-software/installed-software.component.ts
@@ -0,0 +1,15 @@
+import { Component, OnInit } from '@angular/core';
+
+@Component({
+  selector: 'app-installed-software',
+  templateUrl: './installed-software.component.html',
+  styleUrls: ['./installed-software.component.scss']
+})
+export class InstalledSoftwareComponent implements OnInit {
+
+  constructor() { }
+
+  ngOnInit() {
+  }
+
+}
diff --git a/src/app/components/settings/settings.component.html b/src/app/components/settings/settings.component.html
index 3852a97a..43f08e88 100644
--- a/src/app/components/settings/settings.component.html
+++ b/src/app/components/settings/settings.component.html
@@ -35,4 +35,5 @@
       <button mat-raised-button color="primary" (click)="save()">Save settings</button>
     </div>
   </div>
+
 </div>
diff --git a/src/app/layouts/default-layout/default-layout.component.html b/src/app/layouts/default-layout/default-layout.component.html
index 0ffd7b58..302e5e5a 100644
--- a/src/app/layouts/default-layout/default-layout.component.html
+++ b/src/app/layouts/default-layout/default-layout.component.html
@@ -8,9 +8,22 @@
 
     <span class="fill-space"></span>
 
-    <button mat-button routerLink="/settings" >
-      <mat-icon>settings</mat-icon>
+    <button mat-button [matMenuTriggerFor]="menu" >
+      <mat-icon>more_vert</mat-icon>
     </button>
+
+    <mat-menu #menu="matMenu">
+      <button mat-menu-item routerLink="/settings">
+        <mat-icon>settings</mat-icon>
+        <span>Settings</span>
+      </button>
+      <button mat-menu-item routerLink="/installed-software" [disabled]="!isInstalledSoftwareAvailable">
+        <mat-icon>cloud_download</mat-icon>
+        <span>Installed software</span>
+      </button>
+    </mat-menu>
+
+
   </mat-toolbar>
 </header>
 
@@ -21,6 +34,6 @@
 <app-progress></app-progress>
 
 <footer class="footer mat-app-background">
-  GNS3 Web UI demo &copy; 2018
+  GNS3 Web UI &copy; 2019
 </footer>
 
diff --git a/src/app/layouts/default-layout/default-layout.component.ts b/src/app/layouts/default-layout/default-layout.component.ts
index ed7bcf4f..f829afc2 100644
--- a/src/app/layouts/default-layout/default-layout.component.ts
+++ b/src/app/layouts/default-layout/default-layout.component.ts
@@ -1,4 +1,5 @@
 import {Component, OnInit, ViewEncapsulation} from '@angular/core';
+import { ElectronService } from 'ngx-electron';
 
 @Component({
   selector: 'app-default-layout',
@@ -7,10 +8,14 @@ import {Component, OnInit, ViewEncapsulation} from '@angular/core';
   styleUrls: ['./default-layout.component.css']
 })
 export class DefaultLayoutComponent implements OnInit {
+  public isInstalledSoftwareAvailable = false;
 
-  constructor() { }
+  constructor(
+    private electronService: ElectronService
+  ) { }
 
   ngOnInit() {
+    this.isInstalledSoftwareAvailable = this.electronService.isElectronApp;
   }
 
 }
diff --git a/src/app/services/installed-software.service.spec.ts b/src/app/services/installed-software.service.spec.ts
new file mode 100644
index 00000000..13eee14f
--- /dev/null
+++ b/src/app/services/installed-software.service.spec.ts
@@ -0,0 +1,12 @@
+import { TestBed } from '@angular/core/testing';
+
+import { InstalledSoftwareService } from './installed-software.service';
+
+describe('InstalledSoftwareService', () => {
+  beforeEach(() => TestBed.configureTestingModule({}));
+
+  it('should be created', () => {
+    const service: InstalledSoftwareService = TestBed.get(InstalledSoftwareService);
+    expect(service).toBeTruthy();
+  });
+});
diff --git a/src/app/services/installed-software.service.ts b/src/app/services/installed-software.service.ts
new file mode 100644
index 00000000..29cba3fc
--- /dev/null
+++ b/src/app/services/installed-software.service.ts
@@ -0,0 +1,9 @@
+import { Injectable } from '@angular/core';
+
+@Injectable({
+  providedIn: 'root'
+})
+export class InstalledSoftwareService {
+
+  constructor() { }
+}