Option to add blank project

This commit is contained in:
Piotr Pekala 2019-08-09 07:27:27 -07:00
commit 85b7d0943d
9 changed files with 47 additions and 2 deletions

View File

@ -46,6 +46,14 @@
<mat-icon>developer_board</mat-icon>
<span>Go to servers</span>
</button>
<button mat-menu-item (click)="addNewProject()">
<mat-icon>add</mat-icon>
<span>New blank project</span>
</button>
<button mat-menu-item (click)="saveProject()">
<mat-icon>save</mat-icon>
<span>Save project as</span>
</button>
<button mat-menu-item (click)="exportProject()">
<mat-icon>call_made</mat-icon>
<span>Export portable project</span>

View File

@ -53,6 +53,7 @@ import { ProjectMapMenuComponent } from './project-map-menu/project-map-menu.com
import { ToasterService } from '../../services/toaster.service';
import { ImportProjectDialogComponent } from '../projects/import-project-dialog/import-project-dialog.component';
import { MatDialog } from '@angular/material';
import { AddBlankProjectDialogComponent } from '../projects/add-blank-project-dialog/add-blank-project-dialog.component';
@Component({
@ -391,6 +392,19 @@ export class ProjectMapComponent implements OnInit, OnDestroy {
this.mapScaleService.resetToDefault();
}
addNewProject() {
const dialogRef = this.dialog.open(AddBlankProjectDialogComponent, {
width: '400px',
autoFocus: false
});
let instance = dialogRef.componentInstance;
instance.server = this.server;
}
saveProject() {
}
importProject() {
let uuid: string = '';
const dialogRef = this.dialog.open(ImportProjectDialogComponent, {

View File

@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, EventEmitter } from '@angular/core';
import { Router } from '@angular/router';
import { MatDialog, MatDialogRef } from '@angular/material';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
@ -20,6 +20,8 @@ import { ToasterService } from '../../../services/toaster.service';
export class AddBlankProjectDialogComponent implements OnInit {
server: Server;
projectNameForm: FormGroup;
uuid: string;
onAddProject = new EventEmitter<string>();
constructor(
public dialogRef: MatDialogRef<AddBlankProjectDialogComponent>,
@ -62,8 +64,9 @@ export class AddBlankProjectDialogComponent implements OnInit {
}
addProject(): void {
this.uuid = uuid();
this.projectService
.add(this.server, this.projectNameForm.controls['projectName'].value, uuid())
.add(this.server, this.projectNameForm.controls['projectName'].value, this.uuid)
.subscribe((project: Project) => {
this.dialogRef.close();
this.toasterService.success(`Project ${project.name} added`);

View File

@ -40,6 +40,9 @@
<button mat-icon-button matTooltip="Delete project" (click)="delete(row)" *ngIf="row.status == 'closed'">
<mat-icon aria-label="Delete project">delete</mat-icon>
</button>
<button mat-icon-button matTooltip="Duplicate project" (click)="duplicate(row)">
<mat-icon aria-label="Duplicate project">filter_2</mat-icon>
</button>
<button mat-icon-button matTooltip="Open project" (click)="open(row)" *ngIf="row.status == 'closed'">
<mat-icon aria-label="Open project">play_arrow</mat-icon>
</button>

View File

@ -107,6 +107,12 @@ export class ProjectsComponent implements OnInit {
);
}
duplicate(project: Project) {
this.projectService.duplicate(this.server, project.project_id, project.name).subscribe(() => {
this.refresh();
});
}
addBlankProject() {
const dialogRef = this.dialog.open(AddBlankProjectDialogComponent, {
width: '400px',

View File

@ -132,6 +132,13 @@ describe('ProjectService', () => {
expect(req.request.method).toEqual('DELETE');
});
it('should duplicate the project', () => {
service.duplicate(server, 'projectId', 'projectName').subscribe();
const req = httpTestingController.expectOne('http://127.0.0.1:3080/v2/projects/projectId/duplicate');
expect(req.request.method).toEqual('POST');
});
it('should get notifications path of project', () => {
const path = service.notificationsPath(server, 'myproject');
expect(path).toEqual('ws://127.0.0.1:3080/v2/projects/myproject/notifications/ws');

View File

@ -52,6 +52,10 @@ export class ProjectService {
export(server: Server, project_id: string): Observable<any> {
return this.httpServer.get(server, `/projects/${project_id}/export`)
}
duplicate(server: Server, project_id: string, project_name): Observable<any> {
return this.httpServer.post(server, `/projects/${project_id}/duplicate`, { name: project_name });
}
notificationsPath(server: Server, project_id: string): string {
return `ws://${server.host}:${server.port}/v2/projects/${project_id}/notifications/ws`;