~jan0sch/smederee

Showing details for patch 71d756af611333c4292bbc0d7ed5417ad4408911.
2023-02-01 (Wed), 4:05 PM - Jens Grassel - 71d756af611333c4292bbc0d7ed5417ad4408911

HTML/CSS: Refactor repository menu into separate template.

This removes duplicate code and eases further adjustments.
Summary of changes
1 files added
  • modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryMenu.scala.html
4 files modified with 4 lines added and 46 lines removed
  • modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html with 1 added and 10 removed lines
  • modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHistory.scala.html with 1 added and 10 removed lines
  • modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryOverview.scala.html with 1 added and 16 removed lines
  • modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryPatch.scala.html with 1 added and 10 removed lines
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-01-31 22:49:24.861472688 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryFiles.scala.html	2025-01-31 22:49:24.861472688 +0000
@@ -17,16 +17,7 @@
       <div class="pure-u-1-1 pure-u-md-1-1">
         <div class="l-box-left-right">
           <h2><a href="@{baseUri.addSegment(s"~${vcsRepository.owner.name}")}">~@vcsRepository.owner.name</a>/@vcsRepository.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="@repositoryBaseUri">@icon(baseUri)("eye") @Messages("repository.menu.overview")</a></li>
-              <li class="pure-menu-item pure-menu-active"><a class="pure-menu-link" href="@repositoryBaseUri.addSegment("files")">@icon(baseUri)("folder") @Messages("repository.menu.files")</a></li>
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@repositoryBaseUri.addSegment("history")">@icon(baseUri)("list") @Messages("repository.menu.changes")</a></li>
-              @for(website <- vcsRepository.website) {
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@website" target="_blank" title="@Messages("repository.menu.website.tooltip", website)">@icon(baseUri)("external-link") @Messages("repository.menu.website")</a></li>
-              }
-            </ul>
-          </nav>
+          @showRepositoryMenu(baseUri)(repositoryBaseUri.addSegment("files").some, repositoryBaseUri, user, vcsRepository)
           <div class="repo-summary-description">
             <code>@{actionBaseUri.path.toString.replaceFirst("/files", "")}</code>
           </div>
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-01-31 22:49:24.861472688 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryHistory.scala.html	2025-01-31 22:49:24.861472688 +0000
@@ -17,16 +17,7 @@
       <div class="pure-u-1-1 pure-u-md-1-1">
         <div class="l-box-left-right">
           <h2><a href="@{baseUri.addSegment(s"~${vcsRepository.owner.name}")}">~@vcsRepository.owner.name</a>/@vcsRepository.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="@repositoryBaseUri">@icon(baseUri)("eye") @Messages("repository.menu.overview")</a></li>
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@repositoryBaseUri.addSegment("files")">@icon(baseUri)("folder") @Messages("repository.menu.files")</a></li>
-              <li class="pure-menu-item pure-menu-active"><a class="pure-menu-link" href="@repositoryBaseUri.addSegment("history")">@icon(baseUri)("list") @Messages("repository.menu.changes")</a></li>
-              @for(website <- vcsRepository.website) {
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@website" target="_blank" title="@Messages("repository.menu.website.tooltip", website)">@icon(baseUri)("external-link") @Messages("repository.menu.website")</a></li>
-              }
-            </ul>
-          </nav>
+          @showRepositoryMenu(baseUri)(repositoryBaseUri.addSegment("history").some, repositoryBaseUri, user, vcsRepository)
           <div class="repo-summary-description">
             @for(firstEntry <- history.headOption) {
               @Messages("repository.changes.description", history.size, firstEntry.hash.toString)
diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryMenu.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryMenu.scala.html
--- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryMenu.scala.html	1970-01-01 00:00:00.000000000 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryMenu.scala.html	2025-01-31 22:49:24.861472688 +0000
@@ -0,0 +1,30 @@
+@(baseUri: Uri
+)(activeUri: Option[Uri],
+  repositoryBaseUri: Uri,
+  user: Option[Account] = None,
+  vcsRepository: VcsRepository
+)(implicit locale: java.util.Locale)
+<nav class="pure-menu pure-menu-horizontal">
+  <ul class="pure-menu-list">
+    @defining(repositoryBaseUri) { uri =>
+    <li class="pure-menu-item@if(activeUri.exists(_ === uri)){ pure-menu-active}else{}"><a class="pure-menu-link" href="@uri">@icon(baseUri)("eye") @Messages("repository.menu.overview")</a></li>
+    }
+    @defining(repositoryBaseUri.addSegment("files")) { uri =>
+    <li class="pure-menu-item@if(activeUri.exists(_ === uri)){ pure-menu-active}else{}"><a class="pure-menu-link" href="@uri">@icon(baseUri)("folder") @Messages("repository.menu.files")</a></li>
+    }
+    @defining(repositoryBaseUri.addSegment("history")) { uri =>
+    <li class="pure-menu-item@if(activeUri.exists(_ === uri)){ pure-menu-active}else{}"><a class="pure-menu-link" href="@uri">@icon(baseUri)("list") @Messages("repository.menu.changes")</a></li>
+    }
+    @for(website <- vcsRepository.website) {
+    <li class="pure-menu-item"><a class="pure-menu-link" href="@website" target="_blank" title="@Messages("repository.menu.website.tooltip", website)">@icon(baseUri)("external-link") @Messages("repository.menu.website")</a></li>
+    }
+    @if(activeUri.exists(_ === repositoryBaseUri)) {
+      @if(user.exists(_.uid === vcsRepository.owner.uid)) {
+      <li class="pure-menu-item"><a class="pure-menu-link" href="@repositoryBaseUri.addSegment("edit")">@icon(baseUri)("edit-2") @Messages("repository.menu.edit")</a></li>
+      } else { }
+      @if(user.exists(_.uid === vcsRepository.owner.uid)) {
+      <li class="pure-menu-item"><a class="pure-menu-link" href="@repositoryBaseUri.addSegment("delete")">@icon(baseUri)("trash-2") @Messages("repository.menu.delete")</a></li>
+      } else { }
+    } else { }
+  </ul>
+</nav>
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-01-31 22:49:24.861472688 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryOverview.scala.html	2025-01-31 22:49:24.861472688 +0000
@@ -18,22 +18,7 @@
       <div class="pure-u-1">
         <div class="l-box-left-right">
           <h2><a href="@{baseUri.addSegment(s"~${vcsRepository.owner.name}")}">~@vcsRepository.owner.name</a>/@vcsRepository.name</h2>
-          <nav class="pure-menu pure-menu-horizontal">
-            <ul class="pure-menu-list">
-              <li class="pure-menu-item pure-menu-active"><a class="pure-menu-link" href="@actionBaseUri">@icon(baseUri)("eye") @Messages("repository.menu.overview")</a></li>
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@actionBaseUri.addSegment("files")">@icon(baseUri)("folder") @Messages("repository.menu.files")</a></li>
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@actionBaseUri.addSegment("history")">@icon(baseUri)("list") @Messages("repository.menu.changes")</a></li>
-              @for(website <- vcsRepository.website) {
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@website" target="_blank" title="@Messages("repository.menu.website.tooltip", website)">@icon(baseUri)("external-link") @Messages("repository.menu.website")</a></li>
-              }
-              @if(user.exists(_.uid === vcsRepository.owner.uid)) {
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@actionBaseUri.addSegment("edit")">@icon(baseUri)("edit-2") @Messages("repository.menu.edit")</a></li>
-              } else { }
-              @if(user.exists(_.uid === vcsRepository.owner.uid)) {
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@actionBaseUri.addSegment("delete")">@icon(baseUri)("trash-2") @Messages("repository.menu.delete")</a></li>
-              } else { }
-            </ul>
-          </nav>
+          @showRepositoryMenu(baseUri)(actionBaseUri.some, actionBaseUri, user, vcsRepository)
           @for(description <- vcsRepository.description) {
             <div class="repo-summary-description">
               <strong>@Messages("repository.description.title")</strong> @description
diff -rN -u old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryPatch.scala.html new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryPatch.scala.html
--- old-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryPatch.scala.html	2025-01-31 22:49:24.861472688 +0000
+++ new-smederee/modules/hub/src/main/twirl/de/smederee/hub/views/showRepositoryPatch.scala.html	2025-01-31 22:49:24.861472688 +0000
@@ -15,16 +15,7 @@
       <div class="pure-u-1-1 pure-u-md-1-1">
         <div class="l-box-left-right">
           <h2><a href="@{baseUri.addSegment(s"~${vcsRepository.owner.name}")}">~@vcsRepository.owner.name</a>/@vcsRepository.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="@actionBaseUri">@icon(baseUri)("eye") @Messages("repository.menu.overview")</a></li>
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@actionBaseUri.addSegment("files")">@icon(baseUri)("folder") @Messages("repository.menu.files")</a></li>
-              <li class="pure-menu-item pure-menu-active"><a class="pure-menu-link" href="@actionBaseUri.addSegment("history")">@icon(baseUri)("list") @Messages("repository.menu.changes")</a></li>
-              @for(website <- vcsRepository.website) {
-              <li class="pure-menu-item"><a class="pure-menu-link" href="@website" target="_blank" title="@Messages("repository.menu.website.tooltip", website)">@icon(baseUri)("external-link") @Messages("repository.menu.website")</a></li>
-              }
-            </ul>
-          </nav>
+          @showRepositoryMenu(baseUri)(actionBaseUri.addSegment("history").some, actionBaseUri, user, vcsRepository)
           <div class="repo-summary-description">
             @for(patch <- patch) {
               @Messages("repository.changes.patch.description", patch.hash.toString)