Skip to content

Commit

Permalink
feat: a better folder navigation for big filesystems
Browse files Browse the repository at this point in the history
  • Loading branch information
nilp0inter committed Jun 7, 2020
1 parent 0f7b06b commit 5ad89d1
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/srv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ func ScanForGames(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(err.Error()))
return
}
defer f.Close()

enc := json.NewEncoder(f)

Expand Down
102 changes: 88 additions & 14 deletions src/web/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ type alias GameTree =
, contents : Contents
}

type ZipperParent
= ZipperParent (GameTreeZipper)

type alias GameTreeZipper =
{ name : String
, parent : Maybe ZipperParent
, current : GameTree
}

type alias GameFolder =
{ label : String
Expand Down Expand Up @@ -391,6 +399,7 @@ type alias Model =
, messages : List Panel
, cores : CoreState
, games : GameState
, folderSettingsNav : Maybe GameTreeZipper
, openContentWithDialog : ContentLoadInfo
, gameLoaderScript : Maybe String
, platforms : Maybe (List Platform)
Expand Down Expand Up @@ -473,6 +482,7 @@ init flags url key =
, modalFooter = [ Button.button [ Button.warning, Button.onClick CloseModal ] [ text "Proceed" ] ]
, cores = CoresNotFound
, games = GameFoldersNotFound
, folderSettingsNav = Nothing
, openContentWithDialog = emptyContentLoadInfo
, gameLoaderScript = Nothing
, platforms = Nothing
Expand Down Expand Up @@ -541,7 +551,11 @@ type Msg
| FilterGames String
| GamePaginationMsg Int
| GameMissingThumbnail String
| SettingFolderNav FolderNavMsg

type FolderNavMsg
= NavUp GameTreeZipper
| NavDown (String, GameTree)

subscriptions : Model -> Sub Msg
subscriptions model =
Expand Down Expand Up @@ -901,6 +915,9 @@ update msg model =
, page = 0
, missingThumbnails = Set.empty
}
, folderSettingsNav = Just { parent = Nothing
, name = "/"
, current = value }
, waiting = model.waiting - 1
}
, Cmd.batch
Expand Down Expand Up @@ -1076,6 +1093,20 @@ update msg model =
_ ->
( model, Cmd.none )

SettingFolderNav m ->
case m of
NavUp zipper ->
( { model | folderSettingsNav = Just zipper }
, Cmd.none )
NavDown (name, tree) ->
case model.folderSettingsNav of
Nothing -> ( model, Cmd.none)
Just parent ->
( {model | folderSettingsNav = Just { parent = Just (ZipperParent parent)
, name = name
, current = tree }}
, Cmd.none )


coreSelect : String -> Core -> Maybe (Select.Item Msg)
coreSelect selectedPath c =
Expand Down Expand Up @@ -1673,11 +1704,21 @@ scanGamesBlock model =
)
]
|> Card.block []
(case model.games of
GameFoldersLoaded games ->
(case (model.folderSettingsNav, model.games) of
(Just folders, GameFoldersLoaded games) ->
[ Block.text []
[ h3 [] [ text "Game Folders" ]
, ListGroup.ul (folderSelector games.scanningOn games.topFolder)
[ Grid.container []
[ Grid.row []
[ Grid.col [ Col.sm6 ]
[ h4 [] [ text "Folders" ]
, ListGroup.ul ([ ListGroup.li [ ListGroup.light ] [ text folders.current.path ] ] ++ (folderSelector games.scanningOn folders))
]
, Grid.col [ Col.sm6 ]
[ h4 [] [ text "Scanned" ]
, ListGroup.ul (scannedFolderSelector games.scanningOn games.topFolder)
]
]
]
]
]

Expand Down Expand Up @@ -2773,18 +2814,30 @@ isJust x =
True


addFolderSelector : Maybe String -> String -> GameTree -> List (ListGroup.Item Msg) -> List (ListGroup.Item Msg)
addFolderSelector scanningOn _ gt xs =
folderSelector scanningOn gt ++ xs
-- addFolderSelector : Maybe String -> String -> GameTree -> List (ListGroup.Item Msg) -> List (ListGroup.Item Msg)
-- addFolderSelector scanningOn _ gt xs =
-- folderSelector scanningOn gt ++ xs


folderSelector : Maybe String -> GameTree -> List (ListGroup.Item Msg)
folderSelector : Maybe String -> GameTreeZipper -> List (ListGroup.Item Msg)
folderSelector scanningOn gt =
(if String.length gt.path >= String.length "/media/fat" then
[ gameFolderElement scanningOn gt.path gt.scanned ]

else
[]
let
parent = case gt.parent of
Just (ZipperParent zz) -> [gameSubFolderElement scanningOn ".." ScanFound "" (onClick <| SettingFolderNav <| NavUp zz)]
_ -> []
in
case gt.current.contents of
Contents folders ->
Dict.foldl (\k v acc -> acc ++ [gameSubFolderElement scanningOn k v.scanned v.path (onClick <| SettingFolderNav <| NavDown (k, v))]) parent folders


scannedFolderSelector : Maybe String -> GameTree -> List (ListGroup.Item Msg)
scannedFolderSelector scanningOn gt =
(case gt.scanned of
ScanFound ->
[ gameFolderElement scanningOn gt.path gt.scanned ]

_ -> []
)
++ (case gt.scanned of
ScanFound ->
Expand All @@ -2793,7 +2846,7 @@ folderSelector scanningOn gt =
_ ->
case gt.contents of
Contents c ->
Dict.foldr (addFolderSelector scanningOn) [] c
Dict.foldr (\k v acc -> (scannedFolderSelector scanningOn v) ++ acc) [] c
)


Expand All @@ -2812,6 +2865,27 @@ scanningSpinner path scanningOn textNoScanning textScanning =
else
[ text textNoScanning ]

gameSubFolderElement : Maybe String -> String -> ScanStatus -> String -> Attribute Msg -> ListGroup.Item Msg
gameSubFolderElement scanningOn name scanned path clickEv =
ListGroup.li [ ListGroup.attrs [ Flex.block, Flex.justifyBetween, Flex.alignItemsCenter ] ]
([ Button.button [ Button.roleLink, Button.attrs [ clickEv ] ] [ text name ] ]
++ [ ButtonGroup.buttonGroup
[ ButtonGroup.small ]
(case scanned of
ScanFound ->
[ ]

_ ->
[ ButtonGroup.button
[ Button.disabled (isJust scanningOn)
, Button.primary
, Button.onClick (ScanGames path)
]
(scanningSpinner path scanningOn "Scan" "Scanning...")
]
)
]
)

gameFolderElement : Maybe String -> String -> ScanStatus -> ListGroup.Item Msg
gameFolderElement scanningOn name scanned =
Expand Down

0 comments on commit 5ad89d1

Please sign in to comment.