Skip to content

Commit

Permalink
Individual tab added
Browse files Browse the repository at this point in the history
  • Loading branch information
UksusoFF committed Jun 24, 2020
1 parent 62adc5d commit 65fdf27
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 21 deletions.
2 changes: 1 addition & 1 deletion resources/build/admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions resources/langs/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
'Link individual with media when mark them on photo' => 'Link individual with media when mark them on photo',
'Show meta' => 'Show meta',
'Load and show information from linked fact' => 'Load and show information from linked fact',
'Show tab' => 'Show tab',
'Show tab on individuals page' => 'Show tab on individuals page',
//Config: Table
//'Media' => 'Media',
//'Notes' => 'Notes',
Expand Down
2 changes: 2 additions & 0 deletions resources/langs/ru.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
'Link individual with media when mark them on photo' => 'Связывать персону с медиа при добавлении ее на фото',
'Show meta' => 'Показывать мету',
'Load and show information from linked fact' => 'Загружать и показывать информацию из связанного факта',
'Show tab' => 'Показывать вкладку',
'Show tab on individuals page' => 'Показывать вкладку на странице персоны',
//Config: Table
//'Media' => 'Медиа',
//'Notes' => 'Примечания',
Expand Down
48 changes: 31 additions & 17 deletions resources/scripts/admin/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,40 @@ $(document).ready(function() {
}
});

$page.find('[data-action="setting-exif"], [data-action="setting-linking"], [data-action="setting-meta"]').on('change', function(e) {
$.ajax({
url: $(this).data('url')
}).done(function(response) {
facesShowMessage(response);
});
});

$page.find('[aria-labelledby="faces-settings-menu"]').on('click', function(e) {
e.stopPropagation();
});

$page.find('[data-action="missed-repair"], [data-action="missed-delete"]').on('click', function() {
if (confirm(window.WT_FACES_WARNING)) {
$page
.find([
'[data-action="setting-exif"]',
'[data-action="setting-linking"]',
'[data-action="setting-meta"]',
'[data-action="setting-tab"]',
].join(', '))
.on('change', function() {
$.ajax({
url: $(this).data('url')
}).done(function(response) {
facesShowMessage(response);
$table.DataTable().ajax.reload();
});
}
});
});

$page
.find('[aria-labelledby="faces-settings-menu"]')
.on('click', function(e) {
e.stopPropagation();
});

$page
.find([
'[data-action="missed-repair"]',
'[data-action="missed-delete"]',
].join(', '))
.on('click', function() {
if (confirm(window.WT_FACES_WARNING)) {
$.ajax({
url: $(this).data('url')
}).done(function(response) {
facesShowMessage(response);
$table.DataTable().ajax.reload();
});
}
});
});
14 changes: 14 additions & 0 deletions resources/views/admin/config.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ use Fisharebest\Webtrees\View;
</label>
</span>
</span>
<span class="dropdown-item text-right"
title="<?= I18N::translate('Show tab on individuals page') ?>">
<span class="custom-control custom-switch">
<input type="checkbox"
class="custom-control-input"
id="faces-tab-state"
data-action="setting-tab"
data-url="<?= e($routes['setting_tab']) ?>"
<?= $settings['tab'] ? 'checked' : '' ?>>
<label class="custom-control-label" for="faces-tab-state">
<?= I18N::translate('Show tab') ?>
</label>
</span>
</span>
</div>
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions resources/views/tab.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="py-4">
<div class="row row-cols-1 row-cols-md-4">
<?php foreach ($list as $media) : ?>
<?php foreach ($media->mediaFiles() as $file) : ?>
<div class="col mb-4">
<div class="card">
<?= $file->displayImage(200, 200, 'contain', ['rel' => 'faces-tab', 'class' => 'card-img-top']) ?>
</div>
</div>
<?php endforeach ?>
<?php endforeach ?>
</div>
</div>
14 changes: 12 additions & 2 deletions src/Helpers/DatabaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,20 @@ public function setMediaMap(
return null;
}

