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' ,
leaf : true
} ,
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' ,
leaf : true
} ,
2020-05-20 12:15:37 +02:00
{
text : gettext ( 'Permissions' ) ,
iconCls : 'fa fa-unlock' ,
path : 'pbsACLView' ,
leaf : true
} ,
2020-04-29 11:09:35 +02:00
{
text : gettext ( 'Data Store' ) ,
iconCls : 'fa fa-archive' ,
path : 'pbsDataStoreConfig' ,
leaf : true
} ,
2019-01-22 11:48:00 +01:00
{
text : gettext ( 'Subscription' ) ,
iconCls : 'fa fa-support' ,
path : 'pbsSubscription' ,
leaf : true
}
]
} ,
{
text : gettext ( 'Administration' ) ,
iconCls : 'fa fa-wrench' ,
path : 'pbsServerAdministration' ,
leaf : true
}
]
}
} ) ;
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 ,
storeid : 'pbs-datastore-list' ,
2020-04-30 06:50:45 +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 ) {
var view = this . getView ( ) ;
let root = view . getStore ( ) . getRoot ( ) ;
2020-04-29 11:22:05 +02:00
if ( ! root . findChild ( 'path' , 'pbsDataStoreStatus' , false ) ) {
2019-12-20 12:46:09 +01:00
root . appendChild ( {
text : gettext ( 'Data Store' ) ,
expanded : true ,
iconCls : 'fa fa-archive' ,
2020-04-29 11:22:05 +02:00
path : 'pbsDataStoreStatus' ,
2019-12-20 12:46:09 +01:00
leaf : false
} ) ;
}
2020-05-25 19:46:43 +02:00
// FIXME: newly added always get appended to the end..
records . sort ( ( a , b ) => {
if ( a . id > b . id ) return 1 ;
if ( a . id < b . id ) return - 1 ;
return 0 ;
} ) ;
2020-04-29 11:22:05 +02:00
var list = root . findChild ( 'path' , 'pbsDataStoreStatus' , false ) ;
2019-12-20 12:46:09 +01:00
var length = records . length ;
var lookup _hash = { } ;
for ( var i = 0 ; i < length ; i ++ ) {
var name = records [ i ] . id ;
lookup _hash [ name ] = true ;
if ( ! list . findChild ( 'text' , name , false ) ) {
list . appendChild ( {
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' ,
2019-12-20 12:46:09 +01:00
leaf : true
} ) ;
}
}
var erase _list = [ ] ;
list . eachChild ( function ( node ) {
var name = node . data . text ;
if ( ! lookup _hash [ name ] ) {
erase _list . push ( node ) ;
}
} ) ;
Ext . Array . forEach ( erase _list , function ( node ) { node . erase ( ) ; } ) ;
}
} ,
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' ,
ui : 'nav'
} ) ;