Permalink
Browse files

first commit

  • Loading branch information...
1 parent dbe791a commit d0f44e16d5a60433af5a5612f2c1a2183b660587 @luisgutierrezkoombea luisgutierrezkoombea committed Sep 28, 2012
Showing with 1,937 additions and 159 deletions.
  1. BIN .DS_Store
  2. +3 −2 Gemfile
  3. +13 −1 Gemfile.lock
  4. BIN app/.DS_Store
  5. BIN app/assets/.DS_Store
  6. BIN app/assets/images/.DS_Store
  7. BIN app/assets/images/Delete-icon.png
  8. BIN app/assets/images/Gas-pump-icon.png
  9. BIN app/assets/images/app-edit-icon.png
  10. BIN app/assets/images/available.png
  11. BIN app/assets/images/not_available.png
  12. BIN app/assets/javascripts/.DS_Store
  13. +9 −0 app/assets/javascripts/application.js
  14. +4 −0 app/assets/javascripts/collections/cars.js
  15. +4 −0 app/assets/javascripts/collections/gas_stations.js
  16. +4 −0 app/assets/javascripts/collections/tanking_logs.js
  17. +3 −0 app/assets/javascripts/models/car.js
  18. +3 −0 app/assets/javascripts/models/gas_station.js
  19. +3 −0 app/assets/javascripts/models/tanking_log.js
  20. +36 −0 app/assets/javascripts/routers/cars.js
  21. +41 −0 app/assets/javascripts/routers/gas_stations.js
  22. +17 −0 app/assets/javascripts/routers/tanking_logs.js
  23. +8 −0 app/assets/javascripts/station.js
  24. BIN app/assets/javascripts/views/.DS_Store
  25. BIN app/assets/javascripts/views/cars/.DS_Store
  26. +24 −0 app/assets/javascripts/views/cars/car.js
  27. +21 −0 app/assets/javascripts/views/cars/cars_index.js
  28. +58 −0 app/assets/javascripts/views/cars/edit_car.js
  29. +60 −0 app/assets/javascripts/views/cars/new_car.js
  30. +55 −0 app/assets/javascripts/views/gas/edit_gas_station.js
  31. +24 −0 app/assets/javascripts/views/gas/gas_station.js
  32. +21 −0 app/assets/javascripts/views/gas/gas_stations_index.js
  33. +55 −0 app/assets/javascripts/views/gas/new_gas_station.js
  34. +55 −0 app/assets/javascripts/views/tanking_logs/edit_tanking_log.js
  35. +55 −0 app/assets/javascripts/views/tanking_logs/new_tanking_log.js
  36. +15 −0 app/assets/javascripts/views/tanking_logs/tanking_log.js
  37. +21 −0 app/assets/javascripts/views/tanking_logs/tanking_logs_index.js
  38. +1 −0 app/assets/stylesheets/application.css
  39. +640 −0 app/assets/stylesheets/custom.css.scss
  40. +3 −0 app/assets/stylesheets/home.css.scss
  41. +10 −0 app/assets/templates/cars/car.jst.eco
  42. +20 −0 app/assets/templates/cars/edit.jst.eco
  43. +6 −0 app/assets/templates/cars/flash.jst.eco
  44. +16 −0 app/assets/templates/cars/index.jst.eco
  45. +20 −0 app/assets/templates/cars/new.jst.eco
  46. +17 −0 app/assets/templates/gas/edit.jst.eco
  47. +5 −0 app/assets/templates/gas/gas.jst.eco
  48. +12 −0 app/assets/templates/gas/index.jst.eco
  49. +17 −0 app/assets/templates/gas/new.jst.eco
  50. +12 −0 app/assets/templates/tanking_logs/index.jst.eco
  51. 0 app/assets/templates/tanking_logs/new.jst.eco
  52. +6 −0 app/assets/templates/tanking_logs/tanking.jst.eco
  53. +86 −16 app/controllers/cars_controller.rb
  54. +75 −27 app/controllers/gas_stations_controller.rb
  55. +4 −0 app/controllers/home_controller.rb
  56. +87 −26 app/controllers/tanking_logs_controller.rb
  57. +5 −0 app/helpers/application_helper.rb
  58. +2 −0 app/helpers/home_helper.rb
  59. +3 −1 app/models/car.rb
  60. +2 −0 app/models/tanking_log.rb
  61. +1 −3 app/models/user.rb
  62. BIN app/views/.DS_Store
  63. BIN app/views/cars/.DS_Store
  64. +8 −2 app/views/cars/index.html.erb
  65. +23 −16 app/views/devise/registrations/edit.html.erb
  66. +19 −12 app/views/devise/registrations/new.html.erb
  67. +16 −12 app/views/devise/sessions/new.html.erb
  68. +8 −2 app/views/gas_stations/index.html.erb
  69. +22 −0 app/views/home/index.html.erb
  70. +17 −0 app/views/layouts/_error_messages.html.erb
  71. +10 −0 app/views/layouts/_footer.html.erb
  72. +39 −0 app/views/layouts/_header.html.erb
  73. +15 −5 app/views/layouts/application.html.erb
  74. +8 −2 app/views/tanking_logs/index.html.erb
  75. +9 −4 config/routes.rb
  76. +4 −0 spec/controllers/cars_controller_spec.rb
  77. +12 −0 spec/controllers/home_controller_spec.rb
  78. +12 −0 spec/factories/cars.rb
  79. +12 −0 spec/factories/users.rb
  80. +41 −28 spec/models/car_spec.rb
