diff options
| author | Maximilian Hils <git@maximilianhils.com> | 2016-02-18 23:10:47 +0100 | 
|---|---|---|
| committer | Maximilian Hils <git@maximilianhils.com> | 2016-02-18 23:10:47 +0100 | 
| commit | 7c6bf7abb3c0e94f9c4dfa77fe0690fe11c6d4d3 (patch) | |
| tree | 3f583d91ff97924068f7017f770b710da2768abe /web/src/js/components/flowview/index.js | |
| parent | be02dd105b7803b7b2b6942f9d254539dfd6ba26 (diff) | |
| parent | 61cde30ef8410dc5400039eea5d312fabf3779a9 (diff) | |
| download | mitmproxy-7c6bf7abb3c0e94f9c4dfa77fe0690fe11c6d4d3.tar.gz mitmproxy-7c6bf7abb3c0e94f9c4dfa77fe0690fe11c6d4d3.tar.bz2 mitmproxy-7c6bf7abb3c0e94f9c4dfa77fe0690fe11c6d4d3.zip  | |
Merge pull request #964 from mitmproxy/flat-structure
Flat structure
Diffstat (limited to 'web/src/js/components/flowview/index.js')
| -rw-r--r-- | web/src/js/components/flowview/index.js | 127 | 
1 files changed, 127 insertions, 0 deletions
diff --git a/web/src/js/components/flowview/index.js b/web/src/js/components/flowview/index.js new file mode 100644 index 00000000..739a46dc --- /dev/null +++ b/web/src/js/components/flowview/index.js @@ -0,0 +1,127 @@ +var React = require("react"); +var _ = require("lodash"); + +var common = require("../common.js"); +var Nav = require("./nav.js"); +var Messages = require("./messages.js"); +var Details = require("./details.js"); +var Prompt = require("../prompt.js"); + + +var allTabs = { +    request: Messages.Request, +    response: Messages.Response, +    error: Messages.Error, +    details: Details +}; + +var FlowView = React.createClass({ +    mixins: [common.StickyHeadMixin, common.Navigation, common.RouterState], +    getInitialState: function () { +        return { +            prompt: false +        }; +    }, +    getTabs: function (flow) { +        var tabs = []; +        ["request", "response", "error"].forEach(function (e) { +            if (flow[e]) { +                tabs.push(e); +            } +        }); +        tabs.push("details"); +        return tabs; +    }, +    nextTab: function (i) { +        var tabs = this.getTabs(this.props.flow); +        var currentIndex = tabs.indexOf(this.getActive()); +        // JS modulo operator doesn't correct negative numbers, make sure that we are positive. +        var nextIndex = (currentIndex + i + tabs.length) % tabs.length; +        this.selectTab(tabs[nextIndex]); +    }, +    selectTab: function (panel) { +        this.replaceWith( +            "flow", +            { +                flowId: this.getParams().flowId, +                detailTab: panel +            } +        ); +    }, +    getActive: function(){ +        return this.getParams().detailTab; +    }, +    promptEdit: function () { +        var options; +        switch(this.getActive()){ +            case "request": +                options = [ +                    "method", +                    "url", +                    {text:"http version", key:"v"}, +                    "header" +                    /*, "content"*/]; +                break; +            case "response": +                options = [ +                    {text:"http version", key:"v"}, +                    "code", +                    "message", +                    "header" +                    /*, "content"*/]; +                break; +            case "details": +                return; +            default: +                throw "Unknown tab for edit: " + this.getActive(); +        } + +        this.setState({ +            prompt: { +                done: function (k) { +                    this.setState({prompt: false}); +                    if(k){ +                        this.refs.tab.edit(k); +                    } +                }.bind(this), +                options: options +            } +        }); +    }, +    render: function () { +        var flow = this.props.flow; +        var tabs = this.getTabs(flow); +        var active = this.getActive(); + +        if (!_.contains(tabs, active)) { +            if (active === "response" && flow.error) { +                active = "error"; +            } else if (active === "error" && flow.response) { +                active = "response"; +            } else { +                active = tabs[0]; +            } +            this.selectTab(active); +        } + +        var prompt = null; +        if (this.state.prompt) { +            prompt = <Prompt {...this.state.prompt}/>; +        } + +        var Tab = allTabs[active]; +        return ( +            <div className="flow-detail" onScroll={this.adjustHead}> +                <Nav ref="head" +                    flow={flow} +                    tabs={tabs} +                    active={active} +                    selectTab={this.selectTab}/> +                <Tab ref="tab" flow={flow}/> +                {prompt} +            </div> +        ); +    } +}); + +module.exports = FlowView;
\ No newline at end of file  | 
