2021-03-01 14:22:39 +03:00
Ext . define ( 'PBS.TapeManagement.DriveStatus' , {
extend : 'Ext.panel.Panel' ,
alias : 'widget.pbsDriveStatus' ,
mixins : [ 'Proxmox.Mixin.CBind' ] ,
2021-03-08 11:47:44 +03:00
tools : [ PBS . Utils . get _help _tool ( "tape_backup" ) ] ,
2021-03-01 14:22:39 +03:00
cbindData : function ( config ) {
let me = this ;
me . setTitle ( ` ${ gettext ( 'Drive' ) } : ${ me . drive } ` ) ;
2021-03-08 12:06:06 +03:00
let baseurl = ` /api2/json/tape/drive/ ${ me . drive } / ` ;
2021-03-01 14:22:39 +03:00
return {
2021-03-08 12:06:06 +03:00
driveStatusUrl : ` ${ baseurl } /status ` ,
cartridgeMemoryUrl : ` ${ baseurl } /cartridge-memory ` ,
2021-03-01 14:22:39 +03:00
} ;
} ,
2021-03-08 12:06:06 +03:00
layout : {
type : 'vbox' ,
align : 'stretch' ,
} ,
2021-03-01 14:22:39 +03:00
bodyPadding : 5 ,
2021-03-01 16:10:32 +03:00
viewModel : {
data : {
online : false ,
2021-03-02 14:19:40 +03:00
busy : true ,
loaded : false ,
2021-03-01 16:10:32 +03:00
} ,
} ,
2021-03-01 14:22:39 +03:00
controller : {
xclass : 'Ext.app.ViewController' ,
2021-04-23 13:52:45 +03:00
reloadTapeStore : function ( ) {
Ext . ComponentQuery . query ( 'navigationtree' ) [ 0 ] . reloadTapeStore ( ) ;
} ,
2021-03-01 14:22:39 +03:00
reload : function ( ) {
let me = this ;
me . lookup ( 'statusgrid' ) . rstore . load ( ) ;
} ,
2021-03-01 16:10:32 +03:00
onLoad : function ( ) {
let me = this ;
let statusgrid = me . lookup ( 'statusgrid' ) ;
2021-04-08 13:04:14 +03:00
let online = statusgrid . getObjectValue ( 'file-number' ) !== undefined ;
2021-03-01 16:10:32 +03:00
let vm = me . getViewModel ( ) ;
vm . set ( 'online' , online ) ;
2021-04-13 11:18:52 +03:00
let title = online ? gettext ( 'Status' ) : gettext ( 'Status (No Tape loaded)' ) ;
statusgrid . setTitle ( title ) ;
2021-04-23 13:52:45 +03:00
Ext . ComponentQuery . query ( 'navigationtree' ) [ 0 ] . reloadTapeStore ( ) ;
2021-03-01 16:10:32 +03:00
} ,
2021-03-02 14:19:40 +03:00
onStateLoad : function ( store ) {
let me = this ;
let view = me . getView ( ) ;
let vm = me . getViewModel ( ) ;
let driveRecord = store . findRecord ( 'name' , view . drive , 0 , false , true , true ) ;
let busy = ! ! driveRecord . data . state ;
vm . set ( 'busy' , busy ) ;
let statusgrid = me . lookup ( 'statusgrid' ) ;
if ( ! vm . get ( 'loaded' ) ) {
if ( busy ) {
// have to use a timeout so that the component can be rendered first
// otherwise the 'mask' call errors out
setTimeout ( function ( ) {
statusgrid . mask ( gettext ( 'Drive is busy' ) ) ;
} , 10 ) ;
} else {
// have to use a timeout so that the component can be rendered first
// otherwise the 'mask' call errors out
setTimeout ( function ( ) {
statusgrid . unmask ( ) ;
} , 10 ) ;
me . reload ( ) ;
vm . set ( 'loaded' , true ) ;
}
}
} ,
2021-03-01 16:10:32 +03:00
labelMedia : function ( ) {
let me = this ;
Ext . create ( 'PBS.TapeManagement.LabelMediaWindow' , {
driveid : me . getView ( ) . drive ,
2021-04-23 13:52:45 +03:00
apiCallDone : function ( success ) {
if ( success ) {
me . reloadTapeStore ( ) ;
}
} ,
2021-03-01 16:10:32 +03:00
} ) . show ( ) ;
} ,
2021-03-31 10:19:19 +03:00
format : function ( ) {
2021-03-17 13:47:31 +03:00
let me = this ;
let view = me . getView ( ) ;
let driveid = view . drive ;
2021-03-31 10:19:19 +03:00
PBS . Utils . driveCommand ( driveid , 'format-media' , {
2021-03-17 13:47:31 +03:00
waitMsgTarget : view ,
method : 'POST' ,
success : function ( response ) {
2021-04-23 13:52:45 +03:00
me . reloadTapeStore ( ) ;
2021-03-17 13:47:31 +03:00
Ext . create ( 'Proxmox.window.TaskProgress' , {
upid : response . result . data ,
taskDone : function ( ) {
me . reload ( ) ;
} ,
} ) . show ( ) ;
} ,
} ) ;
} ,
2021-03-03 17:00:49 +03:00
ejectMedia : function ( ) {
2021-03-01 16:10:32 +03:00
let me = this ;
let view = me . getView ( ) ;
let driveid = view . drive ;
PBS . Utils . driveCommand ( driveid , 'eject-media' , {
waitMsgTarget : view ,
method : 'POST' ,
success : function ( response ) {
2021-04-23 13:52:45 +03:00
me . reloadTapeStore ( ) ;
2021-03-01 16:10:32 +03:00
Ext . create ( 'Proxmox.window.TaskProgress' , {
upid : response . result . data ,
taskDone : function ( ) {
me . reload ( ) ;
} ,
} ) . show ( ) ;
} ,
} ) ;
} ,
catalog : function ( ) {
let me = this ;
let view = me . getView ( ) ;
let drive = view . drive ;
PBS . Utils . driveCommand ( drive , 'catalog' , {
waitMsgTarget : view ,
method : 'POST' ,
success : function ( response ) {
2021-04-23 13:52:45 +03:00
me . reloadTapeStore ( ) ;
2021-03-01 16:10:32 +03:00
Ext . create ( 'Proxmox.window.TaskViewer' , {
upid : response . result . data ,
taskDone : function ( ) {
me . reload ( ) ;
} ,
} ) . show ( ) ;
} ,
} ) ;
} ,
2021-03-08 12:06:07 +03:00
readLabel : function ( ) {
let me = this ;
let view = me . getView ( ) ;
let drive = view . drive ;
PBS . Utils . driveCommand ( drive , 'read-label' , {
waitMsgTarget : view ,
2021-04-23 13:52:45 +03:00
success : function ( response ) {
me . reloadTapeStore ( ) ;
PBS . Utils . showMediaLabelWindow ( response ) ;
} ,
2021-03-08 12:06:07 +03:00
} ) ;
} ,
volumeStatistics : function ( ) {
let me = this ;
let view = me . getView ( ) ;
let drive = view . drive ;
PBS . Utils . driveCommand ( drive , 'volume-statistics' , {
waitMsgTarget : view ,
2021-04-23 13:52:45 +03:00
success : function ( response ) {
me . reloadTapeStore ( ) ;
PBS . Utils . showVolumeStatisticsWindow ( response ) ;
} ,
2021-03-08 12:06:07 +03:00
} ) ;
} ,
2021-03-08 14:52:06 +03:00
cartridgeMemory : function ( ) {
let me = this ;
let view = me . getView ( ) ;
let drive = view . drive ;
PBS . Utils . driveCommand ( drive , 'cartridge-memory' , {
waitMsgTarget : me . getView ( ) ,
2021-04-23 13:52:45 +03:00
success : function ( response ) {
me . reloadTapeStore ( ) ;
PBS . Utils . showCartridgeMemoryWindow ( response ) ;
} ,
2021-03-08 14:52:06 +03:00
} ) ;
} ,
2021-03-01 16:10:32 +03:00
init : function ( view ) {
let me = this ;
me . mon ( me . lookup ( 'statusgrid' ) . getStore ( ) . rstore , 'load' , 'onLoad' ) ;
2021-04-12 13:34:26 +03:00
let tapeStore = Ext . ComponentQuery . query ( 'navigationtree' ) [ 0 ] . tapeStore ;
2021-03-02 14:19:40 +03:00
me . mon ( tapeStore , 'load' , 'onStateLoad' ) ;
if ( tapeStore . isLoaded ( ) ) {
me . onStateLoad ( tapeStore ) ;
}
2021-03-01 16:10:32 +03:00
} ,
2021-03-01 14:22:39 +03:00
} ,
tbar : [
{
xtype : 'proxmoxButton' ,
handler : 'reload' ,
text : gettext ( 'Reload' ) ,
2021-03-02 14:19:40 +03:00
disabled : true ,
bind : {
disabled : '{busy}' ,
} ,
2021-03-01 14:22:39 +03:00
} ,
2021-03-01 16:10:32 +03:00
'-' ,
{
text : gettext ( 'Label Media' ) ,
xtype : 'proxmoxButton' ,
handler : 'labelMedia' ,
iconCls : 'fa fa-barcode' ,
disabled : true ,
bind : {
disabled : '{!online}' ,
} ,
} ,
{
text : gettext ( 'Eject' ) ,
xtype : 'proxmoxButton' ,
handler : 'ejectMedia' ,
iconCls : 'fa fa-eject' ,
disabled : true ,
bind : {
disabled : '{!online}' ,
} ,
} ,
2021-03-17 13:47:31 +03:00
{
2021-03-31 10:19:19 +03:00
text : gettext ( 'Format' ) ,
2021-03-17 13:47:31 +03:00
xtype : 'proxmoxButton' ,
2021-03-31 10:19:19 +03:00
handler : 'format' ,
2021-03-17 13:47:31 +03:00
iconCls : 'fa fa-trash-o' ,
dangerous : true ,
2021-04-14 13:21:37 +03:00
confirmMsg : gettext ( 'Are you sure you want to format the inserted tape?' ) ,
2021-03-17 13:47:31 +03:00
disabled : true ,
bind : {
disabled : '{!online}' ,
} ,
} ,
2021-03-01 16:10:32 +03:00
{
text : gettext ( 'Catalog' ) ,
xtype : 'proxmoxButton' ,
handler : 'catalog' ,
iconCls : 'fa fa-book' ,
disabled : true ,
bind : {
disabled : '{!online}' ,
} ,
} ,
2021-03-08 12:06:07 +03:00
{
text : gettext ( 'Read Label' ) ,
xtype : 'proxmoxButton' ,
handler : 'readLabel' ,
iconCls : 'fa fa-tag' ,
disabled : true ,
bind : {
disabled : '{!online}' ,
} ,
} ,
{
2021-03-08 14:52:06 +03:00
text : gettext ( 'Volume Statistics' ) ,
2021-03-08 12:06:07 +03:00
xtype : 'proxmoxButton' ,
handler : 'volumeStatistics' ,
iconCls : 'fa fa-line-chart' ,
disabled : true ,
bind : {
disabled : '{!online}' ,
} ,
} ,
2021-03-08 14:52:06 +03:00
{
text : gettext ( 'Cartridge Memory' ) ,
xtype : 'proxmoxButton' ,
iconCls : 'fa fa-hdd-o' ,
handler : 'cartridgeMemory' ,
disabled : true ,
bind : {
disabled : '{!online}' ,
} ,
} ,
2021-03-08 12:06:07 +03:00
2021-03-01 14:22:39 +03:00
] ,
items : [
{
xtype : 'container' ,
layout : {
type : 'hbox' ,
align : 'stretch' ,
} ,
defaults : {
padding : 5 ,
flex : 1 ,
} ,
items : [
{
xtype : 'pbsDriveInfoPanel' ,
cbind : {
drive : '{drive}' ,
} ,
} ,
{
xtype : 'pbsDriveStatusGrid' ,
reference : 'statusgrid' ,
cbind : {
url : '{driveStatusUrl}' ,
} ,
} ,
] ,
} ,
] ,
} ) ;
Ext . define ( 'PBS.TapeManagement.DriveStatusGrid' , {
extend : 'Proxmox.grid.ObjectGrid' ,
alias : 'widget.pbsDriveStatusGrid' ,
title : gettext ( 'Status' ) ,
rows : {
2021-04-08 13:04:14 +03:00
'density' : {
required : true ,
header : gettext ( 'Tape Density' ) ,
} ,
2021-03-01 14:22:39 +03:00
'blocksize' : {
required : true ,
2021-03-28 14:04:17 +03:00
header : gettext ( 'Block Size' ) ,
2021-03-01 14:22:39 +03:00
renderer : function ( value ) {
if ( ! value ) {
return gettext ( 'Dynamic' ) ;
}
return ` ${ gettext ( 'Fixed' ) } - ${ Proxmox . Utils . format _size ( value ) } ` ;
} ,
} ,
2021-04-08 13:04:14 +03:00
'write-protect' : {
2021-03-01 14:22:39 +03:00
required : true ,
2021-04-08 13:04:14 +03:00
header : gettext ( 'Write Protect' ) ,
defaultValue : false ,
2021-04-08 14:39:20 +03:00
renderer : Proxmox . Utils . format _boolean ,
2021-03-01 14:22:39 +03:00
} ,
2021-04-08 13:04:14 +03:00
'compression' : {
required : true ,
header : gettext ( 'Compression' ) ,
2021-04-08 14:39:20 +03:00
renderer : Proxmox . Utils . format _boolean ,
2021-04-08 13:04:14 +03:00
} ,
'file-number' : {
2021-04-08 14:39:20 +03:00
header : gettext ( 'Tape Position' ) ,
renderer : function ( value , mD , r , rI , cI , store ) {
let me = this ;
let filenr = value ;
let rec = store . getById ( 'block-number' ) ;
if ( rec ) {
let blocknr = rec . data . value ;
return ` File ${ filenr } , Block ${ blocknr } ` ;
}
return ` File ${ filenr } ` ;
} ,
2021-04-08 13:04:14 +03:00
} ,
'block-number' : {
2021-04-08 14:39:20 +03:00
visible : false ,
2021-03-01 14:22:39 +03:00
} ,
'manufactured' : {
header : gettext ( 'Tape Manufacture Date' ) ,
renderer : function ( value ) {
if ( value ) {
2021-03-08 13:30:12 +03:00
return Ext . Date . format ( new Date ( value * 1000 ) , "Y-m-d" ) ;
2021-03-01 14:22:39 +03:00
}
return "" ;
} ,
} ,
'bytes-read' : {
header : gettext ( 'Tape Read' ) ,
renderer : Proxmox . Utils . format _size ,
} ,
'bytes-written' : {
header : gettext ( 'Tape Written' ) ,
renderer : Proxmox . Utils . format _size ,
} ,
2021-03-02 14:19:38 +03:00
'medium-passes' : {
header : gettext ( 'Tape Passes' ) ,
} ,
'medium-wearout' : {
header : gettext ( 'Tape Wearout' ) ,
2021-03-02 15:08:01 +03:00
renderer : function ( value ) {
if ( value !== undefined ) {
return ( value * 100 ) . toFixed ( 2 ) + "%" ;
}
return value ;
} ,
2021-03-02 14:19:38 +03:00
} ,
2021-04-08 14:39:20 +03:00
'alert-flags' : {
header : gettext ( 'Alert Flags' ) ,
} ,
2021-03-01 14:22:39 +03:00
} ,
} ) ;
Ext . define ( 'PBS.TapeManagement.DriveInfoPanel' , {
extend : 'Ext.panel.Panel' ,
alias : 'widget.pbsDriveInfoPanel' ,
title : gettext ( 'Information' ) ,
defaults : {
printBar : false ,
padding : 5 ,
} ,
bodyPadding : 15 ,
viewModel : {
2021-03-02 14:19:39 +03:00
data : {
drive : { } ,
} ,
formulas : {
driveState : function ( get ) {
let drive = get ( 'drive' ) ;
return PBS . Utils . renderDriveState ( drive . state , { } ) ;
} ,
} ,
2021-03-01 14:22:39 +03:00
} ,
items : [
{
xtype : 'pmxInfoWidget' ,
title : gettext ( 'Name' ) ,
bind : {
data : {
2021-03-02 14:19:39 +03:00
text : '{drive.name}' ,
2021-03-01 14:22:39 +03:00
} ,
} ,
} ,
{
xtype : 'pmxInfoWidget' ,
title : gettext ( 'Vendor' ) ,
bind : {
data : {
2021-03-02 14:19:39 +03:00
text : '{drive.vendor}' ,
2021-03-01 14:22:39 +03:00
} ,
} ,
} ,
{
xtype : 'pmxInfoWidget' ,
title : gettext ( 'Model' ) ,
bind : {
data : {
2021-03-02 14:19:39 +03:00
text : '{drive.model}' ,
2021-03-01 14:22:39 +03:00
} ,
} ,
} ,
{
xtype : 'pmxInfoWidget' ,
title : gettext ( 'Serial' ) ,
bind : {
data : {
2021-03-02 14:19:39 +03:00
text : '{drive.serial}' ,
2021-03-01 14:22:39 +03:00
} ,
} ,
} ,
{
xtype : 'pmxInfoWidget' ,
title : gettext ( 'Path' ) ,
bind : {
data : {
2021-03-02 14:19:39 +03:00
text : '{drive.path}' ,
} ,
} ,
} ,
{
xtype : 'pmxInfoWidget' ,
2021-03-15 15:01:46 +03:00
reference : 'statewidget' ,
2021-03-02 14:19:39 +03:00
title : gettext ( 'State' ) ,
bind : {
data : {
text : '{driveState}' ,
2021-03-01 14:22:39 +03:00
} ,
} ,
} ,
] ,
2021-03-15 15:01:46 +03:00
clickState : function ( e , t , eOpts ) {
let me = this ;
let vm = me . getViewModel ( ) ;
let drive = vm . get ( 'drive' ) ;
if ( t . classList . contains ( 'right-aligned' ) ) {
let upid = drive . state ;
if ( ! upid || ! upid . startsWith ( "UPID" ) ) {
return ;
}
Ext . create ( 'Proxmox.window.TaskViewer' , {
autoShow : true ,
upid ,
} ) ;
}
} ,
2021-03-02 14:19:39 +03:00
updateData : function ( store ) {
2021-03-01 14:22:39 +03:00
let me = this ;
2021-03-02 14:19:39 +03:00
if ( ! store ) {
return ;
}
let record = store . findRecord ( 'name' , me . drive , 0 , false , true , true ) ;
2021-03-01 14:22:39 +03:00
if ( ! record ) {
return ;
}
let vm = me . getViewModel ( ) ;
2021-03-02 14:19:39 +03:00
vm . set ( 'drive' , record . data ) ;
2021-03-17 13:47:32 +03:00
vm . notify ( ) ;
me . updatePointer ( ) ;
} ,
updatePointer : function ( ) {
let me = this ;
2021-03-15 15:01:46 +03:00
let stateWidget = me . down ( 'pmxInfoWidget[reference=statewidget]' ) ;
let stateEl = stateWidget . getEl ( ) ;
2021-03-17 13:47:32 +03:00
if ( ! stateEl ) {
setTimeout ( function ( ) {
me . updatePointer ( ) ;
} , 100 ) ;
return ;
}
let vm = me . getViewModel ( ) ;
let drive = vm . get ( 'drive' ) ;
if ( drive . state ) {
2021-03-15 15:01:46 +03:00
stateEl . addCls ( 'info-pointer' ) ;
} else {
stateEl . removeCls ( 'info-pointer' ) ;
}
2021-03-17 13:47:32 +03:00
} ,
2021-03-15 15:01:46 +03:00
2021-03-17 13:47:32 +03:00
listeners : {
afterrender : function ( ) {
let me = this ;
let stateWidget = me . down ( 'pmxInfoWidget[reference=statewidget]' ) ;
let stateEl = stateWidget . getEl ( ) ;
stateEl . on ( 'click' , me . clickState , me ) ;
} ,
2021-03-01 14:22:39 +03:00
} ,
initComponent : function ( ) {
let me = this ;
if ( ! me . drive ) {
throw "no drive given" ;
}
2021-03-17 13:47:32 +03:00
me . callParent ( ) ;
2021-04-12 13:34:26 +03:00
let tapeStore = Ext . ComponentQuery . query ( 'navigationtree' ) [ 0 ] . tapeStore ;
2021-03-02 14:19:39 +03:00
me . mon ( tapeStore , 'load' , me . updateData , me ) ;
if ( tapeStore . isLoaded ( ) ) {
me . updateData ( tapeStore ) ;
2021-03-01 14:22:39 +03:00
}
} ,
} ) ;