mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-06-01 15:00:49 +00:00
33 lines
753 B
TypeScript
33 lines
753 B
TypeScript
import { Injectable } from "@angular/core";
|
|
import { BehaviorSubject } from "rxjs";
|
|
import { Server } from "../models/server";
|
|
|
|
|
|
@Injectable()
|
|
export class ServerDatabase {
|
|
dataChange: BehaviorSubject<Server[]> = new BehaviorSubject<Server[]>([]);
|
|
|
|
constructor() {}
|
|
|
|
get data(): Server[] {
|
|
return this.dataChange.value;
|
|
}
|
|
|
|
public addServer(server: Server) {
|
|
const servers = this.data.slice();
|
|
servers.push(server);
|
|
this.dataChange.next(servers);
|
|
}
|
|
|
|
public addServers(servers: Server[]) {
|
|
this.dataChange.next(servers);
|
|
}
|
|
|
|
public remove(server: Server) {
|
|
const index = this.data.indexOf(server);
|
|
if (index >= 0) {
|
|
this.data.splice(index, 1);
|
|
this.dataChange.next(this.data.slice());
|
|
}
|
|
}
|
|
} |