Skip to content

Commit f394ae3

Browse files
Various subscription page fixes (#161)
* Disable checkboxes when backend goes down * Replace js modal with bootstrap * Click event fix * Upload sub now resets file path * Fix tests * Check all is moved from initComplete to completion of ajax request * Implement checkbox disable on draw and status poll * Use same function for bulk and single delete * Fix comments * Fix error
1 parent 4874f19 commit f394ae3

File tree

4 files changed

+93
-98
lines changed

4 files changed

+93
-98
lines changed

src/functionaltest/java/com/ericsson/ei/frontend/TestSubscriptionHandling.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public void testSubscriptionButtons() throws Exception {
8484

8585
// Verify that "get template" button works
8686
// Download subscription template
87+
subscriptionPage.refreshPage();
8788
new WebDriverWait(driver, 10).until((webdriver) -> subscriptionPage.presenceOfClickGetTemplateButton());
8889
subscriptionPage.clickGetTemplate();
8990

src/functionaltest/java/com/ericsson/ei/frontend/pageobjects/SubscriptionPage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public void clickBulkDelete() throws IOException {
4949
bulkDeleteBtn.click();
5050
// Click confirm button to confirm delete
5151
new WebDriverWait(driver, TIMEOUT_TIMER)
52-
.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(),'confirm')]")));
53-
WebElement confirmBtn = driver.findElement(By.xpath("//button[contains(text(),'confirm')]"));
52+
.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".confirm-delete .modal-footer .btn-danger")));
53+
WebElement confirmBtn = driver.findElement(By.cssSelector(".confirm-delete .modal-footer .btn-danger"));
5454
confirmBtn.click();
5555
}
5656

src/main/resources/static/js/subscription.js

