christopher commited on
Commit
50d0d7d
·
1 Parent(s): 2ba5ab4

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +2 -116
templates/index.html CHANGED
@@ -2,26 +2,7 @@
2
  <html>
3
  <head>
4
  <link rel="stylesheet" href="/static/chessboard-1.0.0.min.css">
5
- <style>
6
- body { font-family: Arial; max-width: 1200px; margin: 50px auto; padding: 20px; }
7
- .container { display: flex; gap: 40px; margin: 20px 0; }
8
- #board { width: 400px; }
9
- .info-panel { flex: 1; }
10
- .info-panel h3 { margin-top: 0; }
11
- button { padding: 10px 20px; margin: 5px; cursor: pointer; }
12
- #fen { background: #f0f0f0; padding: 10px; margin: 10px 0; font-family: monospace; }
13
- #results { margin-top: 30px; }
14
- .pagination { text-align: center; margin: 20px 0; }
15
- .pagination button { padding: 10px 20px; margin: 0 5px; }
16
- .pagination button:disabled { opacity: 0.5; cursor: not-allowed; }
17
- .puzzle { border: 1px solid #ddd; padding: 15px; margin: 15px 0; display: flex; gap: 20px; }
18
- .puzzle-board { width: 200px; height: 200px; }
19
- .puzzle-info { flex: 1; }
20
- .puzzle-info h3 { margin: 0 0 10px 0; }
21
- .puzzle-info a { color: #0066cc; }
22
- .themes { display: flex; gap: 5px; flex-wrap: wrap; margin: 10px 0; }
23
- .theme { background: #e0e0e0; padding: 3px 8px; border-radius: 3px; font-size: 12px; }
24
- </style>
25
  </head>
26
  <body>
27
  <h1>Chess Position Search</h1>
@@ -42,101 +23,6 @@
42
 
43
  <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
44
  <script src="/static/chessboard-1.0.0.min.js"></script>
45
- <script>
46
- const RESULTS_PER_PAGE = 10;
47
- let allResults = [];
48
- let currentPage = 0;
49
-
50
- var board = Chessboard('board', {
51
- draggable: true,
52
- dropOffBoard: 'trash',
53
- sparePieces: true,
54
- pieceTheme: '/static/img/chesspieces/wikipedia/{piece}.png',
55
- onSnapEnd: updateInfo
56
- });
57
-
58
- function updateInfo() {
59
- document.getElementById('fen').textContent = 'FEN: ' + board.fen();
60
- let pos = board.position();
61
- let pieces = Object.keys(pos).length;
62
- document.getElementById('position-info').textContent = `Pieces on board: ${pieces}`;
63
- }
64
-
65
- function search() {
66
- document.getElementById('results').innerHTML = '<p>Searching...</p>';
67
- fetch('/search', {
68
- method: 'POST',
69
- headers: {'Content-Type': 'application/json'},
70
- body: JSON.stringify({fen: board.fen()})
71
- })
72
- .then(r => r.json())
73
- .then(data => {
74
- allResults = data.results;
75
- currentPage = 0;
76
- displayPage();
77
- });
78
- }
79
-
80
- function displayPage() {
81
- const start = currentPage * RESULTS_PER_PAGE;
82
- const end = start + RESULTS_PER_PAGE;
83
- const pageResults = allResults.slice(start, end);
84
- const totalPages = Math.ceil(allResults.length / RESULTS_PER_PAGE);
85
-
86
- let html = `<h2>Found ${allResults.length} puzzles (page ${currentPage + 1} of ${totalPages})</h2>`;
87
- html += `<div class="pagination">
88
- <button onclick="prevPage()" ${currentPage === 0 ? 'disabled' : ''}>Previous</button>
89
- <button onclick="nextPage()" ${end >= allResults.length ? 'disabled' : ''}>Next</button>
90
- </div>`;
91
-
92
- pageResults.forEach((p, i) => {
93
- const globalIdx = start + i;
94
- html += `
95
- <div class="puzzle">
96
- <div class="puzzle-board" id="result-board-${globalIdx}"></div>
97
- <div class="puzzle-info">
98
- <h3><a href="${p.PuzzleUrl}" target="_blank">${p.PuzzleId}</a></h3>
99
- <p>Rating: ${p.Rating} | Popularity: ${p.Popularity}%</p>
100
- <div class="themes">${p.Themes.map(t => `<span class="theme">${t}</span>`).join('')}</div>
101
- <p>Moves: ${p.Moves}</p>
102
- <p><a href="${p.GameUrl}" target="_blank">View game</a></p>
103
- </div>
104
- </div>`;
105
- });
106
-
107
- html += `<div class="pagination">
108
- <button onclick="prevPage()" ${currentPage === 0 ? 'disabled' : ''}>Previous</button>
109
- <button onclick="nextPage()" ${end >= allResults.length ? 'disabled' : ''}>Next</button>
110
- </div>`;
111
-
112
- document.getElementById('results').innerHTML = html;
113
-
114
- pageResults.forEach((p, i) => {
115
- const globalIdx = start + i;
116
- Chessboard(`result-board-${globalIdx}`, {
117
- position: p.FEN,
118
- pieceTheme: '/static/img/chesspieces/wikipedia/{piece}.png'
119
- });
120
- });
121
- }
122
-
123
- function nextPage() {
124
- if ((currentPage + 1) * RESULTS_PER_PAGE < allResults.length) {
125
- currentPage++;
126
- displayPage();
127
- window.scrollTo(0, 0);
128
- }
129
- }
130
-
131
- function prevPage() {
132
- if (currentPage > 0) {
133
- currentPage--;
134
- displayPage();
135
- window.scrollTo(0, 0);
136
- }
137
- }
138
-
139
- updateInfo();
140
- </script>
141
  </body>
142
  </html>
 
2
  <html>
3
  <head>
4
  <link rel="stylesheet" href="/static/chessboard-1.0.0.min.css">
5
+ <link rel="stylesheet" href="/static/styles.css">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  </head>
7
  <body>
8
  <h1>Chess Position Search</h1>
 
23
 
24
  <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
25
  <script src="/static/chessboard-1.0.0.min.js"></script>
26
+ <script src="/static/app.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  </body>
28
  </html>