Finished v0.1.0

master
Ayush Mukherjee 5 years ago
parent f83ce96bcc
commit 195cfdccfc

@ -63,8 +63,32 @@ ipcMain.on('login', async () => {
}, false);
});
ipcMain.on('changeProject', () => {
repo = undefined;
ipcMain.on('chooseDir', async function(event, data) {
let altWin = new BrowserWindow({
width: 1280,
height: 800,
webPreferences: {
nodeIntegration: true
}
});
// load the index.html file
altWin.loadFile('src/intro.html');
if(user.name == undefined || user.email == undefined) {
win.webContents.on('did-finish-load', function() {
win.webContents.send('get-user-name', true);
});
}
win.destroy();
win = altWin;
altWin = undefined;
});
ipcMain.on('chooseDir', function() {
// set dir
dir = modules.chooseDir(win);
@ -72,15 +96,43 @@ ipcMain.on('chooseDir', async function(event, data) {
win.loadFile('src/index.html');
// load the user info
repo = await modules.getRepoInfo(dir);
repo = modules.getRepoInfo(dir);
// when done loading the window, send the details.
win.webContents.on('did-finish-load', () => {
win.webContents.send('send_username', user.name);
win.webContents.send('send_useremail', user.email);
win.webContents.send('send_remote', repo.remote);
win.webContents.send('send_status', repo.status);
win.webContents.send('send_log', repo.log);
win.webContents.send('send_branch', repo.branch);
try {
win.webContents.send('send_remote', repo.remote);
win.webContents.send('send_status', repo.status);
win.webContents.send('send_log', repo.log);
win.webContents.send('send_branch', repo.branch);
} catch(e) {
console.log('repo send 2.');
}
});
});
ipcMain.on('gotoCommit', function() {
win.loadFile('src/commit.html');
win.webContents.on('did-finish-load', () => {
win.webContents.send('send_username', user.name);
win.webContents.send('send_useremail', user.email);
try {
win.webContents.send('send_remote', repo.remote);
win.webContents.send('send_status', repo.status);
win.webContents.send('send_log', repo.log);
win.webContents.send('send_branch', repo.branch);
} catch(e) {
console.log('repo send 2.');
}
});
});
ipcMain.on('gotoOverview', function() {
win.loadFile('src/index.html');
});
ipcMain.on('getCollaborators', (event, token) => {
api.getCollaborators(token, win, repo.remote);
});

@ -49,11 +49,40 @@ function requestGitHubToken(code, mainWin) {
})
.then((response) => {
let token = response.data.split('&')[0].split('=')[1];
mainWin.reload();
mainWin.webContents.send("token", token);
});
}
function getCollaborators(token, mainWin, repo) {
axios.get('https://api.github.com/user', {
headers: {
'Authorization': `token ${token}`
}
})
.then(response => {
let user = response.data.login;
axios.get(`https://api.github.com/repos/${user}/${repo}`, {
headers: {
'Authorization': `token ${token}`
}
})
.then(response => {
mainWin.webContents.send('gh_user', user);
mainWin.webContents.send('desc', response.data.description);
})
.catch(error => {
console.log(error);
});
})
.catch(error => {
console.log('error!');
});
}
module.exports = {
handleGitHub,
handleGitHubCallback
handleGitHubCallback,
getCollaborators
};

@ -12,10 +12,24 @@ function getRepoInfo(dir) {
// get branch, split by nextline, take the first one(assumed to be active), split by space and take the name of the branch
let branch = execSync("git branch").toString().split("\n")[0].split(' ')[1];
// process the log
let logSplit = log.split('\n');
let arrLog = [];
for(let i = 0; i < logSplit.length; i += 6) {
arrLog.push([
logSplit[i],
logSplit[i+1],
logSplit[i+2],
logSplit[i+3],
logSplit[i+4],
logSplit[i+5]
]);
}
return {
'remote': remote,
'status': status,
'log': log,
'log': arrLog,
'branch': branch
};
}

@ -0,0 +1,40 @@
<html>
<head>
<title>CPGC</title>
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,600,800" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/normalize.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<div class="container">
<div class="left">
<header>
<h1>CPGC</h1>
<h3>0.1.0</h3>
</header>
<div class="container u-full-width">
<a href="" onclick="gotoOverview()">Overview</a>
<a href="" class="active">Commit History</a>
<a href="" onclick="handleChangeProject()">Change Project</a>
</div>
</div>
<div class="right">
<div class="user_name">
Welcome,&nbsp;<span id="user_name"></span>
</div>
<section>Commit History - <span class="remote"></span></section>
<p id="desc"></p>
<span class="login" onclick="login()">Connect with GitHub</span>
<span class="logged_in" style="display: none;">Logged in to GitHub as </span>
<div class="window commit">
<div class="heading">Branch <span id="branch"></span></div>
</div>
</div>
</div>
</body>
<script src="js/commit.js"></script>
</html>

@ -77,12 +77,17 @@ body {
width: 100%;
color: white;
text-decoration: none;
transition: background 0.2s ease;
}
a.active {
background: rgba(0, 0, 0, 0.2);
}
.left > .container > a:hover {
background: rgba(0, 0, 0, 0.1);
}
.left > .user_email {
margin: 50px 0;
}
@ -90,13 +95,16 @@ a.active {
.container > .right {
grid-area: right;
padding: 1.5em 0;
overflow: hidden;
overflow-x: hidden;
overflow-y: scroll;
min-width: 0;
position: relative;
}
.window {
width: 95%;
height: 77%;
/* height: 77%; */
position: relative;
background: white;
border-radius: 5px;
box-shadow: 2px 1px 5px rgba(0, 0, 0, 0.05);
@ -179,4 +187,64 @@ button:hover {
font-weight: 600;
line-height: 0;
font-size: 16pt;
}
.heading {
display: block;
padding: 1em 1.5em 0 1.5em;
font-size: 1.5em;
}
.log {
display: inline-block;
margin: 1em 1.5em;
padding: 1em 1.5em;
background: #dadada;
border-radius: 5px;
}
.log--message {
font-weight: 500;
font-size: 14pt;
}
.log--email {
font-size: 12pt;
/* font-weight: 500; */
}
.log--time {
font-size: 12pt;
/* font-weight: 500; */
}
.status {
display: inline-block;
margin: 1em 1.5em;
padding: 1em 1.5em;
background: #dadada;
border-radius: 5px;
}
.login {
position: absolute;
right: 30px;
top: 23px;
font-size: 12pt;
border-bottom: 1px solid #292929;
}
.login:hover {
cursor: pointer;
}
.logged_in {
position: absolute;
right: 30px;
top: 23px;
font-size: 12pt;
}
.commit > .log {
display: block;
}

@ -12,23 +12,11 @@
<h1>CPGC</h1>
<h3>0.1.0</h3>
</header>
<!-- <div class="user_name">
User Name:
<span id="user_name"></span>
</div>
<div class="user_email">
User Email:
<span id="user_email"></span>
</div>
<div class="remote">
Remote URL: <br>
<span id="remote"></span>
</div> -->
<div class="container u-full-width">
<a href="" class="active">Overview</a>
<a href="" onclick="gotoCommit()">Commit History</a>
<a href="" onclick="handleChangeProject()">Change Project</a>
</div>
</div>
<div class="right">
@ -36,14 +24,21 @@
Welcome,&nbsp;<span id="user_name"></span>
</div>
<section>Overview</section>
<div class="container window">
<section>Overview - <span class="remote"></span></section>
<p id="desc"></p>
<span class="login" onclick="login()">Connect with GitHub</span>
<span class="logged_in" style="display: none;">Logged in to GitHub as </span>
<div class="window">
<div class="heading">Latest Commit in <span id="branch"></span></div>
<div class="log">
<div class="log--message"></div>
<span class="log--email"></span><span class="log--time"></span>
</div>
<div class="heading">Status</div>
<div class="status"></div>
</div>
<!-- Git Status: <br>
<textarea name="status" id="status" cols="30" rows="10"></textarea>
Git Log: <br>
<textarea name="log" id="log" cols="30" rows="10"></textarea> -->
</div>
</div>
</body>

@ -0,0 +1,72 @@
const electron = require('electron');
const ipc = electron.ipcRenderer;
if(localStorage.getItem('token') != null) {
document.querySelector('.login').style.display = 'none';
document.querySelector('.logged_in').style.display = 'block';
ipc.send('getCollaborators', localStorage.getItem('token'));
}
ipc.on('send_username', function(event, args) {
document.getElementById("user_name").innerHTML = args;
});
ipc.on('send_useremail', function(event, args) {
document.getElementById("user_email").innerHTML = args;
});
ipc.on('send_remote', function(event, args) {
document.querySelector(".remote").innerHTML = args;
});
ipc.on('send_branch', function(event, args) {
document.querySelector("#branch").innerHTML = args;
});
ipc.once('send_status', function(event, args) {
let res = args.split('\n');
for(let i = 0; i < res.length; i++) {
document.querySelector(".status").innerHTML += res[i] + '<br>';
}
});
ipc.once('send_log', function(event, args) {
for(let i = 0; i < args.length; i++) {
let w = document.querySelector('.window');
w.innerHTML +=
`<div class="log">
<div class="log--message">${args[i][4]}</div>
<div class="log--email">${args[i][1]}</div><div class="log--time">${args[i][2]}</div>
<span class="log--number">${args[i][0]}</span>
</div><br>`;
}
});
ipc.on('token', function(event, data) {
localStorage.setItem('token', data);
});
ipc.once('gh_user', (event, data) => {
document.querySelector('.logged_in').innerHTML += data;
});
ipc.once('desc', (event, data) => {
document.querySelector('#desc').innerHTML += data;
});
function login() {
event.preventDefault();
ipc.send('login');
}
function handleChangeProject() {
event.preventDefault();
ipc.send('changeProject');
}
function gotoOverview() {
event.preventDefault();
ipc.send('gotoOverview');
}

@ -7,10 +7,6 @@ ipcRenderer.on('get-user-name', function(event, data) {
}
});
ipcRenderer.on('token', function(event, data) {
localStorage.setItem('token', data);
});
function handleClick() {
ipcRenderer.sendSync('chooseDir');
}
@ -26,9 +22,4 @@ function handleUserChange() {
}
ipcRenderer.sendSync('changeUser', user);
}
function login() {
event.preventDefault();
ipcRenderer.send('login');
}

@ -1,25 +1,67 @@
const electron = require('electron');
const ipc = electron.ipcRenderer;
if(localStorage.getItem('token') != null) {
document.querySelector('.login').style.display = 'none';
document.querySelector('.logged_in').style.display = 'block';
ipc.send('getCollaborators', localStorage.getItem('token'));
}
ipc.on('send_username', function(event, args) {
document.getElementById("user_name").innerHTML = args;
console.log(args);
});
ipc.on('send_useremail', function(event, args) {
document.getElementById("user_email").innerHTML = args;
console.log(args);
});
// ipc.on('send_useremail', function(event, args) {
// document.getElementById("user_email").innerHTML = args;
// });
ipc.on('send_remote', function(event, args) {
document.getElementById("remote").innerHTML = args;
console.log(args);
document.querySelector(".remote").innerHTML = args;
});
ipc.on('send_branch', function(event, args) {
document.querySelector("#branch").innerHTML = args;
});
ipc.once('send_status', function(event, args) {
let res = args.split('\n');
for(let i = 0; i < res.length; i++) {
document.querySelector(".status").innerHTML += res[i] + '<br>';
}
});
ipc.on('send_status', function(event, args) {
document.getElementById("status").innerHTML = args;
console.log(args);
ipc.once('send_log', function(event, args) {
document.querySelector(".log--message").innerHTML = args[0][4];
document.querySelector(".log--email").innerHTML = args[0][1];
document.querySelector(".log--time").innerHTML = args[0][2];
});
ipc.on('send_log', function(event, args) {
document.getElementById("log").innerHTML = args;
console.log(args);
});
ipc.on('token', function(event, data) {
localStorage.setItem('token', data);
});
ipc.once('gh_user', (event, data) => {
document.querySelector('.logged_in').innerHTML += data;
});
ipc.once('desc', (event, data) => {
document.querySelector('#desc').innerHTML += data;
});
function login() {
event.preventDefault();
ipc.send('login');
}
function handleChangeProject() {
event.preventDefault();
ipc.send('changeProject');
}
function gotoCommit() {
event.preventDefault();
ipc.send('gotoCommit');
}
Loading…
Cancel
Save