Merge "Suggestions to enhance the SQL call pattern."
authorFelix Dörre <felix@dogcraft.de>
Sun, 19 Jun 2016 17:10:13 +0000 (19:10 +0200)
committerGerrit Code Review <gigi-system@dogcraft.de>
Sun, 19 Jun 2016 17:10:13 +0000 (19:10 +0200)
src/org/cacert/gigi/Gigi.templ
src/org/cacert/gigi/dbObjects/DomainPingConfiguration.java
src/org/cacert/gigi/dbObjects/EmailAddress.java
src/org/cacert/gigi/output/template/SprintfCommand.java
src/org/cacert/gigi/output/template/Template.java
static/static/js/expert.js [moved from static/static/expert.js with 100% similarity]
static/static/js/localDate.js [new file with mode: 0644]
static/static/menu.js [deleted file]

index 26ce9206e4c3c73e4d7fed2fe7d569726c5f5bd1..a163c7d532f74f74bdb5f3f9500b33c9e6a29e6c 100644 (file)
@@ -8,14 +8,14 @@
         <meta name="description" content="">
         <link rel="stylesheet" href="<?=$static?>/css/jquery-ui-timepicker-addon.css">
         <meta name="viewport" content="width=device-width, initial-scale=1">
-        <link rel="apple-touch-icon" href="<?=$static?>/apple-touch-icon.png">
 
         <link rel="stylesheet" href="<?=$static?>/css/bootstrap.min.css">
         <link rel="stylesheet" href="<?=$static?>/css/cacert.css">
-        
+
         <script src="<?=$static?>/js/jquery.min.js"></script>
         <script src="<?=$static?>/js/bootstrap.min.js"></script>
-        <script src="<?=$static?>/expert.js"></script>
+        <script src="<?=$static?>/js/expert.js"></script>
+        <script src="<?=$static?>/js/localDate.js"></script>
     </head>
 <body>
 <nav class="navbar navbar-default">
index d63aff9b6fb81b250f9fded5649f64c2d689fcb6..772b066f173db45cb0535d2d110b1a7faa8a86bc 100644 (file)
@@ -1,15 +1,11 @@
 package org.cacert.gigi.dbObjects;
 
-import java.util.Arrays;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.cacert.gigi.Gigi;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
-import org.cacert.gigi.output.template.Scope;
 import org.cacert.gigi.output.template.SprintfCommand;
 
 public class DomainPingConfiguration implements IdCachable {
@@ -94,9 +90,6 @@ public class DomainPingConfiguration implements IdCachable {
             Gigi.notifyPinger(this);
             return;
         }
-        Map<String, Object> data = new HashMap<String, Object>();
-        data.put("delay", REPING_MINIMUM_DELAY / 60 / 1000);
-        data.put("data", new Date(lastExecution.getTime() + REPING_MINIMUM_DELAY));
-        throw new GigiApiException(new Scope(new SprintfCommand("Reping is only allowed after {0} minutes, yours end at {1}.", Arrays.asList("${delay}", "${data}")), data));
+        throw new GigiApiException(SprintfCommand.createSimple("Reping is only allowed after {0} minutes, yours end at {1}.", REPING_MINIMUM_DELAY / 60 / 1000, new Date(lastExecution.getTime() + REPING_MINIMUM_DELAY)));
     }
 }
index 04108ea2ec3831284f479ecd186f843d6a7790ee..964d1b68ec8dda6cb2afb7685d43c46415f303d7 100644 (file)
@@ -1,11 +1,8 @@
 package org.cacert.gigi.dbObjects;
 
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.Locale;
-import java.util.Map;
 
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.GigiPreparedStatement;
@@ -13,7 +10,6 @@ import org.cacert.gigi.database.GigiResultSet;
 import org.cacert.gigi.email.EmailProvider;
 import org.cacert.gigi.email.MailProbe;
 import org.cacert.gigi.localisation.Language;
-import org.cacert.gigi.output.template.Scope;
 import org.cacert.gigi.output.template.SprintfCommand;
 import org.cacert.gigi.util.RandomToken;
 