Lines changed: 72 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ jQuery(document).ready(function () {
7474
backendStatus = true;
7575
},
7676
complete: function () {
77+
if(table != undefined && table.rows().data().length == 0) {
78+
toggleCheckboxesDisabled(true);
79+
} else {
80+
toggleCheckboxesDisabled(!backendStatus);
81+
}
7782
toggleOnBackendStatus(backendStatus);
7883
setTimeout(loadSubButtons, 800);
7984
}
@@ -112,6 +117,20 @@ jQuery(document).ready(function () {
112117
toggleButtonsDisabled(!backendStatus);
113118
}
114119

120+
function toggleCheckboxesDisabled(disabled) {
121+
$('#check-all').prop("disabled", disabled);
122+
$('.data-check').prop("disabled", disabled);
123+
}
124+
125+
function toggleButtonsDisabled(disabled) {
126+
$('#addSubscription').prop("disabled", disabled);
127+
$('#bulkDelete').prop("disabled", disabled);
128+
$('#uploadSubscription').prop("disabled", disabled);
129+
$('#getTemplateButton').prop("disabled", disabled);
130+
$('#reloadButton').prop("disabled", disabled);
131+
$('.table-btn').prop("disabled", disabled);
132+
}
133+
115134
// Check if EI Backend Server is online when Status Connection button is pressed.
116135
$("#btnEIConnection").click(function () {
117136
checkBackendStatus();
@@ -382,6 +401,11 @@ jQuery(document).ready(function () {
382401
success: function (data) {
383402
isSecured = JSON.parse(ko.toJSON(data)).security;
384403
drawTable(isSecured);
404+
},
405+
complete: function() {
406+
$("#check-all").click(function () {
407+
$(".data-check").prop('checked', $(this).prop('checked'));
408+
});
385409
}
386410
});
387411
}
@@ -402,7 +426,14 @@ jQuery(document).ready(function () {
402426
"url": frontendServiceUrl + "/subscriptions",
403427
"type": "GET",
404428
"dataSrc": "", // Flat structure from EI backend REST API
405-
"error": function () { }
429+
"error": function () { },
430+
"complete": function(data) {
431+
if(data.responseJSON.length != undefined && data.responseJSON.length > 0) {
432+
toggleCheckboxesDisabled(false);
433+
} else {
434+
toggleCheckboxesDisabled(true);
435+
}
436+
}
406437
},
407438
//Set column definition initialisation properties.
408439
"columnDefs": [
@@ -486,9 +517,6 @@ jQuery(document).ready(function () {
486517
if (isSecured == false) {
487518
table.column(2).visible(false);
488519
}
489-
$("#check-all").click(function () {
490-
$(".data-check").prop('checked', $(this).prop('checked'));
491-
});
492520
$(".control").click(function () {
493521
setTimeout(function () { toggleOnBackendStatus(backendStatus); }, 50);
494522
});
@@ -519,6 +547,38 @@ jQuery(document).ready(function () {
519547
// /Stop ## Reload Table#################################################
520548

521549
// /Start ## Bulk delete#################################################
550+
function deleteSubscriptions(subscriptionsToDeleteString) {
551+
var callback = {
552+
beforeSend: function () {
553+
},
554+
success: function (data, textStatus) {
555+
reload_table();
556+
},
557+
error: function (XMLHttpRequest, textStatus, errorThrown) {
558+
reload_table();
559+
var responseJSON = JSON.parse(XMLHttpRequest.responseText);
560+
for (var i = 0; i < responseJSON.length; i++) {
561+
window.logMessages("Error deleting subscription: [" + responseJSON[i].subscription + "] Reason: [" + responseJSON[i].reason + "]");
562+
}
563+
},
564+
complete: function () {
565+
}
566+
};
567+
568+
$('.confirm-delete .modal-body').text(subscriptionsToDeleteString);
569+
$('.confirm-delete .btn-danger').unbind();
570+
$('.confirm-delete .btn-danger').click(function () {
571+
$("#check-all").prop('checked', false);
572+
var ajaxHttpSender = new AjaxHttpSender();
573+
// replace all /n with comma
574+
if(/\n/.exec(subscriptionsToDeleteString)) {
575+
subscriptionsToDeleteString = subscriptionsToDeleteString.replace(new RegExp('\n', 'g'), ',').slice(0, -1);
576+
}
577+
ajaxHttpSender.sendAjax(frontendServiceUrl + "/subscriptions/" + subscriptionsToDeleteString, "DELETE", null, callback);
578+
});
579+
$('.confirm-delete').modal('show');
580+
};
581+
522582
$("#bulkDelete").click(function () {
523583
var subscriptionsToDelete = [];
524584
var data = table.rows().nodes();
@@ -539,39 +599,7 @@ jQuery(document).ready(function () {
539599
subscriptionsToDeleteString += subscriptionsToDelete[i] + "\n";
540600
}
541601

542-
var callback = {
543-
beforeSend: function () {
544-
},
545-
success: function (data, textStatus) {
546-
//if success reload ajax table
547-
$('#modal_form').modal('hide');
548-
reload_table();
549-
},
550-
error: function (XMLHttpRequest, textStatus, errorThrown) {
551-
reload_table();
552-
var responseJSON = JSON.parse(XMLHttpRequest.responseText);
553-
for (var i = 0; i < responseJSON.length; i++) {
554-
window.logMessages("Error deleteing subscription: [" + responseJSON[i].subscription + "] Reason: [" + responseJSON[i].reason + "]");
555-
}
556-
},
557-
complete: function () {
558-
}
559-
};
560-
561-
$.confirm({
562-
title: 'Confirm!',
563-
content: 'Are you sure you want to delete these subscriptions?<pre>' + subscriptionsToDeleteString,
564-
buttons: {
565-
confirm: function () {
566-
var ajaxHttpSender = new AjaxHttpSender();
567-
// replace all /n with comma
568-
subscriptionsToDeleteString = subscriptionsToDeleteString.replace(new RegExp('\n', 'g'), ',').slice(0, -1);
569-
ajaxHttpSender.sendAjax(frontendServiceUrl + "/subscriptions/" + subscriptionsToDeleteString, "DELETE", null, callback);
570-
},
571-
cancel: function () {
572-
}
573-
}
574-
});
602+
deleteSubscriptions(subscriptionsToDeleteString);
575603
});
576604
// /Stop ## Bulk delete##################################################
577605

@@ -626,11 +654,11 @@ jQuery(document).ready(function () {
626654
}
627655
}
628656

629-
var pom = document.getElementById('upload_sub');
630-
pom.onchange = function uploadFinished() {
631-
var subscriptionFile = pom.files[0];
657+
$('#upload_sub').change(function () {
658+
var subscriptionFile = document.getElementById('upload_sub').files[0];
659+
$('#upload_sub').val("");
632660
validateJsonAndCreateSubscriptions(subscriptionFile);
633-
};
661+
});
634662
function tryToCreateSubscription(subscriptionJson) {
635663
// Send Subscription JSON file to Spring MVC
636664
// AJAX Callback handling
@@ -667,22 +695,7 @@ jQuery(document).ready(function () {
667695
// /Start ## upload_subscriptions #################################################
668696
$("#uploadSubscription").click(function () {
669697
function createUploadWindow() {
670-
// var pom = document.createElement('input');
671-
// pom.setAttribute('id', 'uploadFile');
672-
// pom.setAttribute('type', 'file');
673-
// pom.setAttribute('name', 'upFile');
674-
// pom.onchange = function uploadFinished() {
675-
// var subscriptionFile = pom.files[0];
676-
// validateJsonAndCreateSubscriptions(subscriptionFile);
677-
// };
678-
if (document.createEvent) {
679-
var event = document.createEvent('MouseEvents');
680-
event.initEvent('click', true, true);
681-
pom.dispatchEvent(event);
682-
}
683-
else {
684-
pom.click();
685-
}
698+
$('#upload_sub').click();
686699
}
687700

688701
function createUploadWindowMSExplorer() {
@@ -1113,47 +1126,12 @@ jQuery(document).ready(function () {
11131126
event.stopPropagation();
11141127
event.preventDefault();
11151128
// Get tag that contains subscriptionName
1116-
var id = $(this).attr("id").split("-")[1];
1117-
var callback = {
1118-
beforeSend: function () {
1119-
},
1120-
success: function (data, textStatus) {
1121-
//if success reload ajax table
1122-
$('#modal_form').modal('hide');
1123-
reload_table();
1124-
1125-
},
1126-
error: function (XMLHttpRequest, textStatus, errorThrown) {
1127-
window.logMessages("Error: " + XMLHttpRequest.responseText);
1128-
},
1129-
complete: function () {
1130-
}
1131-
};
1129+
var subscription = $(this).attr("id").split("-")[1];
11321130

1133-
$.confirm({
1134-
title: 'Confirm!',
1135-
content: 'Please confirm before deleting subscription!',
1136-
buttons: {
1137-
confirm: function () {
1138-
var ajaxHttpSender = new AjaxHttpSender();
1139-
ajaxHttpSender.sendAjax(frontendServiceUrl + "/subscriptions/" + id, "DELETE", null, callback);
1140-
},
1141-
cancel: function () {
1142-
}
1143-
}
1144-
});
1131+
deleteSubscriptions(subscription);
11451132
});
11461133
// /Stop ## Delete Subscription #########################################
11471134

1148-
function toggleButtonsDisabled(disabled) {
1149-
$('#addSubscription').prop("disabled", disabled);
1150-
$('#bulkDelete').prop("disabled", disabled);
1151-
$('#uploadSubscription').prop("disabled", disabled);
1152-
$('#getTemplateButton').prop("disabled", disabled);
1153-
$('#reloadButton').prop("disabled", disabled);
1154-
$('.table-btn').prop("disabled", disabled);
1155-
}
1156-
11571135
function loadTooltip() {
11581136
$('[data-toggle="tooltip"]').tooltip({ trigger: "click", html: true });
11591137
}

src/main/resources/templates/subscription.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,30 @@ <h5 class="d-inline">AND</h5>
360360
</div>
361361
<!-- /.modal-dialog -->
362362
</div>
363-
<!-- /.modal -->
363+
364+
<div class="modal fade confirm-delete" role="dialog">
365+
<div class="modal-dialog">
366+
<div class="modal-content">
367+
<div class="modal-header">Do you really want to delete subscription(s)?</div>
368+
<div class="modal-body pre"></div>
369+
<div class="modal-footer">
370+
<button type="button" class="btn btn-danger" data-dismiss="modal">Delete</button>
371+
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
372+
</div>
373+
</div>
374+
</div>
375+
</div>
376+
377+
<!-- End Bootstrap modal -->
378+
379+
<!-- /.modal_instance -->
364380
<div id="modal_info" class="modal_instance">
365381
<div class="modal_info-content">
366382
<span class="close_instance">&times;</span>
367383
<pre id="info_text"></pre>
368384
</div>
369385
</div>
370-
<!-- End Bootstrap modal -->
386+
371387

372388
<script type="text/javascript" src="resources/subscription_templates.js"></script>
373389
<script type="text/javascript" src="js/subscription.js"></script>

0 commit comments

Comments
 (0)