Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixos-search
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b2b1d59a7293
Choose a base ref
...
head repository: NixOS/nixos-search
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9bec66b7699a
Choose a head ref
  • 2 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 16, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    turboMaCk Marek Fajkus
    Copy the full SHA
    bfaefcd View commit details
  2. trap and improve options

    turboMaCk committed Jan 16, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    turboMaCk Marek Fajkus
    Copy the full SHA
    9bec66b View commit details
Showing with 65 additions and 41 deletions.
  1. +4 −5 src/Page/Options.elm
  2. +25 −34 src/Page/Packages.elm
  3. +22 −0 src/Search.elm
  4. +14 −2 src/index.less
9 changes: 4 additions & 5 deletions src/Page/Options.elm
Original file line number Diff line number Diff line change
@@ -167,7 +167,7 @@ viewResultItem channel _ show item =
pre [] [ text value ]

asPreCode value =
div [] [ pre [] [ code [] [ text value ] ] ]
div [] [ pre [] [ code [ class "code-block" ] [ text value ] ] ]

githubUrlPrefix branch =
"https://github.com/NixOS/nixpkgs/blob/" ++ branch ++ "/"
@@ -186,7 +186,7 @@ viewResultItem channel _ show item =
[ href <| githubUrlPrefix channelDetails.branch ++ (value |> String.replace ":" "#L")
, target "_blank"
]
[ text <| value ]
[ text value ]

Nothing ->
text <| cleanPosition value
@@ -212,7 +212,7 @@ viewResultItem channel _ show item =

showDetails =
if Just item.source.name == show then
[ div []
[ div [ Html.Attributes.map SearchMsg Search.trapClick ]
[ div [] [ text "Default value" ]
, div [] [ withEmpty (wrapped asPreCode) item.source.default ]
, div [] [ text "Type" ]
@@ -235,8 +235,7 @@ viewResultItem channel _ show item =
, onClick open
, Search.elementId item.source.name
]
([]
|> List.append showDetails
(showDetails
|> List.append
(item.source.description
|> Maybe.map showHtml
59 changes: 25 additions & 34 deletions src/Page/Packages.elm
Original file line number Diff line number Diff line change
@@ -32,10 +32,7 @@ import Html.Attributes
, id
, target
)
import Html.Events
exposing
( onClick
)
import Html.Events exposing (onClick)
import Json.Decode
import Json.Decode.Pipeline
import Json.Encode
@@ -308,14 +305,6 @@ viewResultItem :
-> List (Html Msg)
viewResultItem channel showNixOSDetails show item =
let
onClickStop message =
Html.Events.custom "click" <|
Json.Decode.succeed
{ message = message
, stopPropagation = True
, preventDefault = True
}

cleanPosition =
Regex.fromString "^[0-9a-f]+\\.tar\\.gz\\/"
|> Maybe.withDefault Regex.never
@@ -331,7 +320,7 @@ viewResultItem channel showNixOSDetails show item =
"https://github.com/NixOS/nixpkgs/blob/" ++ branch ++ "/" ++ uri

createShortDetailsItem title url =
[ li []
[ li [ Html.Attributes.map SearchMsg Search.trapClick ]
[ a
[ href url
, target "_blank"
@@ -342,22 +331,20 @@ viewResultItem channel showNixOSDetails show item =

shortPackageDetails =
ul []
([]
|> List.append
(item.source.position
|> Maybe.map
(\position ->
case Search.channelDetailsFromId channel of
Nothing ->
[]

Just channelDetails ->
createShortDetailsItem
"source"
(createGithubUrl channelDetails.branch position)
)
|> Maybe.withDefault []
((item.source.position
|> Maybe.map
(\position ->
case Search.channelDetailsFromId channel of
Nothing ->
[]

Just channelDetails ->
createShortDetailsItem
"source"
(createGithubUrl channelDetails.branch position)
)
|> Maybe.withDefault []
)
|> List.append
(item.source.homepage
|> List.head
@@ -448,9 +435,8 @@ viewResultItem channel showNixOSDetails show item =

longerPackageDetails =
if Just item.source.attr_name == show then
[ div []
([]
|> List.append maintainersAndPlatforms
[ div [ Html.Attributes.map SearchMsg Search.trapClick ]
(maintainersAndPlatforms
|> List.append
(item.source.longDescription
|> Maybe.map (\desc -> [ p [] [ text desc ] ])
@@ -472,7 +458,9 @@ viewResultItem channel showNixOSDetails show item =
]
[ a
[ href "#"
, onClickStop <| SearchMsg (Search.ShowNixOSDetails True)
, Search.onClickStop <|
SearchMsg <|
Search.ShowNixOSDetails True
]
[ text "On NixOS" ]
]
@@ -484,12 +472,15 @@ viewResultItem channel showNixOSDetails show item =
]
[ a
[ href "#"
, onClickStop <| SearchMsg (Search.ShowNixOSDetails False)
, Search.onClickStop <|
SearchMsg <|
Search.ShowNixOSDetails False
]
[ text "On non-NixOS" ]
]
]
, div [ class "tab-content" ]
, div
[ class "tab-content" ]
[ div
[ classList
[ ( "tab-pane", True )
22 changes: 22 additions & 0 deletions src/Search.elm
Original file line number Diff line number Diff line change
@@ -16,7 +16,9 @@ module Search exposing
, init
, makeRequest
, makeRequestBody
, onClickStop
, shouldLoad
, trapClick
, update
, view
)
@@ -1164,3 +1166,23 @@ decodeAggregationBucketItem =
Json.Decode.map2 AggregationsBucketItem
(Json.Decode.field "doc_count" Json.Decode.int)
(Json.Decode.field "key" Json.Decode.string)



-- Html Event Helpers


onClickStop : msg -> Html.Attribute msg
onClickStop message =
Html.Events.custom "click" <|
Json.Decode.succeed
{ message = message
, stopPropagation = True
, preventDefault = True
}


trapClick : Html.Attribute (Msg a b)
trapClick =
Html.Events.stopPropagationOn "click" <|
Json.Decode.succeed ( NoOp, True )
16 changes: 14 additions & 2 deletions src/index.less
Original file line number Diff line number Diff line change
@@ -27,6 +27,11 @@ body {
}
}

.code-block {
display: block;
cursor: text;
}

#content {
padding-bottom: 4rem;
}
@@ -341,7 +346,7 @@ header .navbar.navbar-static-top {

div.tab-content {
padding: 1em;
border: 1px solid #ddd;
border: 1px solid #ddd;
border-top: 0;
}

@@ -366,13 +371,20 @@ header .navbar.navbar-static-top {
}

&.option {
&:hover {
cursor: pointer;

.search-result-button {
text-decoration: underline;
}
}

// short details of a pacakge
& > :nth-child(3) {
margin-top: 1em;
margin-left: 1em;
display: grid;
grid-template-columns: 100px max-content;
grid-template-columns: 100px 1fr;
column-gap: 1em;
row-gap: 0.5em;