media page now responsive to media width

This commit is contained in:
nek0 2015-01-14 23:08:58 +01:00
parent 312a89e0b7
commit 7d3872d1e6
7 changed files with 21 additions and 13 deletions

View file

@ -76,6 +76,7 @@ adminMediumSetForm medium = renderDivs $ Medium
<*> pure (mediumOwner medium) <*> pure (mediumOwner medium)
<*> areq textareaField "Description" (Just $ mediumDescription medium) <*> areq textareaField "Description" (Just $ mediumDescription medium)
<*> areq tagField "Tags" (Just $ mediumTags medium) <*> areq tagField "Tags" (Just $ mediumTags medium)
<*> pure (mediumWidth medium)
<*> pure (mediumThumbWidth medium) <*> pure (mediumThumbWidth medium)
<*> pure (mediumAlbum medium) <*> pure (mediumAlbum medium)

View file

@ -33,6 +33,9 @@ getMediumR mediumId = do
(commentWidget, enctype) <- generateFormPost $ commentForm userId userSl mediumId Nothing (commentWidget, enctype) <- generateFormPost $ commentForm userId userSl mediumId Nothing
comments <- runDB $ selectList [CommentOrigin ==. mediumId, CommentParent ==. Nothing] [Desc CommentTime] comments <- runDB $ selectList [CommentOrigin ==. mediumId, CommentParent ==. Nothing] [Desc CommentTime]
replies <- runDB $ selectList [CommentOrigin ==. mediumId, CommentParent !=. Nothing] [Desc CommentTime] replies <- runDB $ selectList [CommentOrigin ==. mediumId, CommentParent !=. Nothing] [Desc CommentTime]
dataWidth <- case mediumWidth medium >= 750 of
True -> return 750
False -> return $ (mediumWidth medium) + 53
formLayout $ do formLayout $ do
setTitle $ toHtml ("Eidolon :: Medium " `T.append` (mediumTitle medium)) setTitle $ toHtml ("Eidolon :: Medium " `T.append` (mediumTitle medium))
$(widgetFile "medium") $(widgetFile "medium")

View file

@ -51,6 +51,7 @@ mediumSettingsForm medium = renderDivs $ Medium
<*> pure (mediumOwner medium) <*> pure (mediumOwner medium)
<*> areq textareaField "Description" (Just $ mediumDescription medium) <*> areq textareaField "Description" (Just $ mediumDescription medium)
<*> areq tagField "tags" (Just $ mediumTags medium) <*> areq tagField "tags" (Just $ mediumTags medium)
<*> pure (mediumWidth medium)
<*> pure (mediumThumbWidth medium) <*> pure (mediumThumbWidth medium)
<*> pure (mediumAlbum medium) <*> pure (mediumAlbum medium)

View file

