diff options
| author | Marius Peter <marius.peter@tutanota.com> | 2025-05-27 23:35:39 +0200 | 
|---|---|---|
| committer | Marius Peter <marius.peter@tutanota.com> | 2025-05-27 23:35:39 +0200 | 
| commit | 3d19770adbc6bed784ce2385a03c5c350aa75ebe (patch) | |
| tree | d6ed601e08d987d31484a0f9d812f2be0432e487 /lib | |
| parent | 08844a043b5ba4d77176c58d30db5088c9751b96 (diff) | |
Refactor + proper implementation for refs and log pages.
Great progress!  Ogit is increasingly looking like a usable (useful?)
product.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/views.ml | 49 | 
1 files changed, 32 insertions, 17 deletions
| diff --git a/lib/views.ml b/lib/views.ml index 456bbd1..b204674 100644 --- a/lib/views.ml +++ b/lib/views.ml @@ -1,5 +1,7 @@  (* -*- mode: tuareg; -*- *) +open Dream_html +open Git_presenters  open Config  type head_data = { page_title : string } @@ -79,10 +81,10 @@ module Page = struct  end  let root () = -  let open Dream_html in -  let repositories_in directory = +  let all_repositories =      let repos = -      Sys.readdir directory |> Array.to_list |> List.sort String.compare +      Sys.readdir config.git_project_root +      |> Array.to_list |> List.sort String.compare      in      let li_of_repo repo =        HTML.(li [] [ a [ href "%s/" repo ] [ txt "%s" repo ] ]) @@ -94,18 +96,17 @@ let root () =        title = "Ogit";        subtitle = "Repositories for " ^ config.user;        topnav = HTML.null []; -      content = [ repositories_in config.repositories_root_path ]; +      content = [ all_repositories ];      }    in    Page.render body_data  module Repo = struct    let summary repo branches commits authors = -    let open Dream_html in      let li_of_branch branch = -      HTML.(li [] [ a [ href "%s" branch ] [ txt "%s" branch ] ]) +      HTML.(li [] [ a [ href "%s" branch.name ] [ txt "%s" branch.name ] ])      in -    let li_of_commit (commit : Git_presenters.Commit.t) = +    let li_of_commit commit =        match commit.message with        | Some msg ->            HTML.( @@ -139,30 +140,46 @@ module Repo = struct          content;        } -  let refs repo = -    let open Dream_html in +  let refs repo branches = +    let li_of_branch branch = +      HTML.(li [] [ a [ href "%s" branch.name ] [ txt "%s" branch.name ] ]) +    in      Page.render        HTML.          {            title = repo;            subtitle = Git_presenters.repo_description repo;            topnav = Components.topnav repo; -          content = [ null [] ]; +          content = +            [ h3 [] [ txt "Branches" ]; ul [] (List.map li_of_branch branches) ];          } -  let log repo = -    let open Dream_html in +  let log repo commits = +    let li_of_commit commit = +      match commit.message with +      | Some msg -> +          HTML.( +            li [] +              [ +                a +                  [ href "commit/?id=%s" commit.hash ] +                  [ txt "%s %s" commit.short_hash msg ]; +              ]) +      | None -> HTML.(li [] [ a [ href "" ] [ txt "caca!!" ] ]) +    in      Page.render        HTML.          {            title = repo;            subtitle = Git_presenters.repo_description repo;            topnav = Components.topnav repo; -          content = [ null [] ]; +          content = +            [ +              h3 [] [ txt "All commits" ]; ul [] (List.map li_of_commit commits); +            ];          }    let tree repo = -    let open Dream_html in      Page.render        HTML.          { @@ -172,8 +189,7 @@ module Repo = struct            content = [ null [] ];          } -  let commit repo (commit : Git_presenters.Commit.t) = -    let open Dream_html in +  let commit repo commit =      let message = match commit.message with Some msg -> msg | None -> "" in      let content = HTML.[ h3 [] [ txt "%s" message ] ] in      let title = Printf.sprintf "%s : %s" repo commit.short_hash in @@ -182,7 +198,6 @@ module Repo = struct  end  let error_page message = -  let open Dream_html in    HTML.(      html []        [ | 
