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) diff --git a/README.md b/README.md index 970632f..454de2d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ Main Repo Status: + @@ -7,7 +8,6 @@ CS169 Group Forked Repo Status: - # MVP dashboard for ProjectScope diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 84905c1..a94b8dc 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,9 +1,12 @@ class ProjectsController < ApplicationController before_action :set_project, only: [:show, :edit, :update, :destroy] + + before_action :init_existed_configs, only: [:show, :edit, :new] before_action :authenticate_user! # GET /projects # GET /projects.json + def index @projects = Project.all @metric_names = ProjectMetrics.metric_names @@ -23,6 +26,14 @@ def new # GET /projects/1/edit def edit + @project.configs.each do |config| + name = config.metric_name + if config.klass.respond_to?(:credentials) + config.options.each_pair do |key,_val| + @existed_configs[name] << key.to_sym + end + end + end end # POST /projects @@ -72,6 +83,13 @@ def set_project @project = Project.includes(:configs).find(params[:id]) 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/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 9d68f5b..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,15 +24,24 @@ = 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 + - 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' + \ : + = 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' + - else + = 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 diff --git a/features/add_project_with_config.feature b/features/add_project_with_config.feature index 1059176..986b873 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 402eabf..71dac92 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