<commit_before>/**
 * Created by i061485 on 6/10/14.
 */

define([], function defineRouter() {

    /**
     * Define router
     * class Router
     * @constructor
     */
    var Router = function Router() {

    };

    return Router.extend('Router', {

        /**
         * Get Hash location
         * @member Router
         * @returns {string}
         */
        getHashLocation: function getHashLocation() {
            return window.location.hash;
        },

        /**
         * Set Hash location
         * @member Router
         */
        setHashLocation: function setHashLocation(hash) {
            window.location.hash = hash;
        },

        /**
         * Set page by hash location
         * @member Router
         * @param {Page} page
         */
        setPageByHashLocation: function setPageByHashLocation(page) {

            /**
             * Define hash
             * @type {*|String|string}
             */
            var hash = this.getItemIdentity(page) || '';

            this.setHashLocation(hash);
        },

        /**
         * Define hash page matcher
         * @member Router
         * @returns {Array|{index: number, input: string}}
         */
        isPageMatch2Hash: function isPageMatch2Hash() {
            return this.getHashLocation().match(/#\/([^+(\/)]*):?/i);
        },

        /**
         * Define hash widget matcher
         * @member Router
         * @returns {Array|{index: number, input: string}}
         */
        isWidgetMatch2Hash: function isWidgetMatch2Hash() {
            return this.getHashLocation().match(/#\/([^+]*)\/([^+]*):?/i);
        },

        /**
         * Get page by hash
         * @member Router
         * @param {Workspace} workspace
         * @returns {Page}
         */
        getPageByHashLocation: function getPageByHashLocation(workspace) {

            /**
             * Match regex
             * @type {Array|{index: number, input: string}|*}
             */
            var pageMatch = this.isPageMatch2Hash();

            /**
             * Get workspace
             * @type {Workspace}
             */
            workspace = workspace || this.getWorkspace();

            /**
             * Get current page
             * @type {Page}
             */
            var currentPage = workspace.controller.getCurrentItem();

            /**
             * Get page
             * @type {Page}
             */
            var page = pageMatch ?
                (workspace.model.getItemByTitle(pageMatch[1]) ||
                workspace.model.getItemByUUID(pageMatch[1])) :
                currentPage;

            if (typeof(page) === 'undefined') {

                workspace.observer.publish(
                    workspace.eventmanager.eventList.switchToPage,
                    currentPage
                );

                /**
                 * Define page as current
                 * @type {Page}
                 */
                page = currentPage;
            }

            return page;
        },

        /**
         * Get widget by hash
         * @member Router
         * @param {Page} page
         * @returns {Widget|*}
         */
        getWidgetByHashLocation: function getWidgetByHashLocation(page) {

            /**
             * Match regex
             * @type {Array|{index: number, input: string}}
             */
            var widgetMatch = this.isWidgetMatch2Hash();

            /**
             * Get widget
             * @type {*|Widget}
             */
            var widget = widgetMatch ?
                (page.model.getItemByTitle(widgetMatch[2]) ||
                page.model.getItemByUUID(widgetMatch[2])) :
                null;

            return widget;
        },

        /**
         * Update hash on widget maximize
         * @member Router
         * @param {Widget} widget
         */
        updateHashOnMaximize: function updateHashOnMaximize(widget) {

            /**
             * Get hash location
             * @type {string}
             */
            var hash = this.controller.getItemIdentity(
                widget.controller.getContainment()
            );

            this.controller.setHashLocation(
                ''.concat(
                    hash, '/',
                    this.controller.getItemIdentity(widget)
                )
            );
        },

        /**
         * Update hash on widget reduce
         * @member Router
         * @param {Widget} widget
         */
        updateHashOnReduce: function updateHashOnReduce(widget) {

            /**
             * Get workspace
             * @type {Workspace}
             */
            var workspace = this.controller.getWorkspace();

            /**
             * Get page
             * @type {Page}
             */
            var page = this.controller.getPageByHashLocation.bind(
                workspace.controller
            )(workspace);

            this.controller.setPageByHashLocation(page);
        },

        /**
         * Get item identity<commit_msg>cont maximize hash<commit_after>/**
 * Created by i061485 on 6/10/14.
 */

define([], function defineRouter() {

    /**
     * Define router
     * class Router
     * @constructor
     */
    var Router = function Router() {

    };

    return Router.extend('Router', {

        /**
         * Get Hash location
         * @member Router
         * @returns {string}
         */
        getHashLocation: function getHashLocation() {
            return window.location.hash;
        },

        /**
         * Set Hash location
         * @member Router
         */
        setHashLocation: function setHashLocation(hash) {
            window.location.hash = hash;
        },

        /**
         * Set page by hash location
         * @member Router
         * @param {Page} page
         */
        setPageByHashLocation: function setPageByHashLocation(page) {

            /**
             * Define hash
             * @type {*|String|string}
             */
            var hash = this.getItemIdentity(page) || '';

            this.setHashLocation(hash);
        },

        /**
         * Define hash page matcher
         * @member Router
         * @returns {Array|{index: number, input: string}}
         */
        isPageMatch2Hash: function isPageMatch2Hash() {
            return this.getHashLocation().match(/#\/([^+(\/)]*):?/i);
        },

        /**
         * Define hash widget matcher
         * @member Router
         * @returns {Array|{index: number, input: string}}
         */
        isWidgetMatch2Hash: function isWidgetMatch2Hash() {
            return this.getHashLocation().match(/#\/([^+]*)\/([^+]*):?/i);
        },

        /**
         * Get page by hash
         * @member Router
         * @param {Workspace} workspace
         * @returns {Page}
         */
        getPageByHashLocation: function getPageByHashLocation(workspace) {

            /**
             * Match regex
             * @type {Array|{index: number, input: string}|*}
             */
            var pageMatch = this.isPageMatch2Hash();

            /**
             * Get workspace
             * @type {Workspace}
             */
            workspace = workspace || this.getWorkspace();

            /**
             * Get current page
             * @type {Page}
             */
            var currentPage = workspace.controller.getCurrentItem();

            /**
             * Get page
             * @type {Page}
             */
            var page = pageMatch ?
                (workspace.model.getItemByTitle(pageMatch[1]) ||
                workspace.model.getItemByUUID(pageMatch[1])) :
                currentPage;

            if (typeof(page) === 'undefined') {

                workspace.observer.publish(
                    workspace.eventmanager.eventList.switchToPage,
                    currentPage
                );

                /**
                 * Define page as current
                 * @type {Page}
                 */
                page = currentPage;
            }

            return page;
        },

        /**
         * Get widget by hash
         * @member Router
         * @param {Page} page
         * @returns {Widget|*}
         */
        getWidgetByHashLocation: function getWidgetByHashLocation(page) {

            /**
             * Match regex
             * @type {Array|{index: number, input: string}}
             */
            var widgetMatch = this.isWidgetMatch2Hash();

            /**
             * Get widget
             * @type {*|Widget}
             */
            var widget = widgetMatch ?
                (page.model.getItemByTitle(widgetMatch[2]) ||
                page.model.getItemByUUID(widgetMatch[2])) :
                null;

            return widget;
        },

        /**
         * Update hash on widget maximize
         * @member Router
         * @param {Widget} widget
         */
        updateHashOnMaximize: function updateHashOnMaximize(widget) {

            /**
             * Get hash location
             * @type {string}
             */
            var hash = this.controller.getItemIdentity(
                widget.controller.getContainment()
            );

            this.controller.setHashLocation(
                ''.concat(
                    '/', hash, '/',
                    this.controller.getItemIdentity(widget)
                )
            );
        },

        /**
         * Update hash on widget reduce
         * @member Router
         * @param {Widget} widget
         */
        updateHashOnReduce: function updateHashOnReduce(widget) {

            /**
             * Get workspace
             * @type {Workspace}
             */
            var workspace = this.controller.getWorkspace();

            /**
             * Get page
             * @type {Page}
             */
            var page = this.controller.getPageByHashLocation.bind(
                workspace.controller
            )(workspace);

            this.controller.setPageByHashLocation(page);
        },

        /**
         * Get item identity
{'fraction_non_alphanumeric': 0.11221056797941817, 'fraction_numerical': 0.004155946962200673, 'mean_word_length': 1.1938354677664424, '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': '6537967', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2470, 'n_words': 511}