gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-backoffice] branch master updated (8fee152 -> ea4d0b


From: gnunet
Subject: [GNUnet-SVN] [taler-backoffice] branch master updated (8fee152 -> ea4d0bd)
Date: Thu, 07 Jun 2018 11:55:55 +0200

This is an automated email from the git hooks/post-receive script.

marcello pushed a change to branch master
in repository backoffice.

    from 8fee152  Use red bar to advertise 202s.
     new 465dac0  Still UI minor changes.
     new ea4d0bd  Polishing comments.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 js/backoffice.js                                   | 214 +++++++++------------
 .../backoffice/templates/backoffice.html           |   3 -
 2 files changed, 96 insertions(+), 121 deletions(-)

diff --git a/js/backoffice.js b/js/backoffice.js
index 9fd0bda..187ebf5 100644
--- a/js/backoffice.js
+++ b/js/backoffice.js
@@ -27,17 +27,41 @@
 */
 "use strict";
 
+/**
+ * The precision of the amount's fraction, when
+ * it comes objectified.
+ */
 var FRACTION = 100000000;
+
+/**
+ * Default 'start' URL argument used when querying for /history.
+ */
 var START = 0;
+
+/**
+ * Fixed 'delta' URL argument used when querying for /history.
+ */
 var DELTA = 5
+
+/**
+ * Row id of the _oldest_ /history record that's shown on the
+ * screen; will be used as the next 'delta' argument if scrolling
+ * down occurs.
+ */
 var LAST = 0;
+
+/**
+ * Flag controlling whether the scrolling of the page is enabled
+ * or not; for example, after /track/transfer results are shown
+ * on page, the semantics of "scrolling down towards older records"
+ * disappears because former results aren't arranged regarding of
+ * time.
+ */
 var SCROLL = true;
 
 /**
- * This function *could* "type check" 'amount',
- * but once 'amount' got here it is already "too late",
- * because this means that the merchant *backend* gave
- * it wrong.
+ * Convert Taler-compliant amount to human-friendly string.
+ * The amount may be both a string or object type.
  */
 function amount_to_string(amount){
   if (typeof amount === 'string' || amount instanceof String)
@@ -54,6 +78,12 @@ function amount_to_string(amount){
   return `${number.toFixed(2)} ${amount.currency}`;
 }
 
+
+/**
+ * Close the center-box that shows results from /track/transaction
+ * Note that this function first *empties* the results, and then
+ * closes the box.
+ */
 function close_popup(){
 
   var ctx = document.getElementsByClassName("track-content")[0];
@@ -67,18 +97,6 @@ function close_popup(){
   toggle_overlay(true);
 }
 
-function amount_sum(a1, a2){
-  if(a1.currency != a2.currency)
-    throw "Currency mismatch, terminating.";
-  var ret = {currency: a2.currency,
-             value: 0,
-             fraction: 0};
-  ret.value = a1.value + a2.value;
-  var fraction = a1.fraction + a2.fraction;
-  ret.value += Math.floor(fraction / FRACTION);
-  ret.fraction = fraction % FRACTION;
-  return ret;
-}
 
 /**
  * Parse Taler /Date(x)/ into human-friendly format.
@@ -105,7 +123,8 @@ function parse_date(date){
 
 /**
  * Make screen-centerd box (which show a order's tracks)
- * appear/disappear.
+ * appear/disappear.  Note, this function does NOT check if
+ * the box has content or not.
  */
 function toggle_overlay(force_close){
   var overlay = document.getElementsByClassName("overlay")[0];
@@ -122,8 +141,8 @@ function toggle_overlay(force_close){
 }
 
 /**
- * Draws a line at the bottom of a orders list to indicate
- * they have all being paid out by the same WTID.
+ * Draws a line at the bottom of a orders list to
+ * indicate they have all being paid out by the same WTID.
  */
 function make_marker(wtid){
   var tr = document.createElement("tr");
@@ -141,16 +160,15 @@ function make_marker(wtid){
 /**
  * Use the /track/transfer API from the frontend.  Once data
  * arrives, it calls a UI function which lists all the entries
- * in the page.
- *
- * 'cb' is a UI transforming function.  Typically, it is set to
- * 'fill_table()'.
+ * in the page.  Results will be shown in the same style of
+ * /history's.
  */
 var track_transfer = function(exchange, wtid, cb){
-  /* Remove any previous errors, if there are any.  */
+
+  /* Remove potential information bar.  */
   var info_bar = document.getElementById("information-bar");
   info_bar.style.visibility = "hidden"; 
-  /* Will be untoggled by the 'cb' */
+
   toggle_loader();
   var qs = `/track/transfer?` +
            `exchange=${exchange}&` +
@@ -169,9 +187,9 @@ var track_transfer = function(exchange, wtid, cb){
          * results: older than what?  The scroll feature will
          * be re-enabled from the /history callback.  */
         SCROLL = false;
+        clear_results();
         var tracks = JSON.parse(req.responseText);
-        cb(false,
-           tracks.deposits_sums,
+        cb(tracks.deposits_sums,
            tracks.execution_time,
            wtid);
         break;
@@ -184,8 +202,10 @@ var track_transfer = function(exchange, wtid, cb){
 }
 
 
-/* Fill the information bar on the top of the page with
- * error messages.  */
+/**
+ * Fill the information bar on the top of the page with
+ * error messages.  The same orange bar is used for warnings.
+ */
 var show_warning;
 var show_error = show_warning = function(response_text){
 
@@ -208,27 +228,22 @@ var show_error = show_warning = function(response_text){
     console.log("Must keep raw response");
   }
   
-  /* msg is ready here.  */
-
   /* Get hold of the info bar.  */
   var info_bar = document.getElementById("information-bar");
   info_bar.innerHTML = `<p>${msg}</p>`; 
   info_bar.style.visibility = "visible"; 
-
-  /* Info bar will disappear at next page load/reload.  */
 }
 
 /**
- * Call /track/order API offered by the frontend.  Once data
- * arrives it calls a UI routine which fills the "entries table"
- * in the page.
+ * Call /track/order API offered by the frontend.  It will make
+ * results shown in a centered box that overlays the page.
  */
 var track_order = function(order_id, cb){
   
-  /* Remove any previous errors, if there are any.  */
+  /* Remove potential information bar.  */
   var info_bar = document.getElementById("information-bar");
   info_bar.style.visibility = "hidden"; 
-  /* Will be untoggled by the 'cb' */
+
   toggle_loader();
   var req = new XMLHttpRequest();
   var url = `/track/order?` +
@@ -249,6 +264,8 @@ var track_order = function(order_id, cb){
 
 /**
  * Fill the screen-centered box with data from /track/order.
+ * This box will overlay the ordinary page, and disappear when
+ * the user clicks the close button or Esc key.
  */
 function fill_box(tracks, http_code)
 {
@@ -267,6 +284,7 @@ function fill_box(tracks, http_code)
   }
 
   if(!tracks)
+    show_error("/track/transfer returned EMPTY!  Very bad.");
     console.log("Got invalid JSON");
     if(0 == tracks.length || !tracks.length){
       console.log(`Got no tracks and status == ${http_code}.  ` +
@@ -277,12 +295,6 @@ function fill_box(tracks, http_code)
 
   for(var i=0; i<tracks.length; i++){
     var entry = tracks[i];
-    /**
-     * 'track_content' contains the tracks (WTID/Amount/Date)
-     * about *one* order.  It is contained in the 'overlay',
-     * which renders it in a "box" in the middle of the
-     * screen.  This "box" is then toggleable as visible/hidden.
-     */
     var overlay = document.getElementsByClassName("overlay")[0];
     var track_content = document.getElementsByClassName
       ("track-content")[0];
@@ -328,57 +340,17 @@ function xpath_get(xpath, ctx){
   return ret;
 }
 
+
 /**
- * Modify the table showing orders.  Those orders could be
- * either from /history or /track/transfer.  If data is _not_
- * to be appended to previous results in the table, this
- * function will erase previous results and either show new
- * data or make the "no results" message available.  Otherwise,
- * it will just append data to what already exists in the table.
- *
- * Data is non-appending if (1) the page has been (re)loaded,
- * (2) the user queried /track/transfer, (3) the user changed
- * the instance being tracked.  Those 1-3 cases will all have
- * the 'refresh' parameter set to true.
- *
- * 'wtid_marker' - set to <WTID> - serves to show a line at the
- * bottom of the lines being added in the table which indicates
- * that all those entries - orders - have been paid out by the
- * same WTID.
- *
- * FIXME: 'execution_time' is a problematic field: when showing
- * /history results, it shows the order timestamp.  When instead
- * /track/tranfer results are being shown, it indicates the time
- * the exchange wire transferred this order's amount.
+ * Fill the page with orders rows.
  */
-function fill_table(scroll, data, execution_time, wtid_marker){
+function fill_table(data, execution_time, wtid_marker){
   var table = document.getElementById("history");
   var tbody = xpath_get("tbody", table).snapshotItem(0);
-  var nr = xpath_get("address@hidden'no-records']", tbody)
-  .snapshotItem(0)
-
-  /* not append data, erase!  */
-  if (!scroll){
-    clear_results();
-    if(0 == data.length){
-      /* make NO RESULTS visible and hide tab headers */
-      nr.style.display = "block";
-      xpath_get("address@hidden'headers']", tbody)
-        .snapshotItem(0).style.visibility = "hidden";
-      toggle_loader();
-      console.log("Nothing gotten!");
-      return;
-    }
-  }
-
-  /* hide "no records" message */
-  nr.style.display = "none";
 
-  /* Make table's header visible */
+  /* Make table visible, if it's hidden.  */
   xpath_get("address@hidden'headers']", tbody)
     .snapshotItem(0).style.visibility = "visible";
-  /* Will only be effective on page first load; afterwards
-   * it is just idempotent.  */
   table.style.visibility = "visible";
 
   for (var i=0; i<data.length; i++){
@@ -425,8 +397,7 @@ function fill_table(scroll, data, execution_time, 
wtid_marker){
 }
 
 /**
- * Make the spinning wheel appear if it is not shown,
- * and viceversa.
+ * Make the spinning wheel appear/disappear.
  */
 function toggle_loader(){
   var loader = document.getElementsByClassName("loader")[0]; 
@@ -445,7 +416,7 @@ function toggle_loader(){
 /**
  * Issue a /track/order (/track/transfer) depending on
  * whether the user selected "order" ("transfer") on the
- * given form.
+ * dedicated form.
  */
 function track_cherry_pick(form){
   var types = xpath_get("address@hidden'radio']", form);
@@ -468,17 +439,7 @@ function track_cherry_pick(form){
 }
 
 /**
- * The "cherry pick" form allows the user to track a particular
- * order or wire transfer by entering its "id" in the input field.
- *
- * The UI is such that a radio button can switch the form "type"
- * to query for a order or for a wire transfer;  the following two
- * functions help to switch the form appearance according to this
- * order/wire-transfer switch.
- */
-
-/**
- * Make the "cherry pick" form be suitable to query /track/order.
+ * Make the /track/order form visible.
  */
 function cherry_pick_form_order(form){
   var input_order = xpath_get("address@hidden'order']", form)
@@ -490,7 +451,7 @@ function cherry_pick_form_order(form){
 }
 
 /**
- * Make the "cherry pick" form be suitable to query /track/transfer.
+ * Make the /track/transaction form visible.
  */
 function cherry_pick_form_transfer(form){
   var input_order = xpath_get("address@hidden'order']", form)
@@ -502,7 +463,7 @@ function cherry_pick_form_transfer(form){
 }
 
 /**
- * Retrieve current istance being tracked.
+ * Retrieve the selected instance.
  */
 function get_instance(){
   var select = document.getElementById("instance");
@@ -510,20 +471,26 @@ function get_instance(){
 }
 
 /**
- * Remove tracks from the main page table, but do NOT remove
- * the table headers
+ * Remove tracks from the main page table, but
+ * do NOT remove the table headers; it hides them though.
  */
 function clear_results(){
   var table = document.getElementById("history");
   var tbody = xpath_get("tbody", table).snapshotItem(0);
-  var tbody_children = xpath_get("tbody/*[position() > 2]", table);
+  var tbody_children = xpath_get("tbody/*[position() > 1]", table);
   for(var i=0; i<tbody_children.snapshotLength; i++){
     tbody.removeChild(tbody_children.snapshotItem(i));
   }
+
+  xpath_get("address@hidden'headers']", tbody)
+    .snapshotItem(0).style.visibility = "hidden";
+
 }
+
+
 /**
- * Nullify curreny instance and triggers history for newly
- * selected one.
+ * Make the instance selected effective.  In particular, it
+ * triggers history retrieval for it.
  */
 function change_instance(){
   /* Restore values.  Changing instance should have
@@ -540,13 +507,7 @@ function change_instance(){
 }
 
 /**
- * If 'scroll' is true, the logic tries to retrieve the
- * "next page" of all the proposals known to the merchant.
- * Otherwise, it gets the merchant's history from the beginning
- * of their business.
- *
- * 'cb' is a UI transforming function.  Typically, it is set
- * to 'fill_table()'.
+ * Query the /history API.
  */
 function get_history(scroll, cb){
   SCROLL = true;
@@ -567,11 +528,15 @@ function get_history(scroll, cb){
           console.log("Got invalid JSON");
           return;
         }
+        if (0 == history.length){
+          show_warning("No records found!"); 
+          return;
+        }
         if(0 < history.length){
           console.log(history);
           LAST = history[history.length - 1].row_id;
+          cb(history);
         }
-        cb(scroll, history);
       }
       else{
         console.log("error: status != 200");
@@ -583,11 +548,18 @@ function get_history(scroll, cb){
   req.send();
 }
 
+/**
+ * Trigger /history as soon as the page loads.
+ */
 document.addEventListener
   ("DOMContentLoaded",
    function(){
      get_history(false, fill_table);});
 
+/**
+ * Implement scrolling down of history.  When the user
+ * scrolls down, older results from /history will be requested.
+ */
 document.addEventListener
   ("scroll", function(){
   /* If page bottom is hit */
@@ -596,7 +568,10 @@ document.addEventListener
     get_history(true, fill_table);
   });
 
-/* Close dialog on ESC press */
+/**
+ * Close the centered box that (typically) shows /track/transfer
+ * results.
+ */
 document.onkeydown = function(e) {
   if(!e)
     e = event;
@@ -605,6 +580,9 @@ document.onkeydown = function(e) {
   }
 }
 
+/**
+ * export functions to be tested by AVA.
+ */
 if (typeof(module) != "undefined"){
   module.exports.track_transfer = track_transfer;
   module.exports.track_order = track_order;
diff --git a/talerbackoffice/backoffice/templates/backoffice.html 
b/talerbackoffice/backoffice/templates/backoffice.html
index d904531..bccdcc4 100644
--- a/talerbackoffice/backoffice/templates/backoffice.html
+++ b/talerbackoffice/backoffice/templates/backoffice.html
@@ -51,9 +51,6 @@
       <col width="40">
       <col width="40">
       <tbody>
-        <tr class="no-records">
-          <th colspan="3">No records found</th>
-        </tr>
         <tr class="headers" style="visibility: hidden">
           <th class="order-id">Order ID</th>
           <th class="amount">Amount</th>

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]