xref: /webtrees/resources/views/admin/locations.phtml (revision 4a9a60957058ca2a34e30a0d6f783e1540606590)
1<?php
2
3declare(strict_types=1);
4
5use Fisharebest\Webtrees\Http\RequestHandlers\MapDataAdd;
6use Fisharebest\Webtrees\Http\RequestHandlers\MapDataDelete;
7use Fisharebest\Webtrees\Http\RequestHandlers\MapDataDeleteUnused;
8use Fisharebest\Webtrees\Http\RequestHandlers\MapDataEdit;
9use Fisharebest\Webtrees\Http\RequestHandlers\MapDataExportCSV;
10use Fisharebest\Webtrees\Http\RequestHandlers\MapDataExportGeoJson;
11use Fisharebest\Webtrees\Http\RequestHandlers\MapDataImportPage;
12use Fisharebest\Webtrees\Http\RequestHandlers\MapDataList;
13use Fisharebest\Webtrees\I18N;
14use Fisharebest\Webtrees\Module\PlaceHierarchyListModule;
15use Fisharebest\Webtrees\Tree;
16use Illuminate\Support\Collection;
17
18/**
19 * @var array<object>                 $active
20 * @var Collection<int,Tree>          $all_trees
21 * @var array<string,string>          $breadcrumbs
22 * @var int                           $parent_id
23 * @var array<object>                 $placelist
24 * @var PlaceHierarchyListModule|null $list_module
25 * @var string                        $title
26 */
27
28?>
29
30<?= view('components/breadcrumbs', ['links' => $breadcrumbs]) ?>
31
32<h1><?= $title ?></h1>
33
34<p>
35    <label>
36        <input id="hide-unused-locations" type="checkbox" data-bs-toggle="collapse" data-bs-target=".unused-location" data-wt-persist="hide-unused-locations" autocomplete="off">
37        <?= I18N::translate('Hide unused locations') ?>
38    </label>
39</p>
40
41<table class="table table-bordered table-striped table-sm table-hover wt-table-locations">
42    <thead class="thead-dark">
43        <tr>
44            <th><?= I18N::translate('Place') ?></th>
45            <th><?= I18N::translate('Latitude') ?></th>
46            <th><?= I18N::translate('Longitude') ?></th>
47            <!--
48            <th><?= I18N::translate('Flag') ?> </th>
49            -->
50            <th><?= I18N::translate('Edit') ?></th>
51            <th><?= I18N::translate('Facts and events') ?></th>
52            <th><?= I18N::translate('Delete') ?></th>
53        </tr>
54    </thead>
55
56    <tbody>
57    <?php foreach ($placelist as $place) : ?>
58        <tr class="<?= $active[$place->key] ?? null ? '' : 'unused-location collapse show' ?>">
59            <th scope="row">
60                <a href="<?= e(route(MapDataList::class, ['parent_id' => $place->id])) ?>">
61                    <bdi><?= e($place->place) ?></bdi>
62                    <?php if ($place->no_coord > 0) : ?>
63                        <span class="badge bg-secondary rounded-pill">
64                            <?= view('icons/warning') ?>
65                            <?= I18N::number($place->no_coord) ?>
66                            /
67                            <?= I18N::number($place->child_count) ?>
68                        </span>
69                    <?php elseif ($place->child_count > 0) : ?>
70                        <span class="badge bg-secondary rounded-pill">
71                            <?= I18N::number($place->child_count) ?>
72                        </span>
73                    <?php endif ?>
74                </a>
75            </th>
76
77            <td dir="ltr">
78                <?php if ($place->latitude === null) : ?>
79                    <?= view('icons/warning') ?>
80                <?php else : ?>
81                    <?= $place->latitude ?>
82                <?php endif ?>
83            </td>
84
85            <td dir="ltr">
86                <?php if ($place->longitude === null) : ?>
87                    <?= view('icons/warning') ?>
88                <?php else : ?>
89                    <?= $place->longitude ?>
90                <?php endif ?>
91            </td>
92
93            <td>
94                <a class="btn btn-primary" href="<?= e(route(MapDataEdit::class, ['place_id'  => $place->id])) ?>" title="<?= I18N::translate('Edit') ?>">
95                    <?= view('icons/edit') ?>
96                    <span class="visually-hidden">
97                        <?= I18N::translate('Edit') ?>
98                    </span>
99                </a>
100            </td>
101
102            <td>
103                <?php if ($list_module !== null && array_key_exists($place->key, $active)) : ?>
104                    <?php if (count($active[$place->key]) === 1) : ?>
105                        <a class="btn btn-link" href="<?= e($list_module->listUrl($all_trees->get($active[$place->key][0]->tree_name), ['place_id' => $active[$place->key][0]->p_id, 'action2' => 'hierarchy-e'])) ?>">
106                            <?= e($active[$place->key][0]->tree_title) ?>
107                        </a>
108                    <?php else : ?>
109                        <div class="dropdown">
110                            <a class="btn btn-link dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
111                                <?= I18N::plural('%s family tree', '%s family trees', count($active[$place->key]), I18N::number(count($active[$place->key]))) ?>
112                            </a>
113
114                            <div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
115                                <?php foreach ($active[$place->key] as $n => $link) : ?>
116                                    <a class="dropdown-item" href="<?= e($list_module->listUrl($all_trees->get($active[$place->key][$n]->tree_name), ['place_id' => $link->p_id])) ?>">
117                                        <?= e($link->tree_title) ?>
118                                    </a>
119                                <?php endforeach ?>
120                            </div>
121                        </div>
122                    <?php endif ?>
123                <?php endif ?>
124            </td>
125
126            <td>
127                <?php if (!array_key_exists($place->key, $active)) : ?>
128                    <form method="post" action="<?= e(route(MapDataDelete::class, ['place_id' => $place->id])) ?>">
129                        <button type="submit" class="btn btn-danger" aria-label="<?= I18N::translate('delete') ?>" data-wt-confirm="<?= I18N::translate('Remove this location?') ?>">
130                            <?= view('icons/delete') ?>
131                        </button>
132
133                        <?= csrf_field() ?>
134                    </form>
135                <?php endif ?>
136            </td>
137        </tr>
138    <?php endforeach ?>
139    </tbody>
140
141    <tfoot>
142        <tr>
143            <td colspan="4">
144                <a class="btn btn-primary" href="<?= e(route(MapDataAdd::class, ['parent_id' => $parent_id])) ?>">
145                    <?= view('icons/add') ?>
146                    <?= /* I18N: A button label. */
147                    I18N::translate('add place') ?>
148                </a>
149                <button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton"
150                        data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
151                    <?= view('icons/download') ?>
152                    <?= /* I18N: A button label. */
153                    I18N::translate('export file') ?>
154                </button>
155                <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
156                    <a class="dropdown-item" href="<?= e(route(MapDataExportCSV::class, ['parent_id' => $parent_id])) ?>">
157                        csv
158                    </a>
159                    <a class="dropdown-item" href="<?= e(route(MapDataExportGeoJson::class, ['parent_id' => $parent_id])) ?>">
160                        geoJSON
161                    </a>
162                </div>
163                <a class="btn btn-primary" href="<?= e(route(MapDataImportPage::class, ['parent_id' => $parent_id])) ?>">
164                    <?= view('icons/upload') ?>
165                    <?= /* I18N: A button label. */
166                    I18N::translate('import file') ?>
167                </a>
168            </td>
169            <td colspan="2">
170                <?php if (count($active) !== count($placelist)) : ?>
171                    <form class="d-inline" method="post" action="<?= route(MapDataDeleteUnused::class) ?>">
172                        <button type="submit" class="btn btn-danger">
173                            <?= view('icons/delete') ?>
174                            <?= I18N::translate('Delete unused locations') ?>
175                        </button>
176
177                        <?= csrf_field() ?>
178                    </form>
179                <?php endif ?>
180            </td>
181        </tr>
182    </tfoot>
183</table>
184