@@ -138,9 +134,7 @@ public class EmailAddress implements IdCachable, Verifyable {
         Date lastExecution = getLastPing(false);
 
         if (lastExecution != null && lastExecution.getTime() + REPING_MINIMUM_DELAY >= System.currentTimeMillis()) {
-            Map<String, Object> data = new HashMap<String, Object>();
-            data.put("data", new Date(lastExecution.getTime() + REPING_MINIMUM_DELAY));
-            throw new GigiApiException(new Scope(new SprintfCommand("Reping is only allowed after 5 minutes, yours end at {0}.", Arrays.asList("${data}")), data));
+            throw new GigiApiException(SprintfCommand.createSimple("Reping is only allowed after {0} minutes, yours end at {1}.", REPING_MINIMUM_DELAY / 60 / 1000, new Date(lastExecution.getTime() + REPING_MINIMUM_DELAY)));
         }
         ping(l);
         return;
index 006155d2ffdd6f12836aa639506cff4e423a0407..51ea9cf209c16531a2637837c5410057aee9e011 100644 (file)
@@ -111,7 +111,7 @@ public final class SprintfCommand implements Translatable {
      *            the variables to put into the placeholders.
      * @return the constructed {@link Outputable}.
      */
-    public static Outputable createSimple(String msg, String... vars) {
+    public static Outputable createSimple(String msg, Object... vars) {
         HashMap<String, Object> scope = new HashMap<>();
         String[] store = new String[vars.length];
         for (int i = 0; i < vars.length; i++) {
index cc56baf813b8e731c855c71cf0213de912f0651c..15f3408d28ce41d10d55b4f9491fdaf223cb0d84 100644 (file)
@@ -213,9 +213,11 @@ public class Template implements Outputable {
         } else if (s instanceof DayDate) {
             out.print(DateSelector.getDateFormat().format(((DayDate) s).toDate()));
         } else if (s instanceof Date) {
-            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            out.print(sdf.format(s));
-            out.print(" UTC");
+            SimpleDateFormat sdfUI = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+            out.print("<time datetime=\"" + sdf.format(s) + "\">");
+            out.print(sdfUI.format(s));
+            out.print(" UTC</time>");
         } else {
             out.print(s == null ? "null" : (unescaped ? s.toString() : HTMLEncoder.encodeHTML(s.toString())));
         }
diff --git a/static/static/js/localDate.js b/static/static/js/localDate.js
new file mode 100644 (file)
index 0000000..0935810
--- /dev/null
@@ -0,0 +1,29 @@
+(function() {
+       function init(){
+               var elems = document.getElementsByTagName("time");
+               for(var i = 0; i < elems.length; i++){
+                       elems[i].setAttribute("title", elems[i].textContent);
+                       elems[i].removeChild(elems[i].firstChild);
+                       var t = elems[i].getAttribute("datetime");
+                       elems[i].appendChild(document.createTextNode(new Date(t).toLocaleString(undefined, {timeZoneName: "short",
+                               year: "numeric",
+                               month: "2-digit",
+                               day: "2-digit",
+                               hour: "2-digit",
+                               minute: "2-digit",
+                               second: "2-digit"})
+                               ));
+               }
+       }
+       (function(oldLoad) {
+               if (oldLoad == undefined) {
+                       window.onload = init;
+               } else {
+                       window.onload = function() {
+                               init();
+                               oldLoad();
+                       }
+               }
+       })(window.onload);
+
+})();
diff --git a/static/static/menu.js b/static/static/menu.js
deleted file mode 100644 (file)
index bcaee0d..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-(function() {
-       function explodeMenu(e) {
-               if (e.className == 'menu hidden') {
-                       e.className = 'menu';
-               } else {
-                       e.className = 'menu hidden';
-               }
-       }
-
-       function initMenu() {
-               var Nodes = document.getElementsByTagName('ul');
-               var max = Nodes.length;
-               for (var i = 0; i < max; i++) {
-                       var nodeObj = Nodes.item(i);
-                       if (nodeObj.className.indexOf("menu") > -1 && nodeObj.id != "recom") {
-                               nodeObj.previousSibling.previousSibling.onclick = (function(node) {
-                                       return function() {
-                                               explodeMenu(node);
-                                       };
-                               })(nodeObj);
-                       }
-               }
-       }
-
-       (function(oldLoad) {
-               if (oldLoad == undefined) {
-                       window.onload = init;
-               } else {
-                       window.onload = function() {
-                               initMenu();
-                               oldLoad();
-                       }
-               }
-       })(window.onload);
-
-})();