Browse Source

Moved netdata settings modal definition into own function

Removed duplication, each chart array now done in loop rather than explicitly
Henry Whitaker 6 years ago
parent
commit
7906939cd3
2 changed files with 131 additions and 534 deletions
  1. 1 534
      api/functions/homepage-functions.php
  2. 130 0
      api/functions/netdata-functions.php

+ 1 - 534
api/functions/homepage-functions.php

@@ -2983,540 +2983,7 @@ function getHomepageList()
 				),
 			)
 		),
-		array(
-			'name' => 'Netdata',
-			'enabled' => true,
-			'image' => 'plugins/images/tabs/netdata.png',
-			'category' => 'Monitor',
-			'settings' => array(
-				'Enable' => array(
-					array(
-						'type' => 'switch',
-						'name' => 'homepageNetdataEnabled',
-						'label' => 'Enable',
-						'value' => $GLOBALS['homepageNetdataEnabled']
-					),
-					array(
-						'type' => 'select',
-						'name' => 'homepageNetdataAuth',
-						'label' => 'Minimum Authentication',
-						'value' => $GLOBALS['homepageNetdataAuth'],
-						'options' => $groups
-					)
-				),
-				'Connection' => array(
-					array(
-						'type' => 'html',
-						'override' => 12,
-						'label' => 'Info',
-						'html' => 'The URL needs to be on the same domain as your Organizr, and be proxied by subdomain. E.g. If Organizr is accessed at: https://domain.com, then your URL for netdata should be: https://netdata.domain.com'
-					),
-					array(
-						'type' => 'input',
-						'name' => 'netdataURL',
-						'label' => 'URL',
-						'value' => $GLOBALS['netdataURL'],
-						'help' => 'Please enter the local IP:PORT of your netdata instance'
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-				),
-				'Chart 1' => array(
-					array(
-						'type' => 'switch',
-						'name' => 'netdata1Enabled',
-						'label' => 'Enable',
-						'value' => $GLOBALS['netdata1Enabled']
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'input',
-						'name' => 'netdata1Title',
-						'label' => 'Title',
-						'value' => $GLOBALS['netdata1Title'],
-						'help' => 'Title for the netdata graph'
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata1Data',
-						'label' => 'Data',
-						'value' => $GLOBALS['netdata1Data'],
-						'options' => netdataOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata1Chart',
-						'label' => 'Chart',
-						'value' => $GLOBALS['netdata1Chart'],
-						'options' => netdataChartOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata1Colour',
-						'label' => 'Colour',
-						'value' => $GLOBALS['netdata1Colour'],
-						'options' => netdataColourOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata1Size',
-						'label' => 'Size',
-						'value' => $GLOBALS['netdata1Size'],
-						'options' => netdataSizeOptions(),
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata1lg',
-						'label' => 'Show on large screens',
-						'value' => $GLOBALS['netdata1lg']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata1md',
-						'label' => 'Show on medium screens',
-						'value' => $GLOBALS['netdata1md']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata1sm',
-						'label' => 'Show on small screens',
-						'value' => $GLOBALS['netdata1sm']
-					),
-				),
-				'Chart 2' => array(
-					array(
-						'type' => 'switch',
-						'name' => 'netdata2Enabled',
-						'label' => 'Enable',
-						'value' => $GLOBALS['netdata2Enabled']
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'input',
-						'name' => 'netdata2Title',
-						'label' => 'Title',
-						'value' => $GLOBALS['netdata2Title'],
-						'help' => 'Title for the netdata graph'
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata2Data',
-						'label' => 'Data',
-						'value' => $GLOBALS['netdata2Data'],
-						'options' => netdataOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata2Chart',
-						'label' => 'Chart',
-						'value' => $GLOBALS['netdata2Chart'],
-						'options' => netdataChartOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata2Colour',
-						'label' => 'Colour',
-						'value' => $GLOBALS['netdata2Colour'],
-						'options' => netdataColourOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata2Size',
-						'label' => 'Size',
-						'value' => $GLOBALS['netdata2Size'],
-						'options' => netdataSizeOptions(),
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata2lg',
-						'label' => 'Show on large screens',
-						'value' => $GLOBALS['netdata2lg']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata2md',
-						'label' => 'Show on medium screens',
-						'value' => $GLOBALS['netdata2md']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata2sm',
-						'label' => 'Show on small screens',
-						'value' => $GLOBALS['netdata2sm']
-					),
-				),
-				'Chart 3' => array(
-					array(
-						'type' => 'switch',
-						'name' => 'netdata3Enabled',
-						'label' => 'Enable',
-						'value' => $GLOBALS['netdata3Enabled']
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'input',
-						'name' => 'netdata3Title',
-						'label' => 'Title',
-						'value' => $GLOBALS['netdata3Title'],
-						'help' => 'Title for the netdata graph'
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata3Data',
-						'label' => 'Data',
-						'value' => $GLOBALS['netdata3Data'],
-						'options' => netdataOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata3Chart',
-						'label' => 'Data',
-						'value' => $GLOBALS['netdata3Chart'],
-						'options' => netdataChartOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata3Colour',
-						'label' => 'Colour',
-						'value' => $GLOBALS['netdata3Colour'],
-						'options' => netdataColourOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata3Size',
-						'label' => 'Size',
-						'value' => $GLOBALS['netdata3Size'],
-						'options' => netdataSizeOptions(),
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata3lg',
-						'label' => 'Show on large screens',
-						'value' => $GLOBALS['netdata3lg']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata3md',
-						'label' => 'Show on medium screens',
-						'value' => $GLOBALS['netdata3md']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata3sm',
-						'label' => 'Show on small screens',
-						'value' => $GLOBALS['netdata3sm']
-					),
-				),
-				'Chart 4' => array(
-					array(
-						'type' => 'switch',
-						'name' => 'netdata4Enabled',
-						'label' => 'Enable',
-						'value' => $GLOBALS['netdata4Enabled']
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'input',
-						'name' => 'netdata4Title',
-						'label' => 'Title',
-						'value' => $GLOBALS['netdata4Title'],
-						'help' => 'Title for the netdata graph'
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata4Data',
-						'label' => 'Data',
-						'value' => $GLOBALS['netdata4Data'],
-						'options' => netdataOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata4Chart',
-						'label' => 'Chart',
-						'value' => $GLOBALS['netdata4Chart'],
-						'options' => netdataChartOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata4Colour',
-						'label' => 'Colour',
-						'value' => $GLOBALS['netdata4Colour'],
-						'options' => netdataColourOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata4Size',
-						'label' => 'Size',
-						'value' => $GLOBALS['netdata4Size'],
-						'options' => netdataSizeOptions(),
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata4lg',
-						'label' => 'Show on large screens',
-						'value' => $GLOBALS['netdata4lg']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata4md',
-						'label' => 'Show on medium screens',
-						'value' => $GLOBALS['netdata4md']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata4sm',
-						'label' => 'Show on small screens',
-						'value' => $GLOBALS['netdata4sm']
-					),
-				),
-				'Chart 5' => array(
-					array(
-						'type' => 'switch',
-						'name' => 'netdata5Enabled',
-						'label' => 'Enable',
-						'value' => $GLOBALS['netdata5Enabled']
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'input',
-						'name' => 'netdata5Title',
-						'label' => 'Title',
-						'value' => $GLOBALS['netdata5Title'],
-						'help' => 'Title for the netdata graph'
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata5Data',
-						'label' => 'Data',
-						'value' => $GLOBALS['netdata5Data'],
-						'options' => netdataOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata5Chart',
-						'label' => 'Chart',
-						'value' => $GLOBALS['netdata5Chart'],
-						'options' => netdataChartOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata5Colour',
-						'label' => 'Colour',
-						'value' => $GLOBALS['netdata5Colour'],
-						'options' => netdataColourOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata5Size',
-						'label' => 'Size',
-						'value' => $GLOBALS['netdata5Size'],
-						'options' => netdataSizeOptions(),
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata5lg',
-						'label' => 'Show on large screens',
-						'value' => $GLOBALS['netdata5lg']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata5md',
-						'label' => 'Show on medium screens',
-						'value' => $GLOBALS['netdata5md']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata5sm',
-						'label' => 'Show on small screens',
-						'value' => $GLOBALS['netdata5sm']
-					),
-				),
-				'Chart 6' => array(
-					array(
-						'type' => 'switch',
-						'name' => 'netdata6Enabled',
-						'label' => 'Enable',
-						'value' => $GLOBALS['netdata6Enabled']
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'input',
-						'name' => 'netdata6Title',
-						'label' => 'Title',
-						'value' => $GLOBALS['netdata6Title'],
-						'help' => 'Title for the netdata graph'
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata6Data',
-						'label' => 'Data',
-						'value' => $GLOBALS['netdata6Data'],
-						'options' => netdataOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata6Chart',
-						'label' => 'Chart',
-						'value' => $GLOBALS['netdata6Chart'],
-						'options' => netdataChartOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata6Colour',
-						'label' => 'Colour',
-						'value' => $GLOBALS['netdata6Colour'],
-						'options' => netdataColourOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata6Size',
-						'label' => 'Size',
-						'value' => $GLOBALS['netdata6Size'],
-						'options' => netdataSizeOptions(),
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata6lg',
-						'label' => 'Show on large screens',
-						'value' => $GLOBALS['netdata6lg']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata6md',
-						'label' => 'Show on medium screens',
-						'value' => $GLOBALS['netdata6md']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata6sm',
-						'label' => 'Show on small screens',
-						'value' => $GLOBALS['netdata6sm']
-					),
-				),
-				'Chart 7' => array(
-					array(
-						'type' => 'switch',
-						'name' => 'netdata7Enabled',
-						'label' => 'Enable',
-						'value' => $GLOBALS['netdata7Enabled']
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'input',
-						'name' => 'netdata7Title',
-						'label' => 'Title',
-						'value' => $GLOBALS['netdata7Title'],
-						'help' => 'Title for the netdata graph'
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata7Data',
-						'label' => 'Data',
-						'value' => $GLOBALS['netdata7Data'],
-						'options' => netdataOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata7Chart',
-						'label' => 'Chart',
-						'value' => $GLOBALS['netdata7Chart'],
-						'options' => netdataChartOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata7Colour',
-						'label' => 'Colour',
-						'value' => $GLOBALS['netdata7Colour'],
-						'options' => netdataColourOptions(),
-					),
-					array(
-						'type' => 'select',
-						'name' => 'netdata7Size',
-						'label' => 'Size',
-						'value' => $GLOBALS['netdata7Size'],
-						'options' => netdataSizeOptions(),
-					),
-					array(
-						'type' => 'blank',
-						'label' => ''
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata7lg',
-						'label' => 'Show on large screens',
-						'value' => $GLOBALS['netdata7lg']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata7md',
-						'label' => 'Show on medium screens',
-						'value' => $GLOBALS['netdata7md']
-					),
-					array(
-						'type' => 'switch',
-						'name' => 'netdata7sm',
-						'label' => 'Show on small screens',
-						'value' => $GLOBALS['netdata7sm']
-					),
-				),
-				'Options' => array(
-					array(
-						'type' => 'select',
-						'name' => 'homepageNetdataRefresh',
-						'label' => 'Refresh Seconds',
-						'value' => $GLOBALS['homepageNetdataRefresh'],
-						'options' => optionTime()
-					),
-				),
-			)
-		),
+		netdataSettngsArray()
 	);
 }
 

