Skip to content

Commit

Permalink
Model de Exercicio e Rotina
Browse files Browse the repository at this point in the history
  • Loading branch information
cmilfont committed Dec 11, 2012
1 parent 17a9539 commit d1c0c54
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 56 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Expand Up @@ -13,4 +13,4 @@
//= require jquery
//= require jquery_ujs
//= require ext-all
//= require app
//= require app
2 changes: 1 addition & 1 deletion app/assets/javascripts/controller/Rotinas.js
@@ -1,7 +1,7 @@
Ext.define('Workout.controller.Rotinas', {
extend: 'Ext.app.Controller',
views: ['rotina.List'],

models: ['Rotina', 'Item'],
init: function() {
this.control({
"button[itemId='rotinas']": {
Expand Down
38 changes: 0 additions & 38 deletions app/assets/javascripts/ext.js

This file was deleted.

4 changes: 4 additions & 0 deletions app/assets/javascripts/model/Item.js
@@ -0,0 +1,4 @@
Ext.define('Workout.model.Item', {
extend: 'Ext.data.Model',
fields: ['id','repeticao', 'tempo', 'rotina_id', 'exercicio_id']
});
8 changes: 6 additions & 2 deletions app/assets/javascripts/model/Rotina.js
Expand Up @@ -2,10 +2,14 @@ Ext.define('Workout.model.Rotina', {
extend: 'Ext.data.Model',
proxy: {
type: 'rest',
format: 'json',
url: '/rotinas'
},
fields: [
{ name:'src', type:'string' },
{ name:'caption', type:'string' }
'id',
'titulo'
],
hasMany: [
{model: 'Workout.model.Item', name: 'getItens', associationKey: 'itens'}
]
});
9 changes: 4 additions & 5 deletions app/assets/javascripts/view/rotina/List.js
Expand Up @@ -3,14 +3,13 @@ Ext.define('Workout.view.rotina.List', {
alias: 'widget.rotinalist',
tpl: new Ext.XTemplate(
'<tpl for=".">',
'<div style="margin-bottom: 10px;" class="thumb-wrap">',
'<img src="{src}" />',
'<br/><span>{caption}</span>',
'<div style="margin-bottom: 10px;" class="rotina-wrap">',
'<span>{titulo}</span>',
'</div>',
'</tpl>'
),
itemSelector: 'div.thumb-wrap',
emptyText: 'No images available',
itemSelector: 'div.rotina-wrap',
emptyText: 'Sem rotinas criadas',
store: Ext.create("Workout.store.RotinaStore"),
initComponent: function() {
this.callParent(arguments);
Expand Down
8 changes: 0 additions & 8 deletions app/assets/stylesheets/home.css.scss
@@ -1,11 +1,3 @@
// Place all the styles related to the home controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

/*.theme-workout {
background-color: "#7CADCA"
}*/

.x-toolbar .home_title {
color: #fff !important;
line-height: 18px;
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/rotinas_controller.rb
@@ -0,0 +1,15 @@
class RotinasController < ApplicationController

respond_to :html, :json

def index
@rotinas = Rotina.all
respond_with @rotinas, :include => :itens
end

def show
@rotina = Rotina.find params[:id]
respond_with @rotina, :include => :itens
end

end
2 changes: 2 additions & 0 deletions app/helpers/rotina_helper.rb
@@ -0,0 +1,2 @@
module RotinaHelper
end
3 changes: 3 additions & 0 deletions app/models/exercicio.rb
@@ -0,0 +1,3 @@
class Exercicio < ActiveRecord::Base
attr_accessible :descricao, :titulo
end
8 changes: 8 additions & 0 deletions app/models/item.rb
@@ -0,0 +1,8 @@
class Item < ActiveRecord::Base
belongs_to :rotina
belongs_to :exercicio
attr_accessible :repeticao, :tempo, :rotina_id, :exercicio_id

validates_presence_of :rotina, :exercicio

end
5 changes: 5 additions & 0 deletions app/models/rotina.rb
@@ -0,0 +1,5 @@
class Rotina < ActiveRecord::Base
attr_accessible :titulo
has_many :itens
validates_presence_of :titulo
end
6 changes: 6 additions & 0 deletions config/initializers/inflections.rb
Expand Up @@ -8,6 +8,12 @@
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end

ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'item', 'itens'
end


#
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections do |inflect|
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,5 +1,7 @@
Workout::Application.routes.draw do

resources :rotinas

root :to => 'home#index'

end
9 changes: 9 additions & 0 deletions db/migrate/20121210235228_create_rotinas.rb
@@ -0,0 +1,9 @@
class CreateRotinas < ActiveRecord::Migration
def change
create_table :rotinas do |t|
t.string :titulo

t.timestamps
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20121211000803_create_exercicios.rb
@@ -0,0 +1,10 @@
class CreateExercicios < ActiveRecord::Migration
def change
create_table :exercicios do |t|
t.string :titulo
t.text :descricao

t.timestamps
end
end
end
14 changes: 14 additions & 0 deletions db/migrate/20121211001902_create_items.rb
@@ -0,0 +1,14 @@
class CreateItems < ActiveRecord::Migration
def change
create_table :itens do |t|
t.belongs_to :rotina
t.belongs_to :exercicio
t.integer :repeticao
t.string :tempo

t.timestamps
end
add_index :itens, :rotina_id
add_index :itens, :exercicio_id
end
end
27 changes: 26 additions & 1 deletion db/schema.rb
Expand Up @@ -11,6 +11,31 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 0) do
ActiveRecord::Schema.define(:version => 20121211001902) do

create_table "exercicios", :force => true do |t|
t.string "titulo"
t.text "descricao"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "itens", :force => true do |t|
t.integer "rotina_id"
t.integer "exercicio_id"
t.integer "repeticao"
t.string "tempo"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

add_index "itens", ["exercicio_id"], :name => "index_itens_on_exercicio_id"
add_index "itens", ["rotina_id"], :name => "index_itens_on_rotina_id"

create_table "rotinas", :force => true do |t|
t.string "titulo"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

end
20 changes: 20 additions & 0 deletions db/seeds.rb
Expand Up @@ -5,3 +5,23 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)

Exercicio.create :titulo => "Alongamento", :descricao => "Alongar"
cl = Exercicio.create :titulo => "Corrida Leve", :descricao => "corrida"
cr = Exercicio.create :titulo => "Corrida Rapida", :descricao => "corrida"
Exercicio.create :titulo => "Polichinelos", :descricao => "Polichinelos"
Exercicio.create :titulo => "Flexoes", :descricao => "Flexoes"

Rotina.create :titulo => "Treino Funcional"
Rotina.create :titulo => "Treino de Jiujitsu"
rotina = Rotina.create :titulo => "Corrida"

Item.create :rotina_id => rotina.id,
:exercicio_id => cl.id,
:repeticao => 2,
:tempo => "00:10:00"

Item.create :rotina_id => rotina.id,
:exercicio_id => cr.id,
:repeticao => 1,
:tempo => "01:00:00"

0 comments on commit d1c0c54

Please sign in to comment.