diff --git a/src/web/FloraWeb/Components/PaginationNav.hs b/src/web/FloraWeb/Components/PaginationNav.hs index 17fa0098..b2be4bc6 100644 --- a/src/web/FloraWeb/Components/PaginationNav.hs +++ b/src/web/FloraWeb/Components/PaginationNav.hs @@ -45,11 +45,11 @@ mkURL :: SearchAction -> Positive Word -> Text mkURL ListAllPackages pageNumber = "/" <> toUrlPiece (Links.packageIndexLink pageNumber) mkURL (ListAllPackagesInNamespace namespace) pageNumber = - "/" <> toUrlPiece (Links.namespaceLink namespace pageNumber) + Links.namespacePage namespace pageNumber mkURL (SearchPackages searchTerm) pageNumber = "/" <> toUrlPiece (Links.packageSearchLink searchTerm pageNumber) mkURL (DependentsOf namespace packageName mbSearchString) pageNumber = - "/" <> toUrlPiece (Links.packageDependents namespace packageName pageNumber mbSearchString) + Links.dependentsPage namespace packageName pageNumber <> "q=" <> toUrlPiece mbSearchString mkURL (SearchExecutable searchString) pageNumber = "/" <> toUrlPiece (Links.packageWithExecutable pageNumber searchString) diff --git a/src/web/FloraWeb/Links.hs b/src/web/FloraWeb/Links.hs index 08901ca8..19e74845 100644 --- a/src/web/FloraWeb/Links.hs +++ b/src/web/FloraWeb/Links.hs @@ -2,6 +2,7 @@ module FloraWeb.Links where import Data.Positive import Data.Text (Text) +import Data.Text.Display (display) import Distribution.Orphans () import Distribution.Version (Version) import Flora.Model.Package (Namespace (..), PackageName (..)) @@ -115,3 +116,31 @@ packageWithExecutable pageNumber search = // Search.displaySearch /: Just search /: Just pageNumber + +namespacePage :: Namespace -> Positive Word -> Text +namespacePage namespace pageNumber = + "/packages/" <> display namespace <> "?page=" <> toUrlPiece pageNumber + +packageResource :: Namespace -> PackageName -> Text +packageResource namespace name = "/packages/" <> display namespace <> "/" <> display name + +versionResource :: Namespace -> PackageName -> Version -> Text +versionResource namespace name version = + packageResource namespace name + <> "/" + <> display version + +dependentsPage :: Namespace -> PackageName -> Positive Word -> Text +dependentsPage namespace packageName pageNum = + packageResource namespace packageName + <> "/dependents?page=" + <> toUrlPiece pageNum + +dependenciesPage :: Namespace -> PackageName -> Version -> Text +dependenciesPage namespace packageName version = + versionResource namespace packageName version + <> "/dependencies" + +versionsPage :: Namespace -> PackageName -> Text +versionsPage namespace packageName = + packageResource namespace packageName <> "/versions" diff --git a/src/web/FloraWeb/Pages/Templates/Packages.hs b/src/web/FloraWeb/Pages/Templates/Packages.hs index c312e7d0..f3e19ee3 100644 --- a/src/web/FloraWeb/Pages/Templates/Packages.hs +++ b/src/web/FloraWeb/Pages/Templates/Packages.hs @@ -246,7 +246,7 @@ displayNamespace namespace = a_ [ class_ "breadcrumb-segment" , href_ - ("/" <> toUrlPiece (Links.namespaceLink namespace 1)) + ("/packages/" <> display namespace <> "?page=1") ] (toHtml $ display namespace) @@ -324,7 +324,7 @@ displayVersions namespace packageName versions numberOfReleases = let versionClass = "release-version" <> if Just True == release.deprecated then " release-deprecated" else "" let dataText = ([dataText_ "This release is deprecated, pick another one" | Just True == release.deprecated]) a_ - ([class_ versionClass, href_ ("/" <> toUrlPiece (Links.packageVersionLink namespace packageName release.version))] <> dataText) + ([class_ versionClass, href_ $ Links.versionResource namespace packageName release.version] <> dataText) (toHtml $ display release.version) " " case release.uploadedAt of @@ -361,10 +361,10 @@ displayDependencies (namespace, packageName, version) numberOfDependencies depen showAll :: Target -> Maybe Version -> Namespace -> PackageName -> FloraHTML showAll target mVersion namespace packageName = do let resource = case target of - Dependents -> Links.packageDependents namespace packageName (PositiveUnsafe 1) Nothing - Dependencies -> Links.packageDependencies namespace packageName (fromJust mVersion) - Versions -> Links.packageVersions namespace packageName - a_ [class_ "dependency", href_ ("/" <> toUrlPiece resource)] "Show all…" + Dependents -> Links.dependentsPage namespace packageName (PositiveUnsafe 1) + Dependencies -> Links.dependenciesPage namespace packageName (fromJust mVersion) + Versions -> Links.versionsPage namespace packageName + a_ [class_ "dependency", href_ resource] "Show all…" displayInstructions :: Namespace -> PackageName -> Release -> FloraHTML displayInstructions namespace packageName latestRelease = @@ -404,7 +404,7 @@ displayPackageDeprecation (PackageAlternatives inFavourOf) = \PackageAlternative{namespace, package} -> li_ [] $ a_ - [href_ ("/packages/" <> display namespace <> "/" <> display package)] + [href_ $ Links.packageResource namespace package] (text $ display namespace <> "/" <> display package) displayReleaseDeprecation :: Maybe (Namespace, PackageName, Version) -> FloraHTML @@ -416,7 +416,7 @@ displayReleaseDeprecation mLatestViableRelease = Just (namespace, package, version) -> do label_ [for_ "install-string", class_ "font-light"] (text "This release has been deprecated in favour of: ") a_ - [href_ ("/packages/" <> display namespace <> "/" <> display package <> "/" <> display version)] + [href_ $ Links.versionResource namespace package version] (text $ display namespace <> "/" <> display package <> "-" <> display version) displayTestedWith :: Vector Version -> FloraHTML @@ -456,15 +456,13 @@ displayDependents (namespace, packageName) numberOfDependents dependents = renderDependent :: Package -> FloraHTML renderDependent Package{name, namespace} = do let qualifiedName = toHtml $ display namespace <> "/" <> display name - let resource = "/packages/" <> display namespace <> "/" <> display name - a_ [class_ "dependent", href_ resource] qualifiedName + a_ [class_ "dependent", href_ $ Links.packageResource namespace name] qualifiedName renderDependency :: (Namespace, PackageName, Text) -> FloraHTML renderDependency (namespace, name, version) = do - let resource = "/packages/" <> display namespace <> "/" <> display name li_ [class_ "dependency"] $ do - a_ [href_ resource] (toHtml name) + a_ [href_ $ Links.packageResource namespace name] (toHtml name) toHtmlRaw @Text " " if version == ">=0" then ""