Untitled
unknown
plain_text
2 years ago
13 kB
2
Indexable
Never
package.json { "name": "library", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "nodemon app.js" }, "author": "", "license": "ISC", "dependencies": { "body-parser": "*", "ejs": "*", "express": "*", "method-override": "^3.0.0", "morgan": "*", "neo4j-driver": "*", "nodemon": "^2.0.15" } } app.js var express= require('express'); var path= require('path'); var logger= require('morgan'); var bodyParser= require('body-parser'); var neo4j = require('neo4j-driver'); methodOverride = require("method-override"); const { type, json, redirect } = require('express/lib/response'); var app= express(); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'ejs') app.use(logger('dev')); app.use(bodyParser.json()); app.use(bodyParser.urlencoded({ extended: false})); app.use(express.static(path.join(__dirname,'public'))); app.use(methodOverride("_method")); var driver = neo4j.driver('bolt://localhost',neo4j.auth.basic('neo4j','12345')); var session =driver.session(); var session11 =driver.session(); var liste=[]; app.post('/search', function(req,res){ liste=[] var a_adi=req.body.arastirmaci; var y_adi=req.body.yayin; var y_yil=req.body.yil; if(a_adi!=0 && y_yil!=0){ session11.run('MATCH (n:Yayin {yil:$yil} )<-[:Yayin_Yazari]-(m:Arastirmaci{isim:$na}) , (k:Tur )<-[:Yayin_Turu]-(n:Yayin {yil:$yil}) RETURN m,n,k',{na:a_adi,yil:y_yil}) .then(function(result){ result.records.forEach(function(record){ liste.push({ isim:record._fields[0].properties.isim, adi:record._fields[1].properties.adi, yil:record._fields[1].properties.yil, tur:record._fields[2].properties.turAdi, yer:record._fields[2].properties.yer }); })}) } else if(a_adi!=0){ session11.run('MATCH (n:Yayin )<-[:Yayin_Yazari]-(m:Arastirmaci{isim:$na}) , (k:Tur )<-[:Yayin_Turu]-(n:Yayin) RETURN m,n,k',{na:a_adi}) .then(function(result){ result.records.forEach(function(record){ liste.push({ isim:record._fields[0].properties.isim, adi:record._fields[1].properties.adi, yil:record._fields[1].properties.yil, tur:record._fields[2].properties.turAdi, yer:record._fields[2].properties.yer }); })}) } else if(y_yil!=0){ session11.run('MATCH (n:Yayin {yil:$yil} )<-[:Yayin_Yazari]-(m:Arastirmaci) , (k:Tur )<-[:Yayin_Turu]-(n:Yayin {yil:$yil}) RETURN m,n,k',{yil:y_yil}) .then(function(result){ result.records.forEach(function(record){ liste.push({ isim:record._fields[0].properties.isim, adi:record._fields[1].properties.adi, yil:record._fields[1].properties.yil, tur:record._fields[2].properties.turAdi, yer:record._fields[2].properties.yer }); })}) } else if(y_adi!=0){ session11.run('MATCH (n:Yayin {adi:$adi} )<-[:Yayin_Yazari]-(m:Arastirmaci) , (k:Tur )<-[:Yayin_Turu]-(n:Yayin) RETURN m,n,k',{adi:y_adi}) .then(function(result){ result.records.forEach(function(record){ liste.push({ isim:record._fields[0].properties.isim, adi:record._fields[1].properties.adi, yil:record._fields[1].properties.yil, tur:record._fields[2].properties.turAdi, yer:record._fields[2].properties.yer }); })}) } res.redirect('/user'); }) app.get('/user',function(req,res){ var arastirmaciArr=[]; session.run('MATCH (n:Yayin )<-[:Yayin_Yazari]-(m:Arastirmaci) , (k:Tur )<-[:Yayin_Turu]-(n:Yayin) RETURN m,n,k') .then(function(result){ result.records.forEach(function(record){ arastirmaciArr.push({ isim:record._fields[0].properties.isim, adi:record._fields[1].properties.adi, yil:record._fields[1].properties.yil, tur:record._fields[2].properties.turAdi, yer:record._fields[2].properties.yer }); }); const arastirmaci = Array.from(new Set(arastirmaciArr.map(item => item.isim))); const yayin = Array.from(new Set(arastirmaciArr.map(item => item.adi))) const yil = Array.from(new Set(arastirmaciArr.map(item => item.yil))) res.render('user',{ arastirmacilar:liste, arastirmaci: arastirmaci, yayin:yayin, yil:yil}) }).catch(function(err){ console.log(err); }); }) app.get('/',function(req,res){ var arastirmaciArr=[]; session.run('MATCH (n:Yayin )<-[:Yayin_Yazari]-(m:Arastirmaci) , (k:Tur )<-[:Yayin_Turu]-(n:Yayin) RETURN m,n,k') .then(function(result){ result.records.forEach(function(record){ arastirmaciArr.push({ id:record._fields[0].identity.low, isim:record._fields[0].properties.isim, adi:record._fields[1].properties.adi, yil:record._fields[1].properties.yil, tur:record._fields[2].properties.turAdi, yer:record._fields[2].properties.yer }); }); res.render('index',{ arastirmacilar: arastirmaciArr}) }).catch(function(err){ console.log(err); }); }) var session1 =driver.session(); var session2 =driver.session(); var session3 =driver.session(); var session4 =driver.session(); var session5 =driver.session(); app.post('/add', function(req,res){ var isim= req.body.aname; var yayin=req.body.yname; var yil= req.body.year; var yer= req.body.place; var tur=req.body.type; session1.run( 'CREATE (n1:Arastirmaci {isim:$na}),(n2:Yayin {adi: $name,yil:$yil}),(n3:Tur{turAdi:$tur,yer:$yer})',{na:isim, name: yayin ,yil:yil,tur:tur,yer:yer} ) .then(function(){ session1.run( 'MATCH (m:Yayin {adi:$yayin}),(k:Tur {turAdi:$tur}) CREATE (m)-[:Yayin_Turu]->(k)',{yayin:yayin,tur:tur} ) .then(function(result){ // res.redirect('/'); }).catch(function(err){ console.log('error'); }); session1.close(); res.redirect('/'); }).catch(function(err){ session2.run( 'CREATE (n1:Arastirmaci {isim:$na})',{na:isim} ) .then(function(){ res.redirect('/'); session2.close(); }) .catch(function(err){ session3.run( 'CREATE (n2:Yayin {adi: $name,yil:$yil}),(n3:Tur{turAdi:$tur,yer:$yer})',{name: yayin ,yil:yil,tur:tur,yer:yer} ) .then(function(){ session3.run('MATCH (m:Yayin {adi:$yayin}),(k:Tur {turAdi:$tur}) CREATE (m)-[:Yayin_Turu]->(k) ',{yayin:yayin,tur:tur} ) .then(function(result){ }).catch(function(err){ console.log('errormatch'); }); res.redirect('/'); session3.close(); }) .catch(function(err){ session4.run( 'CREATE (n2:Yayin {adi: $name,yil:$yil})',{name: yayin ,yil:yil} ) .then(function(){ session4.run( 'MATCH (m:Yayin {adi:$yayin}),(k:Tur {turAdi:$tur}) CREATE (m)-[:Yayin_Turu]->(k) ',{yayin:yayin,tur:tur} ) .then(function(result){ console.log('only yayin'); }).catch(function(err){ console.log('onlyyayin'); }); res.redirect('/'); session4.close(); }) .catch(function(err){ session5.run( 'MATCH (n:Arastirmaci {isim:$na}), (m:Yayin {adi:$yayin}) CREATE (n)-[:Yayin_Yazari]->(m) ',{na:isim,yayin:yayin} ) .then(function(result){ session5.run('MATCH (n:Yayin {adi: $yayin})<-[:Yayin_Yazari]-(m:Arastirmaci) WHERE m.isim <> $na RETURN m',{yayin:yayin,na:isim}) .then(function(result){ result.records.forEach(function(record){ session5.run('MATCH (n:Arastirmaci {isim:$name}),(m:Arastirmaci {isim:$na}) CREATE (m)-[:BirlikteCalisti]->(n) ',{name:record._fields[0].properties.isim,na:isim}) .then(function(result){ console.log(record._fields[0].properties.isim) }) .catch(function(err){ console.log('error3-2'); }); res.redirect('/'); session5.close(); }) }) .catch(function(err){ console.log('error4'); }); }) .catch(function(err){ console.log('error6');}); });}); }); }); res.redirect('/'); }) app.post("/delete/:id", function(req, res){ session1.run('MATCH (s:Arastirmaci {isim:$id}) detach delete s',{id:req.params.id}) .then(function(result){ console.log('node is deleted') res.redirect('/'); }) .catch(function(err){ console.log('error333'); }); console.log(req.params.id) }); app.listen(3000); module.exports=app; index.ejs <form name="form1" method="POST" action="/add" style="background-color: brown;"> <table style=" margin-left: auto; margin-right: auto;margin-top: 100px;"> <tr> <td style="color: rgb(221, 221, 233);">Arastirmaci Adi Soyadi:</td> <td><input type="text" name="aname" style="width: 350px;" ></td> </tr> <tr> <td style="color: rgb(221, 221, 233);">Yayin adi:</td> <td><input type="text" name="yname" style="width: 350px;"></td> </tr> <tr> <td style="color: rgb(221, 221, 233);">Yayin yili:</td> <td><input type="text" name="year" style="width: 350px;"></td> </tr> <tr> <td style="color: rgb(221, 221, 233);">Yayin yeri:</td> <td><input type="text" name="place" style="width: 350px;" ></td> </tr> <tr> <td style="color: rgb(221, 221, 233);">Yayin turu:</td> <td><input type="text" name="type" style="width: 350px;"></td> </tr> <br> </table> <br> <button style=" margin-left:780px;display: block; " input type="submit">KAYDET</button> <br><br> <table style="color: rgb(255, 255, 255);margin-left:420px;display: block;"> <tr> <th>Araştırmacı </th> <th>Yayın adı </th><th>Yayın yıLı </th> <th>Yayın Türü </th><th>Yayın Yeri</th> </tr> <br> <% for (var i = 0; i < arastirmacilar.length; i++) { %> <tr> <td><%= arastirmacilar[i].isim%></td> <td><%= arastirmacilar[i].adi %></td> <td><%= arastirmacilar[i].yil %></td> <td><%= arastirmacilar[i].tur %></td> <td><%= arastirmacilar[i].yer %></td> <td> <form class="pull-right" action="/delete/<%= arastirmacilar[i].isim%>" method="POST"> <input type="submit" class="btn btn-xs btn-danger" value="Delete"> </form></td> </tr> <% } %> </table> </form> user.ejs <form name="form2" method="POST" action="/search" style="background-color: brown;"> <select style="margin-left:350px;margin-top: 100px;" name="arastirmaci" id="arastirmaci"> <option value=0>Araştırmacı sec:</option> <% for (var i = 0; i < arastirmaci.length; i++) { %> <option value="<%= arastirmaci[i]%>"><%= arastirmaci[i]%></option> <% } %> </select> <select style="margin-left:50px;margin-top: 100px;" name="yayin" id="yayin"> <option value= 0>Yayın Adı sec:</option> <% for (var i = 0; i < yayin.length; i++) { %> <option value="<%= yayin[i]%>"><%= yayin[i]%></option> <% } %> </select> <select style="margin-left:50px;margin-top: 100px;" name="yil" id="yil"> <option value= 0>Yayın yılı sec:</option> <% for (var i = 0; i < yil.length; i++) { %> <option value="<%=yil[i]%>"><%= yil[i]%></option> <% } %> </select> <button style="margin-left: 50px;" input type="submit">Göster</button> <br><br> <table style="color: rgb(255, 255, 255);margin-left:420px;display: block;"> <tr> <th>Araştırmacı </th> <th>Yayın Adı </th><th>Yayın yılı </th> <th>Yayin Turu </th><th>Yayin Yeri</th> </tr> <br> <% for (var i = 0; i < arastirmacilar.length; i++) { %> <tr> <td><%= arastirmacilar[i].isim%></td> <td><%= arastirmacilar[i].adi %></td> <td><%= arastirmacilar[i].yil %></td> <td><%= arastirmacilar[i].tur %></td> <td><%= arastirmacilar[i].yer %></td> </tr> <% } %> </table> </form>