]> source.dussan.org Git - nextcloud-server.git/commitdiff
Theming: Add OCA.Theming Js for app interaction 819/head
authorJulius Haertl <jus@bitgrid.net>
Wed, 10 Aug 2016 09:53:33 +0000 (11:53 +0200)
committerJulius Haertl <jus@bitgrid.net>
Wed, 10 Aug 2016 11:39:21 +0000 (13:39 +0200)
apps/theming/appinfo/app.php
apps/theming/appinfo/routes.php
apps/theming/lib/Controller/ThemingController.php
apps/theming/tests/Controller/ThemingControllerTest.php

index 5ef506e5acd2692d6d7652df68b3409829cd4b7e..051a2e279e59602720f2a9d4d1f9af5139e74b16 100644 (file)
@@ -39,3 +39,15 @@ $linkToCSS = \OC::$server->getURLGenerator()->linkToRoute(
        ]
 );
 
+$linkToJs = \OC::$server->getURLGenerator()->linkToRoute(
+       'theming.Theming.getJavascript',
+       [
+               'v' => \OC::$server->getConfig()->getAppValue('theming', 'cachebuster', '0'),
+       ]
+);
+\OCP\Util::addHeader(
+       'script',
+       [
+               'src' => $linkToJs,
+       ], ''
+);
index e062a68d69df898d0eeb0c3cc6aa7f84348f2e12..4a8d4bac5bcab6912642e4e2dbe81e572a11de26 100644 (file)
@@ -55,5 +55,10 @@ return ['routes' => [
                'url' => '/loginbackground',
                'verb' => 'GET',
        ],
+       [
+               'name' => 'Theming#getJavascript',
+               'url' => '/js/theming',
+               'verb' => 'GET',
+       ],
 ]];
 
index 07bbee4323d45d5e18c4f8789d67e61208515230..0db4dfe0627001365019b8c6c1c1793256b5b713 100644 (file)
@@ -337,4 +337,26 @@ class ThemingController extends Controller {
                $response->cacheFor(3600);
                return $response;
        }
+       /**
+        * @NoCSRFRequired
+        * @PublicPage
+        *
+        * @return DataDownloadResponse
+        */
+       public function getJavascript() {
+               $responseJS = '(function() {
+       OCA.Theming = {
+               name: ' . json_encode($this->template->getName()) . ',
+               url: ' . json_encode($this->template->getBaseUrl()) . ',
+               slogan: ' . json_encode($this->template->getSlogan()) . ',
+               color: ' . json_encode($this->template->getMailHeaderColor()) . ',
+               inverted: ' . json_encode($this->util->invertTextColor($this->template->getMailHeaderColor())) . ',
+       };
+})();';
+               $response = new Http\DataDisplayResponse($responseJS);
+               $response->addHeader("Content-type","text/javascript");
+               $response->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
+               $response->cacheFor(3600);
+               return $response;
+       }
 }
index 1129baafe449d94f2c767aba78bcb3faaa5eba8f..81b6b886c9fc5661ef9f36edf88fe7b181240afd 100644 (file)
@@ -700,4 +700,72 @@ class ThemingControllerTest extends TestCase {
                $expected->addHeader('Expires', date(\DateTime::RFC2822, 123));
                @$this->assertEquals($expected, $this->themingController->getStylesheet());
        }
+
+       public function testGetJavascript() {
+               $this->template
+                       ->expects($this->at(0))
+                       ->method('getName')
+                       ->willReturn("");
+               $this->template
+                       ->expects($this->at(1))
+                       ->method('getBaseUrl')
+                       ->willReturn("");
+               $this->template
+                       ->expects($this->at(2))
+                       ->method('getSlogan')
+                       ->willReturn("");
+               $this->template
+                       ->expects($this->at(3))
+                       ->method('getMailHeaderColor')
+                       ->willReturn("#000");
+
+
+               $expectedResponse = '(function() {
+       OCA.Theming = {
+               name: "",
+               url: "",
+               slogan: "",
+               color: "#000",
+               inverted: false,
+       };
+})();';
+               $expected = new Http\DataDisplayResponse($expectedResponse);
+               $expected->addHeader("Content-type","text/javascript");
+               $expected->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
+               $expected->cacheFor(3600);
+               @$this->assertEquals($expected, $this->themingController->getJavascript());
+       }
+       public function testGetJavascriptInverted() {
+               $this->template
+                       ->expects($this->at(0))
+                       ->method('getName')
+                       ->willReturn("Nextcloud");
+               $this->template
+                       ->expects($this->at(1))
+                       ->method('getBaseUrl')
+                       ->willReturn("nextcloudurl");
+               $this->template
+                       ->expects($this->at(2))
+                       ->method('getSlogan')
+                       ->willReturn("awesome");
+               $this->template
+                       ->expects($this->any())
+                       ->method('getMailHeaderColor')
+                       ->willReturn("#ffffff");
+
+               $expectedResponse = '(function() {
+       OCA.Theming = {
+               name: "Nextcloud",
+               url: "nextcloudurl",
+               slogan: "awesome",
+               color: "#ffffff",
+               inverted: true,
+       };
+})();';
+               $expected = new Http\DataDisplayResponse($expectedResponse);
+               $expected->addHeader("Content-type","text/javascript");
+               $expected->addHeader('Expires', date(\DateTime::RFC2822, $this->timeFactory->getTime()));
+               $expected->cacheFor(3600);
+               @$this->assertEquals($expected, $this->themingController->getJavascript());
+       }
 }