Skip to content

Commit

Permalink
- added non required resource scheduled outages to tool status and kiosk
Browse files Browse the repository at this point in the history
  • Loading branch information
rptmat57 committed Apr 24, 2020
1 parent c20299b commit 508e547
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 300 deletions.
3 changes: 3 additions & 0 deletions NEMO/apps/kiosk/templates/kiosk/category_choices.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ <h1>{{ category }}</h1>
{% if tool.delayed_logoff_in_progress %}
<span style="font-size:x-large; margin-right:10px" class="glyphicon glyphicon-time primary-highlight"></span>
{% endif %}

{% if tool.scheduled_outages %}
<span style="font-size:x-large; margin-right:10px" class="glyphicon glyphicon-time danger-highlight"></span>
{% elif tool.scheduled_partial_outages %}
<span style="font-size:x-large; margin-right:10px" class="glyphicon glyphicon-time warning-highlight"></span>
{% endif %}

{% if tool.required_resource_is_unavailable %}
Expand Down
282 changes: 163 additions & 119 deletions NEMO/apps/kiosk/templates/kiosk/tool_information.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,139 +9,183 @@
<h1>{{ tool.name_or_child_in_use_name }}</h1>

{# Display tool status... #}
{% if tool.in_use %}
<div class="primary-highlight">
<span class="glyphicon glyphicon-user pull-left status-icon"></span>
{% with tool.get_current_usage_event as current_usage_event %}
<h2>
{% if current_usage_event.operator.id == customer.id %}
You are using this tool
{% else %}
{{ current_usage_event.operator }} is using this tool
{% endif %}
{% if current_usage_event.operator.id != current_usage_event.user.id %}
on behalf of {{ current_usage_event.user }}
{% endif %}
for the project named {{ current_usage_event.project.name }} since {{ current_usage_event.start }}.
</h2>
<div class="tool-status">
{% if tool.in_use %}
<div class="primary-highlight media">
<span class="glyphicon glyphicon-user pull-left notification-icon"></span>
{% with tool.get_current_usage_event as current_usage_event %}
<h2>
{% if current_usage_event.operator.id == customer.id %}
You are using this tool
{% else %}
{{ current_usage_event.operator }} is using this tool
{% endif %}
{% if current_usage_event.operator.id != current_usage_event.user.id %}
on behalf of {{ current_usage_event.user }}
{% endif %}
for the project named {{ current_usage_event.project.name }} since {{ current_usage_event.start }}.
</h2>
{% endwith %}
</div>
{% if customer.is_staff and tool.in_use %}
<p>You may <a href="javascript:void(0)" onclick="disable_tool();">force {{ tool.get_current_usage_event.operator }} off this tool</a>.</p>
{% endif %}
{% elif tool.delayed_logoff_in_progress %}
{% with tool.get_delayed_logoff_usage_event as delayed_logoff_event %}
<div class="primary-highlight media">
<span class="glyphicon glyphicon-time pull-left notification-icon"></span>
<h2>{{ delayed_logoff_event.operator }} has finished using the {{ tool.name_or_child_in_use_name }} but delayed logoff is in effect. The tool will be available at {{ delayed_logoff_event.end|time }}.</h2>
</div>
{% endwith %}
</div>
{% if customer.is_staff and tool.in_use %}
<p>You may <a href="javascript:void(0)" onclick="disable_tool();">force {{ tool.get_current_usage_event.operator }} off this tool</a>.</p>
{% endif %}
{% elif tool.delayed_logoff_in_progress %}
{% with tool.get_delayed_logoff_usage_event as delayed_logoff_event %}
<div class="primary-highlight">
<span class="glyphicon glyphicon-time pull-left status-icon"></span>
<h2>{{ delayed_logoff_event.operator }} has finished using the {{ tool.name_or_child_in_use_name }} but delayed logoff is in effect. The tool will be available at {{ delayed_logoff_event.end|time }}.</h2>
{% elif not tool.operational or tool.required_resource_is_unavailable or tool.scheduled_outages %}
<div class="danger-highlight media">
<span class="glyphicon glyphicon-ban-circle pull-left notification-icon"></span>
<h2>This tool is <strong>shut down</strong>.</h2>
</div>
{% endwith %}
{% elif not tool.operational or tool.required_resource_is_unavailable %}
<div class="danger-highlight">
<span class="glyphicon glyphicon-ban-circle pull-left status-icon"></span>
<h2>This tool is <strong>shut down</strong>.</h2>
</div>
{% elif tool.nonrequired_resource_is_unavailable %}
<div class="warning-highlight">
<span class="glyphicon glyphicon-exclamation-sign pull-left status-icon"></span>
<h2>This tool is <strong>operational</strong> but not all resources are available.</h2>
</div>
{% else %}
<div class="success-highlight">
<span class="glyphicon glyphicon-ok pull-left status-icon"></span>
<h2>This tool is <strong>operational</strong> and <strong>idle</strong>.</h2>
{% elif tool.nonrequired_resource_is_unavailable %}
<div class="warning-highlight media">
<span class="glyphicon glyphicon-exclamation-sign pull-left notification-icon"></span>
<h2>This tool is <strong>operational</strong> but not all resources are available.</h2>
</div>
{% else %}
<div class="success-highlight media">
<span class="glyphicon glyphicon-ok pull-left notification-icon"></span>
<h2>This tool is <strong>operational</strong> and <strong>idle</strong>.</h2>
</div>
{% endif %}
</div>

{# dangers #}
{% if tool.unavailable_required_resources or tool.scheduled_outages %}
<div class="danger-status">
{# Display any unavailable required resources... #}
{% for r in tool.unavailable_required_resources %}
<div class="media">
<span class="glyphicon glyphicon-leaf pull-left notification-icon danger-highlight"></span>
<div class="media-body">
<span class="media-heading">A required resource is unavailable: {{ r.name }} <span class="light-grey">({{ r.category }})</span></span>
<span class="media-middle">{{ r.restriction_message }}</span>
</div>
</div>
{% endfor %}

{# Display any resources scheduled outages... #}
{% for o in tool.scheduled_outages %}
<div class="media">
<span class="glyphicon glyphicon-time pull-left notification-icon danger-highlight"></span>
<div class="media-body">
<span class="media-heading">{{ o.title }}<span class="light-grey"> ({{ o.resource.category }})</span></span>
{% if o.details %}<span class="media-middle">{{ o.details }}</span>{% endif %}
<span class="media-bottom">{{ o.creator }} scheduled this outage from {{ o.start }} until {{ o.end }}.</span>
</div>
</div>
{% endfor %}
</div>
{% endif %}

{# Display any unavailable required resources... #}
{% for r in tool.unavailable_required_resources %}
<div class="media">
<span class="glyphicon glyphicon-leaf pull-left notification-icon danger-highlight"></span>
<div class="media-body">
<h4 class="media-heading">A required resource is unavailable: {{ r.name }} <span class="light-grey">({{ r.category }})</span></h4>
{{ r.restriction_message }}
</div>
</div>
{% endfor %}
{# warnings #}
{% if tool.unavailable_nonrequired_resources or tool.scheduled_partial_outages or tool.problems %}
<div class="warning-status">
{# Display any unavailable non-required resources... #}
{% for r in tool.unavailable_nonrequired_resources %}
<div class="media">
<span class="glyphicon glyphicon-leaf pull-left notification-icon warning-highlight"></span>
<div class="media-body">
<span class="media-heading">An optional resource is unavailable: {{ r.name }} <span class="light-grey">({{ r.category }})</span></span>
<span class="media-middle">{{ r.restriction_message }}</span>
</div>
</div>
{% endfor %}

{# Display any unavailable non-required resources... #}
{% for r in tool.unavailable_nonrequired_resources %}
<div class="media">
<span class="glyphicon glyphicon-leaf pull-left notification-icon warning-highlight"></span>
<div class="media-body">
<h4 class="media-heading">An optional resource is unavailable: {{ r.name }} <span class="light-grey">({{ r.category }})</span></h4>
{{ r.restriction_message }}
</div>
{# Display any non-required resources scheduled outages... #}
{% for o in tool.scheduled_partial_outages %}
<div class="media">
<span class="glyphicon glyphicon-time pull-left notification-icon warning-highlight"></span>
<div class="media-body">
<span class="media-heading">An optional resource has an outage: {{ o.resource.name }} <span class="light-grey">({{ o.resource.category }})</span></span>
<span class="media-middle">{{ o.title }}{% if o.details %}: {{ o.details }}{% endif %}</span>
<span class="media-bottom">{{ o.creator }} scheduled this outage from {{ o.start }} until {{ o.end }}.</span>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% endif %}

{# Display all problems and shutdowns... #}
{% for t in tool.problems %}
<div class="media">
<a onclick="toggle_details(this)" data-toggle="collapse" data-target="#task_{{ t.id }}_details" class="pointer">
{% if t.force_shutdown %}
<span class="glyphicon glyphicon-fire pull-left notification-icon danger-highlight"></span>
{% else %}
<span class="glyphicon glyphicon-wrench pull-left notification-icon warning-highlight"></span>
{% endif %}
<span class="glyphicon glyphicon-chevron-right pull-left chevron"></span>
</a>
<div class="media-body">
{% if t.problem_category %}<h4 class="media-heading">{{ t.problem_category }}</h4>{% endif %}
{{ t.problem_description }}
{% if t.estimated_resolution_time %}<br>Estimated resolution time is {{ t.estimated_resolution_time }}.{% endif %}
<div id="task_{{ t.id }}_details" class="collapse">
<span class="grey">
This task was created by {{ t.creator }} on {{ t.creation_time }}.
{% if t.force_shutdown %}
The tool will remain shut down until this task is resolved.
{% endif %}
</span>
{% if t.progress_description %}
<div class="media">
<span class="glyphicon glyphicon-info-sign pull-left notification-icon primary-highlight"></span>
<div class="media-body">
<h4 class="media-heading">Progress updates</h4>
{{ t.progress_description|linebreaksbr }}
</div>
{% if tool.problems %}
<div class="tool-problems">
{# Display all problems and shutdowns... #}
{% for t in tool.problems %}
<div class="media">
<a onclick="toggle_details(this)" data-toggle="collapse" data-target="#task_{{ t.id }}_details" class="pointer">
{% if t.force_shutdown %}
<span class="glyphicon glyphicon-fire pull-left notification-icon danger-highlight"></span>
{% else %}
<span class="glyphicon glyphicon-wrench pull-left notification-icon warning-highlight"></span>
{% endif %}
<span class="glyphicon glyphicon-chevron-right pull-left chevron"></span>
</a>
<div class="media-body">
{% if t.problem_category %}<span class="media-heading">{{ t.problem_category }}</span>{% endif %}
<span class="media-middle">{{ t.problem_description }}</span>
{% if t.estimated_resolution_time %}<span class="media-middle">Estimated resolution time is {{ t.estimated_resolution_time }}.</span>{% endif %}
<div id="task_{{ t.id }}_details" class="collapse">
<span class="media-bottom">
This task was created by {{ t.creator }} on {{ t.creation_time }}.
{% if t.force_shutdown %}
The tool will remain shut down until this task is resolved.
{% endif %}
</span>
{% if t.progress_description %}
<div class="media">
<span class="glyphicon glyphicon-info-sign pull-left notification-icon primary-highlight"></span>
<div class="media-body">
<span class="media-heading">Progress updates</span>
<span class="media-middle">{{ t.progress_description|linebreaksbr }}</span>
</div>
</div>
{% endif %}
</div>
{% endif %}
</div>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% endif %}

{# Display all comments... #}
{% for c in tool.comments %}
<div class="media">
<span class="glyphicon glyphicon-comment pull-left notification-icon primary-highlight"></span>
<div class="media-body">
{{ c.content }}<br>
<span style="color:grey; font-style:italic">{{ c.author }} wrote this comment on {{ c.creation_date }}</span>
</div>
</div>
{% endfor %}
{% if tool.comments or customer.is_staff and tool.staff_only_comments %}
<div class="tool-comments">
{# Display all comments... #}
{% for c in tool.comments %}
<div class="media">
<span class="glyphicon glyphicon-comment pull-left notification-icon primary-highlight"></span>
<div class="media-body">
<span class="media-middle">{{ c.content }}</span>
<span class="media-bottom">{{ c.author }} wrote this comment on {{ c.creation_date }}</span>
</div>
</div>
{% endfor %}

{# Display all staff comments #}
{% if customer.is_staff and tool.staff_only_comments|length > 0 %}
<div class="media">
<a onclick="toggle_details(this)" data-toggle="collapse" data-target="#staff_only_comments" class="pointer">
<span class="glyphicon glyphicon-eye-close pull-left notification-icon warning-highlight"></span><span class="glyphicon glyphicon-chevron-right pull-left chevron"></span>
</a>
<div class="media-body">
Staff Only
<div id="staff_only_comments" class="collapse">
{% for c in tool.staff_only_comments %}
<div class="media">
<span class="glyphicon glyphicon-comment pull-left notification-icon primary-highlight"></span>
<div class="media-body">
{{ c.content }}<br>
<span style="font-size:x-small; color:grey; font-style:italic">{{ c.author }} wrote this comment on {{ c.creation_date }}</span>
</div>
{# Display all staff comments #}
{% if customer.is_staff and tool.staff_only_comments %}
<div class="media">
<a onclick="toggle_details(this)" data-toggle="collapse" data-target="#staff_only_comments" class="pointer">
<span class="glyphicon glyphicon-eye-close pull-left notification-icon warning-highlight"></span><span class="glyphicon glyphicon-chevron-right pull-left chevron"></span>
</a>
<div class="media-body">
Staff Only
<div id="staff_only_comments" class="collapse">
{% for c in tool.staff_only_comments %}
<div class="media">
<span class="glyphicon glyphicon-comment pull-left notification-icon primary-highlight"></span>
<div class="media-body">
<span class="media-middle">{{ c.content }}</span>
<span class="media-bottom">{{ c.author }} wrote this comment on {{ c.creation_date }}</span>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
</div>
</div>
{% endif %}
</div>
{% endif %}

Expand Down Expand Up @@ -204,7 +248,7 @@ <h1>Make a reservation</h1>
</div>
</div>
{% else %}
{% if customer.is_staff or tool.operational and not tool.required_resource_is_unavailable and not tool.delayed_logoff_in_progress and tool in customer.qualifications.all %}
{% if customer.is_staff or tool.ready_to_use and tool in customer.qualifications.all %}
{% include 'kiosk/tool_project_selection_snippet.html' with active_projects=customer.active_projects tool=tool %}
<div id="start_reserve" style="display:none; margin-top:20px">
{% if tool.is_parent_tool %}
Expand Down
11 changes: 9 additions & 2 deletions NEMO/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ def get_absolute_url(self):
from django.urls import reverse
return reverse('tool_control', args=[self.tool_or_parent_id()])

def ready_to_use(self):
return self.operational and not self.required_resource_is_unavailable and not self.delayed_logoff_in_progress and not self.scheduled_outage_in_progress

def name_display(self):
return f"{self.name} ({self.parent_tool.name})" if self.is_child_tool() else f"{self.name}"
name_display.admin_order_field = '_name'
Expand Down Expand Up @@ -579,10 +582,10 @@ def staff_only_comments(self):
unexpired = Q(expiration_date__isnull=True) | Q(expiration_date__gt=timezone.now())
return self.parent_tool.comment_set.filter(visible=True, staff_only=True).filter(unexpired) if self.is_child_tool() else self.comment_set.filter(visible=True, staff_only=True).filter(unexpired)

def required_resource_is_unavailable(self):
def required_resource_is_unavailable(self) -> bool:
return self.parent_tool.required_resource_set.filter(available=False).exists() if self.is_child_tool() else self.required_resource_set.filter(available=False).exists()

def nonrequired_resource_is_unavailable(self):
def nonrequired_resource_is_unavailable(self) -> bool:
return self.parent_tool.nonrequired_resource_set.filter(available=False).exists() if self.is_child_tool() else self.nonrequired_resource_set.filter(available=False).exists()

def all_resources_available(self):
Expand Down Expand Up @@ -616,6 +619,10 @@ def scheduled_outages(self):
""" Returns a QuerySet of scheduled outages that are in progress for this tool. This includes tool outages, and resources outages (when the tool fully depends on the resource). """
return ScheduledOutage.objects.filter(Q(tool=self.tool_or_parent_id()) | Q(resource__fully_dependent_tools__in=[self.tool_or_parent_id()]), start__lte=timezone.now(), end__gt=timezone.now())

def scheduled_partial_outages(self):
""" Returns a QuerySet of scheduled outages that are in progress for this tool. This includes resources outages when the tool partially depends on the resource. """
return ScheduledOutage.objects.filter(resource__partially_dependent_tools__in=[self.tool_or_parent_id()], start__lte=timezone.now(), end__gt=timezone.now())

def scheduled_outage_in_progress(self):
""" Returns a true if a tool or resource outage is currently in effect for this tool. Otherwise, returns false. """
return ScheduledOutage.objects.filter(Q(tool=self.tool_or_parent_id()) | Q(resource__fully_dependent_tools__in=[self.tool_or_parent_id()]), start__lte=timezone.now(), end__gt=timezone.now()).exists()
Expand Down
Loading

0 comments on commit 508e547

Please sign in to comment.