Integrated merged templates and replace of @WORKER-ID@ in template assignment

This commit is contained in:
BenDr0id 2019-03-29 15:16:59 +01:00
parent 959eb3911c
commit ddcf73a735

48
index.html Normal file → Executable file
View file

@ -586,15 +586,25 @@
type: "GET", type: "GET",
url: "/admin/getClientConfig?clientId=template_" + template, url: "/admin/getClientConfig?clientId=template_" + template,
dataType:"json", dataType:"json",
success: function(jsonClientConfig) { success: function(jsonTemplate) {
table.rows({ selected: true }).eq(0).each(function (index) { table.rows({ selected: true }).eq(0).each(function (index) {
var row = table.row(index); var row = table.row(index);
var data = row.data(); var data = row.data();
var clientId = data['client_status']['client_id']; var clientId = data['client_status']['client_id'];
jsonClientConfig['cc-client']['worker-id'] = clientId if ($('#mergeTemplate').prop('checked')) {
setMergedClientConfig(jsonTemplate, clientId);
} else {
jsonTemplate['cc-client']['worker-id'] = clientId
setClientConfig(clientId, JSON.stringify(jsonClientConfig,undefined, 2)); clientConfig = jsonJSON.stringify(jsonTemplate,undefined, 2);
if ($('#replaceWorkerId').prop('checked')) {
clientConfig = clientConfig.replace(new RegExp("@WORKER-ID@", 'g'), clientId).trim();
}
setClientConfig(clientId, clientConfig);
}
}); });
}, },
error: function (data) { error: function (data) {
@ -666,6 +676,28 @@
return data; return data;
} }
function setMergedClientConfig(template, clientId) {
$.ajax({
type: "GET",
url: "/admin/getClientConfig?clientId=" + clientId,
dataType:"json",
success: function(clientConfig) {
$.extend(true, clientConfig, template);
clientConfig = JSON.stringify(clientConfig,undefined, 2)
if ($('#replaceWorkerId').prop('checked')) {
clientConfig = clientConfig.replace(new RegExp("@WORKER-ID@", 'g'), clientId).trim();
}
setClientConfig(clientId, clientConfig);
},
error: function (data) {
setError('<strong>Unable to fetch client config ' + clientId + ' for template merge</strong> - Please make sure it readable!');
}
});
}
function laststatus( data, type, row ) { function laststatus( data, type, row ) {
if (type !== 'sort') { if (type !== 'sort') {
var date = new Date(data*1000 - clockDrift); var date = new Date(data*1000 - clockDrift);
@ -988,6 +1020,16 @@
<div class="form-group"> <div class="form-group">
<label for="assignTemplateSelector">Template:</label> <label for="assignTemplateSelector">Template:</label>
<select class="selectpicker form-control" id="assignTemplateSelector"></select> <select class="selectpicker form-control" id="assignTemplateSelector"></select>
<br/><br/>
<label>
<input id="replaceWorkerId" type="checkbox" data-toggle="toggle" data-size="mini" data-onstyle="success" data-offstyle="danger" data-on="Yes" data-off="No"/>
<span>Replace @MINER_ID@ with Miner-id</span>
</label>
<br/>
<label>
<input id="mergeTemplate" type="checkbox" data-toggle="toggle" data-size="mini" data-onstyle="success" data-offstyle="danger" data-on="Yes" data-off="No"/>
<span>Merge templates</span>
</label>
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">