This repository has been archived by the owner on Aug 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from apo5698/issues/2021/01/31
Helli v0.5.1
- Loading branch information
Showing
29 changed files
with
406 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api | ||
class AssignmentsController < ApplicationController | ||
# GET https://api.helli.app/assignments/:assignment_id/rubrics/items | ||
def rubrics_items | ||
assignment = Assignment.find(params.require(:assignment_id)) | ||
render json: assignment.rubric_items | ||
end | ||
|
||
# POST https://api.helli.app/assignments/:assignment_id/zybooks | ||
def zybooks | ||
csv = params.require(:_json) | ||
csv.each do |record| | ||
participant = Participant.find_by( | ||
assignment_id: params.require(:assignment_id), | ||
email_address: record[:email] | ||
) | ||
Redis.current.set(participant.zybooks_redis_key, record[:total]) | ||
end | ||
|
||
render status: :ok | ||
rescue Redis::BaseError => e | ||
render plain: e.message, status: :unprocessable_entity | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
# noinspection RailsI18nInspection | ||
module Api | ||
class ConstantsController < ApplicationController | ||
def checkstyle | ||
# noinspection RailsI18nInspection | ||
render json: I18n.t('checkstyle').to_json | ||
end | ||
|
||
def zybooks | ||
render json: I18n.t('zybooks').to_json | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
app/javascript/components/grading/v2/options/Zybooks.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import * as React from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
import { Button, Form, Input, message, Space, Upload } from 'antd'; | ||
import { FormInstance } from 'antd/lib/form'; | ||
import { InboxOutlined, MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; | ||
import Papa from 'papaparse'; | ||
import { getHelliApi, HelliApiUrl } from '../../../HelliApiUtil'; | ||
|
||
const { Dragger } = Upload; | ||
|
||
const Zybooks = (props: { form: FormInstance, assignmentId: number }) => { | ||
const { assignmentId } = props; | ||
const [fileList, updateFileList] = useState([]); | ||
const [defaultScale, setDefaultScale] = useState([]); | ||
|
||
const fileProps = { | ||
fileList, | ||
accept: 'text/csv, application/vnd.ms-excel', | ||
beforeUpload(file) { | ||
if (file.type !== 'text/csv' && file.type !== 'application/vnd.ms-excel') { | ||
message.error(`${file.name} is not a csv file.`); | ||
return false; | ||
} | ||
|
||
message.loading({ content: `Parsing ${file.name}...`, key: 'message' }); | ||
|
||
const reader = new FileReader(); | ||
reader.onload = (event) => { | ||
const str = event | ||
.target | ||
.result | ||
.toString() | ||
.replace(/Total \(\d+\)/, 'Total'); | ||
|
||
const json = Papa | ||
.parse(str, { header: true, skipEmptyLines: true }) | ||
.data | ||
.map((e) => ({ email: e['School email'], total: e.Total })); | ||
|
||
fetch(HelliApiUrl(`assignments/${assignmentId}/zybooks`), { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: 'application/json', | ||
}, | ||
body: JSON.stringify(json), | ||
}) | ||
.then((response) => { | ||
if (!response.ok) { | ||
updateFileList([]); | ||
throw response; | ||
} | ||
}) | ||
.then(() => { | ||
message.success({ content: `${file.name} uploaded.`, key: 'message' }); | ||
}) | ||
.catch((error) => { | ||
error | ||
.text() | ||
.then((text) => { | ||
message.error({ content: text, key: 'message' }); | ||
}); | ||
}); | ||
}; | ||
reader.readAsText(file); | ||
|
||
return false; | ||
}, | ||
}; | ||
|
||
useEffect(() => { | ||
getHelliApi('zybooks') | ||
.then((data) => { | ||
setDefaultScale(data); | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { props.form.resetFields(); }, [defaultScale]); | ||
|
||
return ( | ||
<Space direction="vertical"> | ||
<Dragger {...fileProps}> | ||
<p className="ant-upload-drag-icon"> | ||
<InboxOutlined /> | ||
</p> | ||
<p className="ant-upload-text">Click or drag file to this area to upload</p> | ||
<p className="ant-upload-hint"> | ||
The filename should look like NCSUCSC116BalikSpring2021_report_004_2021-01-29_2359.csv | ||
</p> | ||
</Dragger> | ||
<Form.List name="scale" initialValue={defaultScale}> | ||
{ | ||
(fields, { add, remove }) => ( | ||
<> | ||
{ | ||
fields.map((field) => ( | ||
<Space key={field.key} style={{ display: 'flex' }} align="baseline"> | ||
<Form.Item | ||
{...field} | ||
name={[field.name, 'total']} | ||
fieldKey={[field.fieldKey, 'total']} | ||
rules={[{ required: true, message: 'Missing total score' }]} | ||
> | ||
<Input placeholder="Total score >=" /> | ||
</Form.Item> | ||
<Form.Item | ||
{...field} | ||
name={[field.name, 'point']} | ||
fieldKey={[field.fieldKey, 'point']} | ||
rules={[{ required: true, message: 'Missing point' }]} | ||
> | ||
<Input placeholder="Points" /> | ||
</Form.Item> | ||
<MinusCircleOutlined onClick={() => remove(field.name)} /> | ||
</Space> | ||
)) | ||
} | ||
<Form.Item> | ||
<Button type="dashed" onClick={() => add()} block icon={<PlusOutlined />}> | ||
Add scale | ||
</Button> | ||
</Form.Item> | ||
</> | ||
) | ||
} | ||
</Form.List> | ||
</Space> | ||
); | ||
}; | ||
|
||
export default Zybooks; |
Oops, something went wrong.