www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit b63efaeb63138ec0376a65fbfa56224249a03c86
parent 8cd539e6d18b5a676505f8592122615c67ccd7fe
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Fri, 20 May 2011 10:07:25 +0200

Bouton "Retour au site" + j'aime( pas)? dans la BDD + auteur de la partie.

Diffstat:
Mcode/serveur/dump2sqlite.sh | 2+-
Mcode/serveur/php/jeu.php | 9++++++---
Mcode/serveur/php/ressources/backend.inc | 8++++----
Mcode/serveur/php/ressources/my-extensions.js | 7+------
Mcode/serveur/php/ressources/pticlic.js | 74+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Mcode/serveur/php/server.php | 2+-
6 files changed, 76 insertions(+), 26 deletions(-)

diff --git a/code/serveur/dump2sqlite.sh b/code/serveur/dump2sqlite.sh @@ -27,7 +27,7 @@ create table relation(rid integer primary key autoincrement, start, end, type, w create table type_node(name, num); create table type_relation(name, num, extended_name, info); create table user(login primary key, mail, hash_passwd, score, ugroup); -create table game(gid integer primary key autoincrement, eid_central_word, relation_1, relation_2, difficulty, author); +create table game(gid integer primary key autoincrement, eid_central_word, relation_1, relation_2, difficulty, author, nb_like, nb_dislike); create table game_cloud(gid, num, difficulty, eid_word, totalWeight, probaR1, probaR2, probaR0, probaTrash); create table played_game(pgid, gid, login, timestamp, primary key(login, pgid)); create table played_game_sequence(id integer primary key autoincrement); diff --git a/code/serveur/php/jeu.php b/code/serveur/php/jeu.php @@ -17,7 +17,7 @@ .screen { width:100%; height:100%; position:absolute; } .highlight { display:none; width:100%; height:100%; border-width:medium; border-style:solid; border-radius:2em; position:absolute; } a:hover .highlight { display:block; } - #frontpage .icon-container { width:100%; bottom: 40%; height:50%; position:absolute; } + #frontpage .icon-container { width:100%; bottom: 40%; height:50%; position:absolute; vertical-align:bottom; } #frontpage .icon-container img { display:block; margin: 0 auto; } #frontpage .icon-label { width:100%; height:30%; bottom:5%; position:absolute; } #frontpage a { color: black; text-decoration: none; display:inline-block; width: 30%; height: 32%; top: 32%; position:absolute; } @@ -31,7 +31,7 @@ .fitFont, .subFitFont { overflow:auto; } #score { text-align:center; } .marginBox { width: 90%; height: 90%; top: 5%; left:5%; position:absolute; } - #message { left:25%; top:5%; width:50%; height:15%; position:absolute; border-radius:0.5em; text-align:center; opacity:0.9; } + #message { left:25%; top:5%; width:50%; height:10%; position:absolute; border-radius:0.5em; text-align:center; opacity:0.9; } .transition { transition: all 0.7s linear; -moz-transition: all 0.7s linear; -webkit-transition: all 0.7s linear; } .transition-bg { transition: background-color 0.7s linear; -moz-transition: background-color 0.7s linear; -webkit-transition: background-color 0.7s linear; } @@ -80,6 +80,9 @@ </div> </div> <div id="frontpage" class="screen fitFontGroup"> + <a href="index.php" style="width:7%; height:5%; top:2%; right:2%; position:absolute;" class="fitFont button"> + <span style="width:90%; height:90%; top:5%; left:5%; position:absolute;"><span class="center">Retour au site</span></span> + </a> <div style="width:50%; height:24%; top:4%; left:25%; position:absolute;" class="fitFont"> <span class="center">PtiClic</span> </div> @@ -148,7 +151,7 @@ </div> </div> <div id="connection" class="screen"> - <form id="connect-form" action="#" method="GET" style="width:100%; height:100%;" class="fitFontGroup"> + <form action="#" method="GET" style="width:100%; height:100%;" class="fitFontGroup"> <div class="formElement subFitFont" style="right: 55%; top: 25%;"><label id="user-label" for="user">Login : </label></div> <div class="formElement subFitFont" style="left: 55%; top: 25%;"><input type="text" name="user" id="user" class="setFont" /></div> <div class="formElement subFitFont" style="right: 55%; top: 50%;"><label id="passwd-label" for="passwd">Mot de passe : </label></div> diff --git a/code/serveur/php/ressources/backend.inc b/code/serveur/php/ressources/backend.inc @@ -18,7 +18,6 @@ require_once("ressources/db.inc"); * game2json($user, $pgid); * createGame($nbParties, $mode); * createGameCore($cloudSize); -* getGame($user, $nbGames, $mode); * computeScore($probas, $difficulty, $answer, $userReputation); * computeUserReputation($score); * normalizeProbas($row); @@ -299,8 +298,8 @@ function insertCreatedGame($centerEid, $cloud, $r1, $r2, $totalDifficulty, $user $sqlUserName = SQLite3::escapeString($userName); // Insère dans la base une partie avec le mot central $centerEid, le nuage $cloud et les relations $r1 et $r2 $db->exec("begin transaction;"); - $db->exec("INSERT INTO game(gid, eid_central_word, relation_1, relation_2, difficulty, author) - VALUES (null, $centerEid, $r1, $r2, $totalDifficulty, '".$sqlUserName."');"); + $db->exec("INSERT INTO game(gid, eid_central_word, relation_1, relation_2, difficulty, author, nb_like, nb_dislike) + VALUES (null, $centerEid, $r1, $r2, $totalDifficulty, '".$sqlUserName."', 0, 0);"); $gid = $db->lastInsertRowID(); $t = time(); @@ -437,10 +436,11 @@ function game2json($user, $pgid = null) list($gid, $pgid) = makePgid($user, null, $pgid); // TODO Yoann : faire des tests d'erreur pour ces select ? - $game = $db->query("select gid, (select name from node where eid = eid_central_word) as name_central_word, eid_central_word, relation_1, relation_2 from game where gid = ".$gid.";"); + $game = $db->query("select author, gid, (select name from node where eid = eid_central_word) as name_central_word, eid_central_word, relation_1, relation_2 from game where gid = ".$gid.";"); $game = $game->fetchArray(); $ret = array( + "author" => $game['author'], "gid" => $gid, "pgid" => $pgid, "relations" => array( diff --git a/code/serveur/php/ressources/my-extensions.js b/code/serveur/php/ressources/my-extensions.js @@ -189,13 +189,8 @@ function encodeHash(data) { function Cache(resolver) { var cache = []; - var self = this; this.get = function(k) { - return cache[k] = cache[k] || $.Deferred(function(dfd) { resolver(k, dfd, self); }); - }; - this.alias = function(alias, k) { - cache[alias] = cache[alias] || $.Deferred(); - cache[k].done(function(data) { cache[alias].resolve(data); }); + return cache[k] = cache[k] || $.Deferred(function(dfd) { resolver(k, dfd); }).fail(cache[k] = false).promise(); }; } diff --git a/code/serveur/php/ressources/pticlic.js b/code/serveur/php/ressources/pticlic.js @@ -119,20 +119,72 @@ init(function() { }); +// ==== Écran connexion +runstate.pendingGetPrefs = function() { + console.log('Should execute pendingGetPrefs'); +}; + +init(function() { + $('#connection.screen form').submit(function() { + runstate.user = $('#user').val(); + runstate.passwd = $('#passwd').val(); + if (runstate.pendingSetPrefs) { + runstate.pendingSetPrefs(); + } else { + runstate.pendingGetPrefs(); + } + if (state.screen == game) { + $('#game').trigger('pre-enter'); + } else { + location.hash = "#frontpage"; + } + return false; + }); + + $('#connection.screen').bind('leave', function() { + runstate.pendingSetPrefs = false; + runstate.pendingGetGame = false; + }); +}); + // ==== Écran game -runstate.gameCache = new Cache(function(k, dfd, cache) { - $.getJSON("getGame.php?callback=?", {pgid:k}, function(data) { +$.ajaj = function(url, data, callback) { + var user = '' + UI().getPreference("user"); + var passwd = '' + UI().getPreference("passwd"); + if (user != '' && passwd != '') { + if (!data.user) data.user = user; + if (!data.passwd) data.passwd = passwd; + } + $.getJSON(url, data, callback); +}; + +function getGame(k, dfd, retry) { + $.ajaj("getGame.php?callback=?", {pgid:k}, function(data) { if (data.error == 10) { - $('#connection.screen').trigger('goto'); + dfd.reject(data); + if (state.screen == 'game' && state.pgid == k) { + if (retry) { + $('#connection.screen').trigger('goto'); + } else { + location.hash = "#frontpage"; + message("Erreur", "Vous n'êtes pas connecté."); + } + } } else if (data.isError) { + dfd.reject(data); location.hash = "#frontpage"; - message("Erreur", "Une erreur est survenue, veuillez nous en excuser."); + message("Erreur", data.msg); } else { - cache.alias(data.pgid, k); - dfd.resolve(data); + dfd.resolve(data); } + }).fail(function() { + dfd.reject(data); + location.hash = "#frontpage"; + message("Erreur", "Une erreur est survenue, veuillez nous en excuser."); }); -}); +} + +runstate.gameCache = new Cache(function(k, dfd) { getGame(k, dfd, true); }); init(function() { var game = $('#game.screen'); @@ -143,8 +195,8 @@ init(function() { game.bind('pre-enter', function() { runstate.gameCache.get(state.pgid).done(function(data) { - runstate.game = data - if (runstate.screen == 'game') { game.trigger('enter'); } + runstate.game = data; + game.trigger('enter'); }); return false; }); @@ -367,8 +419,8 @@ ajaj.request = function(url, data, okFunction, smallErrorFunction, bigErrorFunct try { smallErrorFunction = smallErrorFunction || ajaj.smallError; bigErrorFunction = bigErrorFunction || ajaj.bigError; - var user = "" + UI().getPreference("user"); - var passwd = "" + UI().getPreference("passwd"); + var user = '' + UI().getPreference("user"); + var passwd = '' + UI().getPreference("passwd"); if (user != '' && passwd != '') { if (!data.user) data.user = user; if (!data.passwd) data.passwd = passwd; diff --git a/code/serveur/php/server.php b/code/serveur/php/server.php @@ -128,7 +128,7 @@ function server() { echo json_encode( Array( "error" => $e->getCode(), - "msg" => "".$e->getMessage(), + "msg" => "Erreur ".$e->getCode()." : ".$e->getMessage(), "isError" => true ) );