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

Keymapper phase 2 enhancements #243

Merged
merged 88 commits into from
Jul 30, 2019
Merged

Conversation

rexagod
Copy link
Member

@rexagod rexagod commented May 3, 2019

Fixes #239

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with grunt
  • code is in uniquely-named feature branch and has no merge conflicts 📁

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If tests do fail, click on the red X to learn why by reading the logs.

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@rexagod
Copy link
Member Author

rexagod commented May 3, 2019

Next up

  • "along the way lets figure out how to make keymapper_options and keymapper more convenient, perhaps merge them into one option."

  • "Update docs"

/cc @jywarren @sashadev-sky

@rexagod
Copy link
Member Author

rexagod commented May 4, 2019

Okay so how I've merged keymapper_position and keymapper is in a position param that will render the keymapper only when there's a non-null value passed to it.

 keymapper = new L.DistortableImage.Keymapper(map,img., {
        position: '' //keymapper not rendered
      });   

@rexagod
Copy link
Member Author

rexagod commented May 4, 2019

Open to other ideas regarding merging both these params, else I guess maybe we can proceed with this?

@rexagod rexagod changed the base branch from main to gh-pages May 5, 2019 12:25
@rexagod rexagod changed the base branch from gh-pages to main May 5, 2019 12:26
Copy link
Member

@sashadev-sky sashadev-sky left a comment

Choose a reason for hiding this comment

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

@rexagod
Ok so looking over this I am wondering about a few things. We might want to set up a time to Zoom to go over it if you'd like.

My main question is why make the keymapper extend the handler class? I see that it gives us the ability to choose whether the keymapper is placed on the map or not depending on whether we leave the line keymapper.enable() uncommented. But I don't see how this is different from having the keymapper extend L.control, and in the index.html file initializing it just like this:

new L.DistortableImage.Keymapper({position: 'bottomleft'}).addTo(map);

and commenting that line out if you don't want to have the keymapper on the page. This takes care of the position problem if we just add an L.setOptions(this, opts) to its initialize function.

We would have to get rid of the keymapper: false option for now but I think thats fine. If we really wanted to we could move this option to work with the keymapper class.

I was also unsure about its functionality because I found that after the keymapper is initially enabled, running keymapper.disable() does not remove it from the map, as img.editing.disable() removes the markers and toolbars from an image.

Would love some insight here because I could be misunderstanding the point! Also I think @jywarren initially suggested used L.handler. Was there a specific reason for that?

@rexagod
Copy link
Member Author

rexagod commented May 25, 2019

In response to #258

Untitled

cc @jywarren

@rexagod
Copy link
Member Author

rexagod commented May 25, 2019

@sashadev-sky I've noted your suggestions and will chime in a bit after I wrap up the CLI tool if it's not a problem? Thanks!

@jywarren
Copy link
Member

jywarren commented May 25, 2019 via email

@rexagod
Copy link
Member Author

rexagod commented May 25, 2019

Okay, no problem, and just to be clear, where should I place this 'x' button? Do you think that maybe we should use a fontawesome icon inside the button above (replace 'disable keymapper' with 'x' icon) or is there any particular position that would make more sense?

@jywarren
Copy link
Member

jywarren commented May 25, 2019 via email

@rexagod
Copy link
Member Author

rexagod commented May 26, 2019

@jywarren How does this look?

Capture

@sashadev-sky
Copy link
Member

@jywarren @rexagod do you think ability to hide keymapper should be addressed in a separate PR? And we can use a toggled icon for minimizing and expanding it? Because deleting is a permanent action and that might confuse people

also still need to review the implementation for this with @rexagod!

@rexagod
Copy link
Member Author

rexagod commented May 29, 2019

Would love some insight here because I could be misunderstanding the point! Also I think @jywarren initially suggested used L.handler. Was there a specific reason for that?

Hmm. I guess his response here should definitely pave the way for this PR. Pinging @jywarren.

I was also unsure about its functionality because I found that after the keymapper is initially enabled, running keymapper.disable() does not remove it from the map, as img.editing.disable() removes the markers and toolbars from an image.

@sashadev-sky disable() seems to work, or am I running a different use case scenario?

test

@jywarren
Copy link
Member

jywarren commented May 29, 2019 via email

@sashadev-sky
Copy link
Member

@jywarren #212 (comment) I think it might have been on accident you suggested but I could be wrong!

@rexagod hmm I think what I was referring to was that if you try to use disable() later on, like in the console perhaps, it doesn't disable the keymapper like it would with the handles.

If there isn't an identifiable benefit to making it in a handler class that then call the control class to create it, should we just refactor to make it control class like in my suggestion above?

@jywarren
Copy link
Member

I just turned off the keymapper in MapKnitter briefly until we get the "many keymappers appearing" and "ability to close keymapper" resolved: #243

Thanks!

I also thought we ought to make it not /ever/ open a 2nd keymapper, does that make sense?

