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

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

Issue 1447183005: [MD Extensions] Fix item sorting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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';
7
8 /**
9 * Compares two extensions to determine which should come first in the list.
Devlin 2015/11/18 00:38:57 note: copy-paste from service.js
10 * @param {chrome.developerPrivate.ExtensionInfo} a
11 * @param {chrome.developerPrivate.ExtensionInfo} b
12 * @return {number}
13 */
14 var compareExtensions = function(a, b) {
15 function compare(x, y) {
16 return x < y ? -1 : (x > y ? 1 : 0);
17 }
18 function compareLocation(x, y) {
19 if (x.location == y.location)
20 return 0;
21 if (x.location == chrome.developerPrivate.Location.UNPACKED)
22 return -1;
23 if (y.location == chrome.developerPrivate.Location.UNPACKED)
24 return 1;
25 return 0;
26 }
27 return compareLocation(a, b) ||
28 compare(a.name.toLowerCase(), b.name.toLowerCase()) ||
29 compare(a.id, b.id);
30 };
31
6 var Manager = Polymer({ 32 var Manager = Polymer({
7 is: 'extensions-manager', 33 is: 'extensions-manager',
8 34
9 properties: { 35 properties: {
10 sidebar: { 36 sidebar: {
michaelpg 2015/11/18 09:08:45 /** @type {extensions.Sidebar} */
Devlin 2015/11/18 17:16:59 Ah, didn't realize that worked. Done.
11 type: Object, 37 type: Object,
12 } 38 }
13 }, 39 },
14 40
15 ready: function() { 41 ready: function() {
42 /** @type {extensions.Sidebar} */
16 this.sidebar = this.$$('extensions-sidebar'); 43 this.sidebar = this.$$('extensions-sidebar');
17 extensions.Service.getInstance().managerReady(this); 44 extensions.Service.getInstance().managerReady(this);
18 this.sidebar.setScrollDelegate(new ScrollHelper(this)); 45 this.sidebar.setScrollDelegate(new ScrollHelper(this));
19 }, 46 },
20 47
21 /** 48 /**
22 * Creates and adds a new extensions-item element to the list. 49 * Creates and adds a new extensions-item element to the list.
michaelpg 2015/11/18 09:08:45 nit: ", inserting it into its sorted position in t
Devlin 2015/11/18 17:16:59 Done.
23 * @param {!chrome.developerPrivate.ExtensionInfo} extension The extension 50 * @param {!chrome.developerPrivate.ExtensionInfo} extension The extension
24 * the item is representing. 51 * the item is representing.
25 * @param {!extensions.ItemDelegate} delegate The delegate for the item. 52 * @param {!extensions.ItemDelegate} delegate The delegate for the item.
26 * @param {!number=} opt_index The index at which to place the item. If
27 * not present, the item is appended to the end of the list.
28 */ 53 */
29 addItem: function(extension, delegate, opt_index) { 54 addItem: function(extension, delegate) {
30 var listId; 55 var listId;
31 var ExtensionType = chrome.developerPrivate.ExtensionType; 56 var ExtensionType = chrome.developerPrivate.ExtensionType;
32 switch (extension.type) { 57 switch (extension.type) {
33 case ExtensionType.HOSTED_APP: 58 case ExtensionType.HOSTED_APP:
34 case ExtensionType.LEGACY_PACKAGED_APP: 59 case ExtensionType.LEGACY_PACKAGED_APP:
35 listId = 'websites-list'; 60 listId = 'websites-list';
36 break; 61 break;
37 case ExtensionType.PLATFORM_APP: 62 case ExtensionType.PLATFORM_APP:
38 listId = 'apps-list'; 63 listId = 'apps-list';
39 break; 64 break;
40 case ExtensionType.EXTENSION: 65 case ExtensionType.EXTENSION:
41 case ExtensionType.SHARED_MODULE: 66 case ExtensionType.SHARED_MODULE:
42 listId = 'extensions-list'; 67 listId = 'extensions-list';
43 break; 68 break;
44 case ExtensionType.THEME: 69 case ExtensionType.THEME:
45 assertNotReached( 70 assertNotReached(
46 'Don\'t send themes to the chrome://extensions page'); 71 'Don\'t send themes to the chrome://extensions page');
47 break; 72 break;
48 } 73 }
49 assert(listId); 74 assert(listId);
50 var extensionItem = new extensions.Item(extension, delegate); 75 var extensionItem = new extensions.Item(extension, delegate);
51 var itemList = this.$[listId]; 76 var itemList = this.$[listId];
52 var refNode = opt_index !== undefined ? 77
53 itemList.children[opt_index] : undefined; 78 var insertBeforeChild = Array.prototype.find.call(itemList.children,
54 itemList.insertBefore(extensionItem, refNode); 79 function(item) {
80 return compareExtensions(item.data, extension) > 0;
81 });
82 itemList.insertBefore(extensionItem, insertBeforeChild);
55 }, 83 },
56 84
57 /** 85 /**
58 * @param {string} id The id of the extension to get the item for. 86 * @param {string} id The id of the extension to get the item for.
59 * @return {?extensions.Item} 87 * @return {?extensions.Item}
60 */ 88 */
61 getItem: function(id) { 89 getItem: function(id) {
62 return this.$$('#' + id); 90 return this.$$('#' + id);
63 }, 91 },
64 92
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 133
106 /** @override */ 134 /** @override */
107 scrollToWebsites: function() { 135 scrollToWebsites: function() {
108 this.items_.scrollTop = 136 this.items_.scrollTop =
109 this.items_.querySelector('#websites-header').offsetTop; 137 this.items_.querySelector('#websites-header').offsetTop;
110 }, 138 },
111 }; 139 };
112 140
113 return {Manager: Manager}; 141 return {Manager: Manager};
114 }); 142 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_extensions/service.js » ('j') | chrome/browser/resources/md_extensions/service.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698