ui: factor out common code
This commit is contained in:
parent
8730cfcc3e
commit
3d3e31b7f8
173
www/Utils.js
173
www/Utils.js
@ -428,6 +428,179 @@ Ext.define('PBS.Utils', {
|
|||||||
.map(val => val.charCodeAt(0)),
|
.map(val => val.charCodeAt(0)),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
driveCommand: function(driveid, command, reqOpts) {
|
||||||
|
let params = Ext.apply(reqOpts, {
|
||||||
|
url: `/api2/extjs/tape/drive/${driveid}/${command}`,
|
||||||
|
timeout: 5*60*1000,
|
||||||
|
failure: function(response) {
|
||||||
|
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
Proxmox.Utils.API2Request(params);
|
||||||
|
},
|
||||||
|
|
||||||
|
showMediaLabelWindow: function(response) {
|
||||||
|
let list = [];
|
||||||
|
for (let [key, val] of Object.entries(response.result.data)) {
|
||||||
|
if (key === 'ctime' || key === 'media-set-ctime') {
|
||||||
|
val = Proxmox.Utils.render_timestamp(val);
|
||||||
|
}
|
||||||
|
list.push({ key: key, value: val });
|
||||||
|
}
|
||||||
|
|
||||||
|
Ext.create('Ext.window.Window', {
|
||||||
|
title: gettext('Label Information'),
|
||||||
|
modal: true,
|
||||||
|
width: 600,
|
||||||
|
height: 450,
|
||||||
|
layout: 'fit',
|
||||||
|
scrollable: true,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
xtype: 'grid',
|
||||||
|
store: {
|
||||||
|
data: list,
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
text: gettext('Property'),
|
||||||
|
dataIndex: 'key',
|
||||||
|
width: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: gettext('Value'),
|
||||||
|
dataIndex: 'value',
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}).show();
|
||||||
|
},
|
||||||
|
|
||||||
|
showCartridgeMemoryWindow: function(response) {
|
||||||
|
Ext.create('Ext.window.Window', {
|
||||||
|
title: gettext('Cartridge Memory'),
|
||||||
|
modal: true,
|
||||||
|
width: 600,
|
||||||
|
height: 450,
|
||||||
|
layout: 'fit',
|
||||||
|
scrollable: true,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
xtype: 'grid',
|
||||||
|
store: {
|
||||||
|
data: response.result.data,
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
text: gettext('ID'),
|
||||||
|
dataIndex: 'id',
|
||||||
|
width: 60,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: gettext('Name'),
|
||||||
|
dataIndex: 'name',
|
||||||
|
flex: 2,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: gettext('Value'),
|
||||||
|
dataIndex: 'value',
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}).show();
|
||||||
|
},
|
||||||
|
|
||||||
|
showVolumeStatisticsWindow: function(response) {
|
||||||
|
let list = [];
|
||||||
|
for (let [key, val] of Object.entries(response.result.data)) {
|
||||||
|
if (key === 'total-native-capacity' ||
|
||||||
|
key === 'total-used-native-capacity' ||
|
||||||
|
key === 'lifetime-bytes-read' ||
|
||||||
|
key === 'lifetime-bytes-written' ||
|
||||||
|
key === 'last-mount-bytes-read' ||
|
||||||
|
key === 'last-mount-bytes-written') {
|
||||||
|
val = Proxmox.Utils.format_size(val);
|
||||||
|
}
|
||||||
|
list.push({ key: key, value: val });
|
||||||
|
}
|
||||||
|
Ext.create('Ext.window.Window', {
|
||||||
|
title: gettext('Volume Statistics'),
|
||||||
|
modal: true,
|
||||||
|
width: 600,
|
||||||
|
height: 450,
|
||||||
|
layout: 'fit',
|
||||||
|
scrollable: true,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
xtype: 'grid',
|
||||||
|
store: {
|
||||||
|
data: list,
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
text: gettext('Property'),
|
||||||
|
dataIndex: 'key',
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: gettext('Value'),
|
||||||
|
dataIndex: 'value',
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}).show();
|
||||||
|
},
|
||||||
|
|
||||||
|
showDriveStatusWindow: function(response) {
|
||||||
|
let list = [];
|
||||||
|
for (let [key, val] of Object.entries(response.result.data)) {
|
||||||
|
if (key === 'manufactured') {
|
||||||
|
val = Proxmox.Utils.render_timestamp(val);
|
||||||
|
}
|
||||||
|
if (key === 'bytes-read' || key === 'bytes-written') {
|
||||||
|
val = Proxmox.Utils.format_size(val);
|
||||||
|
}
|
||||||
|
list.push({ key: key, value: val });
|
||||||
|
}
|
||||||
|
|
||||||
|
Ext.create('Ext.window.Window', {
|
||||||
|
title: gettext('Status'),
|
||||||
|
modal: true,
|
||||||
|
width: 600,
|
||||||
|
height: 450,
|
||||||
|
layout: 'fit',
|
||||||
|
scrollable: true,
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
xtype: 'grid',
|
||||||
|
store: {
|
||||||
|
data: list,
|
||||||
|
},
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
text: gettext('Property'),
|
||||||
|
dataIndex: 'key',
|
||||||
|
width: 120,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: gettext('Value'),
|
||||||
|
dataIndex: 'value',
|
||||||
|
flex: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}).show();
|
||||||
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Ext.define('PBS.Async', {
|
Ext.define('PBS.Async', {
|
||||||
|
@ -178,207 +178,49 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
|
|||||||
me.reload();
|
me.reload();
|
||||||
},
|
},
|
||||||
|
|
||||||
driveCommand: function(driveid, command, callback, params, method) {
|
|
||||||
let me = this;
|
|
||||||
let view = me.getView();
|
|
||||||
params = params || {};
|
|
||||||
method = method || 'GET';
|
|
||||||
Proxmox.Utils.API2Request({
|
|
||||||
url: `/api2/extjs/tape/drive/${driveid}/${command}`,
|
|
||||||
timeout: 5*60*1000,
|
|
||||||
method,
|
|
||||||
waitMsgTarget: view,
|
|
||||||
params,
|
|
||||||
success: function(response) {
|
|
||||||
callback(response);
|
|
||||||
},
|
|
||||||
failure: function(response) {
|
|
||||||
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
cartridgeMemory: function(view, rI, cI, button, el, record) {
|
cartridgeMemory: function(view, rI, cI, button, el, record) {
|
||||||
let me = this;
|
let me = this;
|
||||||
let drive = record.data.name;
|
let drive = record.data.name;
|
||||||
me.driveCommand(drive, 'cartridge-memory', function(response) {
|
PBS.Utils.driveCommand(drive, 'cartridge-memory', {
|
||||||
Ext.create('Ext.window.Window', {
|
waitMsgTarget: me.getView(),
|
||||||
title: gettext('Cartridge Memory'),
|
success: PBS.Utils.showCartridgeMemoryWindow,
|
||||||
modal: true,
|
|
||||||
width: 600,
|
|
||||||
height: 450,
|
|
||||||
layout: 'fit',
|
|
||||||
scrollable: true,
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
xtype: 'grid',
|
|
||||||
store: {
|
|
||||||
data: response.result.data,
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
text: gettext('ID'),
|
|
||||||
dataIndex: 'id',
|
|
||||||
width: 60,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: gettext('Name'),
|
|
||||||
dataIndex: 'name',
|
|
||||||
flex: 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: gettext('Value'),
|
|
||||||
dataIndex: 'value',
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}).show();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
cleanDrive: function(view, rI, cI, button, el, record) {
|
cleanDrive: function(view, rI, cI, button, el, record) {
|
||||||
let me = this;
|
let me = this;
|
||||||
me.driveCommand(record.data.name, 'clean', function(response) {
|
PBS.Utils.driveCommand(record.data.name, 'clean', {
|
||||||
me.reload();
|
waitMsgTarget: me.getView(),
|
||||||
}, {}, 'PUT');
|
callback: me.reload,
|
||||||
|
method: 'PUT',
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
volumeStatistics: function(view, rI, cI, button, el, record) {
|
volumeStatistics: function(view, rI, cI, button, el, record) {
|
||||||
let me = this;
|
let me = this;
|
||||||
let drive = record.data.name;
|
let drive = record.data.name;
|
||||||
me.driveCommand(drive, 'volume-statistics', function(response) {
|
PBS.Utils.driveCommand(drive, 'volume-statistics', {
|
||||||
let list = [];
|
waitMsgTarget: me.getView(),
|
||||||
for (let [key, val] of Object.entries(response.result.data)) {
|
success: PBS.Utils.showVolumeStatisticsWindow,
|
||||||
if (key === 'total-native-capacity' ||
|
|
||||||
key === 'total-used-native-capacity' ||
|
|
||||||
key === 'lifetime-bytes-read' ||
|
|
||||||
key === 'lifetime-bytes-written' ||
|
|
||||||
key === 'last-mount-bytes-read' ||
|
|
||||||
key === 'last-mount-bytes-written')
|
|
||||||
{
|
|
||||||
val = Proxmox.Utils.format_size(val);
|
|
||||||
}
|
|
||||||
list.push({ key: key, value: val });
|
|
||||||
}
|
|
||||||
Ext.create('Ext.window.Window', {
|
|
||||||
title: gettext('Volume Statistics'),
|
|
||||||
modal: true,
|
|
||||||
width: 600,
|
|
||||||
height: 450,
|
|
||||||
layout: 'fit',
|
|
||||||
scrollable: true,
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
xtype: 'grid',
|
|
||||||
store: {
|
|
||||||
data: list,
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
text: gettext('Property'),
|
|
||||||
dataIndex: 'key',
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: gettext('Value'),
|
|
||||||
dataIndex: 'value',
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}).show();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
readLabel: function(view, rI, cI, button, el, record) {
|
readLabel: function(view, rI, cI, button, el, record) {
|
||||||
let me = this;
|
let me = this;
|
||||||
let drive = record.data.name;
|
let drive = record.data.name;
|
||||||
me.driveCommand(drive, 'read-label', function(response) {
|
|
||||||
let list = [];
|
|
||||||
for (let [key, val] of Object.entries(response.result.data)) {
|
|
||||||
if (key === 'ctime' || key === 'media-set-ctime') {
|
|
||||||
val = Proxmox.Utils.render_timestamp(val);
|
|
||||||
}
|
|
||||||
list.push({ key: key, value: val });
|
|
||||||
}
|
|
||||||
|
|
||||||
Ext.create('Ext.window.Window', {
|
PBS.Utils.driveCommand(drive, 'read-label', {
|
||||||
title: gettext('Label Information'),
|
waitMsgTarget: me.getView(),
|
||||||
modal: true,
|
success: PBS.Utils.showMediaLabelWindow,
|
||||||
width: 600,
|
|
||||||
height: 450,
|
|
||||||
layout: 'fit',
|
|
||||||
scrollable: true,
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
xtype: 'grid',
|
|
||||||
store: {
|
|
||||||
data: list,
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
text: gettext('Property'),
|
|
||||||
dataIndex: 'key',
|
|
||||||
width: 120,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: gettext('Value'),
|
|
||||||
dataIndex: 'value',
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}).show();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
status: function(view, rI, cI, button, el, record) {
|
status: function(view, rI, cI, button, el, record) {
|
||||||
let me = this;
|
let me = this;
|
||||||
let drive = record.data.name;
|
let drive = record.data.name;
|
||||||
me.driveCommand(drive, 'status', function(response) {
|
PBS.Utils.driveCommand(drive, 'status', {
|
||||||
let list = [];
|
waitMsgTarget: me.getView(),
|
||||||
for (let [key, val] of Object.entries(response.result.data)) {
|
success: PBS.Utils.showDriveStatusWindow,
|
||||||
if (key === 'manufactured') {
|
|
||||||
val = Proxmox.Utils.render_timestamp(val);
|
|
||||||
}
|
|
||||||
if (key === 'bytes-read' || key === 'bytes-written') {
|
|
||||||
val = Proxmox.Utils.format_size(val);
|
|
||||||
}
|
|
||||||
list.push({ key: key, value: val });
|
|
||||||
}
|
|
||||||
|
|
||||||
Ext.create('Ext.window.Window', {
|
|
||||||
title: gettext('Status'),
|
|
||||||
modal: true,
|
|
||||||
width: 600,
|
|
||||||
height: 450,
|
|
||||||
layout: 'fit',
|
|
||||||
scrollable: true,
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
xtype: 'grid',
|
|
||||||
store: {
|
|
||||||
data: list,
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
text: gettext('Property'),
|
|
||||||
dataIndex: 'key',
|
|
||||||
width: 120,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: gettext('Value'),
|
|
||||||
dataIndex: 'value',
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}).show();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -41,147 +41,51 @@ Ext.define('PBS.TapeManagement.DrivePanel', {
|
|||||||
status: function(view, rI, cI, button, el, record) {
|
status: function(view, rI, cI, button, el, record) {
|
||||||
let me = this;
|
let me = this;
|
||||||
let drive = record.data.name;
|
let drive = record.data.name;
|
||||||
me.driveCommand(drive, 'status', function(response) {
|
PBS.Utils.driveCommand(drive, 'status', {
|
||||||
let lines = [];
|
waitMsgTarget: me.getView(),
|
||||||
for (const [key, val] of Object.entries(response.result.data)) {
|
success: PBS.Utils.showDriveStatusWindow,
|
||||||
lines.push(`${key}: ${val}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
let txt = lines.join('<br>');
|
|
||||||
|
|
||||||
Ext.Msg.show({
|
|
||||||
title: gettext('Label Information'),
|
|
||||||
message: txt,
|
|
||||||
icon: undefined,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
catalog: function(view, rI, cI, button, el, record) {
|
catalog: function(view, rI, cI, button, el, record) {
|
||||||
let me = this;
|
let me = this;
|
||||||
let drive = record.data.name;
|
let drive = record.data.name;
|
||||||
me.driveCommand(drive, 'catalog', function(response) {
|
PBS.Utils.driveCommand(drive, 'catalog', {
|
||||||
Ext.create('Proxmox.window.TaskViewer', {
|
waitMsgTarget: me.getView(),
|
||||||
upid: response.result.data,
|
method: 'POST',
|
||||||
}).show();
|
success: function(response) {
|
||||||
}, {}, 'POST');
|
Ext.create('Proxmox.window.TaskViewer', {
|
||||||
|
upid: response.result.data,
|
||||||
|
}).show();
|
||||||
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
readLabel: function(view, rI, cI, button, el, record) {
|
readLabel: function(view, rI, cI, button, el, record) {
|
||||||
let me = this;
|
let me = this;
|
||||||
let drive = record.data.name;
|
let drive = record.data.name;
|
||||||
me.driveCommand(drive, 'read-label', function(response) {
|
|
||||||
let lines = [];
|
|
||||||
for (const [key, val] of Object.entries(response.result.data)) {
|
|
||||||
lines.push(`${key}: ${val}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
let txt = lines.join('<br>');
|
PBS.Utils.driveCommand(drive, 'read-label', {
|
||||||
|
waitMsgTarget: me.getView(),
|
||||||
Ext.Msg.show({
|
success: PBS.Utils.showMediaLabelWindow,
|
||||||
title: gettext('Label Information'),
|
|
||||||
message: txt,
|
|
||||||
icon: undefined,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
volumeStatistics: function(view, rI, cI, button, el, record) {
|
volumeStatistics: function(view, rI, cI, button, el, record) {
|
||||||
let me = this;
|
let me = this;
|
||||||
let drive = record.data.name;
|
let drive = record.data.name;
|
||||||
me.driveCommand(drive, 'volume-statistics', function(response) {
|
PBS.Utils.driveCommand(drive, 'volume-statistics', {
|
||||||
Ext.create('Ext.window.Window', {
|
waitMsgTarget: me.getView(),
|
||||||
title: gettext('Volume Statistics'),
|
success: PBS.Utils.showVolumeStatisticsWindow,
|
||||||
modal: true,
|
|
||||||
width: 600,
|
|
||||||
height: 450,
|
|
||||||
layout: 'fit',
|
|
||||||
scrollable: true,
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
xtype: 'grid',
|
|
||||||
store: {
|
|
||||||
data: response.result.data,
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
text: gettext('ID'),
|
|
||||||
dataIndex: 'id',
|
|
||||||
width: 60,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: gettext('Name'),
|
|
||||||
dataIndex: 'name',
|
|
||||||
flex: 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: gettext('Value'),
|
|
||||||
dataIndex: 'value',
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}).show();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
cartridgeMemory: function(view, rI, cI, button, el, record) {
|
cartridgeMemory: function(view, rI, cI, button, el, record) {
|
||||||
let me = this;
|
let me = this;
|
||||||
let drive = record.data.name;
|
let drive = record.data.name;
|
||||||
me.driveCommand(drive, 'cartridge-memory', function(response) {
|
PBS.Utils.driveCommand(drive, 'cartridge-memory', {
|
||||||
Ext.create('Ext.window.Window', {
|
waitMsgTarget: me.getView(),
|
||||||
title: gettext('Cartridge Memory'),
|
success: PBS.Utils.showCartridgeMemoryWindow,
|
||||||
modal: true,
|
|
||||||
width: 600,
|
|
||||||
height: 450,
|
|
||||||
layout: 'fit',
|
|
||||||
scrollable: true,
|
|
||||||
items: [
|
|
||||||
{
|
|
||||||
xtype: 'grid',
|
|
||||||
store: {
|
|
||||||
data: response.result.data,
|
|
||||||
},
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
text: gettext('ID'),
|
|
||||||
dataIndex: 'id',
|
|
||||||
width: 60,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: gettext('Name'),
|
|
||||||
dataIndex: 'name',
|
|
||||||
flex: 2,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: gettext('Value'),
|
|
||||||
dataIndex: 'value',
|
|
||||||
flex: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}).show();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
driveCommand: function(driveid, command, callback, params, method) {
|
|
||||||
let me = this;
|
|
||||||
let view = me.getView();
|
|
||||||
params = params || {};
|
|
||||||
method = method || 'GET';
|
|
||||||
Proxmox.Utils.API2Request({
|
|
||||||
url: `/api2/extjs/tape/drive/${driveid}/${command}`,
|
|
||||||
method,
|
|
||||||
waitMsgTarget: view,
|
|
||||||
params,
|
|
||||||
success: function(response) {
|
|
||||||
callback(response);
|
|
||||||
},
|
|
||||||
failure: function(response) {
|
|
||||||
Ext.Msg.alert(gettext('Error'), response.htmlStatus);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user