gns3-web-ui/src/app/services/link.service.ts

51 lines
1.6 KiB
TypeScript
Raw Normal View History

2017-12-04 11:25:13 +00:00
import { Injectable } from '@angular/core';
2018-06-27 08:29:12 +00:00
import { Node } from '../cartography/models/node';
2017-12-04 11:25:13 +00:00
import 'rxjs/add/operator/map';
2019-01-15 10:15:54 +00:00
import { Server } from '../models/server';
import { HttpServer } from './http-server.service';
import { Port } from '../models/port';
2018-11-26 12:36:33 +00:00
import { Link } from '../models/link';
import { LinkNode } from '../models/link-node';
2017-12-04 11:25:13 +00:00
@Injectable()
export class LinkService {
2019-01-15 10:15:54 +00:00
constructor(private httpServer: HttpServer) {}
2017-12-04 11:25:13 +00:00
2019-01-15 10:15:54 +00:00
createLink(server: Server, source_node: Node, source_port: Port, target_node: Node, target_port: Port) {
return this.httpServer.post(server, `/projects/${source_node.project_id}/links`, {
nodes: [
{
node_id: source_node.node_id,
port_number: source_port.port_number,
adapter_number: source_port.adapter_number
},
{
node_id: target_node.node_id,
port_number: target_port.port_number,
adapter_number: target_port.adapter_number
}
]
});
2017-12-04 11:25:13 +00:00
}
2019-01-15 10:15:54 +00:00
updateNodes(server: Server, link: Link, nodes: LinkNode[]) {
const requestNodes = nodes.map(linkNode => {
2018-11-26 12:36:33 +00:00
return {
node_id: linkNode.node_id,
port_number: linkNode.port_number,
adapter_number: linkNode.adapter_number,
label: {
rotation: linkNode.label.rotation,
style: linkNode.label.style,
text: linkNode.label.text,
x: linkNode.label.x,
y: linkNode.label.y
}
2019-01-15 10:15:54 +00:00
};
2018-11-26 12:36:33 +00:00
});
2019-01-15 10:15:54 +00:00
return this.httpServer.put(server, `/projects/${link.project_id}/links/${link.link_id}`, { nodes: requestNodes });
2018-11-26 12:36:33 +00:00
}
2017-12-04 11:25:13 +00:00
}