view src/app/query-state.js @ 58:3b4046e0cc02 default

Merge from ng2-table branch. d7c947909ab888c013171b8c037e4f9fab30fe57
author casties
date Wed, 29 Mar 2017 17:19:12 +0200
parents
children
line wrap: on
line source

"use strict";
var query_step_1 = require('./query-step');
var query_mode_1 = require('./query-mode');
var QueryState = (function () {
    function QueryState() {
        this.steps = [];
    }
    /**
     * Sets the query state from a string.
     */
    QueryState.prototype.setStateFromString = function (newStateString) {
        try {
            // state string is json
            var newState = JSON.parse(newStateString);
            // state should be list of steps
            if (!Array.isArray(newState))
                return;
            var newSteps_1 = [];
            newState.forEach(function (elem) {
                // step is an array [mode, params]
                if (!Array.isArray(elem))
                    return;
                var mode = elem[0];
                // get QueryMode object
                var qm = query_mode_1.getQueryModeById(mode);
                var params = elem[1];
                if (qm != null && params != null) {
                    // construct QueryStep
                    var qs = new query_step_1.QueryStep(qm, params);
                    newSteps_1.push(qs);
                }
            });
            if (newSteps_1.length > 0) {
                // set new state
                this.steps = newSteps_1;
            }
        }
        catch (e) {
            console.error("Unable to set state from string: " + newStateString);
        }
    };
    QueryState.prototype.getNumSteps = function () {
        return this.steps.length;
    };
    /**
     * Returns the current query state as a string.
     */
    QueryState.prototype.getStateAsString = function () {
        var stateList = this.steps.map(function (qs) { return [qs.mode.id, qs.params]; });
        var stateStr = JSON.stringify(stateList);
        return stateStr;
    };
    /**
     * Returns the cypher query as text for display.
     */
    QueryState.prototype.getQueryText = function () {
        var text = this.resultCypherQuery;
        var hasParams = false;
        for (var k in this.cypherQueryParams) {
            if (!hasParams) {
                hasParams = true;
                text += '\n';
            }
            text += "[" + k + "='" + this.cypherQueryParams[k] + "'] ";
        }
        return text;
    };
    return QueryState;
}());
exports.QueryState = QueryState;
//# sourceMappingURL=query-state.js.map