diff --git a/www/DataStoreConfig.js b/www/DataStoreConfig.js deleted file mode 100644 index 8aa3076c..00000000 --- a/www/DataStoreConfig.js +++ /dev/null @@ -1,166 +0,0 @@ -Ext.define('pbs-datastore-list', { - extend: 'Ext.data.Model', - fields: [ 'name', 'comment' ], - proxy: { - type: 'proxmox', - url: "/api2/json/admin/datastore" - }, - idProperty: 'store' -}); - -Ext.define('pbs-data-store-config', { - extend: 'Ext.data.Model', - fields: [ 'name', 'path', 'comment' ], - proxy: { - type: 'proxmox', - url: "/api2/json/config/datastore" - }, - idProperty: 'name' -}); - -Ext.define('PBS.DataStoreConfig', { - extend: 'Ext.grid.GridPanel', - alias: 'widget.pbsDataStoreConfig', - - title: gettext('Data Store Configuration'), - - initComponent : function() { - var me = this; - - var store = new Ext.data.Store({ - model: 'pbs-data-store-config', - sorters: 'name', - }); - - var reload = function() { - store.load(); - }; - - var sm = Ext.create('Ext.selection.RowModel', {}); - - var gc_btn = new Proxmox.button.Button({ - text: gettext('Start GC'), - disabled: true, - selModel: sm, - handler: function() { - var rec = sm.getSelection()[0]; - Proxmox.Utils.API2Request({ - url: '/admin/datastore/' + rec.data.name + '/gc', - method: 'POST', - failure: function(response) { - Ext.Msg.alert(gettext('Error'), response.htmlStatus); - }, - success: function(response, options) { - var upid = response.result.data; - - var win = Ext.create('Proxmox.window.TaskViewer', { - upid: upid - }); - win.show(); - } - }); - } - }); - - var tbar = [ - { - text: gettext('Create'), - handler: function() { - let win = Ext.create('PBS.DataStoreEdit', {}); - win.on('destroy', reload); - win.show(); - } - }, - '-', - gc_btn - //edit_btn, remove_btn - ]; - - Proxmox.Utils.monStoreErrors(me, store); - - Ext.apply(me, { - store: store, - selModel: sm, - tbar: tbar, - columns: [ - { - header: gettext('Name'), - sortable: true, - dataIndex: 'name', - flex: 1 - }, - { - header: gettext('Path'), - sortable: true, - dataIndex: 'path', - flex: 1 - }, - { - header: gettext('Comment'), - sortable: false, - dataIndex: 'comment', - renderer: Ext.String.htmlEncode, - flex: 2 - } - ], - listeners: { - activate: reload - } - }); - - me.callParent(); - - store.load(); - } -}); - -Ext.define('PBS.DataStoreInputPanel', { - extend: 'Proxmox.panel.InputPanel', - alias: 'widget.pbsDataStoreInputPanel', - - onGetValues: function(values) { - var me = this; - - return values; - }, - - column1: [ - { - xtype: 'textfield', - name: 'name', - allowBlank: false, - fieldLabel: gettext('Name'), - }, - ], - - column2: [ - { - xtype: 'textfield', - name: 'path', - allowBlank: false, - fieldLabel: gettext('Backing Path'), - emptyText: gettext('An absolute path'), - }, - ], - - columnB: [ - { - xtype: 'textfield', - name: 'comment', - fieldLabel: gettext('Comment'), - }, - ], -}); - -Ext.define('PBS.DataStoreEdit', { - extend: 'Proxmox.window.Edit', - - url: '/api2/extjs/config/datastore', - method: 'POST', - - subject: gettext('Datastore'), - isAdd: true, - items: [{ - xtype: 'pbsDataStoreInputPanel', - }], -}); diff --git a/www/Makefile b/www/Makefile index 8aa6f74c..0cbd223a 100644 --- a/www/Makefile +++ b/www/Makefile @@ -12,17 +12,18 @@ JSSRC= \ config/RemoteView.js \ config/ACLView.js \ config/SyncView.js \ + config/DataStoreConfig.js \ window/UserEdit.js \ window/RemoteEdit.js \ window/SyncJobEdit.js \ window/ACLEdit.js \ + window/DataStoreEdit.js \ Utils.js \ LoginView.js \ VersionInfo.js \ SystemConfiguration.js \ Subscription.js \ DataStorePrune.js \ - DataStoreConfig.js \ DataStoreStatistic.js \ DataStoreContent.js \ DataStorePanel.js \ diff --git a/www/config/DataStoreConfig.js b/www/config/DataStoreConfig.js new file mode 100644 index 00000000..c5f50c2b --- /dev/null +++ b/www/config/DataStoreConfig.js @@ -0,0 +1,125 @@ +Ext.define('pbs-datastore-list', { + extend: 'Ext.data.Model', + fields: [ 'name', 'comment' ], + proxy: { + type: 'proxmox', + url: "/api2/json/admin/datastore" + }, + idProperty: 'store' +}); + +Ext.define('pbs-data-store-config', { + extend: 'Ext.data.Model', + fields: [ 'name', 'path', 'comment' ], + proxy: { + type: 'proxmox', + url: "/api2/json/config/datastore" + }, + idProperty: 'name' +}); + +Ext.define('PBS.DataStoreConfig', { + extend: 'Ext.grid.GridPanel', + alias: 'widget.pbsDataStoreConfig', + + title: gettext('Data Store Configuration'), + + controller: { + xclass: 'Ext.app.ViewController', + + createDataStore: function() { + let me = this; + Ext.create('PBS.DataStoreEdit', { + listeners: { + destroy: function() { + me.reload(); + }, + }, + }).show(); + }, + + garbageCollect: function() { + let me = this; + let view = me.getView(); + let selection = view.getSelection(); + if (selection.length < 1) return; + + let name = encodeURIComponent(selection[0].data.name); + Proxmox.Utils.API2Request({ + url: `/admin/datastore/${name}/gc`, + method: 'POST', + failure: function(response) { + Ext.Msg.alert(gettext('Error'), response.htmlStatus); + }, + success: function(response, options) { + Ext.create('Proxmox.window.TaskViewer', { + upid: response.result.data, + }).show(); + }, + }); + }, + + reload: function() { this.getView().getStore().rstore.load(); }, + + init: function(view) { + Proxmox.Utils.monStoreErrors(view, view.getStore().rstore); + }, + }, + + store: { + type: 'diff', + autoDestroy: true, + autoDestroyRstore: true, + sorters: 'name', + rstore: { + type: 'update', + storeid: 'pbs-data-store-config', + model: 'pbs-data-store-config', + autoStart: true, + interval: 10000, + }, + }, + + tbar: [ + { + xtype: 'proxmoxButton', + selModel: false, + text: gettext('Create'), + handler: 'createDataStore', + }, + // edit/remove button + '-', + { + xtype: 'proxmoxButton', + text: gettext('Start GC'), + disabled: true, + handler: 'garbageCollect', + }, + ], + + columns: [ + { + header: gettext('Name'), + sortable: true, + dataIndex: 'name', + flex: 1, + }, + { + header: gettext('Path'), + sortable: true, + dataIndex: 'path', + flex: 1, + }, + { + header: gettext('Comment'), + sortable: false, + dataIndex: 'comment', + renderer: Ext.String.htmlEncode, + flex: 2, + }, + ], + + listeners: { + activate: 'reload', + }, +}); diff --git a/www/window/DataStoreEdit.js b/www/window/DataStoreEdit.js new file mode 100644 index 00000000..9bce935e --- /dev/null +++ b/www/window/DataStoreEdit.js @@ -0,0 +1,59 @@ +Ext.define('PBS.DataStoreEdit', { + extend: 'Proxmox.window.Edit', + alias: 'widget.pbsDataStoreEdit', + mixins: ['Proxmox.Mixin.CBind'], + + subject: gettext('Datastore'), + isAdd: true, + + cbindData: function(initialConfig) { + var me = this; + + let name = initialConfig.name; + let baseurl = '/api2/extjs/config/datastore'; + + me.isCreate = !name; + me.url = name ? baseurl + '/' + name : baseurl; + me.method = name ? 'PUT' : 'POST'; + me.autoLoad = !!name; + return {}; + }, + + items: [ + { + xtype: 'inputpanel', + column1: [ + { + xtype: 'pmxDisplayEditField', + cbind: { + editable: '{isCreate}', + }, + name: 'name', + allowBlank: false, + fieldLabel: gettext('Name'), + }, + ], + + column2: [ + { + xtype: 'pmxDisplayEditField', + cbind: { + editable: '{isCreate}', + }, + name: 'path', + allowBlank: false, + fieldLabel: gettext('Backing Path'), + emptyText: gettext('An absolute path'), + }, + ], + + columnB: [ + { + xtype: 'textfield', + name: 'comment', + fieldLabel: gettext('Comment'), + }, + ], + } + ], +});