Awesome!

@jywarren
Copy link
Member

That should relieve pressure on this PR so we can take a bit more time to get it right. Thanks, all!

@jywarren
Copy link
Member

image

@jywarren
Copy link
Member

Also I think @jywarren initially suggested used L.handler. Was there a specific reason for that?

Aha! So, in #212 (comment), I meant that we could give it its own namespace, /like/ the L.Handler example, but didn't mean that it should actually be named Handler. So, L.Keymapper maybe, or if it's very LDI specific, maybe L.DistortableImageKeymapper -- or even L.DistortableImage.Keymapper... although that then isn't as modular again. Make sense?

L.DistortableImage.Keymapper = L.Control.extend({
initialize: function(options) {
L.Control.prototype.initialize.call(this, options);
L.DistortableImage.Keymapper = L.Handler.extend({
Copy link
Member

Choose a reason for hiding this comment

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

So here, yeah - sorry, we don't need this to extend Handler - that was just a fragment of the code i was quoting. I mainly meant just putting this all in L.DistortableImage.Keymapper - which looks great!

@jywarren
Copy link
Member

Sorry, clarifying further re: Handler, i put an inline comment at #243 (comment)

@rexagod
Copy link
Member Author

rexagod commented Jun 1, 2019

And we can use a toggled icon for minimizing and expanding it? Because deleting is a permanent action and that might confuse people

I think what I was referring to was that if you try to use disable() later on, like in the console perhaps, it doesn't disable the keymapper like it would with the handles.

I also thought we ought to make it not /ever/ open a 2nd keymapper, does that make sense? -- Sasha review: confirming this is fixed!

test

@jywarren @sashadev-sky Okay so I've added the aforementioned changes to this, while holding on to the Handler -> Control one, for the following reasons.

  • No Hooks.
  • No enable/enabled methods.
  • Leaflet's doc on L.Control: "L.Control is a base class for implementing map controls. Handles positioning. All other controls extend from this class." Now in case of keymapper, I really don't think we need to "control" the map in any way (like the zoom buttons at the topleft), just the keymapper itself. As far as the positioning is concerned, we can already do that by passing the position parameter at instantiation.

Therefore, I didn't see any benefit from the refactoring, so I thought of discussing this out first. But I can be wrong, and thus ask your views on the same.

Thanks!!

@rexagod
Copy link
Member Author

rexagod commented Jun 1, 2019

Also, I'm currently using Handler wrapper class just for the above mentioned functionality it provides, while the actual keymapper is implemented in Control class itself (refer CSS class below).

var keymapper = L.control({position: this._position});
        keymapper.onAdd = function() {
            var el_wrapper = L.DomUtil.create("div", "l-container");
            el_wrapper.setAttribute('id', 'keymapper-wrapper');
            el_wrapper.innerHTML = "<table><tbody>" +
            "<tr><td><center><span id='keymapper-heading'>Keymappings</span></center></td></tr>" +
            "<tr><td id='keymapper-hr'><hr></td></tr>" +
            "<tr><td><kbd>j</kbd>, <kbd>k</kbd>: <span>Send up / down (stacking order)</span></td></tr>" +
            "<tr><td><kbd>l</kbd>: <span>Lock</span></td></tr>" +
            "<tr><td><kbd>o</kbd>: <span>Outline</span></td></tr>" +
            "<tr><td><kbd>s</kbd>: <span>Scale</span></td></tr>" +
            "<tr><td><kbd>t</kbd>: <span>Transparency</span></td></tr>" +
            "<tr><td><kbd>d</kbd> , <kbd>r</kbd>: <span>RotateScale</span> </td></tr>" +
            "<tr><td><kbd>esc</kbd>: <span>Deselect All</span></td></tr>" +
            "<tr><td><kbd>delete</kbd> , <kbd>backspace</kbd>: <span>Delete</span></td></tr>" +
            "<tr><td><kbd>caps</kbd>: <span>Rotate</span></td></tr>" +
            "<tr><td><center><button id='close-keymapper-button'>" + 
            "<kbd id='close-keymapper-kbd'>" + 
            "<i class='fa fa-times-circle' aria-hidden='true'></i>" + 
            "</kbd></button></center></td></tr>" +
            "</tbody></table>";
            return el_wrapper;
        };
        keymapper.addTo(this._map);

Screenshot (114)

@sashadev-sky
Copy link
Member

@rexagod I am going to pull this and rebase you because you've been out of the repo for a bit and then I will go over it!

Copy link
Member Author

@rexagod rexagod left a comment

Choose a reason for hiding this comment

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

The new look is awesome, @sashadev-sky! Congrats on fixing the Travis build, too! It can sure be quite frustrating at times!

LGTM! 😃🙌

@sashadev-sky sashadev-sky merged commit 0e68573 into publiclab:main Jul 30, 2019
This was referenced Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keymapper Pt. 2 - Modularity
3 participants