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

Side by Side Diff: chrome/browser/resources/md_bookmarks/util.js

Issue 2722083002: [MD Bookmarks] Flatten sidebar. (Closed)
Patch Set: Created 3 years, 9 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 /** 5 /**
6 * @fileoverview Utility functions for the Bookmarks page. 6 * @fileoverview Utility functions for the Bookmarks page.
7 */ 7 */
8 8
9 cr.define('bookmarks.util', function() { 9 cr.define('bookmarks.util', function() {
10 /** 10 /**
(...skipping 30 matching lines...) Expand all
41 childIds.push(child.id); 41 childIds.push(child.id);
42 queue.push(child); 42 queue.push(child);
43 }); 43 });
44 node.children = childIds; 44 node.children = childIds;
45 } 45 }
46 } 46 }
47 47
48 return nodeMap; 48 return nodeMap;
49 } 49 }
50 50
51 function initializeSidebar(rootNodeId, nodes) {
52 var folders = [];
53
54 var calculateFoldersBelow = function(nodeId, depth) {
55 var node = nodes[nodeId];
56 if (!node.children)
57 return;
58
59 folders.push({
60 id: node.id,
61 depth: depth,
62 visible: true,
63 open: true,
64 });
65 node.children.forEach(function(childId) {
66 calculateFoldersBelow(childId, depth + 1);
67 });
68 };
69
70 calculateFoldersBelow(rootNodeId, -1);
71
72 // Remove the root node.
73 folders.shift();
74 return {
75 folders: folders,
76 folderMap: createFolderMap(folders),
77 };
78 }
79
80 /**
81 * @param {!Array<SidebarFolder>} folders
82 * @return {!Object<string, number>}
83 */
84 function createFolderMap(folders) {
85 var folderMap = {};
86 folders.forEach(function(folder, idx) {
87 folderMap[folder.id] = idx;
88 });
89 return folderMap;
90 };
91
51 /** @return {BookmarksPageState} */ 92 /** @return {BookmarksPageState} */
52 function createEmptyState() { 93 function createEmptyState() {
53 return { 94 return {
54 nodes: {}, 95 nodes: {},
55 selectedFolder: '0', 96 selectedFolder: '0',
56 closedFolders: {},
57 search: { 97 search: {
58 term: '', 98 term: '',
59 inProgress: false, 99 inProgress: false,
60 results: [], 100 results: [],
61 }, 101 },
62 selection: { 102 selection: {
63 items: {}, 103 items: {},
64 anchor: null, 104 anchor: null,
65 count: 0, 105 count: 0,
66 }, 106 },
107 sidebar: {
108 folders: [],
109 folderMap: {},
110 },
67 }; 111 };
68 } 112 }
69 113
70 return { 114 return {
71 createEmptyState: createEmptyState, 115 createEmptyState: createEmptyState,
116 createFolderMap: createFolderMap,
72 getDisplayedList: getDisplayedList, 117 getDisplayedList: getDisplayedList,
118 initializeSidebar: initializeSidebar,
73 normalizeNodes: normalizeNodes, 119 normalizeNodes: normalizeNodes,
74 }; 120 };
75 }); 121 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/types.js ('k') | chrome/test/data/webui/md_bookmarks/reducers_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698