Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(814)

Side by Side Diff: 2-7-serve/web/piratebadge.dart

Issue 1056193003: Rename methods to better match new terminology and get rid of json data file. (Closed) Base URL: https://github.com/dart-lang/one-hour-codelab.git@server2
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « 2-7-serve/lib/server/piratesapi.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, 2015 the Dart project authors. 1 // Copyright (c) 2012, 2015 the Dart project authors.
2 // Please see the AUTHORS file for details. All rights reserved. 2 // Please see the AUTHORS file for details. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 5
6 import 'dart:async'; 6 import 'dart:async';
7 import 'dart:html'; 7 import 'dart:html';
8 8
9 import 'package:http/browser_client.dart'; 9 import 'package:http/browser_client.dart';
10 import 'package:server_code_lab/client/piratesapi.dart'; 10 import 'package:server_code_lab/client/piratesapi.dart';
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 ..text = 'Arrr! Write yer name!'; 92 ..text = 'Arrr! Write yer name!';
93 storeButton..disabled = false; 93 storeButton..disabled = false;
94 } 94 }
95 } 95 }
96 96
97 Future storeBadge(Event e) async { 97 Future storeBadge(Event e) async {
98 var pirateName = badgeNameElement.text; 98 var pirateName = badgeNameElement.text;
99 if (pirateName == null || pirateName.isEmpty) return null; 99 if (pirateName == null || pirateName.isEmpty) return null;
100 var pirate = new Pirate.fromString(pirateName); 100 var pirate = new Pirate.fromString(pirateName);
101 try { 101 try {
102 await _api.addPirate(pirate); 102 await _api.hirePirate(pirate);
103 } catch (error) { 103 } catch (error) {
104 window.alert(error.message); 104 window.alert(error.message);
105 } 105 }
106 new Future.delayed(new Duration(milliseconds: 300), () { 106 new Future.delayed(new Duration(milliseconds: 300), () {
107 storeButton 107 storeButton
108 ..disabled = true 108 ..disabled = true
109 ..text = 'Pirate hired!'; 109 ..text = 'Pirate hired!';
110 }); 110 });
111 refreshList(); 111 refreshList();
112 } 112 }
113 113
114 Future selectListener(Event e) async { 114 Future selectListener(Event e) async {
115 fireButton.disabled = false; 115 fireButton.disabled = false;
116 } 116 }
117 117
118 Future removeBadge(Event e) async { 118 Future removeBadge(Event e) async {
119 var idx = pirateList.selectedIndex; 119 var idx = pirateList.selectedIndex;
120 if (idx < 0 || idx >= pirateList.options.length) return null; 120 if (idx < 0 || idx >= pirateList.options.length) return null;
121 var option = pirateList.options.elementAt(idx); 121 var option = pirateList.options.elementAt(idx);
122 var pirate = new Pirate.fromString(option.label); 122 var pirate = new Pirate.fromString(option.label);
123 try { 123 try {
124 await _api.killPirate(pirate.name, pirate.appellation); 124 await _api.firePirate(pirate.name, pirate.appellation);
125 } catch (error) { 125 } catch (error) {
126 window.alert(error.message); 126 window.alert(error.message);
127 } 127 }
128 new Future.delayed(new Duration(milliseconds: 300), () { 128 new Future.delayed(new Duration(milliseconds: 300), () {
129 fireButton.disabled = true; 129 fireButton.disabled = true;
130 }); 130 });
131 refreshList(); 131 refreshList();
132 } 132 }
133 133
134 Future removeAllBadges(Event e) async { 134 Future removeAllBadges(Event e) async {
135 for (var option in pirateList.options) { 135 for (var option in pirateList.options) {
136 var pirate = new Pirate.fromString(option.label); 136 var pirate = new Pirate.fromString(option.label);
137 try { 137 try {
138 await _api.killPirate(pirate.name, pirate.appellation); 138 await _api.firePirate(pirate.name, pirate.appellation);
139 } catch (error) { 139 } catch (error) {
140 // ignoring errors. 140 // ignoring errors.
141 } 141 }
142 } 142 }
143 new Future.delayed(new Duration(milliseconds: 300), () { 143 new Future.delayed(new Duration(milliseconds: 300), () {
144 fireButton.disabled = true; 144 fireButton.disabled = true;
145 slayButton.disabled = true; 145 slayButton.disabled = true;
146 }); 146 });
147 refreshList(); 147 refreshList();
148 } 148 }
149 149
150 void generateBadge(Event e) { 150 void generateBadge(Event e) {
151 var pirate = _shanghaier.shanghaiAPirate(); 151 var pirate = _shanghaier.shanghaiAPirate();
152 setBadgeName(pirate); 152 setBadgeName(pirate);
153 } 153 }
154 154
155 void setBadgeName(Pirate pirate) { 155 void setBadgeName(Pirate pirate) {
156 if (pirate == null || pirate.toString().isEmpty) { 156 if (pirate == null || pirate.toString().isEmpty) {
157 badgeNameElement.text = ''; 157 badgeNameElement.text = '';
158 storeButton.disabled = true; 158 storeButton.disabled = true;
159 return; 159 return;
160 } 160 }
161 badgeNameElement.text = pirate.toString(); 161 badgeNameElement.text = pirate.toString();
162 window.localStorage[TREASURE_KEY] = pirate.jsonString; 162 window.localStorage[TREASURE_KEY] = pirate.toString();
163 storeButton 163 storeButton
164 ..disabled = false 164 ..disabled = false
165 ..text = 'Hire pirate!'; 165 ..text = 'Hire pirate!';
166 } 166 }
167 167
168 Pirate getBadgeNameFromStorage() { 168 Pirate getBadgeNameFromStorage() {
169 String storedName = window.localStorage[TREASURE_KEY]; 169 String storedName = window.localStorage[TREASURE_KEY];
170 if (storedName != null) { 170 if (storedName != null) {
171 return new Pirate.fromJSON(storedName); 171 return new Pirate.fromString(storedName);
172 } else { 172 } else {
173 return null; 173 return null;
174 } 174 }
175 } 175 }
176 176
177 void addRippleEffect(MouseEvent e) { 177 void addRippleEffect(MouseEvent e) {
178 var button = e.target as ButtonElement; 178 var button = e.target as ButtonElement;
179 var ripple = button.querySelector(".ripple"); 179 var ripple = button.querySelector(".ripple");
180 180
181 // we need to delete existing ripple element 181 // we need to delete existing ripple element
182 if (ripple != null) { 182 if (ripple != null) {
183 ripple.remove(); 183 ripple.remove();
184 } 184 }
185 185
186 var x = e.client.x - button.getBoundingClientRect().left; 186 var x = e.client.x - button.getBoundingClientRect().left;
187 var y = e.client.y - button.getBoundingClientRect().top; 187 var y = e.client.y - button.getBoundingClientRect().top;
188 188
189 ripple = new SpanElement() 189 ripple = new SpanElement()
190 ..classes.add("ripple") 190 ..classes.add("ripple")
191 ..style.left = "${x}px" 191 ..style.left = "${x}px"
192 ..style.top = "${y}px" 192 ..style.top = "${y}px"
193 ..classes.add("show"); 193 ..classes.add("show");
194 194
195 button.append(ripple); 195 button.append(ripple);
196 } 196 }
OLDNEW
« no previous file with comments | « 2-7-serve/lib/server/piratesapi.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698