packages feed

mywatch 0.1.1 → 0.1.2

raw patch · 7 files changed

+49/−26 lines, 7 files

Files

ChangeLog.md view
@@ -1,3 +1,9 @@+0.1.2+=====++  * Use location hash for server name+  * Compact server list (`display: inline-block`)+ 0.1.1 ===== 
README.md view
@@ -74,6 +74,6 @@  Screenshots ===========-![MyWatch](./screenshots/mywatch.png)-![Access Denied](./screenshots/mywatch500.png)+![MyWatch1](./screenshots/mywatch-1.png)+![MyWatch2](./screenshots/mywatch-2.png) 
mywatch.cabal view
@@ -1,5 +1,5 @@ name: mywatch-version: 0.1.1+version: 0.1.2 synopsis: View MySQL processes description:   View queries on multiple MySQL servers. Designed to work behind Sproxy.
src/Application.hs view
@@ -41,14 +41,10 @@  myProcess :: Pools  -> Middleware -> FilePath -> ScottyM () myProcess ps logger dataDir = do-  let-    index_html = dataDir ++ "/" ++ "index.html"-   middleware logger    middleware $ staticPolicy (hasPrefix "static" >-> addBase dataDir)-  get "/" $ file index_html-  get "/index.html" $ file index_html+  get "/" $ file (dataDir ++ "/" ++ "index.html")    get "/serverlist.json" $ json (sort $ HM.keys ps)   get "/server/:server/processlist.json" $ apiGetProcessList ps
src/LogFormat.hs view
@@ -12,7 +12,7 @@ import System.Log.FastLogger (LogStr, toLogStr) import qualified Data.ByteString.Char8 as BS --- Sligthly modified Common Log Format.+-- Sligthly modified Combined Log Format. -- User ID extracted from the From header. logFormat :: BS.ByteString -> Request -> Status -> Maybe Integer -> LogStr logFormat t req st msize = ""
static/mywatch.css view
@@ -1,2 +1,4 @@-table#processList td { white-space: nowrap; }+#serverList li { display: inline-block; } table th { text-align: center; }+table#processList td { white-space: nowrap; }+table#processList td.mywatch-query { white-space: pre-wrap; }
static/mywatch.js view
@@ -1,9 +1,10 @@ $(function() {   var info = $('#info');-  var infoHead = $('#info>h1');   var infoAlert = $('#info>div');+  var infoHead = $('#info>h1');   var main = $('#main');   var plBody = $('#processList>tbody');+  var serverList = $('#serverList>ul');    var interval = null; @@ -22,6 +23,27 @@     info.show();   } +  function switchServer(server) {+    clearInterval(interval);+    if ('' !== server) {+      document.title = server + ' — ' + 'MyWatch';+      serverList.find('.active').removeClass('active');+      var s = $('a[href="#' + server + '"]');+      if (s) {+        s.parent().addClass('active');+        getProcessList(server);+        interval = setInterval(getProcessList, 60 * 1000, server);+      }+    } else {+      document.title = 'MyWatch';+    }+  }++  function onHash() {+    switchServer(location.hash.substring(1));+  };+  window.onhashchange = onHash;+   function getProcessList(server) {     $.ajax({       url: "server/" + server + "/processlist.json",@@ -35,7 +57,7 @@             var td = $('<td>');             td.text(p[c]);             if ('info' === c) {-              td.css('white-space', 'pre-wrap');+              td.addClass('mywatch-query');             } else if ('time' === c) {               td.css('text-align', 'right');             } else if ('id' === c) {@@ -52,8 +74,8 @@   };    $.ajax({-    url: "serverlist.json",-    method: "GET",+    url: 'serverlist.json',+    method: 'GET',     error: commonError,     success: function(servers) {       var total = servers.length;@@ -61,28 +83,25 @@       var checked = 0;       $.each(servers, function(i, s) {         $.ajax({-          url: "server/" + s + "/processlist.json",-          method: "HEAD",+          url: 'server/' + s + '/processlist.json',+          method: 'HEAD',           success: function() {             available.push(s);           },           complete: function() {-            var menu = $('#serverList>ul');             checked++;             if (checked === total) {               $.each(available.sort(), function(i, s) {-                menu.append('<li><a href="#">' + s + '</a></li>')+                serverList.append('<li><a href="#' + s + '">' + s + '</a></li>')               });-              $("#serverList a").on("click", function() {-                var server = $(this).text();-                document.title = server + ' — ' + 'MyWatch';-                $(this).parent().parent().find('.active').removeClass('active');-                $(this).parent().addClass('active');-                clearInterval(interval);-                getProcessList(server);-                interval = setInterval(getProcessList, 60 * 1000, server);+              serverList.find('a').on('click', function() {+                var s = $(this).text();+                if ('#' + s === location.hash) {+                  getProcessList(s);+                }               });               info.hide();+              onHash();             }           }         });