From 104ae6093a0d13461bb8e0c8f59d7036aa8ccee2 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 21 May 2021 15:18:54 +0200 Subject: [PATCH] ui: tape: small code/style cleanups It was not actually bad, so they're quite opinionated to be honest, but at least xtypes props must go first and variable declaration should try to be as near as possible to the actual use as long as code stays sensible readable/short. Signed-off-by: Thomas Lamprecht --- www/tape/BackupOverview.js | 13 ++++++------- www/tape/window/TapeRestore.js | 33 +++++++++++++-------------------- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/www/tape/BackupOverview.js b/www/tape/BackupOverview.js index 9ab3a128..51a8c865 100644 --- a/www/tape/BackupOverview.js +++ b/www/tape/BackupOverview.js @@ -13,20 +13,19 @@ Ext.define('PBS.TapeManagement.BackupOverview', { me.reload(); }, }, - }).show(); + autoShow: true, + }); }, - restore: function(view, rI, cI, item, e, rec) { + restoreBackups: function(view, rI, cI, item, e, rec) { let me = this; let mediaset = rec.data.is_media_set ? rec.data.text : rec.data['media-set']; - let uuid = rec.data['media-set-uuid']; - let prefilter = rec.data.prefilter; Ext.create('PBS.TapeManagement.TapeRestoreWindow', { autoShow: true, + uuid: rec.data['media-set-uuid'], + prefilter: rec.data.prefilter, mediaset, - uuid, - prefilter, }); }, @@ -269,7 +268,7 @@ Ext.define('PBS.TapeManagement.BackupOverview', { xtype: 'actioncolumn', items: [ { - handler: 'restore', + handler: 'restoreBackups', tooltip: gettext('Restore'), getClass: (v, m, rec) => rec.data.restore ? 'fa fa-fw fa-undo' : 'pmx-hidden', isDisabled: (v, r, c, i, rec) => !rec.data.restore, diff --git a/www/tape/window/TapeRestore.js b/www/tape/window/TapeRestore.js index 85ebcb1b..5eca7510 100644 --- a/www/tape/window/TapeRestore.js +++ b/www/tape/window/TapeRestore.js @@ -34,11 +34,10 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', { let tabpanel = me.lookup('tabpanel'); let items = tabpanel.items; - let checkValidity = true; - let indexOfActiveTab = items.indexOf(tabpanel.getActiveTab()); let indexOfLastValidTab = 0; + let checkValidity = true; items.each((panel) => { if (checkValidity) { panel.setDisabled(false); @@ -168,8 +167,7 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', { setDataStores: function(datastores, initial) { let me = this; - // save all datastores on the first setting, and - // restore them if we selected all + // save all datastores on the first setting, and restore them if we selected all if (initial) { me.datastores = datastores; } else if (datastores.length === 0) { @@ -309,8 +307,7 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', { reference: 'snapshotGrid', name: 'snapshots', height: 322, - // will be shown/enabled on successful load - disabled: true, + disabled: true, // will be shown/enabled on successful load hidden: true, listeners: { change: 'updateDatastores', @@ -367,9 +364,9 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', { column2: [ { xtype: 'pbsDriveSelector', + name: 'drive', fieldLabel: gettext('Drive'), labelWidth: 120, - name: 'drive', }, { xtype: 'pbsDataStoreSelector', @@ -379,9 +376,7 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', { name: 'store', listeners: { change: function(field, value) { - let me = this; - let grid = me.up('window').lookup('mappingGrid'); - grid.setNeedStores(!value); + this.up('window').lookup('mappingGrid').setNeedStores(!value); }, }, }, @@ -389,16 +384,16 @@ Ext.define('PBS.TapeManagement.TapeRestoreWindow', { columnB: [ { + xtype: 'displayfield', + reference: 'mappingLabel', fieldLabel: gettext('Datastore Mapping'), labelWidth: 200, hidden: true, - reference: 'mappingLabel', - xtype: 'displayfield', }, { xtype: 'pbsDataStoreMappingField', - reference: 'mappingGrid', name: 'mapping', + reference: 'mappingGrid', height: 260, defaultBindProperty: 'value', hidden: true, @@ -424,9 +419,8 @@ Ext.define('PBS.TapeManagement.DataStoreMappingGrid', { getValue: function() { let me = this; let datastores = []; - me.getStore().each((rec) => { - let source = rec.data.source; - let target = rec.data.target; + me.getStore().each(rec => { + let { source, target } = rec.data; if (target && target !== "") { datastores.push(`${source}=${target}`); } @@ -463,7 +457,7 @@ Ext.define('PBS.TapeManagement.DataStoreMappingGrid', { if (me.getViewModel().get('needStores')) { error = true; - me.getStore().each((rec) => { + me.getStore().each(rec => { if (rec.data.target) { error = false; } @@ -489,9 +483,8 @@ Ext.define('PBS.TapeManagement.DataStoreMappingGrid', { setDataStores: function(datastores) { let me = this; - let store = me.getStore(); - let data = []; + let data = []; for (const datastore of datastores) { data.push({ source: datastore, @@ -499,7 +492,7 @@ Ext.define('PBS.TapeManagement.DataStoreMappingGrid', { }); } - store.setData(data); + me.getStore().setData(data); }, viewConfig: {