actually fixed error

This commit is contained in:
vabene1111
2020-07-08 22:14:22 +02:00
parent 19df215bd2
commit 92341380bc
2 changed files with 60 additions and 83 deletions

View File

@@ -1,26 +1,5 @@
{% load i18n %}
<style>
.loader {
border: 16px solid #f3f3f3; /* Light grey */
border-top: 16px solid #3498db; /* Blue */
border-radius: 50%;
width: 120px;
height: 120px;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>
<div class="modal" tabindex="-1" role="dialog" id="modal_recipe">
<div class="modal-dialog" role="document">
<div class="modal-content">
@@ -31,7 +10,7 @@
</button>
</div>
<div class="modal-body" style="text-align: center">
<div class="loader" id="div_loader"></div>
<i class="fas fa-spinner fa-spin fa-8x" id="id_spinner"></i>
<a href="" id="a_recipe_open" target="_blank" onclick="afterClick()" style="font-size: 250%"></a>
</div>
@@ -42,11 +21,11 @@
</div>
</div>
<script type="text/javascript">
<script type="application/javascript">
function openRecipe(id) {
var link = $('#a_recipe_open');
link.hide();
$('#div_loader').show();
$('#id_spinner').show();
var url = "{% url 'api_get_external_file_link' recipe_id=12345 %}".replace(/12345/, id);
@@ -64,7 +43,7 @@
$('#modal_recipe').modal('hide');
}
$('#div_loader').hide();
$('#id_spinner').hide();
}
};

View File

@@ -459,74 +459,72 @@
{% block script %}
<script type="application/javascript">
{% if recipe.internal %}
let csrftoken = Cookies.get('csrftoken');
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
let app = new Vue({
delimiters: ['[[', ']]'],
el: '#id_base_container',
data: {
recipe: undefined,
has_ingredients: false,
has_times: false,
ingredient_factor: 1,
},
let csrftoken = Cookies.get('csrftoken');
Vue.http.headers.common['X-CSRFToken'] = csrftoken;
mounted: function () {
this.loadRecipe()
},
methods: {
loadRecipe: function () {
this.$http.get("{% url 'api:recipe-detail' recipe.pk %}").then((response) => {
this.recipe = response.data;
this.loading = false
let app = new Vue({
delimiters: ['[[', ']]'],
el: '#id_base_container',
data: {
recipe: undefined,
has_ingredients: false,
has_times: false,
ingredient_factor: 1,
},
for (let step of this.recipe.steps) {
if (step.ingredients.length > 0) {
this.has_ingredients = true
}
if (step.time !== 0) {
this.has_times = true
}
this.$set(step, 'time_finished', undefined)
for (let i of step.ingredients) {
this.$set(i, 'checked', false)
}
mounted: function () {
this.loadRecipe()
},
methods: {
loadRecipe: function () {
this.$http.get("{% url 'api:recipe-detail' recipe.pk %}").then((response) => {
this.recipe = response.data;
this.loading = false
for (let step of this.recipe.steps) {
if (step.ingredients.length > 0) {
this.has_ingredients = true
}
}).catch((err) => {
this.error = err.data
this.loading = false
console.log(err)
})
},
roundDecimals: function (num) {
let decimals = {% if request.user.userpreference.ingredient_decimals %}
{{ request.user.userpreference.ingredient_decimals }} {% else %} 2 {% endif %}
return +(Math.round(num + `e+${decimals}`) + `e-${decimals}`);
},
updateTimes: function (step) {
let time_diff_first = 0
for (let s of this.recipe.steps) {
if (this.recipe.steps.indexOf(s) < this.recipe.steps.indexOf(step)) {
time_diff_first += s.time
if (step.time !== 0) {
this.has_times = true
}
this.$set(step, 'time_finished', undefined)
for (let i of step.ingredients) {
this.$set(i, 'checked', false)
}
}
this.recipe.steps[0].time_finished = moment(step.time_finished).subtract(time_diff_first, 'minutes').format(moment.HTML5_FMT.DATETIME_LOCAL);
let time_diff = 0
for (let s of this.recipe.steps) {
s.time_finished = moment(this.recipe.steps[0].time_finished).add(time_diff, 'minutes').format(moment.HTML5_FMT.DATETIME_LOCAL);
time_diff += s.time
}).catch((err) => {
this.error = err.data
this.loading = false
console.log(err)
})
},
roundDecimals: function (num) {
let decimals = {% if request.user.userpreference.ingredient_decimals %}
{{ request.user.userpreference.ingredient_decimals }} {% else %} 2 {% endif %}
return +(Math.round(num + `e+${decimals}`) + `e-${decimals}`);
},
updateTimes: function (step) {
let time_diff_first = 0
for (let s of this.recipe.steps) {
if (this.recipe.steps.indexOf(s) < this.recipe.steps.indexOf(step)) {
time_diff_first += s.time
}
}
}
});
{% endif %}
this.recipe.steps[0].time_finished = moment(step.time_finished).subtract(time_diff_first, 'minutes').format(moment.HTML5_FMT.DATETIME_LOCAL);
let time_diff = 0
for (let s of this.recipe.steps) {
s.time_finished = moment(this.recipe.steps[0].time_finished).add(time_diff, 'minutes').format(moment.HTML5_FMT.DATETIME_LOCAL);
time_diff += s.time
}
}
}
});
// Bootstrap component functions
$(function () {