Skip to content

Commit

Permalink
Single user view filters out wants and haves for a single user
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWingard committed Nov 9, 2010
1 parent d219eb1 commit d673dcd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
25 changes: 22 additions & 3 deletions site/src/index.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ body() ->
#panel{id = content, body = content()}].

content() ->
[#panel{id = wtts, body = [card(C) || C <- umts_db:all_wtts()]}].
[#panel{id = wtts, body = wtts()}].

search() ->
[#textbox{id = search, postback = search},
Expand Down Expand Up @@ -51,7 +51,21 @@ handle_event({wtt, Callback, Id}) ->
Card = card(umts_db:get_card(Id)),
wf:replace("srch" ++ Id, Card#panel{id = "srch" ++ Id}),
%% TODO: Do we really need to redraw everything here?
wf:update(wtts, [card(C) || C <- umts_db:all_wtts()]).
wf:update(wtts, wtts()).

wtts() ->
case catch list_to_integer(wf:path_info()) of
UserID when is_integer(UserID) ->
User = umts_db:get_user(UserID),
[#h1{text = User#users.display},
#link{text = "Show all", url = "index" },
#h2{text = "Wants:"},
[card(C) || C <- umts_db:user_wtts(UserID, #wtts.wanters)],
#h2{text = "Haves:"},
[card(C) || C <- umts_db:user_wtts(UserID, #wtts.havers)]];
_ ->
[card(C) || C <- umts_db:all_wtts()]
end.

card(Card) ->
Id = Card#cards.id,
Expand Down Expand Up @@ -84,4 +98,9 @@ tooltip(Prefix, Title, Wtt, Postback) ->
#panel{class= "wtt2",
body = [#link{text = [Prefix, integer_to_list(length(Wtt))], postback = Postback},
#panel{body = [#h3{text = Title},
#list{body = [#listitem{text = (umts_db:get_user(U))#users.name} || U <- Wtt]}]}]}.
#list{body = lists:map(fun(UserID) ->
User = umts_db:get_user(UserID),
#listitem{body = #link{text = User#users.display,
url = "/index/" ++ integer_to_list(User#users.id)}}
end,
Wtt)}]}]}.
25 changes: 25 additions & 0 deletions site/src/umts_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ create_tables() ->
{atomic, ok} = mnesia:create_table(cards, [{attributes, record_info(fields, cards)}, {disc_copies,[node()]}]),
{atomic, ok} = mnesia:create_table(auto_increment, [{attributes, record_info(fields, auto_increment)}, {disc_copies,[node()]}]).

transform() ->
transform(0).

transform(0) ->
T = fun({users, ID, Name, Password}) ->
#users{id = ID,
name = Name,
password = Password,
display = Name}
end,
mnesia:transform_table(users, T, record_info(fields, users)),
transform(1);
transform(_) ->
ok.

insert_user(Name, Password) ->
Q = qlc:q([U#users.id || U <- mnesia:table(users),
U#users.name == Name]),
Expand Down Expand Up @@ -80,6 +95,16 @@ all_wtts() ->
{atomic, Result} = mnesia:transaction(T),
Result.

user_wtts(User, Kind) ->
Q = qlc:q([C || C <- mnesia:table(cards),
W <- mnesia:table(wtts),
C#cards.id == W#wtts.id,
ordsets:is_element(User, element(Kind, W))]),
T = fun() -> qlc:e(Q) end,
{atomic, Result} = mnesia:transaction(T),
Result.


get_wtts(Id) ->
T = fun() ->
case mnesia:read(wtts, Id) of
Expand Down
4 changes: 0 additions & 4 deletions site/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ h1 {
text-transform: uppercase;
font-size: 1.875em;
line-height: 1.066667em;
margin-top: 1.6em;
margin-bottom: 1.6em;
}

h2 {
font-family: Arial, sans-serif;
font-size: 1.5em;
line-height: 1.333333em;
margin-top: 1.6em;
margin-bottom: 1.6em;
}

h3 {
Expand Down

0 comments on commit d673dcd

Please sign in to comment.