diff --git a/app.py b/app.py index dad2ce5..5b93369 100644 --- a/app.py +++ b/app.py @@ -17,6 +17,7 @@ urls = ( '/tyedye/', 'summary', '/tyedye/stats', 'statistics', '/tyedye/stats/', 'statistics', + '/tyedye/stats/(.+)', 'statistics', '/tyedye/register', 'register', '/tyedye/register/', 'register', '/tyedye/player/(.+)', 'player', @@ -167,13 +168,33 @@ class summary(object): class statistics(object): - def GET(self): - game_name = get_game_name() + def GET(self, player_id = None): stats = [] - for stat in db.select("stats"): - stats.append(stat) + if not player_id: + for stat in db.select("stats"): + stats.append(stat) - return json.dumps(stats) + return json.dumps(stats) + + else: + for p in db.select('players', where = 'code = $player_id', vars = locals()): + player_data = dict(p) + + player_name = player_data['name'] + print player_name + + for s in db.select('sheet', where = 'player_name = $player_name', vars = locals()): + try: + stats_val = dict() + stat_name, def_val = get_stat_info_by_id(s.stat_id) + stats_val[stat_name] = s.value + stats.append(stats_val) + + except Exception as e: + continue + + return json.dumps(stats) + def POST(self): pass diff --git a/public/js/app.js b/public/js/app.js index 9438858..82bfd93 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1,7 +1,7 @@ // Model definition var Stat = Backbone.Model.extend({ - urlRoot: '/tyedye/stat', + urlRoot: '/tyedye/stat/', defaults: { name: 'New Stat', value: 0, @@ -14,9 +14,28 @@ var Stat = Backbone.Model.extend({ var Stats = Backbone.Collection.extend({ model: Stat, - url: "/tyedye/stats/", - initialize: function () { - this.fetch(); + url: function () { + if (this.generic) { + return "/tyedye/stats/"; + } else { + return "/tyedye/stats/" + this.id; + } + }, + initialize: function (models, player_id) { + this.generic = true; + if (typeof player_id != 'undefined') { + this.id = player_id; + this.generic = false; + } + this.fetch({ reset: true }); + if (!this.generic) { + this.on('reset', function () { + this.each(function (statistic) { + $("#player_stats" + this.id ) + .append(''); + }); + }); + } } }); @@ -25,9 +44,14 @@ var Player = Backbone.Model.extend({ defaults: { name: 'New Player', stats: new Stats, + code: 0, }, initialize: function () { - this.on("change", function (model) {}); + // this.on("change", function (model) {}); + if (this.get('code') != 0) { + var player_stats = new Stats([], this.get('code')); + this.set('stats', player_stats); + } } }); @@ -35,7 +59,7 @@ var Players = Backbone.Collection.extend({ model: Player, url: "/tyedye/players/", initialize: function () { - this.fetch(); + this.fetch({ reset: true }); } }); @@ -63,26 +87,20 @@ Backbone.history.start({root: '/tyedye'}); var PlayerListView = Backbone.View.extend({ initialize: function () { - this.listenTo(this.collection, 'add', this.render); + this.listenTo(this.collection, 'reset', this.render); }, collection: players, render: function () { // Load and compile the template - var template = _.template( $("#player_list_template").html(), { 'player_collection' : players, - 'player_num' : this.collection.length, - 'stats_num' : stats.length } ); + var template = _.template( $("#player_list_template").html(), {}); // Put the compiled html into our 'el' element, putting in on the webpage this.$el.html(template); + + this.collection.each(function (playerItem) { + $("div#player_ul_list").append('

' + playerItem.get('name') + '

'); + }); + $("#player_number").text(this.collection.length); } }); var player_list_view = new PlayerListView({ el: $("#player_list") }); - -function listUlPlayer (listPlayers) { - var html = ''; - listPlayers.each(function (item) { - html += '
  • ' + item.name + '
  • '; - }; - return html; - } - diff --git a/views/layout.html b/views/layout.html index afdaf24..8df80cf 100644 --- a/views/layout.html +++ b/views/layout.html @@ -38,6 +38,9 @@ $def with (main_block,sidebar_block, game_name) + + + @@ -75,15 +78,14 @@ $def with (main_block,sidebar_block, game_name)
    $:main_block +

    $game_name quick summary

    +

    Registered players: 0

    +

    Registered stats: 0