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

Commit

Permalink
updated show all four show page details
Browse files Browse the repository at this point in the history
  • Loading branch information
cssandlin committed Jul 12, 2019
1 parent fcadf7f commit 0b55b3a
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 9 deletions.
1 change: 0 additions & 1 deletion app/controllers/response_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def all_dupes
end

def usage
@response_set = ResponseSet.find(params[:id])
if @response_set.status != 'published'
render(json: { error: 'Only published Response Sets provide usage information' }, status: :bad_request)
else
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/sections_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
class SectionsController < ApplicationController
load_and_authorize_resource
before_action :set_paper_trail_whodunnit
load_and_authorize_resource except: [:usage]

def info_for_paper_trail
comment = request.params[:comment] || ''
association_changes = request.params[:association_changes] || {}
{ comment: comment, associations: association_changes }
end

def usage
if @section.status != 'published'
render(json: { error: 'Only published Response Sets provide usage information' }, status: :bad_request)
else
response = { id: @section.id }
response[:surveillance_programs] = @section.surveillance_programs_usage
response[:surveillance_systems] = @section.surveillance_systems_usage
render json: response
end
end

# GET /sections
# GET /sections.json
def index
Expand Down
1 change: 1 addition & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def initialize(user)
can :read, User
else
can :read, [ResponseSet, Question, Section, Survey], status: 'published'
can :usage, [ResponseSet, Question, Section, Survey], status: 'published'
can :redcap, [ResponseSet, Question, Section, Survey], status: 'published'
can :parent_items, [Question, Section], status: 'published'
can :more_responses, [ResponseSet], status: 'published'
Expand Down
22 changes: 22 additions & 0 deletions app/models/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,28 @@ def surveillance_systems
.where('survey_sections.section_id = ?', id).select(:id, :name).distinct.to_a
end

def surveillance_programs_usage
programs_usage = []
surveys.each do |surv|
programs_usage << surv.surveillance_program.name if surv.surveillance_program
end
parent_sections.each do |ps|
programs_usage += ps.surveillance_programs_usage
end
programs_usage.uniq
end

def surveillance_systems_usage
systems_usage = []
surveys.each do |surv|
systems_usage << surv.surveillance_system.name if surv.surveillance_system
end
parent_sections.each do |ps|
systems_usage += ps.surveillance_systems_usage
end
systems_usage.uniq
end

# Provides a list of nested items that are only questions by flattening out
# any subsections. Works recursively
def flatten_questions
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
get :redcap, on: :member
get :epi_info, on: :member
get :parent_items, on: :member
get :usage, on: :member
put :publish, on: :member
put :retire, on: :member
put :update_stage, on: :member
Expand Down
3 changes: 3 additions & 0 deletions webpack/_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,9 @@ Based on Rails routes of Vocabulary::Application
// usage_response_set => /response_sets/:id/usage(.:format)
// function(id, options)
usage_response_set_path: Utils.route([["id",true],["format",false]], {}, [2,[7,"/",false],[2,[6,"response_sets",false],[2,[7,"/",false],[2,[3,"id",false],[2,[7,"/",false],[2,[6,"usage",false],[1,[2,[8,".",false],[3,"format",false]],false]]]]]]]),
// usage_section => /sections/:id/usage(.:format)
// function(id, options)
usage_section_path: Utils.route([["id",true],["format",false]], {}, [2,[7,"/",false],[2,[6,"sections",false],[2,[7,"/",false],[2,[3,"id",false],[2,[7,"/",false],[2,[6,"usage",false],[1,[2,[8,".",false],[3,"format",false]],false]]]]]]]),
// user_openid_connect_omniauth_authorize => /users/auth/openid_connect(.:format)
// function(options)
user_openid_connect_omniauth_authorize_path: Utils.route([["format",false]], {}, [2,[7,"/",false],[2,[6,"users",false],[2,[7,"/",false],[2,[6,"auth",false],[2,[7,"/",false],[2,[6,"openid_connect",false],[1,[2,[8,".",false],[3,"format",false]],false]]]]]]]),
Expand Down
12 changes: 11 additions & 1 deletion webpack/actions/section_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ import {
FETCH_SECTION_PENDING,
FETCH_SECTION_SUCCESS,
FETCH_SECTION_FAILURE,
FETCH_SECTION_PARENTS
FETCH_SECTION_PARENTS,
FETCH_SECTION_USAGE
} from './types';

const AJAX_TIMEOUT = 1000 * 60 * 5; // 5 minutes

export function fetchSectionUsage(id) {
return {
type: FETCH_SECTION_USAGE,
payload: axios.get(routes.usageSectionPath(id), {
headers: {'Accept': 'application/json', 'X-Key-Inflection': 'camel'}
})
};
}

