Skip to content

Commit

Permalink
🐛fix: edit deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
D10S0VSkY-OSS committed Nov 11, 2023
1 parent 3245d4c commit be74f1c
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 162 deletions.
83 changes: 45 additions & 38 deletions sld-dashboard/app/base/static/assets/js/pagination.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,76 @@
$(document).ready(function(){
var rowsPerPage = 10; // Valor inicial
var rows = $('#myTable tr');
var filteredRows = rows; // Inicialmente, todas las filas son el conjunto filtrado
var pagesCount;
var currentPage = 1;
$(document).ready(function(){
var rowsPerPage = 10; // Valor inicial
var rows = $('#myTable tr');
var filteredRows = rows; // Inicialmente, todas las filas son el conjunto filtrado
var pagesCount;
var currentPage = 1;

function displayPage(page) {
function displayPage(page) {
var start = (page - 1) * rowsPerPage;
var end = start + rowsPerPage;
rows.hide();
filteredRows.slice(start, end).show();
}
}

function setupPagination() {
function setupPagination() {
pagesCount = Math.ceil(filteredRows.length / rowsPerPage);
$('.pagination .number-page').remove(); // Remove old page numbers
for (var i = 1; i <= pagesCount; i++) {
$('<li class="page-item number-page"><a class="page-link" href="#">' + i + '</a></li>')
.insertBefore("#next-page")
.on('click', function(e) {
e.preventDefault();
currentPage = parseInt($(this).text());
displayPage(currentPage);
$(".pagination .number-page").removeClass('active');
$(this).addClass('active');
});
$('<li class="page-item number-page"><a class="page-link" href="#">' + i + '</a></li>')
.insertBefore("#next-page")
.on('click', function(e) {
e.preventDefault();
currentPage = parseInt($(this).text());
displayPage(currentPage);
$(".pagination .number-page").removeClass('active');
$(this).addClass('active');
});
}
displayPage(1);
}
}

$("#myInput").on("keyup", function() {
// Event Delegation for edit buttons and other interactive elements
$(document).on('click', '.edit-button', function() {
// Aquí iría el código para manejar la edición
});

// Existing search functionality
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
filteredRows = rows.filter(function() {
return $(this).text().toLowerCase().indexOf(value) > -1;
return $(this).text().toLowerCase().indexOf(value) > -1;
});
currentPage = 1; // Reset to first page
currentPage = 1;
setupPagination();
});
});

// Handle row per page selection
$(".dropdown-menu a").on("click", function(e) {
// Existing dropdown functionality
$(".dropdown-menu a").on("click", function(e) {
e.preventDefault();
var selectedValue = $(this).text().trim();
rowsPerPage = selectedValue.toLowerCase() === 'all' ? rows.length : parseInt(selectedValue);
currentPage = 1; // Reset to first page
setupPagination();
});
});

// Setup initial pagination
setupPagination();
// Initial setup
setupPagination();

// Previous and Next button logic
$("#previous-page").on('click', function(e) {
// Previous and Next button logic
$("#previous-page").on('click', function(e) {
e.preventDefault();
if (currentPage > 1) {
currentPage--;
displayPage(currentPage);
currentPage--;
displayPage(currentPage);
}
});
});

$("#next-page").on('click', function(e) {
$("#next-page").on('click', function(e) {
e.preventDefault();
if (currentPage < pagesCount) {
currentPage++;
displayPage(currentPage);
currentPage++;
displayPage(currentPage);
}
});
});
});
});
d
85 changes: 85 additions & 0 deletions sld-dashboard/app/base/static/assets/js/pagination_edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
document.addEventListener("DOMContentLoaded", function() {
var rowsPerPage = 10;
var table = document.getElementById("table");
var tbody = table.getElementsByTagName("tbody")[0];
var rows = Array.from(tbody.getElementsByTagName("tr"));
var pagination = document.querySelector(".pagination");
var currentPage = 1;

function displayPage(page, rowsToShow) {
var start = (page - 1) * rowsPerPage;
var end = start + rowsPerPage;
rows.forEach(row => row.style.display = "none");
rowsToShow.slice(start, end).forEach(row => row.style.display = "");
}

function setupPagination(rowsToShow) {
pagination.innerHTML = '';
var pagesCount = Math.ceil(rowsToShow.length / rowsPerPage);

// Previous page button
var prevPageItem = document.createElement("li");
prevPageItem.className = "page-item";
var prevPageLink = document.createElement("a");
prevPageLink.className = "page-link";
prevPageLink.href = "#";
prevPageLink.innerText = "Previous";
prevPageItem.appendChild(prevPageLink);
pagination.appendChild(prevPageItem);

// Page number buttons
for (var i = 1; i <= pagesCount; i++) {
var pageItem = document.createElement("li");
pageItem.className = "page-item";
var pageLink = document.createElement("a");
pageLink.className = "page-link";
pageLink.href = "#";
pageLink.innerText = i;
pageItem.appendChild(pageLink);
pagination.appendChild(pageItem);

pageLink.addEventListener("click", function(e) {
e.preventDefault();
currentPage = parseInt(this.innerText);
displayPage(currentPage, rowsToShow);
});
}

// Next page button
var nextPageItem = document.createElement("li");
nextPageItem.className = "page-item";
var nextPageLink = document.createElement("a");
nextPageLink.className = "page-link";
nextPageLink.href = "#";
nextPageLink.innerText = "Next";
nextPageItem.appendChild(nextPageLink);
pagination.appendChild(nextPageItem);

prevPageLink.addEventListener("click", function(e) {
e.preventDefault();
if (currentPage > 1) {
displayPage(--currentPage, rowsToShow);
}
});

nextPageLink.addEventListener("click", function(e) {
e.preventDefault();
if (currentPage < pagesCount) {
displayPage(++currentPage, rowsToShow);
}
});

displayPage(1, rowsToShow); // Display the first page
}

function updateSearchAndPagination() {
var filter = document.getElementById("search").value.toUpperCase();
var filteredRows = rows.filter(row => row.textContent.toUpperCase().indexOf(filter) > -1);
currentPage = 1;
setupPagination(filteredRows);
}

document.getElementById("search").addEventListener("keyup", updateSearchAndPagination);

setupPagination(rows); // Initial setup with all rows
});
48 changes: 14 additions & 34 deletions sld-dashboard/app/home/templates/deploys-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ <h2 class="h4">All Deploys</h2>
<div class="col col-md-6 col-lg-3 col-xl-4">
<div class="input-group">
<span class="input-group-text" id="asic-addon2"><span class="fas fa-search"></span></span>
<input type="text" class="form-control" id="myInput" placeholder="Search" aria-label="Search" aria-describedby="basic-addon2">
<input type="text" class="form-control" id="search" placeholder="Search" aria-label="Search" aria-describedby="basic-addon2">
</div>
</div>
<div class="col-4 col-md-2 col-xl-1 pl-md-0 text-right">
Expand All @@ -62,6 +62,7 @@ <h2 class="h4">All Deploys</h2>
<a class="nav-link icon-notifications text-dark" href="/deploys-list">
<span class="fas fa-redo-alt mr-1"></span></a>
<div class="btn-group">
<!--
<button class="btn btn-link text-dark dropdown-toggle dropdown-toggle-split m-0 p-0"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="icon icon-sm icon-gray">
Expand All @@ -72,13 +73,9 @@ <h2 class="h4">All Deploys</h2>
<div class="dropdown-menu dropdown-menu-xs dropdown-menu-right">
<span class="dropdown-item font-weight-bold text-dark">Show</span>
<a class="dropdown-item d-flex font-weight-bold" href="/deploys-list">All <span
class="icon icon-small ml-auto"><span class="fas fa-check"></span></span></a>
<a class="dropdown-item font-weight-bold" href="/deploys-list/5">5</a>
<a class="dropdown-item font-weight-bold" href="/deploys-list/55">10</a>
<a class="dropdown-item font-weight-bold" href="/deploys-list/75">20</a>
<a class="dropdown-item font-weight-bold" href="/deploys-list/90">30</a>
<a class="dropdown-item font-weight-bold" href="/deploys-list/100">40</a>
class="small ml-auto"><span class="fas fa-check"></span></span></a>
</div>
-->
</div>
</div>
</div>
Expand Down Expand Up @@ -110,7 +107,7 @@ <h2 class="h4">All Deploys</h2>
<th></th>
</tr>
</thead>
<tbody id="myTable">
<tbody>
<!-- Item -->
{% for deploy in deploys| sort(attribute='id') %}

