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

added a save button to export JSON saved state of images #1161

Closed
wants to merge 13 commits into from
Closed

added a save button to export JSON saved state of images #1161

wants to merge 13 commits into from

Conversation

leilayesufu
Copy link
Contributor

Fixes #1139

i created a button in the archive.html, then i used font awesome to add a save icon in it and added it to the sidebar, then i created an array to push every image in, i then put added all the image to a collection then i ran the generateExportJson() on the collection

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 test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updates
  • @mention the original creator of the issue in a comment below for help or for a review

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!

@gitpod-io
Copy link

gitpod-io bot commented Oct 14, 2022

@leilayesufu
Copy link
Contributor Author

@jywarren Kindly review and leave corrections, thank you

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

This is a great start, thank you! I made a bunch of suggestions. Thanks a lot!

examples/archive.html Outdated Show resolved Hide resolved
placeButton.classList.add('btn', 'btn-sm', 'btn-outline-secondary', 'place-button');
placeButton.innerHTML = 'Place on map';

let imageGroup = L.distortableCollection().addTo(map)
Copy link
Member

Choose a reason for hiding this comment

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

Here, I'm not sure if we have to add it to the map - i think images will be added to the map when the user clicks "Place", right? Maybe we leave out addTo(map)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve also made this change

imageRow.classList.add('d-flex', 'justify-content-between', 'align-items-center', 'mb-4', 'pe-5');
imageRow.append(image, placeButton);

imageArray.push[image]
Copy link
Member

Choose a reason for hiding this comment

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

Should we do this only when the user presses the Place button? Maybe in the click handler down on line 141? https://github.com/publiclab/Leaflet.DistortableImage/pull/1161/files#diff-4e935909ea43d3a9c21496afdeae5865a74c6d7ee77640cf467b6e3911b6c63dL141

imageContainer.appendChild(imageRow);
imageCount++;

for(let i=0; i<imageArray.length;i++){
Copy link
Member

Choose a reason for hiding this comment

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

And likewise, here maybe we don't need to iterate with a for loop - we can just run imageGroup.addLayer(image[i]) down on line 141 when the user clicks "Place" -- does that make sense?

@@ -65,13 +67,18 @@ <h3 id="offcanvasRightLabel">Images</h3>
</body>

<script>
let map;
let map = L.map('map').setView([51.505, -0.09], 13);
Copy link
Member

Choose a reason for hiding this comment

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

Hi, I think this may be redundant with line 84, no?

@@ -11,6 +11,8 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<script src="../src/DistortableCollection.js"></script>
Copy link
Member

Choose a reason for hiding this comment

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

Here, I am not sure we need this or the next line in this PR, maybe these are left over from another pull request? Yes - it looks like you are making a PR from your main branch, so this can happen. It's OK as long as you remove these lines now, but in the future you can avoid this by working in a named branch for each new feature, instead of in your main branch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hii @jywarren
I’ve made all the required changes and the script I added was for the generateExportJson() so the function could be passed down
And yes yes, next time I’d work on a different branch
Thank youu

Copy link
Member

Choose a reason for hiding this comment

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

Aha, so what will happen is if you compile the code (I believe it's grunt build?) It will automatically include all files in the src directory into the files in /dist/, so you don't need to separately do this!

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh
Alright
I didn’t know that
Thank youu
Let me make the correction

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done
Thank youu

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The script tag below it is for the font awesome icon on the button.
The save icon

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

I made a bunch of suggested changes; see what you think! If they make sense, you can commit them, or ask questions!

I also want to admit that I'm not 100% sure this will work. We'll have to try it out to see. It could be that we actually have to wait until the last moment to add them all to the collection, instead of adding them as we go? But let's try getting this attempt running first and we'll be able to see when we try it out.

Thanks!

@@ -146,6 +156,8 @@ <h3 id="offcanvasRightLabel">Images</h3>
let imageURL = event.target.previousElementSibling.src;
let image = L.distortableImageOverlay(imageURL);
map.imgGroup.addLayer(image);
placedImagesArray.push[image]
imageGroup.addLayer(image[i])
Copy link
Member

Choose a reason for hiding this comment

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

here, i think we can just say image and not image[i] anymore, since we aren't in a for loop anymore.

Suggested change
imageGroup.addLayer(image[i])
placedImagesCollection.addLayer(image)

@@ -137,6 +145,8 @@ <h3 id="offcanvasRightLabel">Images</h3>
});
});

