~jan0sch/smederee

Showing details for patch b195b945e418336cabca9596c5d3551c6f0169be.
2022-09-02 (Fri), 4:25 PM - Jens Grassel - b195b945e418336cabca9596c5d3551c6f0169be

VCS: Refactoring in project view

- show always username/project
- some css fixes
- include external link config for proper urls
Summary of changes
7 files modified with 90 lines added and 40 lines removed
  • modules/hub/src/main/resources/assets/css/main.css with 14 added and 0 removed lines
  • modules/hub/src/main/scala/de/smederee/hub/HubServer.scala with 6 added and 1 removed lines
  • modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala with 41 added and 22 removed lines
  • modules/hub/src/main/twirl/de/smederee/hub/views/createFullPath.scala.html with 1 added and 1 removed lines
  • modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html with 2 added and 2 removed lines
  • modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHistory.scala.html with 2 added and 2 removed lines
  • modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryOverview.scala.html with 24 added and 12 removed lines
diff -rN -u old-smederee/modules/hub/src/main/resources/assets/css/main.css new-smederee/modules/hub/src/main/resources/assets/css/main.css
--- old-smederee/modules/hub/src/main/resources/assets/css/main.css	2025-02-02 11:50:39.700002508 +0000
+++ new-smederee/modules/hub/src/main/resources/assets/css/main.css	2025-02-02 11:50:39.704002523 +0000
@@ -100,6 +100,20 @@
   color: #AECFE5;
 }
 
