{"size": 2257, "ext": "js", "max_stars_repo_path": "src/assessment-behavior.js", "max_stars_repo_name": "Brightspace/d2l-rubric", "max_stars_repo_stars_event_min_datetime": "2018-01-26T15:06:58.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-06T10:35:24.000Z", "max_issues_repo_path": "src/assessment-behavior.js", "max_issues_repo_name": "Brightspace/d2l-rubric", "max_issues_repo_issues_event_min_datetime": "2018-01-24T16:40:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T23:31:52.000Z", "max_forks_repo_path": "src/assessment-behavior.js", "max_forks_repo_name": "Brightspace/d2l-rubric", "max_forks_repo_forks_event_min_datetime": "2018-01-24T16:10:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-08T18:32:49.000Z"}
{"max_stars_count": 3, "max_issues_count": 484, "max_forks_count": 14, "avg_line_length": 37.0, "max_line_length": 94, "alphanum_fraction": 0.7603012849}
import './d2l-rubric-action-behavior.js';
import AssessmentHelper from './assessment-helpers/assessment.js';
import CriterionAssessmentHelper from './assessment-helpers/criterion-assessment.js';
import CriterionCellAssessmentHelper from './assessment-helpers/criterion-cell-assessment.js';
import OverallLevelAssessmentHelper from './assessment-helpers/overall-level-assessment.js';

window.D2L = window.D2L || {};

window.D2L.PolymerBehaviors = window.D2L.PolymerBehaviors || {};
window.D2L.PolymerBehaviors.Rubric = window.D2L.PolymerBehaviors.Rubric || {};

D2L.PolymerBehaviors.Rubric.AssessmentBehaviorImpl = {

	properties: {
		AssessmentHelper: AssessmentHelper,
		CriterionAssessmentHelper: CriterionAssessmentHelper,
		CriterionCellAssessmentHelper: CriterionCellAssessmentHelper,
		OverallLevelAssessmentHelper: OverallLevelAssessmentHelper
	},

	created: function() {
		const actionRunner = this._execAssessmentAction.bind(this);
		this.AssessmentHelper = new AssessmentHelper(actionRunner);
		this.CriterionAssessmentHelper = new CriterionAssessmentHelper(actionRunner);
		this.CriterionCellAssessmentHelper = new CriterionCellAssessmentHelper(actionRunner);
		this.OverallLevelAssessmentHelper = new OverallLevelAssessmentHelper(actionRunner);
	},

	_execAssessmentAction: function(actionGetter, fieldOverrides) {
		fieldOverrides = fieldOverrides || {};
		return window.D2L.Siren.EntityStore.getToken(this.token).then(token => {
			return window.D2L.Siren.ActionQueue.enqueue(() => {
				const action = actionGetter();
				if (!action) return;

				const fields = [];
				(action.fields || []).forEach(actionField => {
					const valueOverride = fieldOverrides[actionField.name];
					fields.push({
						name: actionField.name,
						value: valueOverride !== undefined ? valueOverride : actionField.value
					});
				});

				return this._performSirenAction(action, fields, token.tokenValue).catch(error => {
					// Throw the error, but still keep processing queued actions
					setTimeout(() => { throw error; }, 0);
					return null;
				});
			});
		});
	}

};

/** @polymerBehavior */
D2L.PolymerBehaviors.Rubric.AssessmentBehavior = [
	D2L.PolymerBehaviors.Rubric.AssessmentBehaviorImpl,
	D2L.PolymerBehaviors.Rubric.ActionBehavior
];
