Duplication option added

This commit is contained in:
Piotr Pekala
2019-06-17 06:50:26 -07:00
parent da896ac783
commit 67741ca601
10 changed files with 192 additions and 0 deletions

View File

@ -0,0 +1,4 @@
<button mat-menu-item (click)="duplicate()">
<mat-icon>filter_none</mat-icon>
<span>Duplicate</span>
</button>

View File

@ -0,0 +1,78 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatIconModule, MatMenuModule } from '@angular/material';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { NodesDataSource } from '../../../../../cartography/datasources/nodes-datasource';
import { DrawingsDataSource } from '../../../../../cartography/datasources/drawings-datasource';
import { NodeService } from '../../../../../services/node.service';
import { DrawingService } from '../../../../../services/drawing.service';
import { MockedDrawingService, MockedNodeService } from '../../../project-map.component.spec';
import { Node } from '../../../../../cartography/models/node';
import { Drawing } from '../../../../../cartography/models/drawing';
import { of } from 'rxjs';
import { DuplicateActionComponent } from './duplicate-action.component';
describe('DuplicateActionComponent', () => {
let component: DuplicateActionComponent;
let fixture: ComponentFixture<DuplicateActionComponent>;
let mockedNodeService: MockedNodeService = new MockedNodeService();
let mockedDrawingService: MockedDrawingService = new MockedDrawingService();
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MatIconModule, MatMenuModule, NoopAnimationsModule],
providers: [
{ provide: NodesDataSource, useClass: NodesDataSource },
{ provide: DrawingsDataSource, useClass: DrawingsDataSource },
{ provide: NodeService, useValue: mockedNodeService },
{ provide: DrawingService, useValue: mockedDrawingService }
],
declarations: [DuplicateActionComponent]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DuplicateActionComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call duplicate action in drawing service', () => {
let drawing = { drawing_id: '1' } as Drawing;
component.drawings = [drawing];
component.nodes = [];
spyOn(mockedDrawingService, 'duplicate').and.returnValue(of());
component.duplicate();
expect(mockedDrawingService.duplicate).toHaveBeenCalled();
});
it('should call duplicate action in node service', () => {
let node = { node_id: '1' } as Node;
component.nodes = [node];
component.drawings = [];
spyOn(mockedNodeService, 'duplicate').and.returnValue(of());
component.duplicate();
expect(mockedNodeService.duplicate).toHaveBeenCalled();
});
it('should call duplicate action in both services', () => {
let drawing = { drawing_id: '1' } as Drawing;
component.drawings = [drawing];
let node = { node_id: '1' } as Node;
component.nodes = [node];
spyOn(mockedDrawingService, 'duplicate').and.returnValue(of());
spyOn(mockedNodeService, 'duplicate').and.returnValue(of());
component.duplicate();
expect(mockedDrawingService.duplicate).toHaveBeenCalled();
expect(mockedNodeService.duplicate).toHaveBeenCalled();
});
});

View File

@ -0,0 +1,41 @@
import { Component, OnInit, Input } from '@angular/core';
import { Server } from '../../../../../models/server';
import { Node } from '../../../../../cartography/models/node';
import { Drawing } from '../../../../../cartography/models/drawing';
import { Project } from '../../../../../models/project';
import { NodeService } from '../../../../../services/node.service';
import { DrawingService } from '../../../../../services/drawing.service';
import { NodesDataSource } from '../../../../../cartography/datasources/nodes-datasource';
import { DrawingsDataSource } from '../../../../../cartography/datasources/drawings-datasource';
@Component({
selector: 'app-duplicate-action',
templateUrl: './duplicate-action.component.html'
})
export class DuplicateActionComponent {
@Input() server: Server;
@Input() project: Project;
@Input() drawings: Drawing[];
@Input() nodes: Node[];
constructor(
private nodeService: NodeService,
private nodesDataSource: NodesDataSource,
private drawingService: DrawingService,
private drawingsDataSource: DrawingsDataSource
) {}
duplicate() {
for(let node of this.nodes) {
this.nodeService.duplicate(this.server, node).subscribe((node: Node) => {
this.nodesDataSource.add(node);
});
}
for(let drawing of this.drawings) {
this.drawingService.duplicate(this.server, drawing.project_id, drawing).subscribe((drawing: Drawing) => {
this.drawingsDataSource.add(drawing);
})
}
}
}

View File

@ -8,6 +8,12 @@
[server]="server"
[nodes]="nodes"
></app-console-device-action>
<app-duplicate-action *ngIf="drawings.length>0 || nodes.length>0"
[server]="server"
[project]="project"
[nodes]="nodes"
[drawings]="drawings"
></app-duplicate-action>
<app-edit-style-action *ngIf="drawings.length===1 && !hasTextCapabilities"
[server]="server"
[project]="project"