Aleksmorshen commited on
Commit
de03262
·
verified ·
1 Parent(s): 156af44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -104
app.py CHANGED
@@ -58,24 +58,21 @@ html_template = '''
58
  <style>
59
  body {
60
  font-family: Arial, sans-serif;
61
- background-color: #f0f0f0;
62
  margin: 0;
63
  padding: 0;
64
- color: #333;
65
- }
66
- header {
67
- background-color: #007BFF;
68
- color: white;
69
- padding: 15px;
70
- text-align: center;
71
  }
72
  #map {
73
- height: 70vh;
74
  width: 100%;
75
  }
76
  h1 {
 
 
77
  margin: 0;
78
- font-size: 28px;
 
 
79
  }
80
  .leaflet-popup-content-wrapper {
81
  background-color: #fff;
@@ -99,10 +96,10 @@ html_template = '''
99
  .popup-form {
100
  display: flex;
101
  flex-direction: column;
102
- width: 250px;
103
  }
104
  .popup-form input, .popup-form textarea {
105
- padding: 8px;
106
  margin-bottom: 10px;
107
  border: 1px solid #ccc;
108
  border-radius: 5px;
@@ -112,25 +109,19 @@ html_template = '''
112
  background-color: #007BFF;
113
  color: white;
114
  border: none;
115
- padding: 10px;
116
  border-radius: 5px;
117
  cursor: pointer;
118
- font-size: 16px;
119
  }
120
  .popup-form button:hover {
121
  background-color: #0056b3;
122
  }
123
- #search-container {
124
- display: flex;
125
- justify-content: center;
126
- margin: 20px;
127
- }
128
  #search-input {
 
129
  padding: 8px;
130
- width: 300px;
131
  border: 1px solid #ccc;
132
  border-radius: 5px;
133
- margin-right: 10px;
134
  }
135
  #search-button {
136
  padding: 8px 12px;
@@ -139,36 +130,18 @@ html_template = '''
139
  border: none;
140
  border-radius: 5px;
141
  cursor: pointer;
142
- font-size: 16px;
143
  }
144
  #search-button:hover {
145
  background-color: #0056b3;
146
  }
147
  #search-results {
148
- display: flex;
149
- flex-direction: column;
150
- align-items: center;
151
  margin: 20px;
152
  }
153
- #search-results div {
154
- background-color: white;
155
- border: 1px solid #ccc;
156
- border-radius: 5px;
157
- padding: 10px;
158
- width: 80%;
159
- margin-bottom: 10px;
160
- box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.1);
161
- }
162
- #search-results div b {
163
- color: #007BFF;
164
- }
165
  </style>
166
  </head>
167
  <body>
168
- <header>
169
- <h1>GeoGram</h1>
170
- </header>
171
- <div id="search-container">
172
  <input type="text" id="search-input" placeholder="Поиск по названию или описанию" />
173
  <button id="search-button">Поиск</button>
174
  </div>
