00 / wikihouse

An open community construction set.
http://wikihouse.cc
37 stars 7 forks source link

Wikihouse Extension not Downloading Models. Javascript error? #12

Open MrKriss opened 11 years ago

MrKriss commented 11 years ago

Hi thruflo, I'm currently looking into the above problem, and I think I have tracked the problem to the execution of a javascript function from within the extension code. Thing is I can't seem to find where the Javascript code is in the Website/Github repository.

The problem also seems to affect downloads using Chrome as well, though Firefox and safari are ok.

Could you point me in the direction of it so I can have a rummage around in the code?

Also, I'm a bit of a newbe at Web stuff and would appreciate some pointers on how to set up the site locally with Google App Engine so I can test any changes I make before committing them.

Cheers.

Chris

MrKriss commented 11 years ago

Found where the load fails in the Ruby end. The attempt to get the segment size for downloading in chunks fails here with segment_count = dialog.get_element_value "design-download-data" returning an empty string.

Can you check the coffee script bellow to make sure this element id is created and that its value is set to the segment count required.

From wikihouse / static / src / coffee / wikihouse.coffee

      wikihouse.download = (id, url) ->
        # Grab the model data over ajax.
        $.ajax
          type: 'GET'
          url: url
          dataType: 'text'
          success: (data) ->
            # Set the data into the hidden textarea.
            l = 1500000
            i = 0
            c = 0
            loop
              chunk = data.slice(c, c + l)
              if chunk.length is 0
                break
              $target = $('#design-download-data-' + i);
              $target.text(chunk)
              c = c + l
              i++
            $('#design-download-data').text(i)
            wikihouse.hideProgress()
            # Inform SketchUp of the available data.
            window.location = "skp:save@#{id}"
          error: ->
            wikihouse.hideProgress()
            # Inform SketchUp of the failed download.
            window.location = "skp:error@#{id}"```
thruflo commented 11 years ago

Hi @MrKriss sorry for not replying on this sooner.

Reading the code above, it looks fine and as long as the ajax call is successful then the text value of #design-download-data should be set to an integer. I guess either the ajax call is failing or the page markup has changed. / the element doesn't exist. Or the ruby is calling before the value is available.

If I'm to have a go at debugging, can I just check the steps I need to take: basically load the extension into sketchup where sketchup is using chrome as the browser and then try and download a model?

MrKriss commented 11 years ago

Hi @thruflo,

Yes the error was generated from trying to load a wikihouse model from within Sketchup using the plugin. Though strangely, now I go back to the code I cant seem to be able to reproduce the exact error I was seeing! Before, the call to wikihouse.downloads via Ruby, dialog.execute_script "wikihouse.download('#{download_id}', '#{base64_url}');" (Line 71 in WebDialogs.rb) was succeeding in finding data, but when executing window.location = "skp:save@#{id}" (Line 259 of wikihouse.coffee) in the javascript, the id was being passed as an empty string.

However now, the wikihouse.download call simply fails, and the window.location = "skp:error@#{id}" call is run instead, producing the popup: !! ERROR !! Couldn't download /Users/chris/Documents/WikiHouse Calibration Test.skp from Wikihouse. Please try again.

Interestingly though, the id is a number and not an empty string when parsed back to Ruby!

I've added a few outputs to the console on my testing branch before and after some of the callbacks are run. Hopefully this will aid in debugging.

The other thought I had was that it may be down to communication issues on the Mac version of Web Dialogues in particual. I found the following on points on synchronous vs asynchronous communication. Link. Do you think this could be part of the problem? Have yet to test this on a windows machine, so cant be certain this error crops up there as well.

MrKriss commented 11 years ago

Hi thruflo, did you get a chance to look into the above? I am assuming you did as downloads via the web dialogues are now working! (as of Sketchup 2013 on mac anyway!)

Cheers