View
BIN .DS_Store
Binary file not shown.
View
5 Gemfile
@@ -5,12 +5,13 @@ gem 'pg','0.14.1'
gem 'devise'
gem 'sass'
gem 'haml'
-gem 'bootstrap-sass', '2.0.0'
+gem 'bootstrap-sass'
gem 'sass-rails', '~> 3.2.3'
-
gem 'jquery-rails',"2.0.2"
gem 'jquery-ui-rails',"0.3.0"
+gem 'backbone-on-rails'
+
group :assets do
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
View
14 Gemfile.lock
@@ -30,6 +30,11 @@ GEM
multi_json (~> 1.0)
addressable (2.3.2)
arel (3.0.2)
+ backbone-on-rails (0.9.2.1)
+ eco (~> 1.0.0)
+ ejs (~> 1.0.0)
+ jquery-rails
+ railties (>= 3.1)
bcrypt-ruby (3.0.1)
bootstrap-sass (2.0.0)
builder (3.0.3)
@@ -56,6 +61,12 @@ GEM
railties (~> 3.1)
warden (~> 1.1.1)
diff-lcs (1.1.3)
+ eco (1.0.0)
+ coffee-script
+ eco-source
+ execjs
+ eco-source (1.1.0.rc.1)
+ ejs (1.0.0)
erubis (2.7.0)
execjs (1.4.0)
multi_json (~> 1.0)
@@ -175,7 +186,8 @@ PLATFORMS
ruby
DEPENDENCIES
- bootstrap-sass (= 2.0.0)
+ backbone-on-rails
+ bootstrap-sass
capybara
coffee-rails (= 3.2.2)
database_cleaner
View
BIN app/.DS_Store
Binary file not shown.
View
BIN app/assets/.DS_Store
Binary file not shown.
View
BIN app/assets/images/.DS_Store
Binary file not shown.
View
BIN app/assets/images/Delete-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN app/assets/images/Gas-pump-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN app/assets/images/app-edit-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN app/assets/images/available.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN app/assets/images/not_available.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN app/assets/javascripts/.DS_Store
Binary file not shown.
View
9 app/assets/javascripts/application.js
@@ -12,4 +12,13 @@
//
//= require jquery
//= require jquery_ujs
+//= require bootstrap
+//= require underscore
+//= require backbone
+//= require .//station
+//= require_tree ../templates/
+//= require_tree .//models
+//= require_tree .//collections
+//= require_tree .//views
+//= require_tree .//routers
//= require_tree .
View
4 app/assets/javascripts/collections/cars.js
@@ -0,0 +1,4 @@
+Station.Collections.Cars = Backbone.Collection.extend({
+ url: "/cars",
+ model: Station.Models.Car
+});
View
4 app/assets/javascripts/collections/gas_stations.js
@@ -0,0 +1,4 @@
+Station.Collections.GasStations = Backbone.Collection.extend({
+ url: "/gas_stations",
+ model: Station.Models.GasStation
+});
View
4 app/assets/javascripts/collections/tanking_logs.js
@@ -0,0 +1,4 @@
+Station.Collections.TankingLogs = Backbone.Collection.extend({
+ url: "/tanking_logs",
+ model: Station.Models.TankingLog
+});
View
3 app/assets/javascripts/models/car.js
@@ -0,0 +1,3 @@
+Station.Models.Car = Backbone.Model.extend({
+ urlRoot : '/cars'
+});
View
3 app/assets/javascripts/models/gas_station.js
@@ -0,0 +1,3 @@
+Station.Models.GasStation = Backbone.Model.extend({
+ urlRoot : '/gas_stations'
+});
View
3 app/assets/javascripts/models/tanking_log.js
@@ -0,0 +1,3 @@
+Station.Models.TankingLog = Backbone.Model.extend({
+ urlRoot : '/tanking_logs'
+});
View
36 app/assets/javascripts/routers/cars.js
@@ -0,0 +1,36 @@
+Station.Routers.Cars = Backbone.Router.extend({
+
+ routes:{
+ '': 'index',
+ 'new': 'add',
+ ':id/edit' : 'edit'
+ },
+
+ initialize: function(){
+ this.collection = new Station.Collections.Cars();
+ this.collection.fetch();
+ },
+
+
+ index: function(){
+ var view = new Station.Views.CarsIndex({"collection": this.collection});
+ $('#container_cars').html(view.render().el);
+ },
+
+
+ add: function(){
+ var view = new Station.Views.NewCar({"collection": this.collection });
+ $('#container_cars').html(view.render().el);
+ },
+
+
+ edit: function(id){
+ var car = this.collection.get(id);
+ var view = new Station.Views.EditCar({'model': car});
+ $('#container_cars').html(view.render().el);
+ }
+
+});
+
+
+
View
41 app/assets/javascripts/routers/gas_stations.js
@@ -0,0 +1,41 @@
+Station.Routers.GasStations = Backbone.Router.extend({
+
+ routes:{
+ '': 'index',
+ 'new': 'add',
+ ':id/edit' : 'edit'
+ },
+
+ initialize: function(){
+
+ this.collection = new Station.Collections.GasStations();
+ this.collection.fetch();
+
+ },
+
+
+ index: function(){
+
+ var view = new Station.Views.GasStationsIndex({"collection": this.collection});
+ $('#container_gasstations').html(view.render().el);
+
+ },
+
+
+ add: function(){
+
+ var view = new Station.Views.NewGasStation({"collection": this.collection });
+ $('#container_gasstations').html(view.render().el);
+
+ },
+
+
+ edit: function(id){
+
+ var gas = this.collection.get(id);
+ var view = new Station.Views.EditGasStation({'model': gas});
+ $('#container_gasstations').html(view.render().el);
+
+ }
+
+});
View
17 app/assets/javascripts/routers/tanking_logs.js
@@ -0,0 +1,17 @@
+Station.Routers.TankingLogs = Backbone.Router.extend({
+
+ routes:{
+ '': 'index'
+ },
+
+ initialize: function(){
+ this.collection = new Station.Collections.TankingLogs();
+ this.collection.fetch();
+ },
+
+ index: function(){
+ var view = new Station.Views.TankingLogIndex({"collection": this.collection });
+ $('#container_tankinglogs').html(view.render().el);
+ }
+
+});
View
8 app/assets/javascripts/station.js
@@ -0,0 +1,8 @@
+window.Station = {
+
+ Models: {},
+ Collections: {},
+ Views: {},
+ Routers: {}
+
+};
View
BIN app/assets/javascripts/views/.DS_Store
Binary file not shown.
View
BIN app/assets/javascripts/views/cars/.DS_Store
Binary file not shown.
View
24 app/assets/javascripts/views/cars/car.js
@@ -0,0 +1,24 @@
+Station.Views.Car = Backbone.View.extend({
+
+ template: JST['cars/car'],
+ tagName:'tr',
+
+ events: {
+ "click .destroy" : "deleteCar"
+ },
+
+ initialize: function(){
+ this.model.on('change',this.render,this);
+ },
+
+ render: function(){
+ this.$el.html(this.template({car: this.model}));
+ return this;
+ },
+
+ deleteCar: function(){
+ this.model.destroy();
+ this.remove();
+ }
+
+});
View
21 app/assets/javascripts/views/cars/cars_index.js
@@ -0,0 +1,21 @@
+Station.Views.CarsIndex = Backbone.View.extend({
+
+ template: JST['cars/index'],
+
+ initialize: function(){
+ this.collection.on('reset',this.render,this);
+ this.collection.bind('add', this.appendCar,this);
+ },
+
+ render: function(){
+ this.$el.html(this.template);
+ this.collection.each(this.appendCar,this);
+ return this;
+ },
+
+ appendCar: function(car){
+ view = new Station.Views.Car({"model": car});
+ this.$('#carlist').append(view.render().el);
+ }
+
+});
View
58 app/assets/javascripts/views/cars/edit_car.js
@@ -0,0 +1,58 @@
+Station.Views.EditCar = Backbone.View.extend({
+
+ template: JST['cars/edit'],
+
+ events:{
+ 'click #edit_car': 'updateCar'
+ },
+
+ render: function(){
+ this.$el.html(this.template({car: this.model}));
+ return this;
+ },
+
+ updateCar: function(event){
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ var attributes = {
+ 'model': $('#edit_car_model').val(),
+ 'brand':$('#edit_car_brand').val(),
+ 'color':$('#edit_car_color').val(),
+ 'year':$('#edit_car_year').val()
+ };
+
+ this.model.save(attributes,{
+
+ wait: true,
+
+ success: function(){
+ window.location.hash = "";
+ },
+
+ error: function(car, response){
+
+ if(response.status == 422){
+
+ var msg = '';
+
+ errors = $.parseJSON(response.responseText);
+
+ var attribute, message, messages, _i, _len;
+
+ for (attribute in errors) {
+
+ messages = errors[attribute];
+
+ for (_i = 0, _len = messages.length; _i < _len; _i++) {
+ message = messages[_i];
+ msg += ''+attribute+' '+message+',';
+ }
+ }
+ alert(msg);
+ }
+ }
+ });
+ }
+});
View
60 app/assets/javascripts/views/cars/new_car.js
@@ -0,0 +1,60 @@
+Station.Views.NewCar = Backbone.View.extend({
+
+ template: JST['cars/new'],
+
+ events:{
+ 'click #new_car': 'createCar'
+ },
+
+ render: function(){
+ this.$el.html(this.template);
+ return this;
+ },
+
+ createCar: function(event){
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ var attributes = {
+ 'model': $('#new_car_model').val(),
+ 'brand':$('#new_car_brand').val(),
+ 'color':$('#new_car_color').val(),
+ 'year':$('#new_car_year').val()
+ };
+
+ this.collection.create(attributes,{
+
+ wait: true,
+
+ success: function(car, response){
+ window.location.hash = "";
+ },
+
+ error: function(car, response){
+
+ if(response.status == 422){
+
+ var msg = '';
+
+ errors = $.parseJSON(response.responseText);
+
+ var attribute, message, messages, _i, _len;
+
+ for (attribute in errors) {
+
+ messages = errors[attribute];
+
+ for (_i = 0, _len = messages.length; _i < _len; _i++) {
+ message = messages[_i];
+ msg += ''+attribute+' '+message+',';
+ }
+ }
+
+ alert(msg);
+ }
+ }
+ });
+ }
+
+});
View
55 app/assets/javascripts/views/gas/edit_gas_station.js
@@ -0,0 +1,55 @@
+Station.Views.EditGasStation = Backbone.View.extend({
+
+ template: JST['gas/edit'],
+
+ events:{
+ 'click #edit_gas': 'updateGas'
+ },
+
+ render: function(){
+ this.$el.html(this.template({gas: this.model}));
+ return this;
+ },
+
+ updateGas: function(event){
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ var attributes = {
+ 'name': $('#edit_gas_name').val()
+ };
+
+ this.model.save(attributes,{
+
+ wait: true,
+
+ success: function(){
+ window.location.hash = "";
+ },
+
+ error: function(car, response){
+
+ if(response.status == 422){
+
+ var msg = '';
+
+ errors = $.parseJSON(response.responseText);
+
+ var attribute, message, messages, _i, _len;
+
+ for (attribute in errors) {
+
+ messages = errors[attribute];
+
+ for (_i = 0, _len = messages.length; _i < _len; _i++) {
+ message = messages[_i];
+ msg += ''+attribute+' '+message+',';
+ }
+ }
+ alert(msg);
+ }
+ }
+ });
+ }
+});
View
24 app/assets/javascripts/views/gas/gas_station.js
@@ -0,0 +1,24 @@
+Station.Views.GasStation = Backbone.View.extend({
+
+ template: JST['gas/gas'],
+ tagName:'tr',
+
+ events: {
+ "click .destroy" : "deleteGas"
+ },
+
+ initialize: function(){
+ this.model.on('change',this.render,this);
+ },
+
+ render: function(){
+ this.$el.html(this.template({gas: this.model}));
+ return this;
+ },
+
+ deleteGas: function(){
+ this.model.destroy();
+ this.remove();
+ }
+
+});
View
21 app/assets/javascripts/views/gas/gas_stations_index.js
@@ -0,0 +1,21 @@
+Station.Views.GasStationsIndex = Backbone.View.extend({
+
+ template: JST['gas/index'],
+
+ initialize: function(){
+ this.collection.on('reset',this.render,this);
+ this.collection.bind('add', this.appendGas,this);
+ },
+
+ render: function(){
+ this.$el.html(this.template);
+ this.collection.each(this.appendGas,this);
+ return this;
+ },
+
+ appendGas: function(gas){
+ view = new Station.Views.GasStation({"model": gas});
+ this.$('#gaslist').append(view.render().el);
+ }
+
+});
View
55 app/assets/javascripts/views/gas/new_gas_station.js
@@ -0,0 +1,55 @@
+Station.Views.NewGasStation = Backbone.View.extend({
+
+ template: JST['gas/new'],
+
+ events:{
+ 'click #new_gas': 'createGas'
+ },
+
+ render: function(){
+ this.$el.html(this.template);
+ return this;
+ },
+
+ createGas: function(event){
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ var attributes = {
+ 'name': $('#new_gas_name').val()
+ };
+
+ this.collection.create(attributes,{
+
+ wait: true,
+
+ success: function(gas, response){
+ window.location.hash = "";
+ },
+
+ error: function(gas, response){
+
+ if(response.status == 422){
+
+ var msg = '';
+
+ errors = $.parseJSON(response.responseText);
+
+ var attribute, message, messages, _i, _len;
+
+ for (attribute in errors) {
+
+ messages = errors[attribute];
+
+ for (_i = 0, _len = messages.length; _i < _len; _i++) {
+ message = messages[_i];
+ msg += ''+attribute+' '+message+',';
+ }
+ }
+ alert(msg);
+ }
+ }
+ });
+ }
+});
View
55 app/assets/javascripts/views/tanking_logs/edit_tanking_log.js
@@ -0,0 +1,55 @@
+Station.Views.EditTankingLog = Backbone.View.extend({
+
+ template: JST['tanking_logs/edit'],
+
+ events:{
+ 'click #edit_tank': 'updateTank'
+ },
+
+ render: function(){
+ this.$el.html(this.template({gas: this.model}));
+ return this;
+ },
+
+ updateGas: function(event){
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ var attributes = {
+ 'name': $('#edit_gas_name').val()
+ };
+
+ this.model.save(attributes,{
+
+ wait: true,
+
+ success: function(){
+ window.location.hash = "";
+ },
+
+ error: function(car, response){
+
+ if(response.status == 422){
+
+ var msg = '';
+
+ errors = $.parseJSON(response.responseText);
+
+ var attribute, message, messages, _i, _len;
+
+ for (attribute in errors) {
+
+ messages = errors[attribute];
+
+ for (_i = 0, _len = messages.length; _i < _len; _i++) {
+ message = messages[_i];
+ msg += ''+attribute+' '+message+',';
+ }
+ }
+ alert(msg);
+ }
+ }
+ });
+ }
+});
View
55 app/assets/javascripts/views/tanking_logs/new_tanking_log.js
@@ -0,0 +1,55 @@
+Station.Views.NewTankingLog = Backbone.View.extend({
+
+ template: JST['tanking_logs/new'],
+
+ events:{
+ 'click #new_gas': 'createTank'
+ },
+
+ render: function(){
+ this.$el.html(this.template);
+ return this;
+ },
+
+ createTank: function(event){
+
+ event.preventDefault();
+ event.stopPropagation();
+
+ var attributes = {
+ 'name': $('#new_tank_name').val()
+ };
+
+ this.collection.create(attributes,{
+
+ wait: true,
+
+ success: function(gas, response){
+ window.location.hash = "";
+ },
+
+ error: function(gas, response){
+
+ if(response.status == 422){
+
+ var msg = '';
+
+ errors = $.parseJSON(response.responseText);
+
+ var attribute, message, messages, _i, _len;
+
+ for (attribute in errors) {
+
+ messages = errors[attribute];
+
+ for (_i = 0, _len = messages.length; _i < _len; _i++) {
+ message = messages[_i];
+ msg += ''+attribute+' '+message+',';
+ }
+ }
+ alert(msg);
+ }
+ }
+ });
+ }
+});
View
15 app/assets/javascripts/views/tanking_logs/tanking_log.js
@@ -0,0 +1,15 @@
+Station.Views.TankingLog = Backbone.View.extend({
+
+ template: JST['tanking_logs/tanking'],
+ tagName:'tr',
+
+ initialize: function(){
+ this.model.on('change',this.render,this);
+ },
+
+ render: function(){
+ this.$el.html(this.template({tank: this.model}));
+ return this;
+ }
+
+});
View
21 app/assets/javascripts/views/tanking_logs/tanking_logs_index.js
@@ -0,0 +1,21 @@
+Station.Views.TankingLogIndex = Backbone.View.extend({
+
+ template: JST['tanking_logs/index'],
+
+ initialize: function(){
+ this.collection.on('reset',this.render,this);
+ this.collection.bind('add', this.appendTank,this);
+ },
+
+ render: function(){
+ this.$el.html(this.template);
+ this.collection.each(this.appendTank,this);
+ return this;
+ },
+
+ appendTank: function(tank){
+ var view = new Station.Views.TankingLog({"model": tank});
+ this.$('#tanklist').append(view.render().el);
+ }
+
+});
View
1 app/assets/stylesheets/application.css
@@ -1,3 +1,4 @@
+
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
View
640 app/assets/stylesheets/custom.css.scss
@@ -0,0 +1,640 @@
+@import "bootstrap";
+
+
+/* mixins, variables, etc. */
+
+
+$grayMediumLight: #eaeaea;
+
+@mixin box_sizing {
+ -moz-box-sizing: border-box;
+ -webkit-box-sizing: border-box;
+ box-sizing: border-box;
+}
+
+/* miscellaneous */
+
+.debug_dump {
+ clear: both;
+ float: left;
+ width: 100%;
+ margin-top: 45px;
+ @include box_sizing;
+}
+
+
+
+
+/* universal */
+
+html {
+ overflow-y: scroll;
+}
+
+body {
+ padding-top: 60px;
+}
+
+section {
+ overflow: auto;
+}
+
+textarea {
+ resize: vertical;
+}
+
+.center {
+ text-align: center;
+ h1 {
+ margin-bottom: 10px;
+ }
+}
+
+
+
+
+/* typography */
+
+h1, h2, h3, h4, h5, h6 {
+ line-height: 1;
+}
+
+h1 {
+ font-size: 3em;
+ letter-spacing: -2px;
+ margin-bottom: 30px;
+ text-align: center;
+}
+
+h2 {
+ font-size: 1.7em;
+ letter-spacing: -1px;
+ margin-bottom: 30px;
+ text-align: center;
+ font-weight: normal;
+ color: $grayLight;
+}
+
+p {
+ font-size: 1.1em;
+ line-height: 1.7em;
+}
+
+
+
+
+/* header */
+
+#logo {
+ float: left;
+ margin-right: 10px;
+ font-size: 1.7em;
+ color: white;
+ text-transform: uppercase;
+ letter-spacing: -1px;
+ padding-top: 9px;
+ font-weight: bold;
+ line-height: 1;
+ &:hover {
+ color: white;
+ text-decoration: none;
+ }
+}
+
+
+
+/* footer */
+
+footer {
+ margin-top: 45px;
+ padding-top: 5px;
+ border-top: 1px solid $grayMediumLight;
+ color: $grayLight;
+ a {
+ color: $gray;
+ &:hover {
+ color: $grayDarker;
+ }
+ }
+ small {
+ float: left;
+ }
+ ul {
+ float: right;
+ list-style: none;
+ li {
+ float: left;
+ margin-left: 10px;
+ }
+ }
+}
+
+
+
+
+/* sidebar */
+
+aside {
+ section {
+ padding: 10px 0;
+ border-top: 1px solid $grayLighter;
+ &:first-child {
+ border: 0;
+ padding-top: 0;
+ }
+ span {
+ display: block;
+ margin-bottom: 3px;
+ line-height: 1;
+ }
+ h1 {
+ font-size: 1.6em;
+ text-align: left;
+ letter-spacing: -1px;
+ margin-bottom: 3px;
+ }
+ }
+}
+
+.gravatar {
+ float: left;
+ margin-right: 10px;
+}
+
+
+/* forms */
+
+input, textarea, select, .uneditable-input {
+ border: 1px solid #bbb;
+ width: 100%;
+ padding: 10px;
+ height: auto;
+ margin-bottom: 15px;
+ @include box_sizing;
+}
+
+#error_explanation {
+ color: #f00;
+ ul {
+ list-style: none;
+ margin: 0 0 18px 0;
+ }
+}
+
+.field_with_errors {
+ @extend .control-group;
+ @extend .error;
+ }
+
+
+ /* Modals */
+ .modal-open .modal .dropdown-menu {
+ z-index: 2050;
+}
+
+.modal-open .modal .dropdown.open {
+ *z-index: 2050;
+}
+
+.modal-open .modal .popover {
+ z-index: 2060;
+}
+
+.modal-open .modal .tooltip {
+ z-index: 2080;
+}
+
+.modal-backdrop {
+ position: fixed;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ left: 0;
+ z-index: 1040;
+ background-color: #000000;
+}
+
+.modal-backdrop.fade {
+ opacity: 0;
+}
+
+.modal-backdrop,
+.modal-backdrop.fade.in {
+ opacity: 0.8;
+ filter: alpha(opacity=80);
+}
+
+.modal {
+ position: fixed;
+ top: 50%;
+ left: 50%;
+ z-index: 1050;
+ width: 560px;
+ margin: -250px 0 0 -280px;
+ overflow: auto;
+ background-color: #ffffff;
+ border: 1px solid #999;
+ border: 1px solid rgba(0, 0, 0, 0.3);
+ *border: 1px solid #999;
+ -webkit-border-radius: 6px;
+ -moz-border-radius: 6px;
+ border-radius: 6px;
+ -webkit-box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3);
+ -moz-box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3);
+ box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3);
+ -webkit-background-clip: padding-box;
+ -moz-background-clip: padding-box;
+ background-clip: padding-box;
+}
+
+.modal.fade {
+ top: -25%;
+ -webkit-transition: opacity 0.3s linear, top 0.3s ease-out;
+ -moz-transition: opacity 0.3s linear, top 0.3s ease-out;
+ -o-transition: opacity 0.3s linear, top 0.3s ease-out;
+ transition: opacity 0.3s linear, top 0.3s ease-out;
+}
+
+.modal.fade.in {
+ top: 50%;
+}
+
+.modal-header {
+ padding: 9px 15px;
+ border-bottom: 1px solid #eee;
+}
+
+.modal-header .close {
+ margin-top: 2px;
+}
+
+.modal-header h3 {
+ margin: 0;
+ line-height: 30px;
+}
+
+.modal-body {
+ max-height: 400px;
+ padding: 15px;
+ overflow-y: auto;
+}
+
+.modal-form {
+ margin-bottom: 0;
+}
+
+.modal-footer {
+ padding: 14px 15px 15px;
+ margin-bottom: 0;
+ text-align: right;
+ background-color: #f5f5f5;
+ border-top: 1px solid #ddd;
+ -webkit-border-radius: 0 0 6px 6px;
+ -moz-border-radius: 0 0 6px 6px;
+ border-radius: 0 0 6px 6px;
+ *zoom: 1;
+ -webkit-box-shadow: inset 0 1px 0 #ffffff;
+ -moz-box-shadow: inset 0 1px 0 #ffffff;
+ box-shadow: inset 0 1px 0 #ffffff;
+}
+
+.modal-footer:before,
+.modal-footer:after {
+ display: table;
+ line-height: 0;
+ content: "";
+}
+
+.modal-footer:after {
+ clear: both;
+}
+
+.modal-footer .btn + .btn {
+ margin-bottom: 0;
+ margin-left: 5px;
+}
+
+.modal-footer .btn-group .btn + .btn {
+ margin-left: -1px;
+}
+
+
+
+/* TABLES */
+table {
+ max-width: 100%;
+ background-color: transparent;
+ border-collapse: collapse;
+ border-spacing: 0;
+}
+
+.table {
+ width: 100%;
+ margin-bottom: 20px;
+}
+
+.table th,
+.table td {
+ padding: 8px;
+ line-height: 20px;
+ text-align: left;
+ vertical-align: top;
+ border-top: 1px solid #dddddd;
+}
+
+.table th {
+ font-weight: bold;
+}
+
+.table thead th {
+ vertical-align: bottom;
+}
+
+.table caption + thead tr:first-child th,
+.table caption + thead tr:first-child td,
+.table colgroup + thead tr:first-child th,
+.table colgroup + thead tr:first-child td,
+.table thead:first-child tr:first-child th,
+.table thead:first-child tr:first-child td {
+ border-top: 0;
+}
+
+.table tbody + tbody {
+ border-top: 2px solid #dddddd;
+}
+
+.table-condensed th,
+.table-condensed td {
+ padding: 4px 5px;
+}
+
+.table-bordered {
+ border: 1px solid #dddddd;
+ border-collapse: separate;
+ *border-collapse: collapse;
+ border-left: 0;
+ -webkit-border-radius: 4px;
+ -moz-border-radius: 4px;
+ border-radius: 4px;
+}
+
+.table-bordered th,
+.table-bordered td {
+ border-left: 1px solid #dddddd;
+}
+
+.table-bordered caption + thead tr:first-child th,
+.table-bordered caption + tbody tr:first-child th,
+.table-bordered caption + tbody tr:first-child td,
+.table-bordered colgroup + thead tr:first-child th,
+.table-bordered colgroup + tbody tr:first-child th,
+.table-bordered colgroup + tbody tr:first-child td,
+.table-bordered thead:first-child tr:first-child th,
+.table-bordered tbody:first-child tr:first-child th,
+.table-bordered tbody:first-child tr:first-child td {
+ border-top: 0;
+}
+
+.table-bordered thead:first-child tr:first-child th:first-child,
+.table-bordered tbody:first-child tr:first-child td:first-child {
+ -webkit-border-top-left-radius: 4px;
+ border-top-left-radius: 4px;
+ -moz-border-radius-topleft: 4px;
+}
+
+.table-bordered thead:first-child tr:first-child th:last-child,
+.table-bordered tbody:first-child tr:first-child td:last-child {
+ -webkit-border-top-right-radius: 4px;
+ border-top-right-radius: 4px;
+ -moz-border-radius-topright: 4px;
+}
+
+.table-bordered thead:last-child tr:last-child th:first-child,
+.table-bordered tbody:last-child tr:last-child td:first-child,
+.table-bordered tfoot:last-child tr:last-child td:first-child {
+ -webkit-border-radius: 0 0 0 4px;
+ -moz-border-radius: 0 0 0 4px;
+ border-radius: 0 0 0 4px;
+ -webkit-border-bottom-left-radius: 4px;
+ border-bottom-left-radius: 4px;
+ -moz-border-radius-bottomleft: 4px;
+}
+
+.table-bordered thead:last-child tr:last-child th:last-child,
+.table-bordered tbody:last-child tr:last-child td:last-child,
+.table-bordered tfoot:last-child tr:last-child td:last-child {
+ -webkit-border-bottom-right-radius: 4px;
+ border-bottom-right-radius: 4px;
+ -moz-border-radius-bottomright: 4px;
+}
+
+.table-bordered caption + thead tr:first-child th:first-child,
+.table-bordered caption + tbody tr:first-child td:first-child,
+.table-bordered colgroup + thead tr:first-child th:first-child,
+.table-bordered colgroup + tbody tr:first-child td:first-child {
+ -webkit-border-top-left-radius: 4px;
+ border-top-left-radius: 4px;
+ -moz-border-radius-topleft: 4px;
+}
+
+.table-bordered caption + thead tr:first-child th:last-child,
+.table-bordered caption + tbody tr:first-child td:last-child,
+.table-bordered colgroup + thead tr:first-child th:last-child,
+.table-bordered colgroup + tbody tr:first-child td:last-child {
+ -webkit-border-top-right-radius: 4px;
+ border-top-right-radius: 4px;
+ -moz-border-radius-topleft: 4px;
+}
+
+.table-striped tbody tr:nth-child(odd) td,
+.table-striped tbody tr:nth-child(odd) th {
+ background-color: #f9f9f9;
+}
+
+.table-hover tbody tr:hover td,
+.table-hover tbody tr:hover th {
+ background-color: #f5f5f5;
+}
+
+table [class*=span],
+.row-fluid table [class*=span] {
+ display: table-cell;
+ float: none;
+ margin-left: 0;
+}
+
+.table .span1 {
+ float: none;
+ width: 44px;
+ margin-left: 0;
+}
+
+.table .span2 {
+ float: none;
+ width: 124px;
+ margin-left: 0;
+}
+
+.table .span3 {
+ float: none;
+ width: 204px;
+ margin-left: 0;
+}
+
+.table .span4 {
+ float: none;
+ width: 284px;
+ margin-left: 0;
+}
+
+.table .span5 {
+ float: none;
+ width: 364px;
+ margin-left: 0;
+}
+
+.table .span6 {
+ float: none;
+ width: 444px;
+ margin-left: 0;
+}
+
+.table .span7 {
+ float: none;
+ width: 524px;
+ margin-left: 0;
+}
+
+.table .span8 {
+ float: none;
+ width: 604px;
+ margin-left: 0;
+}
+
+.table .span9 {
+ float: none;
+ width: 684px;
+ margin-left: 0;
+}
+
+.table .span10 {
+ float: none;
+ width: 764px;
+ margin-left: 0;
+}
+
+.table .span11 {
+ float: none;
+ width: 844px;
+ margin-left: 0;
+}
+
+.table .span12 {
+ float: none;
+ width: 924px;
+ margin-left: 0;
+}
+
+.table .span13 {
+ float: none;
+ width: 1004px;
+ margin-left: 0;
+}
+
+.table .span14 {
+ float: none;
+ width: 1084px;
+ margin-left: 0;
+}
+
+.table .span15 {
+ float: none;
+ width: 1164px;
+ margin-left: 0;
+}
+
+.table .span16 {
+ float: none;
+ width: 1244px;
+ margin-left: 0;
+}
+
+.table .span17 {
+ float: none;
+ width: 1324px;
+ margin-left: 0;
+}
+
+.table .span18 {
+ float: none;
+ width: 1404px;
+ margin-left: 0;
+}
+
+.table .span19 {
+ float: none;
+ width: 1484px;
+ margin-left: 0;
+}
+
+.table .span20 {
+ float: none;
+ width: 1564px;
+ margin-left: 0;
+}
+
+.table .span21 {
+ float: none;
+ width: 1644px;
+ margin-left: 0;
+}
+
+.table .span22 {
+ float: none;
+ width: 1724px;
+ margin-left: 0;
+}
+
+.table .span23 {
+ float: none;
+ width: 1804px;
+ margin-left: 0;
+}
+
+.table .span24 {
+ float: none;
+ width: 1884px;
+ margin-left: 0;
+}
+
+.table tbody tr.success td {
+ background-color: #dff0d8;
+}
+
+.table tbody tr.error td {
+ background-color: #f2dede;
+}
+
+.table tbody tr.warning td {
+ background-color: #fcf8e3;
+}
+
+.table tbody tr.info td {
+ background-color: #d9edf7;
+}
+
+.table-hover tbody tr.success:hover td {
+ background-color: #d0e9c6;
+}
+
+.table-hover tbody tr.error:hover td {
+ background-color: #ebcccc;
+}
+
+.table-hover tbody tr.warning:hover td {
+ background-color: #faf2cc;
+}
+
+.table-hover tbody tr.info:hover td {
+ background-color: #c4e3f3;
+}
View
3 app/assets/stylesheets/home.css.scss
@@ -0,0 +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/
View
10 app/assets/templates/cars/car.jst.eco
@@ -0,0 +1,10 @@
+<td><%= @car.get('brand') %></td>
+ <td><%= @car.get('model') %></td>
+ <td><%= @car.get('color') %></td>
+ <td><%= @car.get('year') %></td>
+
+ <td><a href="#/<%= @car.get('car_id') %>/tank"><img src="http://icons.iconarchive.com/icons/custom-icon-design/pretty-office-8/16/Gas-pump-icon.png" /></a></td>
+
+ <td><a href="#/<%= @car.get('id') %>/edit"><img src="http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/16/Apps-accessories-text-editor-icon.png" /></a></td>
+
+ <td><a href="#" class="destroy"><img src="http://icons.iconarchive.com/icons/ramotion/custom-mac-os/16/Trash-empty-icon.png" /></a></td>
View
20 app/assets/templates/cars/edit.jst.eco
@@ -0,0 +1,20 @@
+<h1> Edit Cars </h1>
+<div class="row" >
+ <div class="well span3 offset4" >
+
+ <form >
+
+ Brand:<input type="text" name="brand" id="edit_car_brand" value="<%= @car.get('brand') %>">
+ Model:<input type="text" name="model" id="edit_car_model" value="<%= @car.get('model') %>">
+ Color:<input type="text" name="color" id="edit_car_color" value="<%= @car.get('color') %>">
+ Year:<input type="text" name="year" id="edit_car_year" value="<%= @car.get('year') %>">
+
+ <br><br>
+
+ <input id="edit_car" type="submit" value="Save" class= "btn btn-success">
+ <a class="btn btn-success" id="back_car" href="#">Back</a>
+
+ </form>
+
+ </div>
+</div>
View
6 app/assets/templates/cars/flash.jst.eco
@@ -0,0 +1,6 @@
+<div class='alert alert-error' data-alert='alert'>
+ <a class='close'>x</a>
+ <p>"<%= @flashText %>"</p>
+</div>
+
+ <%setTimeout("$('.alert').slideUp('slow')",5000);%>
View
16 app/assets/templates/cars/index.jst.eco
@@ -0,0 +1,16 @@
+<h1> Cars Management </h1>
+
+<a class="btn btn-success" id="add_new_car" href="#/new">Add Car</a>
+<br><br>
+
+<table id = "carlist" class="table table-striped table-bordered table-condensed table-hover" >
+ <tr>
+ <th>Brand</th>
+ <th>Model</th>
+ <th>Color</th>
+ <th>Year</th>
+ <th>Tanking</th>
+ <th>Edit</th>
+ <th>Delete</th>
+ </tr>
+</table>
View
20 app/assets/templates/cars/new.jst.eco
@@ -0,0 +1,20 @@
+<h1> Add Cars </h1>
+<div class="row" >
+ <div class="well span3 offset4" >
+
+ <form>
+
+ Brand:<input type="text" name="brand" id="new_car_brand">
+ Model:<input type="text" name="model" id="new_car_model">
+ Color:<input type="text" name="color" id="new_car_color">
+ Year:<input type="text" name="year" id="new_car_year">
+
+ <br><br>
+
+ <input id="new_car" type="submit" value="Save" class= "btn btn-success">
+ <a class="btn btn-success" id="back_car" href="#">Back</a>
+
+ </form>
+
+ </div>
+</div>
View
17 app/assets/templates/gas/edit.jst.eco
@@ -0,0 +1,17 @@
+<h1> Edit Gas Stations </h1>
+<div class="row" >
+ <div class="well span3 offset4" >
+
+ <form>
+
+ Name:<input type="text" name="name" id="edit_gas_name" value="<%= @gas.get('name') %>">
+
+ <br><br>
+
+ <input id="edit_gas" type="submit" value="Save" class= "btn btn-success">
+ <a class="btn btn-success" id="back_gas" href="#">Back</a>
+
+ </form>
+
+ </div>
+</div>
View
5 app/assets/templates/gas/gas.jst.eco
@@ -0,0 +1,5 @@
+<td><%= @gas.get('name') %></td>
+
+<td><a href="#/<%= @gas.get('id') %>/edit"><img src="http://icons.iconarchive.com/icons/oxygen-icons.org/oxygen/16/Apps-accessories-text-editor-icon.png" /></a></td>
+
+<td><a href="#" class="destroy"><img src="http://icons.iconarchive.com/icons/ramotion/custom-mac-os/16/Trash-empty-icon.png" /></a></td>
View
12 app/assets/templates/gas/index.jst.eco
@@ -0,0 +1,12 @@
+<h1> Gas Stations Management </h1>
+
+<a class="btn btn-success" id="add_new_gas" href="#/new">Add Gas Station</a>
+<br><br>
+
+<table id = "gaslist" class="table table-striped table-bordered table-condensed table-hover" >
+ <tr>
+ <th>Name</th>
+ <th>Edit</th>
+ <th>Delete</th>
+ </tr>
+</table>
View
17 app/assets/templates/gas/new.jst.eco
@@ -0,0 +1,17 @@
+<h1> Add Gas Stations </h1>
+<div class="row" >
+ <div class="well span3 offset4" >
+
+ <form>
+
+ Name:<input type="text" name="name" id="new_gas_name">
+
+ <br><br>
+
+ <input id="new_gas" type="submit" value="Save" class= "btn btn-success">
+ <a class="btn btn-success" id="back_gas" href="#">Back</a>
+
+ </form>
+
+ </div>
+</div>
View
12 app/assets/templates/tanking_logs/index.jst.eco
@@ -0,0 +1,12 @@
+<h1> Tanking Logs Management </h1>
+
+<table id = "tanklist" class="table table-striped table-bordered table-condensed table-hover" >
+ <tr>
+ <th>Gas Station</th>
+ <th>Car</th>
+ <th>Date</th>
+ <th>Gallon</th>
+ <th>Km</th>
+ <th>Cost</th>
+ </tr>
+</table>
View
0 app/assets/templates/tanking_logs/new.jst.eco
No changes.
View
6 app/assets/templates/tanking_logs/tanking.jst.eco
@@ -0,0 +1,6 @@
+<td><%= @tank.get('gas_station') %></td>
+ <td><%= @tank.get('car') %></td>
+ <td><%= @tank.get('date') %></td>
+ <td><%= @tank.get('gallon') %></td>
+ <td><%= @tank.get('km') %></td>
+ <td><%= @tank.get('cost') %></td>
View
102 app/controllers/cars_controller.rb
@@ -3,43 +3,113 @@ class CarsController < ApplicationController
before_filter :get_car, except: [:index,:new,:create]
def index
- @cars = Car.all
+
+ if user_signed_in?
+
+ @user = current_user
+ @cars = Car.where(:user_id => @user.id)
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @cars }
+ end
+
+ else
+
+ flash.now[:error] = "You must be logged in to access this section, please sign in."
+ redirect_to new_user_session_path
+
end
- def new
- @car = Car.new
+end
+
+
+def new
+
+ @car = Car.new
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @car }
end
- def create
- @car = Car.new(params[:car])
- if @car.save
- redirect_to @car
- else
- render :new
+end
+
+
+def create
+
+ @car = Car.new(params[:car])
+ @user = current_user.id
+ @car.user_id = @user
+
+ if @car.save
+ respond_to do |format|
+ format.html { redirect_to cars_path, success: 'Car was successfully created.' }
+ format.json { render json: @car, status: :created, location: @car }
+ end
+
+ else
+ respond_to do |format|
+ format.html { render action: "new", notice: 'Car was not successfully created.' }
+ format.json { render json: @car.errors, status: :unprocessable_entity }
+ end
end
+
end
+
def show
- @car
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @car }
+ end
+
end
+
def edit
- @car
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @car }
+ end
+
end
+
def update
+
if @car.update_attributes(params[:car])
- redirect_to @car
- else
- render :edit
-end
+
+ respond_to do |format|
+ format.html { redirect_to cars_path }
+ format.json { head :no_content }
+ end
+
+ else
+ respond_to do |format|
+ format.html { render :edit }
+ format.json { render json: @car.errors, status: :unprocessable_entity }
+ end
+
+ end
+
end
+
def destroy
+
@car.destroy
- redirect_to cars_path
+ respond_to do |format|
+ format.html { redirect_to cars_path }
+ format.json { head :no_content }
+ end
+
end
+
+
private
def get_car
View
102 app/controllers/gas_stations_controller.rb
@@ -2,49 +2,97 @@ class GasStationsController < ApplicationController
before_filter :get_gstation, except: [:index,:new,:create]
-
def index
- @gas_stations = GasStation.all
+
+ if user_signed_in?
+ @gas_stations = GasStation.all
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @gas_stations }
+ end
+
+ else
+ flash.now[:error] = "You must be logged in to access this section, please sign in."
+ redirect_to new_user_session_path
+ end
+
end
def new
@gas_station = GasStation.new
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @gas_station }
+ end
+
end
def create
@gas_station = GasStation.new(params[:gas_station])
+
if @gas_station.save
- redirect_to @gas_station
- else
- render :new
+ respond_to do |format|
+ format.html { redirect_to gas_stations_path, notice: 'Gas Station was successfully created.' }
+ format.json { render json: @gas_station, status: :created, location: @gas_station }
+ end
+
+ else
+ respond_to do |format|
+ format.html { render action: "new" }
+ format.json { render json: @gas_station.errors, status: :unprocessable_entity }
+ end
+ end
+
end
-end
-def show
- @gas_station
-end
+ def show
+ respond_to do |format|
+ format.html
+ format.json { render json: @gas_station }
+ end
+ end
-def edit
- @gas_station
-end
+ def edit
+ respond_to do |format|
+ format.html
+ format.json { render json: @gas_station }
+ end
+ end
-def update
- if @gas_station.update_attributes(params[:gas_station])
- redirect_to @gas_station
- else
- render :edit
-end
-end
+ def update
-def destroy
- @gas_station.destroy
- redirect_to gas_stations_path
-end
+ if @gas_station.update_attributes(params[:gas_station])
-private
+ respond_to do |format|
+ format.html { redirect_to gas_stations_path }
+ format.json { head :no_content }
+ end
-def get_gstation
- @gas_station = GasStation.find(params[:id])
-end
+ else
+
+ respond_to do |format|
+ format.html { render :edit }
+ format.json { render json: @gas_station.errors, status: :unprocessable_entity }
+ end
+
+ end
+
+ end
+
+ def destroy
+ @gas_station.destroy
+ respond_to do |format|
+ format.html { redirect_to gas_stations_path }
+ format.json { head :no_content }
+ end
+ end
+
+ private
+
+ def get_gstation
+ @gas_station = GasStation.find(params[:id])
+ end
end
View
4 app/controllers/home_controller.rb
@@ -0,0 +1,4 @@
+class HomeController < ApplicationController
+ def index
+ end
+end
View
113 app/controllers/tanking_logs_controller.rb
@@ -3,47 +3,108 @@ class TankingLogsController < ApplicationController
before_filter :get_tank, except: [:index,:new,:create]
def index
- @tanking_logs = TankingLog.all
+
+ if user_signed_in?
+ @tanking_logs = TankingLog.where(:user.user_id => current_user.id)
+
+ @tanking_logs.each do |t|
+ t.merge( :car => t.car)
+ end
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @tanking_logs }
+ end
+
+ else
+ flash.now[:error] = "You must be logged in to access this section, please sign in."
+ redirect_to new_user_session_path
+ end
+
end
+
def new
@tanking_log = TankingLog.new
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @tanking_log }
+ end
+
end
+
def create
@tanking_log = TankingLog.new(params[:tanking_log])
+
if @tanking_log.save
- redirect_to @tanking_log
- else
- render :new
+ respond_to do |format|
+ format.html { redirect_to tanking_logs_path, notice: 'Tanking logs was successfully created.' }
+ format.json { render json: @tanking_log, status: :created, location: @tanking_log }
+ end
+
+ else
+ respond_to do |format|
+ format.html { render action: "new" }
+ format.json { render json: @tanking_log.errors, status: :unprocessable_entity }
+ end
+ end
+
end
-end
-def show
- @tanking_log
-end
-def edit
- @tanking_log
-end
+ def show
+ respond_to do |format|
+ format.html
+ format.json { render json: @tanking_log }
+ end
+ end
-def update
- if @tanking_log.update_attributes(params[:tanking_log])
- redirect_to @tanking_log
- else
- render :edit
-end
-end
-def destroy
- @tanking_log.destroy
- redirect_to tanking_logs_path
-end
+ def edit
+ respond_to do |format|
+ format.html
+ format.json { render json: @tanking_log }
+ end
+ end
-private
-def get_tank
- @tanking_log = TankingLog.find(params[:id])
-end
+ def update
+
+ if @tanking_log.update_attributes(params[:tanking_log])
+
+ respond_to do |format|
+ format.html { redirect_to tanking_logs_path }
+ format.json { head :no_content }
+ end
+
+ else
+
+ respond_to do |format|
+ format.html { render :edit }
+ format.json { render json: @tanking_log.errors, status: :unprocessable_entity }
+ end
+
+ end
+
+ end
+
+
+ def destroy
+ @tanking_log.destroy
+ respond_to do |format|
+ format.html { redirect_to tanking_logs_path }
+ format.json { head :no_content }
+ end
+ end
+
+
+
+ private
+
+ def get_tank
+ @tanking_log = TankingLog.find(params[:id])
+ end
end
View
5 app/helpers/application_helper.rb
@@ -1,2 +1,7 @@
module ApplicationHelper
+
+def body_class
+ controller.controller_name
+end
+
end
View
2 app/helpers/home_helper.rb
@@ -0,0 +1,2 @@
+module HomeHelper
+end
View
4 app/models/car.rb
@@ -4,6 +4,8 @@ class Car < ActiveRecord::Base
has_many :tanking_logs, :dependent => :destroy
attr_accessible :brand, :color, :model, :user_id, :year
- validates_presence_of :brand, :color , :model , :year
+ validates_presence_of :brand, :color , :model , :year, :user_id
+ validates :year, :numericality => true
+
end
View
2 app/models/tanking_log.rb
@@ -2,6 +2,7 @@ class TankingLog < ActiveRecord::Base
belongs_to :gas_station
belongs_to :car
+ has_one :user, through: :car
attr_accessible :car_id, :cost, :date, :gallon, :gas_station_id, :km
@@ -11,4 +12,5 @@ class TankingLog < ActiveRecord::Base
validates :cost, numericality: {greater_than: 1.000}
validates :gallon, :km, numericality: {greater_than: 0}
+
end
View
4 app/models/user.rb
@@ -1,10 +1,8 @@
class User < ActiveRecord::Base
- # Include default devise modules. Others available are:
- # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
+
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
- # Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
has_many :cars, :dependent => :destroy
View
BIN app/views/.DS_Store
Binary file not shown.
View
BIN app/views/cars/.DS_Store
Binary file not shown.
View
10 app/views/cars/index.html.erb
@@ -1,2 +1,8 @@
-<h1>Cars#index</h1>
-<p>Find me in app/views/cars/index.html.erb</p>
+<div id='container_cars'></div>
+
+<script type="text/javascript">
+  $(function() {
+    window.router = new Station.Routers.Cars();
+    Backbone.history.start();
+  });
+</script>
View
39 app/views/devise/registrations/edit.html.erb
@@ -1,25 +1,32 @@
-<h2>Edit <%= resource_name.to_s.humanize %></h2>
+<div class="row" >
+ <div class="well span3 offset4" >
+ <h2>Edit <%= resource_name.to_s.humanize %></h2>
-<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
- <%= devise_error_messages! %>
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
+ <%= devise_error_messages! %>
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
+ <div><%= f.label :name %><br />
+ <%= f.text_field :name %></div>
- <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
- <%= f.password_field :password, :autocomplete => "off" %></div>
+ <div><%= f.label :email %><br />
+ <%= f.email_field :email %></div>
- <div><%= f.label :password_confirmation %><br />
- <%= f.password_field :password_confirmation %></div>
+ <div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
+ <%= f.password_field :password, :autocomplete => "off" %></div>
- <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
- <%= f.password_field :current_password %></div>
+ <div><%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %></div>
- <div><%= f.submit "Update" %></div>
-<% end %>
+ <div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
+ <%= f.password_field :current_password %></div>
-<h3>Cancel my account</h3>
+ <div><%= f.submit "Update" %></div>
+ <% end %>
-<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
+ <h3>Cancel my account</h3>
-<%= link_to "Back", :back %>
+ <p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
+
+ <%= link_to "Back", :back %>
+ </div>
+ </div>
View
31 app/views/devise/registrations/new.html.erb
@@ -1,18 +1,25 @@
-<h2>Sign up</h2>
+<div class="row" >
+ <div class="well span3 offset4" >
+ <h2>Sign up</h2>
-<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
- <%= devise_error_messages! %>
+ <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
+ <%= devise_error_messages! %>
- <div><%= f.label :email %><br />
- <%= f.email_field :email %></div>
+ <div><%= f.label :name %><br />
+ <%= f.text_field :name %></div>
- <div><%= f.label :password %><br />
- <%= f.password_field :password %></div>
+ <