From 5435a0a45fdfa1bcceeb36f8531826ddc2bb3508 Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Sat, 10 Aug 2013 17:15:22 +0200 Subject: Added possibility to add notes to studied batch items. --- design/style.css | 39 +++++++++++++++++++++++++++++++++++++-- js/liststudy.js | 33 ++++++++++++++++++++++++++++++--- js/reviewdesu.js | 24 ++++++++++++++++++++++-- lib/study/batch.php | 7 +++++-- lib/study/batchreview.php | 6 ++++-- lib/study/brresults.php | 7 ++++++- schema.sql | 31 ++++++++++++++++--------------- tpl/study/batch.php | 5 ++++- tpl/study/batch_review.php | 4 +++- 9 files changed, 127 insertions(+), 29 deletions(-) diff --git a/design/style.css b/design/style.css index 4959921..56aec67 100644 --- a/design/style.css +++ b/design/style.css @@ -223,6 +223,13 @@ th { text-align: center; } +.invisible_td { + border: none; + background: transparent; + padding: 0px; + padding-top: 8px; +} + code { font-size: 1.2em; } @@ -280,17 +287,45 @@ hr { /* Study lists */ +.study_note_td { + font-size: 0.8em; + background: white; + text-align: right; + padding: 2px; + padding-right: 16px; + padding-left: 16px; + padding-bottom: 4px; +} + .review_item{ text-align: center; } -.review_item div { +.review_item .box, .review_item .box2, .review_item .boxn { width: 400px; margin: auto; - height: 300px; border: 1px solid #eeeeee; background: #ffffff; } +.review_item .box { + height: 300px; +} + +.review_item .box2 { + height: 220px; +} + +.review_item .boxn { + border-top: 0px; + height: 74px; + font-size: 0.8em; + padding-top: 6px; +} + +.review_item .boxn em { + color: grey; +} + .review_item_prop span { display: inline-block; padding-right: 8px; diff --git a/js/liststudy.js b/js/liststudy.js index 820e35d..5ff6aef 100644 --- a/js/liststudy.js +++ b/js/liststudy.js @@ -66,15 +66,16 @@ function process_items() { } function show_contents_table() { - var html = ''; + var html = '
'; for (var i = 0; i < batch_data.columns.length; i++) { var c = batch_data.columns[i]; html += ''; } html += ''; for (var i = 0; i < items.length; i++) { - html += ''; - html += ''; + html += ''; + html += ''; for (var j = 0; j < items[i].info.length; j++) { html += ''; } @@ -84,6 +85,11 @@ function show_contents_table() { (items[i].score == max_score ? '#00aa00' : (items[i].score >= med_score ? '#55FF55' : (items[i].score < 0 ? '#FF7777' : '#FFFF00'))) + '">' + items[i].score + ''; + if (notes[items[i].info[0]]) { + var note = notes[items[i].info[0]]; + html += ''; + } } html += '
' + c + ' - hidewinfailscore
' + items[i].marker + '
' + items[i].marker + '' + + '' + items[i].info[j] + '
' + note + '
'; html += '

Average score : ' + avg_score + '

'; @@ -125,3 +131,24 @@ function show_reviews_table() { $("reviews").innerHTML = html; } } + + +function edit_note(id) { + var idd = items[id].info[0]; + var note = prompt("Add note for item: ", notes[idd] || ''); + if (note != null) notes[idd] = note; + if (notes[idd] == '') delete notes[idd]; + show_contents_table(); + + new Ajax.Request('index.php?p=brresults-study-' + batchid, { + method: 'post', + parameters: { + notes: Object.toJSON(notes), + }, + onSuccess: function(transport) { + // nothing... + }, + }); +} + + diff --git a/js/reviewdesu.js b/js/reviewdesu.js index 829f07a..6750b4b 100644 --- a/js/reviewdesu.js +++ b/js/reviewdesu.js @@ -84,7 +84,7 @@ function next_question() { html = '

Question ' + question_nb + ' of ' + total + '

'; html += '
'; - html += '
' + question.question + '
'; + html += '
' + question.question + '
'; html += '

'; html += '
'; $("core").innerHTML = html; @@ -95,7 +95,8 @@ function next_question() { function show_answer() { html = '

Question ' + question_nb + ' of ' + total + '

'; html += '
'; - html += '
' + question.answer + '
'; + html += '
' + question.answer + '
'; + html += '
' + (notes[question.key] || 'click to add note...') + '
'; html += '

'; html += ''; html += '

'; @@ -109,3 +110,22 @@ function answer_question(a) { score += a; next_question(); } + +function edit_note() { + var idd = question.key; + var note = prompt("Add note for item:", notes[idd] || ''); + if (note != null) notes[idd] = note; + if (notes[idd] == '') delete notes[idd]; + $("notebox").innerHTML = (notes[idd] || 'click to add note...'); + + new Ajax.Request('index.php?p=brresults-study-' + batchid, { + method: 'post', + parameters: { + notes: Object.toJSON(notes), + }, + onSuccess: function(transport) { + // nothing... + }, + }); +} + diff --git a/lib/study/batch.php b/lib/study/batch.php index d8df526..60152f1 100644 --- a/lib/study/batch.php +++ b/lib/study/batch.php @@ -6,7 +6,8 @@ $batchid = intval($args[2]); $info = mysql_fetch_assoc(sql( "SELECT list_study.id AS studyid, batches.name AS bname, ". "lists.name AS lname, account.login AS uname, ". - "batch_study.id AS bsid, batches.id AS batchid, batches.json_data AS json_data ". + "batch_study.id AS bsid, batch_study.notes_json AS notes, ". + "batches.id AS batchid, batches.json_data AS json_data ". "FROM batches LEFT JOIN list_study ON list_study.list = batches.list AND list_study.user = " . $user['id'] . " " . "LEFT JOIN batch_study ON batch_study.batch = $batchid AND batch_study.user = " . $user['id'] . " " . "LEFT JOIN lists ON batches.list = lists.id ". @@ -16,8 +17,10 @@ assert_error($info, "This batch does not exist."); assert_error($info['studyid'] != 0, "You are not studying this list."); if ($info["bsid"] == 0) { - sql("INSERT INTO batch_study(user, batch, last_review) VALUES(" . $user['id'] . ", $batchid, 0)"); + sql("INSERT INTO batch_study(user, batch, last_review, notes_json) ". + "VALUES(" . $user['id'] . ", $batchid, 0, '{}')"); $info['bsid'] = mysql_insert_id(); + $info['notes'] = '{}'; } $reviews = array(); diff --git a/lib/study/batchreview.php b/lib/study/batchreview.php index 8639193..58fc852 100644 --- a/lib/study/batchreview.php +++ b/lib/study/batchreview.php @@ -6,7 +6,8 @@ $batchid = intval($args[2]); $info = mysql_fetch_assoc(sql( "SELECT list_study.id AS studyid, batches.name AS bname, ". "lists.name AS lname, account.login AS uname, ". - "batch_study.id AS bsid, batches.id AS batchid, batches.json_data AS json_data ". + "batch_study.id AS bsid, batch_study.notes_json AS notes, ". + "batches.id AS batchid, batches.json_data AS json_data ". "FROM batches LEFT JOIN list_study ON list_study.list = batches.list AND list_study.user = " . $user['id'] . " " . "LEFT JOIN batch_study ON batch_study.batch = $batchid AND batch_study.user = " . $user['id'] . " " . "LEFT JOIN lists ON batches.list = lists.id ". @@ -16,8 +17,9 @@ assert_error($info, "This batch does not exist."); assert_error($info['studyid'] != 0, "You are not studying this list."); if ($info["bsid"] == 0) { - sql("INSERT INTO batch_study(user, batch, last_review) VALUES(" . $user['id'] . ", $batchid, 0)"); + sql("INSERT INTO batch_study(user, batch, last_review, notes_json) VALUES(" . $user['id'] . ", $batchid, 0, '{}')"); $info['bsid'] = mysql_insert_id(); + $info['notes'] = '{}'; } require("tpl/study/batch_review.php"); diff --git a/lib/study/brresults.php b/lib/study/brresults.php index b3e1068..9bbafac 100644 --- a/lib/study/brresults.php +++ b/lib/study/brresults.php @@ -19,8 +19,10 @@ if (!($info['studyid'] != 0)) { } if ($info["bsid"] == 0) { - sql("INSERT INTO batch_study(user, batch, last_review) VALUES(" . $user['id'] . ", $batchid, 0)"); + sql("INSERT INTO batch_study(user, batch, last_review, notes_json) ". + "VALUES(" . $user['id'] . ", $batchid, 0, '{}')"); $info['bsid'] = mysql_insert_id(); + $info['notes'] = '{}'; } if (isset($_POST['results']) && isset($_POST['score'])) { @@ -28,6 +30,9 @@ if (isset($_POST['results']) && isset($_POST['score'])) { "VALUES(" . $user['id'] . ", $batchid, '" . escs(esca($_POST['results'])) . "', " . intval($_POST['score']) . ", NOW())"); sql("UPDATE batch_study SET last_review = " . mysql_insert_id() . " WHERE id = " . $info['bsid']); echo 'Saved'; +} else if (isset($_POST['notes'])) { + sql("UPDATE batch_study SET notes_json = '" . escs(esca($_POST['notes'])) . "' WHERE id = " . $info['bsid']); + echo 'Saved'; } else { echo 'Error'; } diff --git a/schema.sql b/schema.sql index 86bbfe6..022f193 100644 --- a/schema.sql +++ b/schema.sql @@ -1,13 +1,13 @@ -- phpMyAdmin SQL Dump --- version 3.5.1 +-- version 4.0.5 -- http://www.phpmyadmin.net -- -- Client: localhost --- Généré le: Jeu 21 Juin 2012 à 14:33 --- Version du serveur: 5.5.25-log --- Version de PHP: 5.4.4 +-- Généré le: Sam 10 Août 2013 à 14:13 +-- Version du serveur: 5.5.32-MariaDB-log +-- Version de PHP: 5.4.17 -SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; @@ -17,7 +17,7 @@ SET time_zone = "+00:00"; /*!40101 SET NAMES utf8 */; -- --- Base de données: `alex_auvolat` +-- Base de données: `alex.auvolat` -- -- -------------------------------------------------------- @@ -35,7 +35,7 @@ CREATE TABLE IF NOT EXISTS `account` ( `reg_date` date NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `login` (`login`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -84,6 +84,7 @@ CREATE TABLE IF NOT EXISTS `batch_study` ( `user` int(11) NOT NULL, `batch` int(11) NOT NULL, `last_review` int(11) NOT NULL, + `notes_json` text NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `batch` (`batch`), KEY `user_idx` (`user`) @@ -105,7 +106,7 @@ CREATE TABLE IF NOT EXISTS `blog_comments` ( PRIMARY KEY (`id`), KEY `post` (`post`), KEY `owner` (`owner`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -155,7 +156,7 @@ CREATE TABLE IF NOT EXISTS `cards` ( UNIQUE KEY `unique_name` (`deck`,`name`), UNIQUE KEY `unique_number` (`deck`,`number`), KEY `deck_idx` (`deck`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -171,7 +172,7 @@ CREATE TABLE IF NOT EXISTS `card_study` ( `next_review` date NOT NULL, PRIMARY KEY (`id`), KEY `deck_study` (`deck_study`,`card`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -188,7 +189,7 @@ CREATE TABLE IF NOT EXISTS `decks` ( PRIMARY KEY (`id`), UNIQUE KEY `unique_name` (`owner`,`name`), KEY `owner_idx` (`owner`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -207,7 +208,7 @@ CREATE TABLE IF NOT EXISTS `deck_study` ( UNIQUE KEY `unique_user_deck` (`user`,`deck`), KEY `user_idx` (`user`), KEY `deck_idx` (`deck`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -227,7 +228,7 @@ CREATE TABLE IF NOT EXISTS `files` ( PRIMARY KEY (`id`), KEY `owner` (`owner`), KEY `folder` (`folder`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -244,7 +245,7 @@ CREATE TABLE IF NOT EXISTS `folders` ( `public` tinyint(1) NOT NULL, PRIMARY KEY (`id`), KEY `owner` (`owner`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- @@ -295,7 +296,7 @@ CREATE TABLE IF NOT EXISTS `notes` ( `public` tinyint(1) NOT NULL, PRIMARY KEY (`id`), KEY `owner` (`owner`,`parent`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; diff --git a/tpl/study/batch.php b/tpl/study/batch.php index 666fdc8..842deaa 100644 --- a/tpl/study/batch.php +++ b/tpl/study/batch.php @@ -2,7 +2,10 @@ $title = $info['uname'] . ':' . $info['lname'] . ' - ' . $info['bname']; -$javascript = "\n\nconst batch_data = " . $info['json_data'] . ";\n\nconst reviews_data = $reviews;\n\n"; +$javascript = "\nconst batchid = " . $info['batchid'] . "\n\n". + "const batch_data = " . $info['json_data'] . ";\n\n". + "const reviews_data = $reviews;\n\n". + "var notes = " . $info['notes'] . ";\n\n"; $js_include = array("js/prototype.js", "js/liststudy.js"); $onload_js = 'show_batch_table();'; diff --git a/tpl/study/batch_review.php b/tpl/study/batch_review.php index ed81b75..abe1944 100644 --- a/tpl/study/batch_review.php +++ b/tpl/study/batch_review.php @@ -2,7 +2,9 @@ $title = "Testing " . $info['uname'] . ':' . $info['lname'] . ' - ' . $info['bname']; -$javascript = "\n\nconst batchid = " . $info['batchid'] . "\nconst batch_data = " . $info['json_data'] . ";\n\n"; +$javascript = "\n\nconst batchid = " . $info['batchid'] . "\n". + "const batch_data = " . $info['json_data'] . ";\n\n". + "var notes = " . $info['notes'] . ";\n\n"; $js_include = array("js/prototype.js", "js/reviewdesu.js"); $onload_js = 'start_review();'; -- cgit v1.2.3