Skip to content

Commit e49334e

Browse files
author
p01
committed
cleanup ResourceGroup handling, style tweaks, WIP handler to open individual resources
1 parent a8e8ca4 commit e49334e

File tree

4 files changed

+96
-53
lines changed

4 files changed

+96
-53
lines changed

src/resource-manager/resource_service.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,16 @@ cls.ResourceContext = function(data)
150150
{
151151
var frame = event;
152152
frame.closed = !!event.parentFrameID;
153-
frame.groups = { markup: {closed:true,ids:{}}, css: {closed:true,ids:{}}, script: {closed:true,ids:{}}, image: {closed:true,ids:{}}, other: {closed:true,ids:{}} };
153+
frame.groups =
154+
{
155+
markup: new cls.ResourceGroup('markup'),
156+
css: new cls.ResourceGroup('stylesheets'),
157+
script: new cls.ResourceGroup('scripts'),
158+
image: new cls.ResourceGroup('images'),
159+
font: new cls.ResourceGroup('fonts'),
160+
other: new cls.ResourceGroup('other')
161+
}
162+
154163
this.frames[ event.frameID ] = frame;
155164
return;
156165
}
@@ -160,7 +169,6 @@ cls.ResourceContext = function(data)
160169
{
161170
res = new cls.Resource(event.resourceID);
162171
res.frameID = event.frameID;
163-
// this.resources.push(res);
164172
this.resourcesDict[ res.id ] = res;
165173
}
166174
else if (!res)
@@ -183,8 +191,7 @@ cls.ResourceContext = function(data)
183191
var type = res.type;
184192
if (!frame.groups[type]){ type='other'; }
185193

186-
//if (frame.groups[type].ids.indexOf( res.id )==-1)
187-
frame.groups[type].ids[ res.id ]=1;
194+
frame.groups[type].push( res.id );
188195
}
189196
}
190197

@@ -230,6 +237,27 @@ cls.ResourceContext = function(data)
230237
*/
231238
}
232239

240+
cls.ResourceGroup = function(name)
241+
{
242+
this.ids = [];
243+
this.name = null;
244+
this.closed = true;
245+
246+
this._init = function(name)
247+
{
248+
this.name = name;
249+
this.ids.length = 0;
250+
}
251+
this.push = function( id )
252+
{
253+
if( this.ids.indexOf(id)===-1 )
254+
this.ids.push(id);
255+
}
256+
257+
this._init(name);
258+
}
259+
260+
233261
cls.Resource = function(id)
234262
{
235263
this._init(id);

src/resource-manager/resource_style.css

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
/* WIP style */
174174
.expand-collapse
175175
{
176-
margin:0 0 0 16px;
176+
/* margin:0 0 0 16px;*/
177177
/* background:rgba(0,0,0,.1);*/
178178
}
179179
.expand-collapse > ul
@@ -184,29 +184,40 @@
184184
.expand-collapse > ul > li
185185
{
186186
white-space:nowrap;
187+
padding:0;
188+
margin:0 0 0 16px;
189+
line-height:17px;
187190
}
188191
.expand-collapse.close > ul
189192
{
190193
display:none;
191194
}
192195

193-
.expand-collapse input
196+
.button-expand-collapse
194197
{
195198
background: url("../ui-images/expand-collapse.png") 1px -14px no-repeat transparent;
196199
border: 0px none currentColor;
197200
color: #666666;
198201
height: 13px;
199-
margin: 0px 2px 0px -15px;
202+
/* margin: 0px 2px 0px -15px;*/
203+
margin:0px 2px 0px 0px;
200204
padding: 0px;
201205
width: 13px;
202206
}
203-
.expand-collapse input:focus
207+
.button-expand-collapse:focus
204208
{
205209
outline: 2px solid #598BEC;
206210
outline-offset: -2px;
207211
}
208-
.expand-collapse.close input
212+
.button-expand-collapse.close
209213
{
210214
background-position:1px 1px;
211215
}
212-
.resource-tree li:hover
216+
.resources li:nth-child(2n)
217+
{
218+
background-color:#f8f8f8;
219+
}
220+
.resources li:hover
221+
{
222+
background-color:#D4E3F4;
223+
}

src/resource-manager/resource_templates.js

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,22 @@ templates.resource_tree = function(context)
1111
tpl.push
1212
(
1313
'div',
14-
templates.resource_tree_frame( context, null, 1 ),
14+
templates.resource_tree_frame( context, null ),
1515
'style','background:white;overflow:auto;height:100%;'
1616
);
1717
return tpl;
1818
};
1919

