Skip to content

Commit 3afedc1

Browse files
author
Vidas P
committed
Fully live update diagram badges
1 parent 480ae7a commit 3afedc1

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

app/assets/javascripts/diagram.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,32 @@ window.updateDiagram = function(options){
2525
const badge = $(this);
2626
badge.css({
2727
left: tl.x - (badge.outerWidth() * (2/3)),
28-
top: tl.y - (badge.outerHeight() * (1/3)),
29-
'background-color': badge.find('.badge').css('background-color')});
28+
top: tl.y - (badge.outerHeight() * (1/3))
29+
});
3030
});
3131
});
3232
};
3333

3434
window.updateDiagramStatus = function(json) {
35-
var setBadge = function(agent_id, count) {
35+
var setBadge = function(agent_id, count, working) {
3636
var selector = `#b${agent_id}`;
3737
if (count > 0) {
3838
$(selector).show();
39-
$(`${selector} span.count`).text(count);
39+
$(`${selector}`).text(count);
40+
$(`${selector}`).attr('title', `${count} messages created`);
41+
if (working) {
42+
$(`${selector}`).removeClass('badge-danger');
43+
$(`${selector}`).addClass('badge-success');
44+
} else {
45+
$(`${selector}`).removeClass('badge-success');
46+
$(`${selector}`).addClass('badge-danger');
47+
};
4048
} else {
4149
$(selector).hide();
4250
}
4351
};
4452
for(const agent of json) {
45-
setBadge(agent.id, agent.messages_count);
53+
setBadge(agent.id, agent.messages_count, agent.working);
4654
}
4755
}
4856

app/assets/stylesheets/diagram.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
color: white !important;
3636
z-index: 2;
3737
}
38+
.badge-danger {
39+
background-color: $danger;
40+
};
41+
.badge-success {
42+
background-color: $success;
43+
};
3844
}
3945
}
4046
}

app/helpers/dot_helper.rb

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -204,30 +204,11 @@ def decorate_svg(xml, agents, workflow)
204204
overlay << Nokogiri::XML::Node.new('a', doc) { |badge|
205205
badge['id'] = id = 'b%d' % agent_id
206206
badge['class'] = 'badge'
207+
badge['style'] = 'display: none'
207208
badge['href'] = agent_path(agent, params: { tab: 'messages', workflow_id: workflow })
208-
badge['title'] = "#{count} messages created"
209-
210-
badge << Nokogiri::XML::Node.new('span', doc) { |lbl|
211-
lbl.content = count.to_s
212-
lbl['class'] = 'count'
213-
}
209+
badge.content = count.to_s
214210

215211
node['data-badge-id'] = id
216-
217-
badge << Nokogiri::XML::Node.new('span', doc) { |label|
218-
# a dummy label only to obtain the background color
219-
label['class'] = [
220-
'badge',
221-
if agent.unavailable?
222-
'badge-warning'
223-
elsif agent.working?
224-
'badge-success'
225-
else
226-
'badge-danger'
227-
end
228-
].join(' ')
229-
label['style'] = 'display: none';
230-
}
231212
}
232213
}
233214
# See also: app/assets/diagram.js

0 commit comments

Comments
 (0)