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

Improved JSON viewing/editing with Ace editor #214

Merged
merged 4 commits into from
Oct 24, 2017

Conversation

hogpilot
Copy link
Collaborator

@hogpilot hogpilot commented Oct 16, 2017

This PR includes a new integration of Ace Editor for viewing and editing JSON. Highlight.js was not meant for editing, and the previous line number integration didn't work very well when adding/deleting lines. Here are things to test:

  • Fixes Copying Full JSON into Data section does not "work" anymore #212
  • Fixes an unlogged bug where multiple update requests were being sent when the same item was saved multiple times
  • New capability to expand/collapse JSON
  • New logic for tooltip integration with the associated JSON buttons (copy/save/edit).
  • New capability to find/replace JSON text (Ctrl+F)

For now, a build of this PR is available at hogpilot/ago-assistant

@hogpilot
Copy link
Collaborator Author

I did not remove js\lib\highlight-8.3.min.js (even though it is not used), thoughts?

@bsvensson
Copy link
Member

The new code editor looks and works great :)

As far as the PR goes, I think most of those ace files are not needed. For example, we're only editing json files (not all file types).

@hogpilot
Copy link
Collaborator Author

@bsvensson I agree, and only found 4 files used in my testing:

  • js/lib/ace/ace.js
  • js/lib/ace/mode-json.js
  • js/lib/ace/theme-tomorrow.js
  • js/lib/ace/worker-json.js

I left the rest of them in there in case somewhere down the line, other ace options are utilized. I went back and forth about the proper approach for this scenario, but don't feel strongly one way or the other. For now, the full ace library source code is in there...

I'm open for thoughts on which approach to take. The current approach is safe, and while it increases the repo and deployment size, it has no impact on the client network traffic. I was afraid some other ace call might break things down the line if I removed a file that didn't come up in my testing.

@hogpilot
Copy link
Collaborator Author

Case and point, Find/Replace (Ctrl-F) triggers an additional file (thanks @bsvensson , i didn't know you could do that):

  • js/lib/ace/ext-searchbox.js

… tooltips on buttons when viewing/editing JSON. (squashed appId)
@hogpilot
Copy link
Collaborator Author

hogpilot commented Oct 17, 2017

Another note on which Ace files to include. Pressing Ctrl+, brings up a settings menu. You can change options/themes there, which will dynamically load additional ace files. It might be nice to leave that feature (give a try to see what I mean), which might not allow us to trim down the ace files. Or, we could just include the 5 or 6 files that @bsvensson identified and disable the settings menu.

I'm open to feedback if anyone feels strongly one way or another.

@slibby
Copy link
Member

slibby commented Oct 18, 2017

@hogpilot seeing a few strange characters on one item - highlighted in red:
image

@hogpilot
Copy link
Collaborator Author

@slibby interesting. Ace is telling you that there is an invalid or invisible character there. It turns out, this is because the JSON contains \u00A0 (or &nbsp, or character code 160) in the text. This is due to the ArcGIS Online WYSIWYG editor adding a non-breaking space.

Since this is not printable (other than as a space), Ace is differentiating it for you. I agree that red is not ideal, so I can override the CSS. How does this look?
image

…or invisible `&nbsp` character, and enabled theme change when in edit mode.
@hogpilot
Copy link
Collaborator Author

hogpilot commented Oct 18, 2017

@slibby @bsvensson thanks for the feedback. The latest commit includes the changes you mentioned:

  • Remove unused Ace files
  • Disable Ace settings menu Ctrl+,
  • Switch theme to dark background when editing
  • Change CSS for &nbsp character so it is not red

I think this is ready once testing is complete (@slibby? @rwmajor2? @ecaldwell?), let me know if you have questions.

@hogpilot
Copy link
Collaborator Author

Can someone else test https://hogpilot.github.io/ago-assistant/build/ in IE to see if they get weird cursor/text-selection behavior? If so, anybody have an idea of what CSS is the culprit? Thanks.

@bsvensson
Copy link
Member

Can someone else test https://hogpilot.github.io/ago-assistant/build/ in IE to see if they get weird cursor/text-selection behavior?

Yes, the cursor becomes the cursor-move cursor after clicking the edit/pen icon to go into Edit mode. Weird.

Double-clicking to select text does the right thing (functionally), but displays a selection box of sorts in the wrong place. Weird.

I don't see the same issue in IE11 for neither the JSAPI sandbox, nor the Ace kitchen sink.

If so, anybody have an idea of what CSS is the culprit?

Nope :(

…tenteditable` property of dom element). Fixed a few errors in html templates and removed unused css file from lib.
@hogpilot
Copy link
Collaborator Author

@bsvensson Thanks for checking. I found the culprit and fixed it in the latest commit. It had to do with our use of contenteditable attribute as it pertains to the Enter keypress. Apparently, IE didn't like me using that attribute on a div and when I added it to the Ace editor during edits, it threw off the CSS. Fix was to stop using the contenteditable attribute and instead rely on the .getReadOnly() operation of Ace.

@hogpilot
Copy link
Collaborator Author

Note: In my latest commit, I also snuck a few changes into templates.html that I found while searching for IE issue. These changes are not related to the PR, other than the fact that they are obvious errors that should be fixed (my opinion at least).

@ecaldwell
Copy link
Contributor

I also snuck a few changes into templates.html that I found

Nice find! Maybe this could be addressed with better linting.

@rwmajor2 rwmajor2 merged commit a5a4e10 into Esri:master Oct 24, 2017
@setldsolutions
Copy link

setldsolutions commented Nov 16, 2017

Without reading through all this: are we saying #212 and #213 are fixed (since both threads are closed)? E.g. the pasting of JSON back from notepad can now deal with the window's requirement for numbered lines? If so, that's great.

However, there is still another related issue. Simply hitting the pencil, so that I can click in the box, CTRL A, CTRL C and CTRL V into Notepad ++ takes wayyyyyyyyy longer than it used to. It used to take maybe 30 seconds to give me access to the text - now, it takes 15 browser waits and maybe 30 minutes.

@slibby
Copy link
Member

slibby commented Nov 16, 2017

@setldsolutions yes, both of those should be fixed in the latest code here on github, which has not yet been deployed to https://ago-assistant.esri.com. In the interim, you can try this build of the app first and see if you still have that delay: https://hogpilot.github.io/ago-assistant/build/ -- we are working on getting the latest build deployed.

@setldsolutions
Copy link

Thanks Sam.

@setldsolutions
Copy link

Confirmed working - no hitting the pencil to start editing necessary.

Simply click in the box, wait a sec, CTRL A, CTRL C, CTRL V to Notepad ++ --- 91k+ lines of JSON in 2 seconds.

Thanks again!

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.

6 participants