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