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