diff options
-rw-r--r-- | main.ur | 64 | ||||
-rw-r--r-- | style.ur | 14 | ||||
-rw-r--r-- | style.urs | 14 | ||||
-rw-r--r-- | urwiki.css | 16 | ||||
-rw-r--r-- | urwiki.urp | 6 |
5 files changed, 99 insertions, 15 deletions
@@ -30,6 +30,20 @@ table article : { Title : string, CONSTRAINT Head FOREIGN KEY Head REFERENCES commit(Id) +datatype mode = View | Edit +val eq_mode = + mkEq (fn x y => + case (x, y) of + (View, View) => True + | (Edit, Edit) => True + | _ => False) + +fun only_in mode_source target_mode = + current_mode <- signal mode_source; + return (if current_mode = target_mode + then null + else Style.invisible) + fun commit_article title text : transaction unit = id <- nextval commit_id_next; creation_time <- now; @@ -49,6 +63,7 @@ fun commit_article title text : transaction unit = WHERE Title = {[title]}) fun wiki requested_article_title = + (* Look up the article. *) extant_articles <- queryL (SELECT article.Title, commit.Content FROM article LEFT JOIN commit ON article.Head = commit.Id @@ -65,7 +80,12 @@ fun wiki requested_article_title = ‘{[requested_article_title]}’ </xml> in + (* Stuff the article text in a source so we can live-update it as the user + edits. *) article_body_source <- source article.Body; + (* Initially, we're in View mode, and we can switch to Edit mode on user + request. *) + page_mode <- source View; return <xml> <head> @@ -74,24 +94,40 @@ fun wiki requested_article_title = then Configuration.wiki_title else article.Title ^ " – " ^ Configuration.wiki_title]} </title> + <link rel="stylesheet" href="/urwiki.css" /> </head> <body> - <h1>{[Configuration.wiki_title]}</h1> - <ul> - <li> - <a link={wiki Configuration.main_page_name}> - {[Configuration.main_page_name]} - </a> - </li> - </ul> + (* Page headings *) + <div> + <h1>{[Configuration.wiki_title]}</h1> + <ul> + <li> + <a link={wiki Configuration.main_page_name}> + {[Configuration.main_page_name]} + </a> + </li> + </ul> + </div> + (* Article *) <dyn signal={text <- signal article_body_source; return <xml>{[text]}</xml>} /><br /> - <ctextarea source={article_body_source} /><br /> - <button - value="Commit" - onclick={fn _ => - text <- get article_body_source; - rpc (commit_article article.Title text)} /> + (* Editing panel *) + <div> + (* Controls for View mode *) + <div dynClass={only_in page_mode View}> + <button value="Edit" onclick={fn _ => set page_mode Edit} /> + </div> + (* Controls for Edit mode *) + <div dynClass={only_in page_mode Edit}> + <ctextarea source={article_body_source} /><br /> + <button + value="Commit" + onclick={fn _ => + text <- get article_body_source; + rpc (commit_article article.Title text); + set page_mode View} /> + </div> + </div> </body> </xml> end diff --git a/style.ur b/style.ur new file mode 100644 index 0000000..a592666 --- /dev/null +++ b/style.ur @@ -0,0 +1,14 @@ +(* Copyright 2015 the Massachusetts Institute of Technology + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. *) + +style invisible diff --git a/style.urs b/style.urs new file mode 100644 index 0000000..a592666 --- /dev/null +++ b/style.urs @@ -0,0 +1,14 @@ +(* Copyright 2015 the Massachusetts Institute of Technology + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. *) + +style invisible diff --git a/urwiki.css b/urwiki.css new file mode 100644 index 0000000..78adbe1 --- /dev/null +++ b/urwiki.css @@ -0,0 +1,16 @@ +/* Copyright 2015 the Massachusetts Institute of Technology + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. */ + +.Style_invisible { + display: none; +} @@ -1 +1,5 @@ -main
\ No newline at end of file +allow url /urwiki.css +file /urwiki.css urwiki.css + +style +main |