ui: tape: handle tapes in changers without barcode

by checking for definedness of the label (tapes without barcode
have the empty string as label-text) and falling back to the
source slot for the load action

Note: Changed the load-slot API from PUT to POST

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-04-30 10:13:13 +02:00 committed by Dietmar Maurer
parent d724116c0c
commit d1bee4344d
2 changed files with 47 additions and 21 deletions

View File

@ -1453,7 +1453,7 @@ pub const SUBDIRS: SubdirMap = &sorted!([
( (
"load-slot", "load-slot",
&Router::new() &Router::new()
.put(&API_METHOD_LOAD_SLOT) .post(&API_METHOD_LOAD_SLOT)
), ),
( (
"cartridge-memory", "cartridge-memory",

View File

@ -7,6 +7,12 @@ Ext.define('pbs-slot-model', {
return data.state !== undefined; return data.state !== undefined;
}, },
}, },
{
name: 'is-empty',
calculate: function(data) {
return data['label-text'] === undefined;
},
},
], ],
idProperty: 'entry-id', idProperty: 'entry-id',
}); });
@ -179,17 +185,19 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
let me = this; let me = this;
let view = me.getView(); let view = me.getView();
let label = record.data['label-text']; let label = record.data['label-text'];
let slot = record.data['entry-id'];
let changer = encodeURIComponent(view.changer); let changer = encodeURIComponent(view.changer);
let singleDrive = me.drives.length === 1 ? me.drives[0] : undefined; let singleDrive = me.drives.length === 1 ? me.drives[0] : undefined;
let apiCall = label !== "" ? 'load-media' : 'load-slot';
let params = label !== "" ? { 'label-text': label } : { 'source-slot': slot };
if (singleDrive !== undefined) { if (singleDrive !== undefined) {
Proxmox.Utils.API2Request({ Proxmox.Utils.API2Request({
method: 'POST', method: 'POST',
params: { params,
'label-text': label, url: `/api2/extjs/tape/drive/${singleDrive}/${apiCall}`,
},
url: `/api2/extjs/tape/drive/${singleDrive}/load-media`,
success: function(response, opt) { success: function(response, opt) {
Ext.create('Proxmox.window.TaskProgress', { Ext.create('Proxmox.window.TaskProgress', {
upid: response.result.data, upid: response.result.data,
@ -213,15 +221,21 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
submitUrl: function(url, values) { submitUrl: function(url, values) {
let drive = values.drive; let drive = values.drive;
delete values.drive; delete values.drive;
return `${url}/${encodeURIComponent(drive)}/load-media`; return `${url}/${encodeURIComponent(drive)}/${apiCall}`;
}, },
items: [ items: [
{ label !== undefined ? {
xtype: 'displayfield', xtype: 'displayfield',
name: 'label-text', name: 'label-text',
value: label, value: label,
submitValue: true, submitValue: true,
fieldLabel: gettext('Media'), fieldLabel: gettext('Media'),
} : {
xtype: 'displayfield',
name: 'source-slot',
value: slot,
submitValue: true,
fieldLabel: gettext('Source Slot'),
}, },
{ {
xtype: 'pbsDriveSelector', xtype: 'pbsDriveSelector',
@ -589,6 +603,18 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
me.scheduleReload(5000); me.scheduleReload(5000);
}, },
renderLabel: function(value) {
if (value === undefined) {
return '';
}
if (value === "") {
return Ext.htmlEncode("<no-barcode>");
}
return value;
},
renderIsLabeled: function(value, mD, record) { renderIsLabeled: function(value, mD, record) {
if (!record.data['label-text']) { if (!record.data['label-text']) {
return ""; return "";
@ -704,7 +730,7 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
text: gettext("Content"), text: gettext("Content"),
dataIndex: 'label-text', dataIndex: 'label-text',
flex: 1, flex: 1,
renderer: (value) => value || '', renderer: 'renderLabel',
}, },
{ {
text: gettext('Inventory'), text: gettext('Inventory'),
@ -721,19 +747,19 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
iconCls: 'fa fa-rotate-90 fa-exchange', iconCls: 'fa fa-rotate-90 fa-exchange',
handler: 'slotTransfer', handler: 'slotTransfer',
tooltip: gettext('Transfer'), tooltip: gettext('Transfer'),
isDisabled: (v, r, c, i, rec) => !rec.data['label-text'], isDisabled: (v, r, c, i, rec) => rec.data['is-empty'],
}, },
{ {
iconCls: 'fa fa-trash-o', iconCls: 'fa fa-trash-o',
handler: 'format', handler: 'format',
tooltip: gettext('Format'), tooltip: gettext('Format'),
isDisabled: (v, r, c, i, rec) => !rec.data['label-text'], isDisabled: (v, r, c, i, rec) => rec.data['is-empty'],
}, },
{ {
iconCls: 'fa fa-rotate-90 fa-upload', iconCls: 'fa fa-rotate-90 fa-upload',
handler: 'load', handler: 'load',
tooltip: gettext('Load'), tooltip: gettext('Load'),
isDisabled: (v, r, c, i, rec) => !rec.data['label-text'], isDisabled: (v, r, c, i, rec) => rec.data['is-empty'],
}, },
], ],
}, },
@ -765,7 +791,7 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
handler: 'labelMedia', handler: 'labelMedia',
iconCls: 'fa fa-barcode', iconCls: 'fa fa-barcode',
disabled: true, disabled: true,
enableFn: (rec) => rec.data["label-text"] !== undefined, enableFn: (rec) => !rec.data["is-empty"],
}, },
{ {
text: gettext('Catalog'), text: gettext('Catalog'),
@ -773,7 +799,7 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
handler: 'catalog', handler: 'catalog',
iconCls: 'fa fa-book', iconCls: 'fa fa-book',
disabled: true, disabled: true,
enableFn: (rec) => rec.data["label-text"] !== undefined, enableFn: (rec) => !rec.data["is-empty"],
}, },
{ {
text: gettext('Format'), text: gettext('Format'),
@ -781,7 +807,7 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
handler: 'format-inserted', handler: 'format-inserted',
iconCls: 'fa fa-trash-o', iconCls: 'fa fa-trash-o',
disabled: true, disabled: true,
enableFn: (rec) => rec.data["label-text"] !== undefined, enableFn: (rec) => !rec.data["is-empty"],
dangerous: true, dangerous: true,
confirmMsg: gettext('Are you sure you want to format the inserted tape?'), confirmMsg: gettext('Are you sure you want to format the inserted tape?'),
}, },
@ -805,7 +831,7 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
text: gettext("Content"), text: gettext("Content"),
dataIndex: 'label-text', dataIndex: 'label-text',
flex: 1, flex: 1,
renderer: (value) => value || '', renderer: 'renderLabel',
}, },
{ {
text: gettext('Inventory'), text: gettext('Inventory'),
@ -859,25 +885,25 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
iconCls: 'fa fa-rotate-270 fa-upload', iconCls: 'fa fa-rotate-270 fa-upload',
handler: 'unload', handler: 'unload',
tooltip: gettext('Unload'), tooltip: gettext('Unload'),
isDisabled: (v, r, c, i, rec) => !rec.data['label-text'] || rec.data['is-blocked'], isDisabled: (v, r, c, i, rec) => rec.data['is-empty'] || rec.data['is-blocked'],
}, },
{ {
iconCls: 'fa fa-hdd-o', iconCls: 'fa fa-hdd-o',
handler: 'cartridgeMemory', handler: 'cartridgeMemory',
tooltip: gettext('Cartridge Memory'), tooltip: gettext('Cartridge Memory'),
isDisabled: (v, r, c, i, rec) => !rec.data['label-text'] || rec.data['is-blocked'], isDisabled: (v, r, c, i, rec) => rec.data['is-empty'] || rec.data['is-blocked'],
}, },
{ {
iconCls: 'fa fa-line-chart', iconCls: 'fa fa-line-chart',
handler: 'volumeStatistics', handler: 'volumeStatistics',
tooltip: gettext('Volume Statistics'), tooltip: gettext('Volume Statistics'),
isDisabled: (v, r, c, i, rec) => !rec.data['label-text'] || rec.data['is-blocked'], isDisabled: (v, r, c, i, rec) => rec.data['is-empty'] || rec.data['is-blocked'],
}, },
{ {
iconCls: 'fa fa-tag', iconCls: 'fa fa-tag',
handler: 'readLabel', handler: 'readLabel',
tooltip: gettext('Read Label'), tooltip: gettext('Read Label'),
isDisabled: (v, r, c, i, rec) => !rec.data['label-text'] || rec.data['is-blocked'], isDisabled: (v, r, c, i, rec) => rec.data['is-empty'] || rec.data['is-blocked'],
}, },
{ {
iconCls: 'fa fa-info-circle', iconCls: 'fa fa-info-circle',
@ -910,7 +936,7 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
{ {
text: gettext("Content"), text: gettext("Content"),
dataIndex: 'label-text', dataIndex: 'label-text',
renderer: (value) => value || '', renderer: 'renderLabel',
flex: 1, flex: 1,
}, },
{ {
@ -927,7 +953,7 @@ Ext.define('PBS.TapeManagement.ChangerStatus', {
iconCls: 'fa fa-rotate-270 fa-upload', iconCls: 'fa fa-rotate-270 fa-upload',
handler: 'importTape', handler: 'importTape',
tooltip: gettext('Import'), tooltip: gettext('Import'),
isDisabled: (v, r, c, i, rec) => !rec.data['label-text'], isDisabled: (v, r, c, i, rec) => rec.data['is-empty'],
}, },
], ],
width: 80, width: 80,