Skip to content

Commit

Permalink
Merge pull request #545 from chesslablab/issue/541-Add-a-new-option-t…
Browse files Browse the repository at this point in the history
…o-the-Study-dropdown-menu

Explain a Good Move
  • Loading branch information
programarivm authored Feb 8, 2025
2 parents 230ae8e + 6d172dd commit 55e6300
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
32 changes: 31 additions & 1 deletion assets/js/pages/AnalysisPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export class ExplainPositionModal extends BaseComponent {
}
}

export class ExplainGoodPgnModal extends BaseComponent {
mount() {
const p = this.el.querySelector('p');
p.replaceChildren();
p.appendChild(document.createTextNode(`${this.props.pgn} is a good move now. ${this.props.explanation}`));
}
}

export class AnalysisPanel extends BaseComponent {
plot(event, data) {
return {
Expand Down Expand Up @@ -96,6 +104,18 @@ export class AnalysisPanel extends BaseComponent {
});

this.props.gameStudyDropdown.props.ul.children.item(1).addEventListener('click', async (event) => {
event.preventDefault();
analysisWebSocket
.send('/tutor_good_pgn')
.onChange('/tutor_good_pgn', data => {
this.props.explainGoodPgnModal.props.pgn = data.pgn;
this.props.explainGoodPgnModal.props.explanation = data.paragraph;
this.props.explainGoodPgnModal.mount();
this.props.explainGoodPgnModal.props.modal.show();
});
});

this.props.gameStudyDropdown.props.ul.children.item(2).addEventListener('click', async (event) => {
event.preventDefault();
analysisWebSocket
.send('/eval_names')
Expand All @@ -118,7 +138,7 @@ export class AnalysisPanel extends BaseComponent {
});
});

this.props.gameStudyDropdown.props.ul.children.item(2).addEventListener('click', async (event) => {
this.props.gameStudyDropdown.props.ul.children.item(3).addEventListener('click', async (event) => {
event.preventDefault();
this.progressModal.props.modal.show();
const back = (this.props.movesBrowser.props.fen.length - this.props.movesBrowser.current - 1) * -1;
Expand Down Expand Up @@ -196,6 +216,16 @@ export const analysisPanel = new AnalysisPanel({
});
}
}),
explainGoodPgnModal: new ExplainGoodPgnModal({
el: document.querySelector('#explainGoodPgnModal'),
props() {
return({
modal: new Modal(this.el),
pgn: '',
explanation: ''
});
}
}),
heuristicsModal: new BaseComponent({
el: document.querySelector('#heuristicsModal'),
props() {
Expand Down
1 change: 1 addition & 0 deletions templates/layouts/iframe.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
{% include 'partial/info_modal.html.twig' %}
{% include 'partial/progress_modal.html.twig' %}
{% include 'partial/panel/explain_position_modal.html.twig' %}
{% include 'partial/panel/explain_good_pgn_modal.html.twig' %}
{% include 'partial/panel/heuristics_modal.html.twig' %}
{% include 'partial/panel/steinitz_modal.html.twig' %}
</body>
Expand Down
1 change: 1 addition & 0 deletions templates/pages/games/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</div>
</div>
{% include 'partial/panel/explain_position_modal.html.twig' %}
{% include 'partial/panel/explain_good_pgn_modal.html.twig' %}
{% include 'partial/panel/heuristics_modal.html.twig' %}
{% include 'partial/panel/steinitz_modal.html.twig' %}
{% endblock %}
1 change: 1 addition & 0 deletions templates/pages/home/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
</div>
</div>
{% include 'partial/panel/explain_position_modal.html.twig' %}
{% include 'partial/panel/explain_good_pgn_modal.html.twig' %}
{% include 'partial/panel/heuristics_modal.html.twig' %}
{% include 'partial/panel/steinitz_modal.html.twig' %}
{% endblock %}
13 changes: 13 additions & 0 deletions templates/partial/panel/explain_good_pgn_modal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="modal" id="explainGoodPgnModal" tabindex="-1" aria-labelledby="explainGoodPgnModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="explainGoodPgnModalLabel">{{ 'Explain a Good Move'|trans }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p></p>
</div>
</div>
</div>
</div>
5 changes: 5 additions & 0 deletions templates/partial/panel/game_study_dropdown.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<i class="bi bi-chat-right-text-fill"></i> {{ 'Explain Position'|trans }}
</a>
</li>
<li>
<a class="dropdown-item" href="#">
<i class="bi bi-chat-right-dots-fill"></i> {{ 'Explain a Good Move'|trans }}
</a>
</li>
<li>
<a class="dropdown-item" href="#">
<i class="bi bi-graph-up"></i> {{ 'Heuristic Charts'|trans }}
Expand Down

0 comments on commit 55e6300

Please sign in to comment.