Skip to content

Commit

Permalink
load bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
skalb committed Apr 23, 2012
1 parent e403ed2 commit 98bd9bd
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 33 deletions.
4 changes: 3 additions & 1 deletion app/assets/javascripts/backbone/models/bug.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ class Trackbone.Models.Bug extends Backbone.Model

class Trackbone.Collections.BugsCollection extends Backbone.Collection
model: Trackbone.Models.Bug
url: '/bugs'
initialize: (model, args) ->
@url = ->
args.feature_url + "/bugs"
3 changes: 3 additions & 0 deletions app/assets/javascripts/backbone/models/feature.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class Trackbone.Models.Feature extends Backbone.Model
defaults:
name: null

loadBugs: ->
@bugs = new Trackbone.Collections.BugsCollection([], {feature_url: this.url()});

class Trackbone.Collections.FeaturesCollection extends Backbone.Collection
model: Trackbone.Models.Feature
initialize: (model, args) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Trackbone.Routers.ProjectsRouter extends Backbone.Router

routes:
"index" : "index"
":id" : "show"
".*" : "index"

index: ->
Expand All @@ -17,13 +16,4 @@ class Trackbone.Routers.ProjectsRouter extends Backbone.Router

$("#features").html("")

$("#bugs").html("")

show: (id) ->
project = @projects.get(id)

# project.loadFeatures()
# project.features.fetch success: ->
# @featuresView = new Trackbone.Views.Features.IndexView(features: project.features)
# $("#features").html(@featuresView.render().el)
# project.features.fetch()
$("#bugs").html("")
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<td><%= name %></td>

<td><a href="#/<%= id %>">Show</td>
<td><a href="#/<%= id %>/edit">Edit</td>
<td><a href="#" class="select"><%= name %></td>
<td><a href="#/<%= id %>/destroy" class="destroy">Destroy</a></td>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
<tr>
<th>Name</th>
<th></th>
<th></th>
<th></th>
</tr>
</table>

<br/>

<a href="#/new">New Feature</a>
<br/>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<tr>
<th>Name</th>
<th></th>
<th></th>
<th></th>
</tr>
</table>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<td><%= name %></td>

<td><a href="#/<%= id %>">Show</td>
<td><a href="#/<%= id %>/edit">Edit</td>
<td><a href="#" class="select"><%= name %></td>
<td><a href="#/<%= id %>/destroy" class="destroy">Destroy</a></td>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ class Trackbone.Views.Features.FeatureView extends Backbone.View
template: JST["backbone/templates/features/feature"]

events:
"click .select" : "select"
"click .destroy" : "destroy"

tagName: "tr"

destroy: () ->
select: () ->
@model.loadBugs()
do (@model) ->
@model.bugs.fetch success: ->
bugsView = new Trackbone.Views.Bugs.IndexView(bugs: @model.bugs)
$("#bugs").html(bugsView.render().el)
@model.bugs.fetch()

destroy:( ) ->
@model.destroy()
this.remove()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ class Trackbone.Views.Features.IndexView extends Backbone.View

render: =>
$(@el).html(@template(features: @options.features.toJSON() ))
@addAll()

return this
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@ class Trackbone.Views.Projects.ProjectView extends Backbone.View
template: JST["backbone/templates/projects/project"]

events:
"click .select" : "select"
"click .destroy" : "destroy"

tagName: "tr"

select: () ->
@model.loadFeatures()
do (@model) ->
@model.features.fetch success: ->
featuresView = new Trackbone.Views.Features.IndexView(features: @model.features)
$("#features").html(featuresView.render().el)
$("#bugs").html('')
@model.features.fetch()

destroy: () ->
@model.destroy()
this.remove()
Expand Down
8 changes: 4 additions & 4 deletions db/migrate/20120422181157_sampledata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ class Sampledata < ActiveRecord::Migration
def up
project_id = feature_id = bug_id = 1
5.times do
project = Project.new(:name => "Project #{p}")
project = Project.new(:name => "Project #{project_id }")
project.save!
project_id += 1
5.times do
feature = Feature.new(:name => "Feature #{feature_id}", :project_id => project.id)
feature.save!
feature_id += 1
5.times do
bug = Bug.new(:name => "Bug #{bug_id}", :feature_id => feature.id)
bug = Bug.new(:name => "Bug #{bug_id}", :feature_id => feature.id)
bug.save!
bug_id += 1
end
feature_id += 1
end
project_id += 1
end
end

Expand Down

0 comments on commit 98bd9bd

Please sign in to comment.