Fix pmtiles map

This commit is contained in:
Eugene Burmakin 2025-05-03 20:36:09 +02:00
parent 72927379b7
commit 8087229d87
8 changed files with 93 additions and 10 deletions

View file

@ -10,10 +10,10 @@ class Api::V1::SubscriptionsController < ApiController
render json: { message: 'Subscription updated successfully' }
rescue JWT::DecodeError => e
Sentry.capture_exception(e)
ExceptionReporter.call(e)
render json: { message: 'Failed to verify subscription update.' }, status: :unauthorized
rescue ArgumentError => e
Sentry.capture_exception(e)
ExceptionReporter.call(e)
render json: { message: 'Invalid subscription data received.' }, status: :unprocessable_entity
end
end

View file

@ -25,6 +25,8 @@ class ExportsController < ApplicationController
rescue StandardError => e
export&.destroy
ExceptionReporter.call(e)
redirect_to exports_url, alert: "Export failed to initiate: #{e.message}", status: :unprocessable_entity
end

View file

@ -48,6 +48,8 @@ class ImportsController < ApplicationController
rescue StandardError => e
Import.where(user: current_user, name: files.map(&:original_filename)).destroy_all
ExceptionReporter.call(e)
flash.now[:error] = e.message
redirect_to new_import_path, notice: e.message, status: :unprocessable_entity

View file

@ -0,0 +1,56 @@
import { Controller } from "@hotwired/stimulus"
import { DirectUpload } from "@rails/activestorage"
export default class extends Controller {
static targets = ["input", "progress", "submit"]
static values = {
url: String
}
connect() {
this.inputTarget.addEventListener("change", this.upload.bind(this))
}
upload() {
const files = this.inputTarget.files
if (files.length === 0) return
// Disable submit button during upload
this.submitTarget.disabled = true
// Create progress bar if it doesn't exist
if (!this.hasProgressTarget) {
const progressBar = document.createElement("div")
progressBar.setAttribute("data-direct-upload-target", "progress")
progressBar.className = "w-full bg-gray-200 rounded-full h-2.5 mt-2"
this.inputTarget.parentNode.appendChild(progressBar)
}
Array.from(files).forEach(file => {
const upload = new DirectUpload(file, this.urlValue, this)
upload.create((error, blob) => {
if (error) {
console.error("Error uploading file:", error)
} else {
const hiddenField = document.createElement("input")
hiddenField.setAttribute("type", "hidden")
hiddenField.setAttribute("name", this.inputTarget.name)
hiddenField.setAttribute("value", blob.signed_id)
this.element.appendChild(hiddenField)
}
})
})
}
directUploadWillStoreFileWithXHR(request) {
request.upload.addEventListener("progress", event => {
const progress = (event.loaded / event.total) * 100
this.progressTarget.style.width = `${progress}%`
})
}
directUploadDidProgress(event) {
// This method is called by ActiveStorage during the upload
// We're handling progress in directUploadWillStoreFileWithXHR instead
}
}

View file

@ -12,7 +12,7 @@ export function createMapLayer(map, selectedLayerName, layerKey, selfHosted) {
}
let layer;
console.log("isSelfhosted: ", selfHosted)
if (selfHosted === "true") {
layer = L.tileLayer(config.url, {
maxZoom: config.maxZoom,
@ -21,13 +21,21 @@ export function createMapLayer(map, selectedLayerName, layerKey, selfHosted) {
// Add any other config properties that might be needed
});
} else {
layer = protomapsL.leafletLayer(
{
// Use the global protomapsL object (loaded via script tag)
try {
if (typeof window.protomapsL === 'undefined') {
throw new Error('protomapsL is not defined');
}
layer = window.protomapsL.leafletLayer({
url: config.url,
flavor: config.flavor,
crossOrigin: true,
}
)
});
} catch (error) {
console.error('Error creating protomaps layer:', error);
throw new Error('Failed to create vector tile layer. protomapsL may not be available.');
}
}
if (selectedLayerName === layerKey) {

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class ExceptionReporter
def self.call(exception)
return unless DawarichSettings.self_hosted?
Sentry.capture_exception(exception)
end
end

View file

@ -27,6 +27,8 @@ class Visits::Suggest
title: 'Error suggesting visits',
content: "Error suggesting visits: #{e.message}\n#{e.backtrace.join("\n")}"
)
ExceptionReporter.call(e)
end
private

View file

@ -1,4 +1,4 @@
<%= form_with model: import, class: "contents" do |form| %>
<%= form_with model: import, class: "contents", data: { controller: "direct-upload", direct_upload_url_value: rails_direct_uploads_url } do |form| %>
<div class="form-control w-full">
<label class="label">
<span class="label-text">Select source</span>
@ -65,10 +65,14 @@
<div class="label">
<span class="label-text">Select one or multiple files</span>
</div>
<%= form.file_field :files, multiple: true, class: "file-input file-input-bordered w-full max-w-xs" %>
<%= form.file_field :files,
multiple: true,
class: "file-input file-input-bordered w-full max-w-xs",
data: { direct_upload_target: "input" } %>
</label>
<div class="inline">
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer",
data: { direct_upload_target: "submit" } %>
</div>
<% end %>