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

Added Chapter_07 on production deployment #13

Merged
merged 7 commits into from
Dec 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Chapter_03/lib/recipe_book.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
library recipe_book_controller;

import 'package:angular/angular.dart';

@NgController(
selector: '[recipe-book]',
publishAs: 'ctrl')
class RecipeBookController {

List recipes;

RecipeBookController() {
recipes = _loadData();
}

Recipe selectedRecipe;

void selectRecipe(Recipe recipe) {
selectedRecipe = recipe;
}

List<Recipe> _loadData() {
return [
new Recipe('My Appetizer','Appetizers',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 1),
new Recipe('My Salad','Salads',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3),
new Recipe('My Soup','Soups',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 4),
new Recipe('My Main Dish','Main Dishes',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 2),
new Recipe('My Side Dish','Side Dishes',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3),
new Recipe('My Awesome Dessert','Desserts',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 5),
new Recipe('My So-So Dessert','Desserts',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3),
];
}
}

class Recipe {
String name;
String category;
List<String> ingredients;
String directions;
int rating;

Recipe(this.name, this.category, this.ingredients, this.directions,
this.rating);
}
56 changes: 1 addition & 55 deletions Chapter_03/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,7 @@ import 'package:di/di.dart';
import 'package:perf_api/perf_api.dart';

import 'package:angular_dart_demo/rating/rating_component.dart';

@NgController(
selector: '[recipe-book]',
publishAs: 'ctrl')
class RecipeBookController {

List recipes;

RecipeBookController() {
recipes = _loadData();
}

Recipe selectedRecipe;

void selectRecipe(Recipe recipe) {
selectedRecipe = recipe;
}

List<Recipe> _loadData() {
return [
new Recipe('My Appetizer','Appetizers',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 1),
new Recipe('My Salad','Salads',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3),
new Recipe('My Soup','Soups',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 4),
new Recipe('My Main Dish','Main Dishes',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 2),
new Recipe('My Side Dish','Side Dishes',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3),
new Recipe('My Awesome Dessert','Desserts',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 5),
new Recipe('My So-So Dessert','Desserts',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3),
];
}
}

class Recipe {
String name;
String category;
List<String> ingredients;
String directions;
int rating;

Recipe(this.name, this.category, this.ingredients, this.directions,
this.rating);
}
import 'package:angular_dart_demo/recipe_book.dart';

class MyAppModule extends Module {
MyAppModule() {
Expand Down
73 changes: 73 additions & 0 deletions Chapter_04/lib/recipe_book.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
library recipe_book_controller;

import 'package:angular/angular.dart';

import 'tooltip/tooltip_directive.dart';

@NgController(
selector: '[recipe-book]',
publishAs: 'ctrl')
class RecipeBookController {

List recipes;

RecipeBookController() {
recipes = _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
}

List<Recipe> _loadData() {
return [
new Recipe('My Appetizer','Appetizers',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 1, 'fonzie1.jpg'),
new Recipe('My Salad','Salads',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3, 'fonzie2.jpg'),
new Recipe('My Soup','Soups',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 4, 'fonzie1.jpg'),
new Recipe('My Main Dish','Main Dishes',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 2, 'fonzie2.jpg'),
new Recipe('My Side Dish','Side Dishes',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3, 'fonzie1.jpg'),
new Recipe('My Awesome Dessert','Desserts',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 5, 'fonzie2.jpg'),
new Recipe('My So-So Dessert','Desserts',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3, 'fonzie1.jpg'),
];
}
}

class Recipe {
String name;
String category;
List<String> ingredients;
String directions;
int rating;
String imgUrl;

Recipe(this.name, this.category, this.ingredients, this.directions,
this.rating, this.imgUrl);
}
69 changes: 1 addition & 68 deletions Chapter_04/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,10 @@ import 'package:angular/angular.dart';
import 'package:di/di.dart';
import 'package:perf_api/perf_api.dart';

import 'package:angular_dart_demo/recipe_book.dart';
import 'package:angular_dart_demo/rating/rating_component.dart';
import 'package:angular_dart_demo/tooltip/tooltip_directive.dart';

@NgController(
selector: '[recipe-book]',
publishAs: 'ctrl')
class RecipeBookController {

List recipes;

RecipeBookController() {
recipes = _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
}

List<Recipe> _loadData() {
return [
new Recipe('My Appetizer','Appetizers',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 1, 'fonzie1.jpg'),
new Recipe('My Salad','Salads',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3, 'fonzie2.jpg'),
new Recipe('My Soup','Soups',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 4, 'fonzie1.jpg'),
new Recipe('My Main Dish','Main Dishes',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 2, 'fonzie2.jpg'),
new Recipe('My Side Dish','Side Dishes',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3, 'fonzie1.jpg'),
new Recipe('My Awesome Dessert','Desserts',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 5, 'fonzie2.jpg'),
new Recipe('My So-So Dessert','Desserts',
["Ingredient 1", "Ingredient 2"],
"Some Directions", 3, 'fonzie1.jpg'),
];
}
}

class Recipe {
String name;
String category;
List<String> ingredients;
String directions;
int rating;
String imgUrl;

Recipe(this.name, this.category, this.ingredients, this.directions,
this.rating, this.imgUrl);
}

class MyAppModule extends Module {
MyAppModule() {
type(RecipeBookController);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of recipe_book;
library category_filter;

import 'package:angular/angular.dart';

@NgFilter(name: 'categoryfilter')
class CategoryFilter {
Expand All @@ -13,4 +15,3 @@ class CategoryFilter {
}
}
}

4 changes: 3 additions & 1 deletion Chapter_05/web/recipe.dart → Chapter_05/lib/recipe.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
part of recipe_book;
library recipe;

import 'dart:convert';

class Recipe {
String id;
Expand Down
91 changes: 91 additions & 0 deletions Chapter_05/lib/recipe_book.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
});
}
}
Loading