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

Side by Side Diff: chrome/browser/resources/md_extensions/manager.js

Issue 1913353002: [MD Extensions] Add a details subpage, move to one list (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unneeded method Created 4 years, 7 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('extensions', function() { 5 cr.define('extensions', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Compares two extensions to determine which should come first in the list. 9 * Compares two extensions to determine which should come first in the list.
10 * @param {chrome.developerPrivate.ExtensionInfo} a 10 * @param {chrome.developerPrivate.ExtensionInfo} a
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 extensions: { 53 extensions: {
54 type: Array, 54 type: Array,
55 value: function() { return []; }, 55 value: function() { return []; },
56 }, 56 },
57 57
58 /** @type {!Array<!chrome.developerPrivate.ExtensionInfo>} */ 58 /** @type {!Array<!chrome.developerPrivate.ExtensionInfo>} */
59 apps: { 59 apps: {
60 type: Array, 60 type: Array,
61 value: function() { return []; }, 61 value: function() { return []; },
62 }, 62 },
63
64 /** @type {!Array<!chrome.developerPrivate.ExtensionInfo>} */
65 websites: {
66 type: Array,
67 value: function() { return []; },
68 },
69 }, 63 },
70 64
71 behaviors: [ 65 behaviors: [
72 I18nBehavior, 66 I18nBehavior,
73 ], 67 ],
74 68
69 listeners: {
70 'items-list.extension-item-show-details': 'showItemDetails_',
71 },
72
75 created: function() { 73 created: function() {
76 this.readyPromiseResolver = new PromiseResolver(); 74 this.readyPromiseResolver = new PromiseResolver();
77 }, 75 },
78 76
79 ready: function() { 77 ready: function() {
80 /** @type {extensions.Sidebar} */ 78 /** @type {extensions.Sidebar} */
81 this.sidebar = 79 this.sidebar =
82 /** @type {extensions.Sidebar} */(this.$$('extensions-sidebar')); 80 /** @type {extensions.Sidebar} */(this.$$('extensions-sidebar'));
83 this.scrollHelper_ = new ScrollHelper(this); 81 this.listHelper_ = new ListHelper(this);
84 this.sidebar.setScrollDelegate(this.scrollHelper_); 82 this.sidebar.setListDelegate(this.listHelper_);
85 this.$.toolbar.setSearchDelegate(new SearchHelper(this)); 83 this.$.toolbar.setSearchDelegate(new SearchHelper(this));
86 this.readyPromiseResolver.resolve(); 84 this.readyPromiseResolver.resolve();
87 }, 85 },
88 86
89 /** 87 /**
90 * @param {chrome.developerPrivate.ExtensionType} type The type of item. 88 * @param {chrome.developerPrivate.ExtensionType} type The type of item.
91 * @return {string} The ID of the list that the item belongs in. 89 * @return {string} The ID of the list that the item belongs in.
92 * @private 90 * @private
93 */ 91 */
94 getListId_: function(type) { 92 getListId_: function(type) {
95 var listId; 93 var listId;
96 var ExtensionType = chrome.developerPrivate.ExtensionType; 94 var ExtensionType = chrome.developerPrivate.ExtensionType;
97 switch (type) { 95 switch (type) {
98 case ExtensionType.HOSTED_APP: 96 case ExtensionType.HOSTED_APP:
99 case ExtensionType.LEGACY_PACKAGED_APP: 97 case ExtensionType.LEGACY_PACKAGED_APP:
100 listId = 'websites';
101 break;
102 case ExtensionType.PLATFORM_APP: 98 case ExtensionType.PLATFORM_APP:
103 listId = 'apps'; 99 listId = 'apps';
104 break; 100 break;
105 case ExtensionType.EXTENSION: 101 case ExtensionType.EXTENSION:
106 case ExtensionType.SHARED_MODULE: 102 case ExtensionType.SHARED_MODULE:
107 listId = 'extensions'; 103 listId = 'extensions';
108 break; 104 break;
109 case ExtensionType.THEME: 105 case ExtensionType.THEME:
110 assertNotReached( 106 assertNotReached(
111 'Don\'t send themes to the chrome://extensions page'); 107 'Don\'t send themes to the chrome://extensions page');
112 break; 108 break;
113 } 109 }
114 assert(listId); 110 assert(listId);
115 return listId; 111 return listId;
116 }, 112 },
117 113
118 /** 114 /**
119 * @param {string} listId The list to look for the item in. 115 * @param {string} listId The list to look for the item in.
120 * @param {string} itemId The id of the item to look for. 116 * @param {string} itemId The id of the item to look for.
121 * @return {number} The index of the item in the list, or -1 if not found. 117 * @return {number} The index of the item in the list, or -1 if not found.
122 * @private 118 * @private
123 */ 119 */
124 getIndexInList_: function(listId, itemId) { 120 getIndexInList_: function(listId, itemId) {
125 return this[listId].findIndex(function(item) { 121 return this[listId].findIndex(function(item) {
126 return item.id == itemId; 122 return item.id == itemId;
127 }); 123 });
128 }, 124 },
129 125
130 /** 126 /**
131 * @param {!Array<!chrome.developerPrivate.ExtensionInfo>} list
132 * @return {boolean} Whether the list should be visible. 127 * @return {boolean} Whether the list should be visible.
Dan Beam 2016/05/03 19:16:49 @private
Devlin 2016/05/03 19:56:55 Done.
133 */ 128 */
134 computeListHidden_: function(list) { 129 computeListHidden_: function() {
135 return list.length == 0; 130 return this.$['items-list'].items.length == 0;
136 }, 131 },
137 132
138 /** 133 /**
139 * Creates and adds a new extensions-item element to the list, inserting it 134 * Creates and adds a new extensions-item element to the list, inserting it
140 * into its sorted position in the relevant section. 135 * into its sorted position in the relevant section.
141 * @param {!chrome.developerPrivate.ExtensionInfo} item The extension 136 * @param {!chrome.developerPrivate.ExtensionInfo} item The extension
142 * the new element is representing. 137 * the new element is representing.
143 */ 138 */
144 addItem: function(item) { 139 addItem: function(item) {
145 var listId = this.getListId_(item.type); 140 var listId = this.getListId_(item.type);
(...skipping 23 matching lines...) Expand all
169 * @param {!chrome.developerPrivate.ExtensionInfo} item The data for the 164 * @param {!chrome.developerPrivate.ExtensionInfo} item The data for the
170 * item to remove. 165 * item to remove.
171 */ 166 */
172 removeItem: function(item) { 167 removeItem: function(item) {
173 var listId = this.getListId_(item.type); 168 var listId = this.getListId_(item.type);
174 var index = this.getIndexInList_(listId, item.id); 169 var index = this.getIndexInList_(listId, item.id);
175 // We should never try and remove a non-existent item. 170 // We should never try and remove a non-existent item.
176 assert(index >= 0); 171 assert(index >= 0);
177 this.splice(listId, index, 1); 172 this.splice(listId, index, 1);
178 }, 173 },
174
175 /**
176 * Shows the detailed view for a given item.
177 * @param {CustomEvent} e
Dan Beam 2016/05/03 19:16:49 awesome! i didn't know CustomEvent was a thing --
Dan Beam 2016/05/03 19:16:49 @private
Devlin 2016/05/03 19:56:55 Another item for your bag o' tricks. ;)
Devlin 2016/05/03 19:56:55 Done.
178 */
179 showItemDetails_: function(e) {
180 this.$['details-view'].set('data', assert(e.detail.element.data));
181 this.$.pages.selected = 1;
182 },
183
184 /** @private */
185 onDetailsViewClose_: function() {
186 this.$.pages.selected = 0;
187 }
179 }); 188 });
180 189
181 /** 190 /**
182 * @param {extensions.Manager} manager 191 * @param {extensions.Manager} manager
183 * @constructor 192 * @constructor
184 * @implements {extensions.SidebarScrollDelegate} 193 * @implements {extensions.SidebarListDelegate}
185 */ 194 */
186 function ScrollHelper(manager) { 195 function ListHelper(manager) {
187 this.items_ = manager.$.items; 196 this.manager_ = manager;
188 } 197 }
189 198
190 ScrollHelper.prototype = { 199 ListHelper.prototype = {
191 /** @override */ 200 /** @override */
192 scrollToExtensions: function() { 201 showType: function(type) {
193 this.items_.scrollTop = 202 var items;
194 this.items_.querySelector('#extensions-list').offsetTop; 203 switch (type) {
195 }, 204 case extensions.ShowingType.EXTENSIONS:
196 205 items = this.manager_.extensions;
197 /** @override */ 206 break;
198 scrollToApps: function() { 207 case extensions.ShowingType.APPS:
199 this.items_.scrollTop = 208 items = this.manager_.apps;
200 this.items_.querySelector('#apps-list').offsetTop; 209 break;
201 }, 210 }
202 211 this.manager_.$['items-list'].set('items', assert(items));
203 /** @override */ 212 }
204 scrollToWebsites: function() {
205 this.items_.scrollTop =
206 this.items_.querySelector('#websites-list').offsetTop;
207 },
208 }; 213 };
209 214
210 /** 215 /**
211 * @param {extensions.Manager} manager 216 * @param {extensions.Manager} manager
212 * @constructor 217 * @constructor
213 * @implements {SearchFieldDelegate} 218 * @implements {SearchFieldDelegate}
214 */ 219 */
215 function SearchHelper(manager) { 220 function SearchHelper(manager) {
216 this.manager_ = manager; 221 this.manager_ = manager;
217 } 222 }
218 223
219 SearchHelper.prototype = { 224 SearchHelper.prototype = {
220 /** @override */ 225 /** @override */
221 onSearchTermSearch: function(searchTerm) { 226 onSearchTermSearch: function(searchTerm) {
222 this.manager_.filter = searchTerm; 227 this.manager_.filter = searchTerm;
223 }, 228 },
224 }; 229 };
225 230
226 return {Manager: Manager}; 231 return {Manager: Manager};
227 }); 232 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698