@@ -237,91 +210,59 @@ html_template = '''
237
  popupContent.classList.add('popup-form');
238
 
239
  const inputName = document.createElement('input');
240
- inputName.type = 'text';
241
- inputName.placeholder = 'Название метки';
242
-
243
  const inputDescription = document.createElement('textarea');
244
- inputDescription.placeholder = 'Описание метки';
245
-
246
  const inputTelegram = document.createElement('input');
247
- inputTelegram.type = 'text';
248
- inputTelegram.placeholder = 'Telegram ссылка (без @)';
 
249
 
250
- const button = document.createElement('button');
251
- button.innerText = 'Добавить метку';
252
- button.onclick = function() {
253
- if (inputName.value && inputDescription.value && inputTelegram.value) {
254
- addMarker(inputName.value, inputDescription.value, inputTelegram.value, e.latlng);
255
- map.closePopup(); // Закрыть всплывающее окно после добавления
256
- } else {
257
- alert('Пожалуйста, заполните все обязательные поля.');
258
- }
259
  };
260
 
261
  popupContent.appendChild(inputName);
262
  popupContent.appendChild(inputDescription);
263
  popupContent.appendChild(inputTelegram);
264
- popupContent.appendChild(button);
265
-
266
- L.popup()
267
- .setLatLng(e.latlng)
268
- .setContent(popupContent)
269
- .openOn(map);
270
  });
271
 
272
  // Функция для удаления метки
273
  function removeMarker(markerId) {
274
- fetch(`/remove_marker/${markerId}`, {
275
- method: 'DELETE'
276
- }).then(() => {
277
- location.reload(); // Перезагрузить страницу, чтобы обновить маркеры
278
- });
279
- }
280
-
281
- // Функция для поиска меток
282
- function searchMarkers(query) {
283
- fetch(`/search_markers?query=${encodeURIComponent(query)}`)
284
- .then(response => response.json())
285
- .then(data => {
286
- const resultsDiv = document.getElementById('search-results');
287
- resultsDiv.innerHTML = ''; // Очистка предыдущих результатов
288
-
289
- if (data.length > 0) {
290
- data.forEach(marker => {
291
- const resultItem = document.createElement('div');
292
- resultItem.innerHTML = `<b>${marker.name}</b>: ${marker.description} <button onclick="showMarker(${marker.id})">Показать на карте</button>`;
293
- resultsDiv.appendChild(resultItem);
294
- });
295
- } else {
296
- resultsDiv.innerHTML = '<p>Нет результатов</p>';
297
- }
298
  });
299
  }
300
 
301
- // Обработчик события для кнопки поиска
302
- document.getElementById('search-button').onclick = function() {
303
  const query = document.getElementById('search-input').value;
304
- searchMarkers(query); // Убираем приведение к нижнему регистру
305
- };
306
-
307
- // Функция для показа метки на карте
308
- function showMarker(markerId) {
309
- fetch(`/get_markers`)
310
  .then(response => response.json())
311
  .then(data => {
312
- const marker = data.find(m => m.id === markerId);
313
- if (marker) {
314
- map.setView([marker.latitude, marker.longitude], 13);
315
- L.marker([marker.latitude, marker.longitude]).addTo(map)
316
- .bindPopup(`<b>${marker.name}</b><p>${marker.description}</p><a href="https://t.me/${marker.telegram_link}" target="_blank">Перейти в Telegram</a>`);
317
- }
 
 
318
  });
319
- }
320
  </script>
321
  </body>
322
  </html>
323
  '''
324
 
 
325
  @app.route('/')
326
  def index():
327
  return render_template_string(html_template)
@@ -340,11 +281,12 @@ def get_markers():
340
 
341
  @app.route('/add_marker', methods=['POST'])
342
  def add_marker():
343
- data = request.json
344
  name = data['name']
345
  description = data['description']
346
  telegram_link = data['telegram_link']
347
  latitude, longitude = data['position']
 
348
  marker_id = add_marker_to_db(name, description, telegram_link, latitude, longitude)
349
  return jsonify({
350
  'id': marker_id,
@@ -366,7 +308,7 @@ def search_markers():
366
  conn = sqlite3.connect('markers.db')
367
  cursor = conn.cursor()
368
  cursor.execute('''SELECT id, name, description, telegram_link, latitude, longitude FROM markers
369
- WHERE name LIKE ? OR description LIKE ?''',
370
  (f'%{query}%', f'%{query}%'))
371
  markers = cursor.fetchall()
372
  conn.close()
 
58
  <style>
59
  body {
60
  font-family: Arial, sans-serif;
61
+ background-color: #f7f7f7;
62
  margin: 0;
63
  padding: 0;
 
 
 
 
 
 
 
64
  }
65
  #map {
66
+ height: 80vh;
67
  width: 100%;
68
  }
69
  h1 {
70
+ text-align: center;
71
+ padding: 20px;
72
  margin: 0;
73
+ background-color: #007BFF;
74
+ color: white;
75
+ font-size: 24px;
76
  }
77
  .leaflet-popup-content-wrapper {
78
  background-color: #fff;
 
96
  .popup-form {
97
  display: flex;
98
  flex-direction: column;
99
+ width: 200px;
100
  }
101
  .popup-form input, .popup-form textarea {
102
+ padding: 5px;
103
  margin-bottom: 10px;
104
  border: 1px solid #ccc;
105
  border-radius: 5px;
 
109
  background-color: #007BFF;
110
  color: white;
111
  border: none;
112
+ padding: 8px 12px;
113
  border-radius: 5px;
114
  cursor: pointer;
 
115
  }
116
  .popup-form button:hover {
117
  background-color: #0056b3;
118
  }
 
 
 
 
 
119
  #search-input {
120
+ margin: 20px;
121
  padding: 8px;
122
+ width: calc(100% - 40px);
123
  border: 1px solid #ccc;
124
  border-radius: 5px;
 
125
  }
126
  #search-button {
127
  padding: 8px 12px;
 
130
  border: none;
131
  border-radius: 5px;
132
  cursor: pointer;
 
133
  }
