Started tying app and javascript
This commit is contained in:
parent
e881496bd6
commit
5dae2e797e
5 changed files with 12034 additions and 26 deletions
36
app.py
36
app.py
|
@ -4,6 +4,7 @@
|
|||
import web
|
||||
import hashlib, time
|
||||
from web import form
|
||||
import json
|
||||
|
||||
|
||||
# Framework initialization
|
||||
|
@ -16,14 +17,10 @@ urls = (
|
|||
'/tyedye/', 'summary',
|
||||
'/tyedye/stats', 'statistics',
|
||||
'/tyedye/stats/', 'statistics',
|
||||
'/tyedye/stats/add', 'stat_add',
|
||||
'/tyedye/stats/remove/(.+)', 'remove_stat',
|
||||
'/tyedye/stats/edit/(.+)', 'edit_stat',
|
||||
'/tyedye/register', 'register',
|
||||
'/tyedye/register/', 'register',
|
||||
'/tyedye/player/(.+)', 'player',
|
||||
'/tyedye/player_remove/(.+)', 'remove_player',
|
||||
'/tyedye/player_edit/(.+)', 'edit_player',
|
||||
'/tyedye/players/', 'player_list',
|
||||
'/tyedye/config', 'config',
|
||||
'/tyedye/config/', 'config',
|
||||
'/query/(.+)', 'query',
|
||||
|
@ -161,10 +158,11 @@ class summary(object):
|
|||
|
||||
# We render our main block and feed it to our
|
||||
# Web renderer
|
||||
summary = render.summary(game_name,
|
||||
player_num,
|
||||
stats_num,
|
||||
players)
|
||||
# summary = render.summary(game_name,
|
||||
# player_num,
|
||||
# stats_num,
|
||||
# players)
|
||||
summary = ''
|
||||
return render_web(summary)
|
||||
|
||||
|
||||
|
@ -175,13 +173,10 @@ class statistics(object):
|
|||
for stat in db.select("stats"):
|
||||
stats.append(stat)
|
||||
|
||||
add_stat_form = add_stat.render()
|
||||
return json.dumps(stats)
|
||||
|
||||
config = render.statistics(game_name,
|
||||
stats,
|
||||
add_stat_form)
|
||||
|
||||
return render_web(config)
|
||||
def POST(self):
|
||||
pass
|
||||
|
||||
|
||||
class stat_add(object):
|
||||
|
@ -278,7 +273,7 @@ class register(object):
|
|||
|
||||
|
||||
class player(object):
|
||||
def GET(self, player_name):
|
||||
def GET(self, player_name = None):
|
||||
for p in db.select('players', where = 'name = $player_name', vars = locals()):
|
||||
player_data = p
|
||||
|
||||
|
@ -295,6 +290,15 @@ class player(object):
|
|||
return render_web(result_render)
|
||||
|
||||
|
||||
class player_list(object):
|
||||
def GET(self):
|
||||
players = []
|
||||
for elem in db.select('players'):
|
||||
players.append(dict(elem))
|
||||
|
||||
return json.dumps(players)
|
||||
|
||||
|
||||
class edit_player(object):
|
||||
def GET(self, player_name):
|
||||
form = dynamic_register_form(player_name)
|
||||
|
|
1608
public/backbone.js
Normal file
1608
public/backbone.js
Normal file
File diff suppressed because it is too large
Load diff
10308
public/jquery-1.11.1.js
vendored
Normal file
10308
public/jquery-1.11.1.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,11 +1,88 @@
|
|||
Character = Backbone.Model.extend({
|
||||
urlRoot: '/tyedye/player',
|
||||
defaults: {
|
||||
name: 'New Player',
|
||||
stats: new Stats,
|
||||
}
|
||||
initialize: function(){
|
||||
// Model definition
|
||||
|
||||
var Stat = Backbone.Model.extend({
|
||||
urlRoot: '/tyedye/stat',
|
||||
defaults: {
|
||||
name: 'New Stat',
|
||||
value: 0,
|
||||
default_value: 0,
|
||||
},
|
||||
initialize: function () {
|
||||
this.on("change", function(model) {});
|
||||
}
|
||||
});
|
||||
|
||||
var Stats = Backbone.Collection.extend({
|
||||
model: Stat,
|
||||
url: "/tyedye/stats/",
|
||||
initialize: function () {
|
||||
this.fetch();
|
||||
}
|
||||
});
|
||||
|
||||
var character = new Character;
|
||||
var Player = Backbone.Model.extend({
|
||||
urlRoot: '/tyedye/player/',
|
||||
defaults: {
|
||||
name: 'New Player',
|
||||
stats: new Stats,
|
||||
},
|
||||
initialize: function () {
|
||||
this.on("change", function (model) {});
|
||||
}
|
||||
});
|
||||
|
||||
var Players = Backbone.Collection.extend({
|
||||
model: Player,
|
||||
url: "/tyedye/players/",
|
||||
initialize: function () {
|
||||
this.fetch();
|
||||
}
|
||||
});
|
||||
|
||||
var stats = new Stats;
|
||||
var players = new Players;
|
||||
|
||||
// Routers
|
||||
|
||||
var MainRouter = Backbone.Router.extend({
|
||||
routes: {
|
||||
"" : "index",
|
||||
"player/:player_id" : "player_detail",
|
||||
},
|
||||
index: function () { ;; },
|
||||
player_detail: function () { ;; }
|
||||
});
|
||||
|
||||
var main_router = MainRouter;
|
||||
|
||||
// History controller
|
||||
|
||||
Backbone.history.start({root: '/tyedye'});
|
||||
|
||||
// Views definition
|
||||
|
||||
var PlayerListView = Backbone.View.extend({
|
||||
initialize: function () {
|
||||
this.listenTo(this.collection, 'add', 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 } );
|
||||
// Put the compiled html into our 'el' element, putting in on the webpage
|
||||
this.$el.html(template);
|
||||
}
|
||||
});
|
||||
|
||||
var player_list_view = new PlayerListView({ el: $("#player_list") });
|
||||
|
||||
function listUlPlayer (listPlayers) {
|
||||
var html = '';
|
||||
listPlayers.each(function (item) {
|
||||
html += '<li><a href="/tyedye/player/' + item.code '">' + item.name + '</a></li>';
|
||||
};
|
||||
return html;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
$def with (main_block, sidebar_block, game_name)
|
||||
$def with (main_block,sidebar_block, game_name)
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
@ -6,7 +6,7 @@ $def with (main_block, sidebar_block, game_name)
|
|||
<title>TyeDye control panel for $game_name</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<!-- <link rel='stylesheet' type='text/css' href='/static/public/main.css'> -->
|
||||
<link href="/static/static/public/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/static/public/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style type="text/css">
|
||||
body {
|
||||
padding-top: 60px;
|
||||
|
@ -74,6 +74,17 @@ $def with (main_block, sidebar_block, game_name)
|
|||
</div>
|
||||
<div class='span9'>
|
||||
$:main_block
|
||||
<!-- Out main app blocks are now in control of our backbone app -->
|
||||
<div id="player_list"></div>
|
||||
<script type="text/template" id="player_list_template">
|
||||
<h2>$game_name quick summary</h2>
|
||||
<p>Registered players: <%= player_num %></p>
|
||||
<p>Registered stats: <%= stats_num %></p>
|
||||
<p>Player list:<br />
|
||||
<ul id="player_ul_list">
|
||||
<%= listUlPlayer(player_collection) %>
|
||||
</ul>
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
|
|
Loading…
Reference in a new issue