Skip to content

Commit 2c575b3

Browse files
author
p01
committed
added missing files
1 parent e22e97c commit 2c575b3

File tree

2 files changed

+260
-0
lines changed

2 files changed

+260
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
window.cls || (window.cls = {});
2+
3+
/**
4+
* @constructor
5+
* @extends ViewBase
6+
*/
7+
cls.ResourceDetailView = function(id, name, container_class, html, default_handler) {
8+
if (cls.ResourceDetailView.instance)
9+
{
10+
return cls.ResourceDetailView.instance;
11+
}
12+
cls.ResourceDetailView.instance = this;
13+
14+
15+
this._service = new cls.ResourceManagerService(this);
16+
17+
18+
this.createView = function(container)
19+
{
20+
if (this.resource )
21+
{
22+
if (this.resource.data)
23+
{
24+
container.innerHTML = 'Data available for the resource '+this.resource.id+' '+Date.now(); // to get a visual that something is happening in case the resource is heavy to render
25+
var toto=Date.now();
26+
container.clearAndRender( templates.resource_detail.update(this.resource, this.resource.data) );
27+
container.title = (Date.now()-toto)+'ms';
28+
}
29+
else
30+
{
31+
container.innerHTML = 'No data available for the resource '+this.resource.id+' '+Date.now()+'<p>'+JSON.stringify(this.resource)+'</p>';
32+
}
33+
}
34+
else
35+
{
36+
container.innerHTML = 'No resource selected'+Date.now();
37+
}
38+
}
39+
40+
this.on_resource_data_bound = function(type, data)
41+
{
42+
//if(this.resource && this.resource.id==data[0])
43+
var id = data[0];
44+
var resource = this._service.get_resource(id);
45+
if(resource)
46+
{
47+
/*
48+
resource.data =
49+
{
50+
mimeType:data[2],
51+
characterEncoding:data[3],
52+
contentLength:data[4],
53+
length:data[5][0],
54+
content:data[5][2]||data[5][3]
55+
};
56+
*/
57+
resource.data = new cls.ResourceManager["1.0"].ResourceData( data );
58+
if (this.resourceId==id){ this.resource = resource; }
59+
}
60+
this.update();
61+
}.bind(this);
62+
63+
this.__open_resource = function(resource)
64+
{
65+
var id = resource.id;
66+
this.resourceId = id;
67+
if (!resource.data)
68+
{
69+
var responseType = cls.ResourceUtil.type_to_content_mode(resource.type);
70+
this._service.fetch_resource_data( this.on_resource_data_bound, id, responseType );
71+
}
72+
else
73+
{
74+
this.update();
75+
}
76+
}
77+
78+
this.open_resource_tab = function(resource, data)
79+
{
80+
this.resource = resource;
81+
this.update();
82+
}
83+
84+
this.open_resource = function(id)
85+
{
86+
this.resourceId = id;
87+
var resource = this.resource = this._service.get_resource(id);
88+
this.update();
89+
if (resource && !resource.data)
90+
{
91+
var responseType = cls.ResourceUtil.type_to_content_mode(resource.type);
92+
this._service.fetch_resource_data( this.on_resource_data_bound, id, responseType );
93+
}
94+
}
95+
96+
this.open_resource_group = function(group)
97+
{
98+
this.resources = [];
99+
for( var i=0; i<group.ids.length; i++)
100+
{
101+
var id = group.ids[i];
102+
var resource = this._service.get_resource(id);
103+
if (resource)
104+
{
105+
this.resources.push( resource );
106+
if (!resource.data)
107+
{
108+
var responseType = cls.ResourceUtil.type_to_content_mode(resource.type);
109+
this._service.fetch_resource_data( this.on_resource_data_bound, id, responseType );
110+
}
111+
}
112+
}
113+
this.update();
114+
}
115+
116+
this.init(id, name, container_class, html, default_handler);
117+
};
118+
119+
cls.ResourceDetailView.prototype = ViewBase;
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
window.cls || (window.cls = {});
2+
3+
/**
4+
* @constructor
5+
* @extends ViewBase
6+
*/
7+
cls.ResourceTestView = function(id, name, container_class, html, default_handler) {
8+
if (cls.ResourceTestView.instance)
9+
{
10+
return cls.ResourceTestView.instance;
11+
}
12+
cls.ResourceTestView.instance = this;
13+
14+
// const
15+
var updateThrottleTime = 500;
16+
17+
// "private"
18+
this._service = new cls.ResourceManagerService(this);
19+
this._loading = false;
20+
21+
this._updateTime = 0;
22+
this._updateThrottled = false;
23+
24+
// public
25+
26+
this.createView = function(container)
27+
{
28+
// throttle
29+
var timeSinceLastRender = Date.now()-this._updateTime;
30+
if( timeSinceLastRender<updateThrottleTime )
31+
{
32+
if (!this._updateThrottled)
33+
{
34+
this._updateThrottled = true;
35+
setTimeout( this.update.bind(this), updateThrottleTime-timeSinceLastRender );
36+
}
37+
return;
38+
}
39+
else
40+
{
41+
this._updateThrottled = false;
42+
this._updateTime = Date.now();
43+
}
44+
45+
// createView
46+
var service = this._service;
47+
var ctx = this._service.get_resource_context();
48+
49+
if (ctx && Object.keys(ctx.resourcesDict).length)
50+
{
51+
container.clearAndRender( templates.resource_tree.update(ctx) );
52+
}
53+
else if (this._loading)
54+
{
55+
container.clearAndRender(
56+
['div',
57+
['p', "Loading page..."],
58+
'class', 'info-box'
59+
]
60+
);
61+
}
62+
else
63+
{
64+
container.clearAndRender(
65+
['div',
66+
['span',
67+
'class', 'container-button ui-button',
68+
'handler', 'reload-window',
69+
'tabindex', '1'],
70+
['p', ui_strings.S_RESOURCE_CLICK_BUTTON_TO_FETCH_RESOURCES],
71+
'class', 'info-box'
72+
]
73+
);
74+
}
75+
};
76+
77+
78+
this._on_abouttoloaddocument_bound = function()
79+
{
80+
this._loading = true;
81+
this.update();
82+
}.bind(this);
83+
84+
this._on_documentloaded_bound = function()
85+
{
86+
this._loading = false;
87+
this.update();
88+
}.bind(this);
89+
90+
91+
92+
// WIP: this comes straight from the old resource_all_view
93+
this._type_class_map =
94+
{
95+
image: cls.ImageResourceDetail,
96+
font: cls.FontResourceDetail,
97+
script: cls.JSResourceDetail,
98+
markup: cls.MarkupResourceDetail,
99+
css: cls.CSSResourceDetail,
100+
text: cls.TextResourceDetail,
101+
};
102+
this._open_resource_views = {};
103+
104+
this._open_resource_tab = function(resource, data)
105+
{
106+
var ui = UI.get_instance();
107+
108+
if (!this._open_resource_views[resource.id])
109+
{
110+
var viewclass = this._type_class_map[resource.type]||cls.GenericResourceDetail;
111+
var view = new viewclass( resource, this._service );
112+
this._open_resource_views[resource.id] = view.id;
113+
}
114+
window.views[this._open_resource_views[resource.id]].data = data
115+
116+
ui.get_tabbar("resources").add_tab(this._open_resource_views[resource.id]);
117+
ui.show_view(this._open_resource_views[resource.id]);
118+
}
119+
120+
121+
var eh = window.eventHandlers;
122+
// fixme: this is in the wrong place! Doesn't belong in UI and even if it
123+
// did, the event handler doesn't get added until the view is created
124+
// which means you can't open tabs from elsewhere if you haven't opened
125+
// the resources view first
126+
/*
127+
eh.click["resources-all-open"] = this._handle_open_resource_bound;
128+
eh.click['open-resource-tab'] = function(event, target)
129+
{
130+
var broker = cls.ResourceDisplayBroker.get_instance();
131+
broker.show_resource_for_ele(target);
132+
}
133+
*/
134+
var doc_service = window.services['document-manager'];
135+
doc_service.addListener("abouttoloaddocument", this._on_abouttoloaddocument_bound);
136+
doc_service.addListener("documentloaded", this._on_documentloaded_bound);
137+
138+
this.init(id, name, container_class, html, default_handler);
139+
};
140+
141+
cls.ResourceTestView.prototype = ViewBase;

0 commit comments

Comments
 (0)