fixed not beeing able to open external recipes when internal exists
This commit is contained in:
parent
6a010587bf
commit
9d0a6e63f8
@ -43,12 +43,15 @@
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
function openRecipe(id) {
|
||||
function openRecipe(id, force_external = false) {
|
||||
var link = $('#a_recipe_open');
|
||||
link.hide();
|
||||
$('#div_loader').show();
|
||||
$('#div_loader').show();
|
||||
|
||||
var url = "{% url 'api_get_file_link' recipe_id=12345 %}".replace(/12345/, id);
|
||||
if (force_external) {
|
||||
url = "{% url 'api_get_external_file_link' recipe_id=12345 %}".replace(/12345/, id);
|
||||
}
|
||||
|
||||
link.text("{% trans 'Open Recipe' %}");
|
||||
$('#modal_recipe').modal('show');
|
||||
@ -56,10 +59,10 @@
|
||||
var xhttp = new XMLHttpRequest();
|
||||
xhttp.onreadystatechange = function () {
|
||||
if (this.readyState === 4 && this.status === 200) {
|
||||
if ( /^((?!chrome|android).)*safari/i.test(navigator.userAgent)){
|
||||
if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
|
||||
link.attr("href", this.responseText);
|
||||
link.show();
|
||||
}else{
|
||||
} else {
|
||||
window.open(this.responseText);
|
||||
$('#modal_recipe').modal('hide');
|
||||
}
|
||||
|
@ -110,7 +110,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if recipe.storage %}
|
||||
<a href='#' onClick='openRecipe({{ recipe.id }})'>{% trans 'View external recipe' %} <i
|
||||
<a href='#' onClick='openRecipe({{ recipe.id }}, true)'>{% trans 'View external recipe' %} <i
|
||||
class="fas fa-external-link-alt"></i></a>
|
||||
{% endif %}
|
||||
|
||||
|
@ -54,6 +54,9 @@ urlpatterns = [
|
||||
path('data/statistics', data.statistics, name='data_stats'),
|
||||
|
||||
path('api/get_file_link/<int:recipe_id>/', api.get_file_link, name='api_get_file_link'),
|
||||
path('api/get_external_file_link/<int:recipe_id>/', api.get_external_file_link, name='api_get_external_file_link'),
|
||||
|
||||
|
||||
path('api/sync_all/', api.sync_all, name='api_sync'),
|
||||
|
||||
path('dal/keyword/', dal.KeywordAutocomplete.as_view(), name='dal_keyword'),
|
||||
|
@ -6,7 +6,6 @@ from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import redirect
|
||||
|
||||
from cookbook.models import Recipe, Sync, Storage
|
||||
from cookbook.provider import dropbox
|
||||
from cookbook.provider.dropbox import Dropbox
|
||||
from cookbook.provider.nextcloud import Nextcloud
|
||||
|
||||
@ -17,7 +16,23 @@ def get_file_link(request, recipe_id):
|
||||
|
||||
if recipe.internal:
|
||||
return HttpResponse(reverse('view_recipe', args=[recipe_id]))
|
||||
if recipe.storage.method == Storage.DROPBOX:
|
||||
if recipe.storage.method == Storage.DROPBOX: # TODO move to central location (as all provider related functions)
|
||||
if recipe.link == "":
|
||||
recipe.link = Dropbox.get_share_link(recipe) # TODO response validation
|
||||
recipe.save()
|
||||
if recipe.storage.method == Storage.NEXTCLOUD:
|
||||
if recipe.link == "":
|
||||
recipe.link = Nextcloud.get_share_link(recipe) # TODO response validation
|
||||
recipe.save()
|
||||
|
||||
return HttpResponse(recipe.link)
|
||||
|
||||
|
||||
@login_required
|
||||
def get_external_file_link(request, recipe_id):
|
||||
recipe = Recipe.objects.get(id=recipe_id)
|
||||
|
||||
if recipe.storage.method == Storage.DROPBOX: # TODO move to central location (as all provider related functions)
|
||||
if recipe.link == "":
|
||||
recipe.link = Dropbox.get_share_link(recipe) # TODO response validation
|
||||
recipe.save()
|
||||
|
Loading…
Reference in New Issue
Block a user