Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement our own initialStateService for 15 #1291

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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