jsoftware / j-playground

J playground
https://jsoftware.github.io/j-playground/bin/html2/
Other
10 stars 5 forks source link

Editor Log that uses localStorage #66

Open joebo opened 2 years ago

joebo commented 2 years ago

I often find myself copy/pasting scripts into the J Playground. It would be very useful if there was a facility that restored the editor contents when a new window is opened.

Proposed requirements:

  1. Whenever an instance of the playground is opened, a unique identifier is generated for that session
  2. Whenever the editor is run (or maybe on some timer) the editor contents are written to an Editor Log (stored in browser localStorage) with a timestamp for that session id
  3. Add a new option "Editor Log" under the View menu
  4. Clicking the "Editor Log" brings up a dialog similar to "Input Log" that shows the timestamp and an abbreviated form of the log entry.
  5. The user can pick the log entry to populate the editor window with the full contents
  6. The editor log keeps a reasonable # of sessions - maybe last 10?

Questions: Should this be called Session Log or Editor Log? I initially started with "Session Log" and renamed it to "Editor Log" to be more clear what it was doing.

Question: Should opening a new playground window automatically restore the contents of the last session?

I welcome feedback on this idea. @razetime this may be a good html/js one for you to tackle if you are interested in it

razetime commented 2 years ago

I have a few suggestions:

  1. The unique identifier should be the date and time of the session start
  2. The user should be able to download a log, or download the editor contents
  3. same as above for importing a file
  4. I recommend saving on run, and saving when the tab is closed.
  5. There should be a way to save a session manually

Should this be called Session Log or Editor Log? I initially started with "Session Log" and renamed it to "Editor Log" to be more clear what it was doing.

Editor log is more clear.

Should opening a new playground window automatically restore the contents of the last session?

Yes, absolutely. That should be the main point of having localstorage.

joebo commented 2 years ago

Thanks for the suggestions. If it were me, I would leave out the download and import functions for now. I think copy/paste is sufficient. I find browsers handle file downloads in a clunky way. The downloaded filename would be either be autogenerated like playground-2022-05-25-074031.ijs or it could be a defined name if the user had the ability to specify a name for the editor instance (might kind of useful for the editor log anyways).

My main complaint with the downloads is that it becomes a stream of file names in the Downloads folder. Duplicate names become suffixed with (1) (2) (3). As a result, I probably wouldn't use it. Maybe others would use the Download function though.

I think import is marginally useful. It was also submitted as #27. My feelings could be because my experience is that I don't have that many local j files to upload as I jump across devices throughout the day. Again, others may find it useful so I'm not against it, just sharing a perspective on it.

Outside of the Editor Log, I have thought about Google Drive or Github repository integration. It would be slick to point the Playground to an existing github repo and make it a web editor (similar to how the web version of vscode works by hitting . in a github repo) (https://docs.github.com/en/codespaces/the-githubdev-web-based-editor). I would lean into separating that idea and the upload/download into a separate github issue as both concepts seem like extensions of the core editor log idea.

jonghough commented 2 years ago

Doesn't localStorage have a storage size limit? This could affect the usage. I think I would possibly use the local download functionality, if it existed. Naming can be user specified, with time stamp suffix, or something like that. If that were possible, ability to load the session in jqt, or JHS would be something to think about in future.

joebo commented 2 years ago

It seems localStorage is at least 5MB on modern browsers, which is a lot of J code https://stackoverflow.com/a/25812530

On Thu, May 26, 2022, 9:23 AM Jon Hough @.***> wrote:

Doesn't localStorage have a storage size limit? This could affect the usage. I think I would possibly use the local download functionality, if it existed. Naming can be user specified, with time stamp suffix, or something like that. If that were possible, ability to load the session in jqt, or JHS would be something to think about in future.

— Reply to this email directly, view it on GitHub https://github.com/jsoftware/j-playground/issues/66#issuecomment-1138574127, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABFAFJZPKC4XRAEBOUQXQ3VL53OLANCNFSM5W2U47BQ . You are receiving this because you authored the thread.Message ID: @.***>

plj541 commented 2 years ago

Rather than dated auto saves, I prefer the old APL mainframe model. I have javascript code for )save )load )lib using localStorage. It has been available at https://plj541.github.io/Tools/ I also distingished workspaces from files.

I'd be happy to walk anyone through my code, including a Zoom demo.

razetime commented 2 years ago

I'm not sure if workspaces fit well in the J playground, but we can definitely have a command that immediately saves the editor's current state.

plj541 commented 2 years ago

I'm sorry for any confusion I've caused. I'm talking about saving the editor, but giving the saved version names rather than timestamps. I'd be fine with the default name being a time stamp. But for ideas I'm going to continue to use I'd like to be able to restore named versions.

plj541 commented 2 years ago

Thanks to this discussion, I've provided Term based commands for what I require. The latest version includes the ability to update without copy/paste. I'd appreciate feedback from anyone who has tried it.

I've updated: https://plj541.github.io/Tools/JPlayground.txt Words NB. Is removed for issues with csv files Edit NB. Reads or Writes to the Edit panel Link 'url' NB. Opens a new browser page Page 'url NB. Fetches a web page Next 'local' NB. Begins a simplistic demo Do 'string' NB. Which replaces 0!:101 to run things

Once you have JPlayground.txt installed, this will get Examples: Do Page 'https://plj541.github.io/Tools/Examples.txt' Then type: Do File 'Examples' NB. Which creates three simple demos and a Menu and also: File 'Updates' NB. Describes getting updates to either, or both

On Thu, Jun 9, 2022, 1:49 AM Paul Jackson [plj541@gmail.com](mailto:plj541@gmail.com) wrote: Thanks for the notice. When I looked at carefully, I realized you've recreated almost everyting we had in APL.js. I've put together a package of several of my always loaded tools, including three new ones for this platform.

I've put it on: https://plj541.github.io/Tools/JPlayground.txt but not in the index.html until I get some feedback on it from people here.

New verbs include: Ask 'question' NB. Uses Javascript prompt to take user reply NB. Dyadic provides a default response File 'this is' File 'thisOne' NB. Read and Write local storage Files '' NB. to discover what is there Files~'thisOne' NB. to remove one

It also self installs if you copy everything, paste into Edit and run All Lines. The last line of output shows how to create a brief but full bodied Bookmark.