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

Conversation

NiharikaRay
Copy link
Collaborator

Description of changeset: If you're the author of the webpost, you now get a button on top of the rendered post to quickly take you to the webeditor
screen shot 2017-01-11 at 4 18 48 pm

Test Plan:

  1. Create a webpost where you're the author, publish it, and ensure you see the button (and the button can be clicked to take you to the webpost)
  2. Create a webpost where you're not the author, and ensure the button doesn't show up.

Auto-reviewers: @matthewwardrop @earthmancash @danfrankj

Copy link
Collaborator

@matthewwardrop matthewwardrop left a comment

Choose a reason for hiding this comment

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

With this small change, LGTM. Thanks Nikki.

web_editor_prefixes = current_app.config['WEB_EDITOR_PREFIXES']
is_webeditor = []
if web_editor_prefixes:
is_webeditor = [prefix for prefix in web_editor_prefixes if prefix in path]
Copy link
Collaborator

Choose a reason for hiding this comment

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

prefix in path is a little too loose here, since sometimes a prefix could appear within the path at some other location than the beginning; e.g.: projects/webposts/why_you_should_use_git.kp.

Given that you are using it as a boolean indicator, perhaps you could simplify the code here by just doing:

show_webeditor_buttons = any(path.startswith(prefix) for prefix in current_app.config['WEB_EDITOR_PREFIXES'])

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Way cleaner! Fixed.

@@ -15,6 +15,11 @@
<button type="button" class="btn btn-default btn-raw">
View Raw Markdown
</button>
{% if is_author and webeditor_buttons %}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I think the server should completely control the logic of whether or not to show the button - so I'd have this bit of logic live in render.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Simplified to move the boolean logic into the python file. This whole file could use some of that simplification.

@@ -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.

@NiharikaRay NiharikaRay merged commit 63fa1be into master Jan 12, 2017
@NiharikaRay NiharikaRay deleted the nray_add_easy_link_to_webpost branch January 12, 2017 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants