rhmessaging commits: r4398 - mgmt/trunk/cumin/python/cumin.
by rhmessaging-commits@lists.jboss.org
Author: eallen
Date: 2010-10-20 14:10:28 -0400 (Wed, 20 Oct 2010)
New Revision: 4398
Modified:
mgmt/trunk/cumin/python/cumin/stat.py
Log:
Use calculated max and min values for percentage charts instead of 0 and 100
Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py 2010-10-20 17:28:20 UTC (rev 4397)
+++ mgmt/trunk/cumin/python/cumin/stat.py 2010-10-20 18:10:28 UTC (rev 4398)
@@ -1201,8 +1201,17 @@
class PercentAreaChart(AreaChart):
def get_max_min(self, session, stats, samples):
- return 100.0, 0.0
+ max_val, min_val = super(PercentAreaChart, self).get_max_min(session, stats, samples)
+ percent = self.page.percent_property.get(session)
+ total = self.page.get_object_property(session, percent)
+ total = total and float(total) or 1.0
+
+ max_val = (max_val / total) * 100.0
+ min_val = (min_val / total) * 100.0
+
+ return max_val, min_val
+
def get_vals(self, session, samples, stat, text, duration, end_secs):
tnow = time()
vals = list()
14 years, 2 months
rhmessaging commits: r4397 - in mgmt/trunk/cumin/python/cumin: inventory and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: eallen
Date: 2010-10-20 13:28:20 -0400 (Wed, 20 Oct 2010)
New Revision: 4397
Modified:
mgmt/trunk/cumin/python/cumin/inventory/system.py
mgmt/trunk/cumin/python/cumin/stat.py
Log:
Fix for BZ 633914: Formatted memory and swap number for Sysimage as MB/GB
Added a Percent chart type
Changed the free memory graph to Percent Free Memory to avoid confusion over units
Removed the database id as a parameter for some charts and used _qmf_agent_id instead
Modified: mgmt/trunk/cumin/python/cumin/inventory/system.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/inventory/system.py 2010-10-20 17:24:14 UTC (rev 4396)
+++ mgmt/trunk/cumin/python/cumin/inventory/system.py 2010-10-20 17:28:20 UTC (rev 4397)
@@ -42,6 +42,7 @@
self.view.add_tab(overview)
class SystemGeneralStatSet(StatSet):
+ fmt_as_bytes = ("memFree", "swapFree")
def __init__(self, app, name, object):
super(SystemGeneralStatSet, self).__init__(app, name, object)
@@ -50,13 +51,20 @@
"loadAverage10Min", "procTotal",
"procRunning")
+ def render_item_value(self, session, item):
+ stat, value = item
+ if stat.name in self.fmt_as_bytes:
+ return fmt_bytes(value*1024)
+ return CuminStatistic.fmt_value(value)
+
class SystemStats(Widget):
def __init__(self, app, name, system):
super(SystemStats, self).__init__(app, name)
self.add_child(SystemGeneralStatSet(app, "stats", system))
- chart = StatFlashChart(app, "freemem", system)
+ chart = self.MemoryFlashChart(app, "freemem", system)
+ chart.chart_type = "percent"
chart.stats = ("memFree",)
self.add_child(chart)
@@ -78,6 +86,16 @@
#return self.page.main.grid.pool.job.get_href(session, job, None)
return session.marshal() # XXX
+ class MemoryFlashChart(StatFlashChart):
+ def render_title(self, session, *args):
+ return "Memory Usage"
+
+ def get_href_params(self, session):
+ params = super(SystemStats.MemoryFlashChart, self).get_href_params(session)
+ params.append("tp=memTotal")
+
+ return params
+
class SystemSlotMap(SlotMap):
def __init__(self, app, name, system):
super(SystemSlotMap, self).__init__(app, name)
Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py 2010-10-20 17:24:14 UTC (rev 4396)
+++ mgmt/trunk/cumin/python/cumin/stat.py 2010-10-20 17:28:20 UTC (rev 4397)
@@ -111,8 +111,6 @@
# open-flash-chart can't handle the : in the agent id. Net even if
# it's converted to %3A, so we have to change it
params.append("agent=%s" % object._qmf_agent_id.replace(":", "|"))
-
- params.append("id=%s" % object._id)
params.append("object_id=%s" % object._qmf_object_id)
params.append("chart_id=%s" % self.render_id(session, None))
params.append("duration=%s" % self.duration.get(session))
@@ -229,6 +227,7 @@
return file
class StatChartPage(Page):
+ # handles stats.png request
def __init__(self, app, name):
super(StatChartPage, self).__init__(app, name)
@@ -275,11 +274,29 @@
self.container_height.default = 100
self.add_parameter(self.container_height)
+ self.total_property = Parameter(app, "tp")
+ self.add_parameter(self.total_property)
+
+ self.type = Parameter(app, "type")
+ self.add_parameter(self.type)
+
self.cache = ImageCache()
def get_content_type(self, session):
return self.samples.get(session) and "text/plain" or "image/png"
+ def get_object_property(self, session, property):
+ agent_id = self.agent_id.get(session)
+
+ rpackage = self.rosemary_package.get(session)
+ rclass = self.rosemary_class.get(session)
+ rosemary_package = self.app.model._packages_by_name[rpackage]
+ cls = rosemary_package._classes_by_name[rclass]
+
+ cursor = self.app.database.get_read_cursor()
+ object = cls.get_object(cursor, _qmf_agent_id=agent_id)
+ return object.get_value(property)
+
def get_adapter_stats(self, session):
rpackage = self.rosemary_package.get(session)
rclass = self.rosemary_class.get(session)
@@ -400,6 +417,17 @@
for stat in stats:
samples[stat] = adapter.samples(stat, duration, interval, method)
+ type = self.type.get(session)
+ if type == "percent":
+ total_property = self.total_property.get(session)
+ total = self.get_object_property(session, total_property)
+ total = total and float(total) or 1.0
+
+ for stat in stats:
+ percents = [(x[0], (float(x[1]) / total) * 100.0, x[2])
+ for x in samples[stat] if x[1] is not None]
+ samples[stat] = percents
+
# take stddev into account for max and min y values
deviated_values = list()
for stat in stats:
@@ -454,7 +482,7 @@
if mode == "rate":
titles = ["%s / sec" % x.title for x in stats]
else:
- titles = [x.title for x in stats]
+ titles = ["%s%s" % ((type == "percent") and "Percent " or "", x.title) for x in stats]
title_xy = chart.plot_legend(titles, colors)
@@ -480,8 +508,8 @@
self.object_id = StringParameter(app, "object_id")
self.add_parameter(self.object_id)
- self.id = StringParameter(app, "id")
- self.add_parameter(self.id)
+ self.agent_id = ModifiedAgentIdParameter(app, "agent")
+ self.add_parameter(self.agent_id)
self.rosemary_class = Parameter(app, "rcls")
self.add_parameter(self.rosemary_class)
@@ -513,6 +541,9 @@
self.flash_chart = self.GenericChart(app, "chart", self.object)
self.add_child(self.flash_chart)
+ self.total_property = Parameter(app, "tp")
+ self.add_parameter(self.total_property)
+
def render_content(self, session):
self.flash_chart.stats = self.stats.get(session)
self.flash_chart.mode = self.mode.get(session)
@@ -527,11 +558,11 @@
rclass = self.widget.rosemary_class.get(session)
rosemary_package = self.app.model._packages_by_name[rpackage]
rosemary_class = rosemary_package._classes_by_name[rclass]
+ agent_id = self.widget.agent_id.get(session)
- id = self.widget.id.get(session)
cursor = self.app.database.get_read_cursor()
- obj = rosemary_class.get_object(cursor, _id=id)
+ obj = rosemary_class.get_object(cursor, _qmf_agent_id=agent_id)
self.set(session, obj)
@@ -555,6 +586,9 @@
params.append("width=%i" % self.render_width(session))
params.append("height=%i" % self.render_height(session))
params.append("high=1")
+ tp = self.parent.total_property.get(session)
+ if tp:
+ params.append("tp=%s" % tp)
return escape_entity("%s?" % self.get_flash_name(session) + ";".join(params))
class XAxis(object):
@@ -928,12 +962,15 @@
line.colour = color
line.width = line_width
tip_title = stat.title.split(" ")[-1]
- line.text = mode == "rate" and "%s / sec" % tip_title or stat.title
+ line.text = mode == "rate" and "%s / sec" % tip_title or self.get_line_title(stat)
vals = self.get_vals(session, samples, stat, line.text, duration, end_secs)
line.values = vals
chart.elements.append(line)
+ def get_line_title(self, stat):
+ return stat.title
+
def get_chart(self, session, adapter, stats, samples, duration, max_value, min_value, append, end_secs):
mode = self.page.mode.get(session)
@@ -1086,6 +1123,7 @@
return dict()
class StatFlashPage(StatChartPage):
+ # handles chart.json requests
def __init__(self, app, name):
super(StatFlashPage, self).__init__(app, name)
@@ -1136,6 +1174,9 @@
self.control_max.default = None
self.add_parameter(self.control_max)
+ self.percent_property = Parameter(app, "tp")
+ self.add_parameter(self.percent_property)
+
def get_content_type(self, session):
return "text/plain"
@@ -1151,12 +1192,38 @@
elif chart_type == "stacked":
chart_obj = StackedAreaChart(self.app, chart_type, self)
#chart_obj = StackedChart(self.app, chart_type, self)
+ elif chart_type == "percent":
+ chart_obj = PercentAreaChart(self.app, chart_type, self)
elif chart_type == "pie":
chart_obj = FlashPieChart(self.app, chart_type, self)
return chart_obj
+class PercentAreaChart(AreaChart):
+ def get_max_min(self, session, stats, samples):
+ return 100.0, 0.0
+
+ def get_vals(self, session, samples, stat, text, duration, end_secs):
+ tnow = time()
+ vals = list()
+ percent = self.page.percent_property.get(session)
+ total = self.page.get_object_property(session, percent)
+
+ min_dt = tnow - duration - end_secs
+ for dt, value, dev in samples[stat]:
+ if value is not None:
+ vals.append({"dt": secs(dt), "y": (float(value) / float(total)) * 100.0})
+ if secs(dt) < min_dt:
+ break
+
+ vals.reverse()
+ return vals
+
+ def get_line_title(self, stat):
+ return "Percent %s" % stat.title
+
class StatStackedPage(StatChartPage):
+ # handles stacked.png requests
def do_render(self, session):
adapter, stats = self.get_adapter_stats(session)
14 years, 2 months
rhmessaging commits: r4396 - mgmt/trunk/cumin/model.
by rhmessaging-commits@lists.jboss.org
Author: eallen
Date: 2010-10-20 13:24:14 -0400 (Wed, 20 Oct 2010)
New Revision: 4396
Modified:
mgmt/trunk/cumin/model/rosemary.xml
Log:
Set the Sysimage memory and swap statistics to display as MB/GB
Modified: mgmt/trunk/cumin/model/rosemary.xml
===================================================================
--- mgmt/trunk/cumin/model/rosemary.xml 2010-10-20 17:23:20 UTC (rev 4395)
+++ mgmt/trunk/cumin/model/rosemary.xml 2010-10-20 17:24:14 UTC (rev 4396)
@@ -231,12 +231,24 @@
<title>Distribution</title>
</property>
+ <property name="memTotal">
+ <title>Mem Total</title>
+ <formatter>fmt_kbmb</formatter>
+ </property>
+
+ <property name="swapTotal">
+ <title>Swap Total</title>
+ <formatter>fmt_kbmb</formatter>
+ </property>
+
<statistic name="memFree">
<title>Free Memory</title>
+ <formatter>fmt_kbmb</formatter>
</statistic>
<statistic name="swapFree">
<title>Free Swap</title>
+ <formatter>fmt_kbmb</formatter>
</statistic>
<statistic name="loadAverage1Min">
14 years, 2 months
rhmessaging commits: r4395 - mgmt/trunk/rosemary/python/rosemary.
by rhmessaging-commits@lists.jboss.org
Author: eallen
Date: 2010-10-20 13:23:20 -0400 (Wed, 20 Oct 2010)
New Revision: 4395
Modified:
mgmt/trunk/rosemary/python/rosemary/model.py
mgmt/trunk/rosemary/python/rosemary/util.py
Log:
Added ability to format statistics
Added method to format a property/statistic number as MB / GB / etc.
Modified: mgmt/trunk/rosemary/python/rosemary/model.py
===================================================================
--- mgmt/trunk/rosemary/python/rosemary/model.py 2010-10-19 16:47:20 UTC (rev 4394)
+++ mgmt/trunk/rosemary/python/rosemary/model.py 2010-10-20 17:23:20 UTC (rev 4395)
@@ -766,7 +766,9 @@
formatter = None
if attr in self._class._properties_by_name:
formatter = self._class._properties_by_name[attr].formatter
- #TODO: handle formatters on statistics and headers as well
+ elif attr in self._class._statistics_by_name:
+ formatter = self._class._statistics_by_name[attr].formatter
+ #TODO: handle formatters headers as well
return formatter and formatter(value) or value
def get_value(self, attr):
Modified: mgmt/trunk/rosemary/python/rosemary/util.py
===================================================================
--- mgmt/trunk/rosemary/python/rosemary/util.py 2010-10-19 16:47:20 UTC (rev 4394)
+++ mgmt/trunk/rosemary/python/rosemary/util.py 2010-10-20 17:23:20 UTC (rev 4395)
@@ -3,6 +3,7 @@
import sys
from pprint import pprint
+from cumin.formats import *
try:
from xml.etree.ElementTree import *
@@ -11,3 +12,6 @@
def fmt_exchange_name(value):
return value and value or "Default exchange"
+
+def fmt_kbmb(value):
+ return fmt_bytes(value * 1024)
\ No newline at end of file
14 years, 2 months
rhmessaging commits: r4394 - mgmt/trunk/wooly/bin.
by rhmessaging-commits@lists.jboss.org
Author: tmckay
Date: 2010-10-19 12:47:20 -0400 (Tue, 19 Oct 2010)
New Revision: 4394
Modified:
mgmt/trunk/wooly/bin/wooly-demo
Log:
server.start() returns immediately, main application needs to sleep in a loop
Modified: mgmt/trunk/wooly/bin/wooly-demo
===================================================================
--- mgmt/trunk/wooly/bin/wooly-demo 2010-10-19 14:41:39 UTC (rev 4393)
+++ mgmt/trunk/wooly/bin/wooly-demo 2010-10-19 16:47:20 UTC (rev 4394)
@@ -24,6 +24,8 @@
try:
server.start()
+ while True:
+ sleep(5)
finally:
server.stop()
finally:
14 years, 2 months
rhmessaging commits: r4393 - mgmt/trunk/wooly/python/wooly.
by rhmessaging-commits@lists.jboss.org
Author: eallen
Date: 2010-10-19 10:41:39 -0400 (Tue, 19 Oct 2010)
New Revision: 4393
Modified:
mgmt/trunk/wooly/python/wooly/pages.py
Log:
Fix .js content type
Modified: mgmt/trunk/wooly/python/wooly/pages.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/pages.py 2010-10-18 15:14:10 UTC (rev 4392)
+++ mgmt/trunk/wooly/python/wooly/pages.py 2010-10-19 14:41:39 UTC (rev 4393)
@@ -329,7 +329,7 @@
".html": "text/html",
".jpeg": "image/jpeg",
".jpg": "image/jpeg",
- ".js": "test/javascript",
+ ".js": "text/javascript",
".png": "image/png",
}
14 years, 2 months
rhmessaging commits: r4392 - mgmt/trunk/cumin/resources.
by rhmessaging-commits@lists.jboss.org
Author: eallen
Date: 2010-10-18 11:14:10 -0400 (Mon, 18 Oct 2010)
New Revision: 4392
Modified:
mgmt/trunk/cumin/resources/slotvis.js
Log:
Fix for BZ 629929: The red box drawn when hovering of a png slot vis as too large.
Modified: mgmt/trunk/cumin/resources/slotvis.js
===================================================================
--- mgmt/trunk/cumin/resources/slotvis.js 2010-10-18 14:03:39 UTC (rev 4391)
+++ mgmt/trunk/cumin/resources/slotvis.js 2010-10-18 15:14:10 UTC (rev 4392)
@@ -527,15 +527,13 @@
if (width == 0) return;
var rx = col * width + slot_clip_left;
var ry = row * width + slot_clip_top;
- oHover.style.width = (width-1) + "px";
- oHover.style.height = (width-1) + "px";
+ oHover.style.width = (width-2) + "px";
+ oHover.style.height = (width-2) + "px";
switch (leg) {
case 0:
oHover.style.left = rx + "px";
oHover.style.top = ry + "px";
- oHover.style.width = width + "px";
- oHover.style.height = width + "px";
oHover.style.borderColor = "red pink pink pink";
oHover.style.visibility = "visible";
if ((rx < 0) || (ry < 0) || (rx + width > slot_clip_size) || (ry + width > slot_clip_size)) {
14 years, 2 months
rhmessaging commits: r4391 - in mgmt/trunk/cumin: resources and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: eallen
Date: 2010-10-18 10:03:39 -0400 (Mon, 18 Oct 2010)
New Revision: 4391
Added:
mgmt/trunk/cumin/resources/slotvis.js
Modified:
mgmt/trunk/cumin/python/cumin/grid/slot.strings
Log:
BZ 643914: Moved png slot vis javascript to separate .js file
Modified: mgmt/trunk/cumin/python/cumin/grid/slot.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/slot.strings 2010-10-15 16:48:35 UTC (rev 4390)
+++ mgmt/trunk/cumin/python/cumin/grid/slot.strings 2010-10-18 14:03:39 UTC (rev 4391)
@@ -40,833 +40,8 @@
</table>
[SlotMap.javascript]
-var vis;
+addJavascript('resource?name=slotvis.js', 'head');
-(function() {
- vis = new Visualization();
-
- var slot_clip_left;
- var slot_clip_top;
- var slot_zoom;
- var slot_last_index;
- var slot_info_timer;
- var slot_hover_timer;
- var slot_png_timer;
- var slot_zoom_initialized;
- var slot_center_index;
-
- function Visualization() {
- slot_clip_left = 0;
- slot_clip_top = 0;
- slot_zoom = 1;
- slot_last_index = -1;
- slot_info_timer = null;
- slot_hover_timer = null;
- slot_png_timer = null;
- slot_zoom_initialized = false;
- slot_center_index = -1;
-
- this.notify = function(fullpage, size) {
- slot_clip_size = size;
- this.img_loaded(document.images[slot_current_id]);
- }
- this.pan_left = function () {
- if (slot_clip_left == 0) return;
- var now = new Date();
- animate_pan(slot_clip_left, Math.min(Math.floor(slot_clip_size / 1.1), -slot_clip_left), (now-0), "slot_clip_left");
- }
-
- this.pan_right = function () {
- var to_pan = Math.floor(slot_clip_size / 1.1);
- if (slot_clip_left - slot_clip_size - to_pan < -slot_map_info.width) {
- to_pan = slot_map_info.width - slot_clip_size + slot_clip_left;
- }
- var now = new Date();
- animate_pan(slot_clip_left, -to_pan, (now-0), "slot_clip_left");
- }
-
- this.pan_up = function () {
- if (slot_clip_top == 0) return;
- var now = new Date();
- animate_pan(slot_clip_top, Math.min(Math.floor(slot_clip_size / 1.1), -slot_clip_top), (now-0), "slot_clip_top");
- }
-
- this.pan_down = function () {
- if (slot_map_info.height < slot_clip_size) return;
-
- var to_pan = Math.floor(slot_clip_size / 1.1);
- if (slot_clip_top - slot_clip_size - to_pan < -slot_map_info.height) {
- to_pan = slot_map_info.height - slot_clip_size + slot_clip_top;
- }
- var now = new Date();
- animate_pan(slot_clip_top, -to_pan, (now-0), "slot_clip_top");
- }
-
-
- // in case server stops and then restarts, reget the images
- this.img_error = function (oImg) {
- stop_auto_updates();
- var oZooming = document.getElementById("slot_zooming");
- if (oZooming) {
- oZooming.style.display = "none";
- }
- oImg.style.visibility = "hidden"; // hide broken image indicator
- slot_map_info.size = 0;
- slot_map_info.width = 1;
- slot_map_info.height = 1;
- slot_map_info.rows = 1;
- slot_map_info.cols = 1;
- slot_map_info.count = 0;
- slot_png_timer = setInterval(update_png, 10000);
- }
-
- this.img_loaded = function (oImg) {
- stop_auto_updates();
- var oZooming = document.getElementById("slot_zooming");
- if (oZooming) {
- oZooming.style.display = "none";
- }
-
- if (oImg) {
- oImg.style.visibility = "visible";
- slot_cookie_info();
- oImg.width = slot_map_info.width;
- oImg.height = slot_map_info.height;
- set_pan("slot_panup", "width", slot_map_info.size * slot_map_info.cols, this.pan_up);
- set_pan("slot_pandown", "width", slot_map_info.size * slot_map_info.cols, this.pan_down);
- set_pan("slot_panleft", "height", slot_map_info.size * slot_map_info.rows, this.pan_left);
- set_pan("slot_panright", "height", slot_map_info.size * slot_map_info.rows, this.pan_right);
-
- var oMap = document.getElementById(slot_current_id);
- if (oMap) {
- oMap.style.width = Math.min(oImg.width, slot_clip_size) + "px";
- oMap.style.height = Math.min(oImg.height, slot_clip_size) + "px";
- if ((slot_map_info.size * slot_map_info.rows < slot_clip_size) &&
- (slot_map_info.size * slot_map_info.cols < slot_clip_size))
- oMap.style.borderColor = "transparent";
- else
- oMap.style.borderColor = "#CCCCCC";
-
- }
- var oGlass = document.getElementById("slot_glass");
- if (oGlass) {
- oGlass.style.width = Math.min(oImg.width, slot_clip_size) + "px";
- oGlass.style.height = Math.min(oImg.height, slot_clip_size) + "px";
- }
- if (!slot_zoom_initialized)
- initialize_zoom();
-
- animate_zoom_to(slot_zoom);
- var oControls = document.getElementById("slot_controls");
- if (oControls) {
- var oMap = document.getElementById(slot_current_id);
- oControls.style.left = (oMap.offsetLeft + oMap.offsetWidth - oControls.offsetWidth) + "px";
- //oControls.style.left = (420 - oControls.offsetWidth) + "px";
- }
- refire_info();
- }
- center_on_index();
- draw_clipped();
- slot_png_timer = setInterval(update_png, 6000);
- }
-
- this.upGlass = function (e) {
- if (!e) var e = window.event;
- var oGlass = document.getElementById("slot_glass");
- if (oGlass) {
- if (oGlass.dragging) {
- oGlass.dragging = false;
- }
- }
- }
-
- this.moveGlass = function (e) {
- if (slot_map_info.size == 0) return;
- if (!e) var e = window.event;
- var oGlass = document.getElementById("slot_glass");
- if (oGlass) {
- if (oGlass.dragging) {
- var posxy = get_event_pos(e);
- if ((posxy.x - oGlass.down_pos.x > 0) || (posxy.y - oGlass.down_pos.y > 0))
- oGlass.down_pos = {x: posxy.x - slot_clip_left, y: posxy.y - slot_clip_top};
-
- slot_clip_left = Math.min(posxy.x - oGlass.down_pos.x, 0);
- slot_clip_top = Math.min(posxy.y - oGlass.down_pos.y, 0);
- oGlass.drug = true;
-
- draw_clipped();
- if (e.preventDefault)
- e.preventDefault();
- return false;
- }
- }
-
- var rpos = get_relative_event_pos(e);
- if (rpos) {
- get_slot_info(rpos.x, rpos.y);
- }
- }
-
- this.downGlass = function (e) {
- if (!e) var e = window.event;
-
- var oGlass = document.getElementById("slot_glass");
- if (oGlass) {
- oGlass.dragging = true;
- var posxy = get_event_pos(e);
- oGlass.down_pos = {x: posxy.x - slot_clip_left, y: posxy.y - slot_clip_top};
- clear_hover();
- hide_info();
- }
- return false;
- }
-
- this.outGlass = function outGlass(e) {
- if (!e) var e = window.event;
- clear_hover();
- hide_info();
- }
-
- this.zoom_in_slots = function (posxy) {
- if (slot_zoom >= get_max_zoom()) return;
- var click_info = vis.get_index(posxy.x, posxy.y);
- slot_center_index = click_info.index;
- do_zoom(slot_zoom + 1);
- }
-
- this.fire_slot_info = function (index) {
- slot_last_index = index;
- slot_info_timer = null;
- do_info_request(index);
- }
-
- this.get_index = function (x, y) {
- var width = slot_map_info.size;
- var pngrow = Math.floor((y - slot_clip_top) / width);
- var pngcol = Math.floor((x - slot_clip_left) / width);
-
- if ((pngcol < slot_map_info.cols) && (pngrow < slot_map_info.rows)) {
- var index = pngrow * slot_map_info.cols + pngcol;
-
- if (index < slot_map_info.count)
- return {"index": index, "row": pngrow, "col": pngcol};
- }
-
- return null;
- }
-
- }
-
- function slot_zoom_to(e) {
- if (!e) var e = window.event;
- var targ = get_event_target(e);
- var level = parseInt(targ.level, 10);
-
- get_center_index();
- do_zoom(level);
-
- if (e.stopPropagation)
- e.stopPropagation()
- else if (e.cancelBubble)
- e.cancelBubble = true;
- }
-
- function do_zoom(level) {
- var old_zoom = slot_zoom;
- slot_zoom = level;
-
- stop_auto_updates();
- var oZooming = document.getElementById("slot_zooming");
- if (oZooming) {
- oZooming.style.display = "block";
- //var oMap = document.getElementById(slot_current_id);
- //if (oMap) {
- // oZooming.style.width = oMap.offsetWidth + "px";
- //}
- }
- var oImg = document.images[slot_current_id];
- if (oImg) {
- var src = oImg.src;
- var branch = wooly.session.branch(src);
- branch.zl = level;
- branch.zx = slot_clip_left;
- branch.zy = slot_clip_top;
- src = branch.marshal();
-
- src = cumin.refreshTime(src);
- oImg.src = src;
- }
-
- animate_zoom_to(level);
- return false;
- }
-
- function animate_zoom_to(level) {
- var oPos = document.getElementById("zoom_pos");
- if (oPos) {
- var original_x = oPos.offsetLeft;
- var now = new Date();
- var x_amount = ((level - 1) * 13) - original_x;
- animate_zoom_pos(original_x, (now-0), x_amount)
- }
- }
-
- function animate_zoom_pos(original_x, original_time, x_amount) {
- var oPos = document.getElementById("zoom_pos");
-
- if (oPos) {
- var now = new Date();
- var delta = (now - original_time) / 400.0;
- var partial = 1;
-
- if (delta < 1)
- partial = Math.sin(Math.PI/2 * delta);
-
- oPos.style.left = Math.floor(original_x + x_amount * partial) + "px";
-
- if (delta < 1) {
- setTimeout(function() {
- animate_zoom_pos(original_x, original_time, x_amount)
- }, 10);
- }
- }
- }
-
- function stop_auto_updates() {
- if (slot_png_timer) {
- clearInterval(slot_png_timer);
- slot_png_timer = null;
- }
- }
-
- function update_png() {
- stop_auto_updates();
- cumin.updateChart(slot_current_id, null);
- }
-
- function set_pan(id, which, value, fn) {
- var obj = document.getElementById(id);
- if (obj) {
- if (value <= slot_clip_size) {
- eval("obj.style." + which + " = '" + Math.min(value, slot_clip_size) + "px'");
- obj.style.visibility = "hidden";
- obj.onclick = null;
- } else {
- eval("obj.style." + which + " = '" + Math.min(value, slot_clip_size) + "px'");
- obj.style.visibility = "visible";
- obj.onclick = fn;
- }
- }
- }
-
- function slot_cookie_info() {
- var slot_info = get_cookie("slot_info");
- if (slot_info) {
- var vals = slot_info.split("|");
- if (vals.length == 6) {
- slot_map_info.size = parseInt(vals[0], 10);
- slot_map_info.width = parseInt(vals[1], 10);
- slot_map_info.height = parseInt(vals[2], 10);
- slot_map_info.count = parseInt(vals[3], 10);
- slot_map_info.rows = parseInt(vals[4], 10);
- slot_map_info.cols = parseInt(vals[5], 10);
- }
- }
- }
-
- function center_on_index() {
- if (slot_center_index == -1) return;
-
- var row = slot_center_index % slot_map_info.cols;
- var col = Math.floor(slot_center_index / slot_map_info.cols);
- var x = col * slot_map_info.size + slot_map_info.size / 2;
- var y = row * slot_map_info.size + slot_map_info.size / 2;
-
- var cl = (Math.min(slot_clip_size, slot_map_info.width) / 2) - x;
- var ct = (Math.min(slot_clip_size, slot_map_info.height) / 2) - y;
-
- if (slot_map_info.width + cl < slot_clip_size)
- cl = slot_clip_size - slot_map_info.width;
-
- if (slot_map_info.height + ct < slot_clip_size)
- ct = slot_clip_size - slot_map_info.height;
-
- if (cl > 0) cl = 0;
- if (ct > 0) ct = 0;
-
- slot_clip_left = Math.floor(cl);
- slot_clip_top = Math.floor(ct);
- slot_center_index = -1;
- }
-
- function get_center_index() {
- var rx = Math.min(slot_clip_size, slot_map_info.width) / 2;
- var ry = Math.min(slot_clip_size, slot_map_info.height) / 2;
-
- var click_info = vis.get_index(rx, ry);
- if (click_info)
- slot_center_index = click_info.index;
- }
-
- function get_max_zoom() {
- // allow to zoom until each slot is at least 28px wide
- if ((slot_map_info.size == 0) || (slot_zoom == 0))
- return 1;
- return Math.ceil(28 / (slot_map_info.size / slot_zoom));
- }
-
- function initialize_zoom() {
- var max_zoom = get_max_zoom();
- var oZoom = document.getElementById("zoom_levels");
- if ((oZoom) && (max_zoom > 1)) {
- var oDiv, oText, oNode;
- for (var i=0; i<max_zoom; i++) {
- var oDiv = document.createElement("div");
- if (i == 0) {
- oDiv.className = "zoom_first";
- oDiv.onclick = slot_zoom_to;
- oDiv.level = i+1;
- set_text(oDiv, (i+1)+ "", "zoom_node");
- } else if (i == max_zoom - 1) {
- oDiv.className = "zoom_last";
- oDiv.onclick = slot_zoom_to;
- oDiv.level = i+1;
- set_text(oDiv, i+1, "zoom_node_last");
- } else {
- oDiv.className = "zoom_middle_left";
- oDiv.onclick = slot_zoom_to;
- oDiv.level = i+1;
- oZoom.appendChild(oDiv);
- oDiv = document.createElement("div");
- oDiv.className = "zoom_middle_right";
- oDiv.onclick = slot_zoom_to;
- oDiv.level = i+1;
- set_text(oDiv, (i+1)+ "", "zoom_node");
- }
- oZoom.appendChild(oDiv);
- }
- } else {
- var oControls = document.getElementById("slot_controls");
- if (oControls) {
- oControls.style.display = "none";
- }
- }
- $("slot_visualization").style.display = "block";
- cumin.makeFullPageable($("slot_visualization"));
- slot_zoom_initialized = true;
-
- function set_text(odiv, text, className) {
- var oText = document.createElement("div");
- var oNode = document.createTextNode(text+"");
- oText.className = className;
- oText.appendChild(oNode);
- odiv.appendChild(oText);
- oText.onclick = slot_zoom_to;
- oText.level = text;
- }
- }
-
- function draw_clipped() {
-
- var clip_bottom;
- var clip_right;
- if (slot_map_info.width < slot_clip_size) {
- clip_bottom = slot_map_info.height;
- clip_right = slot_map_info.width;
- slot_clip_left = 0;
- slot_clip_top = 0;
- } else {
- var iZoom = slot_zoom;
- var clip_width = slot_clip_size;
- var clip_height = slot_clip_size;
- clip_bottom = clip_height - slot_clip_top;
- clip_right = clip_width - slot_clip_left;
-
- if (clip_right > slot_map_info.width) {
- slot_clip_left += (clip_right - slot_map_info.width);
- clip_right = slot_map_info.width;
- }
- if (clip_bottom > slot_map_info.height) {
- slot_clip_top = Math.min(clip_height - slot_map_info.height, 0);
- clip_bottom = slot_map_info.height;
- }
- }
-
- var oPng = document.getElementById("slot_png");
- if (oPng) {
- oPng.style.left = slot_clip_left + "px";
- oPng.style.top = slot_clip_top + "px";
- oPng.style.clip = "rect(" + (-slot_clip_top) + "px " + clip_right + "px " + clip_bottom + "px " + (-slot_clip_left) + "px)";
- }
- }
-
-
- function animate_pan(original_edge, move, timer, which) {
- var now = new Date();
- var delta = (now - timer) / 400.0;
- var expression = "=Math.floor(original_edge + move";
- if (delta < 1) {
- expression += " * Math.sin(Math.PI/2 * delta)";
- }
- expression += ")";
- eval(which + expression);
- draw_clipped();
- if (delta < 1)
- setTimeout( function () {animate_pan(original_edge, move, timer, which) }, 10);
-
- }
-
- function clear_hover() {
- if (slot_info_timer) {
- clearTimeout(slot_info_timer);
- slot_info_timer = null;
- slot_last_index = -1;
- }
- oHover = document.getElementById("slot_hover");
- if (oHover) {
- oHover.style.visibility = "hidden";
- }
- }
-
- function hide_info() {
- oInfo = $(slot_info_id);
- if (oInfo) {
- oInfo.style.visibility = "hidden";
- }
- slot_last_index = -1;
- }
-
- function get_slot_info(rx, ry) {
- var click_info = vis.get_index(rx, ry);
- if (click_info) {
- if (click_info.index != slot_last_index) {
- if (slot_info_timer) {
- clearTimeout(slot_info_timer);
- slot_info_timer = null;
- }
- if (slot_hover_timer) {
- clearTimeout(slot_hover_timer);
- slot_hover_timer = null;
- }
- slot_info_timer = setTimeout( function() { vis.fire_slot_info(click_info.index) }, 500);
- animate_hover(0, click_info.row, click_info.col);
- oInfo = $(slot_info_id);
- if (oInfo) {
- oInfo.style.display = "none";
- }
- }
- }
- }
-
- function animate_hover(leg, row, col) {
- var oHover = document.getElementById("slot_hover");
- if (oHover) {
- if (slot_hover_timer) {
- clearTimeout(slot_hover_timer);
- slot_hover_timer = null;
- }
- var width = slot_map_info.size;
- if (width == 0) return;
- var rx = col * width + slot_clip_left;
- var ry = row * width + slot_clip_top;
- oHover.style.width = (width-1) + "px";
- oHover.style.height = (width-1) + "px";
-
- switch (leg) {
- case 0:
- oHover.style.left = rx + "px";
- oHover.style.top = ry + "px";
- oHover.style.width = width + "px";
- oHover.style.height = width + "px";
- oHover.style.borderColor = "red pink pink pink";
- oHover.style.visibility = "visible";
- if ((rx < 0) || (ry < 0) || (rx + width > slot_clip_size) || (ry + width > slot_clip_size)) {
- var cx = (rx < 0) ? rx : 0;
- var cy = (ry < 0) ? ry : 0;
- var cw = (rx + width > slot_clip_size) ? slot_clip_size - rx : width + 1;
- var ch = (ry + width > slot_clip_size) ? slot_clip_size - ry : width + 1;
- oHover.style.clip = "rect(" + (-cy) + "px " + (cw) + "px " + (ch) + "px " + (-cx) + "px)";
- } else {
- oHover.style.clip = "rect(0px " + (width+1) + "px " + (width+1) + "px 0px)";
- }
- slot_hover_timer = setTimeout( function() {animate_hover(1)}, 500/3);
- break;
- case 1: oHover.style.borderColor = "red red pink pink";
- slot_hover_timer = setTimeout( function() {animate_hover(2)}, 500/3);
- break;
- case 2: oHover.style.borderColor = "red red red pink";
- slot_hover_timer = setTimeout( function() {animate_hover(3)}, 500/3);
- break;
- case 3: oHover.style.borderColor = "red red red red";
- break;
- }
- }
- }
-
- function refire_info() {
- if (slot_last_index > -1) {
- do_info_request(slot_last_index)
- }
- }
-
- function do_info_request(index) {
- var branch = wooly.session.branch(slot_info_url);
- branch.session[slot_info_index] = index;
- var newreq = branch.marshal();
- wooly.setIntervalUpdate(newreq, got_slot_info, 0, {index: index});
- }
-
- function got_slot_info(xhtml, args) {
- if (slot_last_index == -1) return;
- var oInfo = $(slot_info_id);
- var slot_clicked = null;
- if (oInfo) {
- oInfo.style.display = "none";
- if (oInfo.slot_clicked) {
- slot_clicked = oInfo.slot_clicked;
- oInfo.slot_clicked = null;
- }
- }
- wooly.updatePage(xhtml);
- var oInfo = $(slot_info_id);
- if (oInfo) {
- oInfo.click_index = args.index;
- oInfo.slot_clicked = null;
- if (slot_clicked) {
- clicks.doClick(slot_clicked.x, slot_clicked.y);
- return;
- }
-
- document.body.appendChild(oInfo); // so position is absolute to entire page
-
- //oInfo.style.left = "-1000px";
- //oInfo.style.visibility = "hidden";
- oInfo.style.display = "block";
-
- var oMap = document.getElementById(slot_current_id);
- if (oMap) {
- var abs_pos = findPos(oMap);
-
- // top of clicked slot is here
- var y = Math.floor(args.index / slot_map_info.cols) * slot_map_info.size + slot_clip_top;
-
- // candidate pos for popup
- // just under the clicked slot
- var topUnder = (abs_pos.y + y) + Math.floor(slot_map_info.size * 1.5);
- var top = topUnder;
-
- // if off the bottom of the map
- if (topUnder + oInfo.offsetHeight > abs_pos.y + oMap.offsetHeight) {
- // position popup above clicked slot
- top = (abs_pos.y + y) - oInfo.offsetHeight - Math.floor(slot_map_info.size * .5);
- }
-
- // if off the top of the page
- if (top < 0) {
- // revert to under the item
- top = topUnder;
- }
-
- oInfo.style.top = top + "px";
- oInfo.style.left = abs_pos.x + "px";
- }
- oInfo.style.visibility = "visible";
- }
- }
-
-}())
-
-var clicks;
-
-(function() {
- clicks = new Clicks();
-
- function Clicks() {
- this.doubleclick_when = 0;
- this.click_when = 0;
- this.click_handle = null;
-
- this.doMouseDown = function(e) {
- if (!e) var e = window.event;
- var which = e.type;
- switch (which) {
- case "click":
- // If we've just had a doubleclick then ignore it
- if (hadDoubleClick()) return false;
- // Otherwise set timer to act. It may be preempted by a doubleclick.
- d = new Date();
- clicks.click_when = d.getTime();
- var rpos = get_relative_event_pos(e);
- if (rpos) {
- clicks.click_handle = setTimeout( function() {clicks.doClick(rpos.x, rpos.y)}, 250);
- break;
- }
- case "dblclick":
- doDoubleClick(e);
- break;
- default:
- }
- }
-
- this.doClick = function(x, y) {
- // preempt if DC occurred after original click.
- if (this.click_when - this.doubleclick_when <= 0) {
- return false;
- }
- var oGlass = document.getElementById("slot_glass");
- if (oGlass) {
- if (oGlass.drug) {
- oGlass.drug = false;
- return false;
- }
- }
- var click_info = vis.get_index(x, y);
- var oInfo = $(slot_info_id);
- if (oInfo && click_info) {
- if ((typeof oInfo.click_index != "undefined") &&
- (oInfo.click_index == click_info.index)) {
- // we already fetched the info for this slot
- var oInfoCellId = document.getElementById("slotInfo_id");
- if (oInfoCellId) {
- var slotid = oInfoCellId.innerHTML;
- if (slotid != "") {
- go_to_slot(slotid);
- return false;
- }
- }
- } else {
- // fetch the slot info so we can get the slot id
- oInfo.slot_clicked = {fetching: true, x: x, y: y};
- vis.fire_slot_info(click_info.index);
- }
- }
- }
- }
-
- function hadDoubleClick() {
- var d = new Date();
- var now = d.getTime();
- if ((now - this.doubleclick_when) < 100) {
- return true;
- }
- return false;
- }
-
- function doDoubleClick(e) {
- var now = new Date();
- clicks.doubleclick_when = now.getTime();
- if (clicks.click_handle != null) {
- clearTimeout(clicks.click_handle); // Clear pending Click
- clicks.click_handle = null;
- }
- if (!e) var e = window.event;
- var posxy = get_relative_event_pos(e);
- vis.zoom_in_slots(posxy);
- }
-}())
-
-function go_to_slot(id) {
- if (show_slot_url != "") {
- var branch = wooly.session.branch(show_slot_url);
- branch[branch.frame + ".id"] = id;
- window.location.href = branch.marshal();
- }
-}
-function vis_clicked(slot) {
- go_to_slot(slot);
-}
-/* generic get value from cookie */
-function get_cookie(name) {
- return get_value(document.cookie, name, ";");
-}
-
-/* generic get value from string */
-function get_value(s, name, sep) {
- var name_plus = name + "=";
- var crumbs = s.split(sep);
- // splitting to avoid false match on substring:
- // ex: bigfoo=duh;foo=blah;
- for(var i=0; i < crumbs.length; i++) {
- var c = crumbs[i];
- while (c.charAt(0) == ' ') {
- c = c.substring(1, c.length);
- }
-
- if (c.indexOf(name_plus) == 0) {
- return c.substring(name_plus.length,c.length);
- }
- }
- return null;
-}
-
-/* generic replace a value in a name=value; string */
-function replace_value(s, name, value, sep) {
- var name_index = s.indexOf(name+"=");
- if (name_index > -1) {
- var sep_index = s.indexOf(sep, name_index);
- if (sep_index == -1) { // end of string
- sep_index = s.length;
- }
- var s1 = s.substring(0, name_index + name.length + 1);
- var s2 = value + "";
- var s3 = s.substring(sep_index);
- return s1 + s2 + s3;
- }
- return s;
-}
-
-/* get the absolute position of something */
-function findPos(obj) {
- var curleft = curtop = 0;
- if (obj.offsetParent) {
- do {
- curleft += obj.offsetLeft;
- curtop += obj.offsetTop;
- } while (obj = obj.offsetParent);
- return {x: curleft, y: curtop};
- }
-}
-
-/* get the absolute event position */
-function get_event_pos(e) {
- if (e.pageX || e.pageY) {
- posx = e.pageX;
- posy = e.pageY;
- }
- else if (e.clientX || e.clientY) {
- posx = e.clientX + document.body.scrollLeft
- + document.documentElement.scrollLeft;
- posy = e.clientY + document.body.scrollTop
- + document.documentElement.scrollTop;
- }
- return {"x": posx, "y": posy};
-}
-
-/* find out what element the event was the event target */
-function get_event_target(e) {
- var targ = null;
- if (e.target)
- targ = e.target;
- else if (e.srcElement)
- targ = e.srcElement;
- if (targ.nodeType == 3) // avoid Safari textNode bug
- targ = targ.parentNode;
- return targ;
-}
-
-/* get the event position relatave to the event target */
-function get_relative_event_pos(e) {
- var targ = get_event_target(e);
- if (targ) {
- var pxy = findPos(targ);
- var posxy = get_event_pos(e);
-
- var rx = posxy.x - pxy.x - 2;
- var ry = posxy.y - pxy.y - 2;
- return {x: rx, y: ry};
- }
-}
-
[SlotMap.css]
div#slot_hover {
visibility: hidden;
Added: mgmt/trunk/cumin/resources/slotvis.js
===================================================================
--- mgmt/trunk/cumin/resources/slotvis.js (rev 0)
+++ mgmt/trunk/cumin/resources/slotvis.js 2010-10-18 14:03:39 UTC (rev 4391)
@@ -0,0 +1,827 @@
+var vis;
+
+(function() {
+ vis = new Visualization();
+
+ var slot_clip_left;
+ var slot_clip_top;
+ var slot_zoom;
+ var slot_last_index;
+ var slot_info_timer;
+ var slot_hover_timer;
+ var slot_png_timer;
+ var slot_zoom_initialized;
+ var slot_center_index;
+
+ function Visualization() {
+ slot_clip_left = 0;
+ slot_clip_top = 0;
+ slot_zoom = 1;
+ slot_last_index = -1;
+ slot_info_timer = null;
+ slot_hover_timer = null;
+ slot_png_timer = null;
+ slot_zoom_initialized = false;
+ slot_center_index = -1;
+
+ this.notify = function(fullpage, size) {
+ slot_clip_size = size;
+ this.img_loaded(document.images[slot_current_id]);
+ }
+ this.pan_left = function () {
+ if (slot_clip_left == 0) return;
+ var now = new Date();
+ animate_pan(slot_clip_left, Math.min(Math.floor(slot_clip_size / 1.1), -slot_clip_left), (now-0), "slot_clip_left");
+ }
+
+ this.pan_right = function () {
+ var to_pan = Math.floor(slot_clip_size / 1.1);
+ if (slot_clip_left - slot_clip_size - to_pan < -slot_map_info.width) {
+ to_pan = slot_map_info.width - slot_clip_size + slot_clip_left;
+ }
+ var now = new Date();
+ animate_pan(slot_clip_left, -to_pan, (now-0), "slot_clip_left");
+ }
+
+ this.pan_up = function () {
+ if (slot_clip_top == 0) return;
+ var now = new Date();
+ animate_pan(slot_clip_top, Math.min(Math.floor(slot_clip_size / 1.1), -slot_clip_top), (now-0), "slot_clip_top");
+ }
+
+ this.pan_down = function () {
+ if (slot_map_info.height < slot_clip_size) return;
+
+ var to_pan = Math.floor(slot_clip_size / 1.1);
+ if (slot_clip_top - slot_clip_size - to_pan < -slot_map_info.height) {
+ to_pan = slot_map_info.height - slot_clip_size + slot_clip_top;
+ }
+ var now = new Date();
+ animate_pan(slot_clip_top, -to_pan, (now-0), "slot_clip_top");
+ }
+
+
+ // in case server stops and then restarts, reget the images
+ this.img_error = function (oImg) {
+ stop_auto_updates();
+ var oZooming = document.getElementById("slot_zooming");
+ if (oZooming) {
+ oZooming.style.display = "none";
+ }
+ oImg.style.visibility = "hidden"; // hide broken image indicator
+ slot_map_info.size = 0;
+ slot_map_info.width = 1;
+ slot_map_info.height = 1;
+ slot_map_info.rows = 1;
+ slot_map_info.cols = 1;
+ slot_map_info.count = 0;
+ slot_png_timer = setInterval(update_png, 10000);
+ }
+
+ this.img_loaded = function (oImg) {
+ stop_auto_updates();
+ var oZooming = document.getElementById("slot_zooming");
+ if (oZooming) {
+ oZooming.style.display = "none";
+ }
+
+ if (oImg) {
+ oImg.style.visibility = "visible";
+ slot_cookie_info();
+ oImg.width = slot_map_info.width;
+ oImg.height = slot_map_info.height;
+ set_pan("slot_panup", "width", slot_map_info.size * slot_map_info.cols, this.pan_up);
+ set_pan("slot_pandown", "width", slot_map_info.size * slot_map_info.cols, this.pan_down);
+ set_pan("slot_panleft", "height", slot_map_info.size * slot_map_info.rows, this.pan_left);
+ set_pan("slot_panright", "height", slot_map_info.size * slot_map_info.rows, this.pan_right);
+
+ var oMap = document.getElementById(slot_current_id);
+ if (oMap) {
+ oMap.style.width = Math.min(oImg.width, slot_clip_size) + "px";
+ oMap.style.height = Math.min(oImg.height, slot_clip_size) + "px";
+ if ((slot_map_info.size * slot_map_info.rows < slot_clip_size) &&
+ (slot_map_info.size * slot_map_info.cols < slot_clip_size))
+ oMap.style.borderColor = "transparent";
+ else
+ oMap.style.borderColor = "#CCCCCC";
+
+ }
+ var oGlass = document.getElementById("slot_glass");
+ if (oGlass) {
+ oGlass.style.width = Math.min(oImg.width, slot_clip_size) + "px";
+ oGlass.style.height = Math.min(oImg.height, slot_clip_size) + "px";
+ }
+ if (!slot_zoom_initialized)
+ initialize_zoom();
+
+ animate_zoom_to(slot_zoom);
+ var oControls = document.getElementById("slot_controls");
+ if (oControls) {
+ var oMap = document.getElementById(slot_current_id);
+ oControls.style.left = (oMap.offsetLeft + oMap.offsetWidth - oControls.offsetWidth) + "px";
+ //oControls.style.left = (420 - oControls.offsetWidth) + "px";
+ }
+ refire_info();
+ }
+ center_on_index();
+ draw_clipped();
+ slot_png_timer = setInterval(update_png, 6000);
+ }
+
+ this.upGlass = function (e) {
+ if (!e) var e = window.event;
+ var oGlass = document.getElementById("slot_glass");
+ if (oGlass) {
+ if (oGlass.dragging) {
+ oGlass.dragging = false;
+ }
+ }
+ }
+
+ this.moveGlass = function (e) {
+ if (slot_map_info.size == 0) return;
+ if (!e) var e = window.event;
+ var oGlass = document.getElementById("slot_glass");
+ if (oGlass) {
+ if (oGlass.dragging) {
+ var posxy = get_event_pos(e);
+ if ((posxy.x - oGlass.down_pos.x > 0) || (posxy.y - oGlass.down_pos.y > 0))
+ oGlass.down_pos = {x: posxy.x - slot_clip_left, y: posxy.y - slot_clip_top};
+
+ slot_clip_left = Math.min(posxy.x - oGlass.down_pos.x, 0);
+ slot_clip_top = Math.min(posxy.y - oGlass.down_pos.y, 0);
+ oGlass.drug = true;
+
+ draw_clipped();
+ if (e.preventDefault)
+ e.preventDefault();
+ return false;
+ }
+ }
+
+ var rpos = get_relative_event_pos(e);
+ if (rpos) {
+ get_slot_info(rpos.x, rpos.y);
+ }
+ }
+
+ this.downGlass = function (e) {
+ if (!e) var e = window.event;
+
+ var oGlass = document.getElementById("slot_glass");
+ if (oGlass) {
+ oGlass.dragging = true;
+ var posxy = get_event_pos(e);
+ oGlass.down_pos = {x: posxy.x - slot_clip_left, y: posxy.y - slot_clip_top};
+ clear_hover();
+ hide_info();
+ }
+ return false;
+ }
+
+ this.outGlass = function outGlass(e) {
+ if (!e) var e = window.event;
+ clear_hover();
+ hide_info();
+ }
+
+ this.zoom_in_slots = function (posxy) {
+ if (slot_zoom >= get_max_zoom()) return;
+ var click_info = vis.get_index(posxy.x, posxy.y);
+ slot_center_index = click_info.index;
+ do_zoom(slot_zoom + 1);
+ }
+
+ this.fire_slot_info = function (index) {
+ slot_last_index = index;
+ slot_info_timer = null;
+ do_info_request(index);
+ }
+
+ this.get_index = function (x, y) {
+ var width = slot_map_info.size;
+ var pngrow = Math.floor((y - slot_clip_top) / width);
+ var pngcol = Math.floor((x - slot_clip_left) / width);
+
+ if ((pngcol < slot_map_info.cols) && (pngrow < slot_map_info.rows)) {
+ var index = pngrow * slot_map_info.cols + pngcol;
+
+ if (index < slot_map_info.count)
+ return {"index": index, "row": pngrow, "col": pngcol};
+ }
+
+ return null;
+ }
+
+ }
+
+ function slot_zoom_to(e) {
+ if (!e) var e = window.event;
+ var targ = get_event_target(e);
+ var level = parseInt(targ.level, 10);
+
+ get_center_index();
+ do_zoom(level);
+
+ if (e.stopPropagation)
+ e.stopPropagation()
+ else if (e.cancelBubble)
+ e.cancelBubble = true;
+ }
+
+ function do_zoom(level) {
+ var old_zoom = slot_zoom;
+ slot_zoom = level;
+
+ stop_auto_updates();
+ var oZooming = document.getElementById("slot_zooming");
+ if (oZooming) {
+ oZooming.style.display = "block";
+ //var oMap = document.getElementById(slot_current_id);
+ //if (oMap) {
+ // oZooming.style.width = oMap.offsetWidth + "px";
+ //}
+ }
+ var oImg = document.images[slot_current_id];
+ if (oImg) {
+ var src = oImg.src;
+ var branch = wooly.session.branch(src);
+ branch.zl = level;
+ branch.zx = slot_clip_left;
+ branch.zy = slot_clip_top;
+ src = branch.marshal();
+
+ src = cumin.refreshTime(src);
+ oImg.src = src;
+ }
+
+ animate_zoom_to(level);
+ return false;
+ }
+
+ function animate_zoom_to(level) {
+ var oPos = document.getElementById("zoom_pos");
+ if (oPos) {
+ var original_x = oPos.offsetLeft;
+ var now = new Date();
+ var x_amount = ((level - 1) * 13) - original_x;
+ animate_zoom_pos(original_x, (now-0), x_amount)
+ }
+ }
+
+ function animate_zoom_pos(original_x, original_time, x_amount) {
+ var oPos = document.getElementById("zoom_pos");
+
+ if (oPos) {
+ var now = new Date();
+ var delta = (now - original_time) / 400.0;
+ var partial = 1;
+
+ if (delta < 1)
+ partial = Math.sin(Math.PI/2 * delta);
+
+ oPos.style.left = Math.floor(original_x + x_amount * partial) + "px";
+
+ if (delta < 1) {
+ setTimeout(function() {
+ animate_zoom_pos(original_x, original_time, x_amount)
+ }, 10);
+ }
+ }
+ }
+
+ function stop_auto_updates() {
+ if (slot_png_timer) {
+ clearInterval(slot_png_timer);
+ slot_png_timer = null;
+ }
+ }
+
+ function update_png() {
+ stop_auto_updates();
+ cumin.updateChart(slot_current_id, null);
+ }
+
+ function set_pan(id, which, value, fn) {
+ var obj = document.getElementById(id);
+ if (obj) {
+ if (value <= slot_clip_size) {
+ eval("obj.style." + which + " = '" + Math.min(value, slot_clip_size) + "px'");
+ obj.style.visibility = "hidden";
+ obj.onclick = null;
+ } else {
+ eval("obj.style." + which + " = '" + Math.min(value, slot_clip_size) + "px'");
+ obj.style.visibility = "visible";
+ obj.onclick = fn;
+ }
+ }
+ }
+
+ function slot_cookie_info() {
+ var slot_info = get_cookie("slot_info");
+ if (slot_info) {
+ var vals = slot_info.split("|");
+ if (vals.length == 6) {
+ slot_map_info.size = parseInt(vals[0], 10);
+ slot_map_info.width = parseInt(vals[1], 10);
+ slot_map_info.height = parseInt(vals[2], 10);
+ slot_map_info.count = parseInt(vals[3], 10);
+ slot_map_info.rows = parseInt(vals[4], 10);
+ slot_map_info.cols = parseInt(vals[5], 10);
+ }
+ }
+ }
+
+ function center_on_index() {
+ if (slot_center_index == -1) return;
+
+ var row = slot_center_index % slot_map_info.cols;
+ var col = Math.floor(slot_center_index / slot_map_info.cols);
+ var x = col * slot_map_info.size + slot_map_info.size / 2;
+ var y = row * slot_map_info.size + slot_map_info.size / 2;
+
+ var cl = (Math.min(slot_clip_size, slot_map_info.width) / 2) - x;
+ var ct = (Math.min(slot_clip_size, slot_map_info.height) / 2) - y;
+
+ if (slot_map_info.width + cl < slot_clip_size)
+ cl = slot_clip_size - slot_map_info.width;
+
+ if (slot_map_info.height + ct < slot_clip_size)
+ ct = slot_clip_size - slot_map_info.height;
+
+ if (cl > 0) cl = 0;
+ if (ct > 0) ct = 0;
+
+ slot_clip_left = Math.floor(cl);
+ slot_clip_top = Math.floor(ct);
+ slot_center_index = -1;
+ }
+
+ function get_center_index() {
+ var rx = Math.min(slot_clip_size, slot_map_info.width) / 2;
+ var ry = Math.min(slot_clip_size, slot_map_info.height) / 2;
+
+ var click_info = vis.get_index(rx, ry);
+ if (click_info)
+ slot_center_index = click_info.index;
+ }
+
+ function get_max_zoom() {
+ // allow to zoom until each slot is at least 28px wide
+ if ((slot_map_info.size == 0) || (slot_zoom == 0))
+ return 1;
+ return Math.ceil(28 / (slot_map_info.size / slot_zoom));
+ }
+
+ function initialize_zoom() {
+ var max_zoom = get_max_zoom();
+ var oZoom = document.getElementById("zoom_levels");
+ if ((oZoom) && (max_zoom > 1)) {
+ var oDiv, oText, oNode;
+ for (var i=0; i<max_zoom; i++) {
+ var oDiv = document.createElement("div");
+ if (i == 0) {
+ oDiv.className = "zoom_first";
+ oDiv.onclick = slot_zoom_to;
+ oDiv.level = i+1;
+ set_text(oDiv, (i+1)+ "", "zoom_node");
+ } else if (i == max_zoom - 1) {
+ oDiv.className = "zoom_last";
+ oDiv.onclick = slot_zoom_to;
+ oDiv.level = i+1;
+ set_text(oDiv, i+1, "zoom_node_last");
+ } else {
+ oDiv.className = "zoom_middle_left";
+ oDiv.onclick = slot_zoom_to;
+ oDiv.level = i+1;
+ oZoom.appendChild(oDiv);
+ oDiv = document.createElement("div");
+ oDiv.className = "zoom_middle_right";
+ oDiv.onclick = slot_zoom_to;
+ oDiv.level = i+1;
+ set_text(oDiv, (i+1)+ "", "zoom_node");
+ }
+ oZoom.appendChild(oDiv);
+ }
+ } else {
+ var oControls = document.getElementById("slot_controls");
+ if (oControls) {
+ oControls.style.display = "none";
+ }
+ }
+ $("slot_visualization").style.display = "block";
+ cumin.makeFullPageable($("slot_visualization"));
+ slot_zoom_initialized = true;
+
+ function set_text(odiv, text, className) {
+ var oText = document.createElement("div");
+ var oNode = document.createTextNode(text+"");
+ oText.className = className;
+ oText.appendChild(oNode);
+ odiv.appendChild(oText);
+ oText.onclick = slot_zoom_to;
+ oText.level = text;
+ }
+ }
+
+ function draw_clipped() {
+
+ var clip_bottom;
+ var clip_right;
+ if (slot_map_info.width < slot_clip_size) {
+ clip_bottom = slot_map_info.height;
+ clip_right = slot_map_info.width;
+ slot_clip_left = 0;
+ slot_clip_top = 0;
+ } else {
+ var iZoom = slot_zoom;
+ var clip_width = slot_clip_size;
+ var clip_height = slot_clip_size;
+ clip_bottom = clip_height - slot_clip_top;
+ clip_right = clip_width - slot_clip_left;
+
+ if (clip_right > slot_map_info.width) {
+ slot_clip_left += (clip_right - slot_map_info.width);
+ clip_right = slot_map_info.width;
+ }
+ if (clip_bottom > slot_map_info.height) {
+ slot_clip_top = Math.min(clip_height - slot_map_info.height, 0);
+ clip_bottom = slot_map_info.height;
+ }
+ }
+
+ var oPng = document.getElementById("slot_png");
+ if (oPng) {
+ oPng.style.left = slot_clip_left + "px";
+ oPng.style.top = slot_clip_top + "px";
+ oPng.style.clip = "rect(" + (-slot_clip_top) + "px " + clip_right + "px " + clip_bottom + "px " + (-slot_clip_left) + "px)";
+ }
+ }
+
+
+ function animate_pan(original_edge, move, timer, which) {
+ var now = new Date();
+ var delta = (now - timer) / 400.0;
+ var expression = "=Math.floor(original_edge + move";
+ if (delta < 1) {
+ expression += " * Math.sin(Math.PI/2 * delta)";
+ }
+ expression += ")";
+ eval(which + expression);
+ draw_clipped();
+ if (delta < 1)
+ setTimeout( function () {animate_pan(original_edge, move, timer, which) }, 10);
+
+ }
+
+ function clear_hover() {
+ if (slot_info_timer) {
+ clearTimeout(slot_info_timer);
+ slot_info_timer = null;
+ slot_last_index = -1;
+ }
+ oHover = document.getElementById("slot_hover");
+ if (oHover) {
+ oHover.style.visibility = "hidden";
+ }
+ }
+
+ function hide_info() {
+ oInfo = $(slot_info_id);
+ if (oInfo) {
+ oInfo.style.visibility = "hidden";
+ }
+ slot_last_index = -1;
+ }
+
+ function get_slot_info(rx, ry) {
+ var click_info = vis.get_index(rx, ry);
+ if (click_info) {
+ if (click_info.index != slot_last_index) {
+ if (slot_info_timer) {
+ clearTimeout(slot_info_timer);
+ slot_info_timer = null;
+ }
+ if (slot_hover_timer) {
+ clearTimeout(slot_hover_timer);
+ slot_hover_timer = null;
+ }
+ slot_info_timer = setTimeout( function() { vis.fire_slot_info(click_info.index) }, 500);
+ animate_hover(0, click_info.row, click_info.col);
+ oInfo = $(slot_info_id);
+ if (oInfo) {
+ oInfo.style.display = "none";
+ }
+ }
+ }
+ }
+
+ function animate_hover(leg, row, col) {
+ var oHover = document.getElementById("slot_hover");
+ if (oHover) {
+ if (slot_hover_timer) {
+ clearTimeout(slot_hover_timer);
+ slot_hover_timer = null;
+ }
+ var width = slot_map_info.size;
+ if (width == 0) return;
+ var rx = col * width + slot_clip_left;
+ var ry = row * width + slot_clip_top;
+ oHover.style.width = (width-1) + "px";
+ oHover.style.height = (width-1) + "px";
+
+ switch (leg) {
+ case 0:
+ oHover.style.left = rx + "px";
+ oHover.style.top = ry + "px";
+ oHover.style.width = width + "px";
+ oHover.style.height = width + "px";
+ oHover.style.borderColor = "red pink pink pink";
+ oHover.style.visibility = "visible";
+ if ((rx < 0) || (ry < 0) || (rx + width > slot_clip_size) || (ry + width > slot_clip_size)) {
+ var cx = (rx < 0) ? rx : 0;
+ var cy = (ry < 0) ? ry : 0;
+ var cw = (rx + width > slot_clip_size) ? slot_clip_size - rx : width + 1;
+ var ch = (ry + width > slot_clip_size) ? slot_clip_size - ry : width + 1;
+ oHover.style.clip = "rect(" + (-cy) + "px " + (cw) + "px " + (ch) + "px " + (-cx) + "px)";
+ } else {
+ oHover.style.clip = "rect(0px " + (width+1) + "px " + (width+1) + "px 0px)";
+ }
+ slot_hover_timer = setTimeout( function() {animate_hover(1)}, 500/3);
+ break;
+ case 1: oHover.style.borderColor = "red red pink pink";
+ slot_hover_timer = setTimeout( function() {animate_hover(2)}, 500/3);
+ break;
+ case 2: oHover.style.borderColor = "red red red pink";
+ slot_hover_timer = setTimeout( function() {animate_hover(3)}, 500/3);
+ break;
+ case 3: oHover.style.borderColor = "red red red red";
+ break;
+ }
+ }
+ }
+
+ function refire_info() {
+ if (slot_last_index > -1) {
+ do_info_request(slot_last_index)
+ }
+ }
+
+ function do_info_request(index) {
+ var branch = wooly.session.branch(slot_info_url);
+ branch.session[slot_info_index] = index;
+ var newreq = branch.marshal();
+ wooly.setIntervalUpdate(newreq, got_slot_info, 0, {index: index});
+ }
+
+ function got_slot_info(xhtml, args) {
+ if (slot_last_index == -1) return;
+ var oInfo = $(slot_info_id);
+ var slot_clicked = null;
+ if (oInfo) {
+ oInfo.style.display = "none";
+ if (oInfo.slot_clicked) {
+ slot_clicked = oInfo.slot_clicked;
+ oInfo.slot_clicked = null;
+ }
+ }
+ wooly.updatePage(xhtml);
+ var oInfo = $(slot_info_id);
+ if (oInfo) {
+ oInfo.click_index = args.index;
+ oInfo.slot_clicked = null;
+ if (slot_clicked) {
+ clicks.doClick(slot_clicked.x, slot_clicked.y);
+ return;
+ }
+
+ document.body.appendChild(oInfo); // so position is absolute to entire page
+
+ //oInfo.style.left = "-1000px";
+ //oInfo.style.visibility = "hidden";
+ oInfo.style.display = "block";
+
+ var oMap = document.getElementById(slot_current_id);
+ if (oMap) {
+ var abs_pos = findPos(oMap);
+
+ // top of clicked slot is here
+ var y = Math.floor(args.index / slot_map_info.cols) * slot_map_info.size + slot_clip_top;
+
+ // candidate pos for popup
+ // just under the clicked slot
+ var topUnder = (abs_pos.y + y) + Math.floor(slot_map_info.size * 1.5);
+ var top = topUnder;
+
+ // if off the bottom of the map
+ if (topUnder + oInfo.offsetHeight > abs_pos.y + oMap.offsetHeight) {
+ // position popup above clicked slot
+ top = (abs_pos.y + y) - oInfo.offsetHeight - Math.floor(slot_map_info.size * .5);
+ }
+
+ // if off the top of the page
+ if (top < 0) {
+ // revert to under the item
+ top = topUnder;
+ }
+
+ oInfo.style.top = top + "px";
+ oInfo.style.left = abs_pos.x + "px";
+ }
+ oInfo.style.visibility = "visible";
+ }
+ }
+
+}())
+
+var clicks;
+
+(function() {
+ clicks = new Clicks();
+
+ function Clicks() {
+ this.doubleclick_when = 0;
+ this.click_when = 0;
+ this.click_handle = null;
+
+ this.doMouseDown = function(e) {
+ if (!e) var e = window.event;
+ var which = e.type;
+ switch (which) {
+ case "click":
+ // If we've just had a doubleclick then ignore it
+ if (hadDoubleClick()) return false;
+ // Otherwise set timer to act. It may be preempted by a doubleclick.
+ d = new Date();
+ clicks.click_when = d.getTime();
+ var rpos = get_relative_event_pos(e);
+ if (rpos) {
+ clicks.click_handle = setTimeout( function() {clicks.doClick(rpos.x, rpos.y)}, 250);
+ break;
+ }
+ case "dblclick":
+ doDoubleClick(e);
+ break;
+ default:
+ }
+ }
+
+ this.doClick = function(x, y) {
+ // preempt if DC occurred after original click.
+ if (this.click_when - this.doubleclick_when <= 0) {
+ return false;
+ }
+ var oGlass = document.getElementById("slot_glass");
+ if (oGlass) {
+ if (oGlass.drug) {
+ oGlass.drug = false;
+ return false;
+ }
+ }
+ var click_info = vis.get_index(x, y);
+ var oInfo = $(slot_info_id);
+ if (oInfo && click_info) {
+ if ((typeof oInfo.click_index != "undefined") &&
+ (oInfo.click_index == click_info.index)) {
+ // we already fetched the info for this slot
+ var oInfoCellId = document.getElementById("slotInfo_id");
+ if (oInfoCellId) {
+ var slotid = oInfoCellId.innerHTML;
+ if (slotid != "") {
+ go_to_slot(slotid);
+ return false;
+ }
+ }
+ } else {
+ // fetch the slot info so we can get the slot id
+ oInfo.slot_clicked = {fetching: true, x: x, y: y};
+ vis.fire_slot_info(click_info.index);
+ }
+ }
+ }
+ }
+
+ function hadDoubleClick() {
+ var d = new Date();
+ var now = d.getTime();
+ if ((now - this.doubleclick_when) < 100) {
+ return true;
+ }
+ return false;
+ }
+
+ function doDoubleClick(e) {
+ var now = new Date();
+ clicks.doubleclick_when = now.getTime();
+ if (clicks.click_handle != null) {
+ clearTimeout(clicks.click_handle); // Clear pending Click
+ clicks.click_handle = null;
+ }
+ if (!e) var e = window.event;
+ var posxy = get_relative_event_pos(e);
+ vis.zoom_in_slots(posxy);
+ }
+}())
+
+function go_to_slot(id) {
+ if (show_slot_url != "") {
+ var branch = wooly.session.branch(show_slot_url);
+ branch[branch.frame + ".id"] = id;
+ window.location.href = branch.marshal();
+ }
+}
+function vis_clicked(slot) {
+ go_to_slot(slot);
+}
+/* generic get value from cookie */
+function get_cookie(name) {
+ return get_value(document.cookie, name, ";");
+}
+
+/* generic get value from string */
+function get_value(s, name, sep) {
+ var name_plus = name + "=";
+ var crumbs = s.split(sep);
+ // splitting to avoid false match on substring:
+ // ex: bigfoo=duh;foo=blah;
+ for(var i=0; i < crumbs.length; i++) {
+ var c = crumbs[i];
+ while (c.charAt(0) == ' ') {
+ c = c.substring(1, c.length);
+ }
+
+ if (c.indexOf(name_plus) == 0) {
+ return c.substring(name_plus.length,c.length);
+ }
+ }
+ return null;
+}
+
+/* generic replace a value in a name=value; string */
+function replace_value(s, name, value, sep) {
+ var name_index = s.indexOf(name+"=");
+ if (name_index > -1) {
+ var sep_index = s.indexOf(sep, name_index);
+ if (sep_index == -1) { // end of string
+ sep_index = s.length;
+ }
+ var s1 = s.substring(0, name_index + name.length + 1);
+ var s2 = value + "";
+ var s3 = s.substring(sep_index);
+ return s1 + s2 + s3;
+ }
+ return s;
+}
+
+/* get the absolute position of something */
+function findPos(obj) {
+ var curleft = curtop = 0;
+ if (obj.offsetParent) {
+ do {
+ curleft += obj.offsetLeft;
+ curtop += obj.offsetTop;
+ } while (obj = obj.offsetParent);
+ return {x: curleft, y: curtop};
+ }
+}
+
+/* get the absolute event position */
+function get_event_pos(e) {
+ if (e.pageX || e.pageY) {
+ posx = e.pageX;
+ posy = e.pageY;
+ }
+ else if (e.clientX || e.clientY) {
+ posx = e.clientX + document.body.scrollLeft
+ + document.documentElement.scrollLeft;
+ posy = e.clientY + document.body.scrollTop
+ + document.documentElement.scrollTop;
+ }
+ return {"x": posx, "y": posy};
+}
+
+/* find out what element the event was the event target */
+function get_event_target(e) {
+ var targ = null;
+ if (e.target)
+ targ = e.target;
+ else if (e.srcElement)
+ targ = e.srcElement;
+ if (targ.nodeType == 3) // avoid Safari textNode bug
+ targ = targ.parentNode;
+ return targ;
+}
+
+/* get the event position relatave to the event target */
+function get_relative_event_pos(e) {
+ var targ = get_event_target(e);
+ if (targ) {
+ var pxy = findPos(targ);
+ var posxy = get_event_pos(e);
+
+ var rx = posxy.x - pxy.x - 2;
+ var ry = posxy.y - pxy.y - 2;
+ return {x: rx, y: ry};
+ }
+}
+
14 years, 2 months
rhmessaging commits: r4390 - in mgmt/trunk: wooly/python/wooly and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2010-10-15 12:48:35 -0400 (Fri, 15 Oct 2010)
New Revision: 4390
Modified:
mgmt/trunk/cumin/python/cumin/main.strings
mgmt/trunk/cumin/python/cumin/widgets.strings
mgmt/trunk/wooly/python/wooly/__init__.py
Log:
Introduce a resource prefix variable for redirecting requests for static resources
Modified: mgmt/trunk/cumin/python/cumin/main.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/main.strings 2010-10-15 16:39:45 UTC (rev 4389)
+++ mgmt/trunk/cumin/python/cumin/main.strings 2010-10-15 16:48:35 UTC (rev 4390)
@@ -24,14 +24,14 @@
<tr>
<td>
<div class="fullpageable">
- <h2><img src="resource?name=queue-20.png"/> Deepest Message Queues</h2>
+ <h2><img src="{resource_prefix}/queue-20.png"/> Deepest Message Queues</h2>
<div class="iblock">{queues}</div>
</div>
</td>
<td>
<div class="fullpageable">
- <h2><img src="resource?name=job-20.png"/> Longest Running Grid Submissions</h2>
+ <h2><img src="{resource_prefix}/job-20.png"/> Longest Running Grid Submissions</h2>
<div class="iblock">{submissions}</div>
</div>
</td>
@@ -39,7 +39,7 @@
<tr>
<td>
<div class="fullpageable">
- <h2><img src="resource?name=system-20.png"/> Busiest Systems</h2>
+ <h2><img src="{resource_prefix}/system-20.png"/> Busiest Systems</h2>
<div class="iblock">{systems}</div>
</div>
@@ -66,7 +66,7 @@
[ConfigurationNotice.html]
<div class="ConfigurationNotice">
- <h1><img src="resource?name=warning-36.png"/> QMF server not found</h1>
+ <h1><img src="{resource_prefix}/warning-36.png"/> QMF server not found</h1>
<p>This console is not connected to any QMF servers and as a result
has no management data to display.</p>
Modified: mgmt/trunk/cumin/python/cumin/widgets.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.strings 2010-10-15 16:39:45 UTC (rev 4389)
+++ mgmt/trunk/cumin/python/cumin/widgets.strings 2010-10-15 16:48:35 UTC (rev 4390)
@@ -145,7 +145,7 @@
[CuminMainView.html]
<div id="head">
- <img id="logo" src="resource?name=mrg-logo-32.png"/>
+ <img id="logo" src="{resource_prefix}/mrg-logo-32.png"/>
<div id="user">
Hi, {user_name}
Modified: mgmt/trunk/wooly/python/wooly/__init__.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/__init__.py 2010-10-15 16:39:45 UTC (rev 4389)
+++ mgmt/trunk/wooly/python/wooly/__init__.py 2010-10-15 16:48:35 UTC (rev 4390)
@@ -340,6 +340,9 @@
def render_title(self, session, *args):
return None
+ def render_resource_prefix(self, session, *args):
+ return self.page.get_resource_prefix(session)
+
def render_content(self, session, *args):
writer = Writer()
@@ -447,6 +450,9 @@
def get_cache_control(self, session):
return None
+ def get_resource_prefix(self, session):
+ return "resource?name="
+
def show(self, session):
pass
14 years, 2 months
rhmessaging commits: r4389 - mgmt/trunk/wooly/python/wooly.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2010-10-15 12:39:45 -0400 (Fri, 15 Oct 2010)
New Revision: 4389
Modified:
mgmt/trunk/wooly/python/wooly/pages.py
Log:
Use a map to lookup content types; tolerate resource names with leading slashes
Modified: mgmt/trunk/wooly/python/wooly/pages.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/pages.py 2010-10-15 15:46:31 UTC (rev 4388)
+++ mgmt/trunk/wooly/python/wooly/pages.py 2010-10-15 16:39:45 UTC (rev 4389)
@@ -323,6 +323,16 @@
return self.get_javascript()
class ResourcePage(Page):
+ content_types_by_extension = {
+ ".css": "text/css",
+ ".gif": "image/gif",
+ ".html": "text/html",
+ ".jpeg": "image/jpeg",
+ ".jpg": "image/jpeg",
+ ".js": "test/javascript",
+ ".png": "image/png",
+ }
+
def __init__(self, app, name):
super(ResourcePage, self).__init__(app, name)
@@ -336,29 +346,19 @@
def get_content_type(self, session):
name = self.rname.get(session)
+ base, ext = os.path.splitext(name)
+ ext = ext.lower()
+ content_type = self.content_types_by_extension.get(ext, "text/plain")
- if name:
- if name.endswith(".png"):
- type = "image/png"
- if name.endswith(".gif"):
- type = "image/gif"
- elif name.endswith(".jpeg"):
- type = "image/jpeg"
- elif name.endswith(".html"):
- type = "text/html"
- elif name.endswith(".css"):
- type = "text/css"
- elif name.endswith(".js"):
- type = "text/javascript"
- else:
- type = "text/plain"
+ return content_type
- return type
-
def do_render(self, session, *args):
name = self.rname.get(session)
if name:
+ if name.startswith("/"):
+ name = name[1:]
+
resource = self.app.get_resource(name)
if resource:
14 years, 2 months