Storing server id for recently opened project list

This commit is contained in:
piotrpekala7 2021-02-26 23:02:49 +01:00
parent d45947999d
commit 1b0c62c0d1
4 changed files with 24 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import { ConfirmationBottomSheetComponent } from './confirmation-bottomsheet/con
import { ToasterService } from '../../services/toaster.service';
import { ConfigureGns3VMDialogComponent } from '../servers/configure-gns3vm-dialog/configure-gns3vm-dialog.component';
import { ElectronService } from 'ngx-electron';
import { RecentlyOpenedProjectService } from '../../services/recentlyOpenedProject.service';
@Component({
selector: 'app-projects',
@ -50,12 +51,14 @@ export class ProjectsComponent implements OnInit {
private router: Router,
private bottomSheet: MatBottomSheet,
private toasterService: ToasterService,
private electronService: ElectronService
private electronService: ElectronService,
private recentlyOpenedProjectService: RecentlyOpenedProjectService
) {}
ngOnInit() {
this.server = this.route.snapshot.data['server'];
if(!this.server) this.router.navigate(['/servers']);
this.recentlyOpenedProjectService.setServerIdProjectList(this.server.id.toString());
this.refresh();
this.sort.sort(<MatSortable>{

View File

@ -4,6 +4,8 @@
<button mat-button routerLink="/servers">Servers</button>
<button *ngIf="!recentlyOpenedProjectId && serverIdProjectList" mat-button (click)="listProjects()">Projects</button>
<button *ngIf="recentlyOpenedProjectId && recentlyOpenedServerId" mat-button (click)="backToProject()">Back to project</button>
<span class="fill-space"></span>

View File

@ -24,6 +24,7 @@ export class DefaultLayoutComponent implements OnInit, OnDestroy {
recentlyOpenedServerId : string;
recentlyOpenedProjectId : string;
serverIdProjectList: string;
constructor(
private electronService: ElectronService,
@ -37,6 +38,7 @@ export class DefaultLayoutComponent implements OnInit, OnDestroy {
ngOnInit() {
this.recentlyOpenedServerId = this.recentlyOpenedProjectService.getServerId();
this.recentlyOpenedProjectId = this.recentlyOpenedProjectService.getProjectId();
this.serverIdProjectList = this.recentlyOpenedProjectService.getServerIdProjectList();
this.isInstalledSoftwareAvailable = this.electronService.isElectronApp;
@ -56,6 +58,11 @@ export class DefaultLayoutComponent implements OnInit, OnDestroy {
this.shouldStopServersOnClosing = this.electronService.isElectronApp;
}
listProjects() {
this.router.navigate(['/server', this.serverIdProjectList, 'projects'])
.catch(error => this.toasterService.error('Cannot list projects'));
}
backToProject() {
this.router.navigate(['/server', this.recentlyOpenedServerId, 'project', this.recentlyOpenedProjectId])
.catch(error => this.toasterService.error('Cannot navigate to the last opened project'));

View File

@ -4,6 +4,8 @@ import { Injectable } from '@angular/core';
export class RecentlyOpenedProjectService {
private serverId: string;
private projectId: string;
private serverIdProjectList: string;
setServerId(serverId: string) {
this.serverId = serverId;
@ -13,6 +15,10 @@ export class RecentlyOpenedProjectService {
this.projectId = projectId;
}
setServerIdProjectList(serverId: string) {
this.serverIdProjectList = serverId;
}
getServerId() : string {
return this.serverId;
}
@ -21,8 +27,12 @@ export class RecentlyOpenedProjectService {
return this.projectId;
}
getServerIdProjectList() : string {
return this.serverIdProjectList;
}
removeData() {
this.serverId = '';
this.serverId = '',
this.projectId = ''
}
}