<commit_before>// Processing step class
// Describes the process of official role (like revision, processing or front desk)

'use strict';

var Map                   = require('es6-map')
  , memoize               = require('memoizee/plain')
  , ensureDb              = require('dbjs/valid-dbjs')
  , defineStringLine      = require('dbjs-ext/string/string-line')
  , defineCreateEnum      = require('dbjs-ext/create-enum')
  , _                     = require('mano').i18n.bind('Model')
  , defineInstitution     = require('./institution')
  , defineFormSectionBase = require('./form-section-base');

module.exports = memoize(function (db) {
	var StringLine = defineStringLine(ensureDb(db))
	  , Institution = defineInstitution(db)
	  , FormSectionBase = defineFormSectionBase(db);

	defineCreateEnum(db);

	// Enum for processing step status
	var ProcessingStepStatus = StringLine.createEnum('ProcessingStepStatus', new Map([
		['paused', { label: _("Paused") }],
		['sentBack', { label: _("Sent back") }],
		['rejected', { label: _("Rejected") }],
		['approved', { label: _("Approved") }]
	]));

	return db.Object.extend('ProcessingStep', {
		// Label (name) of processing step
		label: { type: StringLine },
		// If step is processed by single institution
		// then instution should be exposed here
		institution: { type: Institution },

		// Whether given step applies at all
		isApplicable: { type: db.Boolean, value: true },
		// Whether business process is at given step or have passed it
		isReady: { type: db.Boolean, value: function (_observe) {
			return Boolean(_observe(this.master._isSubmitted) && this.isApplicable);
		} },
		// Processing step form fields section (applies only to approved status)
		dataForm: { type: FormSectionBase, nested: true },
		// Eventual reason of file been sent back
		sentBackReason: { type: db.String, required: true  },
		// Eventual reason of rejection
		rejectReason: { type: db.String, required: true  },
		// Status of step
		status: { type: ProcessingStepStatus, required: true },

		// Whether process is pending at step
		isPending: { type: db.Boolean, value: function (_observe) {
			// If not ready, then obviously not pending
			if (!this.isReady) return false;
			// If status not decided then clearly pending
			if (!this.status) return true;
			// If approved, but form data is complete, it's still pending
			if (this.status === 'approved') return (_observe(this.dataForm._status) !== 1);
			// If sent back, but no reason provided, it's still pending<commit_msg>Define processor property for processingStep<commit_after>// Processing step class
// Describes the process of official role (like revision, processing or front desk)

'use strict';

var Map                   = require('es6-map')
  , memoize               = require('memoizee/plain')
  , ensureDb              = require('dbjs/valid-dbjs')
  , defineStringLine      = require('dbjs-ext/string/string-line')
  , defineCreateEnum      = require('dbjs-ext/create-enum')
  , _                     = require('mano').i18n.bind('Model')
  , defineUser            = require('./user')
  , defineInstitution     = require('./institution')
  , defineFormSectionBase = require('./form-section-base');

module.exports = memoize(function (db) {
	var StringLine = defineStringLine(ensureDb(db))
	  , Institution = defineInstitution(db)
	  , User = defineUser(db)
	  , FormSectionBase = defineFormSectionBase(db);

	defineCreateEnum(db);

	// Enum for processing step status
	var ProcessingStepStatus = StringLine.createEnum('ProcessingStepStatus', new Map([
		['paused', { label: _("Paused") }],
		['sentBack', { label: _("Sent back") }],
		['rejected', { label: _("Rejected") }],
		['approved', { label: _("Approved") }]
	]));

	return db.Object.extend('ProcessingStep', {
		// Label (name) of processing step
		label: { type: StringLine },
		// If step is processed by single institution
		// then instution should be exposed here
		institution: { type: Institution },
		// Official that processed request at given processing step
		processor: { type: User },

		// Whether given step applies at all
		isApplicable: { type: db.Boolean, value: true },
		// Whether business process is at given step or have passed it
		isReady: { type: db.Boolean, value: function (_observe) {
			return Boolean(_observe(this.master._isSubmitted) && this.isApplicable);
		} },
		// Processing step form fields section (applies only to approved status)
		dataForm: { type: FormSectionBase, nested: true },
		// Eventual reason of file been sent back
		sentBackReason: { type: db.String, required: true  },
		// Eventual reason of rejection
		rejectReason: { type: db.String, required: true  },
		// Status of step
		status: { type: ProcessingStepStatus, required: true },

		// Whether process is pending at step
		isPending: { type: db.Boolean, value: function (_observe) {
			// If not ready, then obviously not pending
			if (!this.isReady) return false;
			// If status not decided then clearly pending
			if (!this.status) return true;
			// If approved, but form data is complete, it's still pending
			if (this.status === 'approved') return (_observe(this.dataForm._status) !== 1);
			// If sent back, but no reason provided, it's still pending
{'fraction_non_alphanumeric': 0.1276473955352032, 'fraction_numerical': 0.0015264262545315779, 'mean_word_length': 3.491859468723222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '85009', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1480, 'n_words': 476}