Skip to content

Commit

Permalink
Expose problems to the web interface
Browse files Browse the repository at this point in the history
  • Loading branch information
matejak committed Mar 11, 2024
1 parent 8d44e05 commit 8d4c99d
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 4 deletions.
14 changes: 14 additions & 0 deletions estimage/solutions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class Solution:
def __init__(self):
self.card_name = ""

def describe(self):
return ""

def prime(self, cards: typing.Iterable[BaseCard]):
raise NotImplementedError()

Expand All @@ -23,10 +26,15 @@ def __init__(self):
super().__init__()
self.end_value = None

def describe(self):
return f"Update the record of '{self.card_name}'"

class SolutionByUpdatingChildren(SolutionByUpdating):
action = "update_children_points"

def describe(self):
return f"Update children of '{self.card_name}', so they become consistent with the its record."

def prime(self, cards: typing.Iterable[BaseCard]):
my_card = [c for c in cards if c.name == self.card_name][0]
self.end_value = my_card.point_cost / len(my_card.children)
Expand All @@ -36,6 +44,12 @@ def prime(self, cards: typing.Iterable[BaseCard]):
class SolutionByUpdatingSelf(SolutionByUpdating):
action = "update_points"

def __init__(self):
super().__init__()

def describe(self):
return f"Update the record of '{self.card_name}', so it matches records of its children."

def prime(self, cards: typing.Iterable[BaseCard]):
pass

Expand Down
21 changes: 20 additions & 1 deletion estimage/webapp/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ... import utilities, statops
from ...statops import summary
from ... import simpledata as webdata
from ... import history
from ... import history, problems, solutions
from ...plugins import redhat_compliance


Expand Down Expand Up @@ -431,3 +431,22 @@ def view_epic_retro(epic_name):
return web_utils.render_template(
'epic_view_retrospective.html', title='View epic', breadcrumbs=breadcrumbs,
today=datetime.datetime.today(), epic=t, model=model, summary=summary)


@bp.route('/problems')
@flask_login.login_required
def view_problems():
user = flask_login.current_user
user_id = user.get_id()

all_cards_by_id, model = web_utils.get_all_tasks_by_id_and_user_model("retro", user_id)
all_cards = list(all_cards_by_id.values())

problem_detector = problems.ProblemDetector(model, all_cards)
probs = problem_detector.problems
solver = solutions.ProblemSolver()
sols = {p.description: solver.get_solution_of(p) for p in probs}

return web_utils.render_template(
'problems.html', title='Problems',
all_cards_by_id=all_cards_by_id, problems=probs, solutions=sols)
1 change: 1 addition & 0 deletions estimage/webapp/templates/general_plan.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
{% block navbar_secondary_common %}
{{ render_nav_item(get_head_absolute_endpoint('main.tree_view'), 'Tree View') }}
{{ render_nav_item(get_head_absolute_endpoint('persons.planning_workload'), 'Workloads') }}
{{ render_nav_item(get_head_absolute_endpoint('main.view_problems'), 'Problems') }}
{% endblock %}
1 change: 1 addition & 0 deletions estimage/webapp/templates/general_retro.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
{{ render_nav_item(get_head_absolute_endpoint('main.tree_view_retro'), 'Tree View') }}
{{ render_nav_item(get_head_absolute_endpoint('persons.retrospective_workload'), 'Workloads') }}
{{ render_nav_item(get_head_absolute_endpoint('main.completion'), 'Completion') }}
{{ render_nav_item(get_head_absolute_endpoint('main.view_problems'), 'Problems') }}
{% endblock %}
40 changes: 40 additions & 0 deletions estimage/webapp/templates/problems.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{% extends "general_retro.html" %}

{% import "utils.j2" as utils with context %}


{% macro print_name_replaced_with_links(text, names) %}
{% if names | length > 1 %}
{{ print_name_replaced_with_links(print_name_replaced_with_links(text, [names[0]]), names[1:]) }}
{% else %}
{{ text.replace(names[0], utils.task_or_epic_link(all_cards_by_id[names[0]], "retrospective")) | safe }}
{% endif %}
{% endmacro %}


{% block content %}
<div class="container-md">
<h2>Problems</h2>
<div class="row">
<div>
{% for p in problems %}
<h3>{{ " ".join(p.affected_cards_names) }}</h3>
<p>
{{ print_name_replaced_with_links(p.description, p.affected_cards_names) }}
</p>
<p>
Tags:
<ul>
{% for t in p.tags %}
<li>{{ t }}</li>
{% endfor %}
</ul>
Solution:
{{ solutions[p.description].describe() }}
</p>
{% endfor %}
</div>
</div>
</div>
{% endblock content %}

19 changes: 16 additions & 3 deletions estimage/webapp/templates/utils.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% macro render_epic_retro(epic, model, today, recursive=true) %}
<li>
<div id="{{ epic.name }}">
{{ epic_link(epic, "main.view_epic_retro") }} &mdash; {{ epic.title }}
{{ epic_link(epic, "retrospective") }} &mdash; {{ epic.title }}
<div class="container-md">
<div class="row">
<div class="col">
Expand Down Expand Up @@ -73,6 +73,19 @@
"retrospective": "main.view_retro_task",
} %}

{% set epic_type_to_function = {
"projective": "main.view_epic",
"retrospective": "main.view_epic_retro",
} %}

{% macro task_or_epic_link(card, type) -%}
{% if card.children %}
{{ epic_link(card, type) }}
{% else %}
{{ task_link(card, type) }}
{% endif %}
{%- endmacro %}

{% macro task_link(task, type) -%}
<a href="{{ head_url_for(task_type_to_function[type], task_name=task.name) }}">{{ task.name }}</a>&nbsp;<a href="{{ task.uri }}" rel="external">{{ render_icon("box-arrow-up-right") }}</a>
{%- endmacro %}
Expand All @@ -81,8 +94,8 @@
<a href="{{ epic.uri }}" rel="external">{{ render_icon("box-arrow-up-right") }}</a>
{%- endmacro %}

{% macro epic_link(epic, endpoint="main.view_epic") -%}
<a href="{{ head_url_for(endpoint, epic_name=epic.name) }}">{{ epic.name }}</a>&nbsp;{{ epic_external_link(epic) }}
{% macro epic_link(epic, type="projective") -%}
<a href="{{ head_url_for(epic_type_to_function[type], epic_name=epic.name) }}">{{ epic.name }}</a>&nbsp;{{ epic_external_link(epic) }}
{%- endmacro %}

{% macro render_state_short(state) -%}
Expand Down

0 comments on commit 8d4c99d

Please sign in to comment.