20-
templates.resource_tree_frame = function(context, parentFrameID, depth)
20+
templates.resource_tree_frame = function(context, parentFrameID)
2121
{
22-
var indent = cls.ResourceTestView.instance._getIndentStyle(depth);
23-
depth++;
24-
2522
var tpl = [];
2623
for (var frameID in context.frames)
2724
{
2825
var frame = context.frames[frameID];
2926
if( frame.parentFrameID != parentFrameID ){ continue; }
3027

3128
var r = context.get_resource( frame.resourceID );
32-
var closed = frame.closed;
29+
var className = 'expand-collapse'+(frame.closed?' close':'');
3330
// console.log( JSON.stringify(frame) );
3431
var tmp =
3532
{
@@ -38,23 +35,24 @@ templates.resource_tree_frame = function(context, parentFrameID, depth)
3835
[
3936
'div',
4037
[ // heading expand-collapse
41-
['input','type','button','handler','resources-expand-collapse','class',(closed?'close':'')],
42-
['span','frameID='+frameID+' -- '+(r?r.id+' ':'')+((r?r.url.filename||r.human_url:'')||'resource information not fully available yet'),[],
43-
'data-tooltip',r&&'js-script-select',
44-
'data-tooltip-text',r&&'frame: '+r.human_url]
45-
// 'class','resource-frame'// expand-collapse-open',
38+
['input','type','button','handler','resources-expand-collapse','class','button-'+className],
39+
['span', 'class', 'resource-icon resource-type-storage'],
40+
['span',' '+((r?r.url.filename||r.human_url:'')||'resource information not fully available yet'),[],
41+
'data-tooltip',(r&&'js-script-select'),
42+
'data-tooltip-text',(r&&'frame: '+r.human_url)
43+
]
44+
// 'class','resource-fraem'// expand-collapse-open',
4645
],
4746
[ // resources groups & frames
4847
'ul',
4948
[].concat
5049
(
51-
templates.resource_groups( context, frameID, depth ),
52-
templates.resource_tree_frame( context, frameID, depth )
50+
templates.resource_groups( context, frameID ),
51+
templates.resource_tree_frame( context, frameID )
5352
).map(function(v){ return['li',[v]]; })
5453
],
5554
'data-frame-id',frameID,
56-
'class','expand-collapse'+(closed?' close':'')
57-
// 'style',indent
55+
'class',className
5856
]
5957
};
6058
tpl.push( tmp );
@@ -65,64 +63,65 @@ templates.resource_tree_frame = function(context, parentFrameID, depth)
6563
templates.resource_groups = function(context, frameID, depth)
6664
{
6765
// return [['div','groups of the frame '+frameID]];
68-
var indent = cls.ResourceTestView.instance._getIndentStyle(depth);
69-
depth++;
70-
7166
var tpl = [];
72-
var groups = context.frames[frameID].groups;
73-
for (var group in groups)
67+
var frame = context.frames[frameID];
68+
var groups = frame.groups;
69+
for (var groupName in groups)
7470
{
75-
var count = Object.keys(groups[group].ids).length;
71+
var group = groups[groupName];
72+
var count = group.ids.length;
7673
if( !count ){ continue; }
77-
var closed = groups[group].closed;
74+
75+
var className = 'expand-collapse'+(group.closed?' close':'');
7876
tpl.push
7977
([
8078
'div',
8179
[
82-
['input','type','button','handler','resources-expand-collapse','class',(closed?'close':'')],
83-
['span',group +' ('+ count +')',[],
80+
['input','type','button','handler','resources-expand-collapse','class','button-'+className],
81+
templates.resource_icon({type:groupName}),
82+
['span',' '+ group.name +' ('+ count +')',[],
8483
//'style',indent+'white-space:nowrap;background:rgba(0,255,0,.1);',
8584
'class','resource-group']
8685
],
8786
[ // resources
8887
'ul',
89-
templates.resource_group(context, frameID, group, depth)
88+
templates.resource_group(context, frameID, groupName),
89+
'class','resources'
9090
],
9191
'data-frame-id',frameID,
92-
'data-resource-group',group,
93-
'class','expand-collapse'+(closed?' close':'')
94-
// 'style',indent
92+
'data-resource-group',groupName,
93+
'class',className
9594
]);
9695
}
9796
return tpl;
9897
};
9998

100-
templates.resource_group = function(context, frameID, group, depth)
99+
templates.resource_group = function(context, frameID, groupName)
101100
{
102101
// return ['div','groups of the frame '+frameID];
103-
var indent = cls.ResourceTestView.instance._getIndentStyle(depth);
104-
depth++;
105102

106-
return Object.keys(context.frames[frameID].groups[group].ids).map
103+
var frame = context.frames[frameID];
104+
var group = frame.groups[groupName];
105+
106+
107+
return group.ids.map
107108
(
108-
function(v,i)
109+
function(v)
109110
{
110111
var r=context.get_resource(v);
111112
var tmp =
112113
[
113114
'li',
114115
[
115-
templates.resource_icon(r),
116-
[
117-
'span',
118-
'resourceID='+r.id+' -- '+(r.url.filename||r.human_url||'resource information not fully available yet'),
119-
[],
120-
'data-tooltip',r&&'js-script-select',
121-
'data-tooltip-text',r&&group+': '+r.human_url
122-
]
116+
'span',
117+
(r.url.filename||r.human_url||'resource information not fully available yet'),
118+
[],
119+
'handler','resource-detail',
120+
'data-tooltip',(r&&'js-script-select'),
121+
'data-tooltip-text',(r&&groupName+': '+r.human_url)
123122
],
124-
// 'white-space:nowrap;background-color:rgba(0,0,0,'+(i&1?.1:.2)+');',
125-
'data-resource-id',r.id
123+
'data-resource-id',(''+r.id)
124+
126125
];
127126

128127
return tmp;

src/resource-manager/resource_util.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ cls.ResourceUtil.mime_type_map = {
104104
"font/opentype": "font",
105105
"font/ttf": "font",
106106
"font/otf": "font",
107+
"font/truetype": "font",
107108
"font/woff": "font", // not official, but seems to be common
108109

109110
"audio/mid": "audio",
@@ -186,6 +187,8 @@ cls.ResourceUtil.path_to_type = function(path)
186187
cls.ResourceUtil.url_path = function(url)
187188
{
188189
if (!url) { return null; }
190+
return url.dir_pathname;
191+
189192
var firstslash = url.replace("://", "xxx").indexOf("/");
190193
var querystart = url.indexOf("?");
191194
if (querystart == -1) { querystart = url.length; }
@@ -195,6 +198,7 @@ cls.ResourceUtil.url_path = function(url)
195198

196199
cls.ResourceUtil.url_filename = function(url)
197200
{
201+
return url.filename;
198202
var path = cls.ResourceUtil.url_path(url);
199203
var lastslash = path.lastIndexOf("/");
200204
if (
@@ -211,6 +215,7 @@ cls.ResourceUtil.url_filename = function(url)
211215

212216
cls.ResourceUtil.url_host = function(url)
213217
{
218+
return url.host;
214219
if (!url) { return null; }
215220
var host = url.replace(/\w+?:\/\//, "");
216221
var firstslash = host.indexOf("/");

0 commit comments

Comments
 (0)