xref: /webtrees/resources/views/admin/locations.phtml (revision b6017f990d38d8c56e04c0096ce9a7e8745ad4ba)
1<?php
2
3use Fisharebest\Webtrees\Http\RequestHandlers\MapDataAdd;
4use Fisharebest\Webtrees\Http\RequestHandlers\MapDataDelete;
5use Fisharebest\Webtrees\Http\RequestHandlers\MapDataEdit;
6use Fisharebest\Webtrees\Http\RequestHandlers\MapDataExportCSV;
7use Fisharebest\Webtrees\Http\RequestHandlers\MapDataExportGeoJson;
8use Fisharebest\Webtrees\Http\RequestHandlers\MapDataImportPage;
9use Fisharebest\Webtrees\Http\RequestHandlers\MapDataList;
10use Fisharebest\Webtrees\I18N;
11use Fisharebest\Webtrees\Module\PlaceHierarchyListModule;
12use Fisharebest\Webtrees\Tree;
13use Fisharebest\Webtrees\View;
14use Illuminate\Support\Collection;
15
16/**
17 * @var array<stdClass>               $active
18 * @var Collection<Tree>              $all_trees
19 * @var array<string,string>          $breadcrumbs
20 * @var int                           $parent_id
21 * @var array<mixed>                  $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-toggle="collapse" data-target=".unused-location">
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                    <span dir="auto"><?= e($place->place) ?></span>
60                    <?php if ($place->no_coord > 0): ?>
61                        <span class="badge badge-pill badge-secondary">
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 badge-pill badge-secondary">
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="sr-only">
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-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-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="7">
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-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        </tr>
167    </tfoot>
168</table>
169
170<?php View::push('javascript') ?>
171<script>
172  'use strict';
173
174  webtrees.persistentToggle("hide-unused-locations");
175</script>
176<?php View::endpush() ?>
177