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

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: Michael's 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
« no previous file with comments | « no previous file | chrome/browser/resources/md_extensions/service.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
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: {
36 /** @type {extensions.Sidebar} */
10 sidebar: { 37 sidebar: {
11 type: Object, 38 type: Object,
12 } 39 }
13 }, 40 },
14 41
15 ready: function() { 42 ready: function() {
43 /** @type {extensions.Sidebar} */
16 this.sidebar = this.$$('extensions-sidebar'); 44 this.sidebar = this.$$('extensions-sidebar');
17 extensions.Service.getInstance().managerReady(this); 45 extensions.Service.getInstance().managerReady(this);
18 this.sidebar.setScrollDelegate(new ScrollHelper(this)); 46 this.sidebar.setScrollDelegate(new ScrollHelper(this));
19 }, 47 },
20 48
21 /** 49 /**
22 * Creates and adds a new extensions-item element to the list. 50 * Creates and adds a new extensions-item element to the list, inserting it
51 * into its sorted position in the relevant section.
23 * @param {!chrome.developerPrivate.ExtensionInfo} extension The extension 52 * @param {!chrome.developerPrivate.ExtensionInfo} extension The extension
24 * the item is representing. 53 * the item is representing.
25 * @param {!extensions.ItemDelegate} delegate The delegate for the item. 54 * @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 */ 55 */
29 addItem: function(extension, delegate, opt_index) { 56 addItem: function(extension, delegate) {
30 var listId; 57 var listId;
31 var ExtensionType = chrome.developerPrivate.ExtensionType; 58 var ExtensionType = chrome.developerPrivate.ExtensionType;
32 switch (extension.type) { 59 switch (extension.type) {
33 case ExtensionType.HOSTED_APP: 60 case ExtensionType.HOSTED_APP:
34 case ExtensionType.LEGACY_PACKAGED_APP: 61 case ExtensionType.LEGACY_PACKAGED_APP:
35 listId = 'websites-list'; 62 listId = 'websites-list';
36 break; 63 break;
37 case ExtensionType.PLATFORM_APP: 64 case ExtensionType.PLATFORM_APP:
38 listId = 'apps-list'; 65 listId = 'apps-list';
39 break; 66 break;
40 case ExtensionType.EXTENSION: 67 case ExtensionType.EXTENSION:
41 case ExtensionType.SHARED_MODULE: 68 case ExtensionType.SHARED_MODULE:
42 listId = 'extensions-list'; 69 listId = 'extensions-list';
43 break; 70 break;
44 case ExtensionType.THEME: 71 case ExtensionType.THEME:
45 assertNotReached( 72 assertNotReached(
46 'Don\'t send themes to the chrome://extensions page'); 73 'Don\'t send themes to the chrome://extensions page');
47 break; 74 break;
48 } 75 }
49 assert(listId); 76 assert(listId);
50 var extensionItem = new extensions.Item(extension, delegate); 77 var extensionItem = new extensions.Item(extension, delegate);
51 var itemList = this.$[listId]; 78 var itemList = this.$[listId];
52 var refNode = opt_index !== undefined ? 79
53 itemList.children[opt_index] : undefined; 80 var insertBeforeChild = Array.prototype.find.call(itemList.children,
54 itemList.insertBefore(extensionItem, refNode); 81 function(item) {
82 return compareExtensions(item.data, extension) > 0;
83 });
84 itemList.insertBefore(extensionItem, insertBeforeChild);
55 }, 85 },
56 86
57 /** 87 /**
58 * @param {string} id The id of the extension to get the item for. 88 * @param {string} id The id of the extension to get the item for.
59 * @return {?extensions.Item} 89 * @return {?extensions.Item}
60 */ 90 */
61 getItem: function(id) { 91 getItem: function(id) {
62 return this.$$('#' + id); 92 return this.$$('#' + id);
63 }, 93 },
64 94
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 135
106 /** @override */ 136 /** @override */
107 scrollToWebsites: function() { 137 scrollToWebsites: function() {
108 this.items_.scrollTop = 138 this.items_.scrollTop =
109 this.items_.querySelector('#websites-header').offsetTop; 139 this.items_.querySelector('#websites-header').offsetTop;
110 }, 140 },
111 }; 141 };
112 142
113 return {Manager: Manager}; 143 return {Manager: Manager};
114 }); 144 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_extensions/service.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698