mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-05 06:13:55 +01:00
Improve states UI
This commit is contained in:
parent
4664ae0d9d
commit
369449442e
10 changed files with 79 additions and 17 deletions
|
@ -24,8 +24,10 @@ class AddPathForm(forms.Form):
|
||||||
def __init__(self, character: Character, *args, **kwargs):
|
def __init__(self, character: Character, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
paths = {cap.path_id for cap in character.capabilities.all()}
|
paths = {cap.path_id for cap in character.capabilities.all()}
|
||||||
paths = Path.objects.exclude(pk__in=paths).order_by(
|
paths = (
|
||||||
"profile__name", "race__name"
|
Path.objects.exclude(pk__in=paths)
|
||||||
|
.order_by("profile__name", "race__name")
|
||||||
|
.select_related("profile", "race")
|
||||||
)
|
)
|
||||||
character_paths = paths.filter(
|
character_paths = paths.filter(
|
||||||
Q(profile=character.profile) | Q(race=character.race)
|
Q(profile=character.profile) | Q(race=character.race)
|
||||||
|
|
21
src/character/migrations/0031_alter_harmfulstate_options.py
Normal file
21
src/character/migrations/0031_alter_harmfulstate_options.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Generated by Django 4.1.2 on 2022-11-02 21:01
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("character", "0030_alter_character_states"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="harmfulstate",
|
||||||
|
options={
|
||||||
|
"ordering": ["name"],
|
||||||
|
"verbose_name": "État préjudiciable",
|
||||||
|
"verbose_name_plural": "États préjudiciables",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
|
@ -1 +1 @@
|
||||||
0030_alter_character_states
|
0031_alter_harmfulstate_options
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import collections
|
import collections
|
||||||
|
from collections.abc import Iterable
|
||||||
|
|
||||||
import markdown
|
import markdown
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -56,6 +57,7 @@ class HarmfulState(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "État préjudiciable"
|
verbose_name = "État préjudiciable"
|
||||||
verbose_name_plural = "États préjudiciables"
|
verbose_name_plural = "États préjudiciables"
|
||||||
|
ordering = ["name"]
|
||||||
|
|
||||||
|
|
||||||
def modifier(value: int) -> int:
|
def modifier(value: int) -> int:
|
||||||
|
@ -318,3 +320,8 @@ class Character(models.Model):
|
||||||
def get_formatted_notes(self) -> str:
|
def get_formatted_notes(self) -> str:
|
||||||
md = markdown.Markdown(extensions=["extra", "nl2br"])
|
md = markdown.Markdown(extensions=["extra", "nl2br"])
|
||||||
return md.convert(self.notes)
|
return md.convert(self.notes)
|
||||||
|
|
||||||
|
def get_missing_states(self) -> Iterable[HarmfulState]:
|
||||||
|
return HarmfulState.objects.exclude(
|
||||||
|
pk__in=self.states.all().values_list("pk", flat=True)
|
||||||
|
)
|
||||||
|
|
3
src/character/static/character/style.css
Normal file
3
src/character/static/character/style.css
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.state-enabled {
|
||||||
|
filter: invert(50%) sepia(100%) saturate(3000%) hue-rotate(325deg);
|
||||||
|
}
|
|
@ -1,15 +1,20 @@
|
||||||
<p id="states">
|
<p id="states">
|
||||||
États :
|
États :
|
||||||
{% for state in character.states.all %}
|
{% with character.states.all as character_states %}
|
||||||
<img src="{{ state.icon_url }}" alt="{{ state.name }}" height="25" width="25"
|
{% for state in all_states %}
|
||||||
data-bs-toggle="tooltip"
|
<img src="{{ state.icon_url }}" alt="{{ state.name }}" height="25" width="25"
|
||||||
data-bs-placement="top"
|
data-bs-toggle="tooltip"
|
||||||
data-bs-title="{{ state.name }} : {{ state.description }}"
|
data-bs-placement="top"
|
||||||
hx-get="{% url "character:remove_state" pk=character.pk state_pk=state.pk %}"
|
data-bs-title="{{ state.name }} : {{ state.description }}"
|
||||||
hx-target="#states"
|
{% if state in character_states %}
|
||||||
hx-swap="outerHTML"
|
class="state-enabled"
|
||||||
>
|
hx-get="{% url "character:remove_state" pk=character.pk state_pk=state.pk %}"
|
||||||
{% empty %}
|
{% else %}
|
||||||
Aucun
|
hx-get="{% url "character:add_state" pk=character.pk state_pk=state.pk %}"
|
||||||
{% endfor %}
|
{% endif %}
|
||||||
|
hx-target="#states"
|
||||||
|
hx-swap="outerHTML"
|
||||||
|
>
|
||||||
|
{% endfor %}
|
||||||
|
{% endwith %}
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
{% extends "common/base.html" %}
|
{% extends "common/base.html" %}
|
||||||
|
{% load static %}
|
||||||
{% load django_bootstrap5 %}
|
{% load django_bootstrap5 %}
|
||||||
{% load character_extras %}
|
{% load character_extras %}
|
||||||
|
|
||||||
{% block title %}{{ character.name }}{% endblock %}
|
{% block title %}{{ character.name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block head_end %}
|
||||||
|
<link rel="stylesheet" href="{% static "character/style.css" %}">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ character.name }}</h1>
|
<h1>{{ character.name }}</h1>
|
||||||
<p>
|
<p>
|
||||||
|
|
|
@ -72,4 +72,5 @@ urlpatterns = [
|
||||||
path(
|
path(
|
||||||
"<int:pk>/remove_state/<int:state_pk>/", views.remove_state, name="remove_state"
|
"<int:pk>/remove_state/<int:state_pk>/", views.remove_state, name="remove_state"
|
||||||
),
|
),
|
||||||
|
path("<int:pk>/add_state/<int:state_pk>/", views.add_state, name="add_state"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -32,7 +32,11 @@ def character_view(request, pk: int):
|
||||||
pk=pk,
|
pk=pk,
|
||||||
)
|
)
|
||||||
add_path_form = AddPathForm(character)
|
add_path_form = AddPathForm(character)
|
||||||
context = {"character": character, "add_path_form": add_path_form}
|
context = {
|
||||||
|
"character": character,
|
||||||
|
"add_path_form": add_path_form,
|
||||||
|
"all_states": HarmfulState.objects.all(),
|
||||||
|
}
|
||||||
return render(request, "character/view.html", context)
|
return render(request, "character/view.html", context)
|
||||||
|
|
||||||
|
|
||||||
|
@ -274,6 +278,18 @@ def remove_state(request, pk: int, state_pk: int):
|
||||||
)
|
)
|
||||||
state = get_object_or_404(HarmfulState, pk=state_pk)
|
state = get_object_or_404(HarmfulState, pk=state_pk)
|
||||||
character.states.remove(state)
|
character.states.remove(state)
|
||||||
context = {"character": character}
|
context = {"character": character, "all_states": HarmfulState.objects.all()}
|
||||||
|
response = render(request, "character/states.html", context)
|
||||||
|
return trigger_client_event(response, "refresh_tooltips", {})
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def add_state(request, pk: int, state_pk: int):
|
||||||
|
character: Character = get_object_or_404(
|
||||||
|
Character.objects.filter(player=request.user), pk=pk
|
||||||
|
)
|
||||||
|
state = get_object_or_404(HarmfulState, pk=state_pk)
|
||||||
|
character.states.add(state)
|
||||||
|
context = {"character": character, "all_states": HarmfulState.objects.all()}
|
||||||
response = render(request, "character/states.html", context)
|
response = render(request, "character/states.html", context)
|
||||||
return trigger_client_event(response, "refresh_tooltips", {})
|
return trigger_client_event(response, "refresh_tooltips", {})
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
touch-action: manipulation;
|
touch-action: manipulation;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
{% block head_end %}
|
||||||
|
{% endblock %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% include "common/navbar.html" %}
|
{% include "common/navbar.html" %}
|
||||||
|
|
Loading…
Reference in a new issue