Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit a7592c3

Browse files
committed
Merge pull request #13 from pavelgj/master
Added Chapter_07 on production deployment
2 parents f149eef + edef858 commit a7592c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1558
-325
lines changed

Chapter_03/lib/recipe_book.dart

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
library recipe_book_controller;
2+
3+
import 'package:angular/angular.dart';
4+
5+
@NgController(
6+
selector: '[recipe-book]',
7+
publishAs: 'ctrl')
8+
class RecipeBookController {
9+
10+
List recipes;
11+
12+
RecipeBookController() {
13+
recipes = _loadData();
14+
}
15+
16+
Recipe selectedRecipe;
17+
18+
void selectRecipe(Recipe recipe) {
19+
selectedRecipe = recipe;
20+
}
21+
22+
List<Recipe> _loadData() {
23+
return [
24+
new Recipe('My Appetizer','Appetizers',
25+
["Ingredient 1", "Ingredient 2"],
26+
"Some Directions", 1),
27+
new Recipe('My Salad','Salads',
28+
["Ingredient 1", "Ingredient 2"],
29+
"Some Directions", 3),
30+
new Recipe('My Soup','Soups',
31+
["Ingredient 1", "Ingredient 2"],
32+
"Some Directions", 4),
33+
new Recipe('My Main Dish','Main Dishes',
34+
["Ingredient 1", "Ingredient 2"],
35+
"Some Directions", 2),
36+
new Recipe('My Side Dish','Side Dishes',
37+
["Ingredient 1", "Ingredient 2"],
38+
"Some Directions", 3),
39+
new Recipe('My Awesome Dessert','Desserts',
40+
["Ingredient 1", "Ingredient 2"],
41+
"Some Directions", 5),
42+
new Recipe('My So-So Dessert','Desserts',
43+
["Ingredient 1", "Ingredient 2"],
44+
"Some Directions", 3),
45+
];
46+
}
47+
}
48+
49+
class Recipe {
50+
String name;
51+
String category;
52+
List<String> ingredients;
53+
String directions;
54+
int rating;
55+
56+
Recipe(this.name, this.category, this.ingredients, this.directions,
57+
this.rating);
58+
}

Chapter_03/web/main.dart

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,7 @@ import 'package:di/di.dart';
55
import 'package:perf_api/perf_api.dart';
66

77
import 'package:angular_dart_demo/rating/rating_component.dart';
8-
9-
@NgController(
10-
selector: '[recipe-book]',
11-
publishAs: 'ctrl')
12-
class RecipeBookController {
13-
14-
List recipes;
15-
16-
RecipeBookController() {
17-
recipes = _loadData();
18-
}
19-
20-
Recipe selectedRecipe;
21-
22-
void selectRecipe(Recipe recipe) {
23-
selectedRecipe = recipe;
24-
}
25-
26-
List<Recipe> _loadData() {
27-
return [
28-
new Recipe('My Appetizer','Appetizers',
29-
["Ingredient 1", "Ingredient 2"],
30-
"Some Directions", 1),
31-
new Recipe('My Salad','Salads',
32-
["Ingredient 1", "Ingredient 2"],
33-
"Some Directions", 3),
34-
new Recipe('My Soup','Soups',
35-
["Ingredient 1", "Ingredient 2"],
36-
"Some Directions", 4),
37-
new Recipe('My Main Dish','Main Dishes',
38-
["Ingredient 1", "Ingredient 2"],
39-
"Some Directions", 2),
40-
new Recipe('My Side Dish','Side Dishes',
41-
["Ingredient 1", "Ingredient 2"],
42-
"Some Directions", 3),
43-
new Recipe('My Awesome Dessert','Desserts',
44-
["Ingredient 1", "Ingredient 2"],
45-
"Some Directions", 5),
46-
new Recipe('My So-So Dessert','Desserts',
47-
["Ingredient 1", "Ingredient 2"],
48-
"Some Directions", 3),
49-
];
50-
}
51-
}
52-
53-
class Recipe {
54-
String name;
55-
String category;
56-
List<String> ingredients;
57-
String directions;
58-
int rating;
59-
60-
Recipe(this.name, this.category, this.ingredients, this.directions,
61-
this.rating);
62-
}
8+
import 'package:angular_dart_demo/recipe_book.dart';
639

