Reduce JavaScript function duplication and collect file groups into subfolders

Issue #536 resolved
David Platten created an issue

I'd like to reduce the duplication of the same JavaScript in multiple files.

I'd also like to create some sub-folders within js to group together code for different things.

Comments (19)

  1. David Platten reporter

    Changed CT filtered page to only show Hide, Show and Toggle series buttons if there is more than one series on the chart. Also implemented code so that only one of the Hide all or Show all buttons is showing at any one time. Also moved a couple of duplicate JavaScript functions to a file. References issue #537 and #536

    → <<cset d91da62cbabf>>

  2. Ed McDonagh

    Hi @dplatten - is there going to be any more work on this issue for 0.8.0? Is it complete, or should it be pushed to the next version?

  3. David Platten reporter

    I've tried to use Pycharm's refactor function to move JavaScript files into subfolders, such as "charts" and "skin-dose-map", but unfortunately this process doesn't update the paths in the associated templates. I'm not sure why. Unless someone knows of a way to easily do this I think we should park this for the next release, as I don't want to manually update each reference to the JavaScript files if I move them.

  4. Ed McDonagh

    I think that works, although having pushed a copy to testing one of the charts that happened to be selected doesn't seem to be returning. This search/these charts don't return the study frequency pie chart.

    It does come up with this error in the console:

    Uncaught TypeError: Cannot read property '0' of null
        at sortByName (http://testing.openrem.org/static/js/sorting.js:10:22)
        at Array.sort (native)
        at updateFrequencyChart (http://testing.openrem.org/static/js/charts/chartUpdateData.js:145:18)
        at Object.success (http://testing.openrem.org/static/js/ctChartAjax.js:81:17)
        at j (http://testing.openrem.org/static/js/jquery-1.11.0.min.js:2:27136)
        at Object.fireWith [as resolveWith] (http://testing.openrem.org/static/js/jquery-1.11.0.min.js:2:27949)
        at x (http://testing.openrem.org/static/js/jquery-1.11.0.min.js:4:22244)
        at XMLHttpRequest.b (http://testing.openrem.org/static/js/jquery-1.11.0.min.js:4:26298)
    sortByName @ sorting.js:10
    updateFrequencyChart @ chartUpdateData.js:145
    success @ ctChartAjax.js:81
    j @ jquery-1.11.0.min.js:2
    fireWith @ jquery-1.11.0.min.js:2
    x @ jquery-1.11.0.min.js:4
    b @ jquery-1.11.0.min.js:4
    XMLHttpRequest.send (async)
    send @ jquery-1.11.0.min.js:4
    ajax @ jquery-1.11.0.min.js:4
    (anonymous) @ ctChartAjax.js:15
    j @ jquery-1.11.0.min.js:2
    fireWith @ jquery-1.11.0.min.js:2
    ready @ jquery-1.11.0.min.js:2
    K @ jquery-1.11.0.min.js:2
    

    I don't know if this is related to moving the files. I suspect not?

  5. David Platten reporter

    @edmcdonagh thanks for this. The pie chart works for me (after a SHIFT+F5 to force a complete re-load).

  6. Ed McDonagh

    Good. If you have time, I did it as follows. Otherwise I'll try and do it tonight.

    • opened each of the files to be moved
    • In the cookie trail style file path bit at the top, right click, refactor, move.
    • added /charts to the path

    It would probably work if you right click on the file in project structure view or what ever is called.

  7. David Platten reporter

    OK - will do. It seems to work for me in Pycharm at home, but not on my version at work.

  8. David Platten reporter

    I just wondered if a couple more JavaScript files could be deleted? npm.js, response.min.js and respond.min.js. I don't know what they're for.

  9. Ed McDonagh

    I'm going to merge it in for now. Do you want it closed or not? My preference would be to close it and create another for any more js improvements.

  10. Log in to comment