[icinga-checkins] icinga.org: icinga-web/jmosshammer/default: * Working stage final

git at icinga.org git at icinga.org
Mon Jul 4 12:54:50 CEST 2011


Module: icinga-web
Branch: jmosshammer/default
Commit: 37db20f458a06b794c2fb6b71fd0b3ee92c98686
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=37db20f458a06b794c2fb6b71fd0b3ee92c98686

Author: Marius Hein <marius.hein at netways.de>
Date:   Fri Jul  1 12:41:33 2011 +0200

* Working stage final

---

 .../actions/Report/GenerateAction.class.php        |   39 ++++++----
 .../lib/js/Icinga.Reporting.util.RunReportPanel.js |   39 +++++++++-
 .../models/FieldValueConverterModel.class.php      |   79 ++++++++++++++++++++
 pub/styles/icinga.css                              |   10 +++
 4 files changed, 148 insertions(+), 19 deletions(-)

diff --git a/app/modules/Reporting/actions/Report/GenerateAction.class.php b/app/modules/Reporting/actions/Report/GenerateAction.class.php
index baeb85b..f56ea25 100644
--- a/app/modules/Reporting/actions/Report/GenerateAction.class.php
+++ b/app/modules/Reporting/actions/Report/GenerateAction.class.php
@@ -12,7 +12,6 @@ class Reporting_Report_GenerateAction extends ReportingBaseAction {
     public function executeWrite(AgaviParameterHolder $rd) {
         
         $data = (array)json_decode($rd->getParameter('data', ""));
-        unset($data['_output_format']);
         
         $factory = $this->getContext()->getModel('JasperSoapFactory', 'Reporting', array (
             'jasperconfig' => $rd->getParameter('jasperconfig')
@@ -20,23 +19,29 @@ class Reporting_Report_GenerateAction extends ReportingBaseAction {
         
         $client = $factory->getSoapClientForWSDL(Reporting_JasperSoapFactoryModel::SERVICE_REPOSITORY);
         
-        $parameters = $this->getContext()->getModel('JasperParameterStruct', 'Reporting', array (
-        	        'client'    => $client,
-        	        'uri'       => $rd->getParameter('uri'),
-        	        'filter'	=> 'reportUnit' 
-        ));
-        
-        $reports = $parameters->getObjects();
-        
-        $creator = $this->getContext()->getModel('ReportGenerator', 'Reporting', array(
-            'client' => $client,
-            'report' => $reports[0],
-            'format' => $rd->getParameter('output_type'),
-            'parameters' => $data
-        ));
-        
-        
         try {
+        
+            $parameters = $this->getContext()->getModel('JasperParameterStruct', 'Reporting', array (
+                'client'    => $client,
+                'uri'       => $rd->getParameter('uri'),
+                'filter'	=> 'reportUnit' 
+            ));
+            
+            $reports = $parameters->getObjects();
+            
+            $converter = $this->getContext()->getModel('FieldValueConverter', 'Reporting', array (
+                'client'	   => $client,
+                'uri'		   => $rd->getParameter('uri'),
+                'parameters'   => $data
+            ));
+            
+            $creator = $this->getContext()->getModel('ReportGenerator', 'Reporting', array(
+                'client' => $client,
+                'report' => $reports[0],
+                'format' => $rd->getParameter('output_type'),
+                'parameters' => $converter->getConvertedParameters()
+            ));
+            
             $data = $creator->getReportData();
             
             $userFile = $this->getContext()->getModel('ReportUserFile', 'Reporting');
diff --git a/app/modules/Reporting/lib/js/Icinga.Reporting.util.RunReportPanel.js b/app/modules/Reporting/lib/js/Icinga.Reporting.util.RunReportPanel.js
index 2cf65c8..70e6713 100644
--- a/app/modules/Reporting/lib/js/Icinga.Reporting.util.RunReportPanel.js
+++ b/app/modules/Reporting/lib/js/Icinga.Reporting.util.RunReportPanel.js
@@ -18,6 +18,7 @@ Icinga.Reporting.util.RunReportPanel = Ext.extend(Ext.Panel, {
 	
 	constructor : function(config) {
 		Icinga.Reporting.util.RunReportPanel.superclass.constructor.call(this, config);
+		this.downloadUrl = String.format('{0}/modules/reporting/provider/reportdata', AppKit.util.Config.getBaseUrl());
 	},
 	
 	initComponent : function() {
@@ -106,6 +107,18 @@ Icinga.Reporting.util.RunReportPanel = Ext.extend(Ext.Panel, {
 			
 			this.submitButton = this.createSubmitButton(); 
 			
+			this.messagePanel = new Ext.Container({
+				border : false,
+				width : 356,
+				style : {
+					padding : '10px',
+					margin : '5px',
+					background : 'transparent'
+				}
+			});
+			
+			this.formPanel.add(this.messagePanel);
+			
 			this.formPanel.add({
 				type : 'container',
 				width : 356,
@@ -113,7 +126,7 @@ Icinga.Reporting.util.RunReportPanel = Ext.extend(Ext.Panel, {
 				style : {
 					background : 'transparent',
 					padding : '10px 10px 10px 10px',
-					margin: '10px'
+					margin: '5px'
 				},
 				items: this.submitButton
 			});
@@ -123,6 +136,19 @@ Icinga.Reporting.util.RunReportPanel = Ext.extend(Ext.Panel, {
 		this.doLayout();
 	},
 	
+	addMessage : function(html, cls) {
+		this.messagePanel.removeAll();
+		this.messagePanel.add({
+			xtype : 'container',
+			html : {
+				tag : 'span',
+				html : html,
+				cls : cls
+			}
+		});
+		this.messagePanel.doLayout();
+	},
+	
 	parseOutput : function(response, options) {
 		this.parameterData = Ext.util.JSON.decode(response.responseText);
 		
@@ -166,14 +192,22 @@ Icinga.Reporting.util.RunReportPanel = Ext.extend(Ext.Panel, {
 			success : function(form, action) {
 				this.startEmbeddedDownload();
 				submit.enable();
+				this.addMessage('Report was created.', 'icinga-message-success');
 			},
 			failure : function(form, action) {
 				if (action.failureType == "server") {
 					var data = Ext.util.JSON.decode(action.response.responseText);
 					if (!Ext.isEmpty(data.errors.message)) {
 						AppKit.notifyMessage(_('Jasperserver error'), data.errors.message);
+						this.addMessage(data.errors.message, 'icinga-message-error');
+					}
+					else {
+						this.addMessage(_('Some general error, please examine jasperserver logs'), 'icinga-message-error');
 					}
 				}
+				else {
+					this.addMessage(_('Please check your parameters'), 'icinga-message-error');
+				}
 				submit.enable();
 			}
 		});
@@ -181,13 +215,14 @@ Icinga.Reporting.util.RunReportPanel = Ext.extend(Ext.Panel, {
 		submit.on('click', function(b, e) {
 			this.form.doAction(this.formAction,{});
 			b.disable();
+			this.addMessage(_('Report is being generated . . .'), 'icinga-message-success');
 		}, this);
 		
 		return submit;
 	},
 	
 	startEmbeddedDownload : function() {
-		var dlUrl = String.format('{0}/modules/reporting/provider/reportdata', AppKit.util.Config.getBaseUrl());
+		var dlUrl = this.downloadUrl;
 		var eId = 'icinga-reporting-dl-iframe';
 		Ext.DomHelper.append(Ext.getBody(), {
 			tag : 'iframe',
diff --git a/app/modules/Reporting/models/FieldValueConverterModel.class.php b/app/modules/Reporting/models/FieldValueConverterModel.class.php
new file mode 100644
index 0000000..bf5ad0f
--- /dev/null
+++ b/app/modules/Reporting/models/FieldValueConverterModel.class.php
@@ -0,0 +1,79 @@
+<?php
+
+class Reporting_FieldValueConverterModel extends ReportingBaseModel {
+    
+    const TYPE_DATE = 2;
+    
+    /**
+     * @var SoapClient
+     */
+    private $__client = null;
+    
+    private $__uri = null;
+    
+    private $__p = array ();
+    
+    private $__inputControls = array ();
+    
+    public function initialize(AgaviContext $context, array $parameters = array()) {
+        parent::initialize($context, $parameters);
+        
+        $this->__client = $this->getParameter('client');
+        $this->__uri = $this->getParameter('uri');
+        $this->__p = $this->getParameter('parameters', array());
+        
+        if (!$this->__client instanceof SoapClient) {
+            throw new AppKitModelException('Model needs a SoapClient to work');
+        }
+        
+        if (!$this->__uri) {
+            throw new AppKitModelException('Model needs a reportUnit uri to work');
+        }
+        
+        
+        $this->buildSoapRequest($this->__uri);
+    }
+    
+    private function buildSoapRequest($uri) {
+        $request = new JasperRequestXmlDoc('get');
+        $request->setResourceDescriptor(JasperRequestXmlDoc::RES_URI, $uri);
+        $descriptors = new JasperResponseXmlDoc($this->__client->get($request->getSoapParameter()));
+        foreach ($descriptors as $rd) {
+            if ($rd->getResourceDescriptor()->getParameter(JasperResourceDescriptor::DESCRIPTOR_TYPE) == 'inputControl') {
+                $this->__inputControls[] = $rd;
+            }
+        }
+    }
+    
+    public function getConvertedParameters() {
+        $out = array ();
+        foreach ($this->__inputControls as $rd) {
+            $name = $rd->getResourceDescriptor()->getParameter(JasperResourceDescriptor::DESCRIPTOR_NAME);
+            if (array_key_exists($name, $this->__p)) {
+                $type = $rd->getProperties()->getParameter('PROP_INPUTCONTROL_TYPE');
+                $value = $this->__p[$name];
+                
+                switch ($type) {
+                    case self::TYPE_DATE:
+                        $value = $this->convertDate($value);
+                    break;
+                }
+                
+                $out[$name] = $value;
+            }
+        }
+        return $out;
+    }
+    
+    private function convertDate($value) {
+        $tstamp = strtotime($value);
+        if (is_numeric($tstamp) && $tstamp > 0) {
+            // Java unix epoch are milliseconds
+            return $tstamp*1000;
+        }
+        
+        throw new AppKitModelException('Could not convert '. $value. ' to unix epoch');
+    }
+}
+
+?>
\ No newline at end of file
diff --git a/pub/styles/icinga.css b/pub/styles/icinga.css
index b19a157..2bf3a8a 100644
--- a/pub/styles/icinga.css
+++ b/pub/styles/icinga.css
@@ -68,6 +68,16 @@ table {
 	-webkit-border-radius: 5px;
 }
 
+/** Message colors **/
+
+.icinga-message-success {
+	color: #00cc00;
+}
+
+.icinga-message-error {
+	color: #cc0000;
+}
+
 /** MISC **/
 
 div#icinga-portal-loading-mask {





More information about the icinga-checkins mailing list