Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new display template to show last called tickets #172 #215

Merged
merged 5 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,28 @@ def get_waiting_list_tickets(cls, office_id=None, limit=9):
.limit(limit)\
.all()

@classmethod
def get_processed_tickets(cls, office_id=None, limit=9, offset=0):
'''get list of last processed tickets.

Parameters
----------
office_id : int, optional
office id to filter tickets for, by default None
limit : int, optional
limit the list of ticket to it, by default 9
'''
processed_tickets = cls.query.filter(cls.p == True,
cls.number != 100)

if office_id:
processed_tickets = processed_tickets.filter(cls.office_id == office_id)

return processed_tickets.order_by(cls.pdt.desc())\
.limit(limit)\
.offset(offset)\
.all()

def pull(self, office_id):
''' Mark a ticket as pulled and do the dues.

Expand Down
2 changes: 1 addition & 1 deletion app/forms/constents.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
EXPORT_DELIMETERS = [',', '\t', '\n', '*', '#']
EXPORT_OPTIONS = {0: 'Comma', 1: 'Tab', 2: 'New line', 3: 'Star', 4: 'Hashtag'}

DISPLAY_TEMPLATES = [(0, 'First Template'), (1, 'Second Template'), (2, 'Third Template')]
TOUCH_TEMPLATES = [(0, 'First Template'), (1, 'Second Template'), (2, 'Third Template')]
DISPLAY_TEMPLATES = TOUCH_TEMPLATES + [(3, 'Fourth Template')]


BOOLEAN_SELECT = [(1, 'Enable'), (0, 'Disable')]
Expand Down
28 changes: 18 additions & 10 deletions app/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,40 +322,48 @@ def on_hold(ticket, redirect_to):
@core.route('/feed/<int:office_id>')
def feed(office_id=None):
''' stream list of waiting tickets and current ticket. '''
display_settings = data.Display_store.get()
single_row = data.Settings.get().single_row
hide_ticket_index = data.Display_store.get().hide_ticket_index
current_ticket = data.Serial.get_last_pulled_ticket(office_id)
empty_text = gtranslator.translate('Empty', dest=[session.get('lang')])
current_ticket_text = current_ticket and current_ticket.display_text or empty_text
current_ticket_office_name = current_ticket and current_ticket.office.display_text or empty_text
current_ticket_task_name = current_ticket and current_ticket.task.name or empty_text

def _resolve_ticket_index(_index):
return '' if hide_ticket_index else f'{_index + 1}. '
return '' if display_settings.hide_ticket_index else f'{_index + 1}. '

if single_row:
waiting_list_parameters = {
tickets_parameters = {
f'w{_index + 1}': f'{_resolve_ticket_index(_index)}{number}'
for _index, number in enumerate(range(getattr(current_ticket, 'number', 1) + 1,
getattr(current_ticket, 'number', 1) + 10))}
else:
waiting_tickets = (data.Serial.get_waiting_list_tickets(office_id) + ([None] * 9))[:9]
waiting_list_parameters = {
tickets_parameters = {
f'w{_index + 1}':
f'{_resolve_ticket_index(_index)}{ticket.display_text}' if ticket else empty_text
for _index, ticket in enumerate(waiting_tickets)}

# NOTE: Ensure `waiting_list_parameters` last value is as distinct as the `current_ticket`
# NOTE: Add last 10 processed tickets, for supported template.
if display_settings.tmp == 3:
processed_tickets = (data.Serial.get_processed_tickets(office_id, offset=1) + ([None] * 9))[:9]
tickets_parameters.update({
f'p{_index + 1}':
f'{_resolve_ticket_index(_index)}{ticket.display_text}' if ticket else empty_text
for _index, ticket in enumerate(processed_tickets)})

# NOTE: Ensure `tickets_parameters` last value is as distinct as the `current_ticket`
# To fix `uniqueness` not picking up the change in passed waiting list
waiting_list_parameters[f'w{len(waiting_list_parameters)}'] = (current_ticket.name
if current_ticket.n else
current_ticket.number
) if current_ticket else empty_text
tickets_parameters[f'w{len(tickets_parameters)}'] = (current_ticket.name
if current_ticket.n else
current_ticket.number
) if current_ticket else empty_text

return jsonify(con=current_ticket_office_name,
cot=current_ticket_text,
cott=current_ticket_task_name,
**waiting_list_parameters)
**tickets_parameters)


@core.route('/set_repeat_announcement/<int:status>')
Expand Down
Binary file added static/images/map7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions templates/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -398,5 +398,80 @@ <h1 class='tickets mb-10'>
</h1>
</div>
</div>


{% elif tv == 3 %}
<div class="row">
<div class="col-xs-12 text-center">
<h1 class='title mt-1 mb-1'> {{ ts.title }} </h1>
</div>
</div>
<div class="row text-center mt-5">
<div class="col-xs-3">
<h1 class='tickets'>
<p class='watchit inline' stream='w1'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
<div class="col-xs-3">
<h1 class='tickets'>
<p class='watchit inline' stream='w2'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
<div class="col-xs-3">
<h1 class='tickets'>
<p class='watchit inline' stream='w3'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
<div class="col-xs-3">
<h1 class='tickets'>
<p class='watchit inline' stream='w4'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
</div>
<div class="row text-center mt-5">
{% if not settings.single_row %}
<div class="col-xs-4">
<h1 class='offices'>
{% if alias.office != 'Office' %}{{ alias.office }}{% else %}{{ translate('Office', 'en', [defLang]) }}{% endif %} :
<p stream='con' class='effectit ensureit inline'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
<div class="col-xs-4">
<h1 class='tasks'>
{% if alias.task != 'Task' %}{{ alias.task }}{% else %}{{ translate('Task', 'en', [defLang]) }}{% endif %} :
<p class='effectit ensureit inline' stream='cott'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
{% endif %}
<div class="col-xs-4">
<h1 class='tasks'>
{% if alias.ticket != 'Ticket' %}{{ alias.ticket }}{% else %}{{ translate('Ticket', 'en', [defLang]) }}{% endif %} :
<p class='effectdoit ensureit inline' stream='cot'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
</div>
<div class="row text-center mt-5">
<br>
<div class="col-xs-3">
<h1 class='tickets'>
<p class='watchit inline' stream='p1'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
<div class="col-xs-3">
<h1 class='tickets'>
<p class='watchit inline' stream='p2'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
<div class="col-xs-3">
<h1 class='tickets'>
<p class='watchit inline' stream='p3'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
<div class="col-xs-3">
<h1 class='tickets'>
<p class='watchit inline' stream='p4'>{{ translate('Empty', 'en', [defLang]) }}</p>
</h1>
</div>
</div>
{% endif %}
{% endblock %}
5 changes: 3 additions & 2 deletions templates/display_screen.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
'.tobc',
["{{ url_for('static', filename='images/map2.jpg') }}",
"{{ url_for('static', filename='images/map5.jpg') }}",
"{{ url_for('static', filename='images/map6.jpg') }}"],
"{{ url_for('static', filename='images/map6.jpg') }}",
"{{ url_for('static', filename='images/map7.jpg') }}"],
function (position) {
if (position === '1' || position === '2') $('.warn').removeClass('hide')
if (['1', '2', '3'].indexOf(position) != -1) $('.warn').removeClass('hide')
else $('.warn').addClass('hide')
}
)
Expand Down
6 changes: 6 additions & 0 deletions tests/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,10 @@ def test_feed_stream_tickets_preferences_enabled(c):
display_settings = Display_store.query.first()
display_settings.prefix = True
display_settings.always_show_ticket_number = True
display_settings.tmp = 3
db.session.commit()
tickets = Serial.get_waiting_list_tickets(limit=8)
processed_tickets = Serial.get_processed_tickets(limit=8, offset=1)
current_ticket = Serial.get_last_pulled_ticket()

response = c.get('/feed', follow_redirects=True)
Expand All @@ -533,6 +535,10 @@ def test_feed_stream_tickets_preferences_enabled(c):
assert ticket.name in response.json.get(f'w{i + 1}')
assert f'{ticket.office.prefix}{ticket.number}' in response.json.get(f'w{i + 1}')

for i, ticket in enumerate(processed_tickets):
assert ticket.name in response.json.get(f'p{i + 1}')
assert f'{ticket.office.prefix}{ticket.number}' in response.json.get(f'p{i + 1}')


@pytest.mark.usefixtures('c')
def test_feed_office_with_preferences_enabled(c):
Expand Down