2020-10-27 16:20:09 +01:00
Ext . define ( 'pbs-datastore-list' , {
extend : 'Ext.data.Model' ,
fields : [ 'name' , 'comment' ] ,
proxy : {
type : 'proxmox' ,
url : "/api2/json/admin/datastore" ,
} ,
idProperty : 'store' ,
} ) ;
2019-01-22 11:48:00 +01:00
Ext . define ( 'PBS.store.NavigationStore' , {
extend : 'Ext.data.TreeStore' ,
storeId : 'NavigationStore' ,
root : {
expanded : true ,
children : [
2019-12-18 17:29:05 +01:00
{
text : gettext ( 'Dashboard' ) ,
iconCls : 'fa fa-tachometer' ,
path : 'pbsDashboard' ,
2020-09-25 18:36:58 +02:00
leaf : true ,
2019-12-18 17:29:05 +01:00
} ,
2019-01-22 11:48:00 +01:00
{
text : gettext ( 'Configuration' ) ,
iconCls : 'fa fa-gears' ,
path : 'pbsSystemConfiguration' ,
expanded : true ,
children : [
2020-05-18 14:18:38 +02:00
{
text : gettext ( 'User Management' ) ,
iconCls : 'fa fa-user' ,
path : 'pbsUserView' ,
2020-09-25 18:36:58 +02:00
leaf : true ,
2020-05-18 14:18:38 +02:00
} ,
2020-05-20 12:15:37 +02:00
{
text : gettext ( 'Permissions' ) ,
iconCls : 'fa fa-unlock' ,
path : 'pbsACLView' ,
2020-09-25 18:36:58 +02:00
leaf : true ,
2020-05-20 12:15:37 +02:00
} ,
2020-05-26 12:23:25 +02:00
{
text : gettext ( 'Remotes' ) ,
iconCls : 'fa fa-server' ,
path : 'pbsRemoteView' ,
leaf : true ,
} ,
2019-01-22 11:48:00 +01:00
{
text : gettext ( 'Subscription' ) ,
iconCls : 'fa fa-support' ,
path : 'pbsSubscription' ,
2020-09-25 18:36:58 +02:00
leaf : true ,
} ,
] ,
2019-01-22 11:48:00 +01:00
} ,
{
text : gettext ( 'Administration' ) ,
iconCls : 'fa fa-wrench' ,
path : 'pbsServerAdministration' ,
2020-06-16 11:13:34 +02:00
expanded : true ,
leaf : false ,
children : [
{
text : gettext ( 'Disks' ) ,
iconCls : 'fa fa-hdd-o' ,
path : 'pmxDiskList' ,
leaf : false ,
children : [
{
text : Proxmox . Utils . directoryText ,
iconCls : 'fa fa-folder' ,
path : 'pbsDirectoryList' ,
leaf : true ,
} ,
2020-06-25 14:53:05 +02:00
{
text : "ZFS" ,
iconCls : 'fa fa-th-large' ,
path : 'pbsZFSList' ,
leaf : true ,
} ,
2020-09-25 18:36:58 +02:00
] ,
} ,
] ,
2020-06-05 10:11:51 +02:00
} ,
{
2020-07-02 17:20:38 +02:00
text : gettext ( 'Datastore' ) ,
2020-06-05 10:11:51 +02:00
iconCls : 'fa fa-archive' ,
2020-10-27 16:20:09 +01:00
id : 'datastores' ,
2020-06-05 10:11:51 +02:00
expanded : true ,
2020-10-27 16:20:09 +01:00
expandable : false ,
2020-09-25 18:36:58 +02:00
leaf : false ,
2020-10-27 16:20:09 +01:00
children : [
{
text : gettext ( 'Add Datastore' ) ,
iconCls : 'fa fa-plus-circle' ,
leaf : true ,
id : 'addbutton' ,
} ,
] ,
2020-06-05 10:11:51 +02:00
} ,
2020-09-25 18:36:58 +02:00
] ,
} ,
2019-01-22 11:48:00 +01:00
} ) ;
Ext . define ( 'PBS.view.main.NavigationTree' , {
extend : 'Ext.list.Tree' ,
xtype : 'navigationtree' ,
2019-12-20 12:46:09 +01:00
controller : {
xclass : 'Ext.app.ViewController' ,
init : function ( view ) {
view . rstore = Ext . create ( 'Proxmox.data.UpdateStore' , {
autoStart : true ,
interval : 15 * 1000 ,
2020-07-25 20:10:06 +02:00
storeId : 'pbs-datastore-list' ,
2019-12-20 12:46:09 +01:00
storeid : 'pbs-datastore-list' ,
2020-09-25 18:36:58 +02:00
model : 'pbs-datastore-list' ,
2019-12-20 12:46:09 +01:00
} ) ;
view . rstore . on ( 'load' , this . onLoad , this ) ;
view . on ( 'destroy' , view . rstore . stopUpdate ) ;
} ,
onLoad : function ( store , records , success ) {
2020-06-05 10:11:51 +02:00
if ( ! success ) return ;
2019-12-20 12:46:09 +01:00
var view = this . getView ( ) ;
let root = view . getStore ( ) . getRoot ( ) ;
2020-10-27 16:20:09 +01:00
records . sort ( ( a , b ) => a . id . localeCompare ( b . id ) ) ;
2020-05-25 19:46:43 +02:00
2020-10-27 16:20:09 +01:00
var list = root . findChild ( 'id' , 'datastores' , false ) ;
2019-12-20 12:46:09 +01:00
var length = records . length ;
var lookup _hash = { } ;
2020-10-27 16:20:09 +01:00
let j = 0 ;
for ( let i = 0 ; i < length ; i ++ ) {
2020-09-25 18:36:58 +02:00
let name = records [ i ] . id ;
2019-12-20 12:46:09 +01:00
lookup _hash [ name ] = true ;
2020-10-27 16:20:09 +01:00
while ( name . localeCompare ( list . getChildAt ( j ) . data . text ) > 0 &&
( j + 1 ) < list . childNodes . length ) {
j ++ ;
}
if ( list . getChildAt ( j ) . data . text . localeCompare ( name ) !== 0 ) {
list . insertChild ( j , {
2019-12-20 12:46:09 +01:00
text : name ,
2020-05-20 12:15:38 +02:00
path : ` DataStore- ${ name } ` ,
2019-12-21 09:15:57 +01:00
iconCls : 'fa fa-database' ,
2020-09-25 18:36:58 +02:00
leaf : true ,
2019-12-20 12:46:09 +01:00
} ) ;
}
}
var erase _list = [ ] ;
list . eachChild ( function ( node ) {
2020-09-25 18:36:58 +02:00
let name = node . data . text ;
2020-10-27 16:20:09 +01:00
if ( ! lookup _hash [ name ] && node . data . id !== 'addbutton' ) {
2019-12-20 12:46:09 +01:00
erase _list . push ( node ) ;
}
} ) ;
2020-10-27 16:20:09 +01:00
Ext . Array . forEach ( erase _list , function ( node ) { list . removeChild ( node , true ) ; } ) ;
} ,
} ,
listeners : {
itemclick : function ( tl , info ) {
if ( info . node . data . id === 'datastores' ) {
return false ;
}
if ( info . node . data . id === 'addbutton' ) {
let me = this ;
Ext . create ( 'PBS.DataStoreEdit' , {
listeners : {
destroy : function ( ) {
me . rstore . reload ( ) ;
} ,
} ,
} ) . show ( ) ;
return false ;
}
return true ;
2020-09-25 18:36:58 +02:00
} ,
2019-12-20 12:46:09 +01:00
} ,
2019-01-22 11:48:00 +01:00
select : function ( path ) {
var me = this ;
var item = me . getStore ( ) . findRecord ( 'path' , path , 0 , false , true , true ) ;
me . setSelection ( item ) ;
} ,
animation : false ,
expanderOnly : true ,
expanderFirst : false ,
store : 'NavigationStore' ,
2020-09-25 18:36:58 +02:00
ui : 'nav' ,
2019-01-22 11:48:00 +01:00
} ) ;