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

Use new sentence design as default #2351

Closed
wants to merge 10 commits into from
13 changes: 7 additions & 6 deletions src/Controller/SentencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,17 @@ public function let_go($id)
private function renderAdopt($id)
{
$acceptsJson = $this->request->accepts('application/json');
$sentence = $this->Sentences->get($id, [
'contain' => ['Users' => ['fields' => ['username']]]
]);

if ($acceptsJson) {
$sentence = $this->Sentences->getSentenceWith($id);
$this->loadComponent('RequestHandler');
$this->set('user', $sentence->user);
$this->set('_serialize', ['user']);
$this->set('sentence', $sentence);
$this->set('_serialize', ['sentence']);
$this->RequestHandler->renderAs($this, 'json');
} else {
$sentence = $this->Sentences->get($id, [
'contain' => ['Users' => ['fields' => ['username']]]
]);
$this->set('sentenceId', $id);
$this->set('owner', $sentence->user);
$this->viewBuilder()->setLayout('ajax');
Expand Down Expand Up @@ -476,7 +477,7 @@ public function save_translation()
$numberOfTranslations = $this->request->getQuery('numberOfTranslations');
$includeTranslations = $translationLangFilter == 'und';
$sentence = $this->Sentences->getSentenceWith($sentenceId, ['translations' => $includeTranslations]);
$sentence->extraTranslationsCount = $numberOfTranslations + 1 - SentencesTable::MAX_TRANSLATIONS_DISPLAYED;
$sentence->extraTranslationsCount = $numberOfTranslations + 1 - $sentence->max_visible_translations;

$this->loadComponent('RequestHandler');
$this->set('sentence', $sentence);
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/SentencesListsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function show($id = null, $translationsLang = null)
$this->set('permissions', $list['Permissions']);
$this->set('sentencesInList', $sentencesInList);

if (!CurrentUser::isMember() || CurrentUser::getSetting('use_new_design')) {
if (!CurrentUser::isMember() || !CurrentUser::getSetting('disable_new_design')) {
$this->render('show_angular');
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/Model/Entity/Sentence.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Sentence extends Entity
'is_favorite',
'is_owned_by_current_user',
'permissions',
'max_visible_translations',
'current_user_review'
];

Expand Down Expand Up @@ -145,4 +146,13 @@ protected function _getCurrentUserReview()
}
return null;
}

protected function _getMaxVisibleTranslations()
{
if (CurrentUser::isMember() && (int)CurrentUser::getSetting('max_visible_translations') > 0) {
return CurrentUser::getSetting('max_visible_translations');
}

return 5;
}
}
5 changes: 4 additions & 1 deletion src/Model/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ class User extends Entity
'collapsible_translations' => false,
'show_transcriptions' => false,
'sentences_per_page' => 10,
'max_visible_translations' => 5,
'users_collections_ratings' => false,
'native_indicator' => false,
'hide_random_sentence' => false,
'use_new_design' => false,
'disable_new_design' => false,
'default_license' => 'CC BY 2.0 FR',
'can_switch_license' => false,
'new_terms_of_use' => '1',
'license_switch_list_id' => null,
'hide_new_design_announcement' => false,
'hide_new_design_announcement_2' => false,
);

private $settingsValidation = array(
'sentences_per_page' => array(10, 20, 50, 100),
'max_visible_translations' => array(5, 10, 20, 50),
);

