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

Commit 3661444

Browse files
committed
Merge pull request #102 from vicb/import
[WIP] Upgrade to Angular 0.9.10 & misc changes
2 parents cee2c1f + 94bddab commit 3661444

35 files changed

+95
-134
lines changed

Chapter_01/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ packages:
8484
unittest:
8585
description: unittest
8686
source: hosted
87-
version: "0.10.1"
87+
version: "0.10.1+1"
8888
utf:
8989
description: utf
9090
source: hosted

Chapter_02/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ packages:
8888
unittest:
8989
description: unittest
9090
source: hosted
91-
version: "0.10.1"
91+
version: "0.10.1+2"
9292
utf:
9393
description: utf
9494
source: hosted

Chapter_03/lib/rating/rating_component.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ class RatingComponent {
5353
stars = new List.generate(count, (i) => i + 1);
5454
}
5555

56-
String starClass(int star) {
57-
return star > rating ? _STAR_OFF_CLASS : _STAR_ON_CLASS;
58-
}
56+
String starClass(int star) =>
57+
star > rating ? _STAR_OFF_CLASS : _STAR_ON_CLASS;
5958

6059
String starChar(int star) => star > rating ? _STAR_OFF_CHAR : _STAR_ON_CHAR;
6160

Chapter_03/lib/rating/rating_component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<span class="stars"
2-
ng-if="cmp.rating != null"
32
ng-repeat="star in cmp.stars"
43
ng-click="cmp.handleClick(star)"
54
ng-class="cmp.starClass(star)">

Chapter_03/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ packages:
8888
unittest:
8989
description: unittest
9090
source: hosted
91-
version: "0.10.1"
91+
version: "0.10.1+1"
9292
utf:
9393
description: utf
9494
source: hosted

Chapter_03/web/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
library recipe_book;
22

33
import 'package:angular/angular.dart';
4-
import 'package:di/di.dart';
54

65
import 'package:angular_dart_demo/rating/rating_component.dart';
76
import 'package:angular_dart_demo/recipe_book.dart';

Chapter_04/lib/rating/rating_component.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ class RatingComponent {
5353
stars = new List.generate(count, (i) => i + 1);
5454
}
5555

56-
String starClass(int star) {
57-
return star > rating ? _STAR_OFF_CLASS : _STAR_ON_CLASS;
58-
}
56+
String starClass(int star) =>
57+
star > rating ? _STAR_OFF_CLASS : _STAR_ON_CLASS;
5958

6059
String starChar(int star) => star > rating ? _STAR_OFF_CHAR : _STAR_ON_CHAR;
6160

Chapter_04/lib/rating/rating_component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<span class="stars"
2-
ng-if="cmp.rating != null"
32
ng-repeat="star in cmp.stars"
43
ng-click="cmp.handleClick(star)"
54
ng-class="cmp.starClass(star)">

