ability to restore original image

This commit is contained in:
Jakob Ketterl 2021-02-10 21:29:46 +01:00
parent 8cf9b509c1
commit 7097dc1cd8
4 changed files with 25 additions and 12 deletions

View File

@ -1,11 +1,13 @@
$.fn.imageUpload = function() { $.fn.imageUpload = function() {
$.each(this, function(){ $.each(this, function(){
var $button = $(this).find('button'); var $uploadButton = $(this).find('button.upload');
var $restoreButton = $(this).find('button.restore');
var $img = $(this).find('img'); var $img = $(this).find('img');
var originalUrl = $img.prop('src');
var $input = $(this).find('input'); var $input = $(this).find('input');
var id = $input.prop('id'); var id = $input.prop('id');
$button.click(function(){ $uploadButton.click(function(){
$button.prop('disabled', true); $uploadButton.prop('disabled', true);
var input = document.createElement('input'); var input = document.createElement('input');
input.type = 'file'; input.type = 'file';
input.accept = 'image/jpeg, image/png'; input.accept = 'image/jpeg, image/png';
@ -25,7 +27,7 @@ $.fn.imageUpload = function() {
$input.val(data.uuid); $input.val(data.uuid);
$img.prop('src', "/imageupload?id=" + id + "&uuid=" + data.uuid); $img.prop('src', "/imageupload?id=" + id + "&uuid=" + data.uuid);
}).always(function(){ }).always(function(){
$button.prop('disabled', false); $uploadButton.prop('disabled', false);
}); });
} }
}; };
@ -33,5 +35,11 @@ $.fn.imageUpload = function() {
input.click(); input.click();
return false; return false;
}); });
$restoreButton.click(function(){
$input.val('restore');
$img.prop('src', originalUrl + "&mapped=false");
return false;
});
}); });
} }

View File

@ -94,8 +94,8 @@ class OwrxAssetsController(AssetsController):
"gfx/openwebrx-avatar.png": "receiver_avatar", "gfx/openwebrx-avatar.png": "receiver_avatar",
"gfx/openwebrx-top-photo.jpg": "receiver_top_photo", "gfx/openwebrx-top-photo.jpg": "receiver_top_photo",
} }
config = CoreConfig() if file in mappedFiles and ("mapped" not in self.request.query or self.request.query["mapped"][0] != "false"):
if file in mappedFiles: config = CoreConfig()
user_file = config.get_data_directory() + "/" + mappedFiles[file] user_file = config.get_data_directory() + "/" + mappedFiles[file]
if os.path.exists(user_file) and os.path.isfile(user_file): if os.path.exists(user_file) and os.path.isfile(user_file):
return user_file return user_file

View File

@ -26,6 +26,7 @@ from owrx.wsjt import Fst4Profile, Fst4wProfile
import json import json
import logging import logging
import shutil import shutil
import os
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -370,11 +371,15 @@ class GeneralSettingsController(AuthorizationMixin, WebpageController):
return variables return variables
def handle_image(self, data, image_id): def handle_image(self, data, image_id):
if image_id in data and data[image_id]: if image_id in data:
config = CoreConfig() config = CoreConfig()
filename = "{}-{}".format(image_id, data[image_id]) data_file = config.get_data_directory() + "/" + image_id
shutil.copy(config.get_temporary_directory() + "/" + filename, config.get_data_directory() + "/" + image_id) if data[image_id] == "restore":
del data[image_id] os.unlink(data_file)
elif data[image_id]:
filename = "{}-{}".format(image_id, data[image_id])
shutil.copy(config.get_temporary_directory() + "/" + filename, data_file)
del data[image_id]
def processFormData(self): def processFormData(self):
data = parse_qs(self.get_body().decode("utf-8"), keep_blank_values=True) data = parse_qs(self.get_body().decode("utf-8"), keep_blank_values=True)

View File

@ -3,7 +3,6 @@ from owrx.form import Input
from datetime import datetime from datetime import datetime
# TODO: ability to restore the original image
class ImageInput(Input, metaclass=ABCMeta): class ImageInput(Input, metaclass=ABCMeta):
def render_input(self, value): def render_input(self, value):
return """ return """
@ -12,7 +11,8 @@ class ImageInput(Input, metaclass=ABCMeta):
<div class="image-container"> <div class="image-container">
<img class="{classes}" src="{url}" alt="{label}"/> <img class="{classes}" src="{url}" alt="{label}"/>
</div> </div>
<button class="btn btn-primary">Upload new image...</button> <button class="btn btn-primary upload">Upload new image...</button>
<button class="btn btn-secondary restore">Restore original image</button>
</div> </div>
""".format( """.format(
id=self.id, label=self.label, url=self.cachebuster(self.getUrl()), classes=" ".join(self.getImgClasses()) id=self.id, label=self.label, url=self.cachebuster(self.getUrl()), classes=" ".join(self.getImgClasses())