| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** The top-level collection of all sections for a user. */ | 5 /** The top-level collection of all sections for a user. */ |
| 6 // TODO(jimhug): This is known as UserData in the server model. | 6 // TODO(jimhug): This is known as UserData in the server model. |
| 7 class Sections implements Collection<Section> { | 7 class Sections implements Collection<Section> { |
| 8 final List<Section> _sections; | 8 final List<Section> _sections; |
| 9 | 9 |
| 10 Sections(this._sections); | 10 Sections(this._sections); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 sections.add(Section.decode(decoder)); | 52 sections.add(Section.decode(decoder)); |
| 53 } | 53 } |
| 54 callback(new Sections(sections)); | 54 callback(new Sections(sections)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 static void initializeFromUrl(void callback(Sections sections)) { | 57 static void initializeFromUrl(void callback(Sections sections)) { |
| 58 if (Sections.runningFromFile) { | 58 if (Sections.runningFromFile) { |
| 59 initializeFromData(CannedData.data['user.data'], callback); | 59 initializeFromData(CannedData.data['user.data'], callback); |
| 60 } else { | 60 } else { |
| 61 // TODO(jmesserly): display an error if we fail here! Silent failure bad. | 61 // TODO(jmesserly): display an error if we fail here! Silent failure bad. |
| 62 new XMLHttpRequest.getTEMPNAME('$home/data/user.data', | 62 new XMLHttpRequest.get('$home/data/user.data', |
| 63 EventBatch.wrap((request) { | 63 EventBatch.wrap((request) { |
| 64 // TODO(jimhug): Nice response if get error back from server. | 64 // TODO(jimhug): Nice response if get error back from server. |
| 65 // TODO(jimhug): Might be more efficient to parse request in sections. | 65 // TODO(jimhug): Might be more efficient to parse request in sections. |
| 66 initializeFromData(request.responseText, callback); | 66 initializeFromData(request.responseText, callback); |
| 67 })); | 67 })); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 Section findSectionById(String id) { | 71 Section findSectionById(String id) { |
| 72 return CollectionUtils.find(_sections, (section) => section.id == id); | 72 return CollectionUtils.find(_sections, (section) => section.id == id); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 final srcUrl = decoder.readString(); | 238 final srcUrl = decoder.readString(); |
| 239 final hasThumbnail = decoder.readBool(); | 239 final hasThumbnail = decoder.readBool(); |
| 240 final author = decoder.readString(); | 240 final author = decoder.readString(); |
| 241 final dateInSeconds = decoder.readInt(); | 241 final dateInSeconds = decoder.readInt(); |
| 242 final snippet = decoder.readString(); | 242 final snippet = decoder.readString(); |
| 243 final date = new Date.fromEpoch(dateInSeconds*1000, new TimeZone.utc()); | 243 final date = new Date.fromEpoch(dateInSeconds*1000, new TimeZone.utc()); |
| 244 return new Article(source, id, date, title, author, srcUrl, hasThumbnail, | 244 return new Article(source, id, date, title, author, srcUrl, hasThumbnail, |
| 245 snippet); | 245 snippet); |
| 246 } | 246 } |
| 247 } | 247 } |
| OLD | NEW |