-
Notifications
You must be signed in to change notification settings - Fork 0
/
front.html
148 lines (129 loc) · 4.67 KB
/
front.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shortest Path Finder</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: black;
color: white;
padding-top: 50px;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
position: relative;
}
.select-container {
position: absolute;
top: 20px;
left: 0;
right: 0;
background-color: black;
z-index: 1;
padding: 10px;
}
select {
padding: 10px;
font-size: 16px;
margin: 10px;
background-color: black;
color: white;
}
.images {
display: flex;
justify-content: space-around;
margin-top: 20px;
}
.placeholder {
width: 100px;
height: 100px;
}
img {
width: 250px;
height: 250px;
margin: 10px;
}
</style>
</head>
<body>
<div class="select-container">
<select id="artist1">
<option value="">Selecione um artista</option>
</select>
<select id="artist2">
<option value="">Selecione um artista</option>
</select>
<button onclick="mostrarMenorCaminho()">Encontrar Caminho</button>
</div>
<div class="container" style="display: flex; flex-direction: column;">
<div class="images" id="artist-images">
<div id="artist1-image" class="placeholder"></div>
<div id="artist2-image" class="placeholder"></div>
</div>
<div id="path" style="margin-top: 50px;"></div>
</div>
<script>
async function carregarNomesDosArtistas() {
const artist1Select = document.getElementById('artist1');
const artist2Select = document.getElementById('artist2');
const response = await fetch('http://127.0.0.1:5001/artist_ids');
const data = await response.json();
const artistIds = data.artist_ids;
for (const artistId of artistIds) {
const response = await fetch(`http://127.0.0.1:5001/artist_name/${artistId}`);
const artistData = await response.json();
const option1 = document.createElement('option');
option1.value = artistId;
option1.innerText = artistData.artist_name;
artist1Select.appendChild(option1);
const option2 = document.createElement('option');
option2.value = artistId;
option2.innerText = artistData.artist_name;
artist2Select.appendChild(option2);
}
}
async function mostrarMenorCaminho() {
const artist1Id = document.getElementById('artist1').value;
const artist2Id = document.getElementById('artist2').value;
if (!artist1Id || !artist2Id) {
alert('Por favor, selecione dois artistas.');
return;
}
const response = await fetch(`http://127.0.0.1:5001/shortest_path/${artist1Id}/${artist2Id}`);
const data = await response.json();
const path = data.path.map(node => node.nome).join(' -> ');
if(!path) {
path = 'Inexistente'
}
document.getElementById('path').innerText = `Menor caminho: ${path}`;
preencherCaminho(data.path);
}
function preencherCaminho(nodes) {
const pathContainer = document.getElementById('artist-images');
pathContainer.innerHTML = '';
for (const node of nodes) {
const artistDiv = document.createElement('div');
const image = document.createElement('img');
const name = document.createElement('p');
image.src = node.imagem_url;
image.alt = node.nome;
name.textContent = node.nome;
artistDiv.style.textAlign = 'center';
name.style.marginTop = '5px';
artistDiv.appendChild(image);
artistDiv.appendChild(name);
pathContainer.appendChild(artistDiv);
}
}
document.addEventListener('DOMContentLoaded', () => {
carregarNomesDosArtistas();
});
</script>
</body>
</html>