[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-merchant-frontends] 02/02: Donations backoffice most
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-merchant-frontends] 02/02: Donations backoffice mostly done. |
Date: |
Wed, 01 Mar 2017 20:27:43 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository merchant-frontends.
commit 7194d369657c81af5081ff20606c655303c406c8
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Mar 1 20:27:13 2017 +0100
Donations backoffice mostly done.
---
talerfrontends/blog/blog.py | 2 +-
talerfrontends/blog/static/backoffice.js | 48 +++++---------
talerfrontends/blog/templates/backoffice.html | 6 +-
talerfrontends/blog/templates/base.html | 2 +-
talerfrontends/donations/donations.py | 39 ++++++++++-
.../{blog => donations}/static/backoffice.js | 75 +++++++++------------
talerfrontends/donations/static/popup.css | 77 ++++++++++++++++++++++
.../{blog => donations}/templates/backoffice.html | 6 +-
talerfrontends/donations/templates/base.html | 1 +
9 files changed, 172 insertions(+), 84 deletions(-)
diff --git a/talerfrontends/blog/blog.py b/talerfrontends/blog/blog.py
index e7cd8a7..8a0e6c7 100644
--- a/talerfrontends/blog/blog.py
+++ b/talerfrontends/blog/blog.py
@@ -21,7 +21,7 @@ Implement URL handlers and payment logic for the blog
merchant.
"""
import flask
-from urllib.parse import urljoin, urlencode, quote, parse_qsl, urlsplit
+from urllib.parse import urljoin, urlencode, quote, parse_qsl
import requests
import logging
import os
diff --git a/talerfrontends/blog/static/backoffice.js
b/talerfrontends/blog/static/backoffice.js
index fe1e7e5..62686fe 100644
--- a/talerfrontends/blog/static/backoffice.js
+++ b/talerfrontends/blog/static/backoffice.js
@@ -120,16 +120,21 @@ function track_order(order_id, instance){
req.send();
}
+function xpath_get(xpath, ctx){
+ var ret = document.evaluate(xpath,
+ ctx,
+ null,
+ XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
+ null);
+ return ret.snapshotItem(0);
+}
+
/**
* Append results to the table showing results.
*/
function fill_table(history){
var table = document.getElementById("history");
- var tbody = document.evaluate("tbody",
- table,
- null,
- XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
- null).snapshotItem(0);
+ var tbody = xpath_get("tbody", table);
for (var i=0; i<history.length; i++){
var entry = history[i];
var row = document.createElement("tr");
@@ -156,12 +161,11 @@ function fill_table(history){
window.setTimeout(remove_loader, 900);
}
-function get_more_history(){
- /*FIXME: do add one week to TIMESTAMP*/
- START += 20;
-
+function get_history(scroll){
var loader = document.getElementsByClassName("loader")[0];
loader.style.visibility = "visible";
+ if(scroll)
+ START += 20;
var req = new XMLHttpRequest();
req.open("GET",
`/history?timestamp=${TIMESTAMP}&instance=${INSTANCE}&start=${START}`, true);
req.onload = function(){
@@ -180,27 +184,5 @@ function get_more_history(){
req.send();
}
-function get_history(){
-
- var req = new XMLHttpRequest();
- req.open("GET", `/history?timestamp=${TIMESTAMP}&instance=${INSTANCE}`,
true);
- req.onload = function(){
- if(req.readyState == 4 && req.status == 200){
- var history = JSON.parse(req.responseText);
- if(!history)
- console.log("Got invalid JSON");
- if(0 == history.length){
- console.log("Got no transactions");
- return;
- }
- fill_table(history);
- }
- else{
- console.log("error: status != 200");
- }
- }
- req.send();
-}
-
-document.addEventListener("DOMContentLoaded", get_history);
-document.addEventListener("scroll", get_more_history);
+document.addEventListener("DOMContentLoaded", () => get_history(false));
+document.addEventListener("scroll", () => get_history(true));
diff --git a/talerfrontends/blog/templates/backoffice.html
b/talerfrontends/blog/templates/backoffice.html
index c57e213..719d4b6 100644
--- a/talerfrontends/blog/templates/backoffice.html
+++ b/talerfrontends/blog/templates/backoffice.html
@@ -34,9 +34,13 @@
</div>
</div>
</div>
- <a href="#" onclick="get_more_history();" style="margin-left: 90%;">Fake
scroll</a>
+ <a href="#" onclick="get_history(true);" style="margin-left: 90%;">Fake
scroll</a>
{% endblock main %}
+{% block styles %}
+ <link rel="stylesheet" type="text/css" href="{{ url("/static/popup.css") }}">
+{% endblock styles %}
+
{% block scripts %}
<script src="{{ url('/static/backoffice.js') }}"
type="application/javascript"></script>
{% endblock scripts %}
diff --git a/talerfrontends/blog/templates/base.html
b/talerfrontends/blog/templates/base.html
index 140222a..d65d14b 100644
--- a/talerfrontends/blog/templates/base.html
+++ b/talerfrontends/blog/templates/base.html
@@ -20,10 +20,10 @@
<link rel="stylesheet" type="text/css" href="{{
url("/static/web-common/style.css") }}">
<link rel="stylesheet" type="text/css" href="{{
url("/static/web-common/lang.css") }}">
<link rel="stylesheet" type="text/css" href="{{
url("/static/web-common/taler-fallback.css") }}" id="taler-presence-stylesheet">
- <link rel="stylesheet" type="text/css" href="{{ url("/static/popup.css") }}">
<script src="{{ url("/static/web-common/taler-wallet-lib.js") }}"
type="application/javascript"></script>
<script src="{{ url("/static/web-common/lang.js") }}"
type="application/javascript"></script>
<meta http-equiv="content-type" content="text/html;CHARSET=utf-8">
+ {% block styles %}{% endblock %}
{% block scripts %}{% endblock %}
</head>
diff --git a/talerfrontends/donations/donations.py
b/talerfrontends/donations/donations.py
index 7c18aac..25e7c34 100644
--- a/talerfrontends/donations/donations.py
+++ b/talerfrontends/donations/donations.py
@@ -16,7 +16,7 @@
# @author Marcello Stanisci
import flask
-from urllib.parse import urljoin, urlencode, quote
+from urllib.parse import urljoin, urlencode, quote, parse_qsl
import requests
import logging
import os
@@ -31,7 +31,7 @@ from talerfrontends.errors import BackendError
from talerfrontends.helpers import (make_url,
expect_parameter, amount_to_string,
amount_from_float, amount_to_float,
-join_urlparts)
+join_urlparts, get_query_string)
logger = logging.getLogger(__name__)
@@ -177,3 +177,38 @@ def pay():
def track():
response =
flask.make_response(flask.render_template("templates/backoffice.html"))
return response
+
+
address@hidden("/history")
+def history():
+ # FIXME now JS needs to give a *timestamp*, NOT
+ # days anymore..
+ qs = get_query_string().decode("utf-8")
+ url = urljoin(BACKEND_URL, "history")
+ r = requests.get(url, params=dict(parse_qsl(qs)))
+ if r.status_code != 200:
+ logger.error("failed to GET to '%s'", url)
+ raise BackendError(r.status_code, r.text)
+ return r.text
+
address@hidden("/track/order")
+def track_order():
+
+ instance = expect_parameter("instance")
+ order_id = expect_parameter("order_id")
+
+ url = urljoin(BACKEND_URL, 'track/transaction')
+ r = requests.get(url, params=dict(order_id=order_id, instance=instance))
+
+ if r.status_code not in [200, 202, 424]:
+ logger.error("failed to GET to '%s'", url)
+ raise BackendError(r.status_code, r.text)
+ if 202 == r.status_code:
+ return flask.jsonify(r.json()), 202
+ if 404 == r.status_code:
+ raise CustomError(r.code, "Unknown order_id", s.status_code)
+ if 424 == r.status_code:
+ raise TrackTransactionConflictError(r.status_code, order_id, r.text)
+
+ return flask.jsonify(r.json())
+
diff --git a/talerfrontends/blog/static/backoffice.js
b/talerfrontends/donations/static/backoffice.js
similarity index 79%
copy from talerfrontends/blog/static/backoffice.js
copy to talerfrontends/donations/static/backoffice.js
index fe1e7e5..f7a2003 100644
--- a/talerfrontends/blog/static/backoffice.js
+++ b/talerfrontends/donations/static/backoffice.js
@@ -30,7 +30,7 @@
var FRACTION = 100000000;
var TIMESTAMP = 0;
var START = 0;
-var INSTANCE = "FSF";
+var INSTANCES = ["GNUnet", "Tor", "Taler"];
function amount_to_string(amount){
var number = Number(amount.value) + (Number(amount.fraction)/FRACTION);
@@ -71,6 +71,15 @@ function track_transfer(wtid){
console.log("Tracking", wtid);
}
+function xpath_get(xpath, ctx){
+ var ret = document.evaluate(xpath,
+ ctx,
+ null,
+ XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
+ null);
+ return ret.snapshotItem(0);
+}
+
function track_order(order_id, instance){
var req = new XMLHttpRequest();
req.open("GET", `/track/order?order_id=${order_id}&instance=${instance}`,
true);
@@ -88,11 +97,7 @@ function track_order(order_id, instance){
var entry = tracks[i];
var overlay = document.getElementsByClassName("overlay")[0];
var track_content =
document.getElementsByClassName("track-content")[0];
- var table = document.evaluate("table/tbody",
- track_content,
- null,
- XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
- null).snapshotItem(0);
+ var table = xpath_get("table/tbody", track_content);
toggle_visible(overlay);
for(var j=0; j<entry.coins.length; j++){
var coin = entry.coins[j];
@@ -156,51 +161,31 @@ function fill_table(history){
window.setTimeout(remove_loader, 900);
}
-function get_more_history(){
- /*FIXME: do add one week to TIMESTAMP*/
- START += 20;
-
+function get_history(scroll){
var loader = document.getElementsByClassName("loader")[0];
loader.style.visibility = "visible";
- var req = new XMLHttpRequest();
- req.open("GET",
`/history?timestamp=${TIMESTAMP}&instance=${INSTANCE}&start=${START}`, true);
- req.onload = function(){
- if(req.readyState == 4 && req.status == 200){
- var history = JSON.parse(req.responseText);
- if(!history){
- console.log("Got invalid JSON");
- return;
+ if(scroll)
+ START +=20;
+ var req = new Array(3);
+ for(var i=0; i<INSTANCES.length; i++){
+ req[i] = new XMLHttpRequest();
+ req[i].open("GET",
`/history?timestamp=${TIMESTAMP}&instance=${INSTANCES[i]}&start=${START}`,
true);
+ req[i].onload = function(){
+ if(this.readyState == 4 && this.status == 200){
+ var history = JSON.parse(this.responseText);
+ if(!history){
+ console.log("Got invalid JSON");
+ return;
+ }
+ fill_table(history);
}
- fill_table(history);
- }
- else{
- console.log("error: status != 200");
- }
- }
- req.send();
-}
-
-function get_history(){
-
- var req = new XMLHttpRequest();
- req.open("GET", `/history?timestamp=${TIMESTAMP}&instance=${INSTANCE}`,
true);
- req.onload = function(){
- if(req.readyState == 4 && req.status == 200){
- var history = JSON.parse(req.responseText);
- if(!history)
- console.log("Got invalid JSON");
- if(0 == history.length){
- console.log("Got no transactions");
- return;
+ else{
+ console.log("error: status != 200");
}
- fill_table(history);
- }
- else{
- console.log("error: status != 200");
}
+ req[i].send();
}
- req.send();
}
document.addEventListener("DOMContentLoaded", get_history);
-document.addEventListener("scroll", get_more_history);
+document.addEventListener("scroll", () => get_history(true));
diff --git a/talerfrontends/donations/static/popup.css
b/talerfrontends/donations/static/popup.css
new file mode 100644
index 0000000..4e3afcd
--- /dev/null
+++ b/talerfrontends/donations/static/popup.css
@@ -0,0 +1,77 @@
+.overlay {
+ position: fixed;
+ top: 0;
+ bottom: 0;
+ left: 0;
+ right: 0;
+ background: rgba(0, 0, 0, 0.7);
+ transition: opacity 500ms;
+ visibility: hidden;
+ opacity: 0;
+ z-index: 2;
+}
+
+.popup {
+ margin: 70px auto;
+ padding: 20px;
+ background: #fff;
+ border-radius: 5px;
+ position: relative;
+ transition: all 5s ease-in-out;
+ left: 50%;
+ top: 20%;
+ transform: translate(-50%, -50%);
+ display: inline-block;
+}
+
+.popup h2 {
+ margin-top: 0;
+ color: #333;
+ font-family: Tahoma, Arial, sans-serif;
+}
+.popup .close {
+ position: absolute;
+ top: 10px;
+ right: 30px;
+ transition: all 200ms;
+ font-size: 30px;
+ font-weight: bold;
+ text-decoration: none;
+ color: #333;
+}
+.popup .close:hover {
+ color: #06D85F;
+}
+.popup .track-content {
+ max-height: 30%;
+ overflow: auto;
+ display: inline-block;
+}
+
+th {
+ text-align: left;
+}
+
address@hidden screen and (max-width: 700px){
+ .box{
+ width: 70%;
+ }
+ .popup{
+ width: 70%;
+ }
+}
+
+.loader {
+ margin-left: 30%;
+ border: 7px solid #f3f3f3; /* Light grey */
+ border-top: 7px solid #696969; /* Blue */
+ border-radius: 50%;
+ width: 40px;
+ height: 40px;
+ animation: spin 2s linear infinite;
+}
+
address@hidden spin {
+ 0% { transform: rotate(0deg); }
+ 100% { transform: rotate(360deg); }
+}
diff --git a/talerfrontends/blog/templates/backoffice.html
b/talerfrontends/donations/templates/backoffice.html
similarity index 83%
copy from talerfrontends/blog/templates/backoffice.html
copy to talerfrontends/donations/templates/backoffice.html
index c57e213..719d4b6 100644
--- a/talerfrontends/blog/templates/backoffice.html
+++ b/talerfrontends/donations/templates/backoffice.html
@@ -34,9 +34,13 @@
</div>
</div>
</div>
- <a href="#" onclick="get_more_history();" style="margin-left: 90%;">Fake
scroll</a>
+ <a href="#" onclick="get_history(true);" style="margin-left: 90%;">Fake
scroll</a>
{% endblock main %}
+{% block styles %}
+ <link rel="stylesheet" type="text/css" href="{{ url("/static/popup.css") }}">
+{% endblock styles %}
+
{% block scripts %}
<script src="{{ url('/static/backoffice.js') }}"
type="application/javascript"></script>
{% endblock scripts %}
diff --git a/talerfrontends/donations/templates/base.html
b/talerfrontends/donations/templates/base.html
index 32dbad7..0d02b11 100644
--- a/talerfrontends/donations/templates/base.html
+++ b/talerfrontends/donations/templates/base.html
@@ -22,6 +22,7 @@
<link rel="stylesheet" type="text/css" href="{{
url("/static/web-common/lang.css") }}">
<script src="{{ url("/static/web-common/taler-wallet-lib.js") }}"
type="application/javascript"></script>
<script src="{{ url("/static/web-common/lang.js") }}"
type="application/javascript"></script>
+ {% block styles %}{% endblock %}
{% block scripts %}{% endblock %}
</head>
--
To stop receiving notification emails like this one, please contact
address@hidden