6410
class MyAppModule extends Module {
6511
MyAppModule() {

Chapter_04/lib/recipe_book.dart

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
library recipe_book_controller;
2+
3+
import 'package:angular/angular.dart';
4+
5+
import 'tooltip/tooltip_directive.dart';
6+
7+
@NgController(
8+
selector: '[recipe-book]',
9+
publishAs: 'ctrl')
10+
class RecipeBookController {
11+
12+
List recipes;
13+
14+
RecipeBookController() {
15+
recipes = _loadData();
16+
}
17+
18+
Recipe selectedRecipe;
19+
20+
void selectRecipe(Recipe recipe) {
21+
selectedRecipe = recipe;
22+
}
23+
24+
// Tooltip
25+
static final tooltip = new Expando<TooltipModel>();
26+
TooltipModel tooltipForRecipe(Recipe recipe) {
27+
if (tooltip[recipe] == null) {
28+
tooltip[recipe] = new TooltipModel(recipe.imgUrl,
29+
"I don't have a picture of these recipes, "
30+
"so here's one of my cat instead!",
31+
80);
32+
}
33+
return tooltip[recipe]; // recipe.tooltip
34+
}
35+
36+
List<Recipe> _loadData() {
37+
return [
38+
new Recipe('My Appetizer','Appetizers',
39+
["Ingredient 1", "Ingredient 2"],
40+
"Some Directions", 1, 'fonzie1.jpg'),
41+
new Recipe('My Salad','Salads',
42+
["Ingredient 1", "Ingredient 2"],
43+
"Some Directions", 3, 'fonzie2.jpg'),
44+
new Recipe('My Soup','Soups',
45+
["Ingredient 1", "Ingredient 2"],
46+
"Some Directions", 4, 'fonzie1.jpg'),
47+
new Recipe('My Main Dish','Main Dishes',
48+
["Ingredient 1", "Ingredient 2"],
49+
"Some Directions", 2, 'fonzie2.jpg'),
50+
new Recipe('My Side Dish','Side Dishes',
51+
["Ingredient 1", "Ingredient 2"],
52+
"Some Directions", 3, 'fonzie1.jpg'),
53+
new Recipe('My Awesome Dessert','Desserts',
54+
["Ingredient 1", "Ingredient 2"],
55+
"Some Directions", 5, 'fonzie2.jpg'),
56+
new Recipe('My So-So Dessert','Desserts',
57+
["Ingredient 1", "Ingredient 2"],
58+
"Some Directions", 3, 'fonzie1.jpg'),
59+
];
60+
}
61+
}
62+
63+
class Recipe {
64+
String name;
65+
String category;
66+
List<String> ingredients;
67+
String directions;
68+
int rating;
69+
String imgUrl;
70+
71+
Recipe(this.name, this.category, this.ingredients, this.directions,
72+
this.rating, this.imgUrl);
73+
}

Chapter_04/web/main.dart

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,77 +4,10 @@ import 'package:angular/angular.dart';
44
import 'package:di/di.dart';
55
import 'package:perf_api/perf_api.dart';
66

7+
import 'package:angular_dart_demo/recipe_book.dart';
78
import 'package:angular_dart_demo/rating/rating_component.dart';
89
import 'package:angular_dart_demo/tooltip/tooltip_directive.dart';
910

10-
@NgController(
11-
selector: '[recipe-book]',
12-
publishAs: 'ctrl')
13-
class RecipeBookController {
14-
15-
List recipes;
16-
17-
RecipeBookController() {
18-
recipes = _loadData();
19-
}
20-
21-
Recipe selectedRecipe;
22-
23-
void selectRecipe(Recipe recipe) {
24-
selectedRecipe = recipe;
25-
}
26-
27-
// Tooltip
28-
static final tooltip = new Expando<TooltipModel>();
29-
TooltipModel tooltipForRecipe(Recipe recipe) {
30-
if (tooltip[recipe] == null) {
31-
tooltip[recipe] = new TooltipModel(recipe.imgUrl,
32-
"I don't have a picture of these recipes, "
33-
"so here's one of my cat instead!",
34-
80);
35-
}
36-
return tooltip[recipe]; // recipe.tooltip
37-
}
38-
39-
List<Recipe> _loadData() {
40-
return [
41-
new Recipe('My Appetizer','Appetizers',
42-
["Ingredient 1", "Ingredient 2"],
43-
"Some Directions", 1, 'fonzie1.jpg'),
44-
new Recipe('My Salad','Salads',
45-
["Ingredient 1", "Ingredient 2"],
46-
"Some Directions", 3, 'fonzie2.jpg'),
47-
new Recipe('My Soup','Soups',
48-
["Ingredient 1", "Ingredient 2"],
49-
"Some Directions", 4, 'fonzie1.jpg'),
50-
new Recipe('My Main Dish','Main Dishes',
51-
["Ingredient 1", "Ingredient 2"],
52-
"Some Directions", 2, 'fonzie2.jpg'),
53-
new Recipe('My Side Dish','Side Dishes',
54-
["Ingredient 1", "Ingredient 2"],
55-
"Some Directions", 3, 'fonzie1.jpg'),
56-
new Recipe('My Awesome Dessert','Desserts',
57-
["Ingredient 1", "Ingredient 2"],
58-
"Some Directions", 5, 'fonzie2.jpg'),
59-
new Recipe('My So-So Dessert','Desserts',
60-
["Ingredient 1", "Ingredient 2"],
61-
"Some Directions", 3, 'fonzie1.jpg'),
62-
];
63-
}
64-
}
65-
66-
class Recipe {
67-
String name;
68-
String category;
69-
List<String> ingredients;
70-
String directions;
71-
int rating;
72-
String imgUrl;
73-
74-
Recipe(this.name, this.category, this.ingredients, this.directions,
75-
this.rating, this.imgUrl);
76-
}
77-
7811
class MyAppModule extends Module {
7912
MyAppModule() {
8013
type(RecipeBookController);

Chapter_06/web/filter/category_filter.dart renamed to Chapter_05/lib/filter/category_filter.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
part of recipe_book;
1+
library category_filter;
2+
3+
import 'package:angular/angular.dart';
24

35
@NgFilter(name: 'categoryfilter')
46
class CategoryFilter {
@@ -13,4 +15,3 @@ class CategoryFilter {
1315
}
1416
}
1517
}
16-

Chapter_05/web/recipe.dart renamed to Chapter_05/lib/recipe.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
part of recipe_book;
1+
library recipe;
2+
3+
import 'dart:convert';
24

35
class Recipe {
46
String id;

Chapter_05/lib/recipe_book.dart

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
library recipe_book_controller;
2+
3+
import 'package:angular/angular.dart';
4+
5+
import 'recipe.dart';
6+
import 'tooltip/tooltip_directive.dart';
7+
8+
@NgController(
9+
selector: '[recipe-book]',
10+
publishAs: 'ctrl')
11+
class RecipeBookController {
12+
13+
static const String LOADING_MESSAGE = "Loading recipe book...";
14+
static const String ERROR_MESSAGE = """Sorry! The cook stepped out of the
15+
kitchen and took the recipe book with him!""";
16+
17+
Http _http;
18+
19+
// Determine the initial load state of the app
20+
String message = LOADING_MESSAGE;
21+
bool recipesLoaded = false;
22+
bool categoriesLoaded = false;
23+
24+
// Data objects that are loaded from the server side via json
25+
List categories = [];
26+
List<Recipe> recipes = [];
27+
28+
// Filter box
29+
Map<String, bool> categoryFilterMap = {};
30+
String nameFilterString = "";
31+
32+
RecipeBookController(Http this._http) {
33+
_loadData();
34+
}
35+
36+
Recipe selectedRecipe;
37+
38+
void selectRecipe(Recipe recipe) {
39+
selectedRecipe = recipe;
40+
}
41+
42+
// Tooltip
43+
static final tooltip = new Expando<TooltipModel>();
44+
TooltipModel tooltipForRecipe(Recipe recipe) {
45+
if (tooltip[recipe] == null) {
46+
tooltip[recipe] = new TooltipModel(recipe.imgUrl,
47+
"I don't have a picture of these recipes, "
48+
"so here's one of my cat instead!",
49+
80);
50+
}
51+
return tooltip[recipe]; // recipe.tooltip
52+
}
53+
54+
void clearFilters() {
55+
categoryFilterMap.keys.forEach((f) => categoryFilterMap[f] = false);
56+
nameFilterString = "";
57+
}
58+
59+
void _loadData() {
60+
recipesLoaded = false;
61+
categoriesLoaded = false;
62+
_http.get('recipes.json')
63+
.then((HttpResponse response) {
64+
print(response);
65+
for (Map recipe in response.data) {
66+
recipes.add(new Recipe.fromJsonMap(recipe));
67+
}
68+
recipesLoaded = true;
69+
},
70+
onError: (Object obj) {
71+
print(obj);
72+
recipesLoaded = false;
73+
message = ERROR_MESSAGE;
74+
});
75+
76+
_http.get('categories.json')
77+
.then((HttpResponse response) {
78+
print(response);
79+
for (String category in response.data) {
80+
categories.add(category);
81+
categoryFilterMap[category] = false;
82+
}
83+
categoriesLoaded = true;
84+
},
85+
onError: (Object obj) {
86+
print(obj);
87+
categoriesLoaded = false;
88+
message = ERROR_MESSAGE;
89+
});
90+
}
91+
}

0 commit comments

Comments
 (0)