134
  #search-button:hover {
135
  background-color: #0056b3;
136
  }
137
  #search-results {
 
 
 
138
  margin: 20px;
139
  }
 
 
 
 
 
 
 
 
 
 
 
 
140
  </style>
141
  </head>
142
  <body>
143
+ <h1>GeoGram</h1>
144
+ <div>
 
 
145
  <input type="text" id="search-input" placeholder="Поиск по названию или описанию" />
146
  <button id="search-button">Поиск</button>
147
  </div>
 
210
  popupContent.classList.add('popup-form');
211
 
212
  const inputName = document.createElement('input');
213
+ inputName.placeholder = 'Название';
 
 
214
  const inputDescription = document.createElement('textarea');
215
+ inputDescription.placeholder = 'Описание';
 
216
  const inputTelegram = document.createElement('input');
217
+ inputTelegram.placeholder = 'Telegram ссылка';
218
+ const submitButton = document.createElement('button');
219
+ submitButton.innerText = 'Добавить метку';
220
 
221
+ submitButton.onclick = function() {
222
+ const name = inputName.value;
223
+ const description = inputDescription.value;
224
+ const telegramLink = inputTelegram.value;
225
+ addMarker(name, description, telegramLink, e.latlng);
226
+ map.closePopup();
 
 
 
227
  };
228
 
229
  popupContent.appendChild(inputName);
230
  popupContent.appendChild(inputDescription);
231
  popupContent.appendChild(inputTelegram);
232
+ popupContent.appendChild(submitButton);
233
+ L.popup().setLatLng(e.latlng).setContent(popupContent).openOn(map);
 
 
 
 
234
  });
235
 
236
  // Функция для удаления метки
237
  function removeMarker(markerId) {
238
+ fetch(`/remove_marker/${markerId}`, { method: 'DELETE' })
239
+ .then(() => {
240
+ location.reload(); // Перезагрузка страницы для обновления меток
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  });
242
  }
243
 
244
+ // Обработка поиска меток
245
+ document.getElementById('search-button').addEventListener('click', function() {
246
  const query = document.getElementById('search-input').value;
247
+ fetch(`/search_markers?query=${query}`)
 
 
 
 
 
248
  .then(response => response.json())
249
  .then(data => {
250
+ const searchResultsDiv = document.getElementById('search-results');
251
+ searchResultsDiv.innerHTML = ''; // Очистка предыдущих результатов
252
+
253
+ data.forEach(marker => {
254
+ const resultItem = document.createElement('div');
255
+ resultItem.innerHTML = `<b>${marker.name}</b> - ${marker.description} <a href="https://t.me/${marker.telegram_link}" target="_blank">Перейти в Telegram</a>`;
256
+ searchResultsDiv.appendChild(resultItem);
257
+ });
258
  });
259
+ });
260
  </script>
261
  </body>
262
  </html>
263
  '''
264
 
265
+ # Определение маршрутов
266
  @app.route('/')
267
  def index():
268
  return render_template_string(html_template)
 
281
 
282
  @app.route('/add_marker', methods=['POST'])
283
  def add_marker():
284
+ data = request.get_json()
285
  name = data['name']
286
  description = data['description']
287
  telegram_link = data['telegram_link']
288
  latitude, longitude = data['position']
289
+
290
  marker_id = add_marker_to_db(name, description, telegram_link, latitude, longitude)
291
  return jsonify({
292
  'id': marker_id,
 
308
  conn = sqlite3.connect('markers.db')
309
  cursor = conn.cursor()
310
  cursor.execute('''SELECT id, name, description, telegram_link, latitude, longitude FROM markers
311
+ WHERE LOWER(name) LIKE ? OR LOWER(description) LIKE ?''',
312
  (f'%{query}%', f'%{query}%'))
313
  markers = cursor.fetchall()
314
  conn.close()