-
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.
Migrated old jQuery Tic-Tac-Toe App to run on a Razor Page
- Loading branch information
Showing
10 changed files
with
748 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@page | ||
@model TicTacToeJqModel | ||
@{ | ||
ViewData["Title"] = "Tic-Tac-Toe (jQuery)"; | ||
} | ||
@using Microsoft.JSInterop | ||
|
||
<link rel="stylesheet" href="~/Tic-Tac-Toe/css/tic-tac-toe.css" asp-append-version="false" /> | ||
<script src="~/Tic-Tac-Toe/js/tic-tac-toe.js" asp-append-version="false"></script> | ||
|
||
<h1>@ViewData["Title"]</h1> | ||
<p>The Tic-Tac-Toe project was started in 16 Feb 2022 as a way to learn about Machine Learning. This is the jQuery version.</p> | ||
|
||
<form method="post"> | ||
<div style="display: table"> | ||
<div style="display: table-row"> | ||
<div style="display: table-cell"> | ||
<div id="tictactoejq1" class="tictactoejq"></div> | ||
</div> | ||
@* | ||
<div style="display: table-cell"> | ||
<div id="tictactoejq2" class="tictactoejq"></div> | ||
</div>*@ | ||
</div> | ||
</div> | ||
</form> | ||
|
||
<script type="text/javascript"> | ||
jQuery(document).ready(function () { | ||
function OnPostUpdateTicTacToe(requestArgs) { | ||
if (console && console.log) | ||
console.log('OnPostUpdateTicTacToe'); | ||
if (console && console.log) | ||
console.log(requestArgs); | ||
let requestData = JSON.stringify(requestArgs); | ||
let thepromise = DotNet.invokeMethodAsync('BlazorServerApp', 'jsUpdateTicTacToe', requestData); | ||
if (console && console.log) | ||
console.log(thepromise); | ||
return thepromise; | ||
} | ||
var app1 = new TicTacToeJq("tictactoejq1"); | ||
app1.OnUpdate(OnPostUpdateTicTacToe); | ||
@*var app2 = new TicTacToeJq("tictactoejq2"); | ||
app2.OnUpdate(OnPostUpdateTicTacToe);*@ | ||
}); | ||
</script> |
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 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.JSInterop; | ||
using System.Text.Json; | ||
using TicTacToe.Models; | ||
|
||
namespace BlazorServerApp.Pages | ||
{ | ||
public class TicTacToeJqModel : PageModel | ||
{ | ||
static IConfiguration _config = null; | ||
|
||
public TicTacToeJqModel(IConfiguration config) | ||
{ | ||
_config = config; | ||
} | ||
|
||
public void OnGet() | ||
{ | ||
} | ||
|
||
[JSInvokableAttribute("jsUpdateTicTacToe")] | ||
public static async Task<string> OnPostUpdateTicTacToeAsync(string requestData) | ||
{ | ||
var request = JsonSerializer.Deserialize<TicTacToeUpdateRequest>(requestData); | ||
|
||
if (request != null) | ||
{ | ||
var configExternalServices = | ||
_config.GetSection("ExternalServices"); | ||
|
||
if (configExternalServices != null) | ||
{ | ||
var configTicTacToeWebApi = configExternalServices.GetSection("TicTacToeWebApi"); | ||
if (configTicTacToeWebApi != null) | ||
{ | ||
var endpoint = configTicTacToeWebApi["endpoint"]; | ||
|
||
var client = new HttpClient(); | ||
var httpPostTask = | ||
client.PostAsJsonAsync<TicTacToeUpdateRequest>( | ||
endpoint, | ||
request | ||
); | ||
|
||
httpPostTask.Wait(); | ||
|
||
var httpResponseMessage = httpPostTask.Result; | ||
|
||
var readJsonTask = | ||
httpResponseMessage | ||
.Content | ||
.ReadFromJsonAsync<TicTacToeUpdateResponse>(); | ||
|
||
readJsonTask.Wait(); | ||
|
||
if (readJsonTask.Result != null) | ||
{ | ||
var tictactoeUpdateResponse = readJsonTask.Result; | ||
if (tictactoeUpdateResponse != null) | ||
return JsonSerializer.Serialize(tictactoeUpdateResponse); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return string.Empty; | ||
} | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
BlazorServerApp/Pages/TicTacToe.razor → BlazorServerApp/Pages/TicTacToeRz.razor
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,95 @@ | ||
div.tic-tac-toe-page { | ||
cursor: url('/Tic-Tac-Toe/blueArrow32x32.png'), pointer !important; | ||
} | ||
|
||
div.tic-tac-toe-grid { | ||
display: table; | ||
} | ||
|
||
div.tic-tac-toe-row-first { | ||
display: table-row; | ||
} | ||
|
||
div.tic-tac-toe-row { | ||
display: table-row; | ||
} | ||
|
||
div.tic-tac-toe-row-last { | ||
display: table-row; | ||
} | ||
|
||
div.tic-tac-toe-cell-first { | ||
display: table-cell; | ||
border-right: medium solid black; | ||
padding: 2px; | ||
} | ||
|
||
div.tic-tac-toe-cell { | ||
display: table-cell; | ||
border-left: medium solid black; | ||
border-right: medium solid black; | ||
padding: 2px; | ||
} | ||
|
||
div.tic-tac-toe-cell-last { | ||
display: table-cell; | ||
border-left: medium solid black; | ||
padding: 2px; | ||
} | ||
|
||
div.tic-tac-toe-row-first div { | ||
border-bottom: medium solid black; | ||
} | ||
|
||
div.tic-tac-toe-row div { | ||
border-top: medium solid black; | ||
border-bottom: medium solid black; | ||
} | ||
|
||
div.tic-tac-toe-row-last div { | ||
border-top: medium solid black; | ||
} | ||
|
||
div.tic-tac-toe-display { | ||
padding-top: 5px; | ||
} | ||
|
||
div.tic-tac-toe-display div { | ||
vertical-align: middle; | ||
} | ||
|
||
div.tic-tac-toe-display div div { | ||
vertical-align: middle; | ||
} | ||
|
||
div .gameMode { | ||
float: left; | ||
} | ||
|
||
div.gameMode div { | ||
display: inline-block; | ||
padding: 0px 5px 0px 5px; | ||
} | ||
|
||
div.player1 { | ||
float: right; | ||
padding-left: 3px; | ||
} | ||
|
||
div.player1 div { | ||
display: inline-block; | ||
padding: 0px 5px 0px 5px; | ||
} | ||
|
||
div.player2 { | ||
float: right; | ||
padding-left: 3px; | ||
} | ||
|
||
div.player2 div { | ||
display: inline-block; | ||
padding: 0px 5px 0px 5px; | ||
} | ||
|
||
div.tic-tac-toe-controls { | ||
} |
Oops, something went wrong.