Skip to content

Commit

Permalink
Merge pull request #755 from Lunatic-Labs/SKIL-533
Browse files Browse the repository at this point in the history
SKIL-533
  • Loading branch information
aparriaran authored Nov 7, 2024
2 parents 24684a2 + 2a58ef0 commit 3e8ca31
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ class AdminAddAssessmentTask extends Component {
if (assessmentTask && !addAssessmentTask) {
genericResourceGET(
`/completed_assessment?assessment_task_id=${assessmentTask["assessment_task_id"]}`,
"completedAssessments",
this
"completed_assessments",
this,
{ dest: "completedAssessments" }
);

this.setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CompleteAssessmentTask extends Component {

genericResourceGET(
`/completed_assessment?assessment_task_id=${chosenAssessmentTask["assessment_task_id"]}&unit=${this.state.unitOfAssessment ? "team" : "individual"}`,
"completedAssessments", this
"completed_assessments", this, {dest: "completedAssessments"}
);
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ class CompleteAssessmentTask extends Component {
if (chosenAssessmentTask["role_id"] === 5) {
genericResourceGET(
`/team_by_user?user_id=${this.userId}&course_id=${chosenCourse["course_id"]}`,
"team", this
"teams", this, {dest: "team"}
);
}

Expand All @@ -153,7 +153,7 @@ class CompleteAssessmentTask extends Component {

genericResourceGET(
`/completed_assessment?assessment_task_id=${chosenAssessmentTask["assessment_task_id"]}&unit=${this.state.unitOfAssessment ? "team" : "individual"}`,
"completedAssessments", this
"completed_assessments", this, {dest: "completedAssessments"}
);

const checkinEventSource = createEventSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ReportingDashboard extends Component {
componentDidMount() {
var courseID = this.props.navbar.state.chosenCourse.course_id;

genericResourceGET(`/assessment_task?course_id=${courseID}`, "assessmentTasks", this);
genericResourceGET(`/assessment_task?course_id=${courseID}`, "assessment_tasks", this, {dest: "assessmentTasks"});

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AdminViewAssessmentStatus extends Component {
// Fetch completed assessment tasks data for the chosen assessment task
genericResourceGET(
`/completed_assessment?admin_id=${chosenCourse["admin_id"]}&assessment_task_id=${this.props.chosenAssessmentId}`,
"completedAssessments", this
"completed_assessments", this, {dest: "completedAssessments"}
);
}

Expand Down Expand Up @@ -66,7 +66,7 @@ class AdminViewAssessmentStatus extends Component {
// Fetch ratio of users who have completed assessment task to total users in the class
genericResourceGET(
`/completed_assessment?course_id=${chosenCourse.course_id}&assessment_id=${this.props.chosenAssessmentId}`,
"completedAssessmentsPercentage", this
"completed_assessments", this, {dest: "completedAssessmentsPercentage"}
);

this.setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AdminViewTeamRatings extends Component {
componentDidMount() {
genericResourceGET(
`/assessment_task?admin_id=${this.props.chosenCourse["admin_id"]}`,
"assessmentTasks", this
"assessment_tasks", this, {dest: "assessmentTasks"}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AdminViewAssessmentTask extends Component {

genericResourceGET(
`/assessment_task?course_id=${navbar.state.chosenCourse["course_id"]}`,
"assessmentTasks", this);
"assessment_tasks", this, {dest: "assessmentTasks"});

genericResourceGET(`/role?`,'roles', this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ class ViewAssessmentTasks extends Component {
this.handleDownloadCsv = (atId, exportButtonId, assessmentTaskIdToAssessmentTaskName) => {
let promise = genericResourceGET(
`/csv_assessment_export?assessment_task_id=${atId}`,
"csvCreation",
this
"csv_creation",
this,
{dest: "csvCreation"}
);

promise.then(result => {
Expand Down Expand Up @@ -78,14 +79,16 @@ class ViewAssessmentTasks extends Component {

genericResourceGET(
`/assessment_task?course_id=${courseId}`,
"assessmentTasks",
this
"assessment_tasks",
this,
{dest: "assessmentTasks"}
);

genericResourceGET(
`/completed_assessment?course_id=${courseId}&only_course=true`,
"completedAssessments",
this
"completed_assessments",
this,
{dest: "completedAssessments"}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ class AdminViewCompleteAssessmentTasks extends Component {
if (chosenAssessmentTask["unit_of_assessment"]) {
genericResourceGET(
`/completed_assessment?assessment_task_id=${chosenAssessmentTask["assessment_task_id"]}&unit=team`,
"completedAssessments",
this
"completed_assessments",
this,
{dest: "completedAssessments"}
);
} else {
genericResourceGET(
`/completed_assessment?assessment_task_id=${chosenAssessmentTask["assessment_task_id"]}&unit=individual`,
"completedAssessments",
this
"completed_assessments",
this,
{dest: "completedAssessments"}
);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ class StudentViewAssessmentTask extends Component {

genericResourceGET(
`/assessment_task?course_id=${chosenCourseID}`,
"assessmentTasks", this);
"assessment_tasks", this, {dest: "assessmentTasks"});

genericResourceGET(
`/completed_assessment?course_id=${chosenCourseID}`,
"completedAssessments", this);
"completed_assessments", this, {dest: "completedAssessments"});
} else { // If the user is a TA, this returns assessments completed by the TA
genericResourceGET(
`/assessment_task?course_id=${chosenCourseID}&role_id=${userRole}`,
"assessmentTasks", this);
"assessment_tasks", this, {dest: "assessmentTasks"});

genericResourceGET(
`/completed_assessment?course_id=${chosenCourseID}&role_id=${userRole}`,
"completedAssessments", this);
"completed_assessments", this, {dest: "completedAssessments"});
}

genericResourceGET(
Expand All @@ -58,7 +58,7 @@ class StudentViewAssessmentTask extends Component {

genericResourceGET(
`/course?course_id=${chosenCourseID}`,
"counts", this);
"course_count", this, {dest: "counts"});
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ class StudentCompletedAssessmentTasks extends Component {

genericResourceGET(
`/assessment_task?course_id=${chosenCourseID}`,
"assessmentTasks", this
"assessment_tasks", this, {dest: "assessmentTasks"}
);

if (userRole === 5) { // If the user is a student, this returns completed assessments for the student
genericResourceGET(
`/completed_assessment?course_id=${chosenCourseID}`,
"completedAssessments", this
"completed_assessments", this, {dest: "completedAssessments"}
);
} else { // If the user is a TA, this returns assessments completed by the TA
genericResourceGET(
`/completed_assessment?course_id=${chosenCourseID}&role_id=${userRole}`,
"completedAssessments", this);
"completed_assessments", this, {dest: "completedAssessments"});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class StudentConfirmCurrentTeam extends Component {

genericResourceGET(
`/team_members?course_id=${courseId}`,
"teamMembers", this
"team_members", this, {dest: "teamMembers"}
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CodeRequirement extends Component {

genericResourceGET(
`/assessment_task?assessment_task_id=${atId}`,
"assessmentTasks", this);
"assessment_tasks", this, {dest: "assessmentTasks"});
}

render() {
Expand Down
42 changes: 15 additions & 27 deletions FrontEndReact/src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,31 @@ import Cookies from 'universal-cookie';
import { zonedTimeToUtc, format } from "date-fns-tz";
import * as eventsource from "eventsource-client";

export async function genericResourceGET(fetchURL, resource, component) {
return await genericResourceFetch(fetchURL, resource, component, "GET", null);
export async function genericResourceGET(fetchURL, resource, component, options = {}) {
return await genericResourceFetch(fetchURL, resource, component, "GET", null, options);
}

export async function genericResourcePOST(fetchURL, component, body) {
return await genericResourceFetch(fetchURL, null, component, "POST", body);
export async function genericResourcePOST(fetchURL, component, body, options = {}) {
return await genericResourceFetch(fetchURL, null, component, "POST", body, options);
}

export async function genericResourcePUT(fetchURL, component, body) {
return await genericResourceFetch(fetchURL, null, component, "PUT", body);
export async function genericResourcePUT(fetchURL, component, body, options = {}) {
return await genericResourceFetch(fetchURL, null, component, "PUT", body, options);
}

export async function genericResourceDELETE(fetchURL, component) {
return await genericResourceFetch(fetchURL, null, component, "DELETE", null)
export async function genericResourceDELETE(fetchURL, component, options = {}) {
return await genericResourceFetch(fetchURL, null, component, "DELETE", null, options)
}

function createApiRequestUrl(fetchURL, cookies) {
return fetchURL.indexOf('?') > -1 ? apiUrl + fetchURL + `&user_id=${cookies.get('user')['user_id']}` : apiUrl + fetchURL + `?user_id=${cookies.get('user')['user_id']}`;
}

async function genericResourceFetch(fetchURL, resource, component, type, body) {
async function genericResourceFetch(fetchURL, resource, component, type, body, options = {}) {
const {
dest = resource
} = options;

const cookies = new Cookies();

if(cookies.get('access_token') && cookies.get('refresh_token') && cookies.get('user')) {
Expand Down Expand Up @@ -66,24 +70,8 @@ async function genericResourceFetch(fetchURL, resource, component, type, body) {

state['errorMessage'] = null;

if(resource != null) {
var getResource = resource;

getResource = (getResource === "assessmentTasks") ? "assessment_tasks": getResource;

getResource = (getResource === "completedAssessments" || getResource === "completedAssessmentsPercentage") ? "completed_assessments": getResource;

getResource = (getResource === "csvCreation") ? "csv_creation": getResource;

getResource = (getResource === "teamMembers") ? "team_members": getResource;

getResource = (getResource === "indiv_users") ? "users": getResource;

getResource = (getResource === "counts") ? "course_count": getResource;

getResource = (getResource === "team") ? "teams": getResource;

state[resource] = result['content'][getResource][0];
if(resource) {
state[dest] = result['content'][resource][0];
}

component.setState(state);
Expand Down

0 comments on commit 3e8ca31

Please sign in to comment.