Expand Down Expand Up @@ -336,35 +333,18 @@ <h5 class="modal-title" id="DeleteModalLongTitle-{{deploy.id}}">Delete Deploy
</tbody>
</table>
<div class="card-footer px-3 border-0 d-flex align-items-center justify-content-between">
<nav aria-label="Page navigation example">
<ul class="pagination mb-0">
<li class="page-item">
</li>
<li class="page-item active">
</li>
<li class="page-item">
</li>
<li class="page-item">
</li>
<li class="page-item">
</li>
<li class="page-item">
</li>
<li class="page-item">
</li>
</ul>
<!-- Pagination -->
<nav>
<ul class="pagination">
<li class="page-item" id="previous-page"><a class="page-link" href="#">Previous</a></li>
<!-- Page numbers will be dynamically inserted here -->
<li class="page-item" id="next-page"><a class="page-link" href="#">Next</a></li>
</ul>
</nav>
<div class="font-weight-bold small"></div>
</div>
</div>
<!-- Pagination -->
<nav>
<ul class="pagination">
<li class="page-item" id="previous-page"><a class="page-link" href="#">Previous</a></li>
<!-- Page numbers will be dynamically inserted here -->
<li class="page-item" id="next-page"><a class="page-link" href="#">Next</a></li>
</ul>
</nav>



