summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex AUVOLAT <alexis211@gmail.com>2013-08-10 17:15:22 +0200
committerAlex AUVOLAT <alexis211@gmail.com>2013-08-10 17:15:22 +0200
commit5435a0a45fdfa1bcceeb36f8531826ddc2bb3508 (patch)
tree6254e6f19ca78e394693ef22ea5393dcefc5468d
parent2a748125c27c7f7c41a32a1dba14484c66dc351f (diff)
downloadBits-5435a0a45fdfa1bcceeb36f8531826ddc2bb3508.tar.gz
Bits-5435a0a45fdfa1bcceeb36f8531826ddc2bb3508.zip
Added possibility to add notes to studied batch items.
-rw-r--r--design/style.css39
-rw-r--r--js/liststudy.js33
-rw-r--r--js/reviewdesu.js24
-rw-r--r--lib/study/batch.php7
-rw-r--r--lib/study/batchreview.php6
-rw-r--r--lib/study/brresults.php7
-rw-r--r--schema.sql31
-rw-r--r--tpl/study/batch.php5
-rw-r--r--tpl/study/batch_review.php4
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 = '<table><tr><th style="border: none; background: transparent"></th>';
+ var html = '<table><tr><th class="invisible_td"></th>';
for (var i = 0; i < batch_data.columns.length; i++) {
var c = batch_data.columns[i];
html += '<th>' + c + ' - <a class="tool_link" href="#" onclick="ch(' + i + ')" id="chsl' + i + '">hide</a></th>';
}
html += '<th>win</th><th>fail</th><th>score</th></tr>';
for (var i = 0; i < items.length; i++) {
- html += '<tr>';
- html += '<td style="border: none; background: transparent; padding: 0px; padding-top: 8px; font-weight: bold;">' + items[i].marker + '</td>';
+ html += '<tr onclick="edit_note(' + i + ');">';
+ html += '<td class="invisible_td"><span style="font-weight: bold">' + items[i].marker + '</span>' +
+ '</td>';
for (var j = 0; j < items[i].info.length; j++) {
html += '<td><span class="cd' + j + '">' + items[i].info[j] + '</span></td>';
}
@@ -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 + '</td></tr>';
+ if (notes[items[i].info[0]]) {
+ var note = notes[items[i].info[0]];
+ html += '<tr><td class="invisible_td"></td><td class="study_note_td" colspan="'
+ + (items[i].info.length) + '">' + note + '</td></tr>';
+ }
}
html += '</table>';
html += '<p>Average score : ' + avg_score + '</p>';
@@ -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 = '<h3>Question ' + question_nb + ' of ' + total + '</h3>';
html += '<div class="review_item">';
- html += '<div>' + question.question + '</div>';
+ html += '<div class="box">' + question.question + '</div>';
html += '<p><button id="flipbtn" onclick="show_answer();">answer</button></p>';
html += '</div>';
$("core").innerHTML = html;
@@ -95,7 +95,8 @@ function next_question() {
function show_answer() {
html = '<h3>Question ' + question_nb + ' of ' + total + '</h3>';
html += '<div class="review_item">';
- html += '<div>' + question.answer + '</div>';
+ html += '<div class="box2">' + question.answer + '</div>';
+ html += '<div class="boxn" onclick="edit_note();" id="notebox">' + (notes[question.key] || '<em>click to add note...</em>') + '</div>';
html += '<p><button taborder="1" onclick="answer_question(-1);">fail</button>';
html += '<button taborder="2" id="dunnobtn" onclick="answer_question(0);">dunno</button>';
html += '<button taborder="3" id="winbtn" onclick="answer_question(1);">win</button></p>';
@@ -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] || '<em>click to add note...</em>');
+
+ 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();';