HGustavs / LenaSYS

Code Viewer and Course Organization System used in some courses at University of Skövde
57 stars 31 forks source link

Deleting multiple items in courseversion doesn't work #16167

Open a22chrfa opened 4 months ago

a22chrfa commented 4 months ago

image

In the image, I have marked "HTML5 Example 2", "HTML5 Example 3" and "HTML5 Example 4". When clicking the trashcan and clicking "yes" in the confirmation box. Only the first item in the list is removed. Furthermore, if clicking "yes" again, nothing happens.

a22chrfa commented 4 months ago

Log: Back from lunch. I just popped in to the database to confirm what happens there. I have heard from previous conversations that the items are in certain cases only hidden at first due to the undo selection and so on. So I just wanted to confirm what happens in the database.

The first item is correctly removed from the database. The second item (even if I click "yes" again) is not removed from the website, and is not removed from the database. So the web seems to reflect the database in this regard.

I will now look at the code and document how this process actually works in the background.

a22chrfa commented 4 months ago

Log: added some potential issues to the original issue-text.

a22chrfa commented 4 months ago

When marking items, the items are stored in an array called "selectedItemList". I've added an eventlistener in order to track this list during interactions.

Action called when clicking trashcan: confirmBox("openConfirmBox", this);

When marking multiple items and clicking one of the trashcans, the confirmation windows pops up. When clicking yes, this is what the log looks like: image

Even when closing the popup window, the array looks the same. So one issue is that the item isn't cleared from the array. Another issue is that it doesn't clear the entire array. It seems from both the UI and the function that this was meant to only delete one item.

a22chrfa commented 4 months ago

image image

The attached images visualize the callstack up to deleteAll() which then makes an ajax call.

I tried something quick before reaching to the ajax-call. I added a loop for selectedItemList in the first function, with the intent of iterating through every item to make a call for deletion. This didn't work, which isn't surprising now that I've seen that there is in fact a "deleteAll()" function that is actually made for this purpose. I'll probably have to observe the ajax-call.

a22chrfa commented 4 months ago

I tried the following: image

That didn't work either. I also removed the clearing of the array since the combination with the ajax-call might've removed the cleared the array during the call. This had no effect either. Still, only the first item is removed.

a22chrfa commented 4 months ago

So the console.log errors mentioned in an earlier post seem to have been caused by the intial styling of the element in the first section of deleteItem(). I'm aware this makes the page respond to the deletion instantly and removing the item from sight. But right now I'm focused on having all of the items removed from the database. So We'll ignore the styling for now.

I removed the styling and the timeout. I also edited the iteration of the array in deleteAll(). Code below: image

This still doesnt work for deleting the items from the database though. I can confirm that the "delArr" consists of the elements selected. So they should all be sent through the AJAXService. Not really sure why that's not working. I guess I'll continue looking past the AJAX-call to see what happens to each item.

a22chrfa commented 4 months ago

Found a few other things I need to explore and understand before I trace the AJAX call.

Looking closer at this: image

It seems fishy first of all. First of all, the array is pushed twice. Probably not intended. But also, lid is in our case an array due to the line "lid = item_lid ? item_lid : $("#lid").val();".

lid is then pushed into the delArr array. Which makes it a nested array. Lid is an array inside the first element of the delArr array. This might be the culprit.

a22chrfa commented 4 months ago

So, deleting the items in the database now works in my code. The issue seems to have been that the array "delArr" isn't actually populated by elements containing the listitems, it contained an array in it's first index, that contained the actual listitems.

I will now try to uncomment the timer and the clearing of the array and see if everything still works.

I noticed the log errors regarding the timer seems to be caused by incorrectly identifying elements. So I expect those errors to come back, and I will have a look at those as well.

a22chrfa commented 4 months ago

Had forgotten to assign myself. I am now assigned and have also made a first commit.

a22chrfa commented 4 months ago

I was planning on fixing the styling as well since it generated errors. But it nothing to do with the actual issue here and would probably be more related to an issue related to the undo button, since the styling is an assisting function for the undo feature, and the undo feature is not working at all. So better packeted there.

I did however have a look at it and was able to conclude that the for loop for styling was illogical and therefore not able to identify it's elements, for more than one reason. I also noticed that the "lid" stored in the array is only used as an ID with "lid" as a prefix. It's used as a value on elements but it's used on more than one. So there's a bit of extra info.

I will make a small change and then make a pull request.