OLD | NEW |
---|---|
1 <h1 id="lab_5_manage_data">Save and Fetch Data</h1> | 1 <h1 id="lab_5_manage_data">Save and Fetch Data</h1> |
2 | 2 |
3 <p>The <a href="app_codelab3_mvc.html">sample from Lab 3</a> | 3 <p>The <a href="app_codelab3_mvc">sample from Lab 3</a> |
4 uses a static array of Todos. | 4 uses a static array of Todos. |
5 Every time your app restarts, | 5 Every time your app restarts, |
6 whatever you've changed is lost. | 6 whatever you've changed is lost. |
7 In this section, we will save every change using | 7 In this section, we will save every change using |
8 <a href="storage.html">chrome.storage.sync</a>. | 8 <a href="storage">chrome.storage.sync</a>. |
9 </p> | 9 </p> |
10 | 10 |
11 <p> | 11 <p> |
12 This lets you store <em>small things</em> that automatically sync to the cloud | 12 This lets you store <em>small things</em> that automatically sync to the cloud |
13 if you are online and logged in to Chrome. | 13 if you are online and logged in to Chrome. |
14 If you are offline or unlogged, it saves locally and transparently: | 14 If you are offline or unlogged, it saves locally and transparently: |
15 you don't have to handle online check and offline fallback in your applicati on. | 15 you don't have to handle online check and offline fallback in your applicati on. |
16 </p> | 16 </p> |
17 | 17 |
18 <h2 id="save_your_todos_in_the_cloud">Save your Todos in the cloud</h2> | 18 <h2 id="save_your_todos_in_the_cloud">Save your Todos in the cloud</h2> |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 var storageSave = function() { | 108 var storageSave = function() { |
109 chrome.storage.sync.set({'todolist': model.todos}); | 109 chrome.storage.sync.set({'todolist': model.todos}); |
110 }; | 110 }; |
111 </pre> | 111 </pre> |
112 </content> | 112 </content> |
113 </tabs> | 113 </tabs> |
114 | 114 |
115 <h3 id="simple-view">Update view</h3> | 115 <h3 id="simple-view">Update view</h3> |
116 | 116 |
117 <p>In the view, | 117 <p>In the view, |
118 <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab5_dat a/angularjs/1_storage_sync/index.html">AngularJs index.hmtl</a> or | 118 <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab5_dat a/angularjs/1_storage_sync/index">AngularJs index.hmtl</a> or |
mkearney1
2014/04/09 19:43:29
Check if GitHub links work without .html
mkearney1
2014/04/09 19:43:29
Keep .html here as it refers to a filename in a sa
| |
119 <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab5_dat a/javascript/1_storage_sync/index.html">JavaScript index.html</a>, | 119 <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab5_dat a/javascript/1_storage_sync/index">JavaScript index</a>, |
120 save the data whenever it changes. | 120 save the data whenever it changes. |
121 In AngularJS, | 121 In AngularJS, |
122 we call <code>save()</code> explicitedly | 122 we call <code>save()</code> explicitedly |
123 but there are many ways of doing this. | 123 but there are many ways of doing this. |
124 For example, | 124 For example, |
125 you could also use <code>$watchers</code> on the scope. | 125 you could also use <code>$watchers</code> on the scope. |
126 </p> | 126 </p> |
127 | 127 |
128 <tabs data-group="source"> | 128 <tabs data-group="source"> |
129 | 129 |
130 <header tabindex="0" data-value="angular">Angular</header> | 130 <header tabindex="0" data-value="angular">Angular</header> |
131 <header tabindex="0" data-value="js">JavaScript</header> | 131 <header tabindex="0" data-value="js">JavaScript</header> |
132 | 132 |
133 <content> | 133 <content> |
134 <pre data-filename="index.html"> | 134 <pre data-filename="index"> |
mkearney1
2014/04/09 19:43:29
Keep .html here as it refers to a filename in samp
| |
135 ... | 135 ... |
136 [ <a href="" ng-click="archive() || save()">arc hive</a> ] | 136 [ <a href="" ng-click="archive() || save()">arc hive</a> ] |
137 ... | 137 ... |
138 <input type="checkbox" ng-model="todo.done" n g-change="save()"> | 138 <input type="checkbox" ng-model="todo.done" n g-change="save()"> |
139 ... | 139 ... |
140 <form ng-submit="addTodo() || save()"> | 140 <form ng-submit="addTodo() || save()"> |
141 ... | 141 ... |
142 </pre> | 142 </pre> |
143 </content> | 143 </content> |
144 <content> | 144 <content> |
145 <pre data-filename="index.html"> | 145 <pre data-filename="index"> |
mkearney1
2014/04/09 19:43:29
Keep .html here as it refers to a filename in samp
| |
146 <form> | 146 <form> |
147 <input type="text" size="30" | 147 <input type="text" size="30" |
148 placeholder="add new todo here"> | 148 placeholder="add new todo here"> |
149 <input class="btn-primary" type="submit" value="add"> | 149 <input class="btn-primary" type="submit" value="add"> |
150 </form> | 150 </form> |
151 </pre> | 151 </pre> |
152 </content> | 152 </content> |
153 | 153 |
154 </tabs> | 154 </tabs> |
155 | 155 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 } | 315 } |
316 </pre> | 316 </pre> |
317 </content> | 317 </content> |
318 | 318 |
319 </tabs> | 319 </tabs> |
320 | 320 |
321 <h3 id="dd-view">Update view</h3> | 321 <h3 id="dd-view">Update view</h3> |
322 | 322 |
323 <p>If using AngularJS, | 323 <p>If using AngularJS, |
324 let's move the Angular scope definition from the div to the body in the | 324 let's move the Angular scope definition from the div to the body in the |
325 <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab5_dat a/angularjs/2_drop_files/index.html">AngularJS index.html</a> file to make all t he area of the window accept the drop event and still work on the same scope. | 325 <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab5_dat a/angularjs/2_drop_files/index">AngularJS index</a> file to make all the area of the window accept the drop event and still work on the same scope. |
mkearney1
2014/04/09 19:43:29
Check links work to GitHub samples without .html.
mkearney1
2014/04/09 19:43:29
Keep .html here as it refers to filename in sample
| |
326 Also, let's associate the body's CSS class with the Angular controller&# 39;s class, | 326 Also, let's associate the body's CSS class with the Angular controller&# 39;s class, |
327 so we can change the class directly in the scope and have it automatically chang ed in the DOM: | 327 so we can change the class directly in the scope and have it automatically chang ed in the DOM: |
328 </p> | 328 </p> |
329 | 329 |
330 <tabs data-group="source"> | 330 <tabs data-group="source"> |
331 | 331 |
332 <header tabindex="0" data-value="angular">Angular</header> | 332 <header tabindex="0" data-value="angular">Angular</header> |
333 | 333 |
334 <content> | 334 <content> |
335 <pre data-filename="index.html"> | 335 <pre data-filename="index"> |
336 <body ng-controller="TodoCtrl" ng-class="dropClass"> | 336 <body ng-controller="TodoCtrl" ng-class="dropClass"> |
337 <!-- remember to remove the ng-controller attribute from the div where it was before --> | 337 <!-- remember to remove the ng-controller attribute from the div where it was before --> |
338 </pre> | 338 </pre> |
339 </content> | 339 </content> |
340 | 340 |
341 </tabs> | 341 </tabs> |
342 | 342 |
343 <p>Add a message placeholder | 343 <p>Add a message placeholder |
344 (in <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab5 _data/angularjs/2_drop_files/index.html">AngularJS index.html</a> or | 344 (in <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab5 _data/angularjs/2_drop_files/index">AngularJS index</a> or |
mkearney1
2014/04/09 19:43:29
Check this link works without .html.
mkearney1
2014/04/09 19:43:29
Keep this .html in as it refers to a filename in s
| |
345 <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab5_dat a/javascript/2_drop_files/index.html">JavaScript index.html</a>) to warn the use r that some types of dragging are not allowed: | 345 <a href="https://github.com/GoogleChrome/chrome-app-codelab/blob/master/lab5_dat a/javascript/2_drop_files/index">JavaScript index</a>) to warn the user that som e types of dragging are not allowed: |
mkearney1
2014/04/09 19:43:29
Check this link works without .html.
mkearney1
2014/04/09 19:43:29
Keep .html in as it refers to a filename in sample
| |
346 </p> | 346 </p> |
347 | 347 |
348 <tabs data-group="source"> | 348 <tabs data-group="source"> |
349 | 349 |
350 <header tabindex="0" data-value="angular">Angular</header> | 350 <header tabindex="0" data-value="angular">Angular</header> |
351 <header tabindex="0" data-value="js">JavaScript</header> | 351 <header tabindex="0" data-value="js">JavaScript</header> |
352 | 352 |
353 <content> | 353 <content> |
354 <pre data-filename="index.html"> | 354 <pre data-filename="index"> |
mkearney1
2014/04/09 19:43:29
Keep .html in as it refers to filename in sample.
| |
355 <div> | 355 <div> |
356 {{dropText}} | 356 {{dropText}} |
357 </div> | 357 </div> |
358 </pre> | 358 </pre> |
359 </content> | 359 </content> |
360 <content> | 360 <content> |
361 <pre data-filename="index.html"> | 361 <pre data-filename="index"> |
mkearney1
2014/04/09 19:43:29
Keep .html in as it refers to filename in sample.
| |
362 <div id="dropText"> | 362 <div id="dropText"> |
363 </div> | 363 </div> |
364 </pre> | 364 </pre> |
365 </content> | 365 </content> |
366 | 366 |
367 </tabs> | 367 </tabs> |
368 | 368 |
369 <h3 id="dd-css">Update stylesheet</h3> | 369 <h3 id="dd-css">Update stylesheet</h3> |
370 | 370 |
371 <p>Add appropriate styling for the <code>dragging</code> and | 371 <p>Add appropriate styling for the <code>dragging</code> and |
(...skipping 28 matching lines...) Expand all Loading... | |
400 <p> | 400 <p> |
401 If you get stuck and want to see the app in action, | 401 If you get stuck and want to see the app in action, |
402 go to <code>chrome://extensions</code>, load the unpacked app, | 402 go to <code>chrome://extensions</code>, load the unpacked app, |
403 and launch the app from a new tab: | 403 and launch the app from a new tab: |
404 <a href="https://github.com/GoogleChrome/chrome-app-codelab/tree/master/lab5_dat a/angularjs/2_drop_files">AngularJS 2_drop_files</a> | 404 <a href="https://github.com/GoogleChrome/chrome-app-codelab/tree/master/lab5_dat a/angularjs/2_drop_files">AngularJS 2_drop_files</a> |
405 or <a href="https://github.com/GoogleChrome/chrome-app-codelab/tree/master/lab5_ data/javascript/2_drop_files">JavaScript 2_drop_files</a>. | 405 or <a href="https://github.com/GoogleChrome/chrome-app-codelab/tree/master/lab5_ data/javascript/2_drop_files">JavaScript 2_drop_files</a>. |
406 </p> | 406 </p> |
407 | 407 |
408 <h2 id="challenge_">Challenge</h2> | 408 <h2 id="challenge_">Challenge</h2> |
409 | 409 |
410 <p>The current code only saves the file reference, but it doesn't open the f ile. Using the <a href="http://www.html5rocks.com/en/tutorials/file/filesystem/" >HTML5 Filesystem API</a>, save the file contents in a sandboxed filesystem. Whe n the Todo item is archived, remove the corresponding file from the sandboxed fi lesystem. Add an "open" link on each Todo that has an associated file. When the item is clicked and the file exists in the sandboxed filesystem, use t he Chrome App <a href="fileSystem.html">Filesystem API</a> to request a writable FileEntry from the user. Save the file data from the sandboxed filesystem into that entry.</p> | 410 <p>The current code only saves the file reference, but it doesn't open the f ile. Using the <a href="http://www.html5rocks.com/en/tutorials/file/filesystem/" >HTML5 Filesystem API</a>, save the file contents in a sandboxed filesystem. Whe n the Todo item is archived, remove the corresponding file from the sandboxed fi lesystem. Add an "open" link on each Todo that has an associated file. When the item is clicked and the file exists in the sandboxed filesystem, use t he Chrome App <a href="fileSystem">Filesystem API</a> to request a writable File Entry from the user. Save the file data from the sandboxed filesystem into that entry.</p> |
411 | 411 |
412 <p class="note"><b>Tip:</b> managing file entries using the raw HTML5 Filesyste m API is not trivial. You might want to use a wrapper library, like Eric Bidelma n's <a href="https://github.com/ebidel/filer.js">filer.js</a>.</p> | 412 <p class="note"><b>Tip:</b> managing file entries using the raw HTML5 Filesyste m API is not trivial. You might want to use a wrapper library, like Eric Bidelma n's <a href="https://github.com/ebidel/filer.js">filer.js</a>.</p> |
413 | 413 |
414 <h2 id="takeaways_">Takeaways</h2> | 414 <h2 id="takeaways_">Takeaways</h2> |
415 | 415 |
416 <ul> | 416 <ul> |
417 <li><p>Use <a href="storage.html">chrome.storage.sync</a> to save small data tha t you need to be sync'ed among devices, like configuration options, applicat ion state, etc. The sync is automatic, as long as the same user is logged into C hrome on all devices.</p></li> | 417 <li><p>Use <a href="storage">chrome.storage.sync</a> to save small data that you need to be sync'ed among devices, like configuration options, application s tate, etc. The sync is automatic, as long as the same user is logged into Chrome on all devices.</p></li> |
418 <li><p>Chrome Apps support almost all HTML5 APIs, such as drag and drop. | 418 <li><p>Chrome Apps support almost all HTML5 APIs, such as drag and drop. |
419 HTML Filesystem API is also supported, with extra features from the Chrome App&# 39;s | 419 HTML Filesystem API is also supported, with extra features from the Chrome App&# 39;s |
420 <a href="fileSystem.html">Filesystem API</a>, | 420 <a href="fileSystem">Filesystem API</a>, |
421 like asking the user to pick files on her local disk for read and write. | 421 like asking the user to pick files on her local disk for read and write. |
422 The vanilla HTML5 Filesystem API only allows access to a sandboxed filesystem.</ p></li> | 422 The vanilla HTML5 Filesystem API only allows access to a sandboxed filesystem.</ p></li> |
423 </ul> | 423 </ul> |
424 | 424 |
425 <h2 id="you_should_also_read">You should also read</h2> | 425 <h2 id="you_should_also_read">You should also read</h2> |
426 | 426 |
427 <p><a href="app_storage.html">Manage Data</a> tutorial</p> | 427 <p><a href="app_storage">Manage Data</a> tutorial</p> |
428 | 428 |
429 <h2 id="what_39_s_next_">What's next?</h2> | 429 <h2 id="what_39_s_next_">What's next?</h2> |
430 | 430 |
431 <p>In <a href="app_codelab6_lifecycle.html">5 - Manage App Lifecycle</a>, | 431 <p>In <a href="app_codelab6_lifecycle">5 - Manage App Lifecycle</a>, |
432 you will learn the basics of the Chrome App lifecycle. </p> | 432 you will learn the basics of the Chrome App lifecycle. </p> |
OLD | NEW |