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

View File

@ -4,6 +4,8 @@
<button mat-button routerLink="/servers">Servers</button> <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> <button *ngIf="recentlyOpenedProjectId && recentlyOpenedServerId" mat-button (click)="backToProject()">Back to project</button>
<span class="fill-space"></span> <span class="fill-space"></span>

View File

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

View File

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