summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJulius Haertl <jus@bitgrid.net>2016-08-10 11:53:33 +0200
committerJulius Haertl <jus@bitgrid.net>2016-08-10 13:39:21 +0200
commit5f4e88ef6c6aa5e6768c0f3b1099f8d223607b00 (patch)
tree27046fca495b818949d9ec82d5d7367997c986b0 /apps
parentef17f8b3baf143b907ab4193f46221e39f84d381 (diff)
downloadnextcloud-server-5f4e88ef6c6aa5e6768c0f3b1099f8d223607b00.tar.gz
nextcloud-server-5f4e88ef6c6aa5e6768c0f3b1099f8d223607b00.zip
Theming: Add OCA.Theming Js for app interaction
Diffstat (limited to 'apps')
-rw-r--r--apps/theming/appinfo/app.php12
-rw-r--r--apps/theming/appinfo/routes.php5
-rw-r--r--apps/theming/lib/Controller/ThemingController.php22
-rw-r--r--apps/theming/tests/Controller/ThemingControllerTest.php68
4 files changed, 107 insertions, 0 deletions
diff --git a/apps/theming/appinfo/app.php b/apps/theming/appinfo/app.php
index 5ef506e5acd..051a2e279e5 100644
--- a/apps/theming/appinfo/app.php
+++ b/apps/theming/appinfo/app.php
@@ -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,
+ ], ''
+);
diff --git a/apps/theming/appinfo/routes.php b/apps/theming/appinfo/routes.php
index e062a68d69d..4a8d4bac5bc 100644
--- a/apps/theming/appinfo/routes.php
+++ b/apps/theming/appinfo/routes.php
@@ -55,5 +55,10 @@ return ['routes' => [
'url' => '/loginbackground',
'verb' => 'GET',
],
+ [
+ 'name' => 'Theming#getJavascript',
+ 'url' => '/js/theming',
+ 'verb' => 'GET',
+ ],
]];
diff --git a/apps/theming/lib/Controller/ThemingController.php b/apps/theming/lib/Controller/ThemingController.php
index 07bbee4323d..0db4dfe0627 100644
--- a/apps/theming/lib/Controller/ThemingController.php
+++ b/apps/theming/lib/Controller/ThemingController.php
@@ -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;
+ }
}
diff --git a/apps/theming/tests/Controller/ThemingControllerTest.php b/apps/theming/tests/Controller/ThemingControllerTest.php
index 1129baafe44..81b6b886c9f 100644
--- a/apps/theming/tests/Controller/ThemingControllerTest.php
+++ b/apps/theming/tests/Controller/ThemingControllerTest.php
@@ -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());
+ }
}