From dbc148b7a6d0f06e40d4906190efd809787d1d9a Mon Sep 17 00:00:00 2001 From: Junyu Wang Date: Sat, 8 Oct 2016 03:34:18 +0000 Subject: [PATCH 01/19] updated travis ci badges & iter0 doc --- README.md | 2 +- iterations/iter0.md | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 iterations/iter0.md diff --git a/README.md b/README.md index a5a0024..8d170b8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ - + # MVP dashboard for ProjectScope A dashboard to show project metrics such as those supported by gems like diff --git a/iterations/iter0.md b/iterations/iter0.md new file mode 100644 index 0000000..696e509 --- /dev/null +++ b/iterations/iter0.md @@ -0,0 +1,18 @@ +## Iteration 0 + +Entry video +--- +URL: https://youtu.be/0qMtzclG9Is + +Development Environment Setup Screencast +--- +Junyu Wang: https://youtu.be/pPfSiQsZm5I + +Jiacheng Wu: https://youtu.be/x8AOtKAzmaQ + +Shuotong Wu: http://youtu.be/-65Oz8VtzDw?hd=1 + +Yibing Chen: https://youtu.be/U1Z-9KzoL7c + +Jiawei Jiang: + From 79445f8ae62fbe993833a7ed773fdfac425c7259 Mon Sep 17 00:00:00 2001 From: Junyu Wang Date: Sat, 8 Oct 2016 03:46:25 +0000 Subject: [PATCH 02/19] updated code climate badge & iter0 doc --- README.md | 4 ++-- db/schema.rb | 2 +- iterations/iter0.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8d170b8..32f1e89 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ - - + + # MVP dashboard for ProjectScope A dashboard to show project metrics such as those supported by gems like diff --git a/db/schema.rb b/db/schema.rb index 1a2ae0c..1d9183a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -30,9 +30,9 @@ t.text "encrypted_raw_data" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "encrypted_raw_data_iv" t.float "score" t.text "image" - t.string "encrypted_raw_data_iv" end add_index "metric_samples", ["project_id", "metric_name"], name: "index_metric_samples_on_project_id_and_metric_name" diff --git a/iterations/iter0.md b/iterations/iter0.md index 696e509..5373c54 100644 --- a/iterations/iter0.md +++ b/iterations/iter0.md @@ -14,5 +14,5 @@ Shuotong Wu: http://youtu.be/-65Oz8VtzDw?hd=1 Yibing Chen: https://youtu.be/U1Z-9KzoL7c -Jiawei Jiang: +Jiawei Jiang: https://youtu.be/ClqYbe2Ipnc From 089e1eb53a35d724de70b29e2819938f98df1a81 Mon Sep 17 00:00:00 2001 From: Junyu Wang Date: Sat, 8 Oct 2016 03:54:42 +0000 Subject: [PATCH 03/19] added pivotal tracker project url --- iterations/iter0.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iterations/iter0.md b/iterations/iter0.md index 5373c54..2ab20b1 100644 --- a/iterations/iter0.md +++ b/iterations/iter0.md @@ -16,3 +16,7 @@ Yibing Chen: https://youtu.be/U1Z-9KzoL7c Jiawei Jiang: https://youtu.be/ClqYbe2Ipnc +Pivotal Tracker Project +--- +URL: https://www.pivotaltracker.com/n/projects/1886749 + From 703b0beea9c3e18ea5ac07a6a1522e53fb5c05d6 Mon Sep 17 00:00:00 2001 From: GamaWu Date: Fri, 14 Oct 2016 15:35:32 -0700 Subject: [PATCH 04/19] iter 1: cucumber --- features/dashboard_drag.feature | 23 ++++++++++++++++++ features/dashboard_sort.feature | 35 +++++++++++++++++++++++++++ features/login.feature | 19 +++++++++++++++ features/whitelist_management.feature | 21 ++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 features/dashboard_drag.feature create mode 100644 features/dashboard_sort.feature create mode 100644 features/login.feature create mode 100644 features/whitelist_management.feature diff --git a/features/dashboard_drag.feature b/features/dashboard_drag.feature new file mode 100644 index 0000000..7da6d03 --- /dev/null +++ b/features/dashboard_drag.feature @@ -0,0 +1,23 @@ +Feature: sort projects by metrics + As a coach or admin on the dashboard page + So that I can drag projects in table + +Background: projects in database + + Given the following projects exist: + | project name | code_climate | github | slack | pivotal tracker | + | project scope | 1 | 10 | 6 | 8 | + | city dog | 2 | 9 | 3 | 5 | + | esential | 3 | 7 | 1 | 9 | + | faludi design | 5 | 8 | 10 | 4 | + | oram | 4 | 6 | 9 | 10 | + + Scenario: drag upwards + Given I am on the dashboard page + And I drag oram before city dog + Then I should see oram before city dog + + Scenario: drag downwards + Given I am on the dashboard page + And I drag project scope after faludi design + Then I should see project scope after faludi design \ No newline at end of file diff --git a/features/dashboard_sort.feature b/features/dashboard_sort.feature new file mode 100644 index 0000000..bce28f2 --- /dev/null +++ b/features/dashboard_sort.feature @@ -0,0 +1,35 @@ +Feature: sort projects by metrics + As a coach or admin on the dashboard page + So that I can sort the projects by different metrics + +Background: projects in database + + Given the following projects exist: + | project name | code_climate | github | slack | pivotal tracker | + | project scope | 1 | 10 | 6 | 8 | + | city dog | 2 | 9 | 3 | 5 | + | esential | 3 | 7 | 1 | 9 | + | faludi design | 5 | 8 | 10 | 4 | + | oram | 4 | 6 | 9 | 10 | + + Scenario: sort by code_climate + Given I am on the dashboard page + And I sort projects by code_climate + Then projects should be sorted by code_climate + + Scenario: sort by github + Given I am on the dashboard page + And I sort projects by github + Then projects should be sorted by github + + Scenario: sort by slack + Given I am on the dashboard page + And I sort projects by slack + Then projects should be sorted by slack + + Scenario: sort by pivotal tracker + Given I am on the dashboard page + And I sort projects by pivotal tracker + Then projects should be sorted by pivotal tracker + + diff --git a/features/login.feature b/features/login.feature new file mode 100644 index 0000000..e6f336c --- /dev/null +++ b/features/login.feature @@ -0,0 +1,19 @@ +Feature: login + Scenario: authrozied admin login + Given I am on the login page + And I fill in authroized credentials as admin + Then I should be on the dashboard page + And I should see whitelist management + + Scenario: authrozied coach login + Given I am on the login page + And I fill in authroized credentials as coach + Then I should be on the dashboard page + And I should not see whitelist management + + Scenario: unauthrozied user login + Given I am on the login page + And I fill in unauthroized credentials + Then I should not be on the dashboard page + And I should be on the login page + And I should see "You are not authroized." diff --git a/features/whitelist_management.feature b/features/whitelist_management.feature new file mode 100644 index 0000000..ee192cd --- /dev/null +++ b/features/whitelist_management.feature @@ -0,0 +1,21 @@ +Feature: manage whitelist + As an admin + So that I can add or drop people from whitelist + Given the following account exist in whitelist: + | Github Account | + | cyb | + | junyu Wang | + + Scenario: add people to whitelist + Given I am logged in as an admin + And I click whitelist managment + And whitelist has the following entries: + When I add "shuotong" to whitelist + Then I should see "shuotong" in whitelist + + Scenario: drop people from whitelist + Given I am logged in as an admin + And I click whitelist managment + And whitelist has the following entries: + When I drop "cyb" from whitelist + Then I should not see "cyb" in whitelist \ No newline at end of file From ac82d6f91c1e70b661de951b48f8ff758b3ed64f Mon Sep 17 00:00:00 2001 From: DrakeW Date: Sat, 15 Oct 2016 00:18:10 -0700 Subject: [PATCH 05/19] added status of both main repo and forked repo to readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 34d8e13..cb79177 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ +Main Repo Status: + + + + +CS169 Group Forked Repo Status: + + # MVP dashboard for ProjectScope A dashboard to show project metrics such as those supported by gems like From a3ada8b0c0dc47623ee4841baefe039f25309229 Mon Sep 17 00:00:00 2001 From: DrakeW Date: Sat, 15 Oct 2016 02:15:48 -0700 Subject: [PATCH 06/19] added heroku staging url --- iterations/iter0.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iterations/iter0.md b/iterations/iter0.md index 2ab20b1..07f8e13 100644 --- a/iterations/iter0.md +++ b/iterations/iter0.md @@ -20,3 +20,7 @@ Pivotal Tracker Project --- URL: https://www.pivotaltracker.com/n/projects/1886749 +Heroku +--- +URL: https://projectscope-cs169-junyu.herokuapp.com/ + From b3e3256a11e64fc1e01e8fd927e3786de3ed9299 Mon Sep 17 00:00:00 2001 From: GamaWu Date: Thu, 20 Oct 2016 22:56:58 -0700 Subject: [PATCH 07/19] revise cukes --- features/add_project_with_config.feature | 37 ++++++++++++++++++---- features/step_definitions/project_steps.rb | 12 ++----- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/features/add_project_with_config.feature b/features/add_project_with_config.feature index cf5d7ca..6c53798 100644 --- a/features/add_project_with_config.feature +++ b/features/add_project_with_config.feature @@ -11,14 +11,39 @@ Feature: add project and its config/credentials info When I follow "New Project" And I fill in "Name" with "Test Project" And I enter new "Code Climate" config values: - | key | value | - | token | 12345 | - | login | fox | + | key | value | + | url | a.com | + | channel | 12345 | + | token | 555 | + And I enter new "Github" config values: + | key | value | + | url | b.com | + And I enter new "Slack" config values: + | key | value | + | channel | 1 | + | token | 5 | + And I enter new "Pivotal Tracker" config values: + | key | value | + | project | la | + | token | 444 | + And I enter new "Slack Trends" config values: + | key | value | + | channel | 1 | + | token | 5 | And I press "Create Project" Then there should be a project "Test Project" with config values: - | metric_name | key | value | - | code_climate | token | 12345 | - | code_climate | login | fox | + | metric_name | key | value | + | code_climate | url | a.com | + | code_climate | channel | 12345 | + | code_climate | token | 555 | + | github | url | b.com | + | slack | channel | 1 | + | slack | token | 5 | + | slack_trends | channel | 1 | + | slack_trends | token | 5 | + | pivotal_tracker | project | la | + | pivotal_tracker | token | 444 | + diff --git a/features/step_definitions/project_steps.rb b/features/step_definitions/project_steps.rb index 791c40f..bd61607 100644 --- a/features/step_definitions/project_steps.rb +++ b/features/step_definitions/project_steps.rb @@ -5,17 +5,9 @@ When /^I enter new "(.*)" config values/ do |metric, table| fieldset_id = metric.downcase.gsub(' ', '_') # "Code Climate" => "code_climate" - (table.hashes.length - 1).times do - within "##{fieldset_id}" do - click_link 'Add new' - end - end - idx = 0 - all_inputs = page.all("fieldset##{fieldset_id} .newf") table.hashes.each do |h| - all_inputs[idx].set h['key'] - all_inputs[idx+1].set h['value'] - idx += 2 + credential = h['key'] + fill_in("#{fieldset_id}_#{credential}", :with => h['value']) end end From d406b7c3b060dafc8a603d95f7d567b913a84f39 Mon Sep 17 00:00:00 2001 From: GamaWu Date: Thu, 20 Oct 2016 22:57:37 -0700 Subject: [PATCH 08/19] update _form to use gem's credentials method --- app/views/projects/_form.html.haml | 56 +++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 9d68f5b..20136ee 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -15,24 +15,48 @@ = f.fields_for :configs do |cf| - name,index = cf.object.metric_name, cf.index - %fieldset{:id => name} - %legend= name.titleize - = hidden_field_tag "project[configs_attributes][#{index}][metric_name]", name - - cf.object.options.each_pair do |key,val| - - field_name = "project[configs_attributes][#{index}][options][#{key}]" - %label{:for => field_name}= "#{key}:" - = text_field_tag field_name, val, :disabled => @readonly - %br - - unless @readonly - = link_to 'Add new', '', :class => 'add' - .field.new - = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf' - \ : - = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf' + - classes = {'github' => ProjectMetricGithub, 'code_climate' => ProjectMetricCodeClimate, 'slack' => ProjectMetricSlack,'pivotal_tracker' => ProjectMetricPivotalTracker,'slack_trends' => ProjectMetricSlackTrends} + - if classes[name].respond_to?(:credentials) + %fieldset{:id => name} + %legend= name.titleize + = hidden_field_tag "project[configs_attributes][#{index}][metric_name]", name + - existed = [] + - cf.object.options.each_pair do |key,val| + - existed << key + - field_name = "project[configs_attributes][#{index}][options][#{key}]" + %label{:for => field_name}= "#{key}:" + = text_field_tag field_name, val, :disabled => @readonly %br + %br + - unless @readonly + - classes[name].credentials.each do |cred| + -if !existed.include?(cred) + .field.new + = label_tag "project[configs_attributes][#{index}][new][]", "#{cred}", :id => nil, :class => 'newf' + \ : + = hidden_field_tag "project[configs_attributes][#{index}][new][]", "#{cred}", :id => nil, :class => 'newf' + = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => "#{name}_#{cred}", :class => 'newf' + %br + - else + - name,index = cf.object.metric_name, cf.index + %fieldset{:id => name} + %legend= name.titleize + = hidden_field_tag "project[configs_attributes][#{index}][metric_name]", name + - cf.object.options.each_pair do |key,val| + - field_name = "project[configs_attributes][#{index}][options][#{key}]" + %label{:for => field_name}= "#{key}:" + = text_field_tag field_name, val, :disabled => @readonly + %br + - unless @readonly + = link_to 'Add new', '', :class => 'add' + .field.new + = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf' + \ : + = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf' + %br - :javascript - $('.add').click(function() { $(this).closest('fieldset').append($('.new')[0].outerHTML); return(false); } ) + :javascript + $('.add').click(function() { $(this).closest('fieldset').append($('.new')[0].outerHTML); return(false); } ) - unless @readonly .actions From 4a3279250f87b1b8313b526d305a189846bdf7f8 Mon Sep 17 00:00:00 2001 From: GamaWu Date: Fri, 21 Oct 2016 16:11:18 -0700 Subject: [PATCH 09/19] remove irrelevant features --- features/dashboard_drag.feature | 23 ------------------ features/dashboard_sort.feature | 35 --------------------------- features/login.feature | 19 --------------- features/whitelist_management.feature | 21 ---------------- 4 files changed, 98 deletions(-) delete mode 100644 features/dashboard_drag.feature delete mode 100644 features/dashboard_sort.feature delete mode 100644 features/login.feature delete mode 100644 features/whitelist_management.feature diff --git a/features/dashboard_drag.feature b/features/dashboard_drag.feature deleted file mode 100644 index 7da6d03..0000000 --- a/features/dashboard_drag.feature +++ /dev/null @@ -1,23 +0,0 @@ -Feature: sort projects by metrics - As a coach or admin on the dashboard page - So that I can drag projects in table - -Background: projects in database - - Given the following projects exist: - | project name | code_climate | github | slack | pivotal tracker | - | project scope | 1 | 10 | 6 | 8 | - | city dog | 2 | 9 | 3 | 5 | - | esential | 3 | 7 | 1 | 9 | - | faludi design | 5 | 8 | 10 | 4 | - | oram | 4 | 6 | 9 | 10 | - - Scenario: drag upwards - Given I am on the dashboard page - And I drag oram before city dog - Then I should see oram before city dog - - Scenario: drag downwards - Given I am on the dashboard page - And I drag project scope after faludi design - Then I should see project scope after faludi design \ No newline at end of file diff --git a/features/dashboard_sort.feature b/features/dashboard_sort.feature deleted file mode 100644 index bce28f2..0000000 --- a/features/dashboard_sort.feature +++ /dev/null @@ -1,35 +0,0 @@ -Feature: sort projects by metrics - As a coach or admin on the dashboard page - So that I can sort the projects by different metrics - -Background: projects in database - - Given the following projects exist: - | project name | code_climate | github | slack | pivotal tracker | - | project scope | 1 | 10 | 6 | 8 | - | city dog | 2 | 9 | 3 | 5 | - | esential | 3 | 7 | 1 | 9 | - | faludi design | 5 | 8 | 10 | 4 | - | oram | 4 | 6 | 9 | 10 | - - Scenario: sort by code_climate - Given I am on the dashboard page - And I sort projects by code_climate - Then projects should be sorted by code_climate - - Scenario: sort by github - Given I am on the dashboard page - And I sort projects by github - Then projects should be sorted by github - - Scenario: sort by slack - Given I am on the dashboard page - And I sort projects by slack - Then projects should be sorted by slack - - Scenario: sort by pivotal tracker - Given I am on the dashboard page - And I sort projects by pivotal tracker - Then projects should be sorted by pivotal tracker - - diff --git a/features/login.feature b/features/login.feature deleted file mode 100644 index e6f336c..0000000 --- a/features/login.feature +++ /dev/null @@ -1,19 +0,0 @@ -Feature: login - Scenario: authrozied admin login - Given I am on the login page - And I fill in authroized credentials as admin - Then I should be on the dashboard page - And I should see whitelist management - - Scenario: authrozied coach login - Given I am on the login page - And I fill in authroized credentials as coach - Then I should be on the dashboard page - And I should not see whitelist management - - Scenario: unauthrozied user login - Given I am on the login page - And I fill in unauthroized credentials - Then I should not be on the dashboard page - And I should be on the login page - And I should see "You are not authroized." diff --git a/features/whitelist_management.feature b/features/whitelist_management.feature deleted file mode 100644 index ee192cd..0000000 --- a/features/whitelist_management.feature +++ /dev/null @@ -1,21 +0,0 @@ -Feature: manage whitelist - As an admin - So that I can add or drop people from whitelist - Given the following account exist in whitelist: - | Github Account | - | cyb | - | junyu Wang | - - Scenario: add people to whitelist - Given I am logged in as an admin - And I click whitelist managment - And whitelist has the following entries: - When I add "shuotong" to whitelist - Then I should see "shuotong" in whitelist - - Scenario: drop people from whitelist - Given I am logged in as an admin - And I click whitelist managment - And whitelist has the following entries: - When I drop "cyb" from whitelist - Then I should not see "cyb" in whitelist \ No newline at end of file From d348357c6525752a68d63c286605365db8c137cf Mon Sep 17 00:00:00 2001 From: GamaWu Date: Tue, 25 Oct 2016 00:00:30 -0700 Subject: [PATCH 10/19] change credentials strings to symbols --- app/views/projects/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 20136ee..ec3d384 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -22,7 +22,7 @@ = hidden_field_tag "project[configs_attributes][#{index}][metric_name]", name - existed = [] - cf.object.options.each_pair do |key,val| - - existed << key + - existed << key.intern - field_name = "project[configs_attributes][#{index}][options][#{key}]" %label{:for => field_name}= "#{key}:" = text_field_tag field_name, val, :disabled => @readonly From 570075666eb0930bdf2f8ec628a1b2f1b5770e6d Mon Sep 17 00:00:00 2001 From: GamaWu Date: Tue, 25 Oct 2016 00:06:16 -0700 Subject: [PATCH 11/19] change unless to if not --- app/views/projects/_form.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index ec3d384..f94a047 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -28,7 +28,7 @@ = text_field_tag field_name, val, :disabled => @readonly %br %br - - unless @readonly + - if !@readonly - classes[name].credentials.each do |cred| -if !existed.include?(cred) .field.new @@ -47,7 +47,7 @@ %label{:for => field_name}= "#{key}:" = text_field_tag field_name, val, :disabled => @readonly %br - - unless @readonly + - if !@readonly = link_to 'Add new', '', :class => 'add' .field.new = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf' From fcb1f539362e523bf8b1ac866f2ff0af47c62e40 Mon Sep 17 00:00:00 2001 From: GamaWu Date: Tue, 25 Oct 2016 00:28:12 -0700 Subject: [PATCH 12/19] change if not back to unless --- app/views/projects/_form.html.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index f94a047..ae1b042 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -28,9 +28,9 @@ = text_field_tag field_name, val, :disabled => @readonly %br %br - - if !@readonly + - unless @readonly - classes[name].credentials.each do |cred| - -if !existed.include?(cred) + -unless existed.include?(cred) .field.new = label_tag "project[configs_attributes][#{index}][new][]", "#{cred}", :id => nil, :class => 'newf' \ : @@ -47,7 +47,7 @@ %label{:for => field_name}= "#{key}:" = text_field_tag field_name, val, :disabled => @readonly %br - - if !@readonly + - unless @readonly = link_to 'Add new', '', :class => 'add' .field.new = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf' From 13b2654ff25bf86a2c4ec01db5fa79a9d4d598e6 Mon Sep 17 00:00:00 2001 From: GamaWu Date: Tue, 25 Oct 2016 23:33:51 -0700 Subject: [PATCH 13/19] move logic from view to controller --- app/controllers/projects_controller.rb | 29 ++++++++++++++++-- app/views/projects/_form.html.haml | 41 ++++++++------------------ 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 43fb48b..ee93850 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,10 +1,12 @@ class ProjectsController < ApplicationController + include ProjectsHelper before_action :set_project, only: [:show, :edit, :update, :destroy] - + before_action :set_project_metrics, only: [:show, :edit, :new] + before_action :init_existed_configs, only: [:show, :edit, :new] http_basic_authenticate_with name: "cs169", password: ENV['PROJECTSCOPE_PASSWORD'] - # GET /projects # GET /projects.json + def index @projects = Project.all @metric_names = ProjectMetrics.metric_names @@ -24,6 +26,15 @@ def new # GET /projects/1/edit def edit + setup_metric_configs(@project) + @project.configs.each do |config| + name = config.metric_name + if @project_metrics[name].respond_to?(:credentials) + config.options.each_pair do |key,val| + @existed_configs[name] << key.intern + end + end + end end # POST /projects @@ -73,6 +84,20 @@ def set_project @project = Project.includes(:configs).find(params[:id]) end + def set_project_metrics + @project_metrics = {} + ProjectMetrics.metric_names.each do |name| + @project_metrics[name] = ProjectMetrics.class_for name + end + end + + def init_existed_configs + @existed_configs = {} + ProjectMetrics.metric_names.each do |name| + @existed_configs[name] = [] + end + end + # Never trust parameters from the scary internet, only allow the white list through. def project_params # Grab new option keys/vals from params, and incorporate them into diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index ae1b042..7075103 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -15,39 +15,24 @@ = f.fields_for :configs do |cf| - name,index = cf.object.metric_name, cf.index - - classes = {'github' => ProjectMetricGithub, 'code_climate' => ProjectMetricCodeClimate, 'slack' => ProjectMetricSlack,'pivotal_tracker' => ProjectMetricPivotalTracker,'slack_trends' => ProjectMetricSlackTrends} - - if classes[name].respond_to?(:credentials) - %fieldset{:id => name} - %legend= name.titleize - = hidden_field_tag "project[configs_attributes][#{index}][metric_name]", name - - existed = [] - - cf.object.options.each_pair do |key,val| - - existed << key.intern - - field_name = "project[configs_attributes][#{index}][options][#{key}]" - %label{:for => field_name}= "#{key}:" - = text_field_tag field_name, val, :disabled => @readonly - %br - %br - - unless @readonly - - classes[name].credentials.each do |cred| - -unless existed.include?(cred) + %fieldset{:id => name} + %legend= name.titleize + = hidden_field_tag "project[configs_attributes][#{index}][metric_name]", name + - cf.object.options.each_pair do |key,val| + - field_name = "project[configs_attributes][#{index}][options][#{key}]" + %label{:for => field_name}= "#{key}:" + = text_field_tag field_name, val, :disabled => @readonly + %br + - unless @readonly + - if @project_metrics[name].respond_to?(:credentials) + - @project_metrics[name].credentials.each do |cred| + -unless @existed_configs[name].include?(cred) .field.new = label_tag "project[configs_attributes][#{index}][new][]", "#{cred}", :id => nil, :class => 'newf' \ : = hidden_field_tag "project[configs_attributes][#{index}][new][]", "#{cred}", :id => nil, :class => 'newf' = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => "#{name}_#{cred}", :class => 'newf' - %br - - else - - name,index = cf.object.metric_name, cf.index - %fieldset{:id => name} - %legend= name.titleize - = hidden_field_tag "project[configs_attributes][#{index}][metric_name]", name - - cf.object.options.each_pair do |key,val| - - field_name = "project[configs_attributes][#{index}][options][#{key}]" - %label{:for => field_name}= "#{key}:" - = text_field_tag field_name, val, :disabled => @readonly - %br - - unless @readonly + - else = link_to 'Add new', '', :class => 'add' .field.new = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf' From 739fd3a1e6d7b881544972362d3c3b921dcbb4fe Mon Sep 17 00:00:00 2001 From: GamaWu Date: Wed, 26 Oct 2016 02:08:07 -0700 Subject: [PATCH 14/19] change intern to to_sym --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ee93850..ffd9f62 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -31,7 +31,7 @@ def edit name = config.metric_name if @project_metrics[name].respond_to?(:credentials) config.options.each_pair do |key,val| - @existed_configs[name] << key.intern + @existed_configs[name] << key.to_sym end end end From d8a4ffc69825cd67f7b99f3d762835fa71df221c Mon Sep 17 00:00:00 2001 From: DrakeW Date: Wed, 2 Nov 2016 10:04:28 -0700 Subject: [PATCH 15/19] updated gems --- Gemfile.lock | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1759201..cb083a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,35 +15,35 @@ GIT GIT remote: https://github.com/AgileVentures/project_metric_code_climate - revision: 428cf1ca92e2e822bfdd4569fec5b1a8b518a52e + revision: 99c1927642270777620a683a2b8bd92ce2190af9 specs: project_metric_code_climate (0.0.5) httparty GIT remote: https://github.com/AgileVentures/project_metric_github - revision: 629101fa195ece6843e13281a11604abdf4b597e + revision: 98ca683a242d0ab4489ce0a644cf3d5ca0f4ac44 specs: project_metric_github (0.0.9) octokit GIT remote: https://github.com/AgileVentures/project_metric_pivotal_tracker - revision: d2b603bb1f6c8639e74a68d4a739d255e383d808 + revision: 0923771b2ef15a4f44698aaa4cb27f8cdf7235cb specs: project_metric_pivotal_tracker (0.0.1) tracker_api (~> 0.2.0) GIT remote: https://github.com/AgileVentures/project_metric_slack - revision: f0e2a83a761087542c089f2b1226942d7c083bb8 + revision: 35d9827d5fd6ec9d7a7e4b5dbdc0ca2e22f1578d specs: project_metric_slack (0.0.0) slack-ruby-client (>= 0.7.6) GIT remote: https://github.com/AgileVentures/project_metric_slack_trends - revision: 5721ff93fc8f50cfda02c5fcaee9efba50b483df + revision: 646b106b610bc29508ffbeb5b97047eb629f04ec specs: project_metric_slack_trends (0.0.1) rasem (~> 0.6.1) @@ -111,8 +111,8 @@ GEM autoprefixer-rails (>= 5.2.1) sass (>= 3.3.4) builder (3.2.2) - byebug (9.0.5) - capybara (2.8.1) + byebug (9.0.6) + capybara (2.10.1) addressable mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -145,9 +145,9 @@ GEM multi_test (>= 0.1.2) cucumber-core (1.5.0) gherkin (~> 4.0) - cucumber-rails (1.4.4) + cucumber-rails (1.4.5) capybara (>= 1.1.2, < 3) - cucumber (>= 1.3.8, < 3) + cucumber (>= 1.3.8, < 4) mime-types (>= 1.16, < 4) nokogiri (~> 1.5) railties (>= 3, < 5.1) @@ -175,7 +175,7 @@ GEM encryptor (3.0.0) equalizer (0.0.11) erubis (2.7.0) - excon (0.52.0) + excon (0.54.0) execjs (2.7.0) factory_girl (4.7.0) activesupport (>= 3.0.0) @@ -195,7 +195,7 @@ GEM haml (4.0.7) tilt hashdiff (0.3.0) - hashie (3.4.4) + hashie (3.4.6) httparty (0.14.0) multi_xml (>= 0.5.2) i18n (0.7.0) @@ -219,21 +219,20 @@ GEM mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) mini_portile2 (2.1.0) - minitest (5.9.0) + minitest (5.9.1) multi_json (1.12.1) multi_test (0.1.2) multi_xml (0.5.5) multipart-post (2.0.0) - nokogiri (1.6.8) + nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) - pkg-config (~> 1.1.7) oauth2 (1.2.0) faraday (>= 0.8, < 0.10) jwt (~> 1.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - octokit (4.3.0) + octokit (4.4.1) sawyer (~> 0.7.0, >= 0.5.3) omniauth (1.3.1) hashie (>= 1.2, < 4) @@ -242,10 +241,9 @@ GEM oauth2 (~> 1.0) omniauth (~> 1.2) orm_adapter (0.5.0) - pg (0.18.4) + pg (0.19.0) phantomjs (2.1.1.0) - pkg-config (1.1.7) - poltergeist (1.10.0) + poltergeist (1.11.0) capybara (~> 2.1) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) @@ -283,7 +281,7 @@ GEM activesupport (= 4.2.6) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (11.2.2) + rake (11.3.0) rasem (0.6.1) rdoc (4.2.2) json (~> 1.4) @@ -292,7 +290,7 @@ GEM uber (~> 0.0.15) responders (2.3.0) railties (>= 4.2.0, < 5.1) - rspec-core (3.5.3) + rspec-core (3.5.4) rspec-support (~> 3.5.0) rspec-expectations (3.5.0) diff-lcs (>= 1.2.0, < 2.0) @@ -320,7 +318,7 @@ GEM sawyer (0.7.0) addressable (>= 2.3.5, < 2.5) faraday (~> 0.8, < 0.10) - sdoc (0.4.1) + sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) simplecov (0.12.0) @@ -343,7 +341,7 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - sqlite3 (1.3.11) + sqlite3 (1.3.12) thor (0.19.1) thread_safe (0.3.5) tilt (2.0.5) @@ -363,7 +361,7 @@ GEM tzinfo (1.2.2) thread_safe (~> 0.1) uber (0.0.15) - uglifier (3.0.2) + uglifier (3.0.3) execjs (>= 0.3.0, < 3) vcr (3.0.3) virtus (1.0.5) From 306eef6d8b919c684f6b5b41fe0142ba83a37beb Mon Sep 17 00:00:00 2001 From: GamaWu Date: Sun, 20 Nov 2016 00:19:39 -0800 Subject: [PATCH 16/19] change hash to ruby style and remove redundant lines --- app/controllers/projects_controller.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ffd9f62..defdb30 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,9 +1,8 @@ class ProjectsController < ApplicationController - include ProjectsHelper before_action :set_project, only: [:show, :edit, :update, :destroy] before_action :set_project_metrics, only: [:show, :edit, :new] before_action :init_existed_configs, only: [:show, :edit, :new] - http_basic_authenticate_with name: "cs169", password: ENV['PROJECTSCOPE_PASSWORD'] + #http_basic_authenticate_with name: "cs169", password: ENV['PROJECTSCOPE_PASSWORD'] # GET /projects # GET /projects.json @@ -26,11 +25,10 @@ def new # GET /projects/1/edit def edit - setup_metric_configs(@project) @project.configs.each do |config| name = config.metric_name if @project_metrics[name].respond_to?(:credentials) - config.options.each_pair do |key,val| + config.options.each_pair do |key,val| @existed_configs[name] << key.to_sym end end @@ -85,9 +83,8 @@ def set_project end def set_project_metrics - @project_metrics = {} - ProjectMetrics.metric_names.each do |name| - @project_metrics[name] = ProjectMetrics.class_for name + @project_metrics = ProjectMetrics.metric_names.inject({}) do |hash, name| + hash[name] = ProjectMetrics.class_for name; hash end end From a0c599ccfcac056cface7bc67d55b215761aaad8 Mon Sep 17 00:00:00 2001 From: GamaWu Date: Sun, 20 Nov 2016 01:08:08 -0800 Subject: [PATCH 17/19] move logic from view to controller: check repondency to credentials methods --- app/controllers/projects_controller.rb | 8 ++++++++ app/views/projects/_form.html.haml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index defdb30..158053b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -2,6 +2,7 @@ class ProjectsController < ApplicationController before_action :set_project, only: [:show, :edit, :update, :destroy] before_action :set_project_metrics, only: [:show, :edit, :new] before_action :init_existed_configs, only: [:show, :edit, :new] + before_action :metrics_credentials_check, only: [:show, :edit, :new] #http_basic_authenticate_with name: "cs169", password: ENV['PROJECTSCOPE_PASSWORD'] # GET /projects # GET /projects.json @@ -82,11 +83,18 @@ def set_project @project = Project.includes(:configs).find(params[:id]) end + # Set up hash mapping from name to class name check whether a metrics has credentials method. def set_project_metrics @project_metrics = ProjectMetrics.metric_names.inject({}) do |hash, name| hash[name] = ProjectMetrics.class_for name; hash end end + # Check whether a metrics gem responds to credentials method + def metrics_credentials_check + @credentials_check = ProjectMetrics.metric_names.inject({}) do |hash, name| + hash[name] = ProjectMetrics.class_for(name).respond_to? :credentials; hash + end + end def init_existed_configs @existed_configs = {} diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 7075103..256019d 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -24,7 +24,7 @@ = text_field_tag field_name, val, :disabled => @readonly %br - unless @readonly - - if @project_metrics[name].respond_to?(:credentials) + - if @credentials_check[name] - @project_metrics[name].credentials.each do |cred| -unless @existed_configs[name].include?(cred) .field.new From fc6b85b47ed83b64b40cbbf8909da438ea4b68f0 Mon Sep 17 00:00:00 2001 From: GamaWu Date: Sun, 20 Nov 2016 01:15:29 -0800 Subject: [PATCH 18/19] change styling according to codeclimate report --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f3aea83..0b0918d 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -31,7 +31,7 @@ def edit @project.configs.each do |config| name = config.metric_name if @project_metrics[name].respond_to?(:credentials) - config.options.each_pair do |key,val| + config.options.each_pair do |key,_val| @existed_configs[name] << key.to_sym end end From a6c1797de0a01fc48c6962d0c8a864274ca6d87a Mon Sep 17 00:00:00 2001 From: GamaWu Date: Thu, 1 Dec 2016 21:49:08 -0800 Subject: [PATCH 19/19] add klass method in config model and change logic accordingly --- app/controllers/projects_controller.rb | 17 +---------------- app/models/config.rb | 3 +++ app/views/projects/_form.html.haml | 6 +++--- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 0b0918d..a94b8dc 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,9 +1,7 @@ class ProjectsController < ApplicationController before_action :set_project, only: [:show, :edit, :update, :destroy] - before_action :set_project_metrics, only: [:show, :edit, :new] before_action :init_existed_configs, only: [:show, :edit, :new] - before_action :metrics_credentials_check, only: [:show, :edit, :new] before_action :authenticate_user! # GET /projects @@ -30,7 +28,7 @@ def new def edit @project.configs.each do |config| name = config.metric_name - if @project_metrics[name].respond_to?(:credentials) + if config.klass.respond_to?(:credentials) config.options.each_pair do |key,_val| @existed_configs[name] << key.to_sym end @@ -85,19 +83,6 @@ def set_project @project = Project.includes(:configs).find(params[:id]) end - # Set up hash mapping from name to class name check whether a metrics has credentials method. - def set_project_metrics - @project_metrics = ProjectMetrics.metric_names.inject({}) do |hash, name| - hash[name] = ProjectMetrics.class_for name; hash - end - end - # Check whether a metrics gem responds to credentials method - def metrics_credentials_check - @credentials_check = ProjectMetrics.metric_names.inject({}) do |hash, name| - hash[name] = ProjectMetrics.class_for(name).respond_to? :credentials; hash - end - end - def init_existed_configs @existed_configs = {} ProjectMetrics.metric_names.each do |name| diff --git a/app/models/config.rb b/app/models/config.rb index d988655..d05b0e2 100644 --- a/app/models/config.rb +++ b/app/models/config.rb @@ -21,5 +21,8 @@ class Config < ActiveRecord::Base attr_accessible :options, :metric_name + def klass + ProjectMetrics.class_for self.metric_name + end end diff --git a/app/views/projects/_form.html.haml b/app/views/projects/_form.html.haml index 256019d..2b18457 100644 --- a/app/views/projects/_form.html.haml +++ b/app/views/projects/_form.html.haml @@ -14,7 +14,7 @@ = f.text_field :name, :disabled => @readonly = f.fields_for :configs do |cf| - - name,index = cf.object.metric_name, cf.index + - name,klass,index = cf.object.metric_name, cf.object.klass, cf.index %fieldset{:id => name} %legend= name.titleize = hidden_field_tag "project[configs_attributes][#{index}][metric_name]", name @@ -24,8 +24,8 @@ = text_field_tag field_name, val, :disabled => @readonly %br - unless @readonly - - if @credentials_check[name] - - @project_metrics[name].credentials.each do |cred| + - if klass.respond_to? :credentials + - klass.credentials.each do |cred| -unless @existed_configs[name].include?(cred) .field.new = label_tag "project[configs_attributes][#{index}][new][]", "#{cred}", :id => nil, :class => 'newf'