Skip to content

Commit

Permalink
Theming: Add OCA.Theming Js for app interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr committed Aug 10, 2016
1 parent ef17f8b commit 87df041
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/theming/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,15 @@
]
);

$linkToJs = \OC::$server->getURLGenerator()->linkToRoute(
'theming.Theming.getJavascript',
[
'v' => \OC::$server->getConfig()->getAppValue('theming', 'cachebuster', '0'),
]
);
\OCP\Util::addHeader(
'script',
[
'src' => $linkToJs,
], ''
);
5 changes: 5 additions & 0 deletions apps/theming/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@
'url' => '/loginbackground',
'verb' => 'GET',
],
[
'name' => 'Theming#getJavascript',
'url' => '/js/theming.js',
'verb' => 'GET',
],
]];

22 changes: 22 additions & 0 deletions apps/theming/lib/Controller/ThemingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,26 @@ public function getStylesheet() {
$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;
}
}
68 changes: 68 additions & 0 deletions apps/theming/tests/Controller/ThemingControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,4 +700,72 @@ public function testGetStylesheetWithAllCombinedInverted() {
$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());
}
}

0 comments on commit 87df041

Please sign in to comment.