1
0
mirror of https://github.com/newnius/YAO-portal.git synced 2025-06-06 23:21:55 +00:00
YAO-portal/static/cluster.js

180 lines
4.9 KiB
JavaScript
Raw Normal View History

2019-05-20 08:53:28 +00:00
function register_events_cluster() {
$('#btn-cluster-add').click(function (e) {
$('#form-cluster-submit-type').val('add');
2019-08-01 01:48:20 +00:00
$('#form-cluster-name').removeAttr('disabled');
2019-08-01 02:07:21 +00:00
$('#form-cluster-name').val('');
$('#form-cluster-weight').val(10);
$('#form-cluster-reserved').prop('checked', false);
2019-05-20 08:53:28 +00:00
$('#modal-cluster').modal('show');
});
$("#form-cluster-submit").click(function (e) {
var name = $('#form-cluster-name').val();
2019-07-30 07:49:09 +00:00
var weight = $('#form-cluster-weight').val();
2019-08-01 01:48:20 +00:00
var reserved = $('#form-cluster-reserved').prop('checked');
2019-05-20 08:53:28 +00:00
var quota_gpu = $('#form-cluster-quota-gpu-number').val();
var quota_gpu_mem = $('#form-cluster-quota-gpu-memory').val();
var quota_cpu = $('#form-cluster-quota-cpu').val();
var quota_mem = $('#form-cluster-quota-mem').val();
2019-07-30 07:49:09 +00:00
/* TODO: validate form */
2019-05-20 08:53:28 +00:00
$('#modal-cluster').modal('hide');
2019-08-01 01:48:20 +00:00
var action = 'cluster_add';
2019-05-20 08:53:28 +00:00
if ($('#form-cluster-submit-type').val() !== 'add')
2019-08-01 01:48:20 +00:00
action = 'cluster_update';
2019-05-20 08:53:28 +00:00
var ajax = $.ajax({
2019-08-01 01:48:20 +00:00
url: 'service?action=' + action,
2019-05-20 08:53:28 +00:00
type: 'POST',
data: {
name: name,
2019-07-30 07:49:09 +00:00
weight: weight,
reserved: reserved,
2019-05-20 08:53:28 +00:00
quota_gpu: quota_gpu,
quota_gpu_mem: quota_gpu_mem,
quota_cpu: quota_cpu,
quota_mem: quota_mem
}
});
ajax.done(function (res) {
2019-08-01 01:48:20 +00:00
if (res['errno'] !== 0) {
$('#modal-msg-content').html(res['msg']);
$('#modal-msg').modal('show');
2019-05-20 08:53:28 +00:00
}
2019-08-01 01:48:20 +00:00
$('#table-cluster').bootstrapTable('refresh');
2019-05-20 08:53:28 +00:00
});
ajax.fail(function (jqXHR, textStatus) {
2019-08-01 01:48:20 +00:00
$('#modal-msg-content').html('Request failed : ' + jqXHR.statusText);
$('#modal-msg').modal('show');
$('#table-cluster').bootstrapTable('refresh');
2019-05-20 08:53:28 +00:00
});
});
}
function load_clusters() {
2019-08-01 01:48:20 +00:00
$('#table-cluster').bootstrapTable({
2019-05-20 08:53:28 +00:00
url: 'service?action=cluster_list',
responseHandler: clusterResponseHandler,
sidePagination: 'server',
cache: true,
striped: true,
pagination: true,
pageSize: 10,
pageList: [10, 25, 50, 100, 200],
search: false,
showColumns: true,
showRefresh: true,
showToggle: false,
showPaginationSwitch: true,
minimumCountColumns: 2,
clickToSelect: false,
sortName: 'nobody',
sortOrder: 'desc',
smartDisplay: true,
mobileResponsive: true,
showExport: true,
columns: [{
field: 'name',
title: 'Name',
align: 'center',
valign: 'middle'
2019-08-01 02:07:21 +00:00
}, {
field: 'reserved',
title: 'Reserved',
align: 'center',
valign: 'middle'
}, {
field: 'weight',
title: 'Weight',
align: 'center',
valign: 'middle'
2019-05-20 08:53:28 +00:00
}, {
field: 'operate',
title: 'Operate',
align: 'center',
events: clusterOperateEvents,
formatter: clusterOperateFormatter
}]
});
}
function clusterResponseHandler(res) {
if (res['errno'] === 0) {
var tmp = {};
2019-08-01 01:48:20 +00:00
tmp['total'] = res['count'];
tmp['rows'] = res['clusters'];
2019-05-20 08:53:28 +00:00
return tmp;
}
2019-08-01 01:48:20 +00:00
$('#modal-msg-content').html(res['msg']);
$('#modal-msg').modal('show');
2019-05-20 08:53:28 +00:00
return [];
}
function clusterOperateFormatter(value, row, index) {
var div = '<div class="btn-group" role="group" aria-label="...">';
2019-08-01 01:48:20 +00:00
div += '<button class="btn btn-default edit"><i class="glyphicon glyphicon-edit"></i>&nbsp;</button>';
2019-05-20 08:53:28 +00:00
div += '<button class="btn btn-default remove"><i class="glyphicon glyphicon-remove"></i>&nbsp;</button>';
div += '</div>';
return div;
}
2019-08-01 01:48:20 +00:00
function cluster_gets(cb) {
var ajax = $.ajax({
url: 'service?action=cluster_list',
type: 'GET',
data: {}
});
ajax.done(function (res) {
if (res["errno"] !== 0) {
$("#modal-msg-content").html(res['msg']);
$("#modal-msg").modal('show');
} else {
if (cb !== undefined) {
cb(res['clusters']);
}
}
});
ajax.fail(function (jqXHR, textStatus) {
$("#modal-msg-content").html('Request failed : ' + jqXHR.statusText);
$("#modal-msg").modal('show');
});
}
2019-05-20 08:53:28 +00:00
window.clusterOperateEvents = {
2019-08-01 01:48:20 +00:00
'click .edit': function (e, value, row, index) {
$('#form-cluster-submit-type').val('update');
$('#form-cluster-name').val(row.name);
$('#form-cluster-name').attr('disabled', 'disabled');
$('#form-cluster-weight').val(row.weight);
$('#form-cluster-reserved').prop('checked', row.reserved === true);
2019-08-01 01:54:13 +00:00
$('#form-cluster-quota-gpu-number').val(row.quota_gpu);
$('#form-cluster-quota-gpu-memory').val(row.quota_gpu_mem);
$('#form-cluster-quota-cpu').val(row.quota_cpu);
$('#form-cluster-quota-mem').val(row.quota_mem);
2019-05-20 08:53:28 +00:00
$('#modal-cluster').modal('show');
},
'click .remove': function (e, value, row, index) {
if (!confirm('Are you sure to remove this virtual cluster?')) {
return;
}
var ajax = $.ajax({
2019-08-01 01:48:20 +00:00
url: 'service?action=cluster_remove',
2019-05-20 08:53:28 +00:00
type: 'POST',
data: {name: row.name}
});
ajax.done(function (res) {
2019-08-01 01:48:20 +00:00
if (res['errno'] !== 0) {
$("#modal-msg-content").html(res['msg']);
2019-05-20 08:53:28 +00:00
$("#modal-msg").modal('show');
}
2019-08-01 01:48:20 +00:00
$('#table-cluster').bootstrapTable('refresh');
2019-05-20 08:53:28 +00:00
});
ajax.fail(function (jqXHR, textStatus) {
2019-08-01 01:48:20 +00:00
$("#modal-msg-content").html('Request failed : ' + jqXHR.statusText);
2019-05-20 08:53:28 +00:00
$("#modal-msg").modal('show');
2019-08-01 01:48:20 +00:00
$('#table-cluster').bootstrapTable('refresh');
2019-05-20 08:53:28 +00:00
});
}
};