Skip to content

Commit

Permalink
Merge pull request #19727 from code-dot-org/more_cohort_view_columns
Browse files Browse the repository at this point in the history
In cohort view, add columns for assigned workshop/fit
  • Loading branch information
mehalshah committed Jan 4, 2018
2 parents f2f3f91 + 5df052f commit 487a139
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 72 deletions.
Expand Up @@ -118,6 +118,7 @@ export default class ApplicationDashboard extends React.Component {
breadcrumbs={cohort_path_name}
component={CohortView}
applicationType={cohort_path_name}
viewType={paths[path].type}
/>
)
];
Expand Down
Expand Up @@ -12,10 +12,15 @@ class CohortView extends React.Component{
regionalPartnerName: PropTypes.string.isRequired,
route: PropTypes.shape({
path: PropTypes.string.isRequired,
applicationType: PropTypes.string.isRequired
applicationType: PropTypes.string.isRequired,
viewType: PropTypes.oneOf(['teacher', 'facilitator']).isRequired
})
}

static contextTypes = {
router: PropTypes.object.isRequired
}

state = {
loading: true,
applications: null
Expand Down Expand Up @@ -47,6 +52,8 @@ class CohortView extends React.Component{
<h2>{this.props.route.applicationType}</h2>
<CohortViewTable
data={this.state.applications}
viewType={this.props.route.viewType}
path={this.props.route.path}
/>
</div>
);
Expand Down
81 changes: 71 additions & 10 deletions apps/src/code-studio/pd/application_dashboard/cohort_view_table.jsx
@@ -1,5 +1,6 @@
import React, {PropTypes} from 'react';
import {Table} from 'reactabular';
import {Button} from 'react-bootstrap';

const styles = {
table: {
Expand All @@ -10,19 +11,20 @@ const styles = {
export default class CohortViewTable extends React.Component {
static propTypes = {
data: PropTypes.array.isRequired,
path: PropTypes.string.isRequired,
viewType: PropTypes.oneOf(['facilitator', 'teacher']).isRequired
}

static contextTypes = {
router: PropTypes.object
}

constructColumns() {
return [
let columns = [
{
property: 'date_accepted',
property: 'accepted_at',
header: {
label: 'Date Accepted'
},
cell: {
format: (date_accepted) => {
return new Date(date_accepted).toLocaleDateString('en-us', {month: 'long', day: 'numeric'});
}
}
}, {
property: 'applicant_name',
Expand All @@ -45,14 +47,73 @@ export default class CohortViewTable extends React.Component {
label: 'Email'
}
}, {
property: 'registered_for_summer_workshop',
property: 'notified',
header: {
label: 'Registered Summer Workshop'
label: 'Notified'
}
}
];

if (this.props.viewType === 'facilitator') {
columns.push({
property: 'assigned_fit',
header: {
label: 'Assigned FIT'
}
}, {
property: 'registered_fit',
header: {
label: 'Registered FIT'
}
}
);
} else {
columns.push(
{
property: 'assigned_workshop',
header: {
label: 'Assigned Workshop'
}
}, {
property: 'registered_workshop',
header: {
label: 'Registered Workshop'
}
}
);
}

columns.push({
property: 'id',
header: {
label: 'View Application'
},
cell: {
format: this.formatViewButton
}
});

return columns;
}

formatViewButton = (id) => {
return (
<Button
bsSize="xsmall"
// TODO: (mehal) Build a wrapper for react stories that lets us pass in a context with router
href={this.context.router && this.context.router.createHref(`/${this.props.path.replace('_cohort', '')}/${id}`)}
onClick={this.handleViewClick.bind(this, id)}
>
View Application
</Button>
);
};

handleViewClick = (id, event) => {
event.preventDefault();
this.context.router.push(`/${this.props.path.replace('_cohort', '')}/${id}`);
};

render() {
return (
<Table.Provider
Expand All @@ -61,7 +122,7 @@ export default class CohortViewTable extends React.Component {
style={styles.table}
>
<Table.Header />
<Table.Body rows={this.props.data} rowKey="email"/>
<Table.Body rows={this.props.data} rowKey="id"/>
</Table.Provider>
);
}
Expand Down
Expand Up @@ -8,27 +8,71 @@ export default storybook => {
.addDecorator(reactBootstrapStoryDecorator)
.addStoryTable([
{
name: 'Cohort view for application',
name: 'Cohort view for teacher application',
story: () => (
<CohortViewTable
data={[
{
id: 1,
date_accepted: '11/1/2017',
applicant_name: 'Poppy Pomfrey ',
district_name: 'UK Wizarding',
school_name: 'Hogwarts',
email: 'nurse@hogwarts.edu',
registered_for_summer_workshop: 'Yes'
notified: 'Yes',
assigned_workshop: 'Seattle, 5/1',
registered_workshop: 'Seattle, 5/1'
},
{
id: 2,
date_accepted: '12/1/2017',
applicant_name: 'Filius Flitwick',
district_name: 'UK Wizarding',
school_name: 'Hogwarts',
email: 'short@hogwarts.edu',
registered_for_summer_workshop: 'No'
notified: 'Yes',
assigned_workshop: 'TeacherCon Chicago',
registered_workshop: 'TeacherCon Chicago'
}
]}
viewType="teacher"
path="path"
/>
)
}, {
name: 'Cohort view for facilitator application',
story: () => (
<CohortViewTable
data={[
{
id: 1,
date_accepted: '11/1/2017',
applicant_name: 'Poppy Pomfrey ',
district_name: 'UK Wizarding',
school_name: 'Hogwarts',
email: 'nurse@hogwarts.edu',
notified: 'Yes',
assigned_workshop: 'Seattle, 5/1',
registered_workshop: 'Seattle, 5/1',
assigned_fit: 'Buffalo 6/1',
registered_fit: 'Yes'
},
{
id: 2,
date_accepted: '12/1/2017',
applicant_name: 'Filius Flitwick',
district_name: 'UK Wizarding',
school_name: 'Hogwarts',
email: 'short@hogwarts.edu',
notified: 'Yes',
assigned_workshop: 'Seattle, 5/1',
registered_workshop: 'Seattle, 5/1',
assigned_fit: 'Buffalo 7/1',
registered_fit: 'Yes',
}
]}
viewType="facilitator"
path="path"
/>
)
}
Expand Down
Expand Up @@ -61,7 +61,14 @@ def quick_view
def cohort_view
applications = get_applications_by_role(params[:role].to_sym).where(status: 'accepted').where.not(locked_at: nil)

render json: applications, each_serializer: Api::V1::Pd::ApplicationCohortViewSerializer
serializer =
if TYPES_BY_ROLE[params[:role].to_sym] == Pd::Application::Facilitator1819Application
Api::V1::Pd::FacilitatorApplicationCohortViewSerializer
elsif TYPES_BY_ROLE[params[:role].to_sym] == Pd::Application::Teacher1819Application
Api::V1::Pd::TeacherApplicationCohortViewSerializer
end

render json: applications, each_serializer: serializer
end

# PATCH /api/v1/pd/applications/1
Expand Down
5 changes: 5 additions & 0 deletions dashboard/app/models/pd/application/application_base.rb
Expand Up @@ -97,6 +97,7 @@ class ApplicationBase < ActiveRecord::Base
before_create -> {self.status = :unreviewed}
after_initialize :set_type_and_year
before_validation :set_type_and_year
before_save :update_accepted_date, if: :status_changed?

def set_type_and_year
# Override in derived classes and set to valid values.
Expand All @@ -105,6 +106,10 @@ def set_type_and_year
self.application_type = nil
end

def update_accepted_date
self.accepted_at = status == 'accepted' ? Time.now : nil
end

self.table_name = 'pd_applications'

enum status: %w(
Expand Down

This file was deleted.

@@ -0,0 +1,27 @@
class Api::V1::Pd::FacilitatorApplicationCohortViewSerializer < ActiveModel::Serializer
attributes :id, :date_accepted, :applicant_name, :district_name, :school_name, :email,
:notified, :assigned_fit, :registered_fit

def date_accepted
object.accepted_at.try(:strftime, '%b %e')
end

def email
object.user.email
end

def notified
# TODO: (mehal) implement this
'Not implemented'
end

def assigned_fit
# TODO: (mehal) implement this
'Not implemented'
end

def registered_fit
# TODO: (mehal) implement this
'Not implemented'
end
end
@@ -0,0 +1,31 @@
class Api::V1::Pd::TeacherApplicationCohortViewSerializer < ActiveModel::Serializer
attributes :id, :date_accepted, :applicant_name, :district_name, :school_name, :email,
:notified, :assigned_workshop, :registered_workshop, :accepted_teachercon

def date_accepted
object.accepted_at.try(:strftime, '%b %e')
end

def email
object.user.email
end

def notified
# TODO: (mehal) implement this
'Not implemented'
end

def assigned_workshop
# TODO: (mehal) implement this
'Not implemented'
end

def registered_workshop
# TODO: (mehal) implement this
'Not implemented'
end

def accepted_teachercon
'Not implemented'
end
end

0 comments on commit 487a139

Please sign in to comment.