From 3fbe7f7a303cdad41d366ad725d0f87339437e9e Mon Sep 17 00:00:00 2001 From: doug-salvati Date: Fri, 18 Aug 2017 16:22:06 -0400 Subject: [PATCH 01/26] Restores & fixes functionality for group by num fields --- .../visualizations/highvis/baseVis.coffee.erb | 32 +++++++++++++++++-- .../highvis/highmodifiers.coffee | 14 ++++---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb index 4bb7f6b78..8ffbc2168 100644 --- a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb +++ b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb @@ -179,10 +179,36 @@ $ -> when @ANALYSISTYPE_MEDIAN then data.getMedian when @ANALYSISTYPE_COUNT then data.getCount - hiddenFields = data.fields.map((field) -> field.fieldID).filter((id) -> id == -1).length - for fieldId, index in data.groupSelection - fData[index] = analysisMethod.call(data, fieldId + hiddenFields, null, dp) + # PROBLEM: + # Fields aren't necessarily in alphabetical order in DB + # SOLUTION: + # Map the group selection to reflect the discrepency + hiddenFields = data.fields.map((field) -> field.fieldID).filter((id) -> id == -1).length + console.log hiddenFields + + # Relevant fields in alpahbetical selection list order + selectionOrder = data.groups + + # Relevant fields in internally-stored project order + internalOrder = [] + for elt, i in data.fields + internalOrder[i] = elt + internalOrder = internalOrder.splice(hiddenFields, internalOrder.length) + ignoredFields = internalOrder.findIndex (f) -> f.typeID is data.types.NUMBER + internalOrder = internalOrder.filter (f) -> f.typeID is data.types.NUMBER + internalOrder = internalOrder.map (f) -> f.fieldName + + # Map the group selection to reflect the discrepency + mappedSelections = [] + for elt in data.groupSelection + correspondingField = selectionOrder[elt] + actualIdxOfField = internalOrder.findIndex (fieldName) -> fieldName is correspondingField + mappedSelections[actualIdxOfField] = elt; + + # Get the data + for fieldId, index in mappedSelections + fData[fieldId] = analysisMethod.call(data, index + hiddenFields + ignoredFields, null, dp) return fData ### diff --git a/app/assets/javascripts/visualizations/highvis/highmodifiers.coffee b/app/assets/javascripts/visualizations/highvis/highmodifiers.coffee index 917b0c6eb..f5129c19a 100644 --- a/app/assets/javascripts/visualizations/highvis/highmodifiers.coffee +++ b/app/assets/javascripts/visualizations/highvis/highmodifiers.coffee @@ -474,6 +474,11 @@ $ -> if data.fields[f].fieldID != -1 groups.push(data.fields[f].fieldName) else + for dp in @dataPoints + if dp[gIndex] isnt null + result[String(dp[gIndex])] = true + groups = for keys of result + keys if gIndex == data.TIME_PERIOD_FIELD #and globals.configs.isPeriod timestampIndex = data.timeFields[0] @@ -487,14 +492,7 @@ $ -> else period = globals.getCurrentPeriod(new Date(timestamp)) point[data.TIME_PERIOD_FIELD] = period - - for dp in @dataPoints - if dp[gIndex] isnt null - result[String(dp[gIndex])] = true - - groups = for keys of result - keys - + groups.sort() ### From 7058bb7c105598236ac5bf328064534483ffd413 Mon Sep 17 00:00:00 2001 From: doug-salvati Date: Tue, 12 Sep 2017 11:04:48 -0400 Subject: [PATCH 02/26] Continued fix --- .../javascripts/visualizations/highvis/baseVis.coffee.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb index 03defb810..7f2bf62ad 100644 --- a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb +++ b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb @@ -231,10 +231,10 @@ $ -> # Map the group selection to reflect the discrepency hiddenFields = data.fields.map((field) -> field.fieldID).filter((id) -> id == -1).length - console.log hiddenFields # Relevant fields in alpahbetical selection list order selectionOrder = data.groups + console.log selectionOrder # Relevant fields in internally-stored project order internalOrder = [] @@ -244,6 +244,7 @@ $ -> ignoredFields = internalOrder.findIndex (f) -> f.typeID is data.types.NUMBER internalOrder = internalOrder.filter (f) -> f.typeID is data.types.NUMBER internalOrder = internalOrder.map (f) -> f.fieldName + console.log internalOrder # Map the group selection to reflect the discrepency mappedSelections = [] From 979cc134eac7075e4e466a17041a7c8ee512d8a6 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Wed, 8 Nov 2017 14:21:31 -0500 Subject: [PATCH 03/26] Remove white bars of sides of featured vis --- app/assets/stylesheets/application.css.scss | 4 ++++ app/views/home/index.html.erb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 3acbfda11..aa1474328 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -267,6 +267,10 @@ body { } } +#featured_vis { + padding: 0; +} + #news { background: #bcd66f; background: -moz-linear-gradient(top, #bcd66f 0%, #60c600 40%, #1f9100 100%); diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index b6f9173d3..e461680f5 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -31,7 +31,7 @@ See More Visualizations -
+
-
+ +
From 649e1c874039cd13fb1accfb50e9f9969f0c63b5 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Mon, 20 Nov 2017 18:27:23 -0500 Subject: [PATCH 14/26] tiny style corrections in project_controler.rb --- app/controllers/projects_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 603ace1e5..bf614a2e3 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -102,8 +102,8 @@ def edit @new_contrib_key = ContribKey.new @new_contrib_key.project_id = @project.id end -# POST /projects -# POST /projects.json + # POST /projects + # POST /projects.json def create if params[:project_id] cloned_from = Project.find(params[:project_id]) @@ -458,10 +458,10 @@ def finishTemplateUpload flash[:error] = field.errors.full_messages redirect_to project_path(@project) and return end + # Don't save fields until we know they are all valid fields.push(field) end - # Don't save fields until we know they are all valid fields.each do |field| unless field.save From 5280d434fd5f68bdae6088569cc1326829a95817 Mon Sep 17 00:00:00 2001 From: Chike Abuah Date: Wed, 22 Nov 2017 12:01:17 -0500 Subject: [PATCH 15/26] fix patrick's nothing unselected hack --- .../javascripts/projects/show.js.coffee | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/projects/show.js.coffee b/app/assets/javascripts/projects/show.js.coffee index 58ee3ae1a..0bdc8fcbe 100644 --- a/app/assets/javascripts/projects/show.js.coffee +++ b/app/assets/javascripts/projects/show.js.coffee @@ -65,19 +65,12 @@ IS.onReady "projects/show", -> # Takes all sessions that are checked, appends its id to the url and # redirects the user to the view sessions page (Vis page) $('#vis_button').click (e) -> - unchecked = $(document).find(".dataset .ds_selector input:not(:checked)") - unchecked_list = (get_ds_id u for u in unchecked) - # Viewing a subset of the data sets - if unchecked_list.length > 0 or window.location.href.indexOf('&search') != -1 - targets = $(document).find(".dataset .ds_selector input:checked") - ds_list = (get_ds_id t for t in targets) - # Set the value in the hidden form field - $('#visualize_selected>input').attr('value', ds_list) - # POST form - $('#visualize_selected').submit() - # Just show them all the old-fashioned way - else - window.location = $(this).attr("data-href") + targets = $(document).find(".dataset .ds_selector input:checked") + ds_list = (get_ds_id t for t in targets) + # Set the value in the hidden form field + $('#visualize_selected>input').attr('value', ds_list) + # POST form + $('#visualize_selected').submit() $('#export_button').click (e) -> $('#export_modal').modal('show') From e67d387de0a92db014a663cdf726e1778596aa73 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Mon, 27 Nov 2017 11:31:12 -0500 Subject: [PATCH 16/26] fix minor style errors --- .../javascripts/projects/show.js.coffee | 24 ++----------------- app/controllers/projects_controller.rb | 8 +++---- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/app/assets/javascripts/projects/show.js.coffee b/app/assets/javascripts/projects/show.js.coffee index 58ee3ae1a..3d362dc80 100644 --- a/app/assets/javascripts/projects/show.js.coffee +++ b/app/assets/javascripts/projects/show.js.coffee @@ -337,28 +337,8 @@ IS.onReady "projects/show", -> $("select#display_n").change -> console.log $("#display_n option:selected").val() - - ### - $.ajax - dataType: 'text' - url: "/projects/#{ namespace.id }" - type: 'GET' - data: - id: namespace.id - display_n : $("#display_n option:selected").val() - success: -> - console.log "SENT AJAX FOR display_n" - ### - console.log "/projects/#{ namespace.id }" - console.log window.location - - window.location.href = window.location.origin + window.location.pathname + "?per_page=#{$("#display_n option:selected").val()}" - ### - error: (msg) -> - console.log msg - console.log "failure" - ### - + window.location.href = window.location.origin + window.location.pathname + + "?per_page=#{$("#display_n option:selected").val()}" ### # Tags diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index bf614a2e3..98c0afffd 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -63,9 +63,9 @@ def show @cloned_project = Project.select(:id, :user_id, :title).where(id: @project.cloned_from).first @liked_by_cur_user = Like.find_by_user_id_and_project_id(current_user, @project.id) @all_data_sets = @project.data_sets.includes(:user).select('id', 'title', 'user_id', 'key', 'created_at', 'contributor_name').search(params[:search]) - - #The comparission validates the per_page display. The minimum and maximum are arbitrarily chosen but reasonable - if params[:per_page].to_i < 1 or params[:per_page].to_i > 1000 + + # The comparission validates the per_page display. The minimum and maximum are arbitrarily chosen but reasonable + if params[:per_page].to_i < 1 or params[:per_page].to_i > 1000 @data_sets = @all_data_sets.paginate(page: params[:page], per_page: 25) else @data_sets = @all_data_sets.paginate(page: params[:page], per_page: params[:per_page]) @@ -700,6 +700,6 @@ def project_params params[:project].permit(:content, :title, :user_id, :filter, :hidden, :cloned_from, :has_fields, :featured_media_id, :lock, :updated_at, :default_vis, :precision, - :globals, :kml_metadata,:per_page) + :globals, :kml_metadata, :per_page) end end From 5a3dc6ef68e8c21cfc5c68317d70b3a43f16a5f0 Mon Sep 17 00:00:00 2001 From: doug-salvati Date: Mon, 27 Nov 2017 12:16:57 -0500 Subject: [PATCH 17/26] Should run on load, not resize --- .../javascripts/visualizations/highvis/baseVis.coffee.erb | 4 ---- .../javascripts/visualizations/visualizations.js.coffee | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb index 896e03bfa..459550911 100644 --- a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb +++ b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb @@ -36,10 +36,6 @@ $ -> constructor: (@canvas) -> @configs ?= {} @isSummary = false - - if window.innerWidth <= 600 - globals.configs.ctrlsOpen = false - globals.configs.isPeriod ?= false # Controls how series are constructed in update(). globals.configs.periodMode ?= 'off' # Changes when a period option is selected. diff --git a/app/assets/javascripts/visualizations/visualizations.js.coffee b/app/assets/javascripts/visualizations/visualizations.js.coffee index 44ed86164..fd6f353b1 100644 --- a/app/assets/javascripts/visualizations/visualizations.js.coffee +++ b/app/assets/javascripts/visualizations/visualizations.js.coffee @@ -128,11 +128,15 @@ $ -> savedConfigs = savedGlobals['globals'] savedAnnotations = savedGlobals['annotations'] $.extend(globals.configs, savedConfigs) + # Load annotations if savedAnnotations? globals.annotationSet = new AnnotationSet for elt in savedAnnotations.list annotation = $.extend(true, new Annotation, elt) globals.annotationSet.addToList annotation + # If on mobile, close sidebar + if window.innerWidth <= 600 + globals.configs.ctrlsOpen = false # Restore vis specific configs for visName in data.allVis From 0e8e24205d117a7d8c5282b2c2c6c3ea4c7f586a Mon Sep 17 00:00:00 2001 From: doug-salvati Date: Mon, 27 Nov 2017 12:45:33 -0500 Subject: [PATCH 18/26] Add back space --- app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb index 459550911..bb06f6dc8 100644 --- a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb +++ b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb @@ -36,6 +36,7 @@ $ -> constructor: (@canvas) -> @configs ?= {} @isSummary = false + globals.configs.isPeriod ?= false # Controls how series are constructed in update(). globals.configs.periodMode ?= 'off' # Changes when a period option is selected. From 35495fcb1bea12450680ea092ff13714d85728ac Mon Sep 17 00:00:00 2001 From: doug-salvati Date: Mon, 27 Nov 2017 12:46:16 -0500 Subject: [PATCH 19/26] Linter --- .../javascripts/visualizations/highvis/baseVis.coffee.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb index bb06f6dc8..713ccbba6 100644 --- a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb +++ b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb @@ -36,7 +36,7 @@ $ -> constructor: (@canvas) -> @configs ?= {} @isSummary = false - + globals.configs.isPeriod ?= false # Controls how series are constructed in update(). globals.configs.periodMode ?= 'off' # Changes when a period option is selected. From 528042a3eb55dc4d4087af6a2f564765c28c771f Mon Sep 17 00:00:00 2001 From: doug-salvati Date: Wed, 29 Nov 2017 15:06:29 -0500 Subject: [PATCH 20/26] Account for deselected fields --- .../visualizations/highvis/baseVis.coffee.erb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb index 7f2bf62ad..b33ab4f98 100644 --- a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb +++ b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb @@ -234,7 +234,6 @@ $ -> # Relevant fields in alpahbetical selection list order selectionOrder = data.groups - console.log selectionOrder # Relevant fields in internally-stored project order internalOrder = [] @@ -244,18 +243,18 @@ $ -> ignoredFields = internalOrder.findIndex (f) -> f.typeID is data.types.NUMBER internalOrder = internalOrder.filter (f) -> f.typeID is data.types.NUMBER internalOrder = internalOrder.map (f) -> f.fieldName - console.log internalOrder # Map the group selection to reflect the discrepency mappedSelections = [] for elt in data.groupSelection correspondingField = selectionOrder[elt] actualIdxOfField = internalOrder.findIndex (fieldName) -> fieldName is correspondingField - mappedSelections[actualIdxOfField] = elt; + mappedSelections[actualIdxOfField] = elt # Get the data for fieldId, index in mappedSelections - fData[fieldId] = analysisMethod.call(data, index + hiddenFields + ignoredFields, null, dp) + unless fieldId is undefined + fData[fieldId] = analysisMethod.call(data, index + hiddenFields + ignoredFields, null, dp) return fData ### @@ -1065,8 +1064,8 @@ $ -> temp = text: "#{data.fields[globals.configs.fieldSelection[0]].fieldName} " + "(#{data.fields[globals.configs.fieldSelection[0]].unitName})" - - @chart.yAxis[0].setTitle title, false + console.log this + @chart.yAxis[0].setTitle title, false # Remove curent data while @chart.series.length > 0 From 6ec7cee40af85ca14309c3b5741cfea0f0e65eef Mon Sep 17 00:00:00 2001 From: doug-salvati Date: Thu, 30 Nov 2017 12:32:38 -0500 Subject: [PATCH 21/26] Remove console log --- app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb index b33ab4f98..4e1da0d70 100644 --- a/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb +++ b/app/assets/javascripts/visualizations/highvis/baseVis.coffee.erb @@ -1064,7 +1064,6 @@ $ -> temp = text: "#{data.fields[globals.configs.fieldSelection[0]].fieldName} " + "(#{data.fields[globals.configs.fieldSelection[0]].unitName})" - console.log this @chart.yAxis[0].setTitle title, false # Remove curent data From ae847d88a1c8c50b6b7b0b5755718809f92729dd Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Thu, 30 Nov 2017 15:35:38 -0500 Subject: [PATCH 22/26] fix minor style and spelling errors --- app/assets/javascripts/projects/show.js.coffee | 6 +++--- app/controllers/projects_controller.rb | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/projects/show.js.coffee b/app/assets/javascripts/projects/show.js.coffee index fb3f9e9c4..0dfe268f4 100644 --- a/app/assets/javascripts/projects/show.js.coffee +++ b/app/assets/javascripts/projects/show.js.coffee @@ -328,8 +328,10 @@ IS.onReady "projects/show", -> e.preventDefault() window.print() + ### + # Update per_page param when a drop-down option is selected + ### $("select#display_n").change -> - console.log $("#display_n option:selected").val() window.location.href = window.location.origin + window.location.pathname + "?per_page=#{$("#display_n option:selected").val()}" @@ -385,5 +387,3 @@ IS.onReady "projects/show", -> $('#tag-badge-textfield').val('') $('#tag-badge-form').hide() $('#tag-badge-add').show() - - diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 98c0afffd..51a324091 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -64,7 +64,7 @@ def show @liked_by_cur_user = Like.find_by_user_id_and_project_id(current_user, @project.id) @all_data_sets = @project.data_sets.includes(:user).select('id', 'title', 'user_id', 'key', 'created_at', 'contributor_name').search(params[:search]) - # The comparission validates the per_page display. The minimum and maximum are arbitrarily chosen but reasonable + # The comparision validates the per_page display. The minimum and maximum are arbitrarily chosen but reasonable if params[:per_page].to_i < 1 or params[:per_page].to_i > 1000 @data_sets = @all_data_sets.paginate(page: params[:page], per_page: 25) else @@ -459,7 +459,6 @@ def finishTemplateUpload redirect_to project_path(@project) and return end # Don't save fields until we know they are all valid - fields.push(field) end From 07245474001e294ba37a46e305b63ac6358a177f Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Thu, 30 Nov 2017 16:59:38 -0500 Subject: [PATCH 23/26] change default per_page value to 100, change options to 100,500,100, and clean up per_page drop down style --- app/assets/stylesheets/projects.css.scss | 3 ++- app/controllers/projects_controller.rb | 5 ++++- app/views/projects/show.html.erb | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/projects.css.scss b/app/assets/stylesheets/projects.css.scss index 707fa8588..c2b42108b 100644 --- a/app/assets/stylesheets/projects.css.scss +++ b/app/assets/stylesheets/projects.css.scss @@ -143,5 +143,6 @@ #display_n { - width: 110%; + width: 115%; + padding: 0 10 0 0; } diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 51a324091..94d5175f7 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -66,7 +66,7 @@ def show # The comparision validates the per_page display. The minimum and maximum are arbitrarily chosen but reasonable if params[:per_page].to_i < 1 or params[:per_page].to_i > 1000 - @data_sets = @all_data_sets.paginate(page: params[:page], per_page: 25) + @data_sets = @all_data_sets.paginate(page: params[:page], per_page: 100) else @data_sets = @all_data_sets.paginate(page: params[:page], per_page: params[:per_page]) end @@ -78,6 +78,9 @@ def show recur = params.key?(:recur) ? params[:recur] == 'true' : false + #byebug + #params[:per_page] = params[:per_page].blank? ? 100 : params[:per_page] + respond_to do |format| format.html do # Update view count diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 095722d49..a6e9b749b 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -131,9 +131,9 @@