| 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); | 
|   11  |   11  | 
|   12   operator [](int i) => _sections[i]; |   12   operator [](int i) => _sections[i]; | 
|   13  |   13  | 
|   14   int get length() => _sections.length; |   14   int get length => _sections.length; | 
|   15  |   15  | 
|   16   List<String> get sectionTitles() => |   16   List<String> get sectionTitles => | 
|   17     CollectionUtils.map(_sections, (s) => s.title); |   17     CollectionUtils.map(_sections, (s) => s.title); | 
|   18  |   18  | 
|   19   void refresh() { |   19   void refresh() { | 
|   20     // TODO(jimhug): http://b/issue?id=5351067 |   20     // TODO(jimhug): http://b/issue?id=5351067 | 
|   21   } |   21   } | 
|   22  |   22  | 
|   23   /** |   23   /** | 
|   24    * Find the Section object that has a given title. |   24    * Find the Section object that has a given title. | 
|   25    * This is used to integrate well with [ConveyorView]. |   25    * This is used to integrate well with [ConveyorView]. | 
|   26    */ |   26    */ | 
|   27   Section findSection(String name) { |   27   Section findSection(String name) { | 
|   28     return CollectionUtils.find(_sections, (sect) => sect.title == name); |   28     return CollectionUtils.find(_sections, (sect) => sect.title == name); | 
|   29   } |   29   } | 
|   30  |   30  | 
|   31   // TODO(jimhug): Track down callers! |   31   // TODO(jimhug): Track down callers! | 
|   32   Iterator<Section> iterator() => _sections.iterator(); |   32   Iterator<Section> iterator() => _sections.iterator(); | 
|   33  |   33  | 
|   34   // TODO(jimhug): Better support for switching between local dev and server. |   34   // TODO(jimhug): Better support for switching between local dev and server. | 
|   35   static bool get runningFromFile() { |   35   static bool get runningFromFile { | 
|   36     return window.location.protocol.startsWith('file:'); |   36     return window.location.protocol.startsWith('file:'); | 
|   37   } |   37   } | 
|   38  |   38  | 
|   39   static String get home() { |   39   static String get home { | 
|   40     // TODO(jmesserly): window.location.origin not available on Safari 4. |   40     // TODO(jmesserly): window.location.origin not available on Safari 4. | 
|   41     // Move this workaround to the DOM code. See bug 5389503. |   41     // Move this workaround to the DOM code. See bug 5389503. | 
|   42     return '${window.location.protocol}//${window.location.host}'; |   42     return '${window.location.protocol}//${window.location.host}'; | 
|   43   } |   43   } | 
|   44  |   44  | 
|   45   // This method is exposed for tests. |   45   // This method is exposed for tests. | 
|   46   static void initializeFromData(String data, void callback(Sections sects)) { |   46   static void initializeFromData(String data, void callback(Sections sects)) { | 
|   47     final decoder = new Decoder(data); |   47     final decoder = new Decoder(data); | 
|   48     int nSections = decoder.readInt(); |   48     int nSections = decoder.readInt(); | 
|   49     final sections = new List<Section>(); |   49     final sections = new List<Section>(); | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|   77    */ |   77    */ | 
|   78   int findSectionIndex(String name) { |   78   int findSectionIndex(String name) { | 
|   79     for (int i = 0; i < _sections.length; i++) { |   79     for (int i = 0; i < _sections.length; i++) { | 
|   80       if (name == _sections[i].title) { |   80       if (name == _sections[i].title) { | 
|   81         return i; |   81         return i; | 
|   82       } |   82       } | 
|   83     } |   83     } | 
|   84     return -1; |   84     return -1; | 
|   85   } |   85   } | 
|   86  |   86  | 
|   87   List<Section> get sections() => _sections; |   87   List<Section> get sections => _sections; | 
|   88  |   88  | 
|   89   // Collection<Section> methods: |   89   // Collection<Section> methods: | 
|   90   List map(f(Section element)) { |   90   List map(f(Section element)) { | 
|   91     return Collections.map(this, new List(), f); |   91     return Collections.map(this, new List(), f); | 
|   92   } |   92   } | 
|   93  |   93  | 
|   94   List<Section> filter(bool f(Section element)) { |   94   List<Section> filter(bool f(Section element)) { | 
|   95     return Collections.filter(this, new List<Section>(), f); |   95     return Collections.filter(this, new List<Section>(), f); | 
|   96   } |   96   } | 
|   97   bool every(bool f(Section element)) => Collections.every(this, f); |   97   bool every(bool f(Section element)) => Collections.every(this, f); | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  182   String srcUrl; |  182   String srcUrl; | 
|  183   final ObservableValue<bool> unread; // TODO(jimhug): persist to server. |  183   final ObservableValue<bool> unread; // TODO(jimhug): persist to server. | 
|  184  |  184  | 
|  185   bool error; // TODO(jimhug): Check if this is dead and remove. |  185   bool error; // TODO(jimhug): Check if this is dead and remove. | 
|  186  |  186  | 
|  187   Article(this.dataSource, this.id, this.date, this.title, this.author, |  187   Article(this.dataSource, this.id, this.date, this.title, this.author, | 
|  188       this.srcUrl, this.hasThumbnail, this.textBody, |  188       this.srcUrl, this.hasThumbnail, this.textBody, | 
|  189       [htmlBody = null, bool unread = true, this.error = false]) |  189       [htmlBody = null, bool unread = true, this.error = false]) | 
|  190     : unread = new ObservableValue<bool>(unread), this._htmlBody = htmlBody; |  190     : unread = new ObservableValue<bool>(unread), this._htmlBody = htmlBody; | 
|  191  |  191  | 
|  192   String get htmlBody() { |  192   String get htmlBody { | 
|  193     _ensureLoaded(); |  193     _ensureLoaded(); | 
|  194     return _htmlBody; |  194     return _htmlBody; | 
|  195   } |  195   } | 
|  196  |  196  | 
|  197   String get dataUri() { |  197   String get dataUri { | 
|  198     return Uri.encodeComponent(id).replaceAll('%2F', '/'). |  198     return Uri.encodeComponent(id).replaceAll('%2F', '/'). | 
|  199         replaceAll('%253A', '%3A'); |  199         replaceAll('%253A', '%3A'); | 
|  200   } |  200   } | 
|  201  |  201  | 
|  202   String get thumbUrl() { |  202   String get thumbUrl { | 
|  203     if (!hasThumbnail) return null; |  203     if (!hasThumbnail) return null; | 
|  204  |  204  | 
|  205     var home; |  205     var home; | 
|  206     if (Sections.runningFromFile) { |  206     if (Sections.runningFromFile) { | 
|  207       home = 'http://dart.googleplex.com'; |  207       home = 'http://dart.googleplex.com'; | 
|  208     } else { |  208     } else { | 
|  209       home = Sections.home; |  209       home = Sections.home; | 
|  210     } |  210     } | 
|  211     // By default images from the real server are cached. |  211     // By default images from the real server are cached. | 
|  212     // Bump the version flag if you change the thumbnail size, and you want to |  212     // Bump the version flag if you change the thumbnail size, and you want to | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
|  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 = |  243     final date = | 
|  244         new Date.fromMillisecondsSinceEpoch(dateInSeconds*1000, isUtc: true); |  244         new Date.fromMillisecondsSinceEpoch(dateInSeconds*1000, isUtc: true); | 
|  245     return new Article(source, id, date, title, author, srcUrl, hasThumbnail, |  245     return new Article(source, id, date, title, author, srcUrl, hasThumbnail, | 
|  246         snippet); |  246         snippet); | 
|  247   } |  247   } | 
|  248 } |  248 } | 
| OLD | NEW |