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

Side by Side Diff: chrome/browser/resources/offline_pages/offline_internals.js

Issue 2003883002: [Offline pages] Create offline internals page for Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix minor spelling mishaps Created 4 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('offlineInternals', function() {
6 'use strict';
7
8 var STORED_PAGE_ATTRIBUTES = ['onlineUrl', 'namespace', 'size'];
9 var QUEUE_ATTRIBUTES = ['onlineUrl', 'creation time', 'status'];
Dan Beam 2016/05/31 22:00:59 can you potentially using closure compilation type
chili 2016/06/02 02:38:53 Done.
10
11 /**
12 * Clear the specified table.
Dan Beam 2016/05/31 22:00:59 @param
chili 2016/06/02 02:38:53 Done.
13 */
14 function clearTable(tableId) {
15 var element = $(tableId);
16
17 element.textContent = '';
Dan Beam 2016/05/31 22:00:59 nit: $(tableId).textContent = '';
chili 2016/06/02 02:38:53 Done.
18 }
19
20 /**
21 * Fill stored pages table.
22 * @param {HTMLElement} element A HTML element
23 * @param {!Array} data An array object representing stored offline pages
Dan Beam 2016/05/31 22:00:59 nit: end with .
chili 2016/06/02 02:38:53 Done.
24 */
25 function fillStoredPages(element, data) {
26 for (var i = 0; i < data.length; i++) {
27 var row = document.createElement('tr');
Dan Beam 2016/05/31 22:00:59 indent off
chili 2016/06/02 02:38:54 Done.
28
29 var checkboxCell = document.createElement('td');
30 var checkbox = document.createElement('input');
31 checkbox.setAttribute('type', 'checkbox');
32 checkbox.setAttribute('name', 'stored');
33 checkbox.setAttribute('value', data[i]['id']);
Dan Beam 2016/05/31 22:00:59 nit: ['id'] -> .id
chili 2016/06/02 02:38:53 Done.
34
35 checkboxCell.appendChild(checkbox);
36 row.appendChild(checkboxCell);
37
38 for (let key of STORED_PAGE_ATTRIBUTES) {
39 var cell = document.createElement('td');
40 cell.textContent = data[i][key];
41 row.appendChild(cell);
42 }
43 element.appendChild(row);
44 }
45 }
46
47 /**
48 * Fill requests table.
49 * @param {HTMLElement} element A HTML element
50 * @param {!Array} data An array object representing the request queue
51 */
52 function fillRequestQueue(element, data) {
53 for (var i = 0; i < data.length; i++) {
54 var row = document.createElement('tr');
55
56 for (let key of QUEUE_ATTRIBUTES) {
57 var cell = document.createElement('td');
58 cell.textContent = data[i][key];
59 row.appendChild(cell);
60 }
61 element.appendChild(row);
62 }
63 }
64
65 /**
66 * Refresh all displayed information.
67 */
68 function refreshAll() {
69 chrome.send('getOfflineInternalsInfo');
70 }
71
72 /**
73 * Delete all pages in the offline store.
74 */
75 function deleteAllPages() {
76 chrome.send('deleteAllPages');
77 }
78
79 /**
80 * Callback when pages are deleted.
81 */
82 function pagesDeleted() {
83 // TODO(chili): decide what to do here. Perhaps a refresh of just
84 // the stored pages table?
85 }
86
87 /**
88 * Callback when information is loaded.
89 * @param {{AllPages: !Array, Queue:!Array}} info An object containing both
Dan Beam 2016/05/31 22:00:59 Queue: !Array
chili 2016/06/02 02:38:53 Done.
90 * stored pages and request queue status.
91 */
92 function setOfflineInternalsInfo(info) {
93 clearTable('stored-pages');
94 clearTable('request-queue');
95
96 fillStoredPages($('stored-pages'), info.AllPages);
97 fillRequestQueue($('request-queue'), info.Queue);
98 }
99
100 /**
101 * Delete selected pages from the offline store.
102 */
103 function deleteSelectedPages() {
104 var selectedIds = new Array();
Dan Beam 2016/05/31 22:00:59 new Array() -> []
chili 2016/06/02 02:38:54 Done.
105 var checkboxes = document.getElementsByName('stored');
106
107 for (let box of checkboxes) {
108 if (box.checked) {
Dan Beam 2016/05/31 22:00:59 no curlies
chili 2016/06/02 02:38:53 Java-land habit >"< Done
109 selectedIds.push(box.value);
110 }
111 }
Dan Beam 2016/05/31 22:00:59 nit: if you're gonna use ES6... var selectedIds =
chili 2016/06/02 02:38:54 I don't think this works, because checkboxes is a
dpapad 2016/06/02 17:33:16 Drive-by suggestion. If you want to take advantage
112
113 chrome.send('deleteSelectedPages', [selectedIds]);
Dan Beam 2016/05/31 22:00:59 instead of doing this dance where you say chrome.
chili 2016/06/02 02:38:53 Done.
114 }
115
116 function initialize() {
117 $('clear-all').onclick = deleteAllPages;
118 $('clear-selected').onclick = deleteSelectedPages;
119 $('refresh').onclick = refreshAll;
120 chrome.send('getOfflineInternalsInfo');
121 }
122
123 // Return an object with all of the exports.
124 return {
125 initialize: initialize,
Dan Beam 2016/05/31 22:00:59 why is `initialize` externally exposed?
chili 2016/06/02 02:38:53 Because otherwise I can't seem to call offlineInte
126 setOfflineInternalsInfo: setOfflineInternalsInfo,
127 pagesDeleted: pagesDeleted
128 };
129 });
130
131 document.addEventListener('DOMContentLoaded', offlineInternals.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698