Rails How to pass values ​​from an array to a google script diagram.

Rails App. I have a project and a task model. Tasks have a column project_id to set the project to which they belong, and several columns of completeness to indicate the completeness of the task in time (so I have a column "completeten_at_3hours", "completeten_at_6hours, etc.), to indicate from 1 to 5 levels of completeness of the task.

Now I need graphically, with google diagrams, completeness during the tasks related to the project.

In my project controller, I have

@tasks = Tasks.where("project_id = ?", params[:id])

So, now that I have the tasks of the selected project, in @tasks, how to include data in the google script diagram?

function drawChart() {

        var data = google.visualization.arrayToDataTable([
          ['Time', '<%= @task.name %>', '????????'],
          ['<%= @task.created_at %>',  <%= @task.zerohours %>, '?????????'],
          ['<%= @task.created_at + 3.hours %>',  <%= @task.threehours %>, '????????'],
          ['<%= @task.created_at + 6.hours %>',  <%= @task.sixhours %>, '????????'],
          ['<%= @task.created_at + 9.hours %>',  <%= @task.ninehours %>, '????????'],
          ['<%= @task.created_at + 12.hours %>',  <%= @task.twelvehours %>, '????????']
        ]);

this only works for one task (the one that was just created), but how do I pass all the data contained in @tasks to the script?

, , :

<% @tasks.each do |task| %>
<%= @task.threehours %>
<%= @task.sixhours %>
<%= @task.ninehours %>
<%= @task.twelvehours %>
<% end %>

, google script?

!

+3
1

, , ? , . :

var data = google.visualization.arrayToDataTable(<%= make_a_chart %>);

- :

def make_a_chart
  result = []
  result.push make_labels, 
              make_data( 0, "zerohour" ), 
              make_data( 3, "threehours" ),
              make_data( 6, "sixhours" ),
              make_data( 9, "ninehours" ),
              make_data( 12, "twelvehours" )
  return result
end

def make_labels
  y = ["Time"]
  for task in Task.all do
    y.append task.name
  end
  return y
end

def make_data( time, completeness )
  y = Task.first.created_at + time
  for task in Task.all do
    y.append task[completeness]
  end
  return y
end

, "". , , .

+3

All Articles