<commit_before><link rel="import" href="/resources/polymer/polymer/polymer.html">

<link rel="import" href="/resources/polymer/iron-ajax/iron-ajax.html">
<link rel="import" href="/resources/serialisation/tg-serialiser.html">

<dom-module id="tg-criteria-validator"> <!-- TODO hidden -->
    <template>
        <tg-serialiser id="serialiser"></tg-serialiser>
        <iron-ajax id="ajaxSender" url="[[_url]]" method="POST" handle-as="json" on-response="_processValidatorResponse" on-error="_processValidatorError"></iron-ajax>
    </template>
</dom-module>

<script>
    (function () {
        Polymer({
        	is: 'tg-criteria-validator',
        	
        	properties: {
            	/////////////////////////////////////////////////////////////////////////////////////////////////////////
            	////////////////////////////////////////// EXTERNAL PROPERTIES //////////////////////////////////////////
            	/////////////////////////////////////////////////////////////////////////////////////////////////////////
            	// These mandatory properties must be specified in attributes, when constructing descendant elements.  //
            	// No default values are allowed in this case.														   //
            	/////////////////////////////////////////////////////////////////////////////////////////////////////////
            	miType: String,
            	postValidatedDefault: Function,
            	postValidatedDefaultError: Function,
            	processResponse: Function,
            	processError: Function,
        		
             	/////////////////////////////////////////////////////////////////////////////////////////////////////////
             	//////////////////////////////// INNER PROPERTIES, THAT GOVERN CHILDREN /////////////////////////////////
             	/////////////////////////////////////////////////////////////////////////////////////////////////////////
             	// These properties derive from other properties and are considered as 'private' -- need to have '_'   //
             	//   prefix. 																				           //
             	// Also, these properties are designed to be bound to children element properties -- it is necessary to//
             	//   populate their default values in ready callback (to have these values populated in children)!     //
             	/////////////////////////////////////////////////////////////////////////////////////////////////////////
             	_url: {
             		type: String,
             		computed: '_computeUrl(miType)'
             	}
        	},
        	
            ready: function() { 
                var self = this;
                
                self._processValidatorResponse = function (e) {
                	self.processResponse(e, "criteria-validate", function (entityAndCustomObject) {
                        self.postValidatedDefault(entityAndCustomObject);
                	});
                };
                
                self._processValidatorError = function (e) {
                	self.processError(e, "criteria-validate", function (errorResult) {
                        self.postValidatedDefaultError(errorResult);
                    });
                };
            },

            /**
             * Starts the process of entity validation.
             *
             * @param modifiedPropertiesHolder -- the entity with modified properties
             */
            validate: function (modifiedPropertiesHolder) {
                // console.log("validate: modifiedPropertiesHolder", modifiedPropertiesHolder);
                var ser = this.$.serialiser.serialise(modifiedPropertiesHolder);
                // console.log("validate: serialised modifiedPropertiesHolder", ser);
                this.$.ajaxSender.body = JSON.stringify(ser);
                this.$.ajaxSender.generateRequest();
            },

            /**
             * Cancels any unfinished validation that was requested earlier (if any).
             */
            abortValidationIfAny: function() {
            	var reflector = this.$.serialiser.$.reflector;
            	var numberOfAbortedRequests = reflector.discardAllRequests(this.$.ajaxSender);
            	console.warn("abortValidationIfAny: number of aborted requests =", numberOfAbortedRequests);
            },
            
        	/**
        	 * Computes URL for 'ajaxSender'.
        	 */
        	_computeUrl: function (miType) {
        		return "/criteria/" + miType;
        	}
        });
    })();
</script><commit_msg>#474 Adjusted logging of criteria-validator's count of aborted validations.<commit_after><link rel="import" href="/resources/polymer/polymer/polymer.html">

<link rel="import" href="/resources/polymer/iron-ajax/iron-ajax.html">
<link rel="import" href="/resources/serialisation/tg-serialiser.html">

<dom-module id="tg-criteria-validator"> <!-- TODO hidden -->
    <template>
        <tg-serialiser id="serialiser"></tg-serialiser>
        <iron-ajax id="ajaxSender" url="[[_url]]" method="POST" handle-as="json" on-response="_processValidatorResponse" on-error="_processValidatorError"></iron-ajax>
    </template>
</dom-module>

<script>
    (function () {
        Polymer({
        	is: 'tg-criteria-validator',
        	
        	properties: {
            	/////////////////////////////////////////////////////////////////////////////////////////////////////////
            	////////////////////////////////////////// EXTERNAL PROPERTIES //////////////////////////////////////////
            	/////////////////////////////////////////////////////////////////////////////////////////////////////////
            	// These mandatory properties must be specified in attributes, when constructing descendant elements.  //
            	// No default values are allowed in this case.														   //
            	/////////////////////////////////////////////////////////////////////////////////////////////////////////
            	miType: String,
            	postValidatedDefault: Function,
            	postValidatedDefaultError: Function,
            	processResponse: Function,
            	processError: Function,
        		
             	/////////////////////////////////////////////////////////////////////////////////////////////////////////
             	//////////////////////////////// INNER PROPERTIES, THAT GOVERN CHILDREN /////////////////////////////////
             	/////////////////////////////////////////////////////////////////////////////////////////////////////////
             	// These properties derive from other properties and are considered as 'private' -- need to have '_'   //
             	//   prefix. 																				           //
             	// Also, these properties are designed to be bound to children element properties -- it is necessary to//
             	//   populate their default values in ready callback (to have these values populated in children)!     //
             	/////////////////////////////////////////////////////////////////////////////////////////////////////////
             	_url: {
             		type: String,
             		computed: '_computeUrl(miType)'
             	}
        	},
        	
            ready: function() { 
                var self = this;
                
                self._processValidatorResponse = function (e) {
                	self.processResponse(e, "criteria-validate", function (entityAndCustomObject) {
                        self.postValidatedDefault(entityAndCustomObject);
                	});
                };
                
                self._processValidatorError = function (e) {
                	self.processError(e, "criteria-validate", function (errorResult) {
                        self.postValidatedDefaultError(errorResult);
                    });
                };
            },

            /**
             * Starts the process of entity validation.
             *
             * @param modifiedPropertiesHolder -- the entity with modified properties
             */
            validate: function (modifiedPropertiesHolder) {
                // console.log("validate: modifiedPropertiesHolder", modifiedPropertiesHolder);
                var ser = this.$.serialiser.serialise(modifiedPropertiesHolder);
                // console.log("validate: serialised modifiedPropertiesHolder", ser);
                this.$.ajaxSender.body = JSON.stringify(ser);
                this.$.ajaxSender.generateRequest();
            },

            /**
             * Cancels any unfinished validation that was requested earlier (if any).
             */
            abortValidationIfAny: function() {
            	var reflector = this.$.serialiser.$.reflector;
            	var numberOfAbortedRequests = reflector.discardAllRequests(this.$.ajaxSender);
            	if (numberOfAbortedRequests > 0) {
            	    console.warn("abortValidationIfAny: number of aborted requests =", numberOfAbortedRequests);
            	}
            },
            
        	/**
        	 * Computes URL for 'ajaxSender'.
        	 */
        	_computeUrl: function (miType) {
        		return "/criteria/" + miType;
        	}
        });
    })();
</script>
{'fraction_non_alphanumeric': 0.2520342844743409, 'fraction_numerical': 0.00043398068785939026, 'mean_word_length': 1.0290556900726393, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 32, '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': '1224339', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1839, 'n_words': 416}