public function getMediaList(?string $media, ?string $person, ?string $search, int $start, int $length): array
{
public function getMediaList(
?int $tree,
?string $media,
?string $person,
?string $search,
int $start,
int $length
): array {
$query = DB::table('media_faces');

if ($tree !== null) {
$query->where('f_m_tree', '=', $tree);
}

if ($media !== null) {
$query->where('f_m_id', '=', $media);
}
Expand Down
19 changes: 19 additions & 0 deletions src/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public function handle(ServerRequestInterface $request): Response
return $this->settingLinking();
case 'setting_meta':
return $this->settingMeta();
case 'setting_tab':
return $this->settingTab();
case 'missed_repair':
return $this->missedRepair();
case 'missed_destroy':
Expand All @@ -70,6 +72,7 @@ private function config(Request $request): Response
'exif' => $this->module->settingEnabled(FacesModule::SETTING_EXIF_NAME),
'linking' => $this->module->settingEnabled(FacesModule::SETTING_LINKING_NAME),
'meta' => $this->module->settingEnabled(FacesModule::SETTING_META_NAME),
'tab' => $this->module->settingEnabled(FacesModule::SETTING_TAB_NAME),
],
'filters' => array_filter([
$request->getQueryParams()['mid'] ?? null,
Expand All @@ -93,6 +96,9 @@ private function config(Request $request): Response
'setting_meta' => route(self::ROUTE_PREFIX, [
'action' => 'setting_meta',
]),
'setting_tab' => route(self::ROUTE_PREFIX, [
'action' => 'setting_tab',
]),
'missed_repair' => route(self::ROUTE_PREFIX, [
'action' => 'missed_repair',
]),
Expand All @@ -113,6 +119,7 @@ private function config(Request $request): Response
private function data(Request $request): Response
{
[$rows, $total] = $this->module->query->getMediaList(
null,
$request->getQueryParams()['mid'] ?? null,
$request->getQueryParams()['pid'] ?? null,
$request->getQueryParams()['q'] ?? null,
Expand Down Expand Up @@ -231,7 +238,19 @@ private function settingMeta(): Response
'success' => true,
'message' => "{$state}: "
. I18N::translate('Load and show information from linked fact') . '.',
]);
}

private function settingTab(): Response
{
$state = $this->module->settingToggle(FacesModule::SETTING_TAB_NAME)
? I18N::translate('Enabled')
: I18N::translate('Disabled');

return response([
'success' => true,
'message' => "{$state}: "
. I18N::translate('Show tab on individuals page') . '.',
]);
}

Expand Down
59 changes: 58 additions & 1 deletion src/Modules/FacesModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

use Aura\Router\RouterContainer;
use Fig\Http\Message\RequestMethodInterface;
use Fisharebest\Webtrees\Factory;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
use Fisharebest\Webtrees\Module\ModuleConfigTrait;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\Module\ModuleGlobalInterface;
use Fisharebest\Webtrees\Module\ModuleGlobalTrait;
use Fisharebest\Webtrees\Module\ModuleTabInterface;
use Fisharebest\Webtrees\Module\ModuleTabTrait;
use Fisharebest\Webtrees\Services\MigrationService;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\View;
Expand All @@ -23,11 +27,12 @@
use UksusoFF\WebtreesModules\Faces\Http\Controllers\DataController;
use UksusoFF\WebtreesModules\Faces\Http\Controllers\MediaHelper;

class FacesModule extends AbstractModule implements ModuleCustomInterface, ModuleGlobalInterface, ModuleConfigInterface, MiddlewareInterface
class FacesModule extends AbstractModule implements ModuleCustomInterface, ModuleGlobalInterface, ModuleConfigInterface, ModuleTabInterface, MiddlewareInterface
{
use ModuleCustomTrait;
use ModuleGlobalTrait;
use ModuleConfigTrait;
use ModuleTabTrait;

public const SCHEMA_VERSION = '6';

Expand All @@ -43,6 +48,8 @@ class FacesModule extends AbstractModule implements ModuleCustomInterface, Modul

public const SETTING_META_NAME = 'FACES_META_ENABLED';

public const SETTING_TAB_NAME = 'FACES_TAB_ENABLED';

public $query;

public $media;
Expand Down Expand Up @@ -187,4 +194,54 @@ public function getConfigLink(): string
'action' => 'config',
]);
}

public function getTabContent(Individual $individual): string
{
if (!$this->settingEnabled(self::SETTING_TAB_NAME)) {
return '';
}

[$rows, $total] = $this->query->getMediaList(
$individual->tree()->id(),
null,
$individual->xref(),
null,
0,
1000
);

return view("{$this->name()}::tab", [
'list' => $rows->map(function($row) use ($individual) {
return Factory::media()->make($row->f_m_id, $individual->tree());
}),
]);
}

public function hasTabContent(Individual $individual): bool
{
if (!$this->settingEnabled(self::SETTING_TAB_NAME)) {
return false;
}

[$rows, $total] = $this->query->getMediaList(
$individual->tree()->id(),
null,
$individual->xref(),
null,
0,
1
);

return $total > 0;
}

public function canLoadAjax(): bool
{
return true;
}

public function isGrayedOut(Individual $individual): bool
{
return false;
}
}

0 comments on commit 65fdf27

Please sign in to comment.