Permalink
Browse files

Model de Exercicio e Rotina

  • Loading branch information...
1 parent 17a9539 commit d1c0c5429b0a9bd330f26efbbc8f8c8e37d903f7 @cmilfont committed Dec 11, 2012
View
2 app/assets/javascripts/application.js
@@ -13,4 +13,4 @@
//= require jquery
//= require jquery_ujs
//= require ext-all
-//= require app
+//= require app
View
2 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']": {
View
38 app/assets/javascripts/ext.js
0 additions, 38 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
4 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']
+});
View
8 app/assets/javascripts/model/Rotina.js
@@ -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'}
]
});
View
9 app/assets/javascripts/view/rotina/List.js
@@ -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);
View
8 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;
View
15 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
View
2 app/helpers/rotina_helper.rb
@@ -0,0 +1,2 @@
+module RotinaHelper
+end
View
3 app/models/exercicio.rb
@@ -0,0 +1,3 @@
+class Exercicio < ActiveRecord::Base
+ attr_accessible :descricao, :titulo
+end
View
8 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
View
5 app/models/rotina.rb
@@ -0,0 +1,5 @@
+class Rotina < ActiveRecord::Base
+ attr_accessible :titulo
+ has_many :itens
+ validates_presence_of :titulo
+end
View
6 config/initializers/inflections.rb
@@ -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|
View
2 config/routes.rb
@@ -1,5 +1,7 @@
Workout::Application.routes.draw do
+ resources :rotinas
+
root :to => 'home#index'
end
View
9 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
View
10 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
View
14 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
View
27 db/schema.rb
@@ -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
View
20 db/seeds.rb
@@ -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.