Skip to content

Commit 7962fc1

Browse files
author
p01
committed
Moved the groupOrder to cls.ResourceTreeView and initialize all the default collapsed flags
1 parent 7a60218 commit 7962fc1

File tree

3 files changed

+54
-40
lines changed

3 files changed

+54
-40
lines changed

src/resource-manager/resource_service.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ cls.ResourceManagerService = function(view, network_logger)
7676
}
7777

7878
var ctx = {};
79+
80+
// get the order of the groups of resources
81+
ctx.groupOrder = this._view.get_group_order();
82+
7983
// get list of window_contexts for which we saw the main_document
8084
ctx.windowList = (this._network_logger.get_window_contexts()||[])
8185
.filter(function(w)
@@ -98,7 +102,6 @@ cls.ResourceManagerService = function(view, network_logger)
98102
var windowID_index = {};
99103
ctx.windowList.forEach(function(w,i){ windowID_index[w.id] = i; });
100104

101-
102105
var documentID_index = {};
103106
// filter the documentId that belong in the windowIdList
104107
ctx.documentList = this._documentList
@@ -116,9 +119,18 @@ cls.ResourceManagerService = function(view, network_logger)
116119

117120
// set depth, pivotID and sameOrigin
118121
var p = a[ documentID_index[ d.parentDocumentID ] ]||{pivotID:d.windowID,depth:0};
122+
var id = p.pivotID+'_'+d.documentID;
119123
d.depth = p.depth+1;
120-
d.pivotID = p.pivotID+'_'+d.documentID;
124+
d.pivotID = id;
121125
d.sameOrigin = cls.ResourceUtil.sameOrigin(p.url, d.url);
126+
127+
// set the default collapsed flag
128+
var hash = this. _collapsedHash;
129+
if (!hash.hasOwnProperty(id))
130+
{
131+
hash[id] = d.depth>1;
132+
ctx.groupOrder.forEach( function(g){ hash[id+'_'+g] = true; } );
133+
}
122134
}
123135

124136
return inContext;

src/resource-manager/resource_templates.js

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,6 @@ templates.resource_icon = function(resource)
77

88
templates.resource_tree =
99
{
10-
_groupOrder:
11-
[
12-
ui_strings.S_HTTP_LABEL_FILTER_MARKUP,
13-
ui_strings.S_HTTP_LABEL_FILTER_STYLESHEETS,
14-
ui_strings.S_HTTP_LABEL_FILTER_SCRIPTS,
15-
ui_strings.S_HTTP_LABEL_FILTER_IMAGES,
16-
ui_strings.S_HTTP_LABEL_FILTER_FONTS,
17-
ui_strings.S_HTTP_LABEL_FILTER_OTHER
18-
],
19-
2010
URL_MATCH_CONTEXT_SIZE: 10,
2111
DEPTH_IDENTATION: 18,
2212
DISTINGUISHER_MAX_LENGTH: 64,
@@ -33,35 +23,33 @@ templates.resource_tree =
3323
_expander_extras:function(context, pivotID, depth)
3424
{
3525
var hash = context.collapsed;
26+
27+
// expand all pivots when searching
3628
if (context.searchTerm != '')
3729
hash[pivotID] = false;
38-
else if (!hash.hasOwnProperty(pivotID))
39-
hash[pivotID] = depth>1;
4030

4131
var collapsed = hash[pivotID];
4232

43-
return ({
44-
collapsed:collapsed,
45-
tpl:
46-
{
47-
li:
48-
[
49-
'data-expand-collapse-id', pivotID,
50-
'class', 'resource-tree-expand-collapse'+(collapsed?' close':'')
51-
],
52-
h2:
53-
[
54-
'handler','resources-expand-collapse'
55-
],
56-
button:
57-
[
58-
'input',
59-
'type','button',
60-
'class','button-expand-collapse',
61-
'style', 'margin-left:'+ depth*this.DEPTH_IDENTATION +'px;'
62-
]
63-
}
64-
});
33+
var tpl = {};
34+
35+
tpl.h2 = ['handler', 'resources-expand-collapse'];
36+
tpl.li =
37+
[
38+
'data-expand-collapse-id', pivotID,
39+
'class', 'resource-tree-expand-collapse'+(collapsed?' close':'')
40+
];
41+
tpl.button =
42+
[
43+
'input',
44+
'type','button',
45+
'class','button-expand-collapse'
46+
];
47+
48+
if(depth)
49+
tpl.button.push('style', 'margin-left:'+ depth*this.DEPTH_IDENTATION +'px;');
50+
51+
52+
return { collapsed:collapsed, tpl:tpl };
6553
},
6654

6755
update:function(context)
@@ -169,7 +157,7 @@ templates.resource_tree =
169157

170158
resource_groups:function(context, resources, d)
171159
{
172-
var tpl = this._groupOrder
160+
var tpl = context.groupOrder
173161
.map( this.resource_group.bind(this, context, resources, d) )
174162
.filter(function(v){
175163
return v!=null;
@@ -195,7 +183,8 @@ templates.resource_tree =
195183
if (!resources.length)
196184
return [];
197185

198-
var extras = this._expander_extras( context, d.pivotID+'_'+g, d.depth+1);
186+
var depth = d.depth+1;
187+
var extras = this._expander_extras( context, d.pivotID+'_'+g, depth);
199188

200189
var tpl =
201190
['li',
@@ -212,7 +201,7 @@ templates.resource_tree =
212201
],
213202
'class','resource-tree-group resource-tree-group-'+g.toLowerCase()
214203
].concat( extras.tpl.h2 ),
215-
extras.collapsed?[]:this.resources(context, resources, d.depth+2)
204+
extras.collapsed?[]:this.resources(context, resources, depth+1)
216205
].concat( extras.tpl.li );
217206

218207
return tpl;

src/resource-manager/resource_tree_view.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
1313

1414
// const
1515
const THROTTLE_DELAY = 250;
16+
const GROUP_ORDER =
17+
[
18+
ui_strings.S_HTTP_LABEL_FILTER_MARKUP,
19+
ui_strings.S_HTTP_LABEL_FILTER_STYLESHEETS,
20+
ui_strings.S_HTTP_LABEL_FILTER_SCRIPTS,
21+
ui_strings.S_HTTP_LABEL_FILTER_IMAGES,
22+
ui_strings.S_HTTP_LABEL_FILTER_FONTS,
23+
ui_strings.S_HTTP_LABEL_FILTER_OTHER
24+
];
1625

1726
// "private"
1827
this._service = new cls.ResourceManagerService(this, network_logger);
1928
this._loading = false;
2029

2130
// public
31+
this.get_group_order = function()
32+
{
33+
return GROUP_ORDER;
34+
};
2235

2336
// throttle the update
2437
this.update = this.update.bind(this).throttle(THROTTLE_DELAY);
@@ -60,7 +73,7 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
6073
);
6174
}
6275

63-
// only render it if the template has changed ( using its JSON representation as hash )
76+
// only render the template if it has changed ( using its JSON representation as hash )
6477
var tpl_JSON = JSON.stringify(tpl);
6578
if( !this.tpl_JSON || tpl_JSON.length != this.tpl_JSON.length || tpl_JSON != this.tpl_JSON)
6679
{

0 commit comments

Comments
 (0)