Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In cohort view, add columns for assigned workshop/fit #19727

Merged
merged 5 commits into from Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -115,6 +115,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 @@ -10,10 +10,15 @@ export default class CohortView extends React.Component{
static propTypes = {
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 @@ -44,6 +49,8 @@ export default class CohortView extends React.Component{
{this.props.route.applicationType}
<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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about, above on line 100

before_save :update_accepted_date, if: -> {status_changed? && accepted?}

Then this method can be simplified to:

def update_accepted_data
  self.accepted_at = Time.zone.now
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want accepted date to be cleared if the application is un-accepted


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