Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Rough in UI for identifications; #449
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Apr 14, 2013
1 parent 11ab548 commit 6fe538f
Show file tree
Hide file tree
Showing 12 changed files with 253 additions and 103 deletions.
7 changes: 5 additions & 2 deletions branch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ BEGIN;
, ctime timestamp with time zone NOT NULL
, mtime timestamp with time zone NOT NULL
DEFAULT CURRENT_TIMESTAMP
, individual text NOT NULL REFERENCES participants
, member text NOT NULL REFERENCES participants
ON DELETE RESTRICT ON UPDATE CASCADE
, "group" text NOT NULL REFERENCES participants
ON DELETE RESTRICT ON UPDATE CASCADE
, weight numeric(17, 16) NOT NULL
, weight numeric DEFAULT 0.1
, identified_by text NOT NULL REFERENCES participants
ON DELETE RESTRICT ON UPDATE CASCADE
, CONSTRAINT no_member_of_self CHECK (member != "group")
, CONSTRAINT no_self_nomination CHECK (member != "identified_by")
, CONSTRAINT no_stacking_the_deck CHECK ("group" != "identified_by")
);

END;
1 change: 1 addition & 0 deletions gittip/csrf.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def inbound(request):
request_csrf_token = request.headers.get('X-CSRF-TOKEN', '')

if not constant_time_compare(request_csrf_token, csrf_token):
import ipdb; ipdb.set_trace()
raise Response(403, REASON_BAD_TOKEN)


Expand Down
5 changes: 5 additions & 0 deletions gittip/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ def get_age_in_seconds(self):
out = (now - self.claimed_time).total_seconds()
return out

def compute_split(self):
if self.type != 'open company':
return [{"username": self.username, "weight": "1.0"}]
pass


# TODO: Move these queries into this class.

Expand Down
68 changes: 48 additions & 20 deletions templates/gittip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -969,16 +969,16 @@ button.selected:hover {
}
}

#for {
#openco {

.fine {
font: normal 10px $Helvetica;
text-transform: uppercase;
}

#weeks {
margin-top: 10px;

.fine {
font: normal 10px $Helvetica;
text-transform: uppercase;
}

#this-week {
width: 220px;
float: left;
Expand All @@ -999,45 +999,73 @@ button.selected:hover {
}
}

#deserts {
width: 220px;
float: left;
TD {
padding-right: 0.5em;
}

#my-identifications {
width: 250px;
float: right;
position: relative;

::-webkit-input-placeholder { color: $light-brown; }
::-moz-placeholder { color: $light-brown; } /* firefox 19+ */
:-ms-input-placeholder { color: $light-brown; } /* ie */
input:-moz-placeholder { color: $light-brown; }

#query {
width: 110px;
width: 170px;
padding: 2px 5px;
z-index: 1;
position: relative;
top: 1px;
outline: none;
border: none;
}

#lookup-results-container {
.weight {
background: $green;
display: inline-block;
}
.weight.a { height: 24px; width: 24px; }
.weight.b { height: 12px; width: 12px; }
.weight.c { height: 6px; width: 6px }
.weight.d { height: 3px; width: 3px; }
.weight.e { height: 1px; width: 1px; }
.weight.f { height: 0.25px; width: 0.25px; }
.weight.g { background: red; width: 1px; height: 1px; }

#lookup-container {
position: relative;
vertical-align: middle;

#lookup-results {
width: 120px;
width: 188px;
min-height: 30px;
position: absolute;
bottom: 0px;
left: -128px;
bottom: -1px;
left: -4px;
background: white;
border: 2px solid black;
margin: 0;
padding: 5px;
padding: 2px 0;
border: 4px solid rgba($brown, 0.5);
color: $light-brown;
@include border-radius(3px);

li {
font: normal 16px/16px $Helvetica;
white-space: nowrap;
margin: 0;
padding: 3px 0;
padding: 3px 5px;
overflow: hidden;
}
}
}
}

#crowd {
width: 220px;
float: right;
text-align: right;
width: 180px;
float: left;
}

}
Expand Down
100 changes: 54 additions & 46 deletions templates/identifications.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
<script src="/assets/{{ __version__ }}/for.js"></script>
<script src="/assets/{{ __version__ }}/openco.js"></script>

<div id="for" ng-app="Gittip.for">
<div id="openco" ng-app="Gittip.openco">

<div id="weeks" class="group">
<div id="this-week">
{% set nbackers = participant.get_number_of_backers() %}
<h2>This Week</h2>
<div class="fine">Gittip will receive about</div>
<div class="amount">$100.00</div>
<div class="fine">from about 20 patrons</div>
<div class="amount">${{ participant.get_dollars_receiving() }}</div>
<div class="fine">from {{ nbackers }} patron{{ '' if nbackers == 1 else 's' }}</div>
</div>
<div id="last-week">
<h2>Last Week</h2>
Expand All @@ -19,53 +20,60 @@ <h2>Last Week</h2>
</div>
</div>