{% include 'includes/footer.html' %}
Expand All @@ -375,5 +355,5 @@ <h5 class="modal-title" id="DeleteModalLongTitle-{{deploy.id}}">Delete Deploy

<!-- Specific Page JS goes HERE -->
{% block javascripts %}
<script src="/static/assets/js/pagination.js"></script>
<script src="/static/assets/js/pagination_edit.js"></script>
{% endblock javascripts %}
89 changes: 1 addition & 88 deletions sld-dashboard/app/home/templates/stacks-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,92 +190,5 @@ <h5 class="modal-title" id="SyncModalLongTitle-{{stack.stack_name}}">Remove Repo
}

</script>
<script>
document.addEventListener("DOMContentLoaded", function() {
var rowsPerPage = 10;
var table = document.getElementById("table");
var tbody = table.getElementsByTagName("tbody")[0];
var rows = Array.from(tbody.getElementsByTagName("tr"));
var pagination = document.querySelector(".pagination");
var currentPage = 1;

function displayPage(page, rowsToShow) {
var start = (page - 1) * rowsPerPage;
var end = start + rowsPerPage;
rows.forEach(row => row.style.display = "none");
rowsToShow.slice(start, end).forEach(row => row.style.display = "");
}

function setupPagination(rowsToShow) {
pagination.innerHTML = '';
var pagesCount = Math.ceil(rowsToShow.length / rowsPerPage);

// Previous page button
var prevPageItem = document.createElement("li");
prevPageItem.className = "page-item";
var prevPageLink = document.createElement("a");
prevPageLink.className = "page-link";
prevPageLink.href = "#";
prevPageLink.innerText = "Previous";
prevPageItem.appendChild(prevPageLink);
pagination.appendChild(prevPageItem);

// Page number buttons
for (var i = 1; i <= pagesCount; i++) {
var pageItem = document.createElement("li");
pageItem.className = "page-item";
var pageLink = document.createElement("a");
pageLink.className = "page-link";
pageLink.href = "#";
pageLink.innerText = i;
pageItem.appendChild(pageLink);
pagination.appendChild(pageItem);

pageLink.addEventListener("click", function(e) {
e.preventDefault();
currentPage = parseInt(this.innerText);
displayPage(currentPage, rowsToShow);
});
}

// Next page button
var nextPageItem = document.createElement("li");
nextPageItem.className = "page-item";
var nextPageLink = document.createElement("a");
nextPageLink.className = "page-link";
nextPageLink.href = "#";
nextPageLink.innerText = "Next";
nextPageItem.appendChild(nextPageLink);
pagination.appendChild(nextPageItem);

prevPageLink.addEventListener("click", function(e) {
e.preventDefault();
if (currentPage > 1) {
displayPage(--currentPage, rowsToShow);
}
});

nextPageLink.addEventListener("click", function(e) {
e.preventDefault();
if (currentPage < pagesCount) {
displayPage(++currentPage, rowsToShow);
}
});

displayPage(1, rowsToShow); // Display the first page
}

function updateSearchAndPagination() {
var filter = document.getElementById("search").value.toUpperCase();
var filteredRows = rows.filter(row => row.textContent.toUpperCase().indexOf(filter) > -1);
currentPage = 1;
setupPagination(filteredRows);
}

document.getElementById("search").addEventListener("keyup", updateSearchAndPagination);

setupPagination(rows); // Initial setup with all rows
});
</script>

<script src="/static/assets/js/pagination_edit.js"></script>
{% endblock javascripts %}
Loading

0 comments on commit be74f1c

Please sign in to comment.