Skip to content

Commit

Permalink
re-open fatlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
ppfeufer committed Apr 12, 2021
1 parent 263a277 commit c5efe37
Show file tree
Hide file tree
Showing 16 changed files with 343 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Proper log model
- Proper log messages to fatlink detail view and edit actions
- Modal window when closing ESI fleets manually
- Ability to re-open FAT links for a certain time after they have expired
(`manage_afat` permissions are needed to re-open FAT links)

### Changed

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ To customize the module, the following settings are available.

| Name | Description | Default Value |
|:---------------------------------|:----------------------------------------------------------------|:------------------------|
| AFAT_DEFAULT_FATLINK_EXPIRY_TIME | Sets the default expiry time for clickable FAT links in Minutes | 60 |
| AFAT_APP_NAME | Sets the application name, in case you'd like a different name | Fleet Activity Tracking |
| AFAT_APP_NAME | Custom application name, in case you'd like a different name | Fleet Activity Tracking |
| AFAT_DEFAULT_FATLINK_EXPIRY_TIME | Default expiry time for clickable FAT links in Minutes | 60 |
| AFAT_DEFAULT_FATLINK_REOPEN_GRACE_TIME | Time in minutes a FAT link can be re-opened after it has expired | 60 |
| AFAT_DEFAULT_FATLINK_REOPEN_DURATION | Time in minutes a FAT link is re-opened | 60 |


## Permissions
Expand Down
2 changes: 1 addition & 1 deletion afat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

default_app_config: str = "afat.apps.AfatConfig"

__version__ = "2.0.0-alpha.8"
__version__ = "2.0.0-alpha.9"
__title__ = "Fleet Activity Tracking"
12 changes: 11 additions & 1 deletion afat/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@

from afat.utils import clean_setting

# set default panels if none are set in local.py
# set default expiry time in minutes
AFAT_DEFAULT_FATLINK_EXPIRY_TIME = clean_setting("AFAT_DEFAULT_FATLINK_EXPIRY_TIME", 60)

# set the default time in minutes a FAT lnk can be re-opened after it is expired
AFAT_DEFAULT_FATLINK_REOPEN_GRACE_TIME = clean_setting(
"AFAT_DEFAULT_FATLINK_REOPEN_GRACE_TIME", 60
)

# set the default time in minutes a FAT link is re-opened for
AFAT_DEFAULT_FATLINK_REOPEN_DURATION = clean_setting(
"AFAT_DEFAULT_FATLINK_REOPEN_DURATION", 60
)

