Permalink
Browse files

JS progress

  • Loading branch information...
1 parent 4ee5e2f commit f7ca495ff65f2ab24bce44e30ce28ea8a5e8c171 @timurhai timurhai committed Aug 16, 2012
@@ -11,7 +11,7 @@ g_key_ctrl = false;
g_key_shift = false;
g_recievers = [];
-g_updaters = [];
+g_refreshers = [];
g_monitors = [];
g_cur_monitor = null;
g_monitor_buttons = [];
@@ -56,10 +56,10 @@ function g_ProcessMsg( obj)
}
}
-function g_Update()
+function g_Refresh()
{
g_cycle++;
- setTimeout("g_Update()", 1000);
+ setTimeout("g_Refresh()", 1000);
// document.getElementById('id').innerHTML = 'ID = ' + g_id + ' c' + g_cycle;
@@ -68,9 +68,9 @@ function g_Update()
nw_GetEvents('monitors','events');
- for( i = 0; i < g_updaters.length; i++)
+ for( i = 0; i < g_refreshers.length; i++)
{
- g_updaters[i].update();
+ g_refreshers[i].refresh();
}
}
@@ -82,7 +82,7 @@ function g_Init()
g_monitor_buttons[i].onclick = g_MButtonClick;
g_Register();
- g_Update();
+ g_Refresh();
cm_Init();
}
@@ -94,9 +94,14 @@ function cm_IdsMerge( i_ids1, i_ids2)
return o_ids;
}
-function cm_TimeStringFromNow( time)
+function cm_TimeStringInterval( time1, time2)
{
- time = new Date() - new Date( time * 1000);
+ if( time2 == null )
+ time2 = new Date();
+ else
+ time2 = new Date( time2 * 1000);
+
+ time = time2 - new Date( time1 * 1000);
var seconds = Math.floor(time / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
@@ -117,26 +122,26 @@ function cm_TimeStringFromNow( time)
}
cm_States = ['RDY','RUN','DON','ERR','SKP','OFF','WDP','WTM','DRT','NbY','NBY'];
-function cm_GetState( i_state, i_el)
+function cm_GetState( i_state, i_elParent, i_elChild)
{
- var state = {};
if( i_state == null )
- {
- state.string = '-';
- return state;
- }
+ i_elChild.innerHTML = '-';
+ else
+ i_elChild.innerHTML = i_state;
- state.string = i_state;
for( var i = 0; i < cm_States.length; i++)
{
- if( i_el ) i_el.classList.remove( cm_States[i]);
- if( i_state.indexOf( cm_States[i]) != -1 )
+ i_elParent.classList.remove( cm_States[i]);
+ if( i_state )
{
- eval('state.' + cm_States[i] + ' = true;');
- if( i_el ) i_el.classList.add( cm_States[i]);
+ if( i_state.indexOf( cm_States[i]) != -1 )
+ {
+ eval('i_elChild.' + cm_States[i] + ' = true;');
+ i_elParent.classList.add( cm_States[i]);
+ }
+ else
+ eval('i_elChild.' + cm_States[i] + ' = false;');
}
}
-
- return state;
}
@@ -5,6 +5,7 @@ JobNode.prototype.init = function()
this.element.classList.add('job');
this.name = document.createElement('span');
+ this.name.classList.add('name');
this.element.appendChild( this.name);
this.name.title = 'Job name';
@@ -67,18 +68,12 @@ JobNode.prototype.init = function()
JobNode.prototype.update = function()
{
- var state = cm_GetState( this.params.state, this.element);
- this.state.innerHTML = state.string;
+ cm_GetState( this.params.state, this.element, this.state);
+// this.state.innerHTML = state.string;
this.name.innerHTML = this.params.name;
this.priority.innerHTML = ' p' + this.params.priority;
this.user_name.innerHTML = this.params.user_name;
- var time = this.params.time_started;
- if( time )
- this.time.innerHTML = time;
- else
- this.time.innerHTML = '';
-
if( this.params.depend_mask )
this.depend_mask.innerHTML = ' d(' + this.params.depend_mask + ') ';
else
@@ -109,6 +104,23 @@ JobNode.prototype.update = function()
this.blocks[b].params = this.params.blocks[b];
this.blocks[b].update();
}
+
+ this.refresh();
+}
+
+JobNode.prototype.refresh = function()
+{
+ var time = this.params.time_started;
+ if( time )
+ {
+ if( this.state.DON == true )
+ time = cm_TimeStringInterval( this.params.time_started, this.params.time_done )
+ else
+ time = cm_TimeStringInterval( time);
+ this.time.innerHTML = time;
+ }
+ else
+ this.time.innerHTML = '';
}
JobNode.prototype.onDoubleClick = function()
@@ -63,7 +63,7 @@ function Monitor( i_element, i_type, i_id)
}
else
{
- g_updaters.push( this);
+ g_refreshers.push( this);
nw_Subscribe( this.type, true);
nw_GetNodes( this.type);
}
@@ -76,7 +76,7 @@ Monitor.prototype.destroy = function()
if( g_cur_monitor == this )
g_cur_monitor = null;
cm_ArrayRemove( g_recievers, this);
- cm_ArrayRemove( g_updaters, this);
+ cm_ArrayRemove( g_refreshers, this);
cm_ArrayRemove( g_monitors, this);
if( this.type == 'tasks')
nw_Subscribe( this.type, false, [this.job_id]);
@@ -91,8 +91,10 @@ Monitor.prototype.destroy = function()
this.elParent.removeChild( this.elMonitor);
}
-Monitor.prototype.update = function()
+Monitor.prototype.refresh = function()
{
+ for( i = 0; i < this.items.length; i++)
+ this.items[i].refresh();
}
Monitor.prototype.processMsg = function( obj)
@@ -415,19 +417,19 @@ Monitor.prototype.getBlocks = function( i_block_ids)
blocks = [];
modes = [];
-var test = 'block ids:'
-document.getElementById('test').innerHTML = test;
+//var test = 'block ids:'
+//document.getElementById('test').innerHTML = test;
for( var i = 0; i < i_block_ids.job_id.length; i++)
{
if( this.job_id != i_block_ids.job_id[i]) continue;
-test += ' n' + i_block_ids.block_num[i];
-test += ' m' + i_block_ids.mode[i];
+//test += ' n' + i_block_ids.block_num[i];
+//test += ' m' + i_block_ids.mode[i];
blocks.push( i_block_ids.block_num[i]);
modes.push( i_block_ids.mode[i]);
}
-document.getElementById('test').innerHTML = test;
+//document.getElementById('test').innerHTML = test;
if( blocks.length == 0 ) return;
@@ -3,6 +3,7 @@ function RenderNode() {}
RenderNode.prototype.init = function()
{
this.name = document.createElement('span');
+ this.name.classList.add('name');
this.element.appendChild( this.name);
this.name.title = 'Client host name';
@@ -34,21 +35,23 @@ RenderNode.prototype.init = function()
this.element.appendChild( this.max_tasks);
this.max_tasks.title = 'Running tasks / maximum'
- this.state = document.createElement('span');
- this.element.appendChild( this.state);
- this.state.style.cssFloat = 'right';
- this.state.title = 'Busy / free status and time';
+ this.stateTime = document.createElement('span');
+ this.element.appendChild( this.stateTime);
+ this.stateTime.style.cssFloat = 'right';
+ this.stateTime.title = 'Busy / free status and time';
this.annotation = document.createElement('div');
this.element.appendChild( this.annotation);
this.annotation.title = 'Annotation';
this.annotation.style.textAlign = 'center';
+
+ this.state = {};
}
RenderNode.prototype.update = function()
{
var user = this.params.user_name;
- var state = cm_GetState( this.params.state, this.element);
+ cm_GetState( this.params.state, this.element, this.state);
this.name.innerHTML = this.params.name;
if( this.params.version != null )
@@ -65,12 +68,13 @@ RenderNode.prototype.update = function()
else
this.annotation.innerHTML = '';
- if( state.OFF )
+ if( this.state.OFF == true )
{
this.center.innerHTML = 'offline';
this.capacity.innerHTML = '';
this.max_tasks.innerHTML = '';
this.state.innerHTML = '';
+ this.refresh();
return;
}
this.center.innerHTML = '.';
@@ -91,14 +95,23 @@ RenderNode.prototype.update = function()
max_tasks = ' ' + max_tasks;
this.max_tasks.innerHTML = max_tasks;
- var state = 'NEW';
+ this.refresh();
+}
+
+RenderNode.prototype.refresh = function()
+{
+ var stateTime = 'NEW';
if(( this.params.task_start_finish_time != null ) && ( this.params.task_start_finish_time > 0 ))
{
- state = cm_TimeStringFromNow( this.params.task_start_finish_time);
- if( this.params.busy === true )
- state += ' busy';
+ stateTime = cm_TimeStringInterval( this.params.task_start_finish_time);
+ if( this.state.RUN == true )
+ stateTime += ' busy';
else
- state += ' free';
+ stateTime += ' free';
}
- this.state.innerHTML = state;
+ this.stateTime.innerHTML = stateTime;
+}
+
+RenderNode.prototype.onDoubleClick = function()
+{
}
@@ -1,8 +1,9 @@
body {
font: 16px Arial;
+font-weight: bold;
background: #ab8;
-/*user-select: none;
--moz-user-select: none;*/
+user-select: none;
+-moz-user-select: none;
}
* {
@@ -40,7 +41,6 @@ margin: 10px;
padding: 5px;
cursor: pointer;
text-transform: uppercase;
-font-weight: bold;
color: #222;
box-shadow: 0px 0px 2px #000;
}
@@ -55,7 +55,6 @@ box-shadow: 0px 0px 5px #000 inset;
position: absolute;
top: 0; bottom: 0; left: 0; right: 0;
font-size: 12px;
-font-weight: bold;
}
.monitor .ctrl,.info {
@@ -76,7 +75,7 @@ overflow: auto;
top: 40px;
bottom: 40px;
/*background: #CCD;*/
--moz-user-select: none;
+/*-moz-user-select: none;*/
}
.monitor .ctrl .sort,.filter {
@@ -175,3 +174,9 @@ width: 0%;
height: 100%;
opacity: 0.3;
}
+
+.name {
+font-size: 14px;
+/*font-weight: bold;*/
+}
+
@@ -24,8 +24,7 @@ BlockItem.prototype.init = function()
BlockItem.prototype.update = function()
{
- var state = cm_GetState( this.params.state);
- this.state.innerHTML = state.string + '-';
+ cm_GetState( this.params.state, this.element, this.state);
if( this.params.tasks )
this.props.innerHTML = 'array';
@@ -83,17 +82,17 @@ TaskItem.prototype.updateProgress = function( i_progress)
{
// this.progress = progress;
- var state = cm_GetState( i_progress.state);
- this.state.innerHTML = state.string;
+ cm_GetState( i_progress.state, this.element, this.state);
+// this.state.innerHTML = state.string;
var percent = 0;
- if( state.run && i_progress.per ) percent = i_progress.per;
- if( state.don ) percent = 100;
- if( state.skp ) percent = 100;
+ if( this.state.RUN && i_progress.per ) percent = i_progress.per;
+ if( this.state.DON ) percent = 100;
+ if( this.state.SKP ) percent = 100;
if( percent < 0 ) percent = 0;
if( percent > 100 ) percent = 100;
- if( state.run)
+ if( this.state.RUN )
this.percent.innerHTML = ' ' + percent + '%';
else
this.percent.innerHTML = '';
Oops, something went wrong.

0 comments on commit f7ca495

Please sign in to comment.