<div class="group">
<div id="deserts">
<h2>Who deserves it?</h2>
<div class="group" ng-controller="Gittip.openco.IdentificationsCtrl">
<div id="my-identifications">
<h2>Who does the most work?</h2>

<div ng-controller="Gittip.for.DesertsCtrl">
<table>
<tr ng-repeat="participant in participants">
<td>&#123;{ participant.username }}</td>
<td>
<input type="radio"
name="&#123;{ participant.username }}" />
<input type="radio"
name="&#123;{ participant.username }}" />
<input type="radio"
name="&#123;{ participant.username }}" />
<input type="radio"
name="&#123;{ participant.username }}" />
<input type="radio"
name="&#123;{ participant.username }}" />
</td>
</tr>
<tr>
<td>
<form ng-submit="submit()">
<input tabindex="1" id="query"
autocomplete="off"
placeholdey="Enter a Gittip username"
ng-model="query" ng-change="fetch()" />
</form>
</td>
<td id="lookup-results-container">
&nbsp;
<button>Add</button>
<p class="fine">This info is <b>private</b>.</p>

<ul id="lookup-results">
<li ng-repeat="participant in lookup">
<span>&#123;{ participant.username }}</span>
</li>
</ul>
</td>
</tr>
</table>
</div>
<table>
<tr ng-repeat="participant in identifications">
<td>&#123;{ participant.username }}</td>
<td>
<input type="radio"
name="weight-&#123;{ participant.username }}"
value="&#123;{ weight }}"
ng-repeat="weight in weights"
ng-model="participant.weight"
ng-change="change(participant, weight)"
/>
</td>
</tr>
<tr>
<td colspan="2" id="lookup-container">
<br />
<form ng-submit="doAdd()">
<input tabindex="1" id="query"
autocomplete="off"
placeholder="Enter a Gittip username"
ng-model="query"
ng-change="doLookup()"
/>&nbsp;&nbsp;<button type="submit"
tabindex="2">Add</button>
</form>
<ul id="lookup-results">
<li ng-repeat="participant in lookup">
<span>&#123;{ participant.username }}</span>
</li>
</ul>
</tr>
</table>
</div>

<div id="crowd">
<h2>Current split</h2>
<h2>Where it Goes.</h2>

<p class="fine">This info is <b>public</b>.</p>

<p class="fine">This is how the money is split. It is based on
everyone's vote for who does the most work.</p>

<table>
<tr ng-repeat="participant in identifications">
<td>&#123;{ participant.username }}</td>
<td>&#123;{ participant.weight}}</td>
</tr>
</table>
</div>
</div>

Expand Down
55 changes: 55 additions & 0 deletions www/%username/identifications.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Endpoint to record identifications
"""
from aspen import Response
from gittip import db
from gittip.utils import get_participant

# ================= ^L

request.allow('GET', 'POST')
participant = get_participant(request)
if user == participant:
raise Response(400)
if not participant.type == 'open company':
raise Response(400)

group = participant.username

if POST:
member = body['member']
weight = body['weight']
db.execute("""

INSERT
INTO identifications (ctime, member, "group", weight, identified_by)
VALUES ( COALESCE (( SELECT ctime
FROM identifications
WHERE member=%s
AND "group"=%s
LIMIT 1
), CURRENT_TIMESTAMP)
, %s
, %s
, %s
, %s
);

""", (member, group, member, group, weight, user.username))

identifications = db.fetchall("""

SELECT * FROM (
SELECT DISTINCT ON (member, "group", identified_by)
member AS username
, weight
FROM identifications
WHERE "group"=%s
AND identified_by=%s
ORDER BY member, "group", identified_by, mtime DESC
) AS anon WHERE weight > 0 ORDER BY weight DESC, username

""", (group, user.username))

response.body = { "identifications": list(identifications)
, "split": participant.compute_split()
}
6 changes: 5 additions & 1 deletion www/%username/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from gittip import AMOUNTS
from gittip.utils import get_participant, wrap

MAKING = "I am making the world better by"
MAKING = "making the world better by"
LONG_STATEMENT = 256

def _clip(text, n):
Expand All @@ -28,6 +28,10 @@
# pages
github_account, twitter_account, bitbucket_account = participant.get_accounts_elsewhere()
long_statement = len(participant.statement) > LONG_STATEMENT
if participant.type == 'individual':
MAKING = "I am " + MAKING
else:
MAKING = "We are " + MAKING

# ========================================================================== ^L
{% extends templates/profile.html %}
Expand Down
8 changes: 8 additions & 0 deletions www/%username/split.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Endpoint to record identifications
"""
from gittip.utils import get_participant

# ================= ^L

participant = get_participant(request, restrict=False)
response.body = participant.compute_split()
17 changes: 0 additions & 17 deletions www/assets/%version/for.js

This file was deleted.

2 changes: 1 addition & 1 deletion www/assets/%version/gittip.css

Large diffs are not rendered by default.

Loading

0 comments on commit 6fe538f

Please sign in to comment.