# Name of this app as shown in the Auth sidebar and page titles
AFAT_APP_NAME = clean_setting(
"AFAT_APP_NAME", _("Fleet Activity Tracking"), required_type=str
Expand Down
8 changes: 8 additions & 0 deletions afat/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ class FatLinkEditForm(forms.Form):
"""

fleet = forms.CharField(label=_("Fleet Name"), max_length=255)


# class ExtendFatLinkDuration(forms.Form):
# """
# extending the duration time of a fatlink
# """
#
# duration = forms.IntegerField(label=_("Re-open for (in minutes)"), min_value=1)
110 changes: 110 additions & 0 deletions afat/helper/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""
helper for time related functions
"""

from datetime import datetime


def get_time_delta(then, now=datetime.now(), interval="default"):
"""
Returns a duration as specified by variable interval
Functions, except total_duration, returns [quotient, remainder]
:param then:
:type then:
:param now:
:type now:
:param interval:
:type interval:
:return:
:rtype:
"""

duration = now.replace(tzinfo=None) - then.replace(tzinfo=None)
duration_in_seconds = duration.total_seconds()

def years():
"""
return years
:return:
:rtype:
"""

return divmod(duration_in_seconds, 31536000) # Seconds in a year=31536000.

def days(from_seconds=None):
"""
return days
:param from_seconds:
:type from_seconds:
:return:
:rtype:
"""

return divmod(
from_seconds if from_seconds is not None else duration_in_seconds, 86400
) # Seconds in a day = 86400

def hours(from_seconds=None):
"""
return hours
:param from_seconds:
:type from_seconds:
:return:
:rtype:
"""

return divmod(
from_seconds if from_seconds is not None else duration_in_seconds, 3600
) # Seconds in an hour = 3600

def minutes(from_seconds=None):
"""
return minutes
:param from_seconds:
:type from_seconds:
:return:
:rtype:
"""

return divmod(
from_seconds if from_seconds is not None else duration_in_seconds, 60
) # Seconds in a minute = 60

def seconds(from_seconds=None):
"""
return seconds
:param from_seconds:
:type from_seconds:
:return:
:rtype:
"""

if from_seconds is not None:
return divmod(from_seconds, 1)
return duration_in_seconds

def total_duration():
"""
return total time difference
:return:
:rtype:
"""

y = years()
d = days(y[1]) # Use remainder to calculate next variable
h = hours(d[1])
m = minutes(h[1])
s = seconds(m[1])

return "{} years, {} days, {} hours, {} minutes and {} seconds".format(
int(y[0]), int(d[0]), int(h[0]), int(m[0]), int(s[0])
)

return {
"years": int(years()[0]),
"days": int(days()[0]),
"hours": int(hours()[0]),
"minutes": int(minutes()[0]),
"seconds": int(seconds()),
"default": total_duration(),
}[interval]
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by Django 3.1.8 on 2021-04-06 10:46
# Generated by Django 3.1.8 on 2021-04-12 17:20

import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models
Expand Down Expand Up @@ -37,6 +36,7 @@ class Migration(migrations.Migration):
("CR_FAT_LINK", "FAT Link Created"),
("CH_FAT_LINK", "FAT Link Changed"),
("RM_FAT_LINK", "FAT Link Removed"),
("RO_FAT_LINK", "FAT Link Re-Opened"),
("RM_FAT", "FAT Removed"),
("CR_FAT_MAN", "Manual FAT Added"),
],
Expand Down
1 change: 1 addition & 0 deletions afat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AFatLogEvent(models.TextChoices):
CREATE_FATLINK = "CR_FAT_LINK", _("FAT Link Created")
CHANGE_FATLINK = "CH_FAT_LINK", _("FAT Link Changed")
DELETE_FATLINK = "RM_FAT_LINK", _("FAT Link Removed")
REOPEN_FATLINK = "RO_FAT_LINK", _("FAT Link Re-Opened")
# CREATE_FAT = "CR_FAT", _("FAT Registered")
DELETE_FAT = "RM_FAT", _("FAT Removed")
MANUAL_FAT = "CR_FAT_MAN", _("Manual FAT Added")
Expand Down
6 changes: 6 additions & 0 deletions afat/static/afat/javascript/afat-fatlink-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,10 @@ $(document).ready(function () {
*/
let deleteFatModal = $(afatSettings.modal.deleteModal.element);
manageModal(deleteFatModal);

/**
* Modal :: Delete FAT from FAT link
*/
let reopenFatLinkModal = $(afatSettings.modal.reopenFatLinkModal.element);
manageModal(reopenFatLinkModal);
});
2 changes: 1 addition & 1 deletion afat/static/afat/javascript/afat-fatlink-details.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions afat/templates/afat/fatlinks_details_fatlink.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ <h2>{% translate "FAT Link Details" %}</h2>
modal: {
deleteModal: {
element: '#deleteFatModal',
},
reopenFatLinkModal: {
element: '#reopenFatLinkModal',
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions afat/templates/afat/modals/general.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load i18n %}

<!-- Delete Modal -->
<!-- AFAT Modal -->
<div class="modal fade" id="{{ modal_name }}Modal" tabindex="-1" role="dialog" aria-labelledby="{{ modal_name }}ModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
Expand All @@ -17,9 +17,9 @@ <h5 class="modal-title" id="{{ modal_name }}ModalLongTitle">
<div class="modal-body"></div>

<div class="modal-footer">
<button type="button" id="cancel-action" class="btn btn-secondary btn-sm" data-dismiss="modal"></button>
<button type="button" id="cancel-action" class="btn btn-default btn-sm" data-dismiss="modal"></button>

<a id="confirm-action" class="btn {% if confirm_button_class %}{{ confirm_button_class }}{% else %}btn-default{% endif %} btn-sm" role="button" href=""></a>
<a id="confirm-action" class="btn {% if confirm_button_class %}{{ confirm_button_class }}{% else %}btn-primary{% endif %} btn-sm" role="button" href=""></a>
</div>
</div>

Expand Down
53 changes: 47 additions & 6 deletions afat/templates/afat/partials/fatlinks/details/fatlink_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@
<div class="col-md-12">
<div class="row">
<div class="col-md-6">{% translate "Creator:" %} {{ link.creator.profile.main_character.character_name }}</div>
<div class="col-md-6 text-right">{% translate "Eve Time:" %} {{ link.afattime| date:"d. F Y H:i" }}</div>
<div class="col-md-6 text-right">
{% translate "Link Created (Eve Time):" %} {{ link.afattime| date:"d. F Y H:i" }}

{% if link_expires %}
<br>

{% if link_ongoing %}
{% translate "Link Expires (Eve Time):" %}
{% else %}
{% translate "Link Expired (Eve Time):" %}
{% endif %}

{{ link_expires| date:"d. F Y H:i" }}
{% endif %}

{% if link.is_esilink %}
<br>
{% translate 'Participation has been tracked via ESI' %}
{% endif %}
</div>

{% if link_ongoing %}
<div class="col-md-10">
Expand All @@ -14,16 +33,38 @@
</i>

<button class="copy-btn btn btn-success btn-sm"
data-toggle="tooltip"
data-html="true"
{# title='{% translate "Copied!" %}'#}
data-clipboard-text="{{ request.scheme }}://{{ request.get_host }}{% url 'afat:fatlinks_add_fat' link.hash %}"
style="margin-left: 1rem;"
data-toggle="tooltip"
data-html="true"
{# title='{% translate "Copied!" %}'#}
data-clipboard-text="{{ request.scheme }}://{{ request.get_host }}{% url 'afat:fatlinks_add_fat' link.hash %}"
style="margin-left: 1rem;"
>
{% translate "Copy me!" %}
</button>
</p>
</div>
{% endif %}

{% if link_can_be_reopened and perms.afat.manage_afat %}
<div class="col-md-10">
<p>
{% blocktranslate with reopen_grace_time=reopen_grace_time %}This link has already expired but is within the grace time of {{ reopen_grace_time }} minutes where it can be re-opened.{% endblocktranslate %}
</p>
<p>
<button class="btn btn-default btn-sm"
data-toggle="modal"
data-target="#reopenFatLinkModal"
data-url="{% url 'afat:fatlinks_reopen_fatlink' link.hash %}"
data-body-text="{% blocktranslate with reopen_duration=reopen_duration %}<p>Are you sure you want to re-open this FAT link for another {{ reopen_duration }} minutes?<br><em>(Be aware, this action will be logged)</em></p>{% endblocktranslate %}"
data-confirm-text="{% translate 'Re-Open' %}"
>
{% translate 'Re-open FAT link' %}
</button>
</p>
</div>

{% translate "Re-Open Fat Link" as translated_title %}
{% include 'afat/modals/general.html' with modal_name='reopenFatLink' modal_title=translated_title confirm_button_class='btn-success' %}
{% endif %}
</div>
</div>
Loading

0 comments on commit c5efe37

Please sign in to comment.