From 6af91dadb8a80f72c258b6d64c2e1cd741e38056 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 14 Mar 2013 11:55:36 -0400 Subject: [PATCH] AJAX reordered list back to yesod. THIS TOOK 3 HOURS. Aargh --- Assistant/WebApp/RepoList.hs | 29 ++++++------------- Assistant/WebApp/routes | 3 +- .../configurators/repositories/list.hamlet | 4 +-- .../configurators/repositories/list.julius | 8 ++++- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/Assistant/WebApp/RepoList.hs b/Assistant/WebApp/RepoList.hs index de9e66979f..374e196733 100644 --- a/Assistant/WebApp/RepoList.hs +++ b/Assistant/WebApp/RepoList.hs @@ -63,30 +63,22 @@ data Actions { setupRepoLink :: Route WebApp } | SyncingRepoActions { setupRepoLink :: Route WebApp - , moveUpRepoList :: Route WebApp - , moveDownRepoList :: Route WebApp , syncToggleLink :: Route WebApp } | NotSyncingRepoActions { setupRepoLink :: Route WebApp - , moveUpRepoList :: Route WebApp - , moveDownRepoList :: Route WebApp , syncToggleLink :: Route WebApp } mkSyncingRepoActions :: UUID -> Actions mkSyncingRepoActions u = SyncingRepoActions { setupRepoLink = EditRepositoryR u - , moveUpRepoList = MoveRepositoryUp u - , moveDownRepoList = MoveRepositoryDown u , syncToggleLink = DisableSyncR u } mkNotSyncingRepoActions :: UUID -> Actions mkNotSyncingRepoActions u = NotSyncingRepoActions { setupRepoLink = EditRepositoryR u - , moveUpRepoList = MoveRepositoryUp u - , moveDownRepoList = MoveRepositoryDown u , syncToggleLink = EnableSyncR u } @@ -95,7 +87,7 @@ needsEnabled (DisabledRepoActions _) = True needsEnabled _ = False notSyncing :: Actions -> Bool -notSyncing (SyncingRepoActions _ _ _ _) = False +notSyncing (SyncingRepoActions _ _) = False notSyncing _ = True {- Called by client to get a list of repos, that refreshes @@ -124,7 +116,8 @@ repoListDisplay reposelector = do where ident = "repolist" -type RepoList = [(String, String, Actions)] +-- (num, name, (uuid, actions)) +type RepoList = [(String, String, (UUID, Actions))] {- A numbered list of known repositories, - with actions that can be taken on them. -} @@ -186,7 +179,7 @@ repoList reposelector zip3 <$> pure counter <*> Remote.prettyListUUIDs (map fst l') - <*> pure (map snd l') + <*> pure l' counter = map show ([1..] :: [Int]) getEnableSyncR :: UUID -> Handler () @@ -201,15 +194,11 @@ flipSync enable uuid = do changeSyncable mremote enable redirect RepositoriesR -getMoveRepositoryUp :: UUID -> Handler () -getMoveRepositoryUp u = do - reorderRepository u - redirect RepositoriesR - -getMoveRepositoryDown :: UUID -> Handler () -getMoveRepositoryDown u = do - reorderRepository u - redirect RepositoriesR +getRepositoriesReorderR :: Handler () +getRepositoriesReorderR = do + moved <- runInputGet $ ireq textField "moved" + list <- lookupGetParams "list[]" + error $ show (moved, list) reorderRepository :: UUID -> Handler () reorderRepository uuid = do diff --git a/Assistant/WebApp/routes b/Assistant/WebApp/routes index 6a170bc950..15f3e65155 100644 --- a/Assistant/WebApp/routes +++ b/Assistant/WebApp/routes @@ -1,8 +1,7 @@ / DashboardR GET HEAD /repositories RepositoriesR GET -/repositories/moveup/#UUID MoveRepositoryUp GET -/repositories/movedown/#UUID MoveRepositoryDown GET +/repositories/reorder RepositoriesReorderR GET /noscript NoScriptR GET /noscript/auto NoScriptAutoR GET diff --git a/templates/configurators/repositories/list.hamlet b/templates/configurators/repositories/list.hamlet index 82411ffd28..b1fb0da284 100644 --- a/templates/configurators/repositories/list.hamlet +++ b/templates/configurators/repositories/list.hamlet @@ -11,8 +11,8 @@ Repositories - $forall (_num, name, actions) <- repolist - + $forall (num, name, (uuid, actions)) <- repolist +
#{name} diff --git a/templates/configurators/repositories/list.julius b/templates/configurators/repositories/list.julius index c75c9c841c..8e18f6d474 100644 --- a/templates/configurators/repositories/list.julius +++ b/templates/configurators/repositories/list.julius @@ -8,8 +8,14 @@ $(function() { }, stop: function(event, ui) { ui.item.children(".draghide").show(); + var list = $("#costsortable").sortable("toArray"); + var moved = ui.item.attr("id"); $.ajax({ - 'url': "http://localhost/testajax", + 'url': "@{RepositoriesReorderR}", + 'data': { + 'moved': moved, + 'list': list + } }); }, });