+ 130 - 0
api/functions/netdata-functions.php

@@ -1,5 +1,135 @@
 <?php
 
+function netdataSettngsArray()
+{
+    $array = array(
+        'name' => 'Netdata',
+        'enabled' => true,
+        'image' => 'plugins/images/tabs/netdata.png',
+        'category' => 'Monitor',
+        'settings' => array(
+            'Enable' => array(
+                array(
+                    'type' => 'switch',
+                    'name' => 'homepageNetdataEnabled',
+                    'label' => 'Enable',
+                    'value' => $GLOBALS['homepageNetdataEnabled']
+                ),
+                array(
+                    'type' => 'select',
+                    'name' => 'homepageNetdataAuth',
+                    'label' => 'Minimum Authentication',
+                    'value' => $GLOBALS['homepageNetdataAuth'],
+                    'options' => groupSelect()
+                )
+            ),
+            'Connection' => array(
+                array(
+                    'type' => 'html',
+                    'override' => 12,
+                    'label' => 'Info',
+                    'html' => 'The URL needs to be on the same domain as your Organizr, and be proxied by subdomain. E.g. If Organizr is accessed at: https://domain.com, then your URL for netdata should be: https://netdata.domain.com'
+                ),
+                array(
+                    'type' => 'input',
+                    'name' => 'netdataURL',
+                    'label' => 'URL',
+                    'value' => $GLOBALS['netdataURL'],
+                    'help' => 'Please enter the local IP:PORT of your netdata instance'
+                ),
+                array(
+                    'type' => 'blank',
+                    'label' => ''
+                ),
+            ),
+        )
+    );
+
+    for($i = 1; $i <= 7; $i++) {
+        $array['settings']['Chart '.$i] = array(
+            array(
+                'type' => 'switch',
+                'name' => 'netdata'.$i.'Enabled',
+                'label' => 'Enable',
+                'value' => $GLOBALS['netdata'.$i.'Enabled']
+            ),
+            array(
+                'type' => 'blank',
+                'label' => ''
+            ),
+            array(
+                'type' => 'input',
+                'name' => 'netdata'.$i.'Title',
+                'label' => 'Title',
+                'value' => $GLOBALS['netdata'.$i.'Title'],
+                'help' => 'Title for the netdata graph'
+            ),
+            array(
+                'type' => 'select',
+                'name' => 'netdata'.$i.'Data',
+                'label' => 'Data',
+                'value' => $GLOBALS['netdata'.$i.'Data'],
+                'options' => netdataOptions(),
+            ),
+            array(
+                'type' => 'select',
+                'name' => 'netdata'.$i.'Chart',
+                'label' => 'Chart',
+                'value' => $GLOBALS['netdata'.$i.'Chart'],
+                'options' => netdataChartOptions(),
+            ),
+            array(
+                'type' => 'select',
+                'name' => 'netdata'.$i.'Colour',
+                'label' => 'Colour',
+                'value' => $GLOBALS['netdata'.$i.'Colour'],
+                'options' => netdataColourOptions(),
+            ),
+            array(
+                'type' => 'select',
+                'name' => 'netdata'.$i.'Size',
+                'label' => 'Size',
+                'value' => $GLOBALS['netdata'.$i.'Size'],
+                'options' => netdataSizeOptions(),
+            ),
+            array(
+                'type' => 'blank',
+                'label' => ''
+            ),
+            array(
+                'type' => 'switch',
+                'name' => 'netdata'.$i.'lg',
+                'label' => 'Show on large screens',
+                'value' => $GLOBALS['netdata'.$i.'lg']
+            ),
+            array(
+                'type' => 'switch',
+                'name' => 'netdata'.$i.'md',
+                'label' => 'Show on medium screens',
+                'value' => $GLOBALS['netdata'.$i.'md']
+            ),
+            array(
+                'type' => 'switch',
+                'name' => 'netdata'.$i.'sm',
+                'label' => 'Show on small screens',
+                'value' => $GLOBALS['netdata'.$i.'sm']
+            ),
+        );
+    }
+
+    $array['settings']['Options'] =  array(
+        array(
+            'type' => 'select',
+            'name' => 'homepageNetdataRefresh',
+            'label' => 'Refresh Seconds',
+            'value' => $GLOBALS['homepageNetdataRefresh'],
+            'options' => optionTime()
+        ),
+    );
+
+    return $array;
+}
+
 function disk($dimension, $url)
 {
     $data = [];