+pre.latest-changes {
+  overflow-x: auto;
+  overflow-y: hidden;
+  white-space: pre-wrap;
+  white-space: -moz-pre-wrap;
+  white-space: -pre-wrap;
+  white-space: -o-pre-wrap;
+  word-wrap: break-word;
+}
+
+pre.latest-changes code {
+  font-size: 85%;
+}
+
 pre.repository-file-content {
   display: block;
   overflow-x: auto;
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/HubServer.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/HubServer.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/HubServer.scala	2025-02-02 11:50:39.700002508 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/HubServer.scala	2025-02-02 11:50:39.704002523 +0000
@@ -113,7 +113,12 @@
       signUpRoutes    = new SignupRoutes[IO](configuration.service.signup, signUpRepo)
       landingPages    = new LandingPageRoutes[IO]()
       vcsMetadataRepo = new DoobieVcsMetadataRepository[IO](transactor)
-      vcsRepoRoutes = new VcsRepositoryRoutes[IO](configuration.service.darcs, darcsWrapper, vcsMetadataRepo)
+      vcsRepoRoutes = new VcsRepositoryRoutes[IO](
+        configuration.service.darcs,
+        darcsWrapper,
+        configuration.service.external,
+        vcsMetadataRepo
+      )
       protectedRoutesWithFallThrough = authenticationWithFallThrough(
         authenticationRoutes.protectedRoutes <+> signUpRoutes.protectedRoutes <+> vcsRepoRoutes.protectedRoutes <+> landingPages.protectedRoutes
       )
diff -rN -u old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala
--- old-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-02-02 11:50:39.704002523 +0000
+++ new-smederee/modules/hub/src/main/scala/de/smederee/hub/VcsRepositoryRoutes.scala	2025-02-02 11:50:39.704002523 +0000
@@ -41,18 +41,21 @@
 
 /** Routes for handling VCS repositories, including creation, management and public serving.
   *
-  * @param config
+  * @param darcsConfig
   *   The configuration for darcs related operations.
   * @param darcs
   *   A class providing darcs VCS operations.
+  * @param linkConfig
+  *   The configuration needed to build correct links which are working from the outside.
   * @param vcsMetadataRepo
   *   A repository for handling database operations regarding our vcs repositories and their metadata.
   * @tparam F
   *   A higher kinded type providing needed functionality, which is usually an IO monad like Async or Sync.
   */
 final class VcsRepositoryRoutes[F[_]: Async](
-    config: DarcsConfiguration,
+    darcsConfig: DarcsConfiguration,
     darcs: DarcsCommands[F],
+    linkConfig: ExternalLinkConfig,
     vcsMetadataRepo: VcsMetadataRepository[F]
 ) extends Http4sDsl[F] {
   private val log = LoggerFactory.getLogger(getClass)
@@ -110,8 +113,16 @@
           loadedRepo.filter(r => r.isPrivate === false || r.owner === user.toVcsRepositoryOwner)
       }
       actionBaseUri <- Sync[F].delay(
-        Uri(path =
-          Uri.Path.Root |+| Uri.Path(
+        Uri(
+          scheme = linkConfig.scheme.some,
+          authority = Uri
+            .Authority(
+              userInfo = None,
+              host = Uri.Host.fromIp4sHost(linkConfig.host),
+              port = linkConfig.port.map(_.value)
+            )
+            .some,
+          path = Uri.Path.Root |+| Uri.Path(
             Vector(Uri.Path.Segment(s"~$repositoryOwnerName"), Uri.Path.Segment(repositoryName.toString))
           )
         )
@@ -119,12 +130,12 @@
       directory <- Sync[F].delay(
         os.Path(
           Paths.get(
-            config.repositoriesDirectory.toPath.toString,
+            darcsConfig.repositoriesDirectory.toPath.toString,
             repositoryOwnerName.toString
           )
         )
       )
-      log        <- darcs.log(directory.toNIO)(repositoryName.toString)(Chain(s"--max-count=3"))
+      log        <- darcs.log(directory.toNIO)(repositoryName.toString)(Chain(s"--max-count=2"))
       readmeData <- repo.traverse(repo => doLoadReadme(repo))
       readme <- readmeData match {
         case Some((lines, Some(filename))) =>
@@ -198,7 +209,7 @@
           Sync[F].delay(
             os.Path(
               Paths.get(
-                config.repositoriesDirectory.toPath.toString,
+                darcsConfig.repositoriesDirectory.toPath.toString,
                 repositoryOwnerName.toString,
                 repositoryName.toString,
                 filePath.segments.mkString("/")
@@ -250,7 +261,7 @@
       resp <-
         repo match {
           case None => NotFound("Repository not found!")
-          case Some(_) =>
+          case Some(repo) =>
             if (
               filePath.segments.mkString
                 .startsWith("_darcs") || filePath.segments.mkString.startsWith("/_darcs")
@@ -264,7 +275,7 @@
                   Option(goBackUri),
                   s"Smederee/~$repositoryOwnerName/$repositoryName".some,
                   user
-                )(fileContent, listing, repositoryBaseUri, repositoryName)
+                )(fileContent, listing, repositoryBaseUri, repo)
               )
         }
     } yield resp
@@ -304,7 +315,7 @@
       directory <- Sync[F].delay(
         os.Path(
           Paths.get(
-            config.repositoriesDirectory.toPath.toString,
+            darcsConfig.repositoriesDirectory.toPath.toString,
             repositoryOwnerName.toString
           )
         )
@@ -347,15 +358,19 @@
           )
         )
       )
-      resp <- Ok.apply(
-        views.html.showRepositoryHistory()(
-          actionBaseUri,
-          csrf,
-          Option(goBackUri),
-          s"Smederee - History of ~$repositoryOwnerName/$repositoryName".some,
-          user
-        )(history.stdout.toList.mkString("\n"), next, repositoryBaseUri, repositoryName)
-      )
+      resp <- repo match {
+        case None => NotFound()
+        case Some(repo) =>
+          Ok.apply(
+            views.html.showRepositoryHistory()(
+              actionBaseUri,
+              csrf,
+              Option(goBackUri),
+              s"Smederee - History of ~$repositoryOwnerName/$repositoryName".some,
+              user
+            )(history.stdout.toList.mkString("\n"), next, repositoryBaseUri, repo)
+          )
+      }
     } yield resp
 
   /** List walk the given directory at the first level and return all found files and directories and their
@@ -402,7 +417,11 @@
   private def doLoadReadme(repo: VcsRepository): F[(Vector[String], Option[String])] =
     for {
       path <- Sync[F].delay(
-        Paths.get(config.repositoriesDirectory.toPath.toString, repo.owner.name.toString, repo.name.toString)
+        Paths.get(
+          darcsConfig.repositoriesDirectory.toPath.toString,
+          repo.owner.name.toString,
+          repo.name.toString
+        )
       )
       _     <- Sync[F].delay(log.debug(s"Trying to find README file in $path."))
       files <- Sync[F].delay(os.list(os.Path(path)))
@@ -435,7 +454,7 @@
           repo.map(_ =>
             fs2.io.file.Path.fromNioPath(
               Paths.get(
-                config.repositoriesDirectory.toPath.toString,
+                darcsConfig.repositoriesDirectory.toPath.toString,
                 repositoryOwnerName.toString,
                 repositoryName.toString,
                 filePath.segments.mkString("/")
@@ -478,7 +497,7 @@
             case Validated.Valid(newVcsRepository) =>
               for {
                 directory <- Sync[F].delay(
-                  Paths.get(config.repositoriesDirectory.toPath.toString, user.name.toString)
+                  Paths.get(darcsConfig.repositoriesDirectory.toPath.toString, user.name.toString)
                 )
                 repoInDb <- vcsMetadataRepo.findVcsRepository(
                   user.toVcsRepositoryOwner,
diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/createFullPath.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/createFullPath.scala.html
--- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/createFullPath.scala.html	2025-02-02 11:50:39.704002523 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/createFullPath.scala.html	2025-02-02 11:50:39.704002523 +0000
@@ -1,2 +1,2 @@
 @(pathPrefix: Option[Uri] = None)(path: Uri)
-@{pathPrefix.map(prefix => prefix.copy(path = prefix.path |+| path.path)).getOrElse(path)}
+@{path.copy(path = pathPrefix.map(_.path).getOrElse(Uri.Path.empty) |+| path.path)}
diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html
--- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html	2025-02-02 11:50:39.704002523 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html	2025-02-02 11:50:39.704002523 +0000
@@ -1,10 +1,10 @@
-@(lang: LanguageCode = LanguageCode("en"), pathPrefix: Option[Uri] = None)(actionBaseUri: Uri, csrf: Option[CsrfToken] = None, goBackUri: Option[Uri] = None, title: Option[String] = None, user: Option[Account])(fileContent: Option[String], listing: IndexedSeq[(os.RelPath, os.StatInfo)], repositoryBaseUri: Uri, repositoryName: VcsRepositoryName)
+@(lang: LanguageCode = LanguageCode("en"), pathPrefix: Option[Uri] = None)(actionBaseUri: Uri, csrf: Option[CsrfToken] = None, goBackUri: Option[Uri] = None, title: Option[String] = None, user: Option[Account])(fileContent: Option[String], listing: IndexedSeq[(os.RelPath, os.StatInfo)], repositoryBaseUri: Uri, repository: VcsRepository)
 @main(lang, pathPrefix)()(csrf, title, user) {
 @defining(lang.toLocale) { implicit locale =>
   <div class="content">
     <div class="pure-g">
       <div class="l-box pure-u-1-1 pure-u-md-1-1">
-        <h2>@repositoryName</h2>
+        <h2>~@{repository.owner.name}/@{repository.name}</h2>
         <nav class="pure-menu pure-menu-horizontal">
           <ul class="pure-menu-list">
             <li class="pure-menu-item"><a class="pure-menu-link" href="@createFullPath(pathPrefix)(repositoryBaseUri)"><i class="fa-solid fa-eye"></i> Overview</a></li>
diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHistory.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHistory.scala.html
--- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHistory.scala.html	2025-02-02 11:50:39.704002523 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHistory.scala.html	2025-02-02 11:50:39.704002523 +0000
@@ -1,10 +1,10 @@
-@(lang: LanguageCode = LanguageCode("en"), pathPrefix: Option[Uri] = None)(actionBaseUri: Uri, csrf: Option[CsrfToken] = None, goBackUri: Option[Uri] = None, title: Option[String] = None, user: Option[Account])(history: String, nextEntry: Option[Int], repositoryBaseUri: Uri, repositoryName: VcsRepositoryName)
+@(lang: LanguageCode = LanguageCode("en"), pathPrefix: Option[Uri] = None)(actionBaseUri: Uri, csrf: Option[CsrfToken] = None, goBackUri: Option[Uri] = None, title: Option[String] = None, user: Option[Account])(history: String, nextEntry: Option[Int], repositoryBaseUri: Uri, repository: VcsRepository)
 @main(lang, pathPrefix)()(csrf, title, user) {
 @defining(lang.toLocale) { implicit locale =>
   <div class="content">
     <div class="pure-g">
       <div class="l-box pure-u-1-1 pure-u-md-1-1">
-        <h2>@repositoryName</h2>
+        <h2>~@{repository.owner.name}/@{repository.name}</h2>
         <nav class="pure-menu pure-menu-horizontal">
           <ul class="pure-menu-list">
             <li class="pure-menu-item"><a class="pure-menu-link" href="@createFullPath(pathPrefix)(actionBaseUri)"><i class="fa-solid fa-eye"></i> Overview</a></li>
diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryOverview.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryOverview.scala.html
--- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryOverview.scala.html	2025-02-02 11:50:39.704002523 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryOverview.scala.html	2025-02-02 11:50:39.704002523 +0000
@@ -18,24 +18,35 @@
   </div>
   <div class="content">
     <div class="pure-g">
-      <div class="l-box pure-u-1 pure-u-md-1-2">
-        <h3>Latest changes</h3>
-        <pre><code>@vcsRepositoryHistory</code></pre>
+      <div class="pure-u-3-5 pure-u-md-3-5">
+        <div class="l-box">
+          <h3>Latest changes</h3>
+          <pre class="latest-changes"><code>@vcsRepositoryHistory</code></pre>
+        </div>
       </div>
-      <div class="l-box pure-u-1 pure-u-md-1-2">
-        <h3>Clone</h3>
-        <dl class="clone-links">
-          <dt>read-only</dt>
-          <dd><a href="@{createFullPath(pathPrefix)(actionBaseUri)}.darcs">@{createFullPath(pathPrefix)(actionBaseUri)}.darcs</a></dd>
-          <dt>read-write</dt>
-          <dd>TODO</dd>
-        </dl>
+      <div class="pure-u-2-5 pure-u-md-2-5">
+        <div class="l-box">
+          <h3>Clone</h3>
+          <dl class="clone-links">
+            <dt>read-only</dt>
+            <dd>
+              <form class="pure-form">
+                <fieldset>
+                  <input class="pure-input-1" type="text" value="@{createFullPath(pathPrefix)(actionBaseUri)}.darcs" readonly="readonly"/>
+                </fieldset>
+              </form>
+            </dd>
+            <dt>read-write</dt>
+            <dd>TODO</dd>
+          </dl>
+        </div>
       </div>
     </div>
   </div>
   <div class="content">
     <div class="pure-g">
-      <div class="l-box pure-u-1 pure-u-md-1-1 repo-summary-readme">
+      <div class="pure-u-1 pure-u-md-1-1 repo-summary-readme">
+        <div class="l-box">
         @for(content <- vcsRepositoryReadme) {
           @if(vcsRepositoryReadmeFilename.exists(_.matches("(?iu).*\\.(md|markdown)$"))) {
             @Html(content)
@@ -43,6 +54,7 @@
             @content
           }
         }
+        </div>
       </div>
     </div>
   </div>