Skip to content
Extraits de code Groupes Projets
Valider d726d33a rédigé par Guillaume Schurck's avatar Guillaume Schurck
Parcourir les fichiers

Merge remote-tracking branch 'origin/dockerised' into dockerised

parents 3ef0967f d5d95694
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -62,3 +62,22 @@ class Neo4j:
results = session.run("MATCH (a) return Id(a) as key, a.name as name")
return results.data()
def insert_software(self, insert_data):
with self.driver.session() as session:
# On check si la node avec laquelle on se relie existe
results = session.run("match (a:Software) where ID(a) = %d return a" % int(insert_data.nodeId))
if not results.data():
return {"Error": "%d ID not found" % int(insert_data.nodeId)}
# On check si le logiciel n'existe pas déjà
results = session.run("match (a:Software) where a.name = '%s' return a" % insert_data.newNodeName)
if results.data():
return {"Error": "%s already exist" % insert_data.newNodeName}
session.run("CREATE (n:Software {name: '%s'})" % insert_data.newNodeName)
results = session.run(
"MATCH (a:Software), (b:Software) WHERE a.name = '%s' AND ID(b) = %d CREATE (a)-[r:%s]->(b) "
"RETURN type(r)" % (insert_data.newNodeName, int(insert_data.nodeId), insert_data.relationType))
return results.data()
......@@ -14,6 +14,12 @@ class SoftwareSearch(BaseModel):
software2: str
class SoftwareInsert(BaseModel):
newNodeName: str
relationType: str
nodeId: str
driver = Neo4j(os.environ.get("NEO4J_URI"), os.environ.get("NEO4J_USER"), os.environ.get("NEO4J_PASSWORD"))
app = FastAPI()
......@@ -70,7 +76,7 @@ async def software():
for idx, relation in enumerate(jsondata["edges"]):
relation['key'] = str(idx)
relation['attributes'] = {}
relation['attributes']['label'] = relation['relation_type'][1]
relation['label'] = relation['relation_type'][1]
relation['source'] = findNodeIdWithName(jsondata["nodes"], relation["source"])
relation['target'] = findNodeIdWithName(jsondata["nodes"], relation["target"])
del relation['relation_type']
......@@ -91,3 +97,9 @@ async def software_search(search: SoftwareSearch):
print(search.software1, search.software2)
res = driver.get_softwares_shortest_path(search)
return {"softwares": res}
@app.post("/software-insert")
async def software_insert(insert_data: SoftwareInsert):
res = driver.insert_software(insert_data)
return res
......@@ -12,6 +12,7 @@
<div class="topnav">
<a id="home" class="active" href="/">Home</a>
<a id="sigma" href="#/sigma-custom">Software graph</a>
<a id="add" href="#/add-node">Software graph</a>
</div>
</div>
<script type="module" src="/src/main.ts"></script>
......
......@@ -6,6 +6,7 @@
import NotFound from "./routes/NotFound.svelte";
import Sigma from "./routes/Sigma.svelte";
import SigmaCustom from "./routes/SigmaCustom.svelte";
import AddNode from "./routes/AddNode.svelte";
let routes = {
"/": Index,
......@@ -13,6 +14,7 @@
"/graph": Graph,
"/sigma": Sigma,
"/sigma-custom": SigmaCustom,
"/add-node": AddNode,
"*": NotFound
}
</script>
......
<script lang="ts">
import {onMount} from 'svelte';
onMount(() => {
fetch("http://localhost:8000/add-node")
.then(response => response.json())
.then(data => {
// Retrieve some useful DOM elements:
const link = document.getElementById("sigma") as HTMLElement;
const home = document.getElementById("home") as HTMLElement;
const add = document.getElementById("add") as HTMLElement;
add.classList.add("active");
home.classList.remove("active");
link.classList.remove("active");
})
});
</script>
<div id="app-base">
<h1>Add new node</h1>
</div>
\ No newline at end of file
......@@ -2,8 +2,10 @@
import SoftwareMerger from "../components/SoftwareMerger.svelte";
const link = document.getElementById("sigma");
const home = document.getElementById("home");
const add = document.getElementById("add");
home.classList.add("active");
link.classList.remove("active");
add.classList.remove("active");
</script>
<div id="app-base">
......
......@@ -19,8 +19,10 @@
const container = document.getElementById("sigma-container") as HTMLElement;
const link = document.getElementById("sigma") as HTMLElement;
const home = document.getElementById("home") as HTMLElement;
const add = document.getElementById("add") as HTMLElement;
link.classList.add("active");
home.classList.remove("active");
add.classList.remove("active");
// Instantiate sigma:
const graph = new Graph();
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter