-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
502 lines (481 loc) · 23.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
<!DOCTYPE html>
<html>
<head>
<title>Recepturer</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="icon" href="favicon.ico" type="image/x-icon">
<!-- Dependencies -->
<script src="resources/vuejs/vue.js"></script>
<link href="resources/googlefonts/materialicons.css" rel="stylesheet">
<link rel="stylesheet" href="resources/materialize/css/materialize.min.css">
<script type="application/javascript" src="resources/materialize/js/materialize.min.js"></script>
<script src="https://unpkg.com/dropbox@9.8.0/dist/Dropbox-sdk.min.js"></script>
<!-- Recepturer -->
<link rel="stylesheet" href="css/style.css" />
<script type="application/javascript" src="js/recepturer.js"></script>
<script type="application/javascript" src="components/recipes.js"></script>
<script type="application/javascript" src="components/recipe.js"></script>
<script type="application/javascript" src="components/mealplan.js"></script>
<script type="application/javascript" src="components/shoppinglist.js"></script>
<script type="application/javascript" src="components/administration.js"></script>
<script type="application/javascript" src="components/debug.js"></script>
</head>
<body>
<div id="recepturer">
<!-- Start -->
<div v-if="page=='start'" class="container" style="max-width: 600px;">
<h1 class="header">
<img src="resources/faviconio-logo/recepturer.svg" width="80%" title="Recepturer" />
</h1>
<div class="divider"></div>
<div class="section">
<h4 class="light">Manage all your recipes in one app.</h4>
<p style="text-align: justify;">
Let Recepturer help you organize all your recipes in one place. You can add, edit and delete recipes, and create meal plans. Simply type your recipe and all ingredients will be listed as you go.
</p>
<p style="text-align: justify;">
Set up your shopping list and tick off all the ingredients you need. Easily order your shopping list according to your favorite groceries store.
</p>
</div>
<div class="section center-align">
<button class="btn-large waves-effect waves-light" v-on:click="dropboxConnect()"><i class="material-icons left">import_contacts</i>Open with Dropbox</button>
<button class="btn-large waves-effect waves-light teal lighten-3" v-on:click="loadDemo()"><i class="material-icons left">science</i>Demo</button>
</div>
<div class="section">
<p>
Recepturer is a <a href="https://github.com/sjoerdvanderhoorn/recepturer" target="_blank">free and open source</a> application. All data is stored in your own Dropbox account.
</p>
</div>
<div class="divider"></div>
<div class="section">
<h4 class="header">Features</h4>
<ul class="collapsible">
<li>
<div class="collapsible-header"><i class="material-icons">blender</i>Recipe authoring</div>
<div class="collapsible-body">
<span>Easily type up your recipes. Recepturer will automatically distill all ingredients so they can be added to your shopping list.</span>
<p>
<img class="materialboxed" width="100%" src="screenshots/recipe.png">
</p>
</div>
</li>
<li>
<div class="collapsible-header"><i class="material-icons">menu_book</i>Create a meal plan</div>
<div class="collapsible-body">
<span>Add or remove recipes to create a meal plan. Ingredients are automatically added to your shopping list as you go.</span>
<p>
<img class="materialboxed" width="100%" src="screenshots/mealplan.png">
</p>
</div>
</li>
<li>
<div class="collapsible-header"><i class="material-icons">shopping_cart</i>Shopping list</div>
<div class="collapsible-body">
<span>All ingedients from your meal plan are added to the shopping list. Tell Recepturer what type of product each ingredient is and it will arrange them in the right order for you to pick them up at your grocies store.</span>
<p>
<img class="materialboxed" width="100%" src="screenshots/shoppinglist.png">
</p>
</div>
</li>
</ul>
</div>
</div>
<!-- App -->
<header v-cloak v-if="page!='start'">
<a data-target="nav-mobile" class="top-nav sidenav-trigger btn-floating btn-large teal lighten-3 waves-effect waves-light hide-on-large-only" style="margin: 15px;">
<i class="material-icons">menu</i>
</a>
<ul id="nav-mobile" class="sidenav sidenav-fixed">
<li class="center-align" style="padding-top: 20px;">
<img src="resources/faviconio-logo/r.svg" />
<img src="resources/faviconio-logo/recepturer.svg" width="80%" />
</li>
<li>
<div class="divider"></div>
</li>
<li class="bold sidenav-close" :class="{active: page=='recipes' || page=='recipe' }">
<a :href=" '#/recipes/'" class="waves-effect waves-teal"><i class="material-icons">blender</i>Recipes <span class="new badge" data-badge-caption="">{{this.recipes.length}}</span></a>
</li>
<li class="bold sidenav-close" :class="{active: page=='mealplan' }">
<a :href=" '#/mealplan/'" class="waves-effect waves-teal"><i class="material-icons">menu_book</i>Meal plan <span class="new badge" data-badge-caption="" v-if="this.mealplan.length> 0">{{this.mealplan.length}}</span>
</a>
</li>
<li class="bold sidenav-close" :class="{active: page=='shoppinglist'}">
<a :href="'#/shoppinglist/'" class="waves-effect waves-teal"><i class="material-icons">shopping_cart</i>Shopping list <span class="new badge" data-badge-caption="" v-if="shoppinglistArranged.length > 0">{{ shoppinglistArranged.reduce(function(total, category) {return total + category.ingredients.filter(ingredient => ingredient.checked).length;}, 0) }} / {{ shoppinglistArranged.reduce(function(total, category) {return total + category.ingredients.length;}, 0) }}</span></a>
</li>
<li>
<a class="subheader">Configuration</a>
</li>
<li class="bold sidenav-close" :class="{active: page=='administration'}">
<a :href="'#/administration/'" class="waves-effect waves-teal"><i class="material-icons">tune</i>Administration</a>
</li>
<li>
<a class="subheader">{{ storage.location=='dropbox' ?"Dropbox" :"Storage" }}</a>
</li>
<li class="bold sidenav-close" v-if="storage.location=='dropbox'">
<a @click="dropboxSave()" v-if="!storage.outstandingChanges" class="waves-effect waves-teal grey-text"><i class="material-icons">published_with_changes</i>Up to date</a>
<a @click="dropboxSave()" v-if="storage.outstandingChanges" class="waves-effect waves-teal"><i class="material-icons">hourglass_empty</i>Unsaved changes</a>
<a @click="dropboxLogout()" class="waves-effect waves-teal"><i class="material-icons">logout</i>Log out</a>
</li>
<li class="bold sidenav-close" v-if="storage.location=='file'">
<a @click="dropboxLogout()" class="waves-effect waves-teal"><i class="material-icons">logout</i>Exit</a>
</li>
<li v-if="isDebug()">
<div class="divider"></div>
</li>
<li v-if="isDebug()">
<a class="subheader">Development</a>
</li>
<li class="bold sidenav-close" :class="{active: page=='debug'}" v-if="isDebug()">
<a :href="'#/debug'" class="waves-effect waves-teal"><i class="material-icons">adb</i>Debug</a>
</li>
</ul>
</header>
<main class="container">
<main v-if="page=='recipes'">
<recipes :recipes="recipes" />
</main>
<main v-if="page=='recipe'">
<recipe :recipe="recipe" />
</main>
<main v-if="page=='mealplan'">
<mealplan :mealplan="mealplan" />
</main>
<main v-if="page=='shoppinglist'">
<shoppinglist :mealplan="mealplan" :shoppinglist="shoppinglist" :categories="categories" />
</main>
<main v-if="page=='administration'">
<administration :settings="settings" />
</main>
<main v-if="page=='debug'">
<debug :recipes="recipes" />
</main>
</main>
</div>
<script type="application/javascript">
var rcp;
// DOM bindings
var recepturer = new Vue({
el: "#recepturer",
data: {
page: null,
"recipe": {
"id": "",
"title": "",
"description": "",
"directions": ""
},
recipes: [],
mealplan: [],
shoppinglist: [],
categories: [],
settings: {
unitofmeasure: [],
temperature: [],
time: []
},
storage: {
location: null,
outstandingChanges: false
}
},
computed: {
shoppinglistArranged: function() {
// Calculate exact quantity based on "recipe for" and people
var ingredients = this.mealplan.map(recipe => {
return rcp.parse(recipe.directions).map(ingredient => {
ingredient.quantity = ingredient.quantity / recipe.for * recipe.people;
return ingredient;
});
});
// Combine ingredients from mealplan with (ad hoc) shoppinglist
ingredients = ingredients.flat().map(ingredient => {
ingredient.checked = false;
return ingredient;
})
ingredients = ingredients.concat(this.shoppinglist);
ingredients = rcp.aggregate(ingredients);
// Group and by categories
ingredients = ingredients.map(ingredient => {
ingredient.category = (this.categories.find(category => category.products.find(product => product.name == ingredient.product)) || {
name: "Unarranged"
}).name;
return ingredient;
});
ingredients = ingredients.reduce((output, ingredient) => {
var existing = output.find(category => category.name == ingredient.category);
if (existing) {
existing.ingredients.push(ingredient);
} else {
output.push({
name: ingredient.category,
ingredients: [ingredient]
});
}
return output;
}, []);
ingredients.sort((a, b) => {
var c = this.categories.findIndex(category => category.name == a.name);
var d = this.categories.findIndex(category => category.name == b.name);
return (c < 0 ? 999 : c) - (d < 0 ? 999 : d);
});
return ingredients;
}
},
mounted() {
var dropboxAuth = JSON.parse(window.localStorage.getItem("dropboxAuth"));
if (dropboxAuth) {
this.dropboxLoad();
}
},
created: function() {
rcp = new Recepturer();
rcp.settings(this.settings);
},
watch: {
recipes: {
handler: function() {
this.autoSave();
},
deep: true
},
mealplan: {
handler: function() {
this.autoSave();
},
deep: true
},
shoppinglist: {
handler: function() {
this.autoSave();
},
deep: true
},
categories: {
handler: function() {
this.autoSave();
},
deep: true
},
settings: {
handler: function() {
this.autoSave();
},
deep: true
}
},
methods: {
autoSave: function() {
// Delay saving until no changes have been made for 1 seconds
recepturer.storage.outstandingChanges = true;
clearTimeout(this.autoSaveTimeout);
this.autoSaveTimeout = setTimeout(function() {
recepturer.dropboxSave();
}, 1 * 1000);
},
dropboxConnect: function() {
var dropboxAuth = JSON.parse(window.localStorage.getItem("dropboxAuth"));
if (!(dropboxAuth || {}).access_token) {
var dbx = new Dropbox.Dropbox({
clientId: 'ssfj3kbdixnrev9'
});
var authUrl = dbx.auth.getAuthenticationUrl(`${window.location.protocol}//${window.location.host}${window.location.pathname}`)
.then(function(authUrl) {
// Open URL for authentication
document.location = authUrl;
});
}
},
dropboxLoad: function() {
var dropboxAuth = JSON.parse(window.localStorage.getItem("dropboxAuth"));
var dbx = new Dropbox.Dropbox({
accessToken: dropboxAuth.access_token
});
dbx.filesListFolder({
path: ''
})
.then(function(response) {
dbx.filesDownload({
path: response.result.entries.find(file => file.name == "recepturer.json").path_display
})
.then(file => file.result.fileBlob.text())
.then(function(data) {
recepturer.storage.location = "dropbox";
recepturer.load(JSON.parse(data));
})
.catch(function(error) {
console.error("Error processing file from Dropbox:", error);
});
})
.catch(function(error) {
console.error("Error opening file from Dropbox:", error);
});
},
dropboxSave: function() {
var data = recepturer.save();
var dropboxAuth = JSON.parse(window.localStorage.getItem("dropboxAuth"));
var dbx = new Dropbox.Dropbox({
accessToken: dropboxAuth.access_token
});
// Save file
dbx.filesUpload({
path: '/recepturer.json',
contents: JSON.stringify(data),
mode: {
".tag": "overwrite"
}
})
.then(function(response) {
recepturer.storage.outstandingChanges = false;
})
.catch(function(error) {
console.error("Error saving file to Dropbox:", error);
});
},
dropboxLogout: function() {
localStorage.removeItem("dropboxAuth");
document.location.href = "#/";
document.location.reload();
},
loadNew: function() {
recepturer.storage.location = "file";
fetch("example/new.json")
.then(function(response) {
return response.json();
}).then(function(data) {
recepturer.load(data);
});
},
loadDemo: function() {
recepturer.storage.location = "file";
fetch("example/demo.json")
.then(function(response) {
return response.json();
}).then(function(data) {
recepturer.load(data);
});
},
load: function(data) {
recepturer.recipes = data.recipes;
recepturer.mealplan = data.mealplan;
recepturer.shoppinglist = data.shoppinglist;
recepturer.categories = data.categories;
recepturer.settings = data.settings;
rcp.settings(recepturer.settings);
if (recepturer.page == "start") {
recepturer.page = "recipes";
}
router();
},
save: function() {
var data = {
recipes: this.recipes,
mealplan: this.mealplan,
shoppinglist: this.shoppinglist,
categories: this.categories,
settings: this.settings
}
return data;
},
isDebug: function() {
if (window.sessionStorage.getItem("isDebug") != "on") {
// This function will detect whether Dev Tools are on, and if so, enable debug mode for the session
var t1 = new Date();
debugger;
if (new Date() - t1 > 200) {
window.sessionStorage.setItem("isDebug", "on");
} else {
window.sessionStorage.setItem("isDebug", "off");
}
}
return (window.sessionStorage.getItem("isDebug") == "on" ? true : false);
},
isOnMealplan: function(recipe) {
return this.$root.mealplan.some(r => r.id == recipe.id);
},
addToMealPlan: function(recipe, people) {
recipe.people = people;
this.$root.mealplan.push(recipe);
},
removeFromMealPlan: function(recipe) {
var i = this.$root.mealplan.findIndex(r => r.id == recipe.id);
if (i > -1) {
this.$delete(this.$root.mealplan, i);
}
},
clearMealPlanAndShoppingList: function() {
if (window.confirm("Are you sure you want to clear the Meal plan and Shopping list?")) {
this.$root.mealplan = [];
this.$root.shoppinglist = [];
}
}
}
});
function router() {
var url = document.location.hash.split("/");
document.title = `Recepturer`;
switch (url[1]) {
case "recipes":
recepturer.page = url[1];
document.title = `Recepturer - Recipes`;
break;
case "recipe":
recepturer.page = url[1];
recepturer.recipe = recepturer.recipes.find(recipe => recipe.id == url[2]);
if (recepturer.recipe) {
document.title = `Recepturer - ${recepturer.recipe.title || "New recipe"}`;
} else {
document.title = `Recepturer - Recipes`;
}
break;
case "mealplan":
recepturer.page = url[1];
document.title = `Recepturer - Meal plan`;
break;
case "shoppinglist":
recepturer.page = url[1];
document.title = `Recepturer - Shopping list`;
break;
case "administration":
recepturer.page = "administration";
break;
case "debug":
recepturer.page = "debug";
break;
default:
// Unknown link, do nothing
if (recepturer.settings.temperature.length == 0) {
recepturer.page = "start";
} else {
recepturer.page = "recipes";
}
document.title = `Recepturer`;
break;
}
if (document.location.hash.includes("access_token=") && document.location.hash.includes("account_id=")) {
var dropboxAuth = Object.fromEntries(document.location.hash.substr(1).split("&").map(item => item.split("=")));
localStorage.setItem("dropboxAuth", JSON.stringify(dropboxAuth));
document.location.href = "#/";
document.location.reload();
}
window.setTimeout(function() {
M.AutoInit();
}, 50)
}
window.addEventListener("hashchange", router);
router();
window.onbeforeunload = function() {
if (recepturer.storage.outstandingChanges) {
return "You have unsaved changes. Are you sure you want to leave?";
}
}
</script>
<!-- Dependencies -->
<script type="application/javascript">
M.AutoInit();
</script>
</body>
</html>