saveButton.addEventListener('click',generateExportJson(imageGroup))
Copy link
Member

Choose a reason for hiding this comment

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

Very close here! I think we will want to run it like this:

Suggested change
saveButton.addEventListener('click',generateExportJson(imageGroup))
saveButton.addEventListener('click', function() {
alert(placedImagesCollection.generateExportJson()); // we'll do something better than alert in the next PR
}

@@ -72,6 +73,12 @@ <h3 id="offcanvasRightLabel">Images</h3>
let input = document.getElementById('input');
let responseText = document.getElementById('response');
let imageContainer = document.getElementById('imgContainer');
let imageGroup = L.distortableCollection().addTo(map)
Copy link
Member

Choose a reason for hiding this comment

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

Let's rename this "placedImagesCollection" and remove the addTo(map)!

Suggested change
let imageGroup = L.distortableCollection().addTo(map)
let placedImagesCollection = L.distortableCollection()

@@ -114,14 +121,15 @@ <h3 id="offcanvasRightLabel">Images</h3>

placeButton.classList.add('btn', 'btn-sm', 'btn-outline-secondary', 'place-button');
placeButton.innerHTML = 'Place on map';

let imageGroup = L.distortableCollection()
Copy link
Member

Choose a reason for hiding this comment

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

Here we shouldn't have to declare this a second time. Let's remove it!

Suggested change
let imageGroup = L.distortableCollection()

@leilayesufu
Copy link
Contributor Author

@jywarren
Hope you’re having a great day, I have made the corrections and it all made sense to me, I do believe that this PR is on the right path and if it doesn’t work, it’s minor errors we can fix!
Thank youuu

@jywarren
Copy link
Member

This looks great! Thank you for all the changes. Are you able to test it out and upload a video? I'm trying to right now but my connection isn't very good.

examples/archive.html Outdated Show resolved Hide resolved
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
@jywarren
Copy link
Member

To test it, I navigate to /examples/archive.html from the root URL it's already at.

@leilayesufu
Copy link
Contributor Author

Thank youu

@jywarren
Copy link
Member

Just repeating here:

OK, so what I found was that, for some reason, this doesn't work... the images array is empty. But! I also found that we actually already have an distortableImageCollection in this page -- on line 96!

So on this line, we can do:

      alert(JSON.stringify(map.imgGroup.generateExportJson())); // we'll do something better than alert in the next PR

And we can also remove the lines on 76 and 77, since we are just going to use the Collection that's already defined in the page. What do you think?

@jywarren
Copy link
Member

Hmm. I can't seem to get this to work... it did work for a moment, but I'm not sure what I had changed.

Aha! Since there's a check on line 197:

generateExportJson() {
const json = {};
json.images = [];
this.eachLayer(function(layer) {
if (this.isCollected(layer)) {

...for whether the images have been selected, we actually have to go through and select the images. Hmm, how do we do that?

@jywarren
Copy link
Member

jywarren commented Oct 19, 2022 via email

@leilayesufu
Copy link
Contributor Author

Hii @jywarren
I’m sorry I haven’t been active the past day
I don’t think we should use the collection that’s already defined on the page in our click listener cause we have to addlayer(image) on it

@leilayesufu
Copy link
Contributor Author

Also about the line 197
I found that the is a function
So I just thought how about we just pass that function into the generateExportJson function

@jywarren
Copy link
Member

So I just thought how about we just pass that function into the generateExportJson function

Hi @leilayesufu i wonder... what if we make a parameter for generateExportJson() that is something like onlySelected and we only filter for isCollected if that is true, and we default it to true? That way we can use generateExportJson for this use case too, but just set onlySelected to false so we just get everything. What do you think?

@leilayesufu
Copy link
Contributor Author

Hii @jywarren
I was wondering how you were cause I hadn’t heard a review from you a while but I figured you were probably busy with other pull requests
I’d get working on your suggestions and update you

@jywarren
Copy link
Member

Thank you! Yes i had some big work commitments the past week but am catching up now!

@jywarren
Copy link
Member

Just noting that I've linked here from #1225 (comment) where there was a parallel effort also requiring this modified generateExportJson(isCollected = true)

@jywarren
Copy link
Member

Solved in #1237, thank you!!!

@jywarren jywarren closed this Feb 10, 2023
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.

Export JSON saved state of current images in MapKnitter Lite demo
2 participants