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

[#2117] Markdown support for description fields #2121

Merged
merged 1 commit into from
May 3, 2016
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
24 changes: 18 additions & 6 deletions akvo/rsr/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,35 +151,47 @@ class Project(TimestampsMixin, models.Model):

goals_overview = ValidXMLTextField(
_(u'goals overview'), blank=True,
help_text=_(u'Provide a brief description of the overall project goals.')
help_text=_(u'Provide a brief description of the overall project goals. For links and '
u'styling of the text, <a href="https://github.com/adam-p/markdown-here/wiki/'
u'Markdown-Cheatsheet" target="_blank">Markdown</a> is supported.')
)
current_status = ValidXMLTextField(
_(u'baseline situation'), blank=True,
help_text=_(u'Describe the situation at the start of the project.')
help_text=_(u'Describe the situation at the start of the project. For links and styling of '
u'the text, <a href="https://github.com/adam-p/markdown-here/wiki/Markdown-'
u'Cheatsheet" target="_blank">Markdown</a> is supported.')
)
project_plan = ValidXMLTextField(
_(u'project plan'), blank=True,
help_text=_(u'Detailed information about the implementation of the project: the what, how, '
u'who and when.')
u'who and when. For links and styling of the text, <a href="https://github.com/'
u'adam-p/markdown-here/wiki/Markdown-Cheatsheet" target="_blank">Markdown</a> '
u'is supported.')
)
sustainability = ValidXMLTextField(
_(u'sustainability'), blank=True,
help_text=_(u'Describe how you aim to guarantee sustainability of the project until 10 '
u'years after project implementation. Think about the institutional setting, '
u'capacity-building, a cost recovery plan, products used, feasible '
u'arrangements for operation and maintenance, anticipation of environmental '
u'impact and social integration.')
u'impact and social integration. For links and styling of the text, '
u'<a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet" '
u'target="_blank">Markdown</a> is supported.')
)
background = ValidXMLTextField(
_(u'background'), blank=True,
help_text=_(u'This should describe the geographical, political, environmental, social '
u'and/or cultural context of the project, and any related activities that '
u'have already taken place or are underway.')
u'have already taken place or are underway. For links and styling of the text, '
u'<a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet" '
u'target="_blank">Markdown</a> is supported.')
)
target_group = ProjectLimitedTextField(
_(u'target group'), blank=True,
help_text=_(u'This should include information about the people, organisations or resources '
u'that are being impacted by this project.')
u'that are being impacted by this project. For links and styling of the text, '
u'<a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet" '
u'target="_blank">Markdown</a> is supported.')
)

# Results framework (always on)
Expand Down
10 changes: 10 additions & 0 deletions akvo/rsr/static/lib/scripts/micromarkdown-0.3.4.js

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

28 changes: 20 additions & 8 deletions akvo/rsr/static/scripts-src/project-main/project-main-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,13 @@ function renderReportTab() {
},

descriptions: function(proj) {
var projectPlanText = {__html: micromarkdown.parse(proj.project_plan)};
var goalsOverviewText = {__html: micromarkdown.parse(proj.goals_overview)};
var targetGroupText = {__html: micromarkdown.parse(proj.target_group)};
var backgroundText = {__html: micromarkdown.parse(proj.background)};
var currentStatusText = {__html: micromarkdown.parse(proj.current_status)};
var sustainabilityText = {__html: micromarkdown.parse(proj.sustainability)};

return (
React.DOM.div( {className:"row"},
React.DOM.div( {className:"col-sm-12"},
Expand All @@ -407,31 +414,31 @@ function renderReportTab() {
React.DOM.tbody(null,
React.DOM.tr(null,
React.DOM.th( {scope:"row"}, i18nReport.project_plan),
React.DOM.td(null, proj.project_plan)
React.DOM.td( {dangerouslySetInnerHTML:projectPlanText} )
),
React.DOM.tr(null,
React.DOM.th( {scope:"row"}, i18nReport.goals_overview),
React.DOM.td(null, proj.goals_overview)
React.DOM.td( {dangerouslySetInnerHTML:goalsOverviewText} )
),
React.DOM.tr(null,
React.DOM.th( {scope:"row"}, i18nReport.target_group),
React.DOM.td(null, proj.target_group)
React.DOM.td( {dangerouslySetInnerHTML:targetGroupText} )
),
React.DOM.tr(null,
React.DOM.th( {scope:"row"}, i18nReport.project_plan_summary),
React.DOM.td(null, proj.project_plan_summary)
),
React.DOM.tr(null,
React.DOM.th( {scope:"row"}, i18nReport.background),
React.DOM.td(null, proj.background)
React.DOM.td( {dangerouslySetInnerHTML:backgroundText} )
),
React.DOM.tr(null,
React.DOM.th( {scope:"row"}, i18nReport.current_status),
React.DOM.td(null, proj.current_status)
React.DOM.td( {dangerouslySetInnerHTML:currentStatusText} )
),
React.DOM.tr(null,
React.DOM.th( {scope:"row"}, i18nReport.sustainability),
React.DOM.td(null, proj.sustainability)
React.DOM.td( {dangerouslySetInnerHTML:sustainabilityText} )
),
React.DOM.tr(null,
React.DOM.th( {scope:"row"}, i18nReport.keywords),
Expand Down Expand Up @@ -630,9 +637,14 @@ var loadJS = function(url, implementationCode, location){
};

function loadAndRenderReact() {
function loadMarkdown() {
var markdownSrc = document.getElementById('markdown').src;
loadJS(markdownSrc, renderReportTab, document.body);
}

function loadReactDOM() {
var reactDOMSrc = document.getElementById('react-dom').src;
loadJS(reactDOMSrc, renderReportTab, document.body);
loadJS(reactDOMSrc, loadMarkdown, document.body);
}

console.log('No React, load again.');
Expand All @@ -648,7 +660,7 @@ document.addEventListener('DOMContentLoaded', function() {
projectIdReport = JSON.parse(document.getElementById('default-values').innerHTML).project_id;

// Check if React is loaded
if (typeof React !== 'undefined' && typeof ReactDOM !== 'undefined') {
if (typeof React !== 'undefined' && typeof ReactDOM !== 'undefined' && micromarkdown !== 'undefined') {
// Render React components
renderReportTab();
} else {
Expand Down
Loading