From: Greg Burri Date: Sun, 27 Jul 2008 00:05:16 +0000 (+0000) Subject: ADD betterjs qui regroupe les améliorations ajoutés à javascript (each, etc..) X-Git-Tag: 1.1.0~40 X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=commitdiff_plain;h=4dfbbcf0f54cb3eb70856ea404d9ecef6aec5e26 ADD betterjs qui regroupe les améliorations ajoutés à javascript (each, etc..) FIX quelques petits bugs dans euphorik_tests --- diff --git a/doc/graphiques/maquette_1.svg b/doc/graphiques/maquette_1.svg index b6784c9..3f5163f 100644 --- a/doc/graphiques/maquette_1.svg +++ b/doc/graphiques/maquette_1.svg @@ -412,11 +412,11 @@ + style="fill:#350a0a;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;display:inline" /> + diff --git a/js/betterjs.js b/js/betterjs.js new file mode 100644 index 0000000..d7ceb8e --- /dev/null +++ b/js/betterjs.js @@ -0,0 +1,77 @@ +// tout un tas d'améliorations de JavaScript ;) + + +/** + * Pour chaque propriété de l'objet execute f(p, v) ou p est le nom de la propriété et v sa valeur. + * Ne parcours pas les propriétés des prototypes. + * FIXME : Normalement : Object.prototype.each = function(f) mais non supporté par jquery + */ +//Object.prototype.each = function(f) { +var objectEach = function(o, f) { + for (var k in o) { + if (o.hasOwnProperty(k)) { + f(k, o[k]); + } + } +}; + +var objectMemberCount = function(o) { + var nb = 0; + for (var k in o) { + if (o.hasOwnProperty(k)) { + nb += 1; + } + } + return nb; +}; + +Array.prototype.each = function(f) { + for (var i = 0; i < this.length; i++) { + f(i, this[i]); + } +}; + +Array.prototype.map = function(f) { + for (var i = 0; i < this.length; i++) { + this[i] = f(this[i]) + } +}; + +String.prototype.trim = function() { + return jQuery.trim(this) // anciennement : this.replace(/^\s+|\s+$/g, ""); +} + +String.prototype.ltrim = function() { + return this.replace(/^\s+/, ""); +} + +String.prototype.rtrim = function() { + return this.replace(/\s+$/, ""); +} + + +/** + * Voir : http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html + * + * Exemple : + * + * function Mammal(name) { + * this.name = name; + * } + * + * Cat.Inherits(Mammal); + * function Cat(name) { + * this.Super(Mammal, name); + * } + */ +/*Object.prototype.Super = function(parent) { + if(arguments.length > 1) { + parent.apply( this, Array.prototype.slice.call( arguments, 1 ) ); + } else { + parent.call( this ); + } +} +Function.prototype.Inherits = function(parent) { + this.prototype = new parent(); + this.prototype.constructor = this; +}*/ diff --git a/js/euphorik.js b/js/euphorik.js index 5265f28..17748a6 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -16,113 +16,8 @@ // You should have received a copy of the GNU General Public License // along with Euphorik. If not, see . -/** - * Contient la base javascript pour le site euphorik.ch. - * Chaque page possède son propre fichier js nommé "page.js". - * Auteur : GBurri - * Date : 6.11.2007 - */ - // tout euphorik est contenu dans cet objet var euphorik = {} -// ;; euphorik.include = - //;; euphorik.include = function(f) { var s = document.createElement('script'); s.type = 'text/javascript'; s.src = "js/" + f + ".js"; document.getElementsByTagName('head')[0].appendChild(s); } - - -// version jQuery : function(f) { jQuery.ajax({async : false, url : "js/" + f + ".js", dataType : "script"}) } -// mais comme il n'est pas encore chargé... -;; euphorik.include = function(f) { -;; var req, url = 'js/' + f + '.js' -;; if (window.XMLHttpRequest) { -;; req = new XMLHttpRequest(); req.open("GET", url, false); req.send(null); -;; } else if (window.ActiveXObject) { -;; req = new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP"); -;; if (req) { req.open("GET", url, false); req.send(); } -;; } -;; if (req!==false) { if (req.status==200) { window.eval(req.responseText); } else if (req.status==404) { alert("erreur de chargement (404) de : " + url) } } -;; }; - - -// tout un tas d'améliorations de JavaScript ;) -/** - * Pour chaque propriété de l'objet execute f(p, v) ou p est le nom de la propriété et v sa valeur. - * Ne parcours pas les propriétés des prototypes. - * FIXME : Normalement : Object.prototype.each = function(f) mais non supporté par jquery - */ -//Object.prototype.each = function(f) { -var objectEach = function(o, f) { - for (var k in o) { - if (o.hasOwnProperty(k)) { - f(k, o[k]); - } - } -}; - -var objectMemberCount = function(o) { - var nb = 0; - for (var k in o) { - if (o.hasOwnProperty(k)) { - nb += 1; - } - } - return nb; -}; - -Array.prototype.each = function(f) { - for (var i = 0; i < this.length; i++) { - f(i, this[i]); - } -}; - -Array.prototype.map = function(f) { - for (var i = 0; i < this.length; i++) { - this[i] = f(this[i]) - } -}; - -String.prototype.trim = function() { - return jQuery.trim(this) // anciennement : this.replace(/^\s+|\s+$/g, ""); -} - -String.prototype.ltrim = function() { - return this.replace(/^\s+/, ""); -} - -String.prototype.rtrim = function() { - return this.replace(/\s+$/, ""); -} - - -/** - * Voir : http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html - * - * Exemple : - * - * function Mammal(name) { - * this.name = name; - * } - * - * Cat.Inherits(Mammal); - * function Cat(name) { - * this.Super(Mammal, name); - * } - */ -/*Object.prototype.Super = function(parent) { - if(arguments.length > 1) { - parent.apply( this, Array.prototype.slice.call( arguments, 1 ) ); - } else { - parent.call( this ); - } -} -Function.prototype.Inherits = function(parent) { - this.prototype = new parent(); - this.prototype.constructor = this; -}*/ - - - -/////////////////////////////////////////////////////////////////////////////////////////////////// - // le main $(document).ready( @@ -133,7 +28,6 @@ $(document).ready( var client = new euphorik.Client(util) var pages = new euphorik.Pages() - // connexion vers le serveur (utilise un cookie qui traine) client.connexionCookie() diff --git a/modules/erl/euphorik_bd.erl b/modules/erl/euphorik_bd.erl index 904fc0a..196a26e 100755 --- a/modules/erl/euphorik_bd.erl +++ b/modules/erl/euphorik_bd.erl @@ -31,15 +31,11 @@ update_date_derniere_connexion/1, update_ip/2, update_pseudo_user/2, - print_users/0, - print_users/1, - print_user/1, user_by_cookie/1, user_by_id/1, user_by_login/1, user_by_login_password/2, user_by_mess/1, - toggle_ek_master/1, css_from_user_cookie/1, is_ek_master_from_cookie/1, @@ -104,7 +100,7 @@ nouveau_user(Cookie, Profile) -> nouveau_user(Login, Password, Cookie, Profile) -> F = fun() -> Id = nouvel_id(user), - User = #user{id = Id, cookie = Cookie, login = Login, password = Password, date_creation = now(), date_derniere_connexion = now(), profile = Profile#profile{pseudo = login}}, + User = #user{id = Id, cookie = Cookie, login = Login, password = Password, date_creation = now(), date_derniere_connexion = now(), profile = Profile#profile{pseudo = Login}}, mnesia:write(User), User end, @@ -176,76 +172,7 @@ update_pseudo_user(UserId, Pseudo) -> end end ). - - -% Affiche N user trié par leur date de dernière connexion. -% Opt est une liste d'option d'affichage : -% * ekmaster : n'affiche que les admins -print_users(N, Opt) -> - AfficheQueLesEkMaster = lists:any(fun(O) -> O =:= ekmaster end, Opt), - resultat_transaction(mnesia:transaction(fun() -> - C = cursor( - qlc:keysort( - #user.date_derniere_connexion, - if AfficheQueLesEkMaster -> - q([E || E <- mnesia:table(user), E#user.ek_master =:= true]); - true -> - q([E || E <- mnesia:table(user)]) - end, - [{order, descending}] - ), - [{tmpdir, ?KEY_SORT_TEMP_DIR}] - ), - Users = qlc:next_answers(C, N), - lists:foreach( - fun(U) -> - print_user(U) - end, - Users - ), - qlc:delete_cursor(C) - end)). - - -% Affiche tous les users. -print_users(Opt) -> - print_users(all_remaining, Opt). - -% Affiche tous les users. -print_users() -> - print_users(all_remaining, []). - -print_user(User) when is_record(User, user) -> - #user{id = Id, profile = #profile{pseudo = Pseudo}, login = Login, ek_master = Ek_master, date_derniere_connexion = Date, last_ip = IP} = User, - {{Annee, Mois, Jour}, {Heure, Min, _}} = calendar:now_to_local_time(Date), - io:format( - % id pseudo (login) IP Jour Mois Année Heure Minute - "~4w : ~10.10..s(~10.10..s) ~s ~2w.~2.2.0w.~w - ~2wh~2.2.0w~n", - [ - Id, - if Ek_master -> "*"; true -> "" end ++ Pseudo, - Login, - euphorik_common:serialize_ip(IP), - Jour, Mois, Annee, Heure, Min - ] - ); -% Affichage d'un user en fonction de son login -print_user(Login) when is_list(Login) -> - case user_by_login(Login) of - {ok, User} -> - print_user(User); - _ -> - {erreur, "Login pas trouvé : " ++ Login} - end; -% Affichage d'un user en fonction de son id -print_user(Id) when is_integer(Id) -> - case user_by_id(Id) of - {ok, User} -> - print_user(User); - _ -> - {erreur, "Id pas trouvé : " ++ integer_to_list(Id)} - end. - + % Est-ce qu'un utilisateur existe en fonction de son cookie ? % Renvoie {ok, User} ou erreur @@ -282,19 +209,6 @@ user_by_login(Login) -> end )). - -toggle_ek_master(User_id) -> - resultat_transaction(mnesia:transaction( - fun() -> - Users = e(q([E || E <- mnesia:table(user), E#user.id =:= User_id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]), - case Users of - [User] -> - mnesia:write(User#user{ek_master = not User#user.ek_master}); - _ -> erreur - end - end - )). - % Renvoie une chaine représentant le cookie ou undefined si pas trouvé. css_from_user_cookie(Cookie) -> diff --git a/modules/erl/euphorik_bd_admin.erl b/modules/erl/euphorik_bd_admin.erl index 18e6ced..38fabfe 100644 --- a/modules/erl/euphorik_bd_admin.erl +++ b/modules/erl/euphorik_bd_admin.erl @@ -33,7 +33,12 @@ reset/0, update/0, backup/1, - restore/1 + restore/1, + + toggle_ek_master/1, + print_users/0, + print_users/1, + print_user/1 ]). -import(qlc, [e/2, q/1, cursor/2]). -include("../include/euphorik_bd.hrl"). @@ -222,3 +227,86 @@ restore(N) -> % Renvoie le fichier (avec le chemin) correspondant à la version Version, par exemple : "/var/euphorik/BD/backups/backup1" fichier_backup(Version) -> mnesia:system_info(directory) ++ "/backups/" ++ if is_integer(Version) -> "backup" ++ integer_to_list(Version); true -> Version end. + + +toggle_ek_master(User_id) -> + euphorik_bd:resultat_transaction(mnesia:transaction( + fun() -> + Users = e(q([E || E <- mnesia:table(user), E#user.id =:= User_id]), [{tmpdir, ?KEY_SORT_TEMP_DIR}]), + case Users of + [User] -> + mnesia:write(User#user{ek_master = not User#user.ek_master}); + _ -> erreur + end + end + )). + + +% Affiche N user trié par leur date de dernière connexion. +% Opt est une liste d'option d'affichage : +% * ekmaster : n'affiche que les admins +print_users(N, Opt) -> + AfficheQueLesEkMaster = lists:any(fun(O) -> O =:= ekmaster end, Opt), + euphorik_bd:resultat_transaction(mnesia:transaction(fun() -> + C = cursor( + qlc:keysort( + #user.date_derniere_connexion, + if AfficheQueLesEkMaster -> + q([E || E <- mnesia:table(user), E#user.ek_master =:= true]); + true -> + q([E || E <- mnesia:table(user)]) + end, + [{order, descending}] + ), + [{tmpdir, ?KEY_SORT_TEMP_DIR}] + ), + Users = qlc:next_answers(C, N), + lists:foreach( + fun(U) -> + print_user(U) + end, + Users + ), + qlc:delete_cursor(C) + end)). + + +% Affiche tous les users. +print_users(Opt) -> + print_users(all_remaining, Opt). + +% Affiche tous les users. +print_users() -> + print_users(all_remaining, []). + +print_user(User) when is_record(User, user) -> + #user{id = Id, profile = #profile{pseudo = Pseudo}, login = Login, ek_master = Ek_master, date_derniere_connexion = Date, last_ip = IP} = User, + {{Annee, Mois, Jour}, {Heure, Min, _}} = calendar:now_to_local_time(Date), + io:format( + % id pseudo (login) IP Jour Mois Année Heure Minute + "~4w : ~10.10..s(~10.10..s) ~s ~2w.~2.2.0w.~w - ~2wh~2.2.0w~n", + [ + Id, + if Ek_master -> "*"; true -> "" end ++ Pseudo, + Login, + euphorik_common:serialize_ip(IP), + Jour, Mois, Annee, Heure, Min + ] + ); +% Affichage d'un user en fonction de son login +print_user(Login) when is_list(Login) -> + case euphorik_bd:user_by_login(Login) of + {ok, User} -> + print_user(User); + _ -> + {erreur, "Login pas trouvé : " ++ Login} + end; +% Affichage d'un user en fonction de son id +print_user(Id) when is_integer(Id) -> + case euphorik_bd:user_by_id(Id) of + {ok, User} -> + print_user(User); + _ -> + {erreur, "Id pas trouvé : " ++ integer_to_list(Id)} + end. + \ No newline at end of file diff --git a/modules/erl/euphorik_test.erl b/modules/erl/euphorik_test.erl index 3b70bf2..8b8dbfb 100644 --- a/modules/erl/euphorik_test.erl +++ b/modules/erl/euphorik_test.erl @@ -52,7 +52,7 @@ creer_users(N) -> creer_users(N, []). creer_users(0, Ids) -> lists:map(fun(#user{id = Id}) -> Id end, Ids); creer_users(N, Ids) -> - creer_users(N - 1, [euphorik_bd:nouveau_user(mot_rand(random:uniform(4) + 4), "", "") | Ids ]). + creer_users(N - 1, [euphorik_bd:nouveau_user(mot_rand(random:uniform(4) + 4), "", "", #profile{}) | Ids ]). % crée un message aléatoire et le renvoie diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 51f6702..ea8bdaf 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -3,7 +3,7 @@ modules/erl/euphorik_protocole.erl - 677 + 713 js/pageMinichat.js diff --git a/tools/tools.rb b/tools/tools.rb index fe7eb9d..644c825 100644 --- a/tools/tools.rb +++ b/tools/tools.rb @@ -20,14 +20,19 @@ along with Euphorik. If not, see . #TODO : # - mettre à jour les numéros de versions en appelant le script "cope_num_version.rb" -# - création de unit tests (voir eunit) et validation avant la mise en prod +# - création de unit tests (voir eunit) et validation avant la mise en prod + +# Utilisation : +# tools.rb +# commandes : +# class MiseEnProd @@rep_remote = '/var/www/euphorik' @@host = 'euphorik.ch' @@opt_rsync = '' - def initialize + def initialize end def creer_remote_rep(rep) @@ -55,12 +60,19 @@ class MiseEnProd end # css, images, html, etc.. - def copier_partie_statique - print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}` - print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}` - print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}` - print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}` - print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}` + def copier_partie_statique + copier_fichier_html("index.yaws") + + ####print `rsync #{$opt_rsync} index.yaws #{$host}:#{$rep_remote}` + #print `rsync #{$opt_rsync} favicon.ico #{$host}:#{$rep_remote}` + #print `rsync #{$opt_rsync} -r css #{$host}:#{$rep_remote}` + #print `rsync #{$opt_rsync} -r pages #{$host}:#{$rep_remote}` + #print `rsync #{$opt_rsync} -r --exclude 'autres' img #{$host}:#{$rep_remote}` + end + + # Copie un fichier html, enlève les balises qui ont comme attribut : prod="delete" + def copier_fichier_htm(fichier) + end # contrôle des fichiers js à l'aide de jslint