protected function _setPassword($password) {
Expand Down
1 change: 0 additions & 1 deletion src/Model/Table/SentencesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class SentencesTable extends Table
{
const MIN_CORRECTNESS = -1;
const MAX_CORRECTNESS = 0;
const MAX_TRANSLATIONS_DISPLAYED = 5;

protected function _initializeSchema(TableSchema $schema)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Activities/adopt_sentences.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ $this->set('title_for_layout', $this->Pages->formatTitle($title));

$this->Pagination->display();

if (!CurrentUser::isMember() || CurrentUser::getSetting('use_new_design')) {
if (!CurrentUser::isMember() || !CurrentUser::getSetting('disable_new_design')) {
foreach ($results as $sentence) {
echo $this->element(
'sentences/sentence_and_translations',
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Activities/translate_sentences_of.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $this->set('title_for_layout', $this->Pages->formatTitle($title));
if ($results != null) {
$this->Pagination->display();

if (!CurrentUser::isMember() || CurrentUser::getSetting('use_new_design')) {
if (!CurrentUser::isMember() || !CurrentUser::getSetting('disable_new_design')) {
foreach ($results as $sentence) {
echo $this->element(
'sentences/sentence_and_translations',
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Element/sentences/expand_all_menus_button.ctp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
use App\Model\CurrentUser;

if (CurrentUser::getSetting('use_new_design')) { ?>
if (!CurrentUser::getSetting('disable_new_design')) { ?>
<span toggle-all-menus ng-cloak>
<md-button ng-if="!menu.expanded" class="md-icon-button" ng-click="menu.toggleAll()">
<md-icon>unfold_more</md-icon>
Expand Down
10 changes: 8 additions & 2 deletions src/Template/Element/sentences/sentence_and_translations.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ $sentenceUrl = $this->Url->build([
'controller' => 'sentences',
'action' => 'show'
]);

if (CurrentUser::isMember()) {
$headerLayout = "{{vm.isMenuExpanded ? 'column' : 'row'}}";
} else {
$headerLayout = "row";
}
?>
<div ng-cloak flex
sentence-and-translations
Expand All @@ -82,8 +88,8 @@ $sentenceUrl = $this->Url->build([
<div flex><?= $duplicateWarning ?></div>
</div>
<div layout="column">
<div layout="row" class="header">
<md-subheader flex class="ellipsis">
<div layout="<?= $headerLayout ?>" class="header">
<md-subheader flex class="ellipsis" flex-order="0">
<span ng-if="vm.sentence.user && vm.sentence.user.username">
<?php
echo format(
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Element/sentences/sentence_menu.ctp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="menu-wrapper" sentence-menu flex="{{vm.isMenuExpanded ? '100' : 'none'}}"
<div class="menu-wrapper" sentence-menu flex="{{vm.isMenuExpanded ? '100' : 'none'}}" flex-order="{{vm.isMenuExpanded ? -1 : 1}}"
ng-init="vm.initMenu(<?= (int)$expanded ?>, vm.sentence.permissions)">
<div class="menu" layout="row" layout-align="space-between center">
<div>
Expand Down
10 changes: 4 additions & 6 deletions src/Template/Pages/index.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,16 @@ $moreCommentsUrl = $this->Url->build([

<div id="main_content">
<?php
if (!CurrentUser::getSetting('use_new_design') && !CurrentUser::getSetting('hide_new_design_announcement')) {
if (!CurrentUser::getSetting('use_new_design') && !CurrentUser::getSetting('hide_new_design_announcement_2')) {
$this->Html->script('directives/info-banner.dir.js', ['block' => 'scriptBottom']);
?>
<div info-banner ng-init="vm.init('hide_new_design_announcement')" ng-cloak>
<div info-banner ng-init="vm.init('hide_new_design_announcement_2')" ng-cloak>
<div class="md-whiteframe-1dp" layout-padding style="background: #fafafa" ng-if="vm.isInfoBannerVisible">
<p><?= __(
'The new sentence design will soon completely replace the old one. Please try it out and let us know if you experience any issue. '.
'You can enable it with the option '.
'"Display sentences with the new design" in your Settings.'
'The new sentence design is now used by default. If you find any issue, please let us know on the Wall.'
) ?></p>
<div layout="row" layout-align="end center">
<md-button class="md-primary" href="/user/settings"><?= __('Go to settings') ?></md-button>
<md-button class="md-primary" href="/wall/index"><?= __('Go to the Wall') ?></md-button>
<?php /* @translators: button to close the announcement about the new design (verb) */ ?>
<md-button class="md-primary" ng-click="vm.hideAnnouncement(true)"><?= __('Close') ?></md-button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Sentences/add.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ $vocabularyUrl = $this->Url->build(array(
<div id="main_content">

<?php
if (CurrentUser::getSetting('use_new_design')) {
if (!CurrentUser::getSetting('disable_new_design')) {
echo $this->element('sentences/add_sentences_angular');
} else {
echo $this->element('sentences/add_sentences_jquery');
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Sentences/search.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ if (!isset($results)) {

$this->Pagination->display();

if (!CurrentUser::isMember() || CurrentUser::getSetting('use_new_design')) {
if (!CurrentUser::isMember() || !CurrentUser::getSetting('disable_new_design')) {
foreach ($results as $sentence) {
echo $this->element(
'sentences/sentence_and_translations',
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Sentences/show.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ echo $this->element('/sentences/navigation', [

<?php
if (isset($sentence)) {
if (CurrentUser::isMember() && !CurrentUser::getSetting('use_new_design')) {
if (CurrentUser::isMember() && !!CurrentUser::getSetting('disable_new_design')) {
?><div class="section md-whiteframe-1dp"><?php
$this->Sentences->displaySentencesGroup($sentence);
?></div><?php
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Sentences/show_all_in.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ $this->set('title_for_layout', $this->Pages->formatTitle($title));

$this->Pagination->display();

if (!CurrentUser::isMember() || CurrentUser::getSetting('use_new_design')) {
if (!CurrentUser::isMember() || !CurrentUser::getSetting('disable_new_design')) {
foreach ($results as $sentence) {
echo $this->element(
'sentences/sentence_and_translations',
Expand Down
2 changes: 1 addition & 1 deletion src/Template/Tags/show_sentences_with_tag.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ $tagsIndexUrl = $this->Url->build([
<div class="sentencesList" id="sentencesList">
<?php
$useNewDesign = !CurrentUser::isMember()
|| CurrentUser::getSetting('use_new_design');
|| !CurrentUser::getSetting('disable_new_design');
if ($useNewDesign) {
foreach ($allSentences as $item) {
$sentence = $item->sentence;
Expand Down
59 changes: 34 additions & 25 deletions src/Template/User/settings.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ $this->set('title_for_layout', $this->Pages->formatTitle(__('Settings')));
</div>
</md-list-item>

<md-list-item>
<md-list-item ng-show="disableNewDesign">
<?php $collapsibleTranslations = $userSettings->settings['collapsible_translations']; ?>
<md-checkbox
ng-false-value="0"
Expand Down Expand Up @@ -197,6 +197,30 @@ $this->set('title_for_layout', $this->Pages->formatTitle(__('Settings')));
</div>
</md-list-item>

<md-list-item>
<?php $disableNewDesign = $userSettings->settings['disable_new_design']; ?>
<md-checkbox
ng-false-value="1"
ng-true-value="0"
ng-model="disableNewDesign"
ng-init="disableNewDesign = <?= (int)$disableNewDesign ?>"
class="md-primary">
</md-checkbox>
<p><?php echo __(
'Display sentences with the new design'
) ?></p>
<div ng-hide="true">
<?php
echo $this->Form->input(
'settings.disable_new_design',
array(
'value' => '{{disableNewDesign}}'
)
);
?>
</div>
</md-list-item>

<md-list-item>
<?php
$sentencesByLanguageURL = $this->Url->build(
Expand Down Expand Up @@ -235,6 +259,15 @@ $this->set('title_for_layout', $this->Pages->formatTitle(__('Settings')));
'label' => ''
)); ?>
</md-list-item>

<md-list-item ng-show="!disableNewDesign">
<p><?= __('Number of translations visible by default'); ?></p>
<?php echo $this->Form->input('settings.max_visible_translations', [
'options' => [5 => 5, 10 => 10, 20 => 20, 50 => 50],
'label' => ''
]); ?>
</md-list-item>

<?php if ($userSettings->settings['can_switch_license']) : ?>
<md-list-item>
<p><?= __('Default license for original sentences'); ?></p>
Expand Down Expand Up @@ -311,30 +344,6 @@ $this->set('title_for_layout', $this->Pages->formatTitle(__('Settings')));
?>
</div>
</md-list-item>
<md-list-item>
<?php $useNewDesign = $userSettings->settings['use_new_design']; ?>
<md-checkbox
ng-false-value="0"
ng-true-value="1"
ng-model="useNewDesign"
ng-init="useNewDesign = <?= $useNewDesign ?>"
class="md-primary">
</md-checkbox>
<p><?php echo __(
'Display sentences with the new design. '.
'Note that some features are not yet implemented in this new design but are coming soon.'
) ?></p>
<div ng-hide="true">
<?php
echo $this->Form->input(
'settings.use_new_design',
array(
'value' => '{{useNewDesign}}'
)
);
?>
</div>
</md-list-item>
</md-list>
<br>

Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/SentencesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ private function getNumberOfExtraTranslations($sentence)
{
$translations = $sentence->translations;
$total = count($translations[0]) + count($translations[1]);
return $total - SentencesTable::MAX_TRANSLATIONS_DISPLAYED;
return $total - $sentence->max_visible_translations;
}
}
?>
3 changes: 2 additions & 1 deletion webroot/css/layouts/elements.css
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,7 @@ div.hideLink {
*/
.sentence-and-translations {
background-color: #fff;
padding-bottom: 5px;
}

.sentence-and-translations .header {
Expand Down Expand Up @@ -1332,7 +1333,7 @@ div.hideLink {
}

.sentence-and-translations .translation {
padding: 2px 10px;
padding: 0px 10px;
}

.sentence-and-translations .md-subheader {
Expand Down
13 changes: 7 additions & 6 deletions webroot/js/directives/sentence-and-translations.dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@

SentenceAndTranslationsController.$inject = ['$rootScope', '$scope', '$http', '$cookies', '$timeout', '$injector'];
function SentenceAndTranslationsController($rootScope, $scope, $http, $cookies, $timeout, $injector) {
const MAX_TRANSLATIONS = 5;
const rootUrl = get_tatoeba_root_url();

var vm = this;
Expand Down Expand Up @@ -232,7 +231,7 @@
if (!listsDataService) {
listsDataService = $injector.get('listsDataService');
}
var selectableLists = listsDataService.getLists();
var selectableLists = angular.copy(listsDataService.getLists());

if (selectableLists) {
if (selectedLists) {
Expand Down Expand Up @@ -279,10 +278,10 @@

function showFewerTranslations() {
vm.directTranslations = allDirectTranslations.filter(function(item, index) {
return index <= MAX_TRANSLATIONS - 1;
return index <= vm.sentence.max_visible_translations - 1;
});
vm.indirectTranslations = allIndirectTranslations.filter(function(item, index) {
return index + allDirectTranslations.length <= MAX_TRANSLATIONS - 1;
return index + allDirectTranslations.length <= vm.sentence.max_visible_translations - 1;
});
}

Expand Down Expand Up @@ -456,8 +455,10 @@
var action = vm.sentence.is_owned_by_current_user ? 'let_go' : 'adopt';
vm.iconsInProgress.adopt = true;
$http.get(rootUrl + '/sentences/' + action + '/' + vm.sentence.id).then(function(result) {
vm.sentence.user = result.data.user;
vm.sentence.is_owned_by_current_user = vm.sentence.user && vm.sentence.user.username;
var sentence = result.data.sentence;
sentence.expandLabel = vm.sentence.expandLabel;
initSentence(sentence);
initMenu(!vm.isExpanded, sentence.permissions);
vm.iconsInProgress.adopt = false;
});
}
Expand Down