Compose ' + lan.public.operate + ':
')
$('[name=set_project_status]').change(function(){
that.ajax_task_method($(this).val(),{data:{project_id:dk_cont.id},tips:$('[name=set_project_status]').find('option:selected').text()},function(res){
if(res.status) project_compose_table.$refresh_table_list(true)
bt_tools.msg(res)
})
})
}
}
});
}
})
}
},{
title: lan.public.del,
event:function(row){
bt.confirm({
title: lan.docker.compose.del_compose + ' [' + row.name + ']',
msg: lan.docker.compose.del_compose_tips
}, function () {
that.ajax_task_method('remove', {
data: { project_id: row.id },
tips: lan.docker.compose.deleting_compose
}, function(res){
if (res.status) that.initTabConfig('compose') // 刷新列表
bt_tools.msg(res);
})
});
}
}]
}],
tootls:[{
type: 'group',
positon: ['left', 'top'],
list: [{
title: lan.docker.compose.add_btn,
active: true,
event: function () {
that.add_project();
}
}]
},{ // 批量操作
type: 'batch', //batch_btn
positon: ['left', 'bottom'],
placeholder: lan.public.please_choose,
buttonValue: lan.public.exec,
disabledSelectValue: lan.docker.compose.batch_select_tips,
selectList: [{
title: lan.public.del + " compose",
url: that.global_api,
load: true,
param:function(crow){
return {data:that.batch_param_convert('remove',{project_id:crow.id})}
},
refresh: true,
callback: function (thatc) {
bt.show_confirm(lan.docker.compose.batch_del_compose, "
" + lan.docker.compose.batch_del_tips + "", function () {
thatc.start_batch({}, function (list) {
var html = ''
for (var i = 0; i < list.length; i++) {
var item = list[i];
html += '
| ' + item.name + ' | ' + (item.request.status ? lan.public.setup_success : lan.public.setup_fail) + ' |
';
}
dk_compose_table.$batch_success_table({
title: lan.docker.compose.batch_del_compose,
th: 'compose',
html: html
});
dk_compose_table.$refresh_table_list(true);
});
});
}
}]
}]
})
},
/**
* @description 获取compose模板列表
*/
get_model:function(){
var that = this;
var _config = $.extend({},this.global,{dk_def_name:'template_list'})
var dk_model_table = bt_tools.table({
el:'#dk_model_table',
load: true,
url:this.global_api,
minWidth: '980px',
height:750,
param: {data:JSON.stringify(_config)},
dataFilter: function (res) {
if(!res.msg.installed || !res.msg.service_status) that.stop_user_operation(res.msg.installed,res.msg.service_status)
return { data: res['msg']['template'] };
},
default: lan.docker.public.no_data(lan.docker.public.compose_template),
column:[{
type: 'checkbox',
class: '',
width: 20
},
{
fid: 'name',
width: 266,
title: lan.docker.compose_template.template_name,
template:function(row){
return '
'+row.name+''
}
},
{
width: 266,
title: lan.site.path,
template:function(row){
return '
'+row.path+''
},
event: function (row) {
openEditorView(0,row.path)
}
},
{
fid: 'remark',
title: lan.one_click.description,
type: 'input',
blur: function (row, index, ev, key, thatc) {
if (row.remark == ev.target.value) return false;
that.ajax_task_method('edit_template_remark',{data:{templates_id:row.id,remark:ev.target.value}})
},
keyup: function (row, index, ev) {
if (ev.keyCode === 13) {
$(this).blur();
}
}
},
{
title: lan.public.operate,
type: 'group',
width: 200,
align: 'right',
group: [{
title: lan.public.edit,
event:function(row){
that.ajax_task_method('get_template', {
data: { id: row.id },
tips: lan.docker.compose_template.getting_template
}, function (res) {
if (res.status) {
that.edit_model_view($.extend({content:res['msg']},row))
}
});
}
},{
title: lan.docker.compose_template.pull_mirror_image,
event:function(row){
that.get_log_situation()
that.ajax_task_method('pull',{data:{template_id:row.id},tips:false},function(res){
that.remove_log_clearinterval();
bt_tools.msg(res);
})
}
},{
title: lan.public.del,
event:function(row){
bt.confirm({
title: lan.docker.compose_template.del_template + ' [' + row.name + ']',
msg: lan.docker.compose_template.del_template_tips
}, function () {
that.ajax_task_method('remove_template',{
data: { template_id: row.id },
tips: lan.docker.compose_template.del_template
},function(res){
bt_tools.msg(res);
that.initTabConfig('model') //刷新列表
})
});
}
}]
}],
tootls:[{
type: 'group',
positon: ['left', 'top'],
list: [{
title: lan.public.add,
active: true,
event: function (ev) {
that.add_model_view();
}
}]
},{ // 批量操作
type: 'batch', //batch_btn
positon: ['left', 'bottom'],
placeholder: lan.public.please_choose,
buttonValue: lan.public.exec,
disabledSelectValue: lan.docker.compose_template.batch_select_tips,
selectList: [
{
title: lan.docker.compose_template.del_template,
url: that.global_api,
load: true,
param:function(crow){
return {data:that.batch_param_convert('remove_template',{template_id:crow.id})}
},
refresh: true,
callback: function (thatc) {
bt.show_confirm(lan.docker.compose_template.batch_del_template, "
" + lan.docker.compose_template.batch_del_tips + "", function () {
thatc.start_batch({}, function (list) {
var html = ''
for (var i = 0; i < list.length; i++) {
var item = list[i];
html += '
| ' + item.name + ' | ' + (item.request.status ? lan.public.setup_success : lan.public.setup_fail) + ' |
';
}
dk_model_table.$batch_success_table({
title: lan.docker.compose_template.batch_del_template,
th: lan.docker.compose_template.template_name,
html: html
});
dk_model_table.$refresh_table_list(true);
});
});
}
}
]
}]
})
},
/**
* @description 获取网络列表
*/
get_network:function(){
var that = this;
var _config = $.extend({},this.global,{dk_def_name:'get_host_network'})
var dk_network_table = bt_tools.table({
el:'#dk_network_table',
load: true,
url:this.global_api,
param: {data:JSON.stringify(_config)},
height:750,
dataFilter: function (res) {
if(!res.msg.installed || !res.msg.service_status) that.stop_user_operation(res.msg.installed,res.msg.service_status)
return { data: res['msg']['network'] };
},
default: lan.docker.public.no_data(lan.docker.public.network),
column:[{
type: 'checkbox',
class: '',
width: 20
},
{
width:266,
title: lan.docker.network.name,
template:function(row){
return '
'+row.name+''
}
},
{fid:'driver',title: lan.docker.network.show},
{fid:'subnet',title: lan.docker.network.num},
{fid:'gateway',title: lan.docker.network.gateway},
{
width:226,
title: lan.docker.container.tag,
template:function(row){
var _label = []
if(!$.isEmptyObject(row.labels)){
$.each(row.labels,function(index,item){
_label.push(index+'-'+item)
})
}
return '
'+_label.join() +''
}
},
{
width:150,
title: lan.docker.image.creation_time,
template:function(row){
return '
'+that.utc2beijing(row.time)+''
}
},
{
title: lan.public.operate,
type: 'group',
width: 60,
align: 'right',
group: [{
title: lan.public.del,
event:function(row){
bt.confirm({
title: lan.docker.network.del(row.name),
msg: lan.docker.network.del_tips
}, function () {
that.ajax_task_method('del_network', {
data: { id: row.id },
tips: lan.docker.network.deleting
},function(res){
if(res.status) that.initTabConfig('network') //刷新列表
bt_tools.msg(res);
})
});
}
}]
}],
tootls:[{
type: 'group',
positon: ['left', 'top'],
list: [{
title: lan.docker.network.add,
active: true,
event: function (ev) {
that.add_network();
}
}]
},{ // 批量操作
type: 'batch', //batch_btn
positon: ['left', 'bottom'],
placeholder: lan.public.please_choose,
buttonValue: lan.public.exec,
disabledSelectValue: lan.docker.public.batch_select_tips(lan.docker.public.network),
selectList: [{
title: lan.docker.network.del(),
url: that.global_api,
load: true,
param:function(crow){
return {data:that.batch_param_convert('del_network',{id:crow.id})}
},
refresh: true,
callback: function (thatc) {
bt.show_confirm(lan.docker.public.batch_del(lan.docker.public.network), "
" + lan.docker.public.batch_del_tips(lan.docker.public.network) + "", function () {
thatc.start_batch({}, function (list) {
var html = ''
for (var i = 0; i < list.length; i++) {
var item = list[i];
html += '
| ' + item.name + ' | ' + (item.request.status ? lan.public.setup_success : lan.public.setup_fail) + ' |
';
}
dk_network_table.$batch_success_table({
title: lan.docker.public.batch_del(lan.docker.public.network),
th: lan.docker.network.name,
html: html
});
dk_network_table.$refresh_table_list(true);
});
});
}
}]
}]
})
},
/**
* @description 获取存储卷列表
*/
get_volume:function(){
var that = this;
var _config = $.extend({},this.global,{dk_def_name:'get_volume_list'})
var dk_volume_table = bt_tools.table({
el:'#dk_volume_table',
load: true,
url:this.global_api,
minWidth: '1020px',
height:750,
param: {data:JSON.stringify(_config)},
dataFilter: function (res) {
if(!res.msg.installed || !res.msg.service_status) that.stop_user_operation(res.msg.installed,res.msg.service_status)
return { data: res['msg']['volume'] };
},
default: lan.docker.public.no_data(lan.docker.public.volume),
column:[{
type: 'checkbox',
class: '',
width: 20
},
{fid:'Name',width:216,title: lan.docker.public.volume,template:function(row){
return '
'+row.Name+''
}},
{
type: 'link',
title: lan.docker.volume.mount,
template:function(row){
return '
'+row.Mountpoint+''
},
event: function (row) {
openPath(row.Mountpoint);
}
},
{
fid:'container',
title: lan.docker.public.container
},
{fid: 'Driver',title: lan.docker.volume.driver},
{
fid:'CreatedAt',
width:150,
title: lan.docker.public.creation_time,
template:function(row){
return '
'+that.utc2beijing(row.CreatedAt)+''
}
},
{
width:206,
title: lan.docker.public.tag,
template:function(row){
var _label = []
if(!$.isEmptyObject(row.Labels)){
$.each(row.Labels,function(index,item){
_label.push(index+'-'+item)
})
}
return '
'+_label.join() +''
}
},
{
title: lan.public.operate,
type: 'group',
width: 60,
align: 'right',
group: [{
title: lan.public.del,
event:function(row){
bt.confirm({
title: lan.docker.volume.del(row.Name),
msg: lan.docker.public.del_tips(lan.docker.public.volume)
}, function () {
that.ajax_task_method('remove',{data:{name:row.Name},tips:lan.docker.volume.deleting},function(res){
if(res.status)that.initTabConfig('volume') //刷新列表
bt_tools.msg(res);
})
});
}
}]
}],
tootls:[{
type: 'group',
positon: ['left', 'top'],
list: [{
title: lan.docker.volume.add,
active: true,
event: function (ev) {
that.add_volume();
}
}]
},{ // 批量操作
type: 'batch', //batch_btn
positon: ['left', 'bottom'],
placeholder: lan.public.please_choose,
buttonValue: lan.public.exec,
disabledSelectValue: lan.docker.public.batch_select_tips(lan.docker.public.volume),
selectList: [{
title: lan.docker.volume.del(),
url: that.global_api,
load: true,
param:function(crow){
return {data:that.batch_param_convert('remove',{name:crow.Name})}
},
refresh: true,
callback: function (thatc) {
bt.show_confirm(lan.docker.public.batch_del(lan.docker.public.volume), "
" + lan.docker.public.batch_del_tips(lan.docker.public.volume) + "", function () {
thatc.start_batch({}, function (list) {
var html = ''
for (var i = 0; i < list.length; i++) {
var item = list[i];
html += '
| ' + item.name + ' | ' + (item.request.status ? lan.public.setup_success : lan.public.setup_fail) + ' |
';
}
dk_volume_table.$batch_success_table({
title: lan.docker.public.batch_del(lan.docker.public.volume),
th: lan.docker.volume.name,
html: html
});
dk_volume_table.$refresh_table_list(true);
});
});
}
}]
}]
})
},
/**
* @description 获取仓库列表
*/
get_registry:function(){
var that = this;
var _config = $.extend({},this.global,{dk_def_name:'registry_list'})
var dk_registry_table = bt_tools.table({
el:'#dk_registry_table',
load: true,
url:this.global_api,
height:750,
param: {data:JSON.stringify(_config)},
dataFilter: function (res) {
if(!res.msg.installed || !res.msg.service_status) that.stop_user_operation(res.msg.installed,res.msg.service_status)
return { data: res['msg']['registry'] };
},
default: lan.docker.public.no_data(lan.docker.public.repository),
column:[{
type: 'checkbox',
class: '',
width: 20
},
{width:266,title: 'URL',template:function(row){
return '
'+row.url+''
}},
{fid: 'username',title: lan.docker.repository.username },
{fid: 'name',title: lan.docker.repository.name },
{
fid: 'remark',
title: lan.one_click.description,
type: 'input',
blur: function (row, index, ev, key, thatc) {
if (row.remark == ev.target.value) return false;
row['remark'] = ev.target.value
row['registry'] = row.url
that.ajax_task_method('edit',{data:row})
},
keyup: function (row, index, ev) {
if (ev.keyCode === 13) {
$(this).blur();
}
}
},
{
title: lan.public.operate,
type: 'group',
width: 100,
align: 'right',
group: [{
title: lan.public.edit,
event:function(row){
that.render_registry_view(row);
}
},{
title: lan.public.del,
event:function(row){
bt.confirm({
title: lan.docker.repository.del(row.name),
msg: lan.docker.public.del_tips(lan.docker.public.repository)
}, function () {
that.ajax_task_method('remove',{data:{id:row.id},tips: lan.docker.repository.deleting},function(res){
bt_tools.msg(res);
that.initTabConfig('registry') //刷新列表
})
});
}
}]
}],
tootls:[{
type: 'group',
positon: ['left', 'top'],
list: [{
title: lan.docker.repository.add,
active: true,
event: function (ev) {
that.render_registry_view();
}
}]
},{ // 批量操作
type: 'batch', //batch_btn
positon: ['left', 'bottom'],
placeholder: lan.public.please_choose,
buttonValue: lan.public.exec,
disabledSelectValue: lan.docker.public.batch_select_tips(lan.docker.public.repository),
selectList: [{
title: lan.docker.repository.del(),
url: that.global_api,
load: true,
param:function(crow){
return {data:that.batch_param_convert('remove',{id:crow.id})}
},
refresh: true,
callback: function (thatc) {
bt.show_confirm(lan.docker.public.batch_del(lan.docker.public.repository), "
" + lan.docker.public.batch_del_tips(lan.docker.public.repository) + "", function () {
thatc.start_batch({}, function (list) {
var html = ''
for (var i = 0; i < list.length; i++) {
var item = list[i];
html += '
| ' + item.name + ' | ' + (item.request.status ? lan.public.setup_success : lan.public.setup_fail) + ' |
';
}
dk_registry_table.$batch_success_table({
title: lan.docker.public.batch_del(lan.docker.public.repository),
th: lan.docker.repository.name,
html: html
});
dk_registry_table.$refresh_table_list(true);
});
});
}
}]
}]
})
},
/**
* @description 获取镜像列表
*/
get_image:function(){
var that = this;
var _config = $.extend({},this.global,{dk_def_name:'image_list'})
var dk_image_table = bt_tools.table({
el:'#dk_image_table',
load: true,
url:this.global_api,
minWidth: '1020px',
height:750,
param: {data:JSON.stringify(_config)},
dataFilter: function (res) {
if(!res.msg.installed || !res.msg.service_status) that.stop_user_operation(res.msg.installed,res.msg.service_status)
that.dk_registry = res['msg']['registry_list']
return { data: res['msg']['images_list'] };
},
default: lan.docker.public.no_data(lan.docker.public.mirror_image),
column:[{
type: 'checkbox',
class: '',
width: 20
},
{
width:200,
title: 'ID',
template:function(row){
return '
'+row.id+''
}
},
{
fid: 'name',
title: lan.docker.image.name
},
{
width:86,
title: lan.database.size,
template: function (row) {
return '
'+bt.format_size(row.size)+''
}
},
{
width:150,
title: lan.docker.image.creation_time,
template:function(row){
return '
'+that.utc2beijing(row.time)+''
}
},
{
title: lan.public.operate,
type: 'group',
width: 140,
align: 'right',
group: [{
title: lan.docker.image.push,
event:function(row){
var _registry = []
if(that.dk_registry.length > 0){
$.each(that.dk_registry,function(index,item){
_registry.push({title:item.name+'['+item.url+'/'+item.namespace+']',value:item.name})
})
}else{
_registry = [{title: lan.docker.image.push_tips1,value:'dk_registry_false'}]
}
bt_tools.open({
type: 1,
title: lan.docker.image.push_title1 + ' [' + row.name + '] ' + lan.docker.image.push_title2,
area: '580px',
btn: [lan.public.submit, lan.site.no],
content: {
'class': "pd20",
form: [{
label: lan.docker.image.warehouse_name,
group: {
name:'name',
type:'select',
width: "400px",
list:_registry
}
},{
label: lan.docker.container.tag,
group: {
name: "tag",
type: "text",
value: '',
width: "400px",
placeholder: lan.docker.image.tag_input
}
}]
},
yes: function (formD,indexs) {
if (formD.name === 'dk_registry_false') return bt_tools.msg(lan.docker.image.push_tips2, 2)
if (formD.tag === '') return bt_tools.msg(lan.docker.image.push_tips3, 2)
formD['id'] = row.id
that.get_log_situation()
that.ajax_task_method('push',{data:formD,tips:false},function(res){
that.remove_log_clearinterval();
if(res.status){
layer.closeAll();
that.initTabConfig('image') //刷新列表
}
bt_tools.msg(res)
})
}
})
}
},{
title: lan.docker.image.export,
event:function(row){
bt_tools.open({
type: 1,
title: lan.docker.image.export_title(row.name),
area: '480px',
btn: [lan.docker.image.export, lan.site.no],
content: {
'class': "pd20",
form: [{
label: lan.site.path,
group: {
name: "path",
type: "text",
value: '',
width: "240px",
placeholder: lan.docker.image.path_input,
icon: {
type: 'glyphicon-folder-open',
event:function(){}
}
}
},{
label: lan.files.file_name,
group: {
name: "name",
type: "text",
value: '',
width: "240px",
placeholder: lan.docker.image.file_input,
unit:'.tar'
}
}]
},
yes: function (formD,indexs) {
if (formD.path === '') return bt_tools.msg(lan.docker.image.export_tips1, 2)
if (formD.name === '') return bt_tools.msg(lan.docker.image.export_tips, 2)
formD['id'] = row.id
that.ajax_task_method('save', {
data: formD,
tips: lan.docker.image.exporting
}, function(res){
if(res.status){
layer.close(indexs);
that.initTabConfig('image') //刷新列表
}
bt_tools.msg(res)
})
}
})
}
},{
title: lan.public.del,
event:function(row){
bt.confirm({
title: lan.docker.image.del(row.name),
msg: lan.docker.image.del_tips
}, function () {
that.ajax_task_method('remove', {
data: {
id: row.id, force: 0, name: row.name
},
tips: lan.docker.image.deleting
}, function (res) {
if (res.status) that.initTabConfig('image') //刷新列表
bt_tools.msg(res);
})
});
}
}]
}],
tootls:[{
type: 'group',
positon: ['left', 'top'],
list: [{
title: lan.docker.image.btn1,
active: true,
event:function(ev){
var _registry = []
if(that.dk_registry.length > 0){
$.each(that.dk_registry,function(index,item){
_registry.push({title:item.name+'['+item.url+'/'+item.namespace+']',value:item.name})
})
}else{
_registry = [{title:lan.docker.image.warehouse_select,value:'dk_registry_false'}]
}
bt_tools.open({
type: 1,
title: lan.docker.image.pull_title,
area: '580px',
btn: [lan.public.submit, lan.site.no],
content: {
'class': "pd20",
form: [{
label: lan.docker.image.warehouse_name,
group: {
name:'name',
type:'select',
width: "400px",
list:_registry
}
},{
label: lan.docker.image.mirror_name,
group: {
name: "image",
type: "text",
value: '',
width: "400px",
placeholder: lan.docker.image.mirror_input
}
}]
},
yes: function (formD, indexs) {
if (formD.name === 'dk_registry_false') return bt_tools.msg(lan.docker.image.pull_tips1, 2)
if (formD.image === '') return bt_tools.msg(lan.docker.image.pull_tips2, 2)
that.get_log_situation()
that.ajax_task_method('pull_from_some_registry',{data:formD,tips:false},function(res){
that.remove_log_clearinterval()
if(res.status){
layer.close(indexs);
that.initTabConfig('image') //刷新列表
}
bt_tools.msg(res)
})
}
})
}
},{
title: lan.docker.image.btn2,
event:function(ev){
bt_tools.open({
type: 1,
title: lan.docker.image.btn2,
area: '460px',
btn: [lan.docker.image.import, lan.site.no],
content: {
'class': "pd20",
form: [{
label: lan.site.path,
group: {
name: "path",
type: "text",
value: '',
width: "240px",
placeholder: lan.docker.image.path_input,
icon: {
type: 'glyphicon-folder-open',
select:'file',
event:function(){}
}
}
}]
},
yes: function (formD, indexs) {
if (formD.path === '') return bt_tools.msg(lan.docker.image.export_tips1, 2);
that.ajax_task_method('load',{data:formD,tips: lan.docker.image.importing},function(res){
if(res.status){
layer.close(indexs);
that.initTabConfig('image') //刷新列表
}
bt_tools.msg(res)
})
}
})
}
},{
title: lan.docker.image.btn3,
event: function () {
that.construction_image();
}
}]
},{ // 批量操作
type: 'batch', //batch_btn
positon: ['left', 'bottom'],
placeholder: lan.public.please_choose,
buttonValue: lan.public.exec,
disabledSelectValue: lan.docker.image.batch_tips,
selectList: [{
title: lan.docker.image.del(),
url: that.global_api,
load: true,
param:function(crow){
return {data:that.batch_param_convert('remove',{id:crow.id,force:0,name:crow.name})}
},
refresh: true,
callback: function (thatc) {
bt.show_confirm(lan.docker.image.batch_del, "
" + lan.docker.image.batch_del_tips + "", function () {
thatc.start_batch({}, function (list) {
var html = ''
for (var i = 0; i < list.length; i++) {
var item = list[i];
html += '
| ' + item.name + ' | ' + (item.request.status ? lan.public.setup_success : lan.public.setup_fail) + ' |
';
}
dk_image_table.$batch_success_table({
title: lan.docker.image.batch_del,
th: lan.docker.image.name,
html: html
});
dk_image_table.$refresh_table_list(true);
});
});
}
}]
}]
})
},
/**
* @description 获取设置页面
*/
get_setup:function(){
var _html = '',that = this;
this.ajax_task_method('get_config',{},function(res){
var info = res.msg;
var status_info = info.service_status ? ['Enable', '#20a53a', 'play'] : ['Stopped', 'red', 'pause'];
_html = '
'
$('#dk_setup_form').html(_html)
$('#monitor_status').prop('checked',info.monitor_status) //监控状态
//服务按钮
$('.serveSetup').click(function(){
var _set = $(this).data('setup');
that.ajax_task_method('docker_service',{data:{act:_set},tips:'Set the docker service status'},function(ress){
if(ress.status) that.initTabConfig('setup')
bt_tools.msg(ress)
})
})
//容器监控开关
$("#monitor_status").change(function(){
var _status = $(this).prop('checked');
that.ajax_task_method('set_docker_monitor',{data:{act:_status?'start':'stop'},tips:'Set container monitoring configuration'},function(res){
if(res.status) that.initTabConfig('setup')
bt_tools.msg(res)
})
})
//容器监控天数
$('.monitorSubmit').click(function(){
var save_num = $('[name=monitor_save_day]').val();
if(save_num <= 0)return layer.msg('The number of monitoring and preservation cannot be less than 0',{icon:2})
that.ajax_task_method('set_monitor_save_date',{data:{save_date:save_num},tips:'Set container monitoring configuration'},function(res){
if(res.status) that.initTabConfig('setup')
bt_tools.msg(res)
})
})
//设置加速url
$('.editSpeed').click(function(){
bt_tools.open({
title:'Set the acceleration URL',
type:1,
shadeClose: false,
closeBtn: 2,
area:'520px',
content:{
'class':'pd20',
form:[{
label:'Accelerate URL',
group:{
type:'text',
name:'registry_mirrors_address',
value:info.registry_mirrors,
width:'360px',
placeholder:'Please enter the acceleration URL'
}
},{
label:'',
group:{
type:'help',
style:{'margin-top':'0'},
list:[
'Priority use the acceleration URL to perform operations, and the request timeout will skip the use of the default acceleration method',
'After setting acceleration, you need to restart the docker manually',
'Turn off acceleration, please set it to empty'
]
}
}]
},yes:function(formD,index){
that.ajax_task_method('set_registry_mirrors',{data:formD,tips:false},function(uRes){
if(uRes.status){
layer.close(index)
that.initTabConfig('setup')
}
bt_tools.msg(uRes)
})
}
})
})
})
},
/**
* @description 添加容器
*/
add_container:function(){
var that = this, _imageList = '', _volumesList = '', add_pro = null;
if (this.dk_images.length > 0) {
$.each(this.dk_images, function (index, item) {
_imageList += '
'
})
}
if (this.dk_volumes.length > 0) {
$.each(this.dk_volumes, function (index, item) {
_volumesList +='
' + item.Name + ''
})
}
layer.open({
type: 1,
closeBtn: 2,
title: lan.docker.container.add_container,
area: ['720px','630px'],
skin: 'add_container',
btn: [lan.public.submit, lan.site.no],
shadeClose: false,
content: '\
\
\
' + lan.docker.container.create_container + '\
' + lan.docker.container.container_arr + '\
\
\
',
success:function(){
$(".add_container").on('click', '.tab-nav span', function () {
var index = $(this).index();
$(this).addClass('on').siblings().removeClass('on');
$('.tabs_content .tabpanel').eq(index).removeAttr('style').siblings().attr('style','display:none')
});
// <----------容器----------->
//服务器目录事件
$('[name=dk_server_path]').click(function(e){
var _ul = $(this).siblings('ul')
if (_ul.hasClass('show')) {
_ul.removeClass('show')
} else {
_ul.addClass('show')
}
$(document).one('click',function(){
_ul.removeClass('show');
})
e.stopPropagation();
})
// 服务器目录ul
$('.dk_volumes li').click(function(){
$('[name=dk_server_path]').val($(this).data('key'))
})
// 端口类型触发
$('[name=dk_port]').change(function(){
$(this).val() == 1 ? $('.dk_port_setting').hide() : $('.dk_port_setting').show();
})
//添加端口、目录tbody
$('.plus').click(function(){
var _Arrinput = $(this).siblings('input'),
_val_one = $(_Arrinput[0]).val(),
_val_two = $(_Arrinput[1]).val(),
THbody = $(this).siblings('.divtable').find('tbody'),
_td = '';
if (_val_one == '') return layer.msg(lan.docker.public.please_enter + $(_Arrinput[0]).attr('placeholder'),{icon:2})
if (_val_two == '') return layer.msg(lan.docker.public.please_enter + $(_Arrinput[1]).attr('placeholder'),{icon:2})
switch($(this).data('type')){
case 'port':
_td = '\
\
| ' + _val_one + ' | \
' + _val_two + ' | \
' + lan.public.del + ' | \
'
break;
case 'path':
var pess_type = $('[name=volumes_type]').val();
_td = '\
\
| \
\
' + _val_one + '\
\
| \
' + pess_type + ' | \
\
\
'+_val_two+'\
\
| \
' + lan.public.del + ' | \
'
break;
}
if (THbody.find('td').length === 1) {
$(THbody).html(_td)
} else {
$(THbody).append(_td)
}
//清空输入框内容
$(_Arrinput[0]).val('')
$(_Arrinput[1]).val('')
})
// 端口、目录删除
$('.add_container').on('click','.del-change-td',function(){
var tbody = $(this).parents('tbody')
$(this).parents('tr').remove()
if (tbody.find('tr').length == 0) {
tbody.append('
| ' + lan.site.data_empty + ' |
');
}
})
// 停止后自动删除容器事件
$('.add_container .shop_container_del').click(function(){
if ($(this).find('i').hasClass('active')) {
$(this).find('i').removeClass('active').siblings('input').prop('checked',false)
} else {
$(this).find('i').addClass('active').siblings('input').prop('checked',true)
}
});
// <-----------------容器编排------------------->
var modelList = []
render_model_list()
add_pro = bt_tools.form({
el:'#add_project_form',
form: [
{
label: lan.docker.public.compose_template,
group:[
{
type: 'select',
name: 'template_id',
width: '440px',
list: modelList
},
{
type: 'link',
title: lan.public_backup.create,
event: function () {
that.add_model_view(function(resolve){
if(resolve){
that.ajax_task_method('template_list', {
tips: lan.docker.compose_template.getting_template,
model_name: { dk_model_name: 'compose' }
}, function (model_list) {
that.dk_template = model_list['msg']['template']
render_model_list()
add_pro['config']['form'][0]['group'][0]['list'] = modelList; // 模板列表
add_pro.$local_refresh("template_id", add_pro['config']['form'][0]['group'][0]) // 刷新局部数据
})
}
})
}
}
]
},
{
label: lan.public.name,
group: {
type: 'text',
name: 'project_name',
width: '440px',
placeholder: lan.docker.compose.name_input_tips
}
},
{
label: lan.one_click.description,
group: {
type: 'textarea',
name: 'remark',
style: {
'width': '440px',
'min-width': '380px',
'min-height': '130px',
'line-height': '22px',
'padding-top': '5px',
'resize': 'both'
},
placeholder: lan.docker.compose.description_input_tips
}
}
]
})
function render_model_list () {
if (that.dk_template.length > 0) {
$.each(that.dk_template,function(index,item){
modelList.push({title:item.name,value:item.id})
})
} else {
modelList = [
{ value:'dk_project_false', title: lan.docker.compose.compose_template_select_tips }
]
}
}
},
yes: function (indexs) {
// 创建容器
if ($('.add_container .tab-nav span.on').index() == 0) {
var _name = $('[name=dk_container_name]').val(),
_image = $('[name=dk_image]').val(),
_port = $('[name=dk_port]').val(),
_start_cmd = $('[name=dk_start_cmd]').val(),
auto_remove = $('.form-checkbox').siblings('input').prop('checked')?1:0,
_cpus = $('[name=dk_cpu_num]').val(),
_size = $('[name=dk_cpu_size]').val(),
_unit = $('[name=dk_cpu_unit]').val(),
_tag = $('[name=dk_tag]').val(),
_config = $('[name=dk_config]').val(),
_reset = $('[name=dk_reset]').val();
// 验证
if (_name == '') return layer.msg(lan.docker.container.add_container_tips1, { icon: 2 });
if (_image == '') return layer.msg(lan.docker.container.add_container_tips2, { icon: 2 });
if (_cpus != '' && _cpus <= 0)return layer.msg(lan.docker.container.add_container_tips3, { icon: 2 })
if (_size != '' && _size <= 0)return layer.msg(lan.docker.container.add_container_tips4, { icon: 2 })
var _form = {
name: _name,
image:_image,
publish_all_ports:_port,
command:_start_cmd,
auto_remove:auto_remove,
environment:_config,
cpuset_cpus:_cpus,
mem_limit:_size+_unit,
labels:_tag,
restart_policy:{Name:_reset,MaximumRetryCount:5}
}
var port_array = {},path_array = {}
// 端口
if ($('.dk_port_table tbody tr').length > 0) {
$.each($('.dk_port_table tbody tr'), function(index, item) {
if ($(item).find('td').length == 3) {
port_array[$(item).find('td').eq(0).text()+'/tcp'] = $(item).find('td').eq(1).text();
}
});
_form['ports'] = port_array;
}
// 路径
if ($('.dk_path_table tbody tr').length > 0) {
$.each($('.dk_path_table tbody tr'),function(index,item){
if ($(item).find('td').length == 4) {
path_array[$(item).find('td').eq(0).find('.size_ellipsis').text()] = {
bind: $(item).find('td').eq(2).find('.size_ellipsis').text(),
mode: $(item).find('td').eq(1).text()
}
}
})
_form['volumes'] = path_array
}
//接口参数
that.ajax_task_method('run', {
data: $.extend(_form,that.global),
tips: lan.docker.container.add_container_api_tips
}, function (res) {
if (res.status) {
layer.close(indexs);
that.initTabConfig('container'); // 刷新列表
}
bt_tools.msg(res);
})
} else {
var formValue = add_pro.$get_form_value()
if (formValue.template_id === 'dk_project_false') return bt_tools.msg(lan.docker.compose.add_compose_tips1, 2)
if (formValue.project_name == '') return layer.msg(lan.docker.compose.add_compose_tips2, { icon: 2 })
that.get_log_situation();
that.ajax_task_method('create', {
data: formValue,
tips: false,
model_name: { dk_model_name: 'compose' }
}, function (res) {
that.remove_log_clearinterval();
if (res.status) {
layer.closeAll();
$('#cutMode .tabs-item').eq(2).click() // 跳转到容器编排
}
bt_tools.msg(res)
});
}
}
})
},
/**
* @description 添加Compose
*/
add_project:function(){
var that = this,add_pro = null
bt_tools.open({
title: lan.docker.compose.add_btn,
btn: [lan.public.submit, lan.site.no],
area: ['560px', '380px'],
content: '
',
success: function () {
var modelList = []
render_model_list()
add_pro = bt_tools.form({
el:'#add_project_form',
form: [{
label: lan.docker.public.compose_template,
group:[
{
type: 'select',
name:'template_id',
width:'300px',
list:modelList
},
{
type:'link',
title: lan.public_backup.create,
event:function(){
that.add_model_view(function(resolve){
if (resolve) {
that.ajax_task_method('template_list', {
tips: lan.docker.compose_template.getting_template,
model_name: {
dk_model_name: 'compose'
}
}, function (model_list) {
that.dk_template = model_list['msg']['template']
render_model_list()
add_pro['config']['form'][0]['group'][0]['list'] = modelList; // 模板列表
add_pro.$local_refresh("template_id", add_pro['config']['form'][0]['group'][0]) // 刷新局部数据
})
}
})
}
}
]
},{
label: lan.public.name,
group: {
type: 'text',
name: 'project_name',
width: '300px',
placeholder: lan.docker.compose.name_input_tips
}
},{
label: lan.one_click.description,
group: {
type: 'textarea',
name: 'remark',
style: {
'width': '300px',
'min-width': '300px',
'min-height': '130px',
'line-height': '22px',
'padding-top': '5px',
'resize': 'both'
},
placeholder: lan.docker.compose.description_input_tips
}
}]
})
function render_model_list () {
if (that.dk_template.length > 0) {
$.each(that.dk_template, function(index, item) {
modelList.push({ title: item.name, value: item.id });
});
}else{
modelList = [
{ value:'dk_project_false', title: lan.docker.compose.compose_template_select_tips }
]
}
}
},
yes:function(indexs){
var formValue = add_pro.$get_form_value()
if (formValue.template_id === 'dk_project_false') return bt_tools.msg(lan.docker.compose.add_compose_tips1, 2)
if(formValue.project_name == '')return layer.msg(lan.docker.compose.add_compose_tips2,{icon:2})
that.get_log_situation()
that.ajax_task_method('create',{data:formValue,tips:false},function(res){
that.remove_log_clearinterval();
if(res.status){
layer.closeAll();
that.initTabConfig('compose') //刷新列表
}
bt_tools.msg(res)
})
}
})
},
/**
* @description 添加Compose模板
*/
add_model_view:function(callback){
var that = this,loca_compose = null,search_list = []
var model_tabl = bt_tools.tab({
class:'pd20',
type:0,
active:1,
theme: { nav: 'yaml' },
list:[{
title: lan.docker.compose_template.add_title,
name:"addCompose",
content: '
',
success:function(){
_aceEditor = bt.aceEditor({ el: 'dkContntBody', content: '' });
}
},{
title: lan.docker.compose_template.search_local_template,
name:'searchCompose',
content:'\
',
success:function(){
var one = 0;
loca_compose = bt_tools.table({
el:'#model_sc_table',
data:search_list,
height: '330px',
column:[{
type: 'checkbox',
class: '',
width: 20
},{
width:180,
title: lan.docker.compose_template.compose_template_name,
template:function(row){
return '
'+row.project_name+''
}
},{
width:180,
title: lan.docker.container.path,
template:function(row){
return '
'+row.conf_file+''
}
},{
fid: 'remark',
title: lan.one_click.description,
type: 'input',
blur: function (row, index, ev, key, thatc) {
row.remark = ev.target.value
},
keyup: function (row, index, ev) {
if (ev.keyCode === 13) {
$(this).blur();
}
}
}],
success:function(){
if(one == 0){
one++
$('#model_sc_table').on('click', '.cust—checkbox', function (e) {
var len = loca_compose.checkbox_list
$('.lc_select').html(len.length+'个')
})
$('.loca_compose_box').append('\
\
- ' + lan.docker.compose_template.add_search_tips1 + ' [' + lan.docker.compose_template.selected + ': 0]
\
');
}
}
})
//停止后自动删除容器事件
$('.model_sc_child').click(function(){
if($(this).find('i').hasClass('active')){
$(this).find('i').removeClass('active').siblings('input').prop('checked',false)
}else{
$(this).find('i').addClass('active').siblings('input').prop('checked',true)
}
})
// 模板搜索按钮
$('.model_search_btn').click(function(){
var _val = $('#model_sc_path').val(),
_child = $('.form-checkbox').siblings('input').prop('checked')?1:0
if(_val == '') return bt_tools.msg(lan.docker.compose_template.search_folder_tips1, 2)
that.ajax_task_method('get_compose_project',{
data: { path: _val, sub_dir: _child },
tips: lan.docker.compose.getting_compose,
model_name:{ dk_model_name: 'compose' }
}, function (mlist) {
if(mlist.status == false)return bt_tools.msg(mlist.msg,2)
if(mlist.length == 0)return bt_tools.msg(lan.docker.compose_template.search_folder_tips2, 0)
loca_compose.$reader_content(mlist)
})
})
}
}]
})
bt_tools.open({
title: lan.docker.compose_template.add_yaml_template,
btn: [lan.public.submit, lan.site.no],
skin:'model_sc_view',
area: ['680px', '640px'],
content:model_tabl.$reader_content(),
success:function(){
model_tabl.$init();
},
yes:function(layers){
if (model_tabl.active == 0) {
var _mName = $('[name=model_name]').val(),
_mDesc = $('[name=model_desc]').val(),
_Con = _aceEditor.ACE.getValue();
if (_mName == '') return layer.msg(lan.docker.compose_template.add_template_tips1,{icon:2})
if (_Con == '') return layer.msg(lan.docker.compose_template.add_template_tips2,{icon:2})
var _param = {name:_mName,remark:_mDesc,data:_Con}
that.ajax_task_method('add_template', {
data: _param,
tips: lan.docker.compose_template.adding_template,
model_name: { dk_model_name: 'compose' }
}, function (res) {
if (res.status) {
layer.close(layers)
if (callback) {
callback(res.status)
} else {
that.initTabConfig('model') //刷新列表
}
}
var entry = { "'": "'", '"': '"', '<': '<', '>': '>' };
res.msg = res.msg.replace(/(['")-><&\\\/\.])/g, function ($0) { return entry[$0] || $0; });
bt_tools.msg(res)
})
} else {
var check_len = loca_compose.checkbox_list.length,
array = []
$.each(loca_compose.data,function(index,item){
if ($.inArray(index,loca_compose.checkbox_list) != -1) {
array.push(item);
}
})
if(check_len == 0) return layer.msg(lan.docker.compose_template.add_path_tips1,{icon:2})
layer.confirm(lan.docker.compose_template.add_path_tips2 + check_len + lan.docker.compose_template.add_path_tips3, {
title: lan.docker.compose_template.add_template,
icon: 3,
closeBtn: 2
}, function () {
that.ajax_task_method('add_template_in_path',{
data: { template_list: array },
tips: lan.docker.compose_template.adding_template,
model_name: { dk_model_name: 'compose' }
}, function (res) {
if(res.status){
layer.close(layers)
if (callback) {
callback(res.status)
}else{
that.initTabConfig('model') // 刷新列表
}
}
bt_tools.msg(res)
})
});
}
}
})
},
/**
* @description 模板添加、编辑界面
* @param {Object} edit 编辑数据
* @param callback 成功后回调
*/
edit_model_view:function(edit){
var that = this,_aceEditor = null;
layer.open({
type: 1,
title: 'Edit template',
btn: [lan.public.save, lan.site.no],
area:'650px',
shadeClose: false,
closeBtn: 2,
content: '
',
success:function(){
_aceEditor = bt.aceEditor({ el: 'dkContntBody', content: edit.content });
},
yes:function(layers){
var _mName = $('[name=model_name]').val(),
_mDesc = $('[name=model_desc]').val(),
_Con = _aceEditor.ACE.getValue();
if(_mName == '') return layer.msg(lan.docker.compose_template.add_template_tips1,{icon:2})
if(_mDesc == '') return layer.msg(lan.docker.compose.description_input_tips,{icon:2})
if(_Con == '') return layer.msg(lan.docker.compose_template.add_template_tips2,{icon:2})
var _param = {name:_mName,remark:_mDesc,data:_Con}
if(edit) _param['id'] = edit.id
that.ajax_task_method('edit_template',{data:_param,tips: lan.docker.compose_template.saving,model_name:{dk_model_name:'compose'}},function(res){
if(res.status){
layer.close(layers)
that.initTabConfig('model') //刷新列表
}
bt_tools.msg(res)
})
}
})
},
/**
* @description 添加网络
*/
add_network:function(){
var that = this,add_network = null
bt_tools.open({
title: lan.docker.network.add,
btn: [lan.public.submit, lan.site.no],
area: ['540px','510px'],
content: '
',
success: function (layers) {
add_network = bt_tools.form({
el:'#add_network_form',
form: [{
label: lan.docker.network.name,
group: {
type: 'text',
name: 'name',
width: '384px',
placeholder: lan.docker.network.name_input
}
},{
label: lan.docker.network.device,
group:{
type: 'select',
name:'driver',
width:'160px',
list:[
{title:'bridge',value:'bridge'},
{title:'ipvlan',value:'ipvlan'},
{title:'macvlan',value:'macvlan'},
{title:'overlay',value:'overlay'}
]
}
},{
label: lan.docker.network.parameter,
group: {
type: 'textarea',
name: 'options',
style: {
'width': '384px',
'min-width': '384px',
'min-height': '70px',
'line-height': '22px',
'padding-top': '5px',
'resize': 'both'
},
placeholder: lan.docker.network.parameter_textarea
}
},{
label: lan.docker.network.sub_network,
group:[{
type: 'text',
name: 'subnet',
width: '160px',
placeholder: lan.docker.network.sub_network_input
},{
label: lan.docker.network.gateway,
type: 'text',
name: 'gateway',
width: '160px',
placeholder: lan.docker.network.gateway_input
}]
},{
label: lan.docker.network.ip_range,
group: {
type: 'text',
name: 'iprange',
width: '384px',
placeholder: lan.docker.network.ip_range_input
}
},{
label: lan.docker.container.tag,
group: {
type: 'textarea',
name: 'labels',
style: {
'width': '384px',
'min-width': '384px',
'min-height': '70px',
'line-height': '22px',
'padding-top': '5px',
'resize': 'both'
},
placeholder: lan.docker.network.tag_textarea
}
}]
})
},
yes:function(layers){
var formValue = add_network.$get_form_value()
if(formValue.name == '')return layer.msg(lan.docker.network.add_tips1,{icon:2})
if(formValue.options == '')return layer.msg(lan.docker.network.add_tips2,{icon:2})
if(formValue.subnet == '')return layer.msg(lan.docker.network.add_tips3,{icon:2})
if(formValue.gateway == '')return layer.msg(lan.docker.network.add_tips4,{icon:2})
if(formValue.iprange == '')return layer.msg(lan.docker.network.add_tips5,{icon:2})
that.ajax_task_method('add',{data:formValue,tips:lan.docker.network.adding},function(res){
if(res.status){
layer.close(layers)
that.initTabConfig('network') //刷新列表
}
bt_tools.msg(res)
})
}
})
},
/**
* @description 添加存储卷
*/
add_volume:function(){
var that = this,add_volume = null
bt_tools.open({
title: lan.docker.volume.add,
btn: [lan.public.submit, lan.site.no],
area:['540px','420px'],
content: '
',
success: function (layers) {
add_volume = bt_tools.form({
el:'#add_volume_form',
form: [{
label: lan.docker.public.volume,
group: {
type: 'text',
name: 'name',
width: '358px',
placeholder: lan.docker.volume.name_input
}
},{
label: lan.docker.volume.driver,
group:{
type: 'select',
name:'driver',
width:'160px',
list:[
{title:'local',value:'local'}
]
}
},{
label: lan.docker.volume.option,
group: {
type: 'textarea',
name: 'driver_opts',
style: {
'width': '358px',
'min-width': '358px',
'min-height': '70px',
'line-height': '22px',
'padding-top': '5px',
'resize': 'both'
},
placeholder: lan.docker.volume.option
}
},{
label: lan.docker.public.tag,
group: {
type: 'textarea',
name: 'labels',
style: {
'width': '358px',
'min-width': '358px',
'min-height': '70px',
'line-height': '22px',
'padding-top': '5px',
'resize': 'both'
},
placeholder: lan.docker.volume.tag_textarea
}
}]
})
},
yes:function(indexs){
var formValue = add_volume.$get_form_value()
if(formValue.name == '')return layer.msg(lan.docker.volume.add_tips1,{icon:2})
that.ajax_task_method('add',{data:formValue,tips:lan.docker.volume.adding},function(res){
if(res.status){
layer.close(indexs);
that.initTabConfig('volume') //刷新列表
}
bt_tools.msg(res)
})
}
})
},
/**
* @description 仓库添加、编辑界面
* @param {Object} edit 编辑数据
*/
render_registry_view:function(edit){
var that = this,add_registry = null,is_edit = false
if(edit){
edit['registry'] = edit['url']
is_edit = true
}
bt_tools.open({
title: (is_edit ? lan.public.edit : lan.public.add) + ' ' + lan.docker.public.repository.toLowerCase(),
btn: [is_edit ? lan.site.save: lan.public.submit, lan.site.no],
area:['580px','420px'],
content: '
',
success: function (layers) {
add_registry = bt_tools.form({
el:'#add_registry_form',
form: [{
label: lan.docker.repository.address,
group: {
type: 'text',
name: 'registry',
width: '340px',
placeholder: lan.docker.repository.address_input
}
},{
label: lan.docker.repository.name,
group: {
type: 'text',
name: 'name',
width: '340px',
placeholder: lan.docker.repository.name_input
}
},{
label: lan.docker.repository.username,
group:[{
type: 'text',
name: 'username',
width: '340px',
placeholder: lan.docker.repository.user_input
}]
},
{
label: lan.docker.repository.pwd,
group: [
{
type: 'text',
name: 'password',
width: '340px',
placeholder: lan.docker.repository.pwd_input
}
]
},
{
label: lan.docker.repository.namespaces,
group: [{
type: 'text',
name: 'namespace',
width: '340px',
placeholder: lan.docker.repository.namespaces_input
},{
type:'link',
title: '?',
class:'bt-ico-ask',
event:function(){
window.open('https://www.bt.cn/bbs/thread-80965-1-1.html')
}
}]
},{
label: lan.one_click.description,
group: {
type: 'text',
name: 'remark',
width: '340px',
placeholder: lan.docker.compose.description_input_tips
}
}],
data:edit?edit:{}
})
},
yes:function(indexs){
var formValue = add_registry.$get_form_value()
if(formValue.registry == '')return layer.msg(lan.docker.repository.form_tips1,{icon:2})
if(formValue.name == '')return layer.msg(lan.docker.repository.form_tips2,{icon:2})
if(formValue.username == '')return layer.msg(lan.docker.repository.form_tips3,{icon:2})
if(formValue.password == '')return layer.msg(lan.docker.repository.form_tips4,{icon:2})
if(formValue.namespace == '')return layer.msg(lan.docker.repository.form_tips5,{icon:2})
if(edit) formValue['id'] = edit['id']
that.ajax_task_method(is_edit?'edit':'add',{data:formValue,tips:(edit? lan.public.save : lan.public.add) + ' ' + lan.docker.public.repository.toLowerCase()},function(res){
if(res.status){
layer.close(indexs);
that.initTabConfig('registry') //刷新列表
}
bt_tools.msg(res)
})
}
})
},
/**
* @description 构建镜像
*/
construction_image:function(){
var that = this,_aceEditor = null;
layer.open({
type: 1,
title: lan.docker.image.build_title,
btn: [lan.public.submit, lan.site.no],
area:'580px',
content: '
',
success:function(){
_aceEditor = bt.aceEditor({ el: 'dkFileBody', content:'' });
$('[name=dockerfile_type]').change(function(){
switch($(this).val()){
case '0':
$('.constr_image .df_type:eq(0)').show();
$('.constr_image .df_type:eq(1)').hide();
$('[name=df_path]').val('');
break;
case '1':
$('.constr_image .df_type:eq(1)').show();
$('.constr_image .df_type:eq(0)').hide();
_aceEditor.ACE.setValue('')
break;
}
})
},
yes:function(layers){
var _mType = $('[name=dockerfile_type]').val(),
_mDesc = $('[name=dk_tag]').val(),
_Con = _aceEditor.ACE.getValue(),
param = {tag:_mDesc}
if(_mType == '0'){
param['path'] = $('[name=df_path]').val()
}else{
param['data'] = _Con
}
that.get_log_situation()
that.ajax_task_method('build',{data:param,tips:false},function(res){
that.remove_log_clearinterval();
if(res.status){
layer.closeAll()
that.initTabConfig('model') //刷新列表
}
bt_tools.msg(res)
})
}
})
},
/**
* @description 容器监控【获取并整理实时数据,刷新图表】
* @param {Object} row 容器信息
*/
transform_cont_chart_data:function(row){
var that = this,_time = new Date().getTime();
this.ajax_task_method('stats',{data:{id:row.id},tips:false,model_name:{dk_model_name:'status'}},function(res){
var _data = res.msg;
if(!res.status){
that.remove_cont_chart_data();
bt_tools.msg(res);
return false
}
//基础信息
$('.cont_chart_basis').eq(0).find('span').html(bt.format_size(_data.limit))
$('.cont_chart_basis').eq(1).find('span').html(lan.index.net_up + ': ' + bt.format_size(_data.tx_total)+' - '+ lan.index.net_down + ': '+bt.format_size(_data.rx_total))
that.cont_chart.time_list.push(_time)
that.cont_chart.mem_list['usage'].push([_time, bt.format_size(_data.usage,false,null,'MB')])
that.cont_chart.mem_list['cache'].push([_time,bt.format_size(_data.cache,false,null,'MB')])
that.cont_chart.cpu_list.push([_time,_data.cpu_usage])
that.cont_chart.disk_list['read'].push([_time, bt.format_size(_data.read_total,false,null,'MB')])
that.cont_chart.disk_list['write'].push([_time, bt.format_size(_data.write_total,false,null,'MB')])
that.cont_chart.network_list['tx'].push([_time, bt.format_size(_data.tx,false,null,'KB')])
that.cont_chart.network_list['rx'].push([_time, bt.format_size(_data.rx,false,null,'KB')])
// console.log(that.cont_chart_id.cpu.getOption());
//实时更新图表数据
that.cont_chart_id.cpu.setOption({
series:[
{
name: 'CPU',
data: that.cont_chart.cpu_list
}
],
xAxis:that.cont_chart.time_list
})
that.cont_chart_id.mem.setOption({
series: [
{
name: lan.pythonmamager.mem,
data: that.cont_chart.mem_list['usage']
},
{
name: lan.site.cache,
data: that.cont_chart.mem_list['cache']
}
]
})
that.cont_chart_id.disk.setOption({
series: [
{
name: lan.files.file_read,
data: that.cont_chart.disk_list['read']
},
{
name: lan.files.file_write,
data: that.cont_chart.disk_list['write']
}
]
})
that.cont_chart_id.network.setOption({
series: [
{
name: lan.index.net_up,
data: that.cont_chart.network_list['tx']
},
{
name: lan.index.net_down,
data: that.cont_chart.network_list['rx']
}
]
})
})
},
/**
* @description 容器监控【图表配置处理】
* @param {String} type 图表类型【CPU/内存/磁盘/网络】
* @return 返回处理好的图表配置
*/
transform_cont_chart_option:function(type){
var _unit = '/MB'
var _option = this.get_default_option();
switch(type){
case 'cpu':
_option.tooltip.formatter = function (config) {
var data = config[0];
return bt.format_data(data.data[0]) + '
' + data.seriesName + ': ' + data.data[1] + '%';
};
_option.yAxis.min = 0;
_option.series = [
{
name: 'CPU',
type: 'line',
symbol: 'none',
smooth: true,
itemStyle: {
normal: {
color: 'rgb(0, 153, 238)'
}
}
}
]
break;
case 'network':
_unit = '/KB'
case 'mem':
case 'disk':
var third = {
mem:[lan.pythonmamager.mem, lan.site.cache],
disk:[lan.files.file_read, lan.files.file_write],
network:[lan.index.net_up, lan.index.net_down],
color:[
{
mem:['rgb(185, 220, 253)','rgb(185, 220, 253,0.6)','rgb(185, 220, 253,0.3)','rgba(229,147,187)','rgba(229,147,187,0.6)','rgba(229,147,187,0.3)'],
disk:['rgb(255, 70, 131)','rgb(255, 70, 131,0.6)','rgb(255, 70, 131,0.3)','rgba(46, 165, 186)','rgba(46, 165, 186,0.6)','rgba(46, 165, 186,0.3)'],
network:['rgb(255, 140, 0)','rgb(255, 140, 0,0.6)','rgb(255, 140, 0,0.3)','rgb(30, 144, 255)','rgb(30, 144, 255,0.6)','rgb(30, 144, 255,0.3)']
}
]
}
_option.tooltip.formatter = function (config) {
var data = config[0];
var time = data.data[0];
var date = bt.format_data(time / 1000);
var _tips = '';
var _style = '
' + config[i].seriesName + ':'
_tips += config[i].data[1] + _unit + (config.length - 1 !== i ? '
' : '');
}
return "时间:" + date + "
" + _tips;
};
_option.legend = {
top: '18px',
data: third[type]
};
_option.series = [
{
name: third[type][0],
type: 'line',
symbol: 'none',
itemStyle: {
normal: {
color: third['color'][0][type][0],
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
offset: 0,
color: third['color'][0][type][1]
}, {
offset: 1,
color: third['color'][0][type][2]
}])
}
}
}
},
{
name: third[type][1],
type: 'line',
symbol: 'none',
itemStyle: {
normal: {
color: third['color'][0][type][4],
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
offset: 0,
color: third['color'][0][type][4]
}, {
offset: 1,
color: third['color'][0][type][5]
}])
}
}
}
}
];
break;
}
return _option
},
/**
* @description 渲染容器监控图表
* @param {Object} row 容器信息
*/
render_cont_chart:function(row){
var that = this;
this.cont_chart_id.cpu = echarts.init(document.getElementById('cont_cpu'))
this.cont_chart_id.mem = echarts.init(document.getElementById('cont_mem'))
this.cont_chart_id.disk = echarts.init(document.getElementById('cont_disk'))
this.cont_chart_id.network = echarts.init(document.getElementById('cont_network'))
$.each(['cpu','mem','disk','network'],function(index,item){
that.cont_chart_id[item].setOption(that.transform_cont_chart_option(item))
})
this.transform_cont_chart_data(row) //默认加载数据
},
/**
* @description 获取默认图表配置
* @return 返回默认图表配置
*/
get_default_option:function(){
return {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
}
},
grid: {
x: 50, //左
y: 50, //上
x2: 30,//右
y2: 30 //下
},
xAxis: {
type: 'time',
scale:true,
splitNumber:4,
boundaryGap: true,
axisLine: {
lineStyle: {
color: "#666"
}
},
axisLabel: {
// interval:0,
formatter: function (value) {
return bt.format_data(value / 1000, 'hh:mm:ss');
}
},
},
yAxis: {
type: 'value',
boundaryGap: [0, '100%'],
splitLine: {
lineStyle: {
color: "#ddd"
}
},
axisLine: {
lineStyle: {
color: "#666"
}
}
}
}
},
/**
* @description 容器详情配置
* @param {Object} row 容器信息
*/
open_container_config:function(obj){
var that = this;
layer.open({
type:1,
title:'Container ['+obj.name+']',
area:['780px','720px'],
shadeClose: false,
closeBtn: 2,
btn:false,
content:'
',
success:function(){
that.set_cont_config(obj);
// 菜单事件
$('.cn_menu p').click(function () {
$('#container_box').html('').removeAttr('style');
$(this).addClass('bgw').siblings().removeClass('bgw');
that['set_cont_'+$(this).data('type')](obj);
})
}
})
},
/**
* @description 容器终端
* @param {Object} row 容器信息
*/
open_container_shell_view:function(row){
var that = this;
web_shell();
var shell = setInterval(function(){
if($('.term-box').length == 0){
pdata_socket['data'] = 'exit\n'
socket.emit('webssh',pdata_socket);
setTimeout(function(){socket.emit('webssh',pdata_socket['data']);},1000);
clearInterval(shell);
}
},500);
setTimeout(function(){
that.ajax_task_method('docker_shell', {
data: { container_id: row.id },
tips: lan.docker.container.execute_container_command,
model_name: { dk_model_name: 'container' }
}, function (res) {
if (res.status) {
pdata_socket['data'] = 'clear && ' + res.msg +'\n'
socket.emit('webssh',pdata_socket);
setTimeout(function(){
socket.emit('webssh',pdata_socket['data']);
}, 1000);
}else{
bt_tools.msg(res)
}
})
});
},
/**
* @description 容器配置
* @param {Object} row 容器信息
*/
set_cont_config:function(row){
$('#container_box').css({'padding-right':'25px','overflow':'overlay'});
var wrapper = document.getElementById("container_box")
jsonTree.create(row.detail,wrapper)
},
/**
* @description 容器生成镜像 【可导出文件】
* @param {Object} row 容器信息
*/
set_cont_create_image:function(row){
var that = this;
bt_tools.form({
el:'#container_box',
form:[{
label:'Mirror name',
group:{
name:'repository',
type: 'text',
placeholder: 'Please enter the mirror name',
width:'350px'
}
},{
label:'Tag',
group:{
name:'tag',
type: 'text',
placeholder: 'Please enter the tag',
width:'350px'
}
},{
label:'Submit description',
group:{
name:'message',
type: 'text',
placeholder: 'Description before submission',
width:'350px'
}
},{
label:'Author',
group:{
name:'author',
type: 'text',
placeholder: 'Please enter the author',
width:'350px'
}
},{
label: '',
group: [{
type: 'button',
size: '',
name: 'cont_caimage_btn',
title: 'Generate mirror image',
event: function (formData) {
if(
formData.repository == '' ||
formData.tag == '' ||
formData.message == '' ||
formData.author == ''
){
return layer.msg('Please fill in the generated mirror information first',{icon:2})
}
formData['id'] = row.id
submitImage(formData)
}
},{
type: 'button',
size: '',
name: 'cont_caimage_export_btn',
style: { 'display': 'block', 'margin-top': '15px' },
title: 'Export the compressed package after the image is generated',
event: function (formData) {
if(
formData.repository == '' ||
formData.tag == '' ||
formData.message == '' ||
formData.author == ''
){
return layer.msg('Please fill in the generated mirror information first',{icon:2})
}
bt_tools.open({
type: 1,
title: 'Export ['+row.name+'] mirror image',
area: '430px',
btn: ['Export', lan.site.no],
content: {
'class': "pd20",
form: [{
label: "Path",
group: {
name: "path",
type: "text",
value: '',
width: "240px",
placeholder:'Please enter the mirror path',
icon: {
type: 'glyphicon-folder-open',
event:function(){}
}
}
},{
label: "File name",
group: {
name: "name",
type: "text",
value: formData.repository,
width: "240px",
disabled:true,
placeholder:'Please enter the exposed file name',
unit:'.tar'
}
}]
},
yes: function (formD,indexs) {
if (formD.path === '') return bt_tools.msg('The path cannot be empty!', 2)
if (formD.name === '') return bt_tools.msg('Export file name cannot be empty!', 2)
formData['id'] = row.id
formData['path'] = formD.path
formData['name'] = formD.name
submitImage(formData,indexs)
}
})
}
}]
}]
})
// 生成镜像 --导出文件
function submitImage(form,closeView){
that.ajax_task_method('commit',{data:form,tips:'Generate mirror image'},function(res){
if(res.status){
if(closeView) layer.close(closeView)
}
bt_tools.msg(res)
})
}
},
/**
* @description 容器状态设置
* @param {String} type 设置状态
* @param {String} id 容器id
* @param {Object} table 需要重新渲染的表格
*/
container_status_setting:function(type,id,table,is_compose){
var config = {id:id},
tips = {start:'Start up',stop:'Stop',pause:'Pause',unpause:'Unpause',restart:'Restart',reload:'Reload'},
param = {tips:tips[type]+' container'}
if(is_compose){
param['model_name'] = {dk_model_name:'container'}
}
param['data'] = config;
this.ajax_task_method(type,param,function(res){
if(res.status){
table.$refresh_table_list(true) //刷新列表
}
layer.msg(res.msg,{icon:res.status?1:2})
})
},
/**
* @description 获取日志窗口状态
*/
get_log_situation:function(){
var that = this;
that.log_layer_open = layer.open({
title: lan.docker.public.execution,
type: 1,
closeBtn: false,
maxmin: true,
skin: 'dockertmp',
area: ["730px", '450px'],
content:"
",
success:function(){
that.log_file_setInterval = setInterval(function(){that.get_log_speed()},1500)
}
})
},
/**
* @description 获取日志进度
*/
get_log_speed:function(){
this.ajax_task_method('get_logs',{data:{logs_file:'/tmp/dockertmp.log'},tips:false,model_name:{dk_model_name:"image"}},function(ires){
$("#dockertmp_pre").text(ires.msg);
$('#dockertmp_pre').animate({
scrollTop: $('#dockertmp_pre').prop("scrollHeight")
}, 400);
})
},
/**
* @description 删除容器监控数据和图表dom
*/
remove_cont_chart_data:function(){
clearInterval(this.cont_setInterval)
this.cont_chart = {
cpu_list:[],
mem_list:{
usage:[],
cache:[]
},
disk_list:{
read:[],
write:[]
},
network_list:{
tx:[],
rx:[]
},
time_list:[]
}
this.cont_chart_id = {
cpu:null,
mem:null,
disk:null,
network:null
}
},
//删除日志定时器
remove_log_clearinterval:function(){
layer.close(layer.index) //最新的弹层
clearInterval(this.log_file_setInterval)
},
/**
* @description 停止用户操作
* @param {Boolean} is_install 是否docker安装
* @param {Boolean} is_service 是否启动docker
*/
stop_user_operation:function(is_install,is_service){
var that = this;
var tips = 'Docker service is not currently started. Please enable it in
Docker Settings';
if(!is_install) tips = 'Currently not installed docker or docker-compose,
click install'
$('.mask_layer').removeAttr('style');
$('.prompt_description').html(tips)
//安装docker
$('.install_docker').click(function(){
that.ajax_task_method('install_docker_program',{model_name:{dk_model_name:'setup'}},function(res){
bt_tools.msg(res)
messagebox()
})
});
$('.setting_docker').click(function () {
$('.tab-list .tabs-item[data-type="setup"]').click()
})
},
/**
* @description docker请求方式转换
* @param {String} action 请求方法
* @param {Object} param data填写请求所需参数,tips填写请求时展示文字
* @param {any} callback 数据回调
*/
ajax_task_method:function(action,param,callback){
var _config = $.extend({},param['data'] || {},this.global,{dk_def_name:action},param['model_name'] || {})
bt_tools.send({
url:this.global_api+'?action='+_config.dk_model_name+'-'+_config.dk_def_name+'',
data:{data:JSON.stringify(_config)}
},function(res){
if(callback)callback(res)
},{load:param['tips'],verify: false})
},
/**
* @description docker批量操作参数处理
* @param {String} action 请求方法
* @param {Object} param 请求所需参数
* @return 返回JSON格式参数
*/
batch_param_convert:function(action,param){
return JSON.stringify($.extend({},this.global,{dk_def_name:action},param || {}))
},
/**
* @description UTC时间转换
* @param {Object} utc_datetime utc时间
* @return 返回处理后的时间
*/
utc2beijing:function(utc_datetime) {
// 转为正常的时间格式 年-月-日 时:分:秒
var T_pos = utc_datetime.indexOf('T');
var Z_pos = utc_datetime.indexOf('Z');
var year_month_day = utc_datetime.substr(0,T_pos);
var hour_minute_second = utc_datetime.substr(T_pos+1,Z_pos-T_pos-1);
var new_datetime = year_month_day+" "+hour_minute_second;
// 处理成为时间戳
timestamp = new Date(Date.parse(new_datetime));
timestamp = timestamp.getTime();
timestamp = timestamp/1000;
// 增加8个小时,北京时间比utc时间多八个时区
var timestamp = timestamp+8*60*60;
return bt.format_data(timestamp)
},
initTabConfig:function(type){
this.tabName = type;
this.global.dk_model_name = type
if(type == 'model') this.global.dk_model_name = 'compose'
$('.mask_layer').hide(); //隐藏未安装或未启动提醒
$('#dk_'+type+'_table').empty(); //清除Table
this['get_'+type]();
}
}
//默认触发
$('#cutMode .tabs-item[data-type="' + (bt.get_cookie('docker_model') || 'container') + '"]').trigger('click');