Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .towns.html.un~
Binary file not shown.
Binary file added .towns.js.un~
Binary file not shown.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Towns for SoftUni
Code for the Git and GitHub Exercise

#me - Editor
#jenkins - Shuffler
#docker - Styler
Binary file added final-result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions towns.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions towns.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,32 @@
<link rel="stylesheet" href="towns.css" />
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="towns.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
</head>

<body>

<h1>Towns</h1>
<article>
<header>Towns</header>
<select id="towns" size="4">
<option>Sofia</option>
<option>Plovdiv</option>
<option>Varna</option>
<option>Bourgas</option>
</select>
</article>

<div>
<article>
<header>Delete Existing Town</header>
<input type="text" id="townName" />
<button id="btnDelete">Delete</button>
</div>
<button id="btnShuffle">Shuffle</button>
<input type="text" id="townNameForAdd" />
<button id="btnAdd">Add</button>
</article>

<div id="result"></div>

</body>

</html>
</html>
29 changes: 29 additions & 0 deletions towns.html~
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>

<head>
<title>Towns</title>
<link rel="stylesheet" href="towns.css" />
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="towns.js"></script>
</head>

<body>

<h1>Towns</h1>
<select id="towns" size="4">
<option>Sofia</option>
<option>Plovdiv</option>
<option>Varna</option>
<option>Bourgas</option>
</select>

<div>
<input type="text" id="townName" />
<button id="btnDelete">Delete</button>
</div>
<div id="result"></div>

</body>

</html>
42 changes: 39 additions & 3 deletions towns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
$(document).ready(function() {
$('#btnDelete').click(deleteTown)
$('#btnDelete').click(deleteTown);
$('#btnAdd').click(addTown);
$('#btnShuffle').click(shuffleTowns);
});

function deleteTown() {
Expand All @@ -13,7 +15,41 @@ function deleteTown() {
}
}
if (removed)
$('#result').text(townName + " deleted.");
showMessage(townName + " deleted.");
else
$('#result').text(townName + " not found.");
showMessage(townName + " not found.");
}

//this is the second part of the task performed by the Styler
function showMessage(msg) {
$('#result').text(msg).css("display", "block");
setTimeout(function () {
$('#result').hide('blind', {}, 500);
}, 3000);
}

//this is intended by the Shuffler on jenkinsVM
function addTown() {
let townName = $('#townNameForAdd').val();
$('#townNameForAdd').val('');
$('#towns').append($('<option>').text(townName));
$('#result').text(townName + " added.");
}

// this is added by the Shuffler on jenkinsVM
function shuffleTowns() {
let towns = $('#towns option').toArray();
$('#towns').empty();
shuffleArray(towns);
$('#towns').append(towns);
$('#result').text("Towns shuffled.");

function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var oldElement = array[i];
array[i] = array[j];
array[j] = oldElement;
}
}
}
19 changes: 19 additions & 0 deletions towns.js~
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
$(document).ready(function() {
$('#btnDelete').click(deleteTown)
});

function deleteTown() {
let townName = $('#townName').val();
$('#townName').val('');
let removed = false;
for (let option of $('#towns option')) {
if (option.textContent == townName) {
removed = true;
option.remove();
}
}
if (removed)
$('#result').text(townName + " deleted.");
else
$('#result').text(townName + " not found.");
}