Skip to content

Commit

Permalink
Adds research questions on the dashboard page.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavle Jonoski committed Dec 10, 2019
1 parent cb8cf03 commit 87a8dea
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 9 deletions.
22 changes: 19 additions & 3 deletions ckanext/knowledgehub/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,27 @@ def get_dashboards(limit=5, order_by='created_by asc'):
def remove_space_for_url(str):
return str.replace(" ", "-")


def format_date(str):
# split date & time
date = str.split('T') # date[0] is the date, date[1] is the time
time_basic = date[1].split('.') # time_basic[0] = hh/mm/ss
# remove seconds
date = str.split('T') # date[0] is the date, date[1] is the time
time_basic = date[1].split('.') # time_basic[0] = hh/mm/ss
# remove seconds
time_basic[0] = time_basic[0][:-3]
display_date = date[0] + ' at ' + time_basic[0]
return display_date


def dashboard_research_questions(dashboard):
questions = []
if dashboard.get('indicators'):
context = _get_context()
research_question_show = logic.get_action('research_question_show')
for indicator in dashboard['indicators']:
if indicator.get('research_question'):
question = research_question_show(context, {
'id': indicator['research_question']
})
questions.append(question)

return questions
3 changes: 3 additions & 0 deletions ckanext/knowledgehub/logic/action/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ def dashboard_create(context, data_dict):

dashboard = Dashboard()

import json
print json.dumps(data_dict, indent=2)

items = ['name', 'title', 'description', 'type']

for item in items:
Expand Down
3 changes: 2 additions & 1 deletion ckanext/knowledgehub/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def get_helpers(self):
'get_single_rq': h.get_single_rq,
'get_rqs_dashboards': h.get_rqs_dashboards,
'remove_space_for_url': h.remove_space_for_url,
'format_date': h.format_date
'format_date': h.format_date,
'dashboard_research_questions': h.dashboard_research_questions,
}

# IDatasetForm
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<section id="research-questions">
{% for question in questions%}
<a href="{{h.url_for('research_question.read', name=question.name)}}"
title="{{_('Research Question')}}: {{question.title}}">
<div class="research-question-badge btn btn-info">
<i class="fa fa-search"></i>
{{ question.title | truncate(30) }}
</div>
</a>
{% endfor %}
</section>
20 changes: 15 additions & 5 deletions ckanext/knowledgehub/templates/dashboard/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,21 @@
{% endif %}
</div>
{% endfor %}
<div id="screenshot-button">
<button class="btn btn-default download-dashboard-btn html2canvas-ignore pull-right"
data-module="download-dashboard-as-image">
<span class="fa fa-download"></span>{{ _('Download screenshot') }}
</button>
<div class="row"></div>
<div class="col-md-10 col-sm-12">
{% set research_questions = h.dashboard_research_questions(dashboard)%}
{% if research_questions %}
{% snippet 'dashboard/snippets/research_questions.html', questions=research_questions %}
{% endif%}
</div>
<div class="col-md-2 col-sm-12">
<div id="screenshot-button">
<button class="btn btn-default download-dashboard-btn html2canvas-ignore pull-right"
data-module="download-dashboard-as-image">
<span class="fa fa-download"></span>{{ _('Download screenshot') }}
</button>
</div>
</div>
</div>

</div>
Expand Down

0 comments on commit 87a8dea

Please sign in to comment.