Browse Source

Merge branch 'master' of https://github.com/jrtechs/github-graphs

pull/11/head
CetaceanNation 5 years ago
parent
commit
0073ddb43b
7 changed files with 189 additions and 2 deletions
  1. +1
    -1
      GraphTest.html
  2. +7
    -0
      conf.json
  3. +33
    -0
      configManager.js
  4. +32
    -0
      fileIO.js
  5. +55
    -1
      js/friendsGraph.js
  6. +25
    -0
      package.json
  7. +36
    -0
      server.js

+ 1
- 1
GraphTest.html View File

@ -34,7 +34,7 @@
<body> <body>
<h2 id="graphLabel"></h2> <h2 id="graphLabel"></h2>
<div id="myGraph" style="width:100%"></div>
<div id="myGraph"></div>
<script> <script>
createFriendsGraph("jrtechs", "myGraph", "graphLabel"); createFriendsGraph("jrtechs", "myGraph", "graphLabel");

+ 7
- 0
conf.json View File

@ -0,0 +1,7 @@
{
"port": 7000,
"sessionSecret": "superDuperSecret",
"clientID": "github client id",
"clientSecret": "clientSecret"
}

+ 33
- 0
configManager.js View File

@ -0,0 +1,33 @@
const fileIO = require('./fileIO');
const CONFIG_FILE_NAME = "conf.json";
const config = fileIO.getFileAsJSON(CONFIG_FILE_NAME);
module.exports=
{
getConfiguration: function()
{
return config;
},
syncToDisk: function()
{
fileIO.writeJSONToFile(CONFIG_FILE_NAME, config);
},
getPort: function()
{
return config.port;
},
getClientID: function()
{
return config.clientID;
},
getClientSecret: function()
{
return config.clientSecret;
}
};

+ 32
- 0
fileIO.js View File

@ -0,0 +1,32 @@
/** Used to read and write files from disk */
const fs = require('fs');
module.exports =
{
writeJSONToFile: function(fileName, jsonObject)
{
const json = JSON.stringify(jsonObject, null, 4);
fs.writeFile(fileName, json, 'utf8', function()
{
console.log("Wrote to " + fileName);
});
},
/**
*
* @param fileName
* @returns {any}
*/
getFileAsJSON: function(fileName)
{
return JSON.parse(module.exports.getFile(fileName));
},
getFile: function(filename)
{
return fs.readFileSync(filename, 'utf8');
}
};

+ 55
- 1
js/friendsGraph.js View File

@ -37,6 +37,7 @@ function addPersonToGraph(profileData)
nodes.push( nodes.push(
{ {
id:profileData.id, id:profileData.id,
name:profileData.login,
shape: 'circularImage', shape: 'circularImage',
image:profileData.avatar_url image:profileData.avatar_url
}); });
@ -66,12 +67,65 @@ function addFriends(username, apiPath)
function addConnection(person1, person2)
{
edges.push(
{
from: person1.id,
to: person2.id
});
}
function processUserConnections(userName)
{
return new Promise(function(resolve, reject)
{
queryAPIByUser(API_FOLLOWING, userName,
function(data)
{
for(var i = 0; i < data.length; i++)
{
}
queryAPIByUser(API_FOLLOWERS, userName, function(data2)
{
for(var i = 0; i < data2.length; i++)
{
}
resolve();
},
function(error)
{
reject(error);
});
},
function(error)
{
reject(error);
})
});
}
function createConnections() function createConnections()
{ {
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject)
{ {
resolve();
var prom = [];
for(var i = 0; i < nodes.length; i++)
{
prom.push(processUserConnections(nodes[i].name));
}
Promise.all(prom).then(function()
{
resolve();
}).catch(function(error)
{
reject(error);
});
}); });
} }

+ 25
- 0
package.json View File

@ -0,0 +1,25 @@
{
"name": "github-graphs",
"version": "0.0.1",
"description": "Generates graphs of github things.",
"main": "server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jrtechs/github-graphs.git"
},
"author": "Jeffery Russell",
"license": "ISC",
"bugs": {
"url": "https://github.com/jrtechs/github-graphs/issues"
},
"homepage": "https://github.com/jrtechs/github-graphs#readme",
"dependencies": {
"express": "^4.16.4",
"express-session": "^1.15.6",
"fs": "0.0.1-security"
}
}

+ 36
- 0
server.js View File

@ -0,0 +1,36 @@
/** express app for routing */
const express = require("express");
/**session data for login and storing preferences*/
const session = require('express-session');
const configLoader = require('./configManager.js');
const app = express();
/**Initializes sessions for login */
app.use(session(
{ secret: configLoader.getConfiguration().sessionSecret,
cookie: { maxAge: 6000000 }}
));
app.use(express.urlencoded()); //for easy retrieval of post and get data
app.use(express.json());
app.use(express.static(__dirname,'css'));
app.use(express.static(__dirname, 'js'));
app.use(express.static(__dirname, 'img'));
app.use(express.static('html'));
app.use(express.static(__dirname, 'fonts'));
const routes = require('./routes');
app.use('/', routes);
app.listen(configLoader.getConfiguration().port, () =>
console.log(`App listening on port ${configLoader.getConfiguration().port}!`)
);

Loading…
Cancel
Save