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

WIP History additional metadata #108

Merged
merged 2 commits into from
Jul 30, 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
10 changes: 8 additions & 2 deletions app/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import flask
from flask import render_template
from flask_jwt_extended import jwt_required
from flask_jwt_extended import jwt_required, get_jwt_identity
import pandas as pd
from sqlalchemy import func, and_

Expand Down Expand Up @@ -98,6 +98,7 @@ def post_core_data_json(payload):
context = payload['context']
flask.current_app.logger.info('Creating new batch from context: %s' % context)
batch = Batch(**context)
batch.user = get_jwt_identity()
db.session.add(batch)
db.session.flush() # this sets the batch ID, which we need for corresponding coreData objects

Expand Down Expand Up @@ -207,6 +208,7 @@ def edit_core_data():
context = payload['context']
flask.current_app.logger.info('Creating new batch from context: %s' % context)
batch = Batch(**context)
batch.user = get_jwt_identity()
batch.isRevision = True
db.session.add(batch)
db.session.flush() # this sets the batch ID, which we need for corresponding coreData objects
Expand Down Expand Up @@ -269,10 +271,11 @@ def edit_core_data_from_states_daily():
return flask.jsonify('No state specified in batch edit context'), 400

flask.current_app.logger.info('Creating new batch from context: %s' % context)
# TODO: if there's any other info that should go into a batch note, put it there
batch = Batch(**context)
batch.user = get_jwt_identity()
batch.isRevision = True
batch.isPublished = True # edit batches are published by default
batch.publishedAt = datetime.utcnow()
db.session.add(batch)
db.session.flush() # this sets the batch ID, which we need for corresponding coreData objects

Expand Down Expand Up @@ -359,6 +362,9 @@ def get_state_date_history(state, date):

rows = list_history_for_state_and_date(state.upper(), date)
row_dicts = pd.DataFrame(x.to_dict() for x in rows).to_dict('records')
for idx, row in enumerate(row_dicts): # copy in the associated batch data
row['batch'] = rows[idx].batch

return render_template(
'state_date_history.html',
title='State Date History',
Expand Down
4 changes: 4 additions & 0 deletions app/models/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class Batch(db.Model, DataMixin):
batchNote = db.Column(db.String)
dataEntryType = db.Column(db.String)

logCategory = db.Column(db.String)
link = db.Column(db.String)
user = db.Column(db.String)

# false if preview state, true if live
isPublished = db.Column(db.Boolean, nullable=False)
isRevision = db.Column(db.Boolean, nullable=False)
Expand Down
45 changes: 44 additions & 1 deletion app/templates/state_date_history.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,56 @@ <h2>{{state}} history table for {{date}}</h2>
{% for dict_item in data %}
<tr>
{% for value in dict_item.values() %}
<td> {{ value }} </td>
{% if loop.index == 2 %}
<td><a tabindex="0" role="button" data-toggle="popover"
data-batchId="{{ value }}"
data-link="{{ dict_item.batch.link }}"
data-logCategory="{{ dict_item.batch.logCategory }}"
data-user="{{ dict_item.batch.user }}"
data-batchNote="{{ dict_item.batch.batchNote }}"
data-shiftLead="{{ dict_item.batch.shiftLead }}"
data-createdAt="{{ dict_item.batch.createdAt.strftime("%Y-%m-%d %H:%M") }}">{{ value }}</a></td>
{% else %}
<td> {{ value }} </td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</table>
</div>

</div>

{% endblock %}

{% block scripts %}
{{super()}}

<style>
.popover {
max-width: 35%;
}
</style>
<script>
$(function () {


$('[data-toggle="popover"]').each(function() {

const link_block = $(this).attr('data-link') ? `<a href="${$(this).attr('data-link')}">link</a>` : '';
$(this).popover({
container: 'body',
trigger: 'focus',
html: true,
content: `Batch #${$(this).attr('data-batchId')} (${$(this).attr('data-shiftLead')})<br />
${$(this).attr('data-createdAt') }<br />
${$(this).attr('data-logCategory') ? $(this).attr('data-logCategory') : ''}<br />
${link_block}<br /><br />
${$(this).attr('data-batchNote')}`,
});
});
});
</script>
{% endblock %}

</body>
32 changes: 32 additions & 0 deletions migrations/versions/7a2068644cd6_batch_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""batch metadata

Revision ID: 7a2068644cd6
Revises: fc83a3cf66ba
Create Date: 2020-07-29 15:33:51.214242

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '7a2068644cd6'
down_revision = 'fc83a3cf66ba'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('batches', sa.Column('link', sa.String(), nullable=True))
op.add_column('batches', sa.Column('logCategory', sa.String(), nullable=True))
op.add_column('batches', sa.Column('user', sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('batches', 'user')
op.drop_column('batches', 'logCategory')
op.drop_column('batches', 'link')
# ### end Alembic commands ###