From 60e7d534087e047e8809e090e04e6ea2fc959209 Mon Sep 17 00:00:00 2001 From: Fardale Date: Tue, 25 Oct 2022 23:01:58 +0200 Subject: [PATCH 1/6] fix: findlib-package in conf --- ocsigenserver.conf.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ocsigenserver.conf.in b/ocsigenserver.conf.in index 58345b9..f12def9 100644 --- a/ocsigenserver.conf.in +++ b/ocsigenserver.conf.in @@ -16,8 +16,9 @@ - + + From 05786532fdeabeeb7bd2fe4d1137a92642a48f23 Mon Sep 17 00:00:00 2001 From: Fardale Date: Tue, 25 Oct 2022 23:02:44 +0200 Subject: [PATCH 2/6] cleanup: remove custom operator define in lib (|>) is define in the stdlib since 4.01 filter_map is define in Lwt_list --- src/database.ml | 2 -- src/history.ml | 4 +--- src/html_util.ml | 10 +++++----- src/main.ml | 48 ++++++++++++++++++------------------------------ src/scheduler.ml | 8 +++----- 5 files changed, 27 insertions(+), 45 deletions(-) diff --git a/src/database.ml b/src/database.ml index f275350..9ef205e 100644 --- a/src/database.ml +++ b/src/database.ml @@ -22,8 +22,6 @@ open Config type connection = Psql.connection -let ( |> ) f g = g f - module ConnectionPool = struct open Psql diff --git a/src/history.ml b/src/history.ml index 8c51054..ab35e12 100644 --- a/src/history.ml +++ b/src/history.ml @@ -32,8 +32,6 @@ open CalendarLib module Db = Database -let ( & ) f x = f x - let n_log_items_per_page = 300 let descr_of_activity_type = function @@ -203,7 +201,7 @@ let view_history_page ~cur_user ~nth_page = [tr [td ~a:[a_class ["no_break"; "h_date_heading"]] date_text]] @ lst_acc, prettified_date)) activity_groups ([],"")))) in - return & Html_util.html_stub ~title:"History" + return @@ Html_util.html_stub ~title:"History" (Html_util.navbar_html ~cur_user ([h1 [txt "Blast from the past"]] @ (page_links nth_page n_total_pages) @ [br (); br ()] @ diff --git a/src/html_util.ml b/src/html_util.ml index bc9a897..ffbb07b 100644 --- a/src/html_util.ml +++ b/src/html_util.ml @@ -41,11 +41,11 @@ let html_stub ?(javascript=[]) ~title body_html = html ~a:[a_xmlns `W3_org_1999_xhtml] (head (Eliom_content.Html.F.title (txt (title ^ " — Nurpawiki"))) - ((scripts) @ - [css_link ~a:[] ~uri:(make_uri ~service:(static_dir ()) - ["style.css"]) (); - css_link ~a:[] ~uri:(make_uri ~service:(static_dir ()) - ["jscalendar"; "calendar-blue2.css"]) ()])) + (css_link ~a:[] ~uri:(make_uri ~service:(static_dir ()) + ["style.css"]) ():: + css_link ~a:[] ~uri:(make_uri ~service:(static_dir ()) + ["jscalendar"; "calendar-blue2.css"]) ():: + scripts)) (body body_html) let is_guest user = diff --git a/src/main.ml b/src/main.ml index 3493752..d5e0180 100644 --- a/src/main.ml +++ b/src/main.ml @@ -33,19 +33,7 @@ module Psql = Postgresql module P = Printf (* TODO no need to extract here *) -let matches_pcre rex s = - try ignore (Pcre.extract ~rex s); true with Not_found -> false - -let ( |> ) f g = g f -let ( & ) f g = f g - -let rec filter_map f = function - | [] -> return [] - | x::xs -> - let%lwt ys = filter_map f xs in - match%lwt f x with - | Some y -> return & y::ys - | None -> return ys +let matches_pcre rex s = Pcre.pmatch ~rex s let newline_re = Pcre.regexp "\n" @@ -57,7 +45,7 @@ let task_side_effect_complete task_id () = begin Db.complete_task ~user_id:user.user_id task_id;%lwt let table = Eliom_request_info.get_request_cache () in - return & Polytables.set ~table ~key:action_completed_task ~value:task_id + return @@ Polytables.set ~table ~key:action_completed_task ~value:task_id end else return ()) @@ -80,7 +68,7 @@ let task_side_effect_mod_priority (task_id, dir) () = else Db.up_task_priority task_id;%lwt let table = Eliom_request_info.get_request_cache () in - return & Polytables.set ~table ~key:action_task_priority_changed ~value:task_id + return @@ Polytables.set ~table ~key:action_task_priority_changed ~value:task_id end else return ()) @@ -262,7 +250,7 @@ module WikiML = else (* External link *) let url = scheme^":"^page in let t = if text = "" then url else text in - return & Raw.a ~a:[a_href (uri_of_string (fun () -> url))] [ext_img; txt t] in + return @@ Raw.a ~a:[a_href (uri_of_string (fun () -> url))] [ext_img; txt t] in let add_html html_acc html = html::html_acc in @@ -301,7 +289,7 @@ module WikiML = let wiki_error s charpos = let s = (String.sub s charpos ((String.length s)-charpos)) in - return & + return @@ add_html acc (Html_util.error ("WIKI SYNTAX ERROR on line: '"^s^"'")) in @@ -383,7 +371,7 @@ module WikiML = let (after_bullets,bullets) = take_while is_list_or_empty lst in let%lwt list_items = - filter_map + Lwt_list.filter_map_s (function (`Wiki e) as wl -> if matches_pcre ws_or_empty_re e then @@ -395,7 +383,7 @@ module WikiML = Some r -> let n_stars = String.length r.(1) in let%lwt x = parse_text [] r.(2) in - return & Some (n_stars, x) + return @@ Some (n_stars, x) | None -> assert false end @@ -418,7 +406,7 @@ module WikiML = end | (`NoWiki x::xs) -> loop (pre [txt (String.concat "\n" x)]::acc) xs - | [] -> return & List.rev acc in + | [] -> return @@ List.rev acc in loop [] preprocessed_lines @@ -446,7 +434,7 @@ let todo_list_table_html ~cur_user cur_page todos = let priority_changes = Session.any_task_priority_changes () in - return & + return @@ table ~a:[a_class ["todo_table"]] @@ (tr [th [txt "Id"]; th [txt "Description"]]) :: @@ -504,7 +492,7 @@ let wiki_page_menu_html ~cur_user page content = ~service:task_side_effect_undo_complete_action [txt "Undo"] id]] in - return & Html_util.navbar_html ~cur_user + return @@ Html_util.navbar_html ~cur_user ~wiki_page_links:(edit_link @ [txt " "] @ printable_link) ~wiki_revisions_link:revisions_link ~top_info_bar @@ -519,14 +507,14 @@ let view_page ~cur_user ?(revision_id=None) page_id page_name ~printable = if printable <> None && Option.get printable = true then let%lwt page_content = wikiml_to_html ~cur_user page_id page_name ~revision_id todos in - return & Html_util.html_stub ~title:page_name page_content + return @@ Html_util.html_stub ~title:page_name page_content else let%lwt page_content = (wiki_page_contents_html ~cur_user page_id page_name ~revision_id todos ()) in - return & Html_util.html_stub ~title:page_name page_content + return @@ Html_util.html_stub ~title:page_name page_content (* Parse existing todo's from the current to-be-saved wiki page and update the DB relation on what todos are on the page. @@ -601,16 +589,16 @@ let check_new_and_removed_todos ~cur_user page_id lines = | None -> return ())) | None -> return ()) page_todos;%lwt - filter_map + Lwt_list.filter_map_s (fun e -> let id = int_of_string (fst e) in let%lwt b = Db.todo_exists id in - if b then return & Some id else return & None) page_todos >>= + if b then return @@ Some id else return @@ None) page_todos >>= (* Update DB "todos in pages" relation *) Db.update_page_todos page_id let global_substitute ?groups pat subst s = - Pcre.substitute_substrings ~rex:pat ~subst:(fun r -> subst r) s + Pcre.substitute_substrings ~rex:pat ~subst s let new_todo_re = Pcre.regexp ("\\[todo ("^WikiML.accepted_chars^")\\]") @@ -684,7 +672,7 @@ let _ = let%lwt page_id = Db.page_id_of_page_name page_name in let%lwt current_page_todos = Db.query_page_todos page_id in let%lwt x = load_wiki_page page_id ~revision_id:None in - return & + return @@ (page_id, current_page_todos, annotate_old_todo_items page_name current_page_todos x) @@ -709,7 +697,7 @@ let _ = wiki_page_contents_html ~cur_user ~revision_id:None page_id page_name page_todos ~content:[f] () in - return & Html_util.html_stub ~title:("Edit " ^ page_name) h + return @@ Html_util.html_stub ~title:("Edit " ^ page_name) h in Eliom_registration.Html.register ~service:wiki_edit_page @@ -727,7 +715,7 @@ let view_wiki_page ~cur_user (page_name, (printable, (revision_id, _))) = let f = a ~service:wiki_edit_page [txt "Create new page"] page_name in let%lwt h = wiki_page_menu_html ~cur_user page_name [f] in - return & Html_util.html_stub ~title:page_name h + return @@ Html_util.html_stub ~title:page_name h (* /view?p=Page *) let _ = diff --git a/src/scheduler.ml b/src/scheduler.ml index 2667d67..4961ad9 100644 --- a/src/scheduler.ml +++ b/src/scheduler.ml @@ -29,8 +29,6 @@ open Types open Util open CalendarLib -let ( & ) f x = f x - module Db = Database let clamp_date_to_today date = @@ -141,7 +139,7 @@ let view_scheduler_page ~cur_user = let table' = Form.post_form ~service:edit_todo_page table (ET_scheduler, None) in - return & + return @@ Html_util.html_stub ~title:"Scheduler" ~javascript:[["nurpawiki_scheduler.js"]] (Html_util.navbar_html ~cur_user ([h1 [txt "Road ahead"]] @ [table'])) in @@ -256,7 +254,7 @@ let rec render_todo_editor ~cur_user (src_page_cont, todos_to_edit) = [tr [td [Form.input ~input_type:`Submit ~value:"Save" Form.string; cancel_page src_page_cont]]])] in - return & + return @@ Form.post_form ~service:service_save_todo_item create_listform src_page_cont in let heading = [txt ("Edit TODOs "^todos_str)] in @@ -270,7 +268,7 @@ let rec render_todo_editor ~cur_user (src_page_cont, todos_to_edit) = ["nurpawiki_calendar.js"]] in - return & + return @@ Html_util.html_stub ~title:"Edit TODO(s)" ~javascript:calendar_js (Html_util.navbar_html ~cur_user ((h1 heading)::[help_str; br(); f])) From 1a049cfaba3f462102edca6eaf2f84b84bda7a3b Mon Sep 17 00:00:00 2001 From: Fardale Date: Sat, 22 Jul 2023 22:52:05 +0200 Subject: [PATCH 3/6] Add the meta tag viewport This is used for building responsive design html page. --- src/html_util.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/html_util.ml b/src/html_util.ml index ffbb07b..4ce0ed1 100644 --- a/src/html_util.ml +++ b/src/html_util.ml @@ -41,7 +41,8 @@ let html_stub ?(javascript=[]) ~title body_html = html ~a:[a_xmlns `W3_org_1999_xhtml] (head (Eliom_content.Html.F.title (txt (title ^ " — Nurpawiki"))) - (css_link ~a:[] ~uri:(make_uri ~service:(static_dir ()) + (meta ~a:[ a_name "viewport"; a_content "width=device-width, initial-scale=1" ] () :: + css_link ~a:[] ~uri:(make_uri ~service:(static_dir ()) ["style.css"]) ():: css_link ~a:[] ~uri:(make_uri ~service:(static_dir ()) ["jscalendar"; "calendar-blue2.css"]) ():: From b19cc9dcebdee228dd5524567b33dcf7432f6ffc Mon Sep 17 00:00:00 2001 From: Fardale Date: Tue, 1 Nov 2022 17:09:29 +0100 Subject: [PATCH 4/6] Feat: basic responsiveness for todo and content --- files/style.css | 37 ++++++++++++++++++++++++------------- src/html_util.ml | 9 +++++---- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/files/style.css b/files/style.css index 2167f94..9accbc6 100644 --- a/files/style.css +++ b/files/style.css @@ -1,7 +1,22 @@ -body { - font-family: Verdana,Geneva,Arial,Sans-serif; - font-size: 12px; - background-color : #FFFFFF + * { + box-sizing: border-box; +} + +.grid-container { + display: grid; + grid-template-columns: auto; + gap: 10px; + padding: 10px; +} + +@media only screen and (min-width: 768px) { + .grid-container { grid-template-columns: 300px auto;} +} + +body { + font-family: Verdana,Geneva,Arial,Sans-serif; + font-size: 12px; + background-color : #FFFFFF } img { @@ -101,7 +116,7 @@ h1 { } h1.left_aligned { - text-align: left; + text-align: left; } h4 { @@ -139,7 +154,7 @@ html, body { #login_align_middle { position:absolute; - top: 35%; + top: 35%; left: 30%; text-align:left; padding: 5px; @@ -174,7 +189,7 @@ table.login_box { color:#000; } -.undo_link { +.undo_link { color:#338; } @@ -202,17 +217,13 @@ table.login_box { } #navbar { - width: 300px; - float: left; - margin-left: 0px; margin-top: 2px; padding: 12px; + background-color: #f1f1f1; } - - + #content { padding: 5px; - margin-left: 400px; } a#login_help_url { diff --git a/src/html_util.ml b/src/html_util.ml index 4ce0ed1..a621e7b 100644 --- a/src/html_util.ml +++ b/src/html_util.ml @@ -71,7 +71,7 @@ let navbar_html ~cur_user ?(top_info_bar=[]) ?(wiki_revisions_link=[]) ?(wiki_pa let search_input = [get_form ~service:search_page (fun (chain : ([`One of string] param_name)) -> - [p [input ~input_type:`Submit ~value:"Search" Form.string; + [p [input ~a:[a_class ["button"]] ~input_type:`Submit ~value:"Search" Form.string; input ~input_type:`Text ~name:chain Form.string]])] in (* Greet user and offer Login link if guest *) @@ -128,10 +128,11 @@ let navbar_html ~cur_user ?(top_info_bar=[]) ?(wiki_revisions_link=[]) ?(wiki_pa @ (if top_info_bar = [] then [] else [div ~a:[a_id "top_action_bar"] top_info_bar]) @ - [div ~a:[a_id "navbar"] + [div ~a:[a_id "page"; a_class ["grid-container"]] + [div ~a:[a_id "navbar";] (user_greeting @ [br ()] @ search_input @ wiki_revisions_link @ todo_list_table); - div ~a:[a_id "content"] - content] + div ~a:[a_id "content"] + content]] let error text = span ~a:[a_class ["error"]] [txt text] From e17365e0e5a27a42978e7abd924a12d5554b6734 Mon Sep 17 00:00:00 2001 From: Fardale Date: Wed, 2 Nov 2022 18:40:24 +0100 Subject: [PATCH 5/6] Limit the background color of todos --- src/html_util.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/html_util.ml b/src/html_util.ml index a621e7b..1c5bc13 100644 --- a/src/html_util.ml +++ b/src/html_util.ml @@ -129,8 +129,8 @@ let navbar_html ~cur_user ?(top_info_bar=[]) ?(wiki_revisions_link=[]) ?(wiki_pa (if top_info_bar = [] then [] else [div ~a:[a_id "top_action_bar"] top_info_bar]) @ [div ~a:[a_id "page"; a_class ["grid-container"]] - [div ~a:[a_id "navbar";] - (user_greeting @ [br ()] @ search_input @ wiki_revisions_link @ todo_list_table); + [div [div ~a:[a_id "navbar";] + (user_greeting @ [br ()] @ search_input @ wiki_revisions_link @ todo_list_table)]; div ~a:[a_id "content"] content]] From dd18b31da4592971a38c2509f25185c1e321a960 Mon Sep 17 00:00:00 2001 From: Fardale Date: Mon, 14 Nov 2022 14:51:10 +0100 Subject: [PATCH 6/6] Feat: responsiveness of the top bar --- files/style.css | 63 ++++++++++++++++++++++++++++++++++++++++++------ src/html_util.ml | 54 +++++++++++++++++------------------------ src/main.ml | 9 ++++--- 3 files changed, 83 insertions(+), 43 deletions(-) diff --git a/files/style.css b/files/style.css index 9accbc6..e3f3890 100644 --- a/files/style.css +++ b/files/style.css @@ -13,16 +13,71 @@ .grid-container { grid-template-columns: 300px auto;} } +ul.topbar { + list-style-type: none; + margin: 0; + padding: 0; + overflow: hidden; + border: 1px solid #e7e7e7; + background-color: #f3f3f3; +} + +ul.topbar li { + height: 100%; + display: block; + float: left; + height: 50px; +} + +ul.topbar li a { + display: block; + color: #666; + text-align: center; + padding: 14px 16px; + text-decoration: none; + text-align: center; + height: 50px; +} + +ul.topbar li a:hover:not(.active) {background-color: #ddd;} + +ul.topbar li a.active {background-color: #04AA6D;} + +ul.topbar li.right {float: right;} + +@media screen and (max-width: 768px) { + ul.topbar li.right, + ul.topbar li { + float: none; + border: 1px solid #e7e7e7; + } +} + +.center-horizontal { + display: grid; + grid-template-columns: auto auto; + align-items: center; + justify-content: center; + height: 55%; + padding: 0; + margin: 0; +} + body { font-family: Verdana,Geneva,Arial,Sans-serif; font-size: 12px; - background-color : #FFFFFF + background-color : #FFFFFF; + margin: 0; } img { border: 0px none; } +.topbar img { + padding-right: 5px; +} + a:visited { color : #000080; ; text-decoration : underline; } a:link { color : #2222FF; ; text-decoration : underline; } a:hover { text-decoration : none; } @@ -40,12 +95,6 @@ a.missing_page:visited { color : Red; text-decoration : underline; } a.missing_page:link { color : Red; text-decoration : underline; } a.missing_page:hover { color : Red; text-decoration : none; } -/* Accesskey'd links -- first letter underlined */ -a.ak { text-decoration: underline; } -a.ak:hover { color:#2222FF; text-decoration: none;} -a.ak:focus { color:#2222FF; text-decoration: none;} -a.ak:first-letter { color:#2222FF; text-decoration: none; font-weight:bold; } - a.palette0 { color:rgb(128, 6, 25); } a.palette1 { color:rgb(0, 104, 28); } a.palette2 { color:rgb(0, 148, 145); } diff --git a/src/html_util.ml b/src/html_util.ml index 1c5bc13..77bfcd6 100644 --- a/src/html_util.ml +++ b/src/html_util.ml @@ -55,18 +55,18 @@ let is_guest user = let navbar_html ~cur_user ?(top_info_bar=[]) ?(wiki_revisions_link=[]) ?(wiki_page_links=[]) ?(todo_list_table=[]) content = let home_link link_text = a ~service:wiki_view_page - ~a:[a_accesskey 'h'; a_class ["ak"]] link_text + ~a:[a_accesskey 'h'] link_text (Config.site.cfg_homepage, (None, (None, None))) in let scheduler_link = a ~service:scheduler_page - ~a:[a_accesskey 'r'; a_class ["ak"]] - [img ~alt:"Scheduler" ~src:(make_static_uri ["calendar.png"]) (); - txt "Scheduler"] () in + ~a:[a_accesskey 'r'] + [div ~a:[a_class ["center-horizontal"]] [img ~alt:"Scheduler" ~src:(make_static_uri ["calendar.png"]) (); + txt "Scheduler"]] () in let history_link = a ~service:history_page - ~a:[a_accesskey 'r'; a_class ["ak"]] - [img ~alt:"History" ~src:(make_static_uri ["home.png"]) (); - txt "History"] None in + ~a:[a_accesskey 'r'] + [div ~a:[a_class ["center-horizontal"]] [img ~alt:"History" ~src:(make_static_uri ["home.png"]) (); + txt "History"]] None in let search_input = [get_form ~service:search_page @@ -90,42 +90,32 @@ let navbar_html ~cur_user ?(top_info_bar=[]) ?(wiki_revisions_link=[]) ?(wiki_pa [] in let disconnect_link = - if is_guest cur_user then [] else [disconnect_box "Logout"] in + if is_guest cur_user then [] else [li ~a:[a_class ["right"]] [disconnect_box "Logout"]] in let my_preferences_link = if is_guest cur_user then [] else - [a ~service:edit_user_page [txt "My Preferences"] - (None,cur_user.user_login)] in + [li ~a:[a_class ["right"]] [a ~service:edit_user_page [txt "My Preferences"] + (None,cur_user.user_login)]] in let edit_users_link = if Privileges.can_view_users cur_user then - [a ~service:user_admin_page [txt "Edit Users"] ()] + [li ~a:[a_class ["right"]] [a ~service:user_admin_page [txt "Edit Users"] ()]] else [] in - [div ~a:[a_id "topbar"] - [table ~a:[a_class ["top_menu_size"]] - [tr - [td ~a:[a_class ["top_menu_left_align"]] - [table - [tr [td [home_link - [img ~alt:"Home" ~src:(make_static_uri ["home.png"]) (); - txt "Home"]]; - td [scheduler_link]; - td [history_link]; - td wiki_page_links]] - ]; - td ~a:[a_class ["top_menu_right_align"]] - ([a ~service:about_page [txt "About"] ()] @ - [txt " "] @ - my_preferences_link @ - [txt " "] @ - edit_users_link @ - [txt " "] @ - disconnect_link)]]]] - @ + ul ~a:[a_class ["top_menu_size"; "topbar"]] + ([li [home_link [div ~a:[a_class ["center-horizontal"]] [img ~alt:"Home" + ~src:(make_static_uri ["home.png"]) (); txt "Home"]]]; + li [scheduler_link]; + li [history_link]] @ + List.map (fun l -> li [l]) wiki_page_links @ + [li ~a:[a_class ["right"]] [a ~service:about_page [txt "About"] ()]] @ + my_preferences_link @ + edit_users_link @ + disconnect_link) + :: (if top_info_bar = [] then [] else [div ~a:[a_id "top_action_bar"] top_info_bar]) @ [div ~a:[a_id "page"; a_class ["grid-container"]] diff --git a/src/main.ml b/src/main.ml index d5e0180..f8a1480 100644 --- a/src/main.ml +++ b/src/main.ml @@ -463,12 +463,13 @@ let wiki_page_menu_html ~cur_user page content = let edit_link = [a ~service:wiki_edit_page ~a:[a_accesskey '1'; a_class ["ak"]] - [img ~alt:"Edit" ~src:(make_static_uri ["edit.png"]) (); - txt "Edit page"] page] in + [div ~a:[a_class ["center-horizontal"]] [img ~alt:"Edit" ~src:(make_static_uri ["edit.png"]) (); + txt "Edit page"]] page] in let printable_link = [a ~service:wiki_view_page - ~a:[a_accesskey 'p'; a_class ["ak"]] [txt "Print"] + ~a:[a_accesskey 'p'; a_class ["ak"]] + [div ~a:[a_class ["center-horizontal"]] [txt "Print"]] (page, (Some true,(None,None)))] in let revisions_link = @@ -493,7 +494,7 @@ let wiki_page_menu_html ~cur_user page content = [txt "Undo"] id]] in return @@ Html_util.navbar_html ~cur_user - ~wiki_page_links:(edit_link @ [txt " "] @ printable_link) + ~wiki_page_links:(edit_link @ printable_link) ~wiki_revisions_link:revisions_link ~top_info_bar ~todo_list_table:[todo_list] content