Permalink
Browse files

Added showing DB-retrieved user photos (on user pages and in msgs).

  • Loading branch information...
1 parent 3ed7afb commit e41b03abb7d1b10d020b45f8c8280c83038992ee @akoprow akoprow committed Apr 12, 2011
Showing with 85 additions and 39 deletions.
  1. +4 −0 src/main.opa
  2. +4 −4 src/msg.opa
  3. +16 −25 src/pages.opa
  4. +54 −10 src/user.opa
  5. +7 −0 src/utils.opa
View
@@ -25,6 +25,10 @@ urls : Parser.general_parser(connexion_id -> resource) =
@static_resource("./img/favicon.png")
| result={Server.resource_map(resources)} -> _conn_id ->
result
+ | "/img/user-photo/" user=(.*) -> _conn_id ->
+ Text.to_string(user)
+ |> User.mk_ref(_)
+ |> User.get_user_photo_resource(_)
| "/user/" user=(.*) ->
Text.to_string(user)
|> User.mk_ref(_)
View
@@ -23,7 +23,7 @@ type Msg.segment =
/ { url : Uri.uri }
/ { user : User.ref }
-@both_implem Msg = {{
+Msg = {{
create(author : User.ref, content : string) : Msg.t =
msg = { ~author ~content created_at=Date.now() }
@@ -68,7 +68,7 @@ type Msg.segment =
// we add spaces around URLs to avoid collapsing them together with adjacent text
<> <a href={url}>{Uri.to_string(url)}</> </>
| ~{ label } -> Label.to_anchor(label)
- | ~{ user } -> User.to_anchor(user)
+ | ~{ user } -> User.ref_to_anchor(user)
content = List.map(render_segment, parse(msg))
date = WDatePrinter.html(WDatePrinter.default_config,
uniq(), Msg.get_creation_date(msg))
@@ -83,9 +83,9 @@ type Msg.segment =
void
| _ -> void
<div id={id} class={classes} onready={ready}>
- {User.show_photo({size_px=48}, author)}
+ {User.show_msg_photo(author)}
<div class="content">
- <div class="user">{User.to_anchor(author)}</>
+ <div class="user">{User.ref_to_anchor(author)}</>
<div class="text">{content}</>
{match mode with
| {final}
View
@@ -32,25 +32,29 @@ Pages = {{
xhtml = WMsgBox.html("msgbox", Msg.create(user, _), MsgFactory.submit)
exec([#newmsg <- xhtml])
- user_page(user : User.ref) =
+ user_page(user_ref : User.ref) =
+ user_string = User.ref_to_string(user_ref)
content =
- <>
- <div class="header">
- {User.show_photo({size_px=80}, user)}
- {User.to_string(user)}
- </>
- <div id=#newmsg onready={setup_newmsg_box(user)} />
- <div class="separator" />
- <div id=#msgs onready={setup_msg_updates} />
- </>
- ("Twopenny :: {User.to_string(user)}", content)
+ match User.get(user_ref) with
+ | {none} ->
+ <div class="error_page">
+ Sorry, but I know of no user <strong>{user_string}</>
+ </>
+ | {some=user} ->
+ <>
+ {User.get_header(user_ref, user)}
+ <div id=#newmsg onready={setup_newmsg_box(user_ref)} />
+ <div class="separator" />
+ <div id=#msgs onready={setup_msg_updates} />
+ </>
+ ("Twopenny :: {user_string}", content)
label_page(label) =
("Twopenny :: {Label.to_string(label)}", unimplemented)
}}
-css = [ page_css, msg_css, msg_box_css ]
+css = [ page_css, msg_css, msg_box_css, user_css ]
page_css = css
body {
@@ -76,19 +80,6 @@ page_css = css
.hidden {
display: none;
}
- .header .image {
- margin: -15px 0px;
- }
- .header {
- border-top: 1px dotted black;
- border-bottom: 1px dotted black;
- font-variant: small-caps;
- font-size: 20pt;
- height: 50px;
- margin: 30px -16px;
- background: #F8F8F8;
- padding: 0px 15px;
- }
div.separator {
margin: 30px -15px;
border-top: 1px dotted black;
View
@@ -33,24 +33,68 @@ type User.ref = private(string)
type User.map('a) = ordered_map(User.ref, 'a, String.order)
-User = {{
+User =
+
+ default_user_photo : resource =
+ img = {png = @static_binary_content("img/user.png")}
+ Resource.image(img)
+
+ max_profile_photo_size =
+ { max_height_px = 80 max_width_px = 80 }
+
+ max_thumb_photo_size =
+ { max_height_px = 40 max_width_px = 40 }
+
+ get_user_photo_url(user_ref : User.ref) : string =
+ "/img/user-photo/{@unwrap(user_ref)}"
+
+{{
mk_ref(user : string) : User.ref =
@wrap(user)
- to_anchor(user_ref : User.ref) : xhtml =
+ get(user_ref : User.ref) : option(User.t) =
+ ?/users[@unwrap(user_ref)]
+
+ get_user_photo_resource(user_ref : User.ref) : resource =
+ match get(user_ref) with
+ | {none} -> default_user_photo
+ | ~{some=user} ->
+ match user.photo with
+ | {some=photo} -> Resource.image(photo)
+ | {none} -> default_user_photo
+
+ ref_to_anchor(user_ref : User.ref) : xhtml =
user = @unwrap(user_ref)
<a href="/user/{user}">@{user}</>
- to_string(user_ref : User.ref) : string =
+ ref_to_string(user_ref : User.ref) : string =
@unwrap(user_ref)
- show_photo(~{size_px}, user_ref : User.ref) : xhtml =
- size_css = css
- { max-width: {size_px}px
- ; max-height: {size_px}px
- }
- <img class="image" src="/img/user.png" />
- |> apply_css(size_css, _)
+ show_msg_photo(user_ref : User.ref) : xhtml =
+ get_user_photo_url(user_ref)
+ |> show_photo(max_thumb_photo_size, _)
+
+ get_header(user_ref : User.ref, user : User.t) : xhtml =
+ <div class="user_header">
+ {show_photo(max_profile_photo_size, get_user_photo_url(user_ref))}
+ {User.ref_to_string(user_ref)}
+ </>
}}
+
+user_css = css
+ td{} // FIXME problems with CSS parsing... remove when resolved
+ .user_header .image {
+ margin: -15px 0px;
+ }
+ .user_header {
+ border-top: 1px dotted black;
+ border-bottom: 1px dotted black;
+ font-variant: small-caps;
+ font-size: 20pt;
+ height: 50px;
+ margin: 30px -16px;
+ background: #F8F8F8;
+ padding: 0px 15px;
+ }
View
@@ -10,3 +10,10 @@ debug = Log.debug("[twopenny]", _)
apply_css(css_style, dom) =
WStyler.add(WStyler.make_style(css_style), dom)
+show_photo(~{max_width_px; max_height_px}, img_url) : xhtml =
+ size_css = css
+ { max-width: {max_width_px}px
+ ; max-height: {max_height_px}px
+ }
+ <img class="image" src={img_url} />
+ |> apply_css(size_css, _)

0 comments on commit e41b03a

Please sign in to comment.