Skip to content

Commit

Permalink
Implement our own initialStateService for 15
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Oct 3, 2019
1 parent c966aa0 commit a806e77
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
15 changes: 8 additions & 7 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@

use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IInitialStateService;
// use OCP\IInitialStateService;
use OCP\L10N\IFactory;
use OCP\IRequest;

class PageController extends Controller {

protected $appName;

/** @var IInitialStateService */
private $initialStateService;
// /** @var IInitialStateService */
// private $initialStateService;

/** @var IFactory */
private $languageFactory;

public function __construct(string $AppName,
IRequest $request,
IInitialStateService $initialStateService,
// IInitialStateService $initialStateService,
IFactory $languageFactory) {
parent::__construct($AppName, $request);

$this->appName = $AppName;
$this->initialStateService = $initialStateService;
// $this->initialStateService = $initialStateService;
$this->languageFactory = $languageFactory;
}

Expand All @@ -58,7 +58,8 @@ public function __construct(string $AppName,
*/
public function index(): TemplateResponse {
$locales = $this->languageFactory->findAvailableLocales();
$this->initialStateService->provideInitialState($this->appName, 'locales', $locales);
return new TemplateResponse('contacts', 'main'); // templates/main.php
// TODO: use initialStateService once min-version is 16!
// $this->initialStateService->provideInitialState($this->appName, 'locales', $locales);
return new TemplateResponse('contacts', 'main', ['locales' => json_encode($locales)]); // templates/main.php
}
}
5 changes: 4 additions & 1 deletion templates/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
if (!\OCP\Util::isIe()) {
script('contacts', 'contacts');
style('contacts', 'contacts');
} else {
?>

<input type="hidden" id="initial-state-contacts-locales" value="<?php p(base64_encode($_['locales'])); ?>">

<?php } else { ?>
<div id="app-content">
<div class="emptycontent">
<div class="icon-contacts-dark"></div>
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

use OCP\AppFramework\Http\TemplateResponse;
use PHPUnit\Framework\MockObject\MockObject;
use OCP\IInitialStateService;
// use OCP\IInitialStateService;
use OCP\IRequest;
use OCP\L10N\IFactory;
use ChristophWurst\Nextcloud\Testing\TestCase;
Expand All @@ -38,8 +38,8 @@ class PageControllerTest extends TestCase {
/** @var IRequest|MockObject */
private $request;

/** @var IInitialStateService|MockObject */
private $initialStateService;
// /** @var IInitialStateService|MockObject */
// private $initialStateService;

/** @var IFactory|MockObject */
private $languageFactory;
Expand All @@ -48,13 +48,13 @@ public function setUp() {
parent::setUp();

$this->request = $this->createMock(IRequest::class);
$this->initialStateService = $this->createMock(IInitialStateService::class);
// $this->initialStateService = $this->createMock(IInitialStateService::class);
$this->languageFactory = $this->createMock(IFactory::class);

$this->controller = new PageController(
'contacts',
$this->request,
$this->initialStateService,
// $this->initialStateService,
$this->languageFactory
);
}
Expand Down

0 comments on commit a806e77

Please sign in to comment.