Skip to content

Commit

Permalink
Customized columns for member table
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronTraas committed Jul 24, 2019
1 parent 645de58 commit 6d487a7
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 12 deletions.
16 changes: 16 additions & 0 deletions crtools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@
'vacation' : [],
'safe' : []
},
'member_table': {
'show_rank' : True,
'show_rank_previous' : False,
'show_name' : True,
'show_score' : True,
'show_trophies' : True,
'show_donations' : True,
'show_donations_recieved' : False,
'show_last_seen' : False,
'show_days_inactive' : True,
'show_current_war' : True,
'show_warlog' : True
},
'crtools' : {
'debug' : False,
'locale' : 'en',
Expand Down Expand Up @@ -123,6 +136,7 @@ def __localize_strings(locale_id):
'labelWarVictories' : _('Victories'),
'labelWarCards' : _('Cards Earned'),
'labelMember' : _('Member'),
'labelRankPrevious' : _('Previous'),
'labelMemberName' : _('Member Name'),
'labelMemberTag' : _('Member Tag'),
'labelMemberJoinDate' : _('Join Date'),
Expand All @@ -134,9 +148,11 @@ def __localize_strings(locale_id):
'labelRank' : _('Rank'),
'labelTrophies' : _('Trophies'),
'labelDonations' : _('Dona­tions'),
'labelDonationsRecieved' : _('Donations recieved'),
'labelDaysInactive' : _('Days Inactive'),
'labelDays' : _('Days'),
'labelDay' : _('Day'),
'labelLastSeen' : _('Last Seen'),
'labelCurrentWar' : _('Current War'),
'labelNotInClan' : _('Not in clan'),
'labelNA' : _('N/A'),
Expand Down
2 changes: 2 additions & 0 deletions crtools/crtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ def enrich_member_with_history(config, fresh_member, historical_members, days_fr
enriched_member['donations_last_week'] = historical_member['donations_last_week']
enriched_member['days_inactive'] = (now - datetime.fromtimestamp(enriched_member['last_activity_date'])).days
enriched_member['days_inactive'] = enriched_member['days_inactive'] if enriched_member['days_inactive'] >= 0 else 0
enriched_member['last_seen'] = datetime.strptime(enriched_member['last_seen'].split('.')[0], '%Y%m%dT%H%M%S').strftime('%c')
#collection_end_time = datetime.strptime(current_war_processed['collection_end_time'].split('.')[0], '%Y%m%dT%H%M%S')

if enriched_member['join_date'] == 0:
enriched_member['join_date_label'] = config['strings']['labelBeforeHistory']
Expand Down
22 changes: 21 additions & 1 deletion crtools/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
CLAN_LOG_FILENAME = 'clan_logo.png'
FAVICON_FILENAME = 'favicon.ico'

MEMBER_TABLE_CSS_MAPPING = {
'show_rank' : 'rank',
'show_rank_previous' : 'rank.previous',
'show_name' : 'name',
'show_score' : 'score',
'show_trophies' : 'trophies',
'show_donations' : 'donations',
'show_donations_recieved' : 'donations-recieved',
'show_last_seen' : 'last-seen',
'show_days_inactive' : 'inactivity',
'show_current_war' : 'war.current',
'show_warlog' : 'war.previous'
}

def write_object_to_file(file_path, obj):
""" Writes contents of object to file. If object is a string, write it
directly. Otherwise, convert it to JSON first """
Expand Down Expand Up @@ -57,6 +71,11 @@ def parse_templates(config, history, tempdir, clan, members, former_members, cur
undefined=StrictUndefined
)

hidden_columns = []
for key, value in MEMBER_TABLE_CSS_MAPPING.items():
if config['member_table'][key] != True:
hidden_columns.append(value)

dashboard_html = env.get_template('page.html.j2').render(
version = __version__,
config = config,
Expand All @@ -69,7 +88,8 @@ def parse_templates(config, history, tempdir, clan, members, former_members, cur
recent_wars = recent_wars,
suggestions = suggestions,
scoring_rules = scoring_rules,
former_members = former_members
former_members = former_members,
hidden_columns = hidden_columns
)

write_object_to_file(os.path.join(tempdir, 'index.html'), dashboard_html)
Expand Down
39 changes: 28 additions & 11 deletions crtools/templates/member-table.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
<table id="member-table" width="100%" data-filter="none">
<thead>
<tr>
<th data-sort-default>#</th>
<th>{{strings.labelMember}}</th>
<th>{{strings.labelScore}}</th>
<th>{{strings.labelTrophies}}</th>
<th>{{strings.labelDonations}}</th>
<th>{{strings.labelDaysInactive}}</th>
<th data-sort-method="none">{{strings.labelCurrentWar}}</th>
<th class="rank" data-sort-default>#</th>
<th class="rank previous">{{strings.labelRankPrevious}}</th>
<th class="name">{{strings.labelMember}}</th>
<th class="score">{{strings.labelScore}}</th>
<th class="trophies">{{strings.labelTrophies}}</th>
<th class="donations">{{strings.labelDonations}}</th>
<th class="donations-recieved">{{strings.labelDonationsRecieved}}</th>
<th class="inactivity">{{strings.labelDaysInactive}}</th>
<th class="last-seen">{{strings.labelLastSeen}}</th>
<th class="war current" data-sort-method="none">{{strings.labelCurrentWar}}</th>
{% for war in recent_wars %}
<th data-sort-method="none">{{war.date}}</th>
<th class="war" data-sort-method="none">{{war.date}}</th>
{% endfor %}
</tr>
</thead>
<class="list">
{% for member in members %}
<tr data-blacklist="{{ 'true' if member.blacklist else 'false' }}" data-nopromote="{{ 'true' if member.no_promote else 'false' }}" data-score="{{member.score}}" data-activity="{{member.activity_status}}" data-status="{{member.status}}" data-clanrole="{{member.role}}" data-currentwar="{{member.currentWar.status}}" data-leadership="{{member.leadership}}" data-vacation="{{member.vacation}}" data-new="{{ 'true' if member.new else 'false' }}">
<td class="id" data-sort="{{member.clan_rank}}">
<td class="id rank" data-sort="{{member.clan_rank}}">
{% if member.clan_rank < member.previous_clan_rank %}
<span class="rank-up">
{% elif member.clan_rank > member.previous_clan_rank %}
Expand All @@ -29,6 +32,9 @@
<strong>{{member.clan_rank}}</strong>
</span>
</td>
<td class="rank previous" data-sort="{{member.previous_clan_rank}}">
<strong>{{member.previous_clan_rank}}</strong>
</td>
<td class="name" data-sort="{{member.name}}" data-role="dialog-show" data-target="member-detail" data-member-tag="{{member.tag}}">
<strong>{{member.name}}</strong><br />
<small class="member-role">{{member.role_label}}</small>
Expand Down Expand Up @@ -60,9 +66,15 @@
</dl>
</div>
</td>
<td class="donations-recieved" data-sort="{{member.donations_received}}">
<strong>{{member.donations_received}}</strong><br />
</td>
<td class="inactivity {{member.activity_status}}" data-sort="{{member.days_inactive}}" >
<strong>{{member.days_inactive}}</strong><br /><small>{{strings.labelDays}}</small>
</td>
<td class="last-seen" data-sort="{{member.last_seen}}" >
{{member.last_seen}}
</td>
<td class="war current {{member.currentWar.status}}" data-tooltip="true">
{% if member.currentWar.battles_played is defined %}
<div data-role="war">
Expand Down Expand Up @@ -117,7 +129,7 @@
{% endif %}
</td>
{% for war in member.warlog %}
<td class="war {{war.status}}" data-tooltip="true">
<td class="war previous {{war.status}}" data-tooltip="true">
{% if war.battles_played is defined %}
<div data-role="war">
<div>
Expand Down Expand Up @@ -172,4 +184,9 @@
</tbody>
</table>
</div>
</div>
</div>
<style>
{% for selector in hidden_columns %}
#member-table tr .{{selector}} { display: none !important; }
{% endfor %}
</style>
13 changes: 13 additions & 0 deletions samples/crtools.ini
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ threshold_kick=0
# elder.
threshold_promote=160

[member_table]

show_rank=True,
show_rank_previous=False,
show_name=True,
show_score=True,
show_trophies=True,
show_donations=True,
show_donations_recieved=False,
show_last_seen=False,
show_days_inactive=True,
show_current_war=True,
show_warlog=True

[members]
# Members who are on vacation. Will display them as on vacation, and
Expand Down

0 comments on commit 6d487a7

Please sign in to comment.