[icinga-checkins] icinga.org: icinga-web/jmosshammer/default: * Moved js action to squishloader action because of etag handling ( fixes #1813)

git at icinga.org git at icinga.org
Fri Aug 12 11:21:38 CEST 2011


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

Author: Marius Hein <marius.hein at netways.de>
Date:   Fri Aug 12 11:12:03 2011 +0200

* Moved js action to squishloader action because of etag handling (fixes #1813)

---

 .../actions/Widgets/SquishLoaderAction.class.php   |    4 +-
 app/modules/AppKit/config/javascript.xml           |    1 -
 .../models/SquishFileContainerModel.class.php      |   50 +++++++++++++++-----
 .../Widgets/SquishLoaderSuccessView.class.php      |   41 +++-------------
 4 files changed, 47 insertions(+), 49 deletions(-)

diff --git a/app/modules/AppKit/actions/Widgets/SquishLoaderAction.class.php b/app/modules/AppKit/actions/Widgets/SquishLoaderAction.class.php
index 5a06d17..eb92477 100644
--- a/app/modules/AppKit/actions/Widgets/SquishLoaderAction.class.php
+++ b/app/modules/AppKit/actions/Widgets/SquishLoaderAction.class.php
@@ -29,8 +29,8 @@ class AppKit_Widgets_SquishLoaderAction extends AppKitBaseAction {
                     $loader->addFiles(
                         $resources->getJavascriptFiles()
                     );
-
-                    $this->setAttribute('javascript_actions', $resources->getJavascriptActions());
+                    
+                    $loader->setActions($resources->getJavascriptActions());
 
                 } catch (AppKitModelException $e) {
                     $this->setAttribute('errors', $e->getMessage());
diff --git a/app/modules/AppKit/config/javascript.xml b/app/modules/AppKit/config/javascript.xml
index 1a899c6..32393e8 100644
--- a/app/modules/AppKit/config/javascript.xml
+++ b/app/modules/AppKit/config/javascript.xml
@@ -24,7 +24,6 @@
             <ae:parameter>%core.root_dir%/lib/jsgettext/lib/Gettext.js</ae:parameter>
         </javascript>
         
-        <!-- testtest -->
         <jactions>
         	<jaction>
         		<ae:parameter name="module">AppKit</ae:parameter>
diff --git a/app/modules/AppKit/models/SquishFileContainerModel.class.php b/app/modules/AppKit/models/SquishFileContainerModel.class.php
index 5ad2642..bd3aacf 100644
--- a/app/modules/AppKit/models/SquishFileContainerModel.class.php
+++ b/app/modules/AppKit/models/SquishFileContainerModel.class.php
@@ -91,28 +91,54 @@ class AppKit_SquishFileContainerModel extends AppKitBaseModel {
                 return true;
             }
         }
-
+        
+        if ($this->useCaching) {
+            $this->readCached();
+        }
+        
+        if ($this->content) {
+            return false;
+        }
+        
         $this->content = null;
-
+        
         if (is_array($this->files)) {
-            if ($this->useCaching) {
-                $this->readCached();
-            }
-
-            if ($this->content) {
-                return false;
-            }
+            
+            $this->content .= '// --- Squished files ---'. str_repeat(chr(10), 2);
 
             $loader = $this->getContext()->getModel('BulkLoader', 'AppKit', array(
                     'newlines' => false,
                     'indent' => false,
                     'comments' => false
-                                                    ));
+            ));
 
             $loader->setFiles($this->files);
-            $this->content = $loader->getContent();
+            
+            $this->content .= $loader->getContent(). str_repeat(chr(10), 2);
+        }
+        
+        if ($this->actions) {
+            
+            $this->content .= '// --- Squished actions ---'. str_repeat(chr(10), 2);
+            
+            foreach ($this->actions as $action) {
+                if (isset($action['module']) && isset($action['action'])) {
+                    
+                    $r = $this->getContext()->getController()->createExecutionContainer($action['module'], $action['action'], null, $action['output_type'])->execute();
+                    
+                    if ($r->hasContent()) {
+                        $this->content .= $r->getContent(). str_repeat(chr(10), 2);
+                    }
+                    
+                } else {
+                    throw new AppKitModelException('Content action to squish need module and action as parameter!');
+                }
+            }
+        }
+        
+        if ($this->content !== null) {
             $this->checksum = md5($this->content);
-
+            
             if ($this->useCaching) {
                 $this->cacheContent();
             }
diff --git a/app/modules/AppKit/views/Widgets/SquishLoaderSuccessView.class.php b/app/modules/AppKit/views/Widgets/SquishLoaderSuccessView.class.php
index 4c5eedc..6006c93 100644
--- a/app/modules/AppKit/views/Widgets/SquishLoaderSuccessView.class.php
+++ b/app/modules/AppKit/views/Widgets/SquishLoaderSuccessView.class.php
@@ -1,7 +1,7 @@
 <?php
 
 class AppKit_Widgets_SquishLoaderSuccessView extends AppKitBaseView {
-
+    
     public function executeJavascript(AgaviRequestDataHolder $rd) {
         if ($this->getAttribute('errors', false)) {
             return "throw '". join(", ", $this->getAttribute('errors')). "';";
@@ -10,20 +10,13 @@ class AppKit_Widgets_SquishLoaderSuccessView extends AppKitBaseView {
 
             $content .= 'AppKit.util.Config.add(\'path\', \''. AgaviConfig::get('org.icinga.appkit.web_path'). '\');'. chr(10);
             $content .= 'AppKit.util.Config.add(\'image_path\', \''. AgaviConfig::get('org.icinga.appkit.image_path'). '\');'. chr(10);
-
-            $content .= $this->executeActions(
-                            $this->getAttribute('javascript_actions',array())
-                        );
-
-
+            
             $etag = $this->getAttribute("etag",rand());
-
-
-
-            header('Cache-Control: private');
-            header('Pragma: ');
-            header('Expires: ');
-            header('ETag: "'.$etag.'"');
+            
+            $this->getResponse()->setHttpHeader('Cache-Control', 'private', true);
+            $this->getResponse()->setHttpHeader('Pragma', null, true);
+            $this->getResponse()->setHttpHeader('Expires', null, true);
+            $this->getResponse()->setHttpHeader('ETag', '"'. $etag. '"', true);
 
             if ($this->getAttribute('existsOnClient',false)) {
                 $this->getResponse()->setHttpStatusCode("304");
@@ -44,24 +37,4 @@ class AppKit_Widgets_SquishLoaderSuccessView extends AppKitBaseView {
         }
     }
 
-    private function executeActions(array $jactions = array()) {
-        $out = null;
-
-        foreach($jactions as $jaction) {
-
-            if (!isset($jaction['arguments'])) {
-                $jaction['arguments'] = array();
-            }
-
-            $r = $this->createForwardContainer($jaction['module'], $jaction['action'], $jaction['arguments'], $jaction['output_type'])
-                 ->execute();
-
-            if ($r->hasContent()) {
-                $out .= $r->getContent(). str_repeat(chr(10), 2);
-            }
-        }
-
-        return $out;
-    }
-
 }





More information about the icinga-checkins mailing list