[Toss-devel-svn] SF.net SVN: toss:[1568] trunk/Toss
Status: Beta
Brought to you by:
lukaszkaiser
From: <luk...@us...> - 2011-09-14 23:17:32
|
Revision: 1568 http://toss.svn.sourceforge.net/toss/?rev=1568&view=rev Author: lukaszkaiser Date: 2011-09-14 23:17:26 +0000 (Wed, 14 Sep 2011) Log Message: ----------- Simple game editing in WebClient. Modified Paths: -------------- trunk/Toss/Server/ReqHandler.ml trunk/Toss/Server/ReqHandler.mli trunk/Toss/Server/Server.ml trunk/Toss/WebClient/Connect.js trunk/Toss/WebClient/Main.js trunk/Toss/WebClient/Style.css trunk/Toss/WebClient/index.html Modified: trunk/Toss/Server/ReqHandler.ml =================================================================== --- trunk/Toss/Server/ReqHandler.ml 2011-09-14 01:00:51 UTC (rev 1567) +++ trunk/Toss/Server/ReqHandler.ml 2011-09-14 23:17:26 UTC (rev 1568) @@ -7,8 +7,8 @@ "/usr/share/toss/html" else "WebClient/") let quit_on_eof = ref true - let do_mails = ref false +let save_games = ref true (* ---------- Basic request type and internal handler ---------- *) @@ -645,6 +645,24 @@ print_endline ("Subject: " ^ subj); print_endline mailtxt; "Invitation email has been sent to " ^ email ^ "." in + let save_game game toss = + let gs_of_str s = + ArenaParser.parse_game_state Lexer.lex (Lexing.from_string s) in + if !save_games then + try + let _ = gs_of_str toss in + let res = dbtable ("game='" ^ game ^ "'") "games" in + if List.length res = 0 then + DB.insert_table dbFILE "games" "game, toss" [game; toss] + else + ignore (DB.update_table dbFILE ~select:("game='" ^ game ^ "'") + ("toss='" ^ toss ^ "'") "games"); + Hashtbl.remove client_game_states game; + "Game saved" + with + | Lexer.Parsing_error msg -> "Parsing error: " ^ msg + | _ -> "Parsing error" + else "Sorry, saving games is not allowed on this server." in let (tcmd, data) = split_two "#" msg in let resp, new_cookies = match tcmd with | "USERNAME" -> @@ -714,16 +732,29 @@ let tp2 = String.sub tp_s (tp_i+1) (tp_l - tp_i - 1) in let tp, a = (strip_ws tp0, strip_ws tp1, strip_ws tp2), get_args args_s in move_play tp a.(0), [] + | "GETGAME" -> + let res = dbtable ("game='" ^ data ^ "'") "games" in + (match List.length res with + | 0 -> "ERROR: no such game found in db", [] + | x when x > 1 -> "ERROR: multiple such games in db", [] + | _ -> (List.hd res).(1), [] + ) + | "SETGAME" -> + let (game, toss) = split_two " $_$ " data in save_game game toss, [] | _ -> "MOD_PYTHON ERROR ; Traceback: Unknown Toss Command! \n " ^ tcmd, [] in http_msg false "200 OK" "text/html; charset=utf-8" new_cookies resp +let http_post_ok_concurrent msg = (* Some things must be in main thread. *) + let (tcmd, data) = split_two "#" msg in tcmd <> "SETGAME" let handle_http_msg rstate cmd head msg ck = if String.sub cmd 0 5 = "GET /" then Aux.Right (rstate, fun () -> handle_http_get cmd head msg ck) else if String.length cmd > 13 && String.sub cmd 0 13 = "POST /Handler" then - Aux.Right (rstate, fun () -> handle_http_post cmd head msg ck) + if http_post_ok_concurrent msg then + Aux.Right (rstate, fun () -> handle_http_post cmd head msg ck) + else Aux.Left (rstate, handle_http_post cmd head msg ck) else try Aux.Left (req_handle rstate (Aux.Right (GDLParser.parse_request KIFLexer.lex (Lexing.from_string msg)))) Modified: trunk/Toss/Server/ReqHandler.mli =================================================================== --- trunk/Toss/Server/ReqHandler.mli 2011-09-14 01:00:51 UTC (rev 1567) +++ trunk/Toss/Server/ReqHandler.mli 2011-09-14 23:17:26 UTC (rev 1568) @@ -6,7 +6,7 @@ val set_debug_level : int -> unit val quit_on_eof : bool ref - +val save_games : bool ref val do_mails : bool ref Modified: trunk/Toss/Server/Server.ml =================================================================== --- trunk/Toss/Server/Server.ml 2011-09-14 01:00:51 UTC (rev 1567) +++ trunk/Toss/Server/Server.ml 2011-09-14 23:17:26 UTC (rev 1568) @@ -177,6 +177,8 @@ ("-mail", Arg.Unit (fun () -> ReqHandler.do_mails:= true), "do send mails"); ("-eof", Arg.Unit (fun () -> ReqHandler.quit_on_eof := false), "do not quit server on end of file of requests"); + ("-nosave", Arg.Unit (fun () -> ReqHandler.save_games := false), + "disallow to save games in database"); ("-html", Arg.String (fun s -> ReqHandler.html_dir_path := s), "set path to directory with html files for the web-based client"); ("-db", Arg.String (fun s -> (DB.dbFILE := s)), "use specified DB file"); Modified: trunk/Toss/WebClient/Connect.js =================================================================== --- trunk/Toss/WebClient/Connect.js 2011-09-14 01:00:51 UTC (rev 1567) +++ trunk/Toss/WebClient/Connect.js 2011-09-14 23:17:26 UTC (rev 1568) @@ -152,6 +152,10 @@ this.change_data = function (name, surname, email) { return (srv ("CHANGEUSR", name +"$"+ surname +"$"+ email)); } + this.get_game = function (game) { return (srv("GETGAME", game)); } + this.set_game = function (game, toss) { + return (srv("SETGAME", game + " $_$ " + toss)); + } return (this); } Modified: trunk/Toss/WebClient/Main.js =================================================================== --- trunk/Toss/WebClient/Main.js 2011-09-14 01:00:51 UTC (rev 1567) +++ trunk/Toss/WebClient/Main.js 2011-09-14 23:17:26 UTC (rev 1568) @@ -71,6 +71,7 @@ var paragraph = document.createElement("p"); this.paragraphs[game] = paragraph; paragraph.setAttribute("class", "game-par"); + this.container.appendChild (paragraph); var button = document.createElement("button"); paragraph.game_button = button; @@ -78,9 +79,8 @@ button.setAttribute("onclick", "new_play('" + game + "')"); button.innerHTML = game; button.style.display = "block"; - this.container.appendChild (paragraph); paragraph.appendChild (button); - + var open_play_list = document.createElement("ul"); paragraph.open_play_list = open_play_list; open_play_list.setAttribute("class", "plays-list"); @@ -108,7 +108,39 @@ closed_plays.style.display = "none"; paragraph.appendChild (closed_plays); + + var edit_div = document.createElement("div"); + paragraph.edit_div = edit_div; + edit_div.setAttribute("id", "edit-div-" + game); + edit_div.setAttribute("class", "edit-div"); + + var edit_button = document.createElement("button"); + paragraph.edit_button = edit_button; + edit_button.setAttribute("class", "completedbt"); + edit_button.setAttribute("onclick", + "GAMESPAGE.toggle_edit ('" + game + "')"); + edit_button.innerHTML = "Edit " + game + " (Show)"; + edit_div.appendChild (edit_button); + + var edit_save_button = document.createElement("button"); + paragraph.edit_save_button = edit_save_button; + edit_save_button.setAttribute("class", "completedbt"); + edit_save_button.setAttribute("onclick", + "GAMESPAGE.save_edit ('" + game + "')"); + edit_save_button.innerHTML = "Save"; + edit_save_button.style.display = "none"; + edit_div.appendChild (edit_save_button); + + var edit_area = document.createElement("textarea"); + edit_area.setAttribute("class", "edit-area"); + paragraph.edit_area = edit_area; + edit_div.appendChild (edit_area); + edit_area.style.display = "none"; + edit_area.value = CONN.get_game (game); + paragraph.appendChild (edit_div); + paragraph.completed_shown = false; + paragraph.edit_shown = false; this.container.appendChild (paragraph); } return (this); @@ -143,7 +175,25 @@ } } +GamesPage.prototype.toggle_edit = function (game) { + var par = this.paragraphs[game]; + if (par.edit_shown) { + par.edit_area.style.display = "none"; + par.edit_save_button.style.display = "none"; + par.edit_button.innerHTML = "Edit " + game + " (Show)"; + par.edit_shown = false; + } else { + par.edit_area.style.display = "block"; + par.edit_save_button.style.display = "inline"; + par.edit_button.innerHTML = "Edit " + game + " (Hide)"; + par.edit_shown = true; + } +} +GamesPage.prototype.save_edit = function (game) { + alert (CONN.set_game (game, this.paragraphs[game].edit_area.value)); +} + function play_from_string (game, s) { var p = s.substring(game.length + 1); var lst = parse_list ('#', p); Modified: trunk/Toss/WebClient/Style.css =================================================================== --- trunk/Toss/WebClient/Style.css 2011-09-14 01:00:51 UTC (rev 1567) +++ trunk/Toss/WebClient/Style.css 2011-09-14 23:17:26 UTC (rev 1568) @@ -93,7 +93,7 @@ .gamebt { margin-bottom: 1em; - + padding-top: 0.5em; } .completedbt { @@ -139,6 +139,17 @@ margin-top: 0.3em; } +.edit-div { + margin-bottom: -1em; + margin-top: -1px; + border-top: 1px solid #260314; +} + +.edit-area { + width: 100%; + height: 35em; +} + .game-picbt { position: relative; top:0px; @@ -796,7 +807,6 @@ .game-par { padding: 0px; - padding-bottom: 0.2em; /* border-bottom: 1px solid #260314; */ } @@ -825,6 +835,7 @@ } .plays-list { + width: 100%; list-style: none; margin: 0.5em; margin-bottom: 0px; @@ -835,7 +846,7 @@ } .plays-list-elem { - margin-left: 1em; + margin-left: 1.5em; margin-bottom: 0em; } Modified: trunk/Toss/WebClient/index.html =================================================================== --- trunk/Toss/WebClient/index.html 2011-09-14 01:00:51 UTC (rev 1567) +++ trunk/Toss/WebClient/index.html 2011-09-14 23:17:26 UTC (rev 1568) @@ -177,6 +177,7 @@ <div id="news"> <h3>News</h3> <ul id="welcome-list-news" class="welcome-list"> +<li><b>14/09/11</b> Simple editing of games added to web interface</li> <li><b>31/07/11</b> Store date and time of moves in games</li> <li><b>30/07/11</b> Corrected opponent lists in the Profile tab</li> <li><b>03/07/11</b> Added game descriptions viewable when playing</li> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |