2021-07-16 15:17:23 +02:00
/ * T h i s s t a t e p r o v i d e r k e e p s p a r t o f t h e s t a t e i n s i d e t h e b r o w s e r h i s t o r y .
2015-04-20 06:06:28 +02:00
*
2021-07-16 15:17:23 +02:00
* We compress ( shorten ) url using dictionary based compression , i . e . , we use
* column separated list instead of url encoded hash :
* # v \ d * version / format
* : = indicates string values
* : \ d + lookup value in dictionary hash
* # v1 : = value1 : 5 : = value2 : = value3 : ...
2015-04-20 06:06:28 +02:00
* /
Ext . define ( 'PVE.StateProvider' , {
extend : 'Ext.state.LocalStorageProvider' ,
// private
setHV : function ( name , newvalue , fireEvents ) {
2021-05-17 16:45:00 +02:00
let me = this ;
2015-04-20 06:06:28 +02:00
2021-05-17 16:45:00 +02:00
let changes = false ;
let oldtext = Ext . encode ( me . UIState [ name ] ) ;
let newtext = Ext . encode ( newvalue ) ;
if ( newtext !== oldtext ) {
2015-04-20 06:06:28 +02:00
changes = true ;
me . UIState [ name ] = newvalue ;
if ( fireEvents ) {
me . fireEvent ( "statechange" , me , name , { value : newvalue } ) ;
}
}
return changes ;
} ,
// private
hslist : [
// order is important for notifications
// [ name, default ]
[ 'view' , 'server' ] ,
[ 'rid' , 'root' ] ,
[ 'ltab' , 'tasks' ] ,
[ 'nodetab' , '' ] ,
[ 'storagetab' , '' ] ,
2020-03-11 03:05:37 +01:00
[ 'sdntab' , '' ] ,
2015-04-20 06:06:28 +02:00
[ 'pooltab' , '' ] ,
[ 'kvmtab' , '' ] ,
2016-03-16 15:58:10 +01:00
[ 'lxctab' , '' ] ,
2021-01-19 17:31:03 +01:00
[ 'dctab' , '' ] ,
2015-04-20 06:06:28 +02:00
] ,
hprefix : 'v1' ,
compDict : {
2021-11-09 12:27:14 +01:00
tfa : 54 ,
2020-03-11 03:05:37 +01:00
sdn : 53 ,
2018-03-15 16:21:36 +01:00
cloudinit : 52 ,
2017-06-19 14:34:34 +02:00
replication : 51 ,
2016-08-22 17:13:36 +02:00
system : 50 ,
2016-04-01 13:10:57 +02:00
monitor : 49 ,
2016-03-16 15:58:10 +01:00
'ha-fencing' : 48 ,
'ha-groups' : 47 ,
'ha-resources' : 46 ,
'ceph-log' : 45 ,
2021-01-19 17:39:15 +01:00
'ceph-crushmap' : 44 ,
2016-03-16 15:58:10 +01:00
'ceph-pools' : 43 ,
'ceph-osdtree' : 42 ,
'ceph-disklist' : 41 ,
'ceph-monlist' : 40 ,
'ceph-config' : 39 ,
ceph : 38 ,
'firewall-fwlog' : 37 ,
'firewall-options' : 36 ,
'firewall-ipset' : 35 ,
'firewall-aliases' : 34 ,
'firewall-sg' : 33 ,
firewall : 32 ,
apt : 31 ,
members : 30 ,
2015-04-20 06:06:28 +02:00
snapshot : 29 ,
ha : 28 ,
support : 27 ,
2016-03-16 15:58:10 +01:00
pools : 26 ,
2015-04-20 06:06:28 +02:00
syslog : 25 ,
ubc : 24 ,
initlog : 23 ,
openvz : 22 ,
backup : 21 ,
2016-03-16 15:58:10 +01:00
resources : 20 ,
2015-04-20 06:06:28 +02:00
content : 19 ,
root : 18 ,
domains : 17 ,
roles : 16 ,
groups : 15 ,
users : 14 ,
time : 13 ,
dns : 12 ,
network : 11 ,
services : 10 ,
options : 9 ,
console : 8 ,
hardware : 7 ,
permissions : 6 ,
summary : 5 ,
tasks : 4 ,
clog : 3 ,
storage : 2 ,
folder : 1 ,
2021-01-19 17:31:03 +01:00
server : 0 ,
2015-04-20 06:06:28 +02:00
} ,
decodeHToken : function ( token ) {
2021-05-17 16:45:00 +02:00
let me = this ;
2015-04-20 06:06:28 +02:00
2021-05-17 16:45:00 +02:00
let state = { } ;
2015-04-20 06:06:28 +02:00
if ( ! token ) {
2021-05-17 16:45:00 +02:00
me . hslist . forEach ( ( [ k , v ] ) => { state [ k ] = v ; } ) ;
2015-04-20 06:06:28 +02:00
return state ;
}
2021-05-17 16:45:00 +02:00
let [ prefix , ... items ] = token . split ( ':' ) ;
2015-04-20 06:06:28 +02:00
2021-05-17 16:45:00 +02:00
if ( prefix !== me . hprefix ) {
2015-04-20 06:06:28 +02:00
return me . decodeHToken ( ) ;
}
Ext . Array . each ( me . hslist , function ( rec ) {
2021-05-17 16:45:00 +02:00
let value = items . shift ( ) ;
2015-04-20 06:06:28 +02:00
if ( value ) {
if ( value [ 0 ] === '=' ) {
value = decodeURIComponent ( value . slice ( 1 ) ) ;
2021-05-17 18:21:50 +02:00
}
for ( const [ key , hash ] of Object . entries ( me . compDict ) ) {
if ( String ( value ) === String ( hash ) ) {
value = key ;
break ;
2021-05-17 16:45:00 +02:00
}
2015-04-20 06:06:28 +02:00
}
}
state [ rec [ 0 ] ] = value ;
} ) ;
return state ;
} ,
encodeHToken : function ( state ) {
2021-05-17 16:45:00 +02:00
let me = this ;
2015-04-20 06:06:28 +02:00
2021-05-17 16:45:00 +02:00
let ctoken = me . hprefix ;
2015-04-20 06:06:28 +02:00
Ext . Array . each ( me . hslist , function ( rec ) {
2021-05-17 16:45:00 +02:00
let value = state [ rec [ 0 ] ] ;
2015-04-20 06:06:28 +02:00
if ( ! Ext . isDefined ( value ) ) {
value = rec [ 1 ] ;
}
value = encodeURIComponent ( value ) ;
if ( ! value ) {
ctoken += ':' ;
2021-05-17 16:45:00 +02:00
} else if ( Ext . isDefined ( me . compDict [ value ] ) ) {
ctoken += ":" + me . compDict [ value ] ;
2015-04-20 06:06:28 +02:00
} else {
2021-05-17 16:45:00 +02:00
ctoken += ":=" + value ;
2015-04-20 06:06:28 +02:00
}
} ) ;
return ctoken ;
} ,
2021-01-19 17:39:15 +01:00
constructor : function ( config ) {
2021-05-17 16:45:00 +02:00
let me = this ;
2015-04-20 06:06:28 +02:00
me . callParent ( [ config ] ) ;
me . UIState = me . decodeHToken ( ) ; // set default
2021-05-17 16:45:00 +02:00
let history _change _cb = function ( token ) {
2015-04-20 06:06:28 +02:00
if ( ! token ) {
2021-05-17 16:40:54 +02:00
Ext . History . back ( ) ;
2015-04-20 06:06:28 +02:00
return ;
}
2021-05-17 16:45:00 +02:00
let newstate = me . decodeHToken ( token ) ;
2015-04-20 06:06:28 +02:00
Ext . Array . each ( me . hslist , function ( rec ) {
2021-05-17 16:45:00 +02:00
if ( typeof newstate [ rec [ 0 ] ] === "undefined" ) {
2015-04-20 06:06:28 +02:00
return ;
}
me . setHV ( rec [ 0 ] , newstate [ rec [ 0 ] ] , true ) ;
} ) ;
} ;
2021-05-17 16:45:00 +02:00
let start _token = Ext . History . getToken ( ) ;
2015-04-20 06:06:28 +02:00
if ( start _token ) {
history _change _cb ( start _token ) ;
} else {
2021-05-17 16:45:00 +02:00
let htext = me . encodeHToken ( me . UIState ) ;
2015-04-20 06:06:28 +02:00
Ext . History . add ( htext ) ;
}
Ext . History . on ( 'change' , history _change _cb ) ;
} ,
2021-01-19 17:39:15 +01:00
get : function ( name , defaultValue ) {
2021-05-17 16:45:00 +02:00
let me = this ;
2015-04-20 06:06:28 +02:00
2021-05-17 16:45:00 +02:00
let data ;
if ( typeof me . UIState [ name ] !== "undefined" ) {
2015-04-20 06:06:28 +02:00
data = { value : me . UIState [ name ] } ;
} else {
data = me . callParent ( arguments ) ;
if ( ! data && name === 'GuiCap' ) {
2021-05-17 16:45:00 +02:00
data = {
vms : { } ,
storage : { } ,
access : { } ,
nodes : { } ,
dc : { } ,
sdn : { } ,
} ;
2015-04-20 06:06:28 +02:00
}
}
return data ;
} ,
2021-01-19 17:39:15 +01:00
clear : function ( name ) {
2021-05-17 16:45:00 +02:00
let me = this ;
2015-04-20 06:06:28 +02:00
2021-05-17 16:45:00 +02:00
if ( typeof me . UIState [ name ] !== "undefined" ) {
2015-04-20 06:06:28 +02:00
me . UIState [ name ] = null ;
}
me . callParent ( arguments ) ;
} ,
2021-01-19 17:39:15 +01:00
set : function ( name , value , fireevent ) {
2021-05-17 16:45:00 +02:00
let me = this ;
2015-04-20 06:06:28 +02:00
2021-05-17 16:45:00 +02:00
if ( typeof me . UIState [ name ] !== "undefined" ) {
2015-04-20 06:06:28 +02:00
var newvalue = value ? value . value : null ;
2019-05-27 14:13:55 +02:00
if ( me . setHV ( name , newvalue , fireevent ) ) {
2021-05-17 16:45:00 +02:00
let htext = me . encodeHToken ( me . UIState ) ;
2015-04-20 06:06:28 +02:00
Ext . History . add ( htext ) ;
}
} else {
me . callParent ( arguments ) ;
}
2021-01-19 17:31:03 +01:00
} ,
2015-04-20 06:06:28 +02:00
} ) ;