summaryrefslogtreecommitdiffstats
path: root/bitvend/templates/index.html
blob: 1960b67b93eb93452df06201ca04d8390d437b14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
{% extends "base.html" %}

{% from "_helpers.html" import format_currency, render_field, render_submit %}

{% block content %}
  {% if not mdb_online or not proc_online %}
  <div class="alert alert-warning">
      <b>Some of the subsystems are misbehaving.</b> Please avoid making payments, unless in absolute need of Mate.
  </div>
  {% endif %}

  {% if current_user.is_authenticated %}
  <div class="row">
      <div class="col-sm-4">
          <div class="well text-right">
              <h3><small class="pull-left">Balance</small> <small>{{ format_currency(current_user.amount_available) }} / </small> {{ format_currency(current_user.balance) }}</h3>
          </div>

          <div class="well text-right">
              <h3><small class="pull-left">Transactions</small> {{ current_user.transactions.count() }}</h3>
          </div>

          <div class="well">
            <p class="text-muted">Use the keypad to select a product.</p>
          {% if current_transaction %}
              <a href="{{ url_for('.cancel') }}" class="btn btn-danger btn-block btn-lg">Cancel transaction
                  {% if current_transaction.user != current_user %}
                      <small>(by {{ current_transaction.user }})</small>
                  {% endif %}
              </a>
          {% else %}
              <a href="{{ url_for('.begin') }}" class="btn btn-primary btn-block btn-lg">Begin transaction</a>
          {% endif %}
          </div>

          <form action="{{ url_for('.transfer') }}" method="POST" class="well">
              {{ transfer_form.hidden_tag() }}
              <div class="form-group">
                  <input type="input" class="form-control" name="target" placeholder="target username" />
              </div>
              <div class="form-group">
              <div class="input-group">
                  <input type="number" class="form-control" min="0" name="amount" placeholder="0.00" step="any" />
                  <span class="input-group-btn">
                      <button class="btn btn-info">Transfer</button>
                  </span>
              </div>
              </div>
          </form>

          <h3 class="page-header">Hall of Shame</h3>
          <table class="table table-hover table-striped">
              <thead><tr>
                  <th>Name</th><th class="text-right">Balance</th>
              </tr></thead>
              {% for user in hallofshame %}
              <tr><td>{{ user }}</td><td class="text-right">{{ format_currency(user.balance) }}</td></tr>
              {% else %}
              <tr><td colspan=2 class="placeholder">Wow! Nobody's due!</td></tr>
              {% endfor %}
          </table>

          <h3 class="page-header">Hall of Addicts</h3>
          <table class="table table-hover table-striped">
              <thead><tr>
                  <th>Name</th><th class="text-right">Amount</th><th>Purchases</th>
              </tr></thead>
              {% for user in hallofaddicts %}
              <tr><td>{{ user }}</td><td class="text-right">{{ format_currency(user.purchase_amount) }}</td><td>{{ user.purchase_count }}</td></tr>
              {% else %}
              <tr><td colspan=3 class="placeholder">Huh?</td></tr>
              {% endfor %}
          </table>
      </div>
      <div class="col-sm-8">
          <h3 class="page-header">Latest transactions</h3>
          <table class="table table-hover table-striped">
              <thead>
                  <tr>
                      <th>Type</th>
                      <th class="text-right">Amount</th>
                      <th>Date</th>
                  </tr>
              </thead>

              {% for tx in transactions %}
                  <tr{% if not tx.finished %} style="opacity: 0.5"{% endif %}>
                      <td>
                          {{ tx.type }} {% if not tx.finished %}<i>(processing)</i>{% endif %}
                          <small>
                          {% if tx.type == 'transfer' and tx.amount > 0 %}
                              from <b>{{ tx.related }}</b>
                          {% elif tx.type == 'transfer' and tx.amount < 0 %}
                              to <b>{{ tx.related }}</b>
                          {% elif tx.type == 'purchase' and tx.product_id %}
                              of product <b>{{ tx.product_id }}</b>
                          {% endif %}
                          </small>
                      </td>
                      <td class="text-right">{{ format_currency(tx.amount) }}</td>
                      <td>{{ tx.created }}</td>
                  </tr>
              {% else %}
                  <tr><td colspan=3 class="placeholder">Nothing to see here...</td></tr>
              {% endfor %}
              {% if transactions.count() == 10 %}
                  <tr><td colspan=3 class="placeholder">
                          <a href="{{ url_for('.transactions') }}" class="btn btn-block">See more...</a>
                      </td></tr>
              {% endif %}
          </table>
      </div>
  </div>
  <hr>
  {% endif %}

  <h3 class="page-header">
      Bitcoin payments
      <small>Send suggested transaction and use the keypad to select a product</small>
  </h3>

  <div class="alert alert-info">
      This is just a test deployment of Warsaw Hackerspace Vending Machine Bitcoin Payments System™.
      <b>Please report any issues to <a href="mailto:informatic@hackerspace.pl" class="alert-link">informatic@hackerspace.pl</a>.</b>
  </div>

  <div class="row">
  {% for item in items %}
  <div class="col-md-6">
      <div class="well vend-item">
          <div class="row">
              <div class="col-md-12">
                  <div class="pull-right">
                      <span class="label label-info">{{ format_currency(item.value) }}</span>
                      <span class="label label-primary">{{ format_btc(from_local_currency(item.value*1.03)) }}</span>
                  </div>
                  <h3>{{ item.name }}</h3>
              </div>
              <div class="col-xs-6">
                  <img src="{{ item.image }}"  class="img-responsive center-block" />
              </div>
              <div class="col-xs-6 text-center">
                  {% with btc_uri = 'bitcoin:%s?amount=%s' % (config['INPUT_ADDRESS'], sat_to_btc(from_local_currency(item.value*1.03))) %}
                  <a href="{{ btc_uri }}">
                      <img src="{{ qrcode(btc_uri) }}" class="img-responsive center-block"/>
                      <code><small>{{ config['INPUT_ADDRESS'] }}</small></code>
                  </a>
                  {% endwith %}
              </div>
          </div>
      </div>
  </div>
  {% endfor %}
  </div>
  <div class="row">
      <div class="col-md-6 col-md-offset-2">
          <div id="purchases"></div>
      </div>
      <div class="col-md-2">
          <div class="well text-center">
              <h3>{{ bottles_purchased * 105 }}mg</h3>
              <small>Caffeine ingested</small>
          </div>
          <div class="well text-center">
              <h3>{{ bottles_purchased }}</h3>
              <small>Bottles purchased</small>
          </div>
      </div>
  </div>

  <blockquote class="blockquote-reverse">
      <p>Kowalski czuje zapach pieniędzy.</p>
      <small>Someone famous</small>
  </blockquote>
{% endblock %}

{% block tail_js %}
<script>
d3.json('/api/1/history.json', function(data) {
    data = MG.convert.date(data, 'date');
    MG.data_graphic({
        title: "Purchases",
        data: data,
        height: 200,
        full_width: true,
        target: document.getElementById('purchases'),
        x_accessor: 'date',
        y_accessor: 'purchases'
    });
});
</script>
{% endblock %}