Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #379 from CDCgov/help-page-admin-update
Browse files Browse the repository at this point in the history
[SDPV-31] Help page update, admin panel changes
  • Loading branch information
eedrummer authored Oct 13, 2017
2 parents 759c37a + 42c7588 commit b382f5c
Show file tree
Hide file tree
Showing 18 changed files with 332 additions and 41 deletions.
19 changes: 19 additions & 0 deletions app/controllers/surveillance_programs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
class SurveillanceProgramsController < ApplicationController
authorize_resource only: [:create]

def index
render json: SurveillanceProgram.all
end

def create
@surveillance_program = SurveillanceProgram.new(surveillance_program_params)
if SurveillanceProgram.find_by(name: @surveillance_program.name)
render json: { msg: "A surveillance program named #{@surveillance_program.name} already exists" }, status: :unprocessable_entity
elsif @surveillance_program.save
render json: SurveillanceProgram.all
else
render json: { msg: 'Error saving program - check format, name cannot be blank' }, status: :unprocessable_entity
end
end

private

def surveillance_program_params
params.permit(:name, :description, :acronym)
end
end
19 changes: 19 additions & 0 deletions app/controllers/surveillance_systems_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
class SurveillanceSystemsController < ApplicationController
authorize_resource only: [:create]

def index
render json: SurveillanceSystem.all
end

def create
@surveillance_system = SurveillanceSystem.new(surveillance_system_params)
if SurveillanceSystem.find_by(name: @surveillance_system.name)
render json: { msg: "A surveillance system named #{@surveillance_system.name} already exists" }, status: :unprocessable_entity
elsif @surveillance_system.save
render json: SurveillanceSystem.all
else
render json: { msg: 'Error saving system - check format, name cannot be blank' }, status: :unprocessable_entity
end
end

private

def surveillance_system_params
params.permit(:name, :description, :acronym)
end
end
1 change: 1 addition & 0 deletions app/models/surveillance_program.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class SurveillanceProgram < ApplicationRecord
has_many :surveys
validates :name, presence: true
end
1 change: 1 addition & 0 deletions app/models/surveillance_system.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class SurveillanceSystem < ApplicationRecord
has_many :surveys
validates :name, presence: true
end
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Rails.application.routes.draw do
resources :surveillance_systems, only: [:index, :show]
resources :surveillance_programs, only: [:index, :show]
resources :surveillance_systems, only: [:index, :create]
resources :surveillance_programs, only: [:index, :create]
get 'response_types', to: 'response_types#index', as: :response_types
get 'question_types', to: 'question_types#index', as: :question_types
get 'concepts', to: 'concepts#index', as: :concepts
Expand Down
35 changes: 35 additions & 0 deletions features/admin_panel.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,38 @@ Feature: Admin Panel
And I should see "[email protected]"
When I click on the "[email protected]" button
Then I should not see "[email protected]"

Scenario: Add program
Given I am the admin test_author@gmail.com
And there is an admin with the email admin@gmail.com
When I go to the dashboard
And I click on the "account-dropdown" link
And I click on the "Admin Panel" link
And I click on the "Program List" link
And I fill in the "program-name" field with "New Program"
And I click on the "submit-prog-sys" button
And I fill in the "program-name" field with "Just clearing the text"
Then I should see "New Program"

Scenario: Add System
Given I am the admin test_author@gmail.com
And there is an admin with the email admin@gmail.com
When I go to the dashboard
And I click on the "account-dropdown" link
And I click on the "Admin Panel" link
And I click on the "System List" link
And I fill in the "system-name" field with "New System"
And I click on the "submit-prog-sys" button
And I fill in the "system-name" field with "Just clearing the text"
Then I should see "New System"

Scenario: Add System with name error
Given I am the admin test_author@gmail.com
And there is an admin with the email admin@gmail.com
When I go to the dashboard
And I click on the "account-dropdown" link
And I click on the "Admin Panel" link
And I click on the "System List" link
And I fill in the "system-description" field with "Trying to add system with no name"
And I click on the "submit-prog-sys" button
Then I should see "Error saving system - check format, name cannot be blank"
16 changes: 16 additions & 0 deletions test/controllers/surveillance_programs_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
require 'test_helper'

class SurveillanceProgramsControllerTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers

test 'should get index' do
get surveillance_programs_url
assert_response :success
end

test 'should not be allowed to create program' do
post surveillance_programs_url, params: { name: 'test prog' }
assert_response :forbidden
end

test 'should be allowed to create program' do
@admin = users(:admin)
@admin.add_role :admin
@admin.save!
sign_in @admin
post surveillance_programs_url, params: { name: 'test prog' }
assert_response :success
end
end
16 changes: 16 additions & 0 deletions test/controllers/surveillance_systems_controller_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
require 'test_helper'

class SurveillanceSystemsControllerTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers

test 'should get index' do
get surveillance_systems_url
assert_response :success
end

test 'should not be allowed to create system' do
post surveillance_systems_url, params: { name: 'test sys' }
assert_response :forbidden
end

test 'should be allowed to create system' do
@admin = users(:admin)
@admin.add_role :admin
@admin.save!
sign_in @admin
post surveillance_systems_url, params: { name: 'test sys' }
assert_response :success
end
end
1 change: 1 addition & 0 deletions test/frontend/components/comment_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Comment', () => {
};
component = renderComponent(Comment, {
comment: comment,
loggedIn: true,
addComment: function() {}
});
});
Expand Down
6 changes: 0 additions & 6 deletions webpack/_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,15 +680,9 @@ Based on Rails routes of Vocabulary::Application
// root => /
// function(options)
root_path: Utils.route([], {}, [7,"/",false]),
// surveillance_program => /surveillance_programs/:id(.:format)
// function(id, options)
surveillance_program_path: Utils.route([["id",true],["format",false]], {}, [2,[7,"/",false],[2,[6,"surveillance_programs",false],[2,[7,"/",false],[2,[3,"id",false],[1,[2,[8,".",false],[3,"format",false]],false]]]]]),
// surveillance_programs => /surveillance_programs(.:format)
// function(options)
surveillance_programs_path: Utils.route([["format",false]], {}, [2,[7,"/",false],[2,[6,"surveillance_programs",false],[1,[2,[8,".",false],[3,"format",false]],false]]]),
// surveillance_system => /surveillance_systems/:id(.:format)
// function(id, options)
surveillance_system_path: Utils.route([["id",true],["format",false]], {}, [2,[7,"/",false],[2,[6,"surveillance_systems",false],[2,[7,"/",false],[2,[3,"id",false],[1,[2,[8,".",false],[3,"format",false]],false]]]]]),
// surveillance_systems => /surveillance_systems(.:format)
// function(options)
surveillance_systems_path: Utils.route([["format",false]], {}, [2,[7,"/",false],[2,[6,"surveillance_systems",false],[1,[2,[8,".",false],[3,"format",false]],false]]]),
Expand Down
25 changes: 24 additions & 1 deletion webpack/actions/surveillance_program_actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import axios from 'axios';
import routes from '../routes';
import { getCSRFToken } from './index';
import {
FETCH_SURVEILLANCE_PROGRAMS
FETCH_SURVEILLANCE_PROGRAMS,
ADD_PROGRAM
} from './types';

export function fetchSurveillancePrograms() {
Expand All @@ -15,3 +17,24 @@ export function fetchSurveillancePrograms() {
})
};
}

export function addProgram(name, description=null, acronym=null, callback=null, failureHandler=null) {
const postPromise = axios.post(routes.surveillanceProgramsPath(), {
headers: {
'X-Key-Inflection': 'camel',
'Accept': 'application/json'
},
authenticityToken: getCSRFToken(),
name, description, acronym
});
if (callback) {
postPromise.then(callback);
}
if (failureHandler) {
postPromise.catch(failureHandler);
}
return {
type: ADD_PROGRAM,
payload: postPromise
};
}
25 changes: 24 additions & 1 deletion webpack/actions/surveillance_system_actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import axios from 'axios';
import routes from '../routes';
import { getCSRFToken } from './index';
import {
FETCH_SURVEILLANCE_SYSTEMS
FETCH_SURVEILLANCE_SYSTEMS,
ADD_SYSTEM
} from './types';

