Round position of nodes and drawings during update to the closest integer

This commit is contained in:
ziajka 2018-12-13 09:17:04 +01:00
parent e76d6c4236
commit f866741011
4 changed files with 63 additions and 12 deletions

View File

@ -58,6 +58,22 @@ describe('DrawingService', () => {
});
}));
it('should updatePosition of drawing and round to integer', inject([DrawingService], (service: DrawingService) => {
const drawing = new Drawing();
drawing.project_id = "myproject";
drawing.drawing_id = "id";
service.updatePosition(server, drawing, 10.1, 20.6).subscribe();
const req = httpTestingController.expectOne(
'http://127.0.0.1:3080/v2/projects/myproject/drawings/id');
expect(req.request.method).toEqual("PUT");
expect(req.request.body).toEqual({
'x': 10,
'y': 21
});
}));
it('should update size and position of drawing', inject([DrawingService], (service: DrawingService) => {
const drawing = new Drawing();
drawing.project_id = "myproject";
@ -76,6 +92,24 @@ describe('DrawingService', () => {
});
}));
it('should update size and position of drawing and round to integer', inject([DrawingService], (service: DrawingService) => {
const drawing = new Drawing();
drawing.project_id = "myproject";
drawing.drawing_id = "id";
let svgSample = "<svg><test></svg>"
service.updateSizeAndPosition(server, drawing, 100.1, 100.6, svgSample).subscribe();
const req = httpTestingController.expectOne(
'http://127.0.0.1:3080/v2/projects/myproject/drawings/id');
expect(req.request.method).toEqual("PUT");
expect(req.request.body).toEqual({
'x': 100,
'y': 101,
'svg': svgSample
});
}));
it('should update drawing', inject([DrawingService], (service: DrawingService) => {
const drawing = new Drawing();
drawing.project_id = "myproject";

View File

@ -16,16 +16,16 @@ export class DrawingService {
return this.httpServer
.post<Drawing>(server, `/projects/${project_id}/drawings`, {
'svg': svg,
'x': x,
'y': y
'x': Math.round(x),
'y': Math.round(y)
});
}
updatePosition(server: Server, drawing: Drawing, x: number, y: number): Observable<Drawing> {
return this.httpServer
.put<Drawing>(server, `/projects/${drawing.project_id}/drawings/${drawing.drawing_id}`, {
'x': x,
'y': y
'x': Math.round(x),
'y': Math.round(y)
});
}
@ -33,8 +33,8 @@ export class DrawingService {
return this.httpServer
.put<Drawing>(server, `/projects/${drawing.project_id}/drawings/${drawing.drawing_id}`, {
'svg': svg,
'x': x,
'y': y
'x': Math.round(x),
'y': Math.round(y)
})
}
@ -42,8 +42,8 @@ export class DrawingService {
return this.httpServer
.put<Drawing>(server, `/projects/${drawing.project_id}/drawings/${drawing.drawing_id}`, {
'svg': svg,
'x': drawing.x,
'y': drawing.y,
'x': Math.round(drawing.x),
'y': Math.round(drawing.y),
'z': drawing.z
});
}
@ -51,8 +51,8 @@ export class DrawingService {
update(server: Server, drawing: Drawing): Observable<Drawing> {
return this.httpServer
.put<Drawing>(server, `/projects/${drawing.project_id}/drawings/${drawing.drawing_id}`, {
'x': drawing.x,
'y': drawing.y,
'x': Math.round(drawing.x),
'y': Math.round(drawing.y),
'z': drawing.z
});
}

View File

@ -103,6 +103,23 @@ describe('NodeService', () => {
});
}));
it('should updatePosition of node and round to integer', inject([NodeService], (service: NodeService) => {
const node = new Node();
node.project_id = "myproject";
node.node_id = "id";
service.updatePosition(server, node, 10.1, 20.6).subscribe();
const req = httpTestingController.expectOne(
'http://127.0.0.1:3080/v2/projects/myproject/nodes/id');
expect(req.request.method).toEqual("PUT");
expect(req.request.body).toEqual({
'x': 10,
'y': 21
});
}));
it('should update label of node', inject([NodeService], (service: NodeService) => {
const node = new Node();
node.project_id = "myproject";

View File

@ -38,8 +38,8 @@ export class NodeService {
updatePosition(server: Server, node: Node, x: number, y: number): Observable<Node> {
return this.httpServer
.put<Node>(server, `/projects/${node.project_id}/nodes/${node.node_id}`, {
'x': x,
'y': y
'x': Math.round(x),
'y': Math.round(y)
});
}