export function newSection() {
return {
type: CREATE_SECTION
Expand Down
2 changes: 2 additions & 0 deletions webpack/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export const REMOVE_NESTED_ITEM = 'REMOVE_NESTED_ITEM';
export const REORDER_NESTED_ITEM = 'REORDER_NESTED_ITEM';
export const FETCH_SECTION_PARENTS = 'FETCH_SECTION_PARENTS';
export const FETCH_SECTION_PARENTS_FULFILLED = 'FETCH_SECTION_PARENTS_FULFILLED';
export const FETCH_SECTION_USAGE = 'FETCH_SECTION_USAGE';
export const FETCH_SECTION_USAGE_FULFILLED = 'FETCH_SECTION_USAGE_FULFILLED';

// Category types
export const FETCH_CATEGORY = 'FETCH_CATEGORY';
Expand Down
4 changes: 2 additions & 2 deletions webpack/components/questions/QuestionShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export default class QuestionShow extends Component {
</div>
<div className="box-content">
<strong>Created: </strong>
{ format(parse(question.createdAt,''), 'MMMM Do YYYY, h:mm:ss a') }
{ format(parse(question.createdAt,''), 'MMMM Do, YYYY') }
</div>
<InfoModal show={this.state.showContentStage} header={question.contentStage} body={<InfoModalBodyContent enum='contentStage' contentStage={question.contentStage}></InfoModalBodyContent>} hideInfo={()=>this.setState({showContentStage: false})} />
{question.contentStage && <div className="box-content">
Expand Down Expand Up @@ -583,7 +583,7 @@ export default class QuestionShow extends Component {

QuestionShow.propTypes = {
question: questionProps,
currentUser: currentUserProps,
currentUser: currentUserProps,
router: PropTypes.object,
handlePublish: PropTypes.func,
retireQuestion: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion webpack/components/response_sets/ResponseSetShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export default class ResponseSetShow extends Component {
</div>
<div className="box-content">
<strong>Created: </strong>
{ format(parse(responseSet.createdAt,''), 'MMMM Do YYYY, h:mm:ss a') }
{ format(parse(responseSet.createdAt,''), 'MMMM Do, YYYY') }
</div>
{ responseSet.parent &&
<div className="box-content">
Expand Down
11 changes: 11 additions & 0 deletions webpack/components/sections/SectionShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Linkify from 'react-linkify';
import Pagination from 'rc-pagination';
import $ from 'jquery';
import { Modal, Button, Row, Col } from 'react-bootstrap';
import parse from 'date-fns/parse';
import format from 'date-fns/format';

import SectionNestedItemList from '../../containers/sections/SectionNestedItemList';
import CodedSetTable from "../CodedSetTable";
Expand All @@ -27,6 +29,8 @@ import { gaSend } from '../../utilities/GoogleAnalytics';
import InfoModal from '../../components/InfoModal';
import InfoModalBodyContent from '../../components/InfoModalBodyContent';

import ProgramsAndSystems from "../shared_show/ProgramsAndSystems";

const PAGE_SIZE = 10;

class SectionShow extends Component {
Expand Down Expand Up @@ -387,6 +391,10 @@ class SectionShow extends Component {
<strong>Description: </strong>
<Linkify properties={{target: '_blank'}}>{section.description}</Linkify>
</div>
<div className="box-content">
<strong>Created: </strong>
{ format(parse(section.createdAt,''), 'MMMM Do, YYYY') }
</div>
<InfoModal show={this.state.showContentStage} header={section.contentStage} body={<InfoModalBodyContent enum='contentStage' contentStage={section.contentStage}></InfoModalBodyContent>} hideInfo={()=>this.setState({showContentStage: false})} />
{ section.contentStage &&
<div className="box-content">
Expand Down Expand Up @@ -490,6 +498,9 @@ class SectionShow extends Component {
</div>
</div>
}
{section.status === 'published' &&
<ProgramsAndSystems item={section} />
}
</div>
</div>
</div>
Expand Down
12 changes: 12 additions & 0 deletions webpack/components/surveys/SurveyShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { hashHistory, Link } from 'react-router';
import { Modal, Button, Row, Col } from 'react-bootstrap';
import Linkify from 'react-linkify';
import Pagination from 'rc-pagination';
import parse from 'date-fns/parse';
import format from 'date-fns/format';

const PAGE_SIZE = 10;

Expand Down Expand Up @@ -404,6 +406,10 @@ class SurveyShow extends Component {
<strong>Description: </strong>
<Linkify properties={{target: '_blank'}}>{this.props.survey.description}</Linkify>
</div>
<div className="box-content">
<strong>Created: </strong>
{ format(parse(this.props.survey.createdAt,''), 'MMMM Do, YYYY') }
</div>
{ this.props.survey.status === 'published' && this.props.survey.publishedBy && this.props.survey.publishedBy.email &&
<div className="box-content">
<strong>Published By: </strong>
Expand All @@ -430,6 +436,12 @@ class SurveyShow extends Component {
</div>
}
{ this.props.survey.parent &&
<div className="box-content">
<strong>Published By: </strong>
{this.props.survey.publishedBy.email}
</div>
}
{ this.props.survey.parent &&
<div className="box-content">
<strong>Extended from: </strong>
<Link to={`/surveys/${this.props.survey.parent.id}`}>{ this.props.survey.parent.name }</Link>
Expand Down
14 changes: 11 additions & 3 deletions webpack/containers/sections/SectionShowContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { bindActionCreators } from 'redux';
import { Grid, Row, Col } from 'react-bootstrap';
import { hashHistory } from 'react-router';

import { fetchSection, publishSection, fetchSectionParents, retireSection, updateStageSection, addSectionToGroup, removeSectionFromGroup, deleteSection, updateSectionTags } from '../../actions/section_actions';
import { fetchSection, publishSection, fetchSectionUsage, fetchSectionParents, retireSection, updateStageSection, addSectionToGroup, removeSectionFromGroup, deleteSection, updateSectionTags } from '../../actions/section_actions';
import { setSteps } from '../../actions/tutorial_actions';
import { setStats } from '../../actions/landing';
import { hideResultControl, toggleResultControl } from '../../actions/display_style_actions';
Expand All @@ -30,6 +30,9 @@ class SectionShowContainer extends Component {

componentDidMount() {
gaSend('send', 'pageview', window.location.toString());
if (this.props.section && this.props.section.status === 'published') {
this.props.fetchSectionUsage(this.props.params.sectionId);
}
if (this.props.section){
this.props.fetchSectionParents(this.props.params.sectionId);
}
Expand Down Expand Up @@ -68,6 +71,10 @@ class SectionShowContainer extends Component {
} else if (this.props.section && this.props.section.parentItems === undefined) {
this.props.fetchSectionParents(this.props.params.sectionId);
}
if (this.props.section && this.props.section.status === 'published' &&
this.props.section.surveillancePrograms === undefined) {
this.props.fetchSectionUsage(this.props.params.sectionId);
}
}

render() {
Expand Down Expand Up @@ -153,7 +160,7 @@ function mapStateToProps(state, ownProps) {
}

function mapDispatchToProps(dispatch) {
return bindActionCreators({setSteps, setStats, fetchSection, fetchSectionParents, publishSection, addSectionToGroup, addPreferred, removePreferred,
return bindActionCreators({setSteps, setStats, fetchSectionUsage, fetchSection, fetchSectionParents, publishSection, addSectionToGroup, addPreferred, removePreferred,
removeSectionFromGroup, deleteSection, updateSectionTags, hideResultControl, updateStageSection, toggleResultControl, retireSection, clearBreadcrumb, addBreadcrumbItem}, dispatch);
}

Expand Down Expand Up @@ -185,7 +192,8 @@ SectionShowContainer.propTypes = {
isLoading: PropTypes.bool,
loadStatus : PropTypes.string,
loadStatusText : PropTypes.string,
addBreadcrumbItem: PropTypes.func
addBreadcrumbItem: PropTypes.func,
fetchSectionUsage: PropTypes.func,
};

export default connect(mapStateToProps, mapDispatchToProps)(SectionShowContainer);
11 changes: 10 additions & 1 deletion webpack/reducers/sections_reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
REMOVE_SECTION_FROM_GROUP_FULFILLED,
UPDATE_SECTION_TAGS_FULFILLED,
UPDATE_PDV_FULFILLED,
FETCH_SECTION_PARENTS_FULFILLED
FETCH_SECTION_PARENTS_FULFILLED,
FETCH_SECTION_USAGE_FULFILLED
} from '../actions/types';
import * as helpers from './helpers';

Expand All @@ -41,6 +42,14 @@ export default function sections(state = {}, action) {
newState = Object.assign({}, state);
newState[0] = {sectionNestedItems: [], questions: [], version: 1, id: 0};
return newState;
case FETCH_SECTION_USAGE_FULFILLED:
const sectionsClone = Object.assign({}, state);
if (sectionsClone[action.payload.data.id] === undefined) {
sectionsClone[action.payload.data.id] = {};
}
sectionsClone[action.payload.data.id].surveillanceSystems = action.payload.data.surveillanceSystems;
sectionsClone[action.payload.data.id].surveillancePrograms = action.payload.data.surveillancePrograms;
return sectionsClone;
case ADD_NESTED_ITEM:
sni = action.payload.nestedItem;
sniType = action.payload.type;
Expand Down

0 comments on commit 0b55b3a

Please sign in to comment.