Skip to content

Commit

Permalink
templates cached, implemented filter
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosCondor committed Jan 25, 2015
1 parent e68b922 commit 2de5ef0
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 15 deletions.
1 change: 1 addition & 0 deletions Bowerfile
@@ -1,2 +1,3 @@
asset 'angular'
asset 'bootstrap-sass-official'
asset 'angular-route'
4 changes: 3 additions & 1 deletion Gemfile
Expand Up @@ -31,7 +31,10 @@ gem 'sdoc', '~> 0.4.0', group: :doc

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'bower-rails'
gem 'angular-rails-templates'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
Expand All @@ -42,4 +45,3 @@ group :development, :test do
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end

5 changes: 5 additions & 0 deletions Gemfile.lock
Expand Up @@ -36,6 +36,10 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
angular-rails-templates (0.1.3)
railties (>= 3.1)
sprockets
tilt
arel (6.0.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
Expand Down Expand Up @@ -151,6 +155,7 @@ PLATFORMS
ruby

DEPENDENCIES
angular-rails-templates
bower-rails
byebug
coffee-rails (~> 4.1.0)
Expand Down
43 changes: 42 additions & 1 deletion app/assets/javascripts/app.coffee
@@ -1,3 +1,44 @@
receta = angular.module('receta', [
receta = angular.module('receta',[
'templates',
'ngRoute',
'controllers',
])

receta.config([ '$routeProvider',
($routeProvider)->
$routeProvider
.when('/',
templateUrl: "index.html"
controller: 'RecipesController'
)
])

recipes = [
{
id: 1
name: 'Baked Potato w/ Cheese'
},
{
id: 2
name: 'Garlic Mashed Potatoes',
},
{
id: 3
name: 'Potatoes Au Gratin',
},
{
id: 4
name: 'Baked Brussel Sprouts',
},
]
controllers = angular.module('controllers',[])
controllers.controller("RecipesController", [ '$scope', '$routeParams', '$location',
($scope,$routeParams,$location)->
$scope.search = (keywords)-> $location.path("/").search('keywords',keywords)

if $routeParams.keywords
keywords = $routeParams.keywords.toLowerCase()
$scope.recipes = recipes.filter (recipe)-> recipe.name.toLowerCase().indexOf(keywords) != -1
else
$scope.recipes = []
])
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -14,4 +14,6 @@
//= require jquery_ujs
//= require turbolinks
//= require angular/angular
//= require angular-route/angular-route
//= require angular-rails-templates
//= require_tree .
32 changes: 32 additions & 0 deletions app/assets/javascripts/templates/index.html
@@ -0,0 +1,32 @@
<header class="row">
<h1 class="text-center col-md-6 col-md-offset-3">Find Recipes</h1>
</header>
<section class="row">
<form>
<div class="form-group col-md-6 col-md-offset-3">
<label for="keywords" class="sr-only">Keywords</label>
<input ng-model="keywords" name="keywords" type="text" autofocus class="form-control" placeholder="Recipe name, e.g. Baked Potato">

</div>
<div class="form-group col-md-6 col-md-offset-3 text-center">
<button ng-click="search(keywords)" class="btn btn-primary btn-lg">Search</button>

</div>
</form>
</section>
<hr>
<section class="row" ng-if="recipes">

<h1 class="text-center h2">Results</h1>
<ul class="list-unstyled">
<li ng-repeat="recipe in recipes">
<section class="well col-md-6 col-md-offset-3">
<h1 class="h3 col-md-6 text-right" style="margin-top: 0"><a href="#">{{recipe.name}}</a></h1>
<div class="col-md-6">
<button class="btn btn-info">Edit</button>
<button class="btn btn-danger">Delete</button>
</div>
</section>
</li>
</ul>
</section>
15 changes: 3 additions & 12 deletions app/views/home/index.html.erb
@@ -1,14 +1,5 @@
<div class="container-fluid" ng-app="receta">
<div class="panel panel-success">
<div class="panel-heading">
<h1 ng-if="name">Hello, {{name}}</h1>
</div>
<div class="panel-body">
<form class="form-inline">
<div class="form-group">
<input class="form-control" type="text" placeholder="Enter your name" autofocus ng-model="name">
</div>
</form>
</div>
<div ng-app="receta">
<div class="view-container">
<div ng-view class="view-frame animate-view"></div>
</div>
</div>
3 changes: 2 additions & 1 deletion vendor/assets/bower.json
Expand Up @@ -2,6 +2,7 @@
"name": "dsl-generated dependencies",
"dependencies": {
"angular": "latest",
"bootstrap-sass-official": "latest"
"bootstrap-sass-official": "latest",
"angular-route": "latest"
}
}

0 comments on commit 2de5ef0

Please sign in to comment.