From 73f3b226d26031aa2307037822999c97c6df2f0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xe=CC=81fir=20Destiny?= Date: Wed, 2 Oct 2013 16:33:16 +0200 Subject: [PATCH] C'est joli <3 --- ajax.php | 7 ++++--- css/styles.css | 18 ++++++++++++++---- index.php | 9 ++++++--- js/app.js | 29 ++++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/ajax.php b/ajax.php index a82417d..276c180 100644 --- a/ajax.php +++ b/ajax.php @@ -4,6 +4,7 @@ require_once 'config/config.php'; require_once 'config/color.php'; require_once 'Net/SSH2.php'; global $servers; +$gitstatus = 'git fetch && git status'; if (!empty($_POST['section'])) { foreach ($servers as $ssh) { @@ -18,12 +19,12 @@ if (!empty($_POST['action'])) { $session = new Net_SSH2($config['host'], $config['port']); if ($session->login($config['user'], $config['pass'])) { if ($_POST['action'] == 'status') { - echo ansi2html($session->exec('cd ' . $config['path'] . ' && git fetch && git status')); + echo ansi2html($session->exec('cd ' . $config['path'] . ' && ' . $gitstatus)); } else if ($_POST['action'] == 'push') { $message = empty($_POST['message']) ? 'FTP' : $_POST['message']; - //echo $session->exec('cd ' . $config['path'] . ' && git add -A && git commit -m "' . $message . '" && git push'); + //echo $session->exec('cd ' . $config['path'] . ' && git add -A && git commit -m "' . $message . '" && git push && ' . $gitstatus); } else if ($_POST['action'] == 'pull') { - //echo $session->exec('cd ' . $config['path'] . ' && git pull'); + //echo $session->exec('cd ' . $config['path'] . ' && git pull && ' . $gitstatus); } } } diff --git a/css/styles.css b/css/styles.css index 528ad42..d9f04e5 100644 --- a/css/styles.css +++ b/css/styles.css @@ -1,21 +1,25 @@ -.btn-group > .btn:first-child { +.btn-group .btn:first-child { border-bottom-left-radius: 0; } -.btn-group > .btn:last-child { +.btn-group .btn:last-child, .input-prepend input { border-bottom-right-radius: 0; } -.btn-group > .btn { +.btn-group .btn { border-bottom: 0; } +.btn-group .input-prepend .btn { + border-left: 0; +} + .label { position: relative; bottom: 4px; } -pre { +pre, .btn-group .input-prepend .btn { border-top-left-radius: 0; } @@ -33,3 +37,9 @@ pre { background-repeat: no-repeat; padding-left: 20px; } + +.input-prepend { + margin-bottom: 0; + position: relative; + top: 1px; +} diff --git a/index.php b/index.php index 5448979..3e70e81 100644 --- a/index.php +++ b/index.php @@ -35,9 +35,12 @@ global $servers;

- - - + + +
+ + +

 							
diff --git a/js/app.js b/js/app.js index 67a0152..bda7241 100644 --- a/js/app.js +++ b/js/app.js @@ -1,20 +1,43 @@ window.addEventListener('load', function() { var sections = document.querySelectorAll('section'); for (var i = 0; i < sections.length; i++) { - callRequest(sections[i].id); + callRequest('status', sections[i].id); } }); -function callRequest(section) { +function callRequest(action, section, message) { var pre = document.querySelector('#' + section + ' pre'); pre.innerHTML = 'Loading ...'; + + var label = document.querySelector('#' + section + ' .label'); + label.classList.remove('label-success'); + label.classList.remove('label-important'); + label.classList.add('label-warning'); + label.innerHTML = 'Loading'; + + message = typeof(message) !== 'undefined' ? message : 'FTP'; var xhr = new XMLHttpRequest(); xhr.open('POST', 'ajax.php'); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhr.send('action=status§ion=' + section); + xhr.send('action=' + action + '§ion=' + section + '&message=' + message); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)) { pre.innerHTML = xhr.responseText; + + var splitLabel = xhr.responseText.split("\n").reverse(); + label.classList.remove('label-warning'); + if (splitLabel[1] !== 'nothing to commit (working directory clean)') { + label.classList.add('label-important'); + label.innerHTML = 'Update needed'; + } else { + label.classList.add('label-success'); + label.innerHTML = 'OK'; + } } }; } + +function push(section) { + //callRequest('push', section, document.getElementById('message').value); + return false; +}