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

[KR] Add easy link to webeditor #192

Merged
merged 1 commit into from
Jan 12, 2017
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
8 changes: 7 additions & 1 deletion knowledge_repo/app/routes/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def render():

is_author = user_id in [author.id for author in post.authors]

web_editor_prefixes = current_app.config['WEB_EDITOR_PREFIXES']
is_webpost = False
if web_editor_prefixes:
is_webpost = any(prefix for prefix in web_editor_prefixes if path.startswith(prefix))

rendered = render_template(tmpl,
html=html,
post_id=post.id,
Expand All @@ -115,7 +120,8 @@ def render():
total_likes=post.vote_count,
tags_list=tags_list,
user_subscriptions=user_subscriptions,
webeditor_buttons=False,
show_webeditor_button=is_webpost and is_author,
webeditor_buttons=is_webpost,
web_uri=post.kp.web_uri,
table_id=None,
is_private=(post.private == 1),
Expand Down
9 changes: 9 additions & 0 deletions knowledge_repo/app/templates/markdown-base.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<button type="button" class="btn btn-default btn-raw">
View Raw Markdown
</button>
{% if is_author and show_webeditor_button %}
<button type="button" class="btn btn-default btn-webeditor">
View post in webeditor
</button>
{% endif %}
</div>
</div>
<div class="col-md-2">
Expand Down Expand Up @@ -89,6 +94,10 @@
$(".btn-raw").on("click", function(){
document.location.href = "/raw?markdown=" + encodeURI(post_path);
})

$(".btn-webeditor").on("click", function(){
document.location.href = "/posteditor?path=" + encodeURI(post_path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be using url_for ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. But since there are other links with the same problem, let's resolve this in a different PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, totally agree! I believe the reason that it's done this way was that it's bad practice to mix jinja templating code with JS (which I did above for some reason, and should also be fixed). We should be able to take this out and replace it with a url_for in another PR.

})
});

</script>
Expand Down