<commit_before>import '/resources/polymer/@polymer/polymer/polymer-legacy.js';
import { TgEntityCentreBehavior } from '/resources/centre/tg-entity-centre-behavior.js';
import '/resources/images/tg-icons.js'; // this is for common tg-icons:share icon

const TgEntityCentreTemplateBehaviorImpl = {

    properties: {
        isRunning: {
            type: Boolean,
            observer: '_isRunningChanged'
        },
        pageNumber: Number,
        pageCount: Number,
        pageNumberUpdated: Number,
        pageCountUpdated: Number,
        staleCriteriaMessage: String,
        _centreDirtyOrEdited: Boolean,
        _defaultPropertyActionAttrs: Object,
        _pendingRefresh : {
            type: Boolean,
            value: false
        },
        _entitiesToRefresh: Array,
        _visible: {
            type: Boolean,
            value: false
        },
        _isEgiEditing : {
            type: Boolean,
            value : false
        }
    },

    created: function () {

        this._entitiesToRefresh = [];

        // bind SSE event handling method regardless of the fact whether this particulare
        // centre is bound to some SSE url or not.
        this.dataHandler = function (msg) {

            let entityToRefresh = null;
            if (msg.id) {
                // let's search for an item to update...
                // if the current EGI model does not contain an updated entity then there is no need for a refresh...
                // TODO such update strategy might need to be revisited in future...
                entityToRefresh = this.$.egi.egiModel.find(entry => entry.entity.get('id') === msg.id);
            }

            //Initialise entities to refresh: If sse event with id and egi has entity with that id then add to the list of entites to refresh.
            //Otherwise if sse event is without id or egi doesn't have an entity with that id then clear entities to refresh list to refresh whole centre.
            if (entityToRefresh) {
                this._entitiesToRefresh.push(entityToRefresh.entity);
            } else {
                this._entitiesToRefresh = [];
            }

            if (!this._pendingRefresh) {
                this._pendingRefresh = true;
                if (this._visible && !this._isEgiEditing) {
                    this.showRefreshToast();
                }
            }
            
        }.bind(this);

        /////////////////TgDelayedActionBehavior related properties//////////////////////
        this.actionText = 'REFRESH';
        this.cancelText = 'SKIP';
        this.textForCountdownAction = "Data changed. Refreshing in ";
        this.textForPromptAction = "Data changed.";
        
        this.actionHandler = function () {
            if (this._pendingRefresh) {
                this._pendingRefresh = false;
                this.refreshEntities(this._entitiesToRefresh);
                this._entitiesToRefresh = [];
            }
        }.bind(this);

        this.cancelHandler = function () {
            this._pendingRefresh = false;
            this._entitiesToRefresh = [];
        }.bind(this);
        /////////////////////////////////////////////////////////////////////////////////
    },

    /**
     * Initialisation block. It has all children web components already initialised.
     */
    ready: function () {
        this.classList.add("canLeave");
        this._defaultPropertyActionAttrs = {currentState: "EDIT", centreUuid: this.uuid};
        this.navigationPreAction = this.navigationPreAction.bind(this);

        //////////////////Event handler to determine centre visibility///////////////////
        const observableNodes = [this._dom().$.centreResultContainer, ...this._dom().$.alternativeViewSlot.assignedNodes({ flatten: true })];
        const observer = new IntersectionObserver((entries, observer) => {

            const anyViewVisibility = entries.some(entry => entry.intersectionRatio > 0 && observableNodes.indexOf(entry.target) >= 0);

            if (anyViewVisibility && !this._visible) {
                this._visible = true;
                if (this._pendingRefresh && !this._isEgiEditing) {
                    this.showRefreshToast();
                }
            } else if (!anyViewVisibility && this._visible) {
                this._visible = false;
                if (this._pendingRefresh && !this._isEgiEditing) {
                    this.hideRefreshToast();
                }
            }
            
        }, {
            root: document.documentElement
        });
        observableNodes.forEach(altView => {
            observer.observe(altView);
        });<commit_msg>#1854 Simplified logi that determines whether any of bserved views are visible or not.<commit_after>import '/resources/polymer/@polymer/polymer/polymer-legacy.js';
import { TgEntityCentreBehavior } from '/resources/centre/tg-entity-centre-behavior.js';
import '/resources/images/tg-icons.js'; // this is for common tg-icons:share icon

const TgEntityCentreTemplateBehaviorImpl = {

    properties: {
        isRunning: {
            type: Boolean,
            observer: '_isRunningChanged'
        },
        pageNumber: Number,
        pageCount: Number,
        pageNumberUpdated: Number,
        pageCountUpdated: Number,
        staleCriteriaMessage: String,
        _centreDirtyOrEdited: Boolean,
        _defaultPropertyActionAttrs: Object,
        _pendingRefresh : {
            type: Boolean,
            value: false
        },
        _entitiesToRefresh: Array,
        _visible: {
            type: Boolean,
            value: false
        },
        _isEgiEditing : {
            type: Boolean,
            value : false
        }
    },

    created: function () {

        this._entitiesToRefresh = [];

        // bind SSE event handling method regardless of the fact whether this particulare
        // centre is bound to some SSE url or not.
        this.dataHandler = function (msg) {

            let entityToRefresh = null;
            if (msg.id) {
                // let's search for an item to update...
                // if the current EGI model does not contain an updated entity then there is no need for a refresh...
                // TODO such update strategy might need to be revisited in future...
                entityToRefresh = this.$.egi.egiModel.find(entry => entry.entity.get('id') === msg.id);
            }

            //Initialise entities to refresh: If sse event with id and egi has entity with that id then add to the list of entites to refresh.
            //Otherwise if sse event is without id or egi doesn't have an entity with that id then clear entities to refresh list to refresh whole centre.
            if (entityToRefresh) {
                this._entitiesToRefresh.push(entityToRefresh.entity);
            } else {
                this._entitiesToRefresh = [];
            }

            if (!this._pendingRefresh) {
                this._pendingRefresh = true;
                if (this._visible && !this._isEgiEditing) {
                    this.showRefreshToast();
                }
            }
            
        }.bind(this);

        /////////////////TgDelayedActionBehavior related properties//////////////////////
        this.actionText = 'REFRESH';
        this.cancelText = 'SKIP';
        this.textForCountdownAction = "Data changed. Refreshing in ";
        this.textForPromptAction = "Data changed.";
        
        this.actionHandler = function () {
            if (this._pendingRefresh) {
                this._pendingRefresh = false;
                this.refreshEntities(this._entitiesToRefresh);
                this._entitiesToRefresh = [];
            }
        }.bind(this);

        this.cancelHandler = function () {
            this._pendingRefresh = false;
            this._entitiesToRefresh = [];
        }.bind(this);
        /////////////////////////////////////////////////////////////////////////////////
    },

    /**
     * Initialisation block. It has all children web components already initialised.
     */
    ready: function () {
        this.classList.add("canLeave");
        this._defaultPropertyActionAttrs = {currentState: "EDIT", centreUuid: this.uuid};
        this.navigationPreAction = this.navigationPreAction.bind(this);

        //////////////////Event handler to determine centre visibility///////////////////
        const observableNodes = [this._dom().$.centreResultContainer, ...this._dom().$.alternativeViewSlot.assignedNodes({ flatten: true })];
        const observer = new IntersectionObserver((entries, observer) => {

            const anyViewVisibility = entries.some(entry => entry.intersectionRatio > 0);

            if (anyViewVisibility && !this._visible) {
                this._visible = true;
                if (this._pendingRefresh && !this._isEgiEditing) {
                    this.showRefreshToast();
                }
            } else if (!anyViewVisibility && this._visible) {
                this._visible = false;
                if (this._pendingRefresh && !this._isEgiEditing) {
                    this.hideRefreshToast();
                }
            }
            
        }, {
            root: document.documentElement
        });
        observableNodes.forEach(altView => {
            observer.observe(altView);
        });
{'fraction_non_alphanumeric': 0.12512051419389394, 'fraction_numerical': 0.0007498660953401178, 'mean_word_length': 1.6350550381033022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '3115635', 'n_tokens_mistral': 2311, 'n_tokens_neox': 2220, 'n_words': 587}