Chapter_04/lib/recipe_book.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class RecipeBookController {
2121

2222
// Tooltip
2323
static final tooltip = new Expando<TooltipModel>();
24+
2425
TooltipModel tooltipForRecipe(Recipe recipe) {
2526
if (tooltip[recipe] == null) {
2627
tooltip[recipe] = new TooltipModel(recipe.imgUrl,

Chapter_04/lib/tooltip/tooltip_directive.dart

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ import 'package:angular/angular.dart';
77
@NgDirective(
88
selector: '[tooltip]')
99
class Tooltip {
10-
dom.Element element;
10+
final dom.Element element;
1111

1212
@NgOneWay('tooltip')
1313
TooltipModel displayModel;
1414

1515
dom.Element tooltipElem;
1616

1717
Tooltip(this.element) {
18-
element
19-
..onMouseEnter.listen((_) => _createTemplate())
20-
..onMouseLeave.listen((_) => _destroyTemplate());
18+
element..onMouseEnter.listen((_) => _createTemplate())
19+
..onMouseLeave.listen((_) => _destroyTemplate());
2120
}
2221

2322
void _createTemplate() {
@@ -47,19 +46,13 @@ class Tooltip {
4746
..borderRadius = "5px"
4847
..width = "${displayModel.imgWidth.toString()}px";
4948

50-
// find the coordinates of the parent DOM element
51-
Rectangle bounds = element.getBoundingClientRect();
52-
int left = (bounds.left + dom.window.pageXOffset).toInt();
53-
int top = (bounds.top + dom.window.pageYOffset).toInt();
54-
int width = bounds.width.toInt();
55-
int height = bounds.height.toInt();
56-
5749
// position the tooltip.
58-
// Figure out where the containing element sits in the window.
50+
var elTopRight = element.offset.topRight;
51+
5952
tooltipElem.style
6053
..position = "absolute"
61-
..top = "${top - height}px"
62-
..left = "${left + width + 10}px";
54+
..top = "${elTopRight.y}px"
55+
..left = "${elTopRight.x + 10}px";
6356

6457
// Add the tooltip to the document body. We add it here because
6558
// we need to position it absolutely, without reference to its

Chapter_04/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ packages:
8888
unittest:
8989
description: unittest
9090
source: hosted
91-
version: "0.10.1"
91+
version: "0.10.1+2"
9292
utf:
9393
description: utf
9494
source: hosted

Chapter_04/web/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
library recipe_book;
22

33
import 'package:angular/angular.dart';
4-
import 'package:di/di.dart';
54

65
import 'package:angular_dart_demo/recipe_book.dart';
76
import 'package:angular_dart_demo/rating/rating_component.dart';

Chapter_05/lib/filter/category_filter.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ class CategoryFilter {
1212
? recipeList.toList()
1313
: recipeList.where((i) => filterMap[i.category] == true).toList();
1414
}
15+
return const [];
1516
}
1617
}

Chapter_05/lib/rating/rating_component.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ class RatingComponent {
5353
stars = new List.generate(count, (i) => i + 1);
5454
}
5555

56-
String starClass(int star) {
57-
return star > rating ? _STAR_OFF_CLASS : _STAR_ON_CLASS;
58-
}
56+
String starClass(int star) =>
57+
star > rating ? _STAR_OFF_CLASS : _STAR_ON_CLASS;
5958

6059
String starChar(int star) => star > rating ? _STAR_OFF_CHAR : _STAR_ON_CHAR;
6160

Chapter_05/lib/rating/rating_component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<span class="stars"
2-
ng-if="cmp.rating != null"
32
ng-repeat="star in cmp.stars"
43
ng-click="cmp.handleClick(star)"
54
ng-class="cmp.starClass(star)">

Chapter_05/lib/recipe_book.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import 'tooltip/tooltip_directive.dart';
1111
class RecipeBookController {
1212

1313
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!""";
14+
static const String ERROR_MESSAGE = "Sorry! The cook stepped out of the "
15+
"kitchen and took the recipe book with him!";
1616

17-
Http _http;
17+
final Http _http;
1818

1919
// Determine the initial load state of the app
2020
String message = LOADING_MESSAGE;
@@ -26,10 +26,10 @@ kitchen and took the recipe book with him!""";
2626
List<Recipe> recipes = [];
2727

2828
// Filter box
29-
Map<String, bool> categoryFilterMap = {};
29+
final categoryFilterMap = <String, bool>{};
3030
String nameFilterString = "";
3131

32-
RecipeBookController(Http this._http) {
32+
RecipeBookController(this._http) {
3333
_loadData();
3434
}
3535

@@ -62,9 +62,7 @@ kitchen and took the recipe book with him!""";
6262
_http.get('recipes.json')
6363
.then((HttpResponse response) {
6464
print(response);
65-
for (Map recipe in response.data) {
66-
recipes.add(new Recipe.fromJson(recipe));
67-
}
65+
recipes = response.data.map((d) => new Recipe.fromJson(d)).toList();
6866
recipesLoaded = true;
6967
})
7068
.catchError((e) {

Chapter_05/lib/tooltip/tooltip_directive.dart

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ import 'package:angular/angular.dart';
77
@NgDirective(
88
selector: '[tooltip]')
99
class Tooltip {
10-
dom.Element element;
10+
final dom.Element element;
1111

1212
@NgOneWay('tooltip')
1313
TooltipModel displayModel;
1414

1515
dom.Element tooltipElem;
1616

1717
Tooltip(this.element) {
18-
element
19-
..onMouseEnter.listen((_) => _createTemplate())
20-
..onMouseLeave.listen((_) => _destroyTemplate());
18+
element..onMouseEnter.listen((_) => _createTemplate())
19+
..onMouseLeave.listen((_) => _destroyTemplate());
2120
}
2221

2322
void _createTemplate() {
@@ -47,19 +46,13 @@ class Tooltip {
4746
..borderRadius = "5px"
4847
..width = "${displayModel.imgWidth.toString()}px";
4948

50-
// find the coordinates of the parent DOM element
51-
Rectangle bounds = element.getBoundingClientRect();
52-
int left = (bounds.left + dom.window.pageXOffset).toInt();
53-
int top = (bounds.top + dom.window.pageYOffset).toInt();
54-
int width = bounds.width.toInt();
55-
int height = bounds.height.toInt();
56-
5749
// position the tooltip.
58-
// Figure out where the containing element sits in the window.
50+
var elTopRight = element.offset.topRight;
51+
5952
tooltipElem.style
6053
..position = "absolute"
61-
..top = "${top - height}px"
62-
..left = "${left + width + 10}px";
54+
..top = "${elTopRight.y}px"
55+
..left = "${elTopRight.x + 10}px";
6356

6457
// Add the tooltip to the document body. We add it here because
6558
// we need to position it absolutely, without reference to its

Chapter_05/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ packages:
8888
unittest:
8989
description: unittest
9090
source: hosted
91-
version: "0.10.1"
91+
version: "0.10.1+1"
9292
utf:
9393
description: utf
9494
source: hosted

Chapter_05/web/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h3>Recipe List</h3>
1515
<div id="filters">
1616
<div>
1717
<label for="name-filter">Filter recipes by name</label>
18-
<input id="name-filter" type="text"
18+
<input id="name-filter" type="text"
1919
ng-model="ctrl.nameFilterString">
2020
</div>
2121
<div>
@@ -29,7 +29,7 @@ <h3>Recipe List</h3>
2929
</div>
3030
<input type="button" value="Clear Filters" ng-click="ctrl.clearFilters()">
3131
</div>
32-
32+
3333
<div id="recipe-list">
3434
<ul>
3535
<li class="pointer"
@@ -41,8 +41,8 @@ <h3>Recipe List</h3>
4141
</span>
4242
</li>
4343
</ul>
44-
</div>
45-
44+
</div>
45+
4646
<div id="recipe-details" ng-if="ctrl.selectedRecipe != null">
4747
<h3>Recipe Details</h3>
4848
<div><strong>Name: </strong>{{ctrl.selectedRecipe.name}}</div>

Chapter_05/web/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
library recipe_book;
22

33
import 'package:angular/angular.dart';
4-
import 'package:di/di.dart';
54

65
import 'package:angular_dart_demo/recipe_book.dart';
76
import 'package:angular_dart_demo/filter/category_filter.dart';

Chapter_06/lib/component/search_recipe_component.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,23 @@ import 'package:angular/angular.dart';
77
templateUrl: 'packages/angular_dart_demo/component/search_recipe_component.html',
88
publishAs: 'cmp')
99
class SearchRecipeComponent {
10+
Map<String, bool> _categoryFilterMap;
11+
List<String> _categories;
12+
1013
@NgTwoWay('name-filter-string')
1114
String nameFilterString = "";
1215

1316
@NgTwoWay('category-filter-map')
14-
Map<String, bool> categoryFilterMap;
17+
Map<String, bool> get categoryFilterMap => _categoryFilterMap;
18+
void set categoryFilterMap(values) {
19+
_categoryFilterMap = values;
20+
_categories = categoryFilterMap.keys.toList();
21+
}
1522

16-
List<String> get categories => categoryFilterMap.keys.toList();
23+
List<String> get categories => _categories;
1724

1825
void clearFilters() {
19-
categoryFilterMap.keys.forEach((f) => categoryFilterMap[f] = false);
26+
_categoryFilterMap.keys.forEach((f) => _categoryFilterMap[f] = false);
2027
nameFilterString = "";
2128
}
2229
}

Chapter_06/lib/filter/category_filter.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ class CategoryFilter {
99
// If there is nothing checked, treat it as "everything is checked"
1010
bool nothingChecked = filterMap.values.every((isChecked) => !isChecked);
1111
return nothingChecked
12-
? recipeList.toList()
12+
? recipeList
1313
: recipeList.where((i) => filterMap[i.category] == true).toList();
1414
}
15+
return const [];
1516
}
1617
}

Chapter_06/lib/rating/rating_component.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ class RatingComponent {
5353
stars = new List.generate(count, (i) => i + 1);
5454
}
5555

56-
String starClass(int star) {
57-
return star > rating ? _STAR_OFF_CLASS : _STAR_ON_CLASS;
58-
}
56+
String starClass(int star) =>
57+
star > rating ? _STAR_OFF_CLASS : _STAR_ON_CLASS;
5958

6059
String starChar(int star) => star > rating ? _STAR_OFF_CHAR : _STAR_ON_CHAR;
6160

Chapter_06/lib/rating/rating_component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<span class="stars"
2-
ng-if="cmp.rating != null"
32
ng-repeat="star in cmp.stars"
43
ng-click="cmp.handleClick(star)"
54
ng-class="cmp.starClass(star)">

0 commit comments

Comments
 (0)