Commit 95600e21a857113b9c9b178ea858a569cb79f344

Thomas de Grivel 2022-01-16T08:38:31

better commit view

diff --git a/lib/kmxgit_web/controllers/repository_controller.ex b/lib/kmxgit_web/controllers/repository_controller.ex
index 7074aa3..d67e094 100644
--- a/lib/kmxgit_web/controllers/repository_controller.ex
+++ b/lib/kmxgit_web/controllers/repository_controller.ex
@@ -255,11 +255,7 @@ defmodule KmxgitWeb.RepositoryController do
                    _ -> mime_type(content)
                  end
           content_html = Pygmentize.html(content, filename(name))
-          line_numbers = content
-          |> String.split("\n")
-          |> Enum.with_index()
-          |> Enum.map(fn {_, i} -> i end)
-          |> Enum.join("\n")
+          line_numbers = line_numbers(content)
           IO.inspect(path: path, name: name, type: type)
           %{git | content: content, content_html: content_html, content_type: type, filename: name, line_numbers: line_numbers}
         {:error, error} -> %{git | status: error}
@@ -362,11 +358,13 @@ defmodule KmxgitWeb.RepositoryController do
     IO.inspect(git)
     {:ok, diff} = GitManager.diff(Repository.full_slug(repo), "#{git.log1.hash}~1", git.log1.hash)
     diff_html = Pygmentize.html(diff, "diff.patch")
+    diff_line_numbers = line_numbers(diff)
     conn
     |> assign(:commit, git.log1)
     |> assign_current_organisation(org)
     |> assign(:current_repository, repo)
     |> assign(:diff_html, diff_html)
+    |> assign(:diff_line_numbers, diff_line_numbers)
     |> assign(:repo, repo)
     |> render("commit.html")
   end
@@ -440,6 +438,14 @@ defmodule KmxgitWeb.RepositoryController do
     end
   end
 
+  def line_numbers(string) do
+    string
+    |> String.split("\n")
+    |> Enum.with_index()
+    |> Enum.map(fn {_, i} -> "#{i}" end)
+    |> Enum.join("\n")
+  end
+
   def update(conn, params) do
     current_user = conn.assigns.current_user
     slug = Enum.join(params["slug"], "/")
diff --git a/lib/kmxgit_web/templates/repository/commit.html.heex b/lib/kmxgit_web/templates/repository/commit.html.heex
index 543bb17..ef9b2f5 100644
--- a/lib/kmxgit_web/templates/repository/commit.html.heex
+++ b/lib/kmxgit_web/templates/repository/commit.html.heex
@@ -1,40 +1,38 @@
 <div class="container-fluid">
   <div class="row">
-    <div class="col col-12">
+    <div class="col col-12 col-md-7">
       <%= render("show_title.html", assigns) %>
+    </div>
+    <div class="col col-12 col-md-5">
+      <%= link gettext("Browse"), to: Routes.repository_path(@conn, :show, Repository.owner_slug(@repo), Repository.splat(@repo, ["_tree", @commit.hash])), class: "btn btn-primary" %>
+      <%= link gettext("Diff"), to: Routes.repository_path(@conn, :show, Repository.owner_slug(@repo), Repository.splat(@repo, ["_diff", @commit.hash, "master"])), class: "btn btn-primary" %>
+    </div>
+  </div>
+  <div class="row">
+    <div class="col col-12">
+      <hr/>
       <h2>
         <%= gettext("Commit") %>
         <%= @commit.hash %>
       </h2>
-    </div>
-  </div>
-  <div class="row">
-    <hr/>
-    <div class="col col-12 col-md-7">
+      <div>
+        <b><%= gettext("Author") %> :</b>
+        <%= @commit.author %>
+      </div>
+      <div>
+        <b><%= gettext("Date") %> :</b>
+        <%= @commit.date |> String.replace("T", " ") |> String.replace("+", " +") %>
+      </div>
       <p>
         <%= @commit.message %>
       </p>
-      <%= raw @diff_html %>
+      <div class="content_text">
+        <div class="line_numbers">
+          <pre><%= @diff_line_numbers %></pre>
+        </div>
+        <%= raw @diff_html %>
+      </div>
       <hr/>
     </div>
-    <div class="col col-12 col-md-5">
-      <table class="table">
-        <tr>
-          <th><%= gettext("Actions") %></th>
-          <td>
-            <%= link gettext("Browse"), to: Routes.repository_path(@conn, :show, Repository.owner_slug(@repo), Repository.splat(@repo, ["_tree", @commit.hash])), class: "btn btn-primary" %>
-            <%= link gettext("Diff"), to: Routes.repository_path(@conn, :show, Repository.owner_slug(@repo), Repository.splat(@repo, ["_diff", @commit.hash, "master"])), class: "btn btn-primary" %>
-          </td>
-        </tr>
-        <tr>
-          <th><%= gettext("Author") %></th>
-          <td><%= @commit.author %></td>
-        </tr>
-        <tr>
-          <th><%= gettext("Date") %></th>
-          <td><%= @commit.date |> String.replace("T", " ") |> String.replace("+", " +") %></td>
-        </tr>
-      </table>
-    </div>
   </div>
 </div>