diff --git a/index.js b/index.js index 1bb35ab..71a9a96 100644 --- a/index.js +++ b/index.js @@ -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); }); \ No newline at end of file diff --git a/modules/api.js b/modules/api.js index 6512eaf..a239db4 100644 --- a/modules/api.js +++ b/modules/api.js @@ -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 }; \ No newline at end of file diff --git a/modules/git.js b/modules/git.js index ecba732..13214dd 100644 --- a/modules/git.js +++ b/modules/git.js @@ -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 }; } diff --git a/src/commit.html b/src/commit.html new file mode 100644 index 0000000..5153ae2 --- /dev/null +++ b/src/commit.html @@ -0,0 +1,40 @@ + + + CPGC + + + + + +
+
+
+

CPGC

+

0.1.0

+
+ + +
+
+
+ Welcome,  +
+ +
Commit History -
+

+ + + +
+
Branch
+
+
+
+ + + + diff --git a/src/css/main.css b/src/css/main.css index 00825a8..e20d9ec 100644 --- a/src/css/main.css +++ b/src/css/main.css @@ -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; } \ No newline at end of file diff --git a/src/index.html b/src/index.html index e326064..c88e9f9 100644 --- a/src/index.html +++ b/src/index.html @@ -12,23 +12,11 @@

CPGC

0.1.0

-
Overview + Commit History + Change Project
@@ -36,14 +24,21 @@ Welcome, 
-
Overview
-
+
Overview -
+

+ Connect with GitHub + +
+
Latest Commit in
+
+
+ +
+ +
Status
+
-
diff --git a/src/js/commit.js b/src/js/commit.js new file mode 100644 index 0000000..687b56d --- /dev/null +++ b/src/js/commit.js @@ -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] + '
'; + } +}); + +ipc.once('send_log', function(event, args) { + for(let i = 0; i < args.length; i++) { + let w = document.querySelector('.window'); + w.innerHTML += + `
+
${args[i][4]}
+
${args[i][1]}
${args[i][2]}
+ ${args[i][0]} +

`; + } +}); + +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'); +} \ No newline at end of file diff --git a/src/js/intro.js b/src/js/intro.js index 8dc690c..9c4e577 100644 --- a/src/js/intro.js +++ b/src/js/intro.js @@ -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'); } \ No newline at end of file diff --git a/src/js/main.js b/src/js/main.js index 13ea305..138b682 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -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] + '
'; + } }); -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); -}); \ No newline at end of file +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'); +} \ No newline at end of file