webapp: Repository costs can be configured by dragging repositories around in the repository list.

This commit is contained in:
Joey Hess 2013-03-14 13:12:27 -04:00
parent 6af91dadb8
commit 99dc302d06
3 changed files with 28 additions and 25 deletions

View file

@ -27,6 +27,7 @@ import qualified Git
#endif #endif
import qualified Data.Map as M import qualified Data.Map as M
import qualified Data.Text as T
{- An intro message, list of repositories, and nudge to make more. -} {- An intro message, list of repositories, and nudge to make more. -}
introDisplay :: Text -> Widget introDisplay :: Text -> Widget
@ -196,33 +197,33 @@ flipSync enable uuid = do
getRepositoriesReorderR :: Handler () getRepositoriesReorderR :: Handler ()
getRepositoriesReorderR = do getRepositoriesReorderR = do
moved <- runInputGet $ ireq textField "moved" {- Get uuid of the moved item, and the list it was moved within. -}
list <- lookupGetParams "list[]" moved <- fromjs <$> runInputGet (ireq textField "moved")
error $ show (moved, list) list <- map fromjs <$> lookupGetParams "list[]"
reorderRepository :: UUID -> Handler ()
reorderRepository uuid = do
void $ liftAnnex $ do void $ liftAnnex $ do
{- The list may have an item for the current repository,
- which needs to be filtered out, as it does not have a
- cost. -}
u <- getUUID
let list' = filter (/= u) list
remote <- fromMaybe (error "Unknown UUID") <$> remote <- fromMaybe (error "Unknown UUID") <$>
Remote.remoteFromUUID uuid Remote.remoteFromUUID moved
rs <- Remote.enabledRemoteList rs <- Remote.enabledRemoteList
let us = map Remote.uuid rs forM_ (reorderCosts moved list' remote rs) $ \(r, newcost) ->
case afteruuid us >>= (\u -> elemIndex u us) of
Nothing -> noop -- already at end
Just i -> do
let rs' = filter other rs
let costs = map Remote.cost rs'
let rs'' = (\(x, y) -> x ++ [remote] ++ y) $
splitAt (i + 1) rs'
let l = zip rs'' (insertCostAfter costs i)
forM_ l $ \(r, newcost) ->
when (Remote.cost r /= newcost) $ when (Remote.cost r /= newcost) $
setRemoteCost r newcost setRemoteCost r newcost
remoteListRefresh remoteListRefresh
liftAssistant updateSyncRemotes liftAssistant updateSyncRemotes
where where
afteruuid [] = Nothing fromjs = toUUID . snd . separate (== '_') . T.unpack
afteruuid (u:us)
| u == uuid = headMaybe us reorderCosts :: UUID -> [UUID] -> Remote -> [Remote] -> [(Remote, Cost)]
| otherwise = afteruuid us reorderCosts moved list remote rs = zip rs'' (insertCostAfter costs i)
other r = Remote.uuid r /= uuid where
{- Find the index of the item in the list that the item
- was moved to be after.
- If it was moved to the start of the list, -1 -}
i = fromMaybe 0 (elemIndex moved list) - 1
rs' = filter (\r -> Remote.uuid r /= moved) rs
costs = map Remote.cost rs'
rs'' = (\(x, y) -> x ++ [remote] ++ y) $ splitAt (i + 1) rs'

2
debian/changelog vendored
View file

@ -56,6 +56,8 @@ git-annex (4.20130228) UNRELEASED; urgency=low
(See https://github.com/yesodweb/wai/issues/146) (See https://github.com/yesodweb/wai/issues/146)
* webapp: New preferences page allows enabling/disabling debug logging * webapp: New preferences page allows enabling/disabling debug logging
at runtime, as well as configuring numcopies and diskreserve. at runtime, as well as configuring numcopies and diskreserve.
* webapp: Repository costs can be configured by dragging repositories around
in the repository list.
* webapp: Proceed automatically on from "Configure jabber account" * webapp: Proceed automatically on from "Configure jabber account"
to pairing. to pairing.
* webapp: Only show up to 10 queued transfers. * webapp: Only show up to 10 queued transfers.

View file

@ -11,7 +11,7 @@
Repositories Repositories
<table .table .table-condensed> <table .table .table-condensed>
<tbody #costsortable> <tbody #costsortable>
$forall (num, name, (uuid, actions)) <- repolist $forall (_num, name, (uuid, actions)) <- repolist
<tr .repoline ##{"costsortable_" ++ fromUUID uuid}> <tr .repoline ##{"costsortable_" ++ fromUUID uuid}>
<td .handle> <td .handle>
<i .icon-resize-vertical></i> <i .icon-resize-vertical></i>