bugfix; simplify
This commit is contained in:
parent
f3c999062d
commit
2bd2703eab
1 changed files with 7 additions and 12 deletions
|
@ -203,15 +203,10 @@ getRepositoriesReorderR = do
|
||||||
moved <- fromjs <$> runInputGet (ireq textField "moved")
|
moved <- fromjs <$> runInputGet (ireq textField "moved")
|
||||||
list <- map fromjs <$> lookupGetParams "list[]"
|
list <- map fromjs <$> lookupGetParams "list[]"
|
||||||
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 moved
|
Remote.remoteFromUUID moved
|
||||||
rs <- Remote.enabledRemoteList
|
rs <- catMaybes <$> mapM Remote.remoteFromUUID list
|
||||||
forM_ (reorderCosts moved list' remote rs) $ \(r, newcost) ->
|
forM_ (reorderCosts remote rs) $ \(r, newcost) ->
|
||||||
when (Remote.cost r /= newcost) $
|
when (Remote.cost r /= newcost) $
|
||||||
setRemoteCost r newcost
|
setRemoteCost r newcost
|
||||||
remoteListRefresh
|
remoteListRefresh
|
||||||
|
@ -219,13 +214,13 @@ getRepositoriesReorderR = do
|
||||||
where
|
where
|
||||||
fromjs = toUUID . snd . separate (== '_') . T.unpack
|
fromjs = toUUID . snd . separate (== '_') . T.unpack
|
||||||
|
|
||||||
reorderCosts :: UUID -> [UUID] -> Remote -> [Remote] -> [(Remote, Cost)]
|
reorderCosts :: Remote -> [Remote] -> [(Remote, Cost)]
|
||||||
reorderCosts moved list remote rs = zip rs'' (insertCostAfter costs i)
|
reorderCosts remote rs = zip rs'' (insertCostAfter costs i)
|
||||||
where
|
where
|
||||||
{- Find the index of the item in the list that the item
|
{- Find the index of the remote in the list that the remote
|
||||||
- was moved to be after.
|
- was moved to be after.
|
||||||
- If it was moved to the start of the list, -1 -}
|
- If it was moved to the start of the list, -1 -}
|
||||||
i = fromMaybe 0 (elemIndex moved list) - 1
|
i = fromMaybe 0 (elemIndex remote rs) - 1
|
||||||
rs' = filter (\r -> Remote.uuid r /= moved) rs
|
rs' = filter (\r -> Remote.uuid r /= Remote.uuid remote) rs
|
||||||
costs = map Remote.cost rs'
|
costs = map Remote.cost rs'
|
||||||
rs'' = (\(x, y) -> x ++ [remote] ++ y) $ splitAt (i + 1) rs'
|
rs'' = (\(x, y) -> x ++ [remote] ++ y) $ splitAt (i + 1) rs'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue