This repository has been archived by the owner on May 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browse.js
130 lines (116 loc) · 4.55 KB
/
browse.js
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
//file that renderers events and sends them to main
const { ipcRenderer } = require('electron')
const { remote } = require('electron'),
currWindow = remote.getCurrentWindow();
window.$ = window.jQuery = require('jquery');
//sends message to main for debugging
function log(message){
ipcRenderer.send('log', message)
}
var returnarr;
//when main sends back a response message it will be received here
//listens for button to be clicked and requests data form main
$( document ).ready(function() {
ipcRenderer.send('first_recipe', "");
});
//displays random recipe into html file
ipcRenderer.on('first_recipe', (event, arg ) => {
//getting a handle on the table and clearing it
let table = document.getElementById('tableId');
table.innerHTML = "";
if(arg.length === 0){
var tr = document.createElement('tr');
var cell1 = document.createElement('td');
cell1.innerHTML = "No recipes found";
tr.appendChild(cell1);
table.appendChild(tr);
returnarr = arg;
}
else{
returnarr = arg;
//making headings
var tr = document.createElement('tr');
var cell0 = document.createElement('td');
var cell1 = document.createElement('td');
var cell2 = document.createElement('td');
//var cell3 = document.createElement('td');
var cell4 = document.createElement('td');
var cell5 = document.createElement('td');
var cell6 = document.createElement('td');
cell0.innerHTML = "";
cell1.innerHTML = "Recipe Name";
cell2.innerHTML = "Ingredients";
//cell3.innerHTML = " ";
cell4.innerHTML = "Origin";
cell5.innerHTML = "Prep-time";
cell6.innerHTML = "Course";
tr.appendChild(cell0);
tr.appendChild(cell1);
tr.appendChild(cell2);
//tr.appendChild(cell3);
tr.appendChild(cell4);
tr.appendChild(cell5);
tr.appendChild(cell6);
tr.id = "title";
table.appendChild(tr);
//for every recipe returned make a new table row
for(var i = 0; i < arg.length; i++){
let ingString = '';
let dirString = '';
var tr = document.createElement('tr');
tr.id = i;
var image_cell = document.createElement('td');
var recipe_cell = document.createElement('td');
var ingredient_cell = document.createElement('td');
//var direction_cell = document.createElement('td');
var origin_cell = document.createElement('td');
var preptime_cell = document.createElement('td');
var course_cell = document.createElement('td');
//origin.textContent = arg[i].origin;
//prep.textContent = arg[i].prep;
//course.textContent = arg[i].course;
//parse out ingredients string
for(let j = 0; j < arg[i].ingredients.length; j++){
if(j == arg[i].ingredients.length - 1){
ingString += arg[i].ingredients[j];
}
else{
ingString += arg[i].ingredients[j] + ", ";
}
}
//parse out directions string
for(let j = 0; j < arg[i].directions.length; j++){
if(j == arg[i].directions.length - 1){
dirString += arg[i].directions[j];
}
else{
dirString += arg[i].directions[j] + ", ";
}
}
//fill cells with appropriate data
if (arg[i].img != "") image_cell.innerHTML = "<img src = 'images/" + arg[i].img + " 'width = 128px height = 128px> </img>";
else image_cell.innerHTML = "";
recipe_cell.innerHTML = arg[i].recipename;
ingredient_cell.innerHTML = ingString;
//direction_cell.innerHTML = dirString;
origin_cell.innerHTML = arg[i].origin;
preptime_cell.innerHTML = arg[i].prep;
course_cell.innerHTML = arg[i].course;
//add rows to the table
tr.appendChild(image_cell);
tr.appendChild(recipe_cell);
tr.appendChild(ingredient_cell);
//tr.appendChild(direction_cell);
tr.appendChild(origin_cell);
tr.appendChild(preptime_cell);
tr.appendChild(course_cell);
table.appendChild(tr);
}
}
})
$("#tableId").on('click', 'tr', function() {
var rowid = this.id;
if(rowid !== "title"){
ipcRenderer.send('display_recipe', returnarr[rowid], 0, "browse");
}
});