Provide "server.css" URL in ThemingController response
Pull request #5429 made cached SCSS files depend on a hash of the base URL, so the "/css/core/server.css" file does no longer exist. The "server.css" URL must be known by the Theming app in order to update the stylesheets when previewing the changes to the theme, so the DataResponse from the controller now provides the full URL to the "server.css" file that has to be reloaded (if any). The "server.css" URL provided by the response will be taken into account by the JavaScript front-end in a following commit. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
parent
986dffdae4
commit
db52e861dd
|
@ -73,6 +73,8 @@ class ThemingController extends Controller {
|
||||||
private $appData;
|
private $appData;
|
||||||
/** @var SCSSCacher */
|
/** @var SCSSCacher */
|
||||||
private $scssCacher;
|
private $scssCacher;
|
||||||
|
/** @var IURLGenerator */
|
||||||
|
private $urlGenerator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ThemingController constructor.
|
* ThemingController constructor.
|
||||||
|
@ -87,6 +89,7 @@ class ThemingController extends Controller {
|
||||||
* @param ITempManager $tempManager
|
* @param ITempManager $tempManager
|
||||||
* @param IAppData $appData
|
* @param IAppData $appData
|
||||||
* @param SCSSCacher $scssCacher
|
* @param SCSSCacher $scssCacher
|
||||||
|
* @param IURLGenerator $urlGenerator
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$appName,
|
$appName,
|
||||||
|
@ -98,7 +101,8 @@ class ThemingController extends Controller {
|
||||||
IL10N $l,
|
IL10N $l,
|
||||||
ITempManager $tempManager,
|
ITempManager $tempManager,
|
||||||
IAppData $appData,
|
IAppData $appData,
|
||||||
SCSSCacher $scssCacher
|
SCSSCacher $scssCacher,
|
||||||
|
IURLGenerator $urlGenerator
|
||||||
) {
|
) {
|
||||||
parent::__construct($appName, $request);
|
parent::__construct($appName, $request);
|
||||||
|
|
||||||
|
@ -110,6 +114,7 @@ class ThemingController extends Controller {
|
||||||
$this->tempManager = $tempManager;
|
$this->tempManager = $tempManager;
|
||||||
$this->appData = $appData;
|
$this->appData = $appData;
|
||||||
$this->scssCacher = $scssCacher;
|
$this->scssCacher = $scssCacher;
|
||||||
|
$this->urlGenerator = $urlGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,7 +177,8 @@ class ThemingController extends Controller {
|
||||||
[
|
[
|
||||||
'data' =>
|
'data' =>
|
||||||
[
|
[
|
||||||
'message' => $this->l10n->t('Saved')
|
'message' => $this->l10n->t('Saved'),
|
||||||
|
'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss'))
|
||||||
],
|
],
|
||||||
'status' => 'success'
|
'status' => 'success'
|
||||||
]
|
]
|
||||||
|
@ -303,7 +309,8 @@ class ThemingController extends Controller {
|
||||||
'data' =>
|
'data' =>
|
||||||
[
|
[
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
'message' => $this->l10n->t('Saved')
|
'message' => $this->l10n->t('Saved'),
|
||||||
|
'serverCssUrl' => $this->urlGenerator->linkTo('', $this->scssCacher->getCachedSCSS('core', '/core/css/server.scss'))
|
||||||
],
|
],
|
||||||
'status' => 'success'
|
'status' => 'success'
|
||||||
]
|
]
|
||||||
|
|
|
@ -70,6 +70,8 @@ class ThemingControllerTest extends TestCase {
|
||||||
private $appData;
|
private $appData;
|
||||||
/** @var SCSSCacher */
|
/** @var SCSSCacher */
|
||||||
private $scssCacher;
|
private $scssCacher;
|
||||||
|
/** @var IURLGenerator */
|
||||||
|
private $urlGenerator;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->request = $this->createMock(IRequest::class);
|
$this->request = $this->createMock(IRequest::class);
|
||||||
|
@ -85,6 +87,7 @@ class ThemingControllerTest extends TestCase {
|
||||||
->willReturn(123);
|
->willReturn(123);
|
||||||
$this->tempManager = \OC::$server->getTempManager();
|
$this->tempManager = \OC::$server->getTempManager();
|
||||||
$this->scssCacher = $this->createMock(SCSSCacher::class);
|
$this->scssCacher = $this->createMock(SCSSCacher::class);
|
||||||
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||||
|
|
||||||
$this->themingController = new ThemingController(
|
$this->themingController = new ThemingController(
|
||||||
'theming',
|
'theming',
|
||||||
|
@ -96,7 +99,8 @@ class ThemingControllerTest extends TestCase {
|
||||||
$this->l10n,
|
$this->l10n,
|
||||||
$this->tempManager,
|
$this->tempManager,
|
||||||
$this->appData,
|
$this->appData,
|
||||||
$this->scssCacher
|
$this->scssCacher,
|
||||||
|
$this->urlGenerator
|
||||||
);
|
);
|
||||||
|
|
||||||
return parent::setUp();
|
return parent::setUp();
|
||||||
|
@ -129,12 +133,23 @@ class ThemingControllerTest extends TestCase {
|
||||||
->method('t')
|
->method('t')
|
||||||
->with($message)
|
->with($message)
|
||||||
->willReturn($message);
|
->willReturn($message);
|
||||||
|
$this->scssCacher
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getCachedSCSS')
|
||||||
|
->with('core', '/core/css/server.scss')
|
||||||
|
->willReturn('/core/css/someHash-server.scss');
|
||||||
|
$this->urlGenerator
|
||||||
|
->expects($this->once())
|
||||||
|
->method('linkTo')
|
||||||
|
->with('', '/core/css/someHash-server.scss')
|
||||||
|
->willReturn('/nextcloudWebroot/core/css/someHash-server.scss');
|
||||||
|
|
||||||
$expected = new DataResponse(
|
$expected = new DataResponse(
|
||||||
[
|
[
|
||||||
'data' =>
|
'data' =>
|
||||||
[
|
[
|
||||||
'message' => $message,
|
'message' => $message,
|
||||||
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
|
||||||
],
|
],
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
]
|
]
|
||||||
|
@ -448,6 +463,16 @@ class ThemingControllerTest extends TestCase {
|
||||||
->method('undo')
|
->method('undo')
|
||||||
->with('MySetting')
|
->with('MySetting')
|
||||||
->willReturn('MyValue');
|
->willReturn('MyValue');
|
||||||
|
$this->scssCacher
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getCachedSCSS')
|
||||||
|
->with('core', '/core/css/server.scss')
|
||||||
|
->willReturn('/core/css/someHash-server.scss');
|
||||||
|
$this->urlGenerator
|
||||||
|
->expects($this->once())
|
||||||
|
->method('linkTo')
|
||||||
|
->with('', '/core/css/someHash-server.scss')
|
||||||
|
->willReturn('/nextcloudWebroot/core/css/someHash-server.scss');
|
||||||
|
|
||||||
$expected = new DataResponse(
|
$expected = new DataResponse(
|
||||||
[
|
[
|
||||||
|
@ -455,6 +480,7 @@ class ThemingControllerTest extends TestCase {
|
||||||
[
|
[
|
||||||
'value' => 'MyValue',
|
'value' => 'MyValue',
|
||||||
'message' => 'Saved',
|
'message' => 'Saved',
|
||||||
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
|
||||||
],
|
],
|
||||||
'status' => 'success'
|
'status' => 'success'
|
||||||
]
|
]
|
||||||
|
@ -481,6 +507,16 @@ class ThemingControllerTest extends TestCase {
|
||||||
->method('undo')
|
->method('undo')
|
||||||
->with($value)
|
->with($value)
|
||||||
->willReturn($value);
|
->willReturn($value);
|
||||||
|
$this->scssCacher
|
||||||
|
->expects($this->once())
|
||||||
|
->method('getCachedSCSS')
|
||||||
|
->with('core', '/core/css/server.scss')
|
||||||
|
->willReturn('/core/css/someHash-server.scss');
|
||||||
|
$this->urlGenerator
|
||||||
|
->expects($this->once())
|
||||||
|
->method('linkTo')
|
||||||
|
->with('', '/core/css/someHash-server.scss')
|
||||||
|
->willReturn('/nextcloudWebroot/core/css/someHash-server.scss');
|
||||||
$folder = $this->createMock(ISimpleFolder::class);
|
$folder = $this->createMock(ISimpleFolder::class);
|
||||||
$file = $this->createMock(ISimpleFile::class);
|
$file = $this->createMock(ISimpleFile::class);
|
||||||
$this->appData
|
$this->appData
|
||||||
|
@ -503,6 +539,7 @@ class ThemingControllerTest extends TestCase {
|
||||||
[
|
[
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
'message' => 'Saved',
|
'message' => 'Saved',
|
||||||
|
'serverCssUrl' => '/nextcloudWebroot/core/css/someHash-server.scss',
|
||||||
],
|
],
|
||||||
'status' => 'success'
|
'status' => 'success'
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue