2019-12-18 19:29:05 +03:00
Ext . define ( 'PBS.Dashboard' , {
extend : 'Ext.panel.Panel' ,
xtype : 'pbsDashboard' ,
controller : {
xclass : 'Ext.app.ViewController' ,
openDashboardOptions : function ( ) {
var me = this ;
var viewModel = me . getViewModel ( ) ;
Ext . create ( 'Ext.window.Window' , {
modal : true ,
width : 300 ,
title : gettext ( 'Dashboard Options' ) ,
layout : {
2020-09-25 19:29:42 +03:00
type : 'auto' ,
2019-12-18 19:29:05 +03:00
} ,
items : [ {
xtype : 'form' ,
bodyPadding : '10 10 10 10' ,
defaultButton : 'savebutton' ,
items : [ {
xtype : 'proxmoxintegerfield' ,
2020-10-06 13:25:25 +03:00
itemId : 'days' ,
2019-12-18 19:29:05 +03:00
labelWidth : 100 ,
anchor : '100%' ,
allowBlank : false ,
minValue : 1 ,
2020-10-06 13:25:25 +03:00
maxValue : 60 ,
value : viewModel . get ( 'days' ) ,
2020-10-06 16:15:18 +03:00
fieldLabel : gettext ( 'Days to show' ) ,
2019-12-18 19:29:05 +03:00
} ] ,
buttons : [ {
text : gettext ( 'Save' ) ,
2020-10-06 13:25:25 +03:00
reference : 'savebutton' ,
2019-12-18 19:29:05 +03:00
formBind : true ,
handler : function ( ) {
var win = this . up ( 'window' ) ;
2020-10-06 13:25:25 +03:00
var days = win . down ( '#days' ) . getValue ( ) ;
me . setDays ( days , true ) ;
2019-12-18 19:29:05 +03:00
win . close ( ) ;
2020-09-25 19:29:42 +03:00
} ,
} ] ,
} ] ,
2019-12-18 19:29:05 +03:00
} ) . show ( ) ;
} ,
2020-10-06 13:25:25 +03:00
setDays : function ( days , setState ) {
2019-12-18 19:29:05 +03:00
var me = this ;
var viewModel = me . getViewModel ( ) ;
2020-10-06 13:25:25 +03:00
viewModel . set ( 'days' , days ) ;
2019-12-18 19:29:05 +03:00
viewModel . notify ( ) ;
2020-10-06 13:25:25 +03:00
viewModel . getStore ( 'tasks' ) . reload ( ) ;
2019-12-18 19:29:05 +03:00
if ( setState ) {
var sp = Ext . state . Manager . getProvider ( ) ;
2020-10-06 13:25:25 +03:00
sp . set ( 'dashboard-days' , days ) ;
2019-12-18 19:29:05 +03:00
}
} ,
2021-07-09 15:44:16 +03:00
updateRepositoryStatus : function ( store , records , success ) {
if ( ! success ) { return ; }
let me = this ;
me . lookup ( 'nodeInfo' ) . setRepositoryInfo ( records [ 0 ] . data [ 'standard-repos' ] ) ;
} ,
2019-12-18 19:29:05 +03:00
updateSubscription : function ( store , records , success ) {
2020-06-12 14:34:07 +03:00
if ( ! success ) { return ; }
let me = this ;
2020-11-02 10:08:25 +03:00
let status = records [ 0 ] . data . status || 'unknown' ;
// 2 = all good, 1 = different leves, 0 = none
let subStatus = status . toLowerCase ( ) === 'active' ? 2 : 0 ;
2020-06-12 14:34:07 +03:00
me . lookup ( 'subscription' ) . setSubStatus ( subStatus ) ;
2021-07-09 15:44:16 +03:00
me . lookup ( 'nodeInfo' ) . setSubscriptionStatus ( subStatus ) ;
2019-12-18 19:29:05 +03:00
} ,
2020-06-12 14:34:06 +03:00
updateTasks : function ( store , records , success ) {
if ( ! success ) return ;
let me = this ;
2020-10-06 13:25:27 +03:00
let viewModel = me . getViewModel ( ) ;
2020-06-12 14:34:06 +03:00
records . sort ( ( a , b ) => a . data . duration - b . data . duration ) ;
let top10 = records . slice ( - 10 ) ;
me . lookup ( 'longesttasks' ) . updateTasks ( top10 ) ;
let data = {
2020-09-25 19:29:42 +03:00
backup : { error : 0 , warning : 0 , ok : 0 } ,
prune : { error : 0 , warning : 0 , ok : 0 } ,
garbage _collection : { error : 0 , warning : 0 , ok : 0 } ,
sync : { error : 0 , warning : 0 , ok : 0 } ,
2020-10-06 13:25:27 +03:00
verify : { error : 0 , warning : 0 , ok : 0 } ,
2020-06-12 14:34:06 +03:00
} ;
records . forEach ( record => {
2020-10-06 16:16:00 +03:00
let task = record . data ;
let type = task . worker _type ;
2020-06-12 14:34:06 +03:00
if ( type === 'syncjob' ) {
type = 'sync' ;
}
2021-02-03 16:15:57 +03:00
if ( type . startsWith ( 'verif' ) ) {
2020-10-06 13:25:27 +03:00
type = 'verify' ;
}
2020-10-06 16:16:00 +03:00
if ( data [ type ] && task . status ) {
let parsed = Proxmox . Utils . parse _task _status ( task . status ) ;
2020-06-12 14:34:06 +03:00
data [ type ] [ parsed ] ++ ;
}
} ) ;
2020-10-06 13:25:28 +03:00
me . lookup ( 'tasksummary' ) . updateTasks ( data , viewModel . get ( 'sinceEpoch' ) ) ;
2020-06-12 14:34:06 +03:00
} ,
2019-12-18 19:29:05 +03:00
init : function ( view ) {
var me = this ;
var sp = Ext . state . Manager . getProvider ( ) ;
2020-10-06 13:25:25 +03:00
var days = sp . get ( 'dashboard-days' ) || 30 ;
me . setDays ( days , false ) ;
2021-04-19 14:02:06 +03:00
view . mon ( sp , 'statechange' , function ( provider , key , value ) {
if ( key !== 'summarycolumns' ) {
return ;
}
Proxmox . Utils . updateColumns ( view ) ;
} ) ;
2020-09-25 19:29:42 +03:00
} ,
2019-12-18 19:29:05 +03:00
} ,
viewModel : {
data : {
2020-10-06 13:25:25 +03:00
days : 30 ,
2019-12-18 19:29:05 +03:00
} ,
2020-07-10 11:51:13 +03:00
formulas : {
2020-10-06 13:25:25 +03:00
sinceEpoch : ( get ) => ( Date . now ( ) / 1000 - get ( 'days' ) * 24 * 3600 ) . toFixed ( 0 ) ,
2020-07-10 11:51:13 +03:00
} ,
2019-12-18 19:29:05 +03:00
stores : {
2021-07-09 15:44:16 +03:00
repositories : {
storeid : 'dash-repositories' ,
type : 'update' ,
interval : 15000 ,
autoStart : true ,
autoLoad : true ,
autoDestroy : true ,
proxy : {
type : 'proxmox' ,
url : '/api2/json/nodes/localhost/apt/repositories' ,
} ,
listeners : {
load : 'updateRepositoryStatus' ,
} ,
} ,
2019-12-18 19:29:05 +03:00
subscription : {
storeid : 'dash-subscription' ,
type : 'update' ,
interval : 10000 ,
autoStart : true ,
autoLoad : true ,
autoDestroy : true ,
proxy : {
type : 'proxmox' ,
2020-09-25 19:29:42 +03:00
url : '/api2/json/nodes/localhost/subscription' ,
2019-12-18 19:29:05 +03:00
} ,
listeners : {
2020-09-25 19:29:42 +03:00
load : 'updateSubscription' ,
} ,
2019-12-18 19:29:05 +03:00
} ,
2020-06-12 14:34:06 +03:00
tasks : {
storeid : 'dash-tasks' ,
type : 'update' ,
interval : 15000 ,
autoStart : true ,
autoLoad : true ,
autoDestroy : true ,
model : 'proxmox-tasks' ,
proxy : {
type : 'proxmox' ,
2020-10-30 17:02:12 +03:00
url : '/api2/json/nodes/localhost/tasks' ,
2020-10-06 13:25:25 +03:00
extraParams : {
2020-10-30 17:02:12 +03:00
limit : 0 ,
2020-10-06 13:25:25 +03:00
since : '{sinceEpoch}' ,
} ,
2020-06-12 14:34:06 +03:00
} ,
listeners : {
2020-09-25 19:29:42 +03:00
load : 'updateTasks' ,
} ,
2020-06-12 14:34:06 +03:00
} ,
2020-09-25 19:29:42 +03:00
} ,
2019-12-18 19:29:05 +03:00
} ,
2021-04-19 14:02:06 +03:00
listeners : {
resize : function ( panel ) {
Proxmox . Utils . updateColumns ( panel ) ;
} ,
} ,
2020-10-06 13:25:25 +03:00
title : gettext ( 'Dashboard' ) ,
2019-12-18 19:29:05 +03:00
layout : {
2020-09-25 19:29:42 +03:00
type : 'column' ,
2019-12-18 19:29:05 +03:00
} ,
bodyPadding : '20 0 0 20' ,
2021-04-19 14:02:06 +03:00
minWidth : 700 ,
2019-12-18 19:29:05 +03:00
defaults : {
columnWidth : 0.49 ,
xtype : 'panel' ,
2020-09-25 19:29:42 +03:00
margin : '0 20 20 0' ,
2019-12-18 19:29:05 +03:00
} ,
2020-10-06 13:25:25 +03:00
tools : [
{
type : 'gear' ,
2020-10-06 16:15:43 +03:00
tooltip : gettext ( 'Edit dashboard settings' ) ,
2020-10-06 13:25:25 +03:00
handler : 'openDashboardOptions' ,
} ,
] ,
2019-12-18 19:29:05 +03:00
scrollable : true ,
items : [
{
2021-04-19 14:02:04 +03:00
xtype : 'pbsNodeInfoPanel' ,
2021-07-09 15:44:16 +03:00
reference : 'nodeInfo' ,
2021-04-19 14:02:05 +03:00
height : 280 ,
2019-12-18 19:29:05 +03:00
} ,
2020-06-09 11:01:14 +03:00
{
xtype : 'pbsDatastoresStatistics' ,
2021-04-19 14:02:05 +03:00
height : 280 ,
2020-06-09 11:01:14 +03:00
} ,
2019-12-18 19:29:05 +03:00
{
2020-06-12 14:34:06 +03:00
xtype : 'pbsLongestTasks' ,
2020-10-06 13:25:25 +03:00
bind : {
title : gettext ( 'Longest Tasks' ) + ' (' +
Ext . String . format ( gettext ( '{0} days' ) , '{days}' ) + ')' ,
} ,
2020-06-12 14:34:06 +03:00
reference : 'longesttasks' ,
2022-03-10 14:27:48 +03:00
height : 280 ,
2020-06-12 14:34:06 +03:00
} ,
{
xtype : 'pbsRunningTasks' ,
2022-03-10 14:27:48 +03:00
height : 280 ,
2020-06-12 14:34:06 +03:00
} ,
{
2020-10-06 13:25:25 +03:00
bind : {
title : gettext ( 'Task Summary' ) + ' (' +
Ext . String . format ( gettext ( '{0} days' ) , '{days}' ) + ')' ,
} ,
2020-06-12 14:34:06 +03:00
xtype : 'pbsTaskSummary' ,
2020-11-10 10:12:35 +03:00
height : 200 ,
2020-06-12 14:34:06 +03:00
reference : 'tasksummary' ,
} ,
{
iconCls : 'fa fa-ticket' ,
title : 'Subscription' ,
2020-11-10 10:12:35 +03:00
height : 200 ,
2020-06-12 14:34:06 +03:00
reference : 'subscription' ,
2020-06-12 14:34:07 +03:00
xtype : 'pbsSubscriptionInfo' ,
2019-12-18 19:29:05 +03:00
} ,
2020-09-25 19:29:42 +03:00
] ,
2019-12-18 19:29:05 +03:00
} ) ;
2020-06-12 14:34:07 +03:00
Ext . define ( 'PBS.dashboard.SubscriptionInfo' , {
2019-12-18 19:29:05 +03:00
extend : 'Ext.panel.Panel' ,
2020-06-12 14:34:07 +03:00
xtype : 'pbsSubscriptionInfo' ,
2019-12-18 19:29:05 +03:00
style : {
2020-09-25 19:29:42 +03:00
cursor : 'pointer' ,
2019-12-18 19:29:05 +03:00
} ,
2020-06-12 14:34:07 +03:00
layout : {
type : 'hbox' ,
align : 'middle' ,
} ,
items : [
{
xtype : 'box' ,
itemId : 'icon' ,
data : {
icon : 'question-circle' ,
} ,
width : 100 ,
tpl : '<center><i class="fa fa-3x fa-{icon}"></i></center>' ,
} ,
{
flex : 1 ,
xtype : 'box' ,
data : {
message : gettext ( 'Unknown' ) ,
} ,
itemId : 'message' ,
tpl : '<center>{message}</center>' ,
} ,
] ,
2019-12-18 19:29:05 +03:00
setSubStatus : function ( status ) {
var me = this ;
2020-06-12 14:34:07 +03:00
let icon = '' ;
let message = '' ;
2019-12-18 19:29:05 +03:00
switch ( status ) {
case 2 :
2020-06-12 14:34:07 +03:00
icon = 'check good' ;
message = gettext ( 'Your subscription status is valid.' ) ;
2019-12-18 19:29:05 +03:00
break ;
2019-12-18 21:21:59 +03:00
case 1 :
2020-06-12 14:34:07 +03:00
icon = 'exclamation-triangle warning' ;
message = gettext ( 'Warning: Your subscription levels are not the same.' ) ;
2019-12-18 19:29:05 +03:00
break ;
2019-12-18 21:21:59 +03:00
case 0 :
2020-06-12 14:34:07 +03:00
icon = 'times-circle critical' ;
2020-11-25 02:21:04 +03:00
message = ` <h1> ${ gettext ( 'No valid subscription' ) } </h1> ${ PBS . Utils . noSubKeyHtml } ` ;
2019-12-18 19:29:05 +03:00
break ;
default :
throw 'invalid subscription status' ;
}
2020-06-12 14:34:07 +03:00
me . getComponent ( 'icon' ) . update ( { icon } ) ;
me . getComponent ( 'message' ) . update ( { message } ) ;
2019-12-18 19:29:05 +03:00
} ,
listeners : {
click : {
element : 'body' ,
fn : function ( ) {
var mainview = this . component . up ( 'mainview' ) ;
2020-06-12 14:34:07 +03:00
mainview . getController ( ) . redirectTo ( 'pbsSubscription' ) ;
2020-09-25 19:29:42 +03:00
} ,
} ,
} ,
2019-12-18 19:29:05 +03:00
} ) ;