Home Reference Source

src/objects/Assessment.js

/**
 * Temporary assessment object used when there are no previous assessment
 * If the user starts assessing a new activity, this object is temporarily filled out
 * before being added to the users assessments
 */

/**
 * The assessment object
 * @type {Object}
 */
let assessment = {
    assessmentID: 0,
    activity: 0,
    activityType: 0,
    activityCreateDate: null,
    createDate: null,
    grading: [],
    comment: {
        content: '',
        textColor: null,
        paperColor: null,
    },
    drawing: null,
};

/**
 * Overwrite assessment. Used if user already have an assessment for current activity
 * @param {Object} a - assessment that should overwrite the assessment object
 */
function setAssessment(a) {
    assessment = Object.assign({}, a); //Overwrite with copy
}

/**
 * Sets the id of the assessment
 * @param {number} id - the new id
 */
function setAssessmentId(id) {
    assessment.assessmentID = id;
}
/**
 * Sets the id of the Activity
 * @param {number} activityId - the new id
 */
function setActivityId(activityId) {
    assessment.activity = activityId;
}
/**
 * Sets the activity type
 * @param {Object} activityType - the activity type
 */
function setActivityType(activityType) {
    assessment.activityType = activityType;
}
/**
 * Sets the activityCreateDate
 * @param {Date} date - new activityCreateDate
 */
function setActivityCreateDate(date) {
    assessment.activityCreateDate = date;
}
/**
 * Sets the createDate
 * @param {Date} date - new createDate
 */
function setCreateDate(date) {
    assessment.createDate = date;
}
/**
 * Sets the grading for a question. Overwrites previous gradings for same question
 * @param {Object} grading - new grading
 */
function setGrading(grading) {
    assessment.grading = assessment.grading.filter(
        obj => obj.questionId != grading.questionId,
    );
    assessment.grading.push(grading);
}
/**
 * Sets the comment which consists of content, and colors. Need colors to display comment in diary
 * @param {string} content - the text
 * @param {string} textColor - the color of the text
 * @param {string} paperColor - the color of the paper
 */
function setComment(content, textColor, paperColor) {
    assessment.comment = {
        content: content,
        textColor: textColor,
        paperColor: paperColor,
    };
}
/**
 * Sets the drawing
 * @param {string} drawing - The path to the drawing
 */
function setDrawing(drawing) {
    assessment.drawing = drawing;
}
/**
 * Resets the assessment
 */
function clearAssessment() {
    assessment.assessmentID = 0;
    assessment.activity = 0;
    assessment.createDate = null;
    assessment.grading = [];
    assessment.comment = {
        content: '',
        textColor: null,
        paperColor: null,
    };
    assessment.drawing = null;
}
/**
 * Returns the assessment object
 * @returns {Object} assessment object
 */
function getAssessment() {
    return assessment;
}
/**
 * Returns the assessment id
 * @returns {number} assessment id
 */
function getAssessmentId() {
    return assessment.assessmentID;
}
/**
 * Returns the activity id
 * @returns {number} activity id
 */
function getActivityId() {
    return assessment.activity;
}
/**
 * Returns the activity type
 * @returns {Object} activity type
 */
function getActivityType() {
    return assessment.activityType;
}
/**
 * Returns the activity create date
 * @returns {Date} activity create dates
 */
function getActivityCreateDate() {
    return assessment.activityCreateDate;
}
/**
 * Returns the comment object
 * @returns {Object} comment
 */
function getComment() {
    return assessment.comment.content;
}
/**
 * Returns the grading object
 * @returns {Object} grading
 */
function getGrading() {
    return assessment.grading;
}
/**
 * Returns the drawing path
 * @returns {string} drawing path
 */
function getDrawing() {
    return assessment.drawing;
}

//Make the functions available outside of this file
export {
    setAssessment,
    setAssessmentId,
    setActivityId,
    setActivityType,
    setActivityCreateDate,
    setCreateDate,
    setGrading,
    setComment,
    setDrawing,
    getActivityId,
    getActivityType,
    getActivityCreateDate,
    getAssessment,
    getComment,
    getGrading,
    getDrawing,
    clearAssessment,
    getAssessmentId,
};