-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
146 lines (137 loc) · 5.19 KB
/
Copy pathscripts.js
File metadata and controls
146 lines (137 loc) · 5.19 KB
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
$(document).ready(function() {
// Função para atualizar a lista de projetos
function updateProjectList() {
$.ajax({
type: "GET",
url: "get_projects.php",
dataType: "json",
success: function(response) {
$("#project-list").empty();
response.forEach(function(project) {
$("#project-list").append(
"<tr>" +
"<td>" + project.project + "</td>" +
"<td>" + project.status + "</td>" +
"<td>" + getUsername(project.user_id) + "</td>" +
"<td>" + getUsername(project.last_user) + "</td>" +
"<td>" +
(project.status === "available" ?
("<button class='btn btn-success start-deploy-button' data-project='" + project.project + "'>Iniciar Deploy</button>") :
("<button class='btn btn-primary complete-deploy-button' data-project='" + project.project + "'>Concluir Deploy</button>")
) +
"</td>" +
"</tr>"
);
});
}
});
}
// Função para obter o nome de usuário com base no ID
function getUsername(user_id) {
var username = "Desconhecido";
$.ajax({
type: "GET",
async: false,
url: "get_username.php",
data: { user_id: user_id },
dataType: "json",
success: function(response) {
username = response.username;
}
});
return username;
}
// Atualizar a lista de projetos ao carregar a página
updateProjectList();
// Tratamento de clique no botão de exclusão
$(document).on('click', '.delete-project-button', function() {
var project = $(this).data('project');
console.log('Clique no botão de exclusão para o projeto:', project);
// Exibir confirmação de exclusão
var shouldDelete = confirm('Tem certeza que deseja excluir o projeto ' + project + '?');
if (shouldDelete) {
// Realizar ação de exclusão
$.ajax({
url: 'delete_project.php',
method: 'POST',
data: { project: project },
dataType: 'json',
success: function(response) {
if (response.success) {
// Recarregar a página para atualizar a lista de projetos
location.reload();
} else {
alert(response.message);
}
},
error: function() {
alert('Ocorreu um erro ao excluir o projeto.');
}
});
}
});
// Exibir o formulário de adicionar projeto ao clicar no botão
$("#add-project-button").click(function() {
$("#add-project-form").show();
});
// Enviar requisição para adicionar projeto
$("#project-form").submit(function(event) {
event.preventDefault();
$.ajax({
type: "POST",
url: "add_project.php",
data: $(this).serialize(),
dataType: "json",
success: function(response) {
if (response.success) {
location.reload();
} else {
alert(response.message);
}
},
error: function() {
alert("Erro ao adicionar projeto. Por favor, tente novamente.");
}
});
});
// Iniciar deploy ao clicar no botão "Iniciar Deploy"
$(document).on("click", ".start-deploy-button", function() {
var project = $(this).data("project");
$.ajax({
type: "POST",
url: "start_deploy.php",
data: { project: project },
dataType: "json",
success: function(response) {
if (response.success) {
updateProjectList();
} else {
alert(response.message);
}
},
error: function() {
alert("Erro ao iniciar o deploy. Por favor, tente novamente.");
}
});
});
// Concluir deploy ao clicar no botão "Concluir Deploy"
$(document).on("click", ".complete-deploy-button", function() {
var project = $(this).data("project");
$.ajax({
type: "POST",
url: "complete_deploy.php",
data: { project: project },
dataType: "json",
success: function(response) {
if (response.success) {
updateProjectList();
} else {
alert(response.message);
}
},
error: function() {
alert("Erro ao concluir o deploy. Por favor, tente novamente.");
}
});
});
});