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

Make the work profile the default one when adding Contacts #1307

Merged
merged 6 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
14 changes: 12 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
// use OCP\IInitialStateService;
use OCP\IConfig;
use OCP\L10N\IFactory;
use OCP\IRequest;

Expand All @@ -38,16 +39,20 @@ class PageController extends Controller {

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

public function __construct(string $AppName,
IRequest $request,
IConfig $config,
GretaD marked this conversation as resolved.
Show resolved Hide resolved
// IInitialStateService $initialStateService,
IFactory $languageFactory) {
parent::__construct($AppName, $request);

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

/**
Expand All @@ -58,8 +63,13 @@ public function __construct(string $AppName,
*/
public function index(): TemplateResponse {
$locales = $this->languageFactory->findAvailableLocales();
$defaultProfile = $this->config->getAppValue($this->appName, 'defaultProfile', 'HOME');
// 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
// $this->initialStateService->provideInitialState($this->appName, 'defaultProfile', $defaultProfile);
return new TemplateResponse(
'contacts',
'main',
['locales' => json_encode($locales), 'defaultProfile'=> json_encode($defaultProfile)]); // templates/main.php
}
}
10 changes: 6 additions & 4 deletions src/models/rfcProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import ActionCopyNtoFN from '../components/Actions/ActionCopyNtoFN'
import ActionToggleYear from '../components/Actions/ActionToggleYear'
import zones from './zones'

// Load the default profile (for example, home or work) configured by the user
const defaultProfileState = loadState('contacts', 'defaultProfile')
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
const localesState = loadState('contacts', 'locales')
const locales = localesState
? localesState.map(({ code, name }) => ({
Expand Down Expand Up @@ -83,7 +85,7 @@ const properties = {
force: 'text',
defaultValue: {
value: [''],
type: ['HOME']
type: [defaultProfileState]
},
options: [
{ id: 'HOME', name: t('contacts', 'Home') },
Expand All @@ -108,7 +110,7 @@ const properties = {
default: true,
defaultValue: {
value: ['', '', '', '', '', '', ''],
type: ['HOME']
type: [defaultProfileState]
},
options: [
{ id: 'HOME', name: t('contacts', 'Home') },
Expand Down Expand Up @@ -151,7 +153,7 @@ const properties = {
default: true,
defaultValue: {
value: '',
type: ['HOME']
type: [defaultProfileState]
},
options: [
{ id: 'HOME', name: t('contacts', 'Home') },
Expand Down Expand Up @@ -182,7 +184,7 @@ const properties = {
default: true,
defaultValue: {
value: '',
type: ['HOME', 'VOICE']
type: [defaultProfileState]
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
},
options: [
{ id: 'HOME,VOICE', name: t('contacts', 'Home') },
Expand Down
3 changes: 2 additions & 1 deletion templates/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
?>

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

<?php } else { ?>
<div id="app-content">
Expand All @@ -15,4 +16,4 @@
</div>
</div>

<?php } ?>
<?php } ?>
7 changes: 7 additions & 0 deletions tests/unit/Controller/PageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace OCA\Contacts\Controller;

use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
// use OCP\IInitialStateService;
use OCP\IRequest;
Expand All @@ -43,19 +44,25 @@ class PageControllerTest extends TestCase {

/** @var IFactory|MockObject */
private $languageFactory;
/** @var IConfig|MockObject*/
private $config;


public function setUp() {
parent::setUp();

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

$this->controller = new PageController(
'contacts',
$this->request,
// $this->initialStateService,
$this->config,
$this->languageFactory

);
}

Expand Down