export function fetchSurveillanceSystems() {
Expand All @@ -15,3 +17,24 @@ export function fetchSurveillanceSystems() {
})
};
}

export function addSystem(name, description=null, acronym=null, callback=null, failureHandler=null) {
const postPromise = axios.post(routes.surveillanceSystemsPath(), {
headers: {
'X-Key-Inflection': 'camel',
'Accept': 'application/json'
},
authenticityToken: getCSRFToken(),
name, description, acronym
});
if (callback) {
postPromise.then(callback);
}
if (failureHandler) {
postPromise.catch(failureHandler);
}
return {
type: ADD_SYSTEM,
payload: postPromise
};
}
4 changes: 4 additions & 0 deletions webpack/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,14 @@ export const FETCH_TAGS_FULFILLED = 'FETCH_TAGS_FULFILLED';
// Surveillance System Types
export const FETCH_SURVEILLANCE_SYSTEMS = 'FETCH_SURVEILLANCE_SYSTEMS';
export const FETCH_SURVEILLANCE_SYSTEMS_FULFILLED = 'FETCH_SURVEILLANCE_SYSTEMS_FULFILLED';
export const ADD_SYSTEM = 'ADD_SYSTEM';
export const ADD_SYSTEM_FULFILLED = 'ADD_SYSTEM_FULFILLED';

// Surveillance Program Types
export const FETCH_SURVEILLANCE_PROGRAMS = 'FETCH_SURVEILLANCE_PROGRAMS';
export const FETCH_SURVEILLANCE_PROGRAMS_FULFILLED = 'FETCH_SURVEILLANCE_PROGRAMS_FULFILLED';
export const ADD_PROGRAM = 'ADD_PROGRAM';
export const ADD_PROGRAM_FULFILLED = 'ADD_PROGRAM_FULFILLED';

// Survey types
export const PUBLISH_SURVEY = 'PUBLISH_SURVEY';
Expand Down
12 changes: 6 additions & 6 deletions webpack/components/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ class Comment extends Component {
<button className="btn btn-default btn-collapse btn-xs" type="button" data-toggle="collapse" data-target={"#comment_id_"+this.props.comment.id} aria-expanded="false" aria-controls={"comment_id_"+this.props.comment.id} aria-label="collapse">
<span className="glyphicon glyphicon-minus" aria-hidden="true"></span>
</button>
<span className="label label-info">{this.props.comment.id}</span>
{distanceInWordsToNow(parse(this.props.comment.createdAt,''), {addSuffix: true})} by {this.props.comment.userName}
<text> {distanceInWordsToNow(parse(this.props.comment.createdAt,''), {addSuffix: true})} by {this.props.comment.userName}</text>
</div>

<div className="panel-collapse collapse in" id={"comment_id_"+this.props.comment.id}>
Expand All @@ -28,7 +27,7 @@ class Comment extends Component {
<p>
{this.props.comment.comment}
</p>
<div className="comment-meta">
{this.props.loggedIn && <div className="comment-meta">
<span>
<a className="" ref={(input) => this.collapse = input} role="button" data-toggle="collapse" href={"#replyComment_"+this.props.comment.id} aria-expanded="false" aria-controls={"replyComment_"+this.props.comment.id}>reply</a>
</span>
Expand All @@ -40,9 +39,8 @@ class Comment extends Component {
comments={this.props.comments}
addComment={this.props.addComment} />
</div>
</div>
</div>}
{this.renderChildren()}

</div>
</div>
</div>
Expand All @@ -56,12 +54,13 @@ class Comment extends Component {
.map((comment) => {
return <Comment key = {comment.id}
comment = {comment}
loggedIn = {this.props.loggedIn}
comments={this.props.comments}
addComment = {this.props.addComment} />;
});
}
}
}
}



Expand All @@ -82,6 +81,7 @@ commentType.children = PropTypes.arrayOf(commentType);

Comment.propTypes = {
comment: commentType,
loggedIn: PropTypes.bool,
addComment: PropTypes.func.isRequired,
comments: PropTypes.array.isRequired
};
Expand Down
Loading

0 comments on commit b382f5c

Please sign in to comment.