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

Unified Diff: chrome/browser/resources/md_bookmarks/store.js

Issue 2614703003: [MD Bookmarks] Add search. (Closed)
Patch Set: Fix bug in remove non-empty folder from search list. Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_bookmarks/store.js
diff --git a/chrome/browser/resources/md_bookmarks/store.js b/chrome/browser/resources/md_bookmarks/store.js
index bdbcb2ebd10de8400a8af2ac44628d861266aede..2d171fd04133552e35b37881139ed9dce51927c9 100644
--- a/chrome/browser/resources/md_bookmarks/store.js
+++ b/chrome/browser/resources/md_bookmarks/store.js
@@ -14,13 +14,23 @@ var BookmarksStore = Polymer({
selectedId: {
tsergeant 2017/01/12 23:44:20 I think you'll need to put /** @type {?string} */
angelayang 2017/01/13 00:25:11 yep that works thankyou
type: String,
- observer: 'updateSelectedNode_',
+ observer: 'updateSelectedDisplay_',
notify: true,
tsergeant 2017/01/12 23:44:21 While you're here: selectedId is public, but neve
angelayang 2017/01/13 00:25:11 left public for URL/router
},
- /** @type {BookmarkTreeNode} */
- selectedNode: {
- type: Object,
+ searchTerm: {
+ type: String,
+ observer: 'updateSearchDisplay_',
+ notify: true,
+ },
+
+ /**
+ * This updates to either the result of a search or the contents of the
+ * selected folder.
+ * @type {Array<BookmarkTreeNode>}
+ */
+ displayedList: {
+ type: Array,
notify: true,
readOnly: true,
},
@@ -36,6 +46,7 @@ var BookmarksStore = Polymer({
this.documentListeners_ = {
'selected-folder-changed': this.onSelectedFolderChanged_.bind(this),
'folder-open-changed': this.onFolderOpenChanged_.bind(this),
+ 'search-term-changed': this.onSearchTermChanged_.bind(this),
};
for (var event in this.documentListeners_)
document.addEventListener(event, this.documentListeners_[event]);
@@ -76,20 +87,49 @@ var BookmarksStore = Polymer({
this.fire('selected-folder-changed', this.rootNode.children[0].id);
},
+ /** @private */
+ deselectFolders_: function() {
+ this.unlinkPaths('displayedList');
+ this.set(this.idToNodeMap_[this.selectedId].path + '.isSelected', false);
+ this.selectedId = null;
angelayang 2017/01/12 07:51:24 This is the closure compilation error. ## foun
angelayang 2017/01/13 00:25:11 Done.
+ },
+
/**
* @param {BookmarkTreeNode} folder
* @private
* @return {boolean}
*/
isAncestorOfSelected_: function(folder) {
- return this.selectedNode.path.startsWith(folder.path);
+ if (!this.selectedId)
+ return false;
+
+ var selectedNode = this.idToNodeMap_[this.selectedId];
+ return selectedNode.path.startsWith(folder.path);
+ },
+
+ /** @private */
+ updateSearchDisplay_: function() {
+ if (this.searchTerm == '') {
+ this.fire('selected-folder-changed', this.rootNode.children[0].id);
+ } else {
+ chrome.bookmarks.search(this.searchTerm, function(results) {
+ if (this.selectedId)
+ this.deselectFolders_();
+
+ this._setDisplayedList(results);
+ }.bind(this));
+ }
},
/** @private */
- updateSelectedNode_: function() {
+ updateSelectedDisplay_: function() {
+ // Don't change to the selected display if ID was cleared.
+ if (!this.selectedId)
+ return;
+
var selectedNode = this.idToNodeMap_[this.selectedId];
- this.linkPaths('selectedNode', selectedNode.path);
- this._setSelectedNode(selectedNode);
+ this.linkPaths('displayedList', selectedNode.path + '.children');
+ this._setDisplayedList(selectedNode.children);
},
/**
@@ -122,13 +162,18 @@ var BookmarksStore = Polymer({
* node: BookmarkTreeNode}} removeInfo
*/
onBookmarkRemoved_: function(id, removeInfo) {
- if (this.isAncestorOfSelected_(this.idToNodeMap_[id]))
+ if (this.isAncestorOfSelected_(this.idToNodeMap_[id])) {
tsergeant 2017/01/12 23:44:21 No need to add {} here
angelayang 2017/01/13 00:25:11 Done.
this.fire('selected-folder-changed', removeInfo.parentId);
+ }
var parentNode = this.idToNodeMap_[removeInfo.parentId];
this.splice(parentNode.path + '.children', removeInfo.index, 1);
this.removeDescendantsFromMap_(id);
BookmarksStore.generatePaths(parentNode, removeInfo.index);
+
+ // Regenerate the search list if its displayed.
+ if (this.searchTerm)
+ this.updateSearchDisplay_();
},
/**
@@ -147,12 +192,23 @@ var BookmarksStore = Polymer({
// bookmarks-store, bookmarks app event listeners:
/**
+ * @param {Event} e
+ * @private
+ */
+ onSearchTermChanged_: function(e) {
+ this.searchTerm = /** @type {string} */ (e.detail);
+ },
+
+ /**
* Selects the folder specified by the event and deselects the previously
* selected folder.
* @param {CustomEvent} e
* @private
*/
onSelectedFolderChanged_: function(e) {
+ if (this.searchTerm)
+ this.searchTerm = '';
+
// Deselect the old folder if defined.
if (this.selectedId)
this.set(this.idToNodeMap_[this.selectedId].path + '.isSelected', false);

Powered by Google App Engine
This is Rietveld 408576698