From 8d9e48af39c8179935012db6cf243ff30c4503a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Wed, 4 Jul 2018 08:48:36 +0900 Subject: [PATCH] Add: player list manager --- src/web/js/maestro_main.js | 70 ++----- src/web/js/player_list.js | 97 +++++---- src/web/js/player_list_manager.js | 196 ++++++++++++++++++ src/web/js/player_list_navigator.js | 58 +++--- src/web/maestro/main_menu.html | 1 + .../module/maestro_section_add_player.html | 20 +- src/web/module/maestro_section_search.html | 57 ++++- src/web/server/user/search_player.php | 66 ++++++ 8 files changed, 435 insertions(+), 130 deletions(-) create mode 100644 src/web/js/player_list_manager.js create mode 100644 src/web/server/user/search_player.php diff --git a/src/web/js/maestro_main.js b/src/web/js/maestro_main.js index 0041e4d..c7c1c94 100644 --- a/src/web/js/maestro_main.js +++ b/src/web/js/maestro_main.js @@ -1,13 +1,16 @@ let maestroID = -1; -let playerCount = 0; -let playerListPage = 0; -let lastPageNo = 0; +// let playerCount = 0; +// let playerListPage = 0; +// let lastPageNo = 0; -let addPlayerList; -let addPlayerListNavigator; +let addPlayerListManager; +let searchPlayerListManager; -let searchPlayerList; -let searchPlayerListNavigator; +// let addPlayerList; +// let addPlayerListNavigator; + +// let searchPlayerList; +// let searchPlayerListNavigator; let mouseAppList; @@ -19,47 +22,6 @@ $(document).ready(function() { console.log("maestroID : " + maestroID); }); -function loadPlayerList() { - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/user/registered_player_count.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send("maestro_id=" + maestroID); - xhr.onload = function() { - if(xhr.readyState === 4 && xhr.status === 200) { - // console.log(xhr.responseText); - // console.log(xhr.responseText.length); - if(xhr.responseText.length === 0 || xhr.responseText === null) { - console.log("no data from server"); - return; - } - - let replyJSON = JSON.parse(xhr.responseText); - // console.log(replyJSON); - - if(replyJSON === null) { - console.log("no data from server"); - return; - } - - if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { - console.log(replyJSON["ERROR"]); - return; - } - - if(replyJSON["RESULT"] === "fail") { - console.log(replyJSON["RESULT"]); - return; - } - - playerCount = replyJSON["Count"]; - - loadPlayerListPage(1); - addPlayerListNavigator.addPlayerListPages(playerCount); - } - } -} - - function tabClicked(tabNo) { // hide and show tab for(let i = 0; i < 4; i++) { @@ -98,3 +60,15 @@ function tabClicked(tabNo) { } } + +function onClickPlayerListPage(item, pageNo) { + let tagDiv = $(item).closest("div"); + let tagDivIDName = tagDiv.prop("id"); + // console.log(tagDivIDName); + + if(tagDivIDName === "add_player_list_navigator") + addPlayerListManager.onClickPlayerListPage(pageNo); + else if(tagDivIDName === "search_player_list_navigator") + searchPlayerListManager.onClickPlayerListPage(pageNo); +} + diff --git a/src/web/js/player_list.js b/src/web/js/player_list.js index 81a3b5d..5c980b7 100644 --- a/src/web/js/player_list.js +++ b/src/web/js/player_list.js @@ -15,7 +15,10 @@ class PlayerList { constructor(parent) { let self = this; this.listParent = parent; - console.log(parent); + // console.log(parent); + + this.playerCount = 0; + this.playerListPage = 1; let id_list = parent.find(".player_id"); // console.log(id_list); @@ -136,50 +139,54 @@ class PlayerList { } } } + + loadPlayerListPage(pageNo) { + self = this; + this.playerListPage = pageNo; + + let pageIndex = pageNo - 1; + let startNo = pageIndex * 10; + let endNo = pageIndex * 10 + 9; + + let xhr = new XMLHttpRequest(); //new로 생성. + xhr.open('POST', './../server/user/registered_player_list_page.php', true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo); + xhr.onload = function() { + if(xhr.readyState === 4 && xhr.status === 200) { + // console.log(xhr.responseText); + // console.log(xhr.responseText.length); + if(xhr.responseText.length === 0 || xhr.responseText === null) { + console.log("no data from server"); + return; + } + + let replyJSON = JSON.parse(xhr.responseText); + // console.log(replyJSON); + + if(replyJSON === null) { + console.log("no data from server"); + return; + } + + if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { + console.log(replyJSON["ERROR"]); + return; + } + + if(replyJSON["RESULT"] === "fail") { + console.log(replyJSON["RESULT"]); + return; + } + + // console.log(replyJSON["PlayerList"]); + // updatePlayerListPage(replyJSON["PlayerList"]); + self.updatePlayerList(replyJSON["PlayerList"]); + + self.playerCount = replyJSON["PlayerList"].length; + } + } + } } -function loadPlayerListPage(pageNo) { - playerListPage = pageNo; - - let pageIndex = pageNo - 1; - let startNo = pageIndex * 10; - let endNo = pageIndex * 10 + 9; - - let xhr = new XMLHttpRequest(); //new로 생성. - xhr.open('POST', './../server/user/registered_player_list_page.php', true); - xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); - xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo); - xhr.onload = function() { - if(xhr.readyState === 4 && xhr.status === 200) { - // console.log(xhr.responseText); - // console.log(xhr.responseText.length); - if(xhr.responseText.length === 0 || xhr.responseText === null) { - console.log("no data from server"); - return; - } - - let replyJSON = JSON.parse(xhr.responseText); - // console.log(replyJSON); - - if(replyJSON === null) { - console.log("no data from server"); - return; - } - - if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { - console.log(replyJSON["ERROR"]); - return; - } - - if(replyJSON["RESULT"] === "fail") { - console.log(replyJSON["RESULT"]); - return; - } - - // console.log(replyJSON["PlayerList"]); - // updatePlayerListPage(replyJSON["PlayerList"]); - addPlayerList.updatePlayerList(replyJSON["PlayerList"]); - } - } -} \ No newline at end of file diff --git a/src/web/js/player_list_manager.js b/src/web/js/player_list_manager.js new file mode 100644 index 0000000..70cb632 --- /dev/null +++ b/src/web/js/player_list_manager.js @@ -0,0 +1,196 @@ +class PlayerListManager { + + constructor(docList, docNav) { + let self = this; + this.docList = docList; + this.docNav = docNav; + + this.list = new PlayerList(this.docList); + this.listNavigator = new PlayerListNavigator(this.docNav); + // console.log(this.list); + // console.log(this.listNavigator); + + this.playerCount = 0; + this.activePageNo = 1; + this.lastPageNo = 0; + + } + + + setupAddPlayerList() { + let self = this; + + let xhr = new XMLHttpRequest(); //new로 생성. + xhr.open('POST', './../server/user/registered_player_count.php', true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send("maestro_id=" + maestroID); + xhr.onload = function() { + if(xhr.readyState === 4 && xhr.status === 200) { + // console.log(xhr.responseText); + // console.log(xhr.responseText.length); + if(xhr.responseText.length === 0 || xhr.responseText === null) { + console.log("no data from server"); + return; + } + + let replyJSON = JSON.parse(xhr.responseText); + // console.log(replyJSON); + + if(replyJSON === null) { + console.log("no data from server"); + return; + } + + if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { + console.log(replyJSON["ERROR"]); + return; + } + + if(replyJSON["RESULT"] === "fail") { + console.log(replyJSON["RESULT"]); + return; + } + + self.playerCount = replyJSON["Count"]; + self.lastPageNo = Math.ceil( (self.playerCount + 1) / 10 ); + self.activePageNo = 1; + + self.list.loadPlayerListPage(self.activePageNo); + self.listNavigator.updateNavigator(self.playerCount); + } + } + } + + + updateAddPlayerListPage(pageNo) { + self = this; + this.playerListPage = pageNo; + + let pageIndex = pageNo - 1; + let startNo = pageIndex * 10; + let endNo = pageIndex * 10 + 9; + + let xhr = new XMLHttpRequest(); //new로 생성. + xhr.open('POST', './../server/user/registered_player_list_page.php', true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send("maestro_id=" + maestroID + "&start_no=" + startNo + "&end_no=" + endNo); + xhr.onload = function() { + if(xhr.readyState === 4 && xhr.status === 200) { + // console.log(xhr.responseText); + // console.log(xhr.responseText.length); + if(xhr.responseText.length === 0 || xhr.responseText === null) { + console.log("no data from server"); + return; + } + + let replyJSON = JSON.parse(xhr.responseText); + // console.log(replyJSON); + + if(replyJSON === null) { + console.log("no data from server"); + return; + } + + if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { + console.log(replyJSON["ERROR"]); + return; + } + + if(replyJSON["RESULT"] === "fail") { + console.log(replyJSON["RESULT"]); + return; + } + + // console.log(replyJSON["PlayerList"]); + self.list.updatePlayerList(replyJSON["PlayerList"]); + + self.playerCount = replyJSON["PlayerList"].length; + console.log(self.playerCount); + self.listNavigator.updateNavigator(self.playerCount); + } + } + } + + updateSearchPlayerListPage(playerName, pageNo) { + let self = this; + this.playerListPage = pageNo; + + let pageIndex = pageNo - 1; + let startNo = pageIndex * 10; + let endNo = pageIndex * 10 + 9; + + let xhr = new XMLHttpRequest(); //new로 생성. + xhr.open('POST', './../server/user/registered_player_list_page.php', true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send("maestro_id=" + maestroID + "&playerName=" + playerName + "&start_no=" + startNo + "&end_no=" + endNo); + xhr.onload = function() { + if(xhr.readyState === 4 && xhr.status === 200) { + // console.log(xhr.responseText); + // console.log(xhr.responseText.length); + if(xhr.responseText.length === 0 || xhr.responseText === null) { + console.log("no data from server"); + return; + } + + let replyJSON = JSON.parse(xhr.responseText); + // console.log(replyJSON); + + if(replyJSON === null) { + console.log("no data from server"); + return; + } + + if(replyJSON["ERROR"] !== undefined || replyJSON["RESULT"] === undefined) { + console.log(replyJSON["ERROR"]); + return; + } + + if(replyJSON["RESULT"] === "fail") { + console.log(replyJSON["RESULT"]); + return; + } + + // console.log(replyJSON["PlayerList"]); + self.list.updatePlayerList(replyJSON["PlayerList"]); + + self.playerCount = replyJSON["PlayerList"].length; + self.listNavigator.updateNavigator(self.playerCount); + } + } + } + + // onClickPlayerListPage(pageNo) { + // this.listNavigator.onClickPlayerListPage(pageNo); + // } + + onClickPlayerListPage(pageNo) { + switch(pageNo) { + case "first": + this.activePageNo = 1; + this.list.loadPlayerListPage(this.activePageNo); + return; + + case "prev": + if(this.activePageNo > 1) + this.activePageNo -= 1; + this.list.loadPlayerListPage(this.activePageNo); + return; + + case "next": + if(this.activePageNo < this.lastPageNo) + this.activePageNo += 1; + this.list.loadPlayerListPage(this.activePageNo); + return; + + case "last": + this.list.loadPlayerListPage(this.lastPageNo); + return; + } + + this.activePageNo = pageNo; + this.list.loadPlayerListPage(this.activePageNo); + } + +} + + diff --git a/src/web/js/player_list_navigator.js b/src/web/js/player_list_navigator.js index eb8e118..a7d3df7 100644 --- a/src/web/js/player_list_navigator.js +++ b/src/web/js/player_list_navigator.js @@ -4,48 +4,52 @@ let self = this; this.pageNoArea = pageNoArea; // console.log(parent); + + this.activePageNo = 1; + this.lastPageNo = 1; } - addPlayerListPages(playerCount) { - lastPageNo = Math.ceil( (playerCount + 1) / 10 ); + updateNavigator(playerCount) { + this.lastPageNo = Math.ceil( (playerCount + 1) / 10 ); $(this.pageNoArea).empty(); - for(let pageNo = 1; pageNo < lastPageNo + 1; pageNo++) { + for(let pageNo = 1; pageNo < this.lastPageNo + 1; pageNo++) { $(this.pageNoArea).append( - " " + pageNo + " " + " " + pageNo + " " ); } } -} + onClickPlayerListPage(pageNo) { + switch(pageNo) { + case "first": + this.activePageNo = 1; + this.playerList.loadPlayerListPage(this.activePageNo); + return; + case "prev": + if(this.activePageNo > 1) + this.activePageNo -= 1; + this.playerList.loadPlayerListPage(this.activePageNo); + return; + case "next": + if(this.activePageNo < this.lastPageNo) + this.activePageNo += 1; + this.playerList.loadPlayerListPage(this.activePageNo); + return; -function onClickPlayerListPage(pageNo) { - switch(pageNo) { - case "first": - playerListPage = 1; - loadPlayerListPage(playerListPage); - return; + case "last": + this.playerList.loadPlayerListPage(this.lastPageNo); + return; + } - case "prev": - if(playerListPage > 1) - playerListPage -= 1; - loadPlayerListPage(playerListPage); - return; - - case "next": - if(playerListPage < lastPageNo) - playerListPage += 1; - loadPlayerListPage(playerListPage); - return; - - case "last": - loadPlayerListPage(lastPageNo); - return; + this.activePageNo = pageNo; + this.playerList.loadPlayerListPage(this.activePageNo); } - loadPlayerListPage(pageNo); } + + diff --git a/src/web/maestro/main_menu.html b/src/web/maestro/main_menu.html index 025a871..3bfb957 100644 --- a/src/web/maestro/main_menu.html +++ b/src/web/maestro/main_menu.html @@ -13,6 +13,7 @@ + diff --git a/src/web/server/user/search_player.php b/src/web/server/user/search_player.php new file mode 100644 index 0000000..d76ea79 --- /dev/null +++ b/src/web/server/user/search_player.php @@ -0,0 +1,66 @@ +close(); + exit; +} + +addPlayer($maestroID, $playerName, $enterCode); + +$result = hasPlayerName($maestroID, $playerName, $enterCode); +if($result === null) { + send_result_message($replyJSON, "fail"); + exit; +} else { + send_result_message($replyJSON, "success"); + exit; +} + +// echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); +// $db_conn->close(); + + +function hasPlayerName($maestroID, $playerName, $enterCode) { + global $db_conn; + + $query = "SELECT UserID FROM moty_user WHERE MaestroID=? AND Name=? AND EnterCode=?"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('iss', $maestroID, $playerName, $enterCode); + $stmt->execute(); + $stmt->bind_result($userID); + // while($stmt->fetch()) + $stmt->fetch(); + $stmt->close(); + + // $replyJSON["UserID"] = $userID; + return $userID; +} + +function addPlayer($maestroID, $playerName, $enterCode) { + global $db_conn; + + $query = "INSERT INTO moty_user (MaestroID, Name, EnterCode) VALUES (?, ?, ?)"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('iss', $maestroID, $playerName, $enterCode); + $stmt->execute(); +} + +?> \ No newline at end of file