Skip to content

Commit 622ccbc

Browse files
authored
Merge pull request #234 from ju1m/for-master/packages
+user/transparency(ui)(/packages): init browsing of packages
2 parents a97a2ae + 1e50b6c commit 622ccbc

File tree

24 files changed

+1095
-527
lines changed

24 files changed

+1095
-527
lines changed

ui/package.nix

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,10 @@ symlinkJoin {
7676
ln -s $out/index.html "app/$app_dir/index.html"
7777
done
7878
79-
# search route
80-
ln -s $out/index.html "app/index.html"
81-
82-
# recipe route
83-
mkdir -p recipe/options
84-
ln -s $out/index.html "recipe/index.html"
85-
ln -s $out/index.html "recipe/options/index.html"
79+
for page in apps packages recipe recipe/options; do
80+
mkdir -p "$page"
81+
ln -s $out/index.html "$page/index.html"
82+
done
8683
8784
popd
8885
'';

ui/src/Main.elm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Json.Encode
88
import Main.Config
99
import Main.Config.App exposing (..)
1010
import Main.Model exposing (..)
11+
import Main.Model.Page exposing (..)
1112
import Main.Model.Preferences exposing (..)
1213
import Main.Route exposing (..)
1314
import Main.Subscriptions
@@ -38,17 +39,14 @@ init flags =
3839
model =
3940
{ model_config = Main.Config.initConfig
4041
, model_search = ""
41-
, model_page = Page_Search
42+
, model_page = defaultPage
4243
, model_errors = []
4344
, model_preferences =
4445
flags.flags_preferences
4546
|> Json.Decode.decodeValue decodePreferences
4647
|> Result.withDefault defaultPreferences
4748
, model_navbarExpanded = False
48-
, model_RecipeOptions =
49-
{ modelRecipeOptions_available = Dict.empty
50-
, modelRecipeOptions_filtered = []
51-
}
49+
, model_RecipeOptions = defaultRecipeOptions
5250
}
5351
in
5452
case flags.href |> Url.fromString of

ui/src/Main/Config.elm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Dict exposing (Dict)
44
import Json.Decode as Decode exposing (Decoder)
55
import List
66
import Main.Config.App as Config exposing (..)
7+
import Main.Config.Package as Config exposing (..)
78
import Main.Error exposing (..)
89
import Main.Helpers.Nix exposing (..)
910
import Url exposing (Url)
@@ -31,6 +32,7 @@ type alias Config =
3132
{ config_repository : NixUrl
3233
, config_recipe : ConfigRecipe
3334
, config_apps : Dict AppName App
35+
, config_packages : Dict PackageName Package
3436
}
3537

3638

@@ -39,19 +41,25 @@ initConfig =
3941
{ config_repository = "github:ngi-nix/forge"
4042
, config_recipe = initRecipe
4143
, config_apps = Dict.empty
44+
, config_packages = Dict.empty
4245
}
4346

4447

4548
decodeConfig : Decoder Config
4649
decodeConfig =
47-
Decode.map3 Config
50+
Decode.map4 Config
4851
(Decode.field "repositoryUrl" Decode.string)
4952
(Decode.field "recipeDirs" decodeConfigRecipe)
5053
(Decode.field "apps"
5154
(Decode.list Config.decodeApp
5255
|> Decode.map (List.map (\app -> ( app.app_name, app )) >> Dict.fromList)
5356
)
5457
)
58+
(Decode.field "packages"
59+
(Decode.list Config.decodePackage
60+
|> Decode.map (List.map (\pkg -> ( pkg.package_name, pkg )) >> Dict.fromList)
61+
)
62+
)
5563

5664

5765
type alias ConfigRecipe =

ui/src/Main/Config/App.elm

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,6 @@ decodeAppServicesRuntimesNixos =
129129
(Decode.field "enable" Decode.bool)
130130

131131

132-
getAppIconPath : AppName -> String
133-
getAppIconPath appName =
134-
"resources/apps/" ++ appName ++ "/icon.svg"
135-
136-
137-
getDefaultIconPath : String
138-
getDefaultIconPath =
139-
"resources/apps/app-icon.svg"
140-
141-
142132
decodeAppContainer : Decoder AppServicesRuntimesContainer
143133
decodeAppContainer =
144134
Decode.map AppServicesRuntimesContainer

ui/src/Main/Config/Package.elm

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module Main.Config.Package exposing (..)
2+
3+
import Json.Decode as Decode exposing (Decoder)
4+
import Main.Helpers.String exposing (..)
5+
6+
7+
type alias Package =
8+
{ package_name : PackageName
9+
, package_description : String
10+
, package_version : String
11+
, package_homePage : String
12+
, package_mainProgram : String
13+
, package_license : PackageLicense
14+
, package_source : PackageSource
15+
}
16+
17+
18+
decodePackage : Decoder Package
19+
decodePackage =
20+
Decode.map7 Package
21+
(Decode.field "name" Decode.string)
22+
(Decode.field "description" Decode.string)
23+
(Decode.field "version" Decode.string)
24+
(Decode.field "homePage" Decode.string)
25+
(Decode.field "mainProgram" Decode.string)
26+
(Decode.field "license" decodeLicense)
27+
(Decode.field "source" decodeSource)
28+
29+
30+
type alias PackageName =
31+
String
32+
33+
34+
type alias PackageSource =
35+
{ source_git : Maybe String
36+
, source_url : Maybe String
37+
, source_path : Maybe String
38+
, source_hash : String
39+
, source_patches : List String
40+
}
41+
42+
43+
decodeSource : Decoder PackageSource
44+
decodeSource =
45+
Decode.map5 PackageSource
46+
(Decode.field "git" (Decode.maybe Decode.string))
47+
(Decode.field "url" (Decode.maybe Decode.string))
48+
(Decode.field "path" (Decode.maybe Decode.string))
49+
(Decode.field "hash" Decode.string)
50+
(Decode.field "patches" (Decode.list Decode.string))
51+
52+
53+
type alias PackageLicense =
54+
{ license_deprecated : Bool
55+
, license_free : Bool
56+
, license_fullName : String
57+
, license_redistributable : Bool
58+
, license_shortName : String
59+
, license_spdxId : String
60+
, license_url : String
61+
}
62+
63+
64+
decodeLicense : Decoder PackageLicense
65+
decodeLicense =
66+
Decode.map7 PackageLicense
67+
(Decode.field "deprecated" Decode.bool)
68+
(Decode.field "free" Decode.bool)
69+
(Decode.field "fullName" Decode.string)
70+
(Decode.field "redistributable" Decode.bool)
71+
(Decode.field "shortName" Decode.string)
72+
(Decode.field "spdxId" Decode.string)
73+
(Decode.field "url" Decode.string)

ui/src/Main/Error.elm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ module Main.Error exposing (..)
33
import AppUrl exposing (AppUrl)
44
import Http
55
import Main.Config.App exposing (..)
6+
import Main.Config.Package exposing (..)
67

78

89
type Error
910
= Error_App ErrorApp
11+
| Error_Package ErrorPackage
1012
| Error_Http Http.Error
1113
| Error_Route ErrorRoute
1214

@@ -20,3 +22,7 @@ type ErrorApp
2022
= ErrorApp_NoSuchRuntime AppName AppRuntime
2123
| ErrorApp_NoRuntime AppName
2224
| ErrorApp_NotFound AppName
25+
26+
27+
type ErrorPackage
28+
= ErrorPackage_NotFound PackageName

ui/src/Main/Helpers/List.elm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
module Main.Helpers.List exposing (..)
22

3-
{-| @'chunksOf' n@ splits a list into length-n pieces. The last
3+
{-| @'paginationOf' n@ splits a list into length-n pieces. The last
44
piece will be shorter if @n@ does not evenly divide the length of
5-
the list. If @n <= 0@, @'chunksOf' n l@ returns an infinite list
5+
the list. If @n <= 0@, @'paginationOf' n l@ returns an infinite list
66
of empty lists.
77
8-
AdaptedFrom: <https://hackage.haskell.org/package/split/docs/Data-List-Split.html#v:chunksOf>
8+
AdaptedFrom: <https://hackage.haskell.org/package/split/docs/Data-List-Split.html#v:paginationOf>
99
1010
-}
1111

1212

13-
chunksOf : Int -> List a -> List (List a)
14-
chunksOf n xs =
13+
paginationOf : Int -> List a -> List (List a)
14+
paginationOf n xs =
1515
case xs of
1616
[] ->
1717
[]
@@ -21,7 +21,7 @@ chunksOf n xs =
2121
( ys, zs ) =
2222
splitAt n xs
2323
in
24-
ys :: chunksOf n zs
24+
ys :: paginationOf n zs
2525

2626

2727
{-| 'splitAt' @n xs@ returns a tuple where first element is @xs@ prefix of

ui/src/Main/Model.elm

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
module Main.Model exposing (..)
22

3+
import Dict
34
import Main.Config exposing (..)
45
import Main.Config.App exposing (..)
6+
import Main.Config.Package exposing (..)
57
import Main.Error exposing (..)
68
import Main.Helpers.Nix exposing (..)
9+
import Main.Model.Page exposing (..)
710
import Main.Model.Preferences exposing (..)
811
import Main.Route exposing (..)
912

@@ -15,44 +18,16 @@ type alias Model =
1518
, model_errors : List Error
1619
, model_preferences : Preferences
1720
, model_navbarExpanded : Bool
18-
, model_RecipeOptions : ModelRecipeOptions
21+
, model_RecipeOptions : RecipeOptions
1922
}
2023

2124

22-
{-| A `Page` is located at a `Route`,
23-
with more or less data than that `Route`:
24-
25-
- More data if viewing the `Page` requires more than provided in its address,
26-
eg. by querying the backend (eg. `pageApp_app`).
27-
28-
- Less data if navigating away from the `Page` must persist that data,
29-
and thus be persisted in `Model` (eg. `Route_Search` persists in `model_search`).
30-
31-
-}
32-
type Page
33-
= Page_Search
34-
| Page_App PageApp
35-
| Page_RecipeOptions PageRecipeOptions
36-
37-
38-
type alias PageApp =
39-
{ pageApp_route : RouteApp
40-
, pageApp_app : App
41-
42-
-- `Nothing` means that the `App` provides no `AppRuntime` at all.
43-
, pageApp_runtime : Maybe AppRuntime
44-
}
45-
46-
47-
type alias PageRecipeOptions =
48-
{ pageRecipeOptions_route : RouteRecipeOptions
49-
, pageRecipeOptions_page : Int
50-
, pageRecipeOptions_MaxResultsPerPage : Int
51-
, pageRecipeOptions_LastPage : Int
25+
type alias RecipeOptions =
26+
{ recipeOptions_available : NixModuleOptions
5227
}
5328

5429

55-
type alias ModelRecipeOptions =
56-
{ modelRecipeOptions_available : NixModuleOptions
57-
, modelRecipeOptions_filtered : List ( NixName, NixModuleOption )
30+
defaultRecipeOptions : RecipeOptions
31+
defaultRecipeOptions =
32+
{ recipeOptions_available = Dict.empty
5833
}

0 commit comments

Comments
 (0)