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