Revision 1a49199e ui/templates/list.html
b/ui/templates/list.html | ||
---|---|---|
152 | 152 |
}); |
153 | 153 |
|
154 | 154 |
function update_machines_view(data){ |
155 |
/* |
|
156 |
Go through the already displayed servers and remove those not in |
|
157 |
the data or those marked as deleted. |
|
158 |
*/ |
|
159 |
$('.machines tr td input').each(function(i,entry) { |
|
160 |
var deleted = true; |
|
161 |
$.each(data.servers, function(j,server) { |
|
162 |
if (server.id == entry.id && ['BUILD', 'ACTIVE', 'STOPPED', 'ERROR'].indexOf(server.status) >= 0) { |
|
163 |
deleted = false; |
|
164 |
} |
|
165 |
}); |
|
166 |
if (deleted) { |
|
167 |
vmTable.fnDeleteRow(entry); |
|
168 |
} |
|
169 |
}); |
|
170 | 155 |
/* |
171 |
Then go through the servers in the input data. Update existing entries, add
|
|
156 |
Go through the servers in the input data. Update existing entries, add
|
|
172 | 157 |
new ones to the list |
173 |
*/ |
|
174 |
$.each(data.servers, function(i,server){ |
|
175 |
// if the machine is deleted it should not be included in any list |
|
176 |
if (server.status == 'DELETED') { |
|
177 |
return; |
|
178 |
} |
|
179 |
|
|
180 |
existing = $('#' + server.id).parent().parent(); |
|
158 |
*/ |
|
159 |
tableData = vmTable.fnGetData(); |
|
160 |
$.each(data.servers, function(i,server){ |
|
161 |
current = -1; |
|
162 |
|
|
163 |
// check if the server already exists in the datatable |
|
164 |
tableData.forEach(function(row,index){ |
|
165 |
|
|
166 |
if (row[0].split(' ')[2].replace('id=','') == server.id){ |
|
167 |
current = index; |
|
168 |
} |
|
169 |
}); |
|
181 | 170 |
|
182 |
if (existing.length){ // simply update the values |
|
183 |
// If the machine already exists in the DOM then simply update it |
|
184 |
if (existing.find(".status").text() != STATUS_MESSAGES[server.status]) { |
|
185 |
try { |
|
186 |
console.info(existing.find("a.name span.name").text() + ' from ' |
|
187 |
+ existing.find(".status").text() + ' to ' + STATUS_MESSAGES[server.status]); |
|
188 |
} catch(err) {} |
|
189 |
existing.find(".status").text(STATUS_MESSAGES[server.status]); |
|
190 |
} |
|
191 |
existing.find("a.name span.name").text(server.name); |
|
192 |
existing.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' ')); |
|
193 |
} else { // does not exist, we should create it |
|
171 |
if (current != -1){ // if it's there, simply update the values |
|
172 |
try { |
|
173 |
console.info(server.name + ' from ' |
|
174 |
+ tableData[current][5] + ' to ' + STATUS_MESSAGES[server.status]); |
|
175 |
} catch(err) {} |
|
176 |
if (server.deleted == true) { |
|
177 |
vmTable.fnDeleteRow(current); |
|
178 |
} else { |
|
179 |
// update status |
|
180 |
tableData[current][0] = "<input class="+server.status+" id="+server.id+" type=checkbox>"; |
|
181 |
tableData[current][5] = "<span class=status>" + STATUS_MESSAGES[server.status] + "</span>"; |
|
182 |
// TODO: update name & ip |
|
183 |
vmTable.fnUpdate(tableData[current],current); |
|
184 |
} |
|
185 |
updateActions(); |
|
186 |
} else if (server.deleted != true) { // does not exist, we should create it |
|
194 | 187 |
// check server status to select the appropriate OS icon |
195 | 188 |
osTag = image_tags[server.imageRef] |
196 | 189 |
var osIcon = osTag + ".png"; |
... | ... | |
209 | 202 |
]); |
210 | 203 |
} |
211 | 204 |
}); |
205 |
updateActions(); |
|
212 | 206 |
$("#spinner").hide(); |
213 | 207 |
// in case there are no data, leave the page empty |
214 | 208 |
if ($("div.list table.list-machines tbody").length > 0) { |
Also available in: Unified diff