TheRosettaFoundation / SOLAS-Match

Self-managed translation project interface
www.TheRosettaFoundation.org
GNU Lesser General Public License v3.0
12 stars 8 forks source link

Cannot update project word count #1267

Closed Paulina-Rosetta closed 7 years ago

Paulina-Rosetta commented 7 years ago

It seems I can olny change incorrect project word counts on the task pages but not on the project page.

Example: https://trommons.org/project/6223/view/

Actual word count is 4740, I changed it on the translation and proofreading tasks, but when I go to Edit Project and update it on the project page, it doesn't update.

alanbarrett commented 7 years ago

It works in Chrome, and I used it to set the project word count. However I cannot get figure out what is going wrong in Firefox. It is some issue with JavaScript...

The https://trommons.org/api/v0/projects/6223/updateWordCount/4741 call on its own works but when combined with the POST in Project Edit, the same call seems to not be received by the Trommons API... I am still trying to track it down.

Alan.
alanbarrett commented 7 years ago

It seems that the issue is that the POST causes Firefox to abort the AJAX connection with the server which was started in the validateForm() JavaScript. And consequently the API call does not seem to make it to Trommons. The abort then seems (naturally enough) to trigger the failure of the AJAX call which then returns an Alert to the user.

So it would seem we need to ensure the completion of the updateWordCount API call to Trommons before returning from the validateForm() JavaScript. I will try that. I have already simulated it by putting up an alert which delays the validateForm().

Alan.
alanbarrett commented 7 years ago

Sorry to be thinking out loud... options seem to be...

alanbarrett commented 7 years ago

We are using JQuery 1.9.0, which might be relevant as there could be bugs.

Alan.
aquilax commented 7 years ago

Where is this ajax call initiated in the code? I can try to debug it here.

alanbarrett commented 7 years ago

File: ui/js/ProjectAlter.js Line: 266, DAOupdateProjectWordCount(project_id, newWordCount, successWordCount, inconsistentWordCount, errorUpdatingWordCount); The $.ajax() is on line 622

https://loc.csisdmz.ul.ie/SOLAS-Match/project/345/alter/ triggers the issue (in Firefox). An alert comes up as the following line is triggered: .fail(functionOnFail); (line 647) Firefox seems to give up on the $.ajax() before it gets to the server (see my other comments)

Don't like the idea of going synchronous (or an equivalent wait until it completes).

Other option is to add Word Count to the POST, which would be the most "obvious" thing to do.

However it would be nice if the $.ajax() completed properly!

Thanks,

Alan.
alanbarrett commented 7 years ago

@aquilax I just want to point out that while we want to fix it, this is not urgent as this (setting Word Count) call can only be used by admins and there is a workaround. Also I checked that there are no other similar issues in the code.

Nevertheless I would appreciate your help getting the code to work rather that doing a workaround.

Alan.
aquilax commented 7 years ago

May the reason be that PUT is with empty data ?

alanbarrett commented 7 years ago

I have not looked at the spec for PUT recently, but I suppose that is a possibility... however it works perfectly when the validate is forced to return false (so no POST happens) or a delay is added before the POST, so I think not.

Alan.
alanbarrett commented 7 years ago

@aquilax ... Not that this is urgent, but are you planning to explore more over the weekend?

Or should I go ahead and look at the best fix to the issue.

Alan.
aquilax commented 7 years ago

@alanbarrett if you have idea how to fix it go ahead. I'm going on vacation next week and don't have much spare time. Sorry for blocking you.

alanbarrett commented 7 years ago

Adding the Word Count to POST is messy (as there are a number of different cases), so I will not do that.

Making the AJAX call synchronous is messy and dangerous, so I will not do that.

I could POST the form from JavaScript (after the Word Count AJAX call finishes) but that is messy also, given what we have works.

So I will add a button for Admins which sets the Word Count as a separate action.

Alan.
alanbarrett commented 7 years ago

@paulina This is now fixed. There will be a button ("Submit Word Count" under Word Count), for Site Admins only, which allows updating the Word Count (only). "Update Project Details" will update everything else. This works on all browsers (I believe).

see: commit e01369161848f6e522bad5ce280b4bdc144457c9

Alan.