-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
189 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
$(document).ready(function () { | ||
const pathSegments = window.location.pathname.split('/'); | ||
const worldcupId = pathSegments[2]; // '12345' | ||
console.log(worldcupId); | ||
getRoundTypes(worldcupId); | ||
|
||
let roundType = null; | ||
$("#roundTypesContainer").on("click", "button", function () { | ||
roundType = $(this).data("round-type"); | ||
selectRoundTypes(worldcupId, roundType) | ||
}); | ||
|
||
} | ||
); | ||
|
||
function selectRoundTypes(worldcupId, roundType) { | ||
|
||
$.ajax({ | ||
url: `/api/v1/worldcup/${worldcupId}/game?initRound=${roundType}`, | ||
type: 'POST', | ||
contentType: `application/json`, | ||
success: function (data, textStatus, xhr) { | ||
console.log(data.gameId); | ||
redirect(`/game/${data.gameId}`); //TODO: 설정해줘야됨 | ||
|
||
}, | ||
error: function () { | ||
alert("selectRoundTypes Error"); | ||
}, | ||
|
||
}) | ||
} | ||
|
||
function getRoundTypes(worldcupId) { | ||
$.ajax({ | ||
url: `/api/v1/worldcup/${worldcupId}/roundTypes`, | ||
type: "GET", | ||
dataType: "json", | ||
success: function (data, textStatus, xhr) { | ||
renderPage(data, worldcupId); | ||
console.log("success"); | ||
}, | ||
error: function () { | ||
alert("getRoundTypes Error"); | ||
}, | ||
}) | ||
} | ||
|
||
function renderPage(data, worldcupId) { | ||
let roundTypes = data.roundTypes; | ||
let container = $("#roundTypesContainer"); | ||
|
||
$("#worldcup-title").text(data.title); | ||
roundTypes.forEach(round => { | ||
let btnDiv = $("<div></div>").addClass("text-center"); | ||
let btn = $("<button></button>") | ||
.text(`${round}강`) | ||
.attr("data-round-type", round) | ||
.attr("id", `round-type-${round}`) | ||
container.append(btnDiv.append(btn)); | ||
}) | ||
} | ||
|
||
function redirect(targetUrl) { | ||
window.location.href = getBaseUrl() + targetUrl; | ||
} | ||
|
||
function getBaseUrl() { | ||
return window.location.protocol + "//" + window.location.host; | ||
} |
Oops, something went wrong.