@ -55,7 +55,7 @@ postUploadR = do
albRef <- runDB $ getJust (tempMediumAlbum temp) albRef <- runDB $ getJust (tempMediumAlbum temp)
ownerId <- return $ albumOwner albRef ownerId <- return $ albumOwner albRef
path <- writeOnDrive fil ownerId (tempMediumAlbum temp) path <- writeOnDrive fil ownerId (tempMediumAlbum temp)
(thumbPath, width) <- generateThumb path ownerId (tempMediumAlbum temp) (thumbPath, iWidth, tWidth) <- generateThumb path ownerId (tempMediumAlbum temp)
inAlbumId <- return $ tempMediumAlbum temp inAlbumId <- return $ tempMediumAlbum temp
medium <- return $ Medium medium <- return $ Medium
(tempMediumTitle temp) (tempMediumTitle temp)
@ -66,7 +66,8 @@ postUploadR = do
(tempMediumOwner temp) (tempMediumOwner temp)
(tempMediumDesc temp) (tempMediumDesc temp)
(tempMediumTags temp) (tempMediumTags temp)
width iWidth
tWidth
inAlbumId inAlbumId
mId <- runDB $ I.insert medium mId <- runDB $ I.insert medium
inAlbum <- runDB $ getJust inAlbumId inAlbum <- runDB $ getJust inAlbumId
@ -134,7 +135,7 @@ postDirectUploadR albumId = do
albRef <- runDB $ getJust (tempMediumAlbum temp) albRef <- runDB $ getJust (tempMediumAlbum temp)
refOwnerId <- return $ albumOwner albRef refOwnerId <- return $ albumOwner albRef
path <- writeOnDrive fil refOwnerId albumId path <- writeOnDrive fil refOwnerId albumId
(thumbPath, width) <- generateThumb path ownerId albumId (thumbPath, iWidth, tWidth) <- generateThumb path ownerId albumId
medium <- return $ Medium medium <- return $ Medium
(tempMediumTitle temp) (tempMediumTitle temp)
('/' : path) ('/' : path)
@ -144,7 +145,8 @@ postDirectUploadR albumId = do
(tempMediumOwner temp) (tempMediumOwner temp)
(tempMediumDesc temp) (tempMediumDesc temp)
(tempMediumTags temp) (tempMediumTags temp)
width iWidth
tWidth
albumId albumId
mId <- runDB $ insert medium mId <- runDB $ insert medium
inAlbum <- runDB $ getJust albumId inAlbum <- runDB $ getJust albumId
@ -168,14 +170,14 @@ postDirectUploadR albumId = do
setMessage "This Album does not exist" setMessage "This Album does not exist"
redirect $ AlbumR albumId redirect $ AlbumR albumId
generateThumb :: FP.FilePath -> UserId -> AlbumId -> Handler (FP.FilePath, Int) generateThumb :: FP.FilePath -> UserId -> AlbumId -> Handler (FP.FilePath, Int, Int)
generateThumb path userId albumId = do generateThumb path userId albumId = do
newName <- return $ (FP.takeBaseName path) ++ "_thumb" ++ (FP.takeExtension path) newName <- return $ (FP.takeBaseName path) ++ "_thumb" ++ (FP.takeExtension path)
newPath <- return $ "static" FP.</> "data" newPath <- return $ "static" FP.</> "data"
FP.</> (T.unpack $ extractKey userId) FP.</> (T.unpack $ extractKey userId)
FP.</> (T.unpack $ extractKey albumId) FP.</> (T.unpack $ extractKey albumId)
FP.</> newName FP.</> newName
width <- liftIO $ withMagickWandGenesis $ do (iWidth, tWidth) <- liftIO $ withMagickWandGenesis $ do
(_ , w) <- magickWand (_ , w) <- magickWand
readImage w (decodeString path) readImage w (decodeString path)
w1 <- getImageWidth w w1 <- getImageWidth w
@ -185,8 +187,8 @@ generateThumb path userId albumId = do
resizeImage w w2 h2 lanczosFilter 1 resizeImage w w2 h2 lanczosFilter 1
setImageCompressionQuality w 95 setImageCompressionQuality w 95
writeImage w (Just (decodeString newPath)) writeImage w (Just (decodeString newPath))
return w2 return (w1, w2)
return (newPath, width) return (newPath, iWidth, tWidth)
writeOnDrive :: FileInfo -> UserId -> AlbumId -> Handler FP.FilePath writeOnDrive :: FileInfo -> UserId -> AlbumId -> Handler FP.FilePath
writeOnDrive fil userId albumId = do writeOnDrive fil userId albumId = do

View file

@ -33,6 +33,7 @@ Medium
owner UserId owner UserId
description Textarea description Textarea
tags Texts tags Texts
width Int
thumbWidth Int thumbWidth Int
album AlbumId album AlbumId
deriving Eq Show deriving Eq Show

View file

@ -1,7 +1,7 @@
img img
position: relative !important position: relative !important
max-width: 100% !important max-width: 100% !important
height: 28em !important max-height: 28em !important
width: auto !important width: auto !important
.reply .reply

View file

@ -1,14 +1,14 @@
<div id="header" class="item" data-width="800"> <div id="header" class="item" data-width=#{dataWidth}>
<div class="inner"> <div class="inner">
<h1>#{mediumTitle medium} <h1>#{mediumTitle medium}
<p>
by <a href=@{UserR ownerName}>#{ownerName}</a> from album <a href=@{AlbumR albumId}>#{albumTitle album}</a> by <a href=@{UserR ownerName}>#{ownerName}</a> from album <a href=@{AlbumR albumId}>#{albumTitle album}</a>
<img src=#{mediumPath medium}> <img src=#{mediumPath medium}>
<div id="header" class="item" data-width="400"> <div id="header" class="item" data-width="400">
<div class="inner"> <div class="inner">
<div class="desc"> <p class="desc">
Uploaded on: #{formatTime defaultTimeLocale "%A %F %H:%M" (mediumTime medium)}<br> Uploaded on: #{formatTime defaultTimeLocale "%A %F %H:%M" (mediumTime medium)}<br>
Description:<br> Description:<br>
#{mediumDescription medium} #{mediumDescription medium}