import './sequence'; import React from 'react'; import _ from 'underscore'; import showErrorModal from './error_modal'; /** * Takes sequence accession as props, fetches the sequence from the server, and * displays it in a modal. */ export default class SequenceModal extends React.Component { constructor(props) { super(props); this.state = { error_msgs: [], sequences: [], requestCompleted: false }; } // Lifecycle methods. // render () { return (

View sequence

{ this.state.requestCompleted && this.resultsJSX() || this.loadingJSX() }
); } /* * Returns jQuery reference to the main modal container. */ modal () { return $(React.findDOMNode(this.refs.modal)); } /** * Shows sequence viewer. */ show (url) { this.setState({requestCompleted: false}, () => { this.modal().modal('show'); this.loadJSON(url); }); } /** * Loads sequence using AJAX and updates modal state. */ loadJSON (url) { // Fetch sequence and update state. $.getJSON(url) .done(_.bind(function (response) { this.setState({ sequences: response.sequences, error_msgs: response.error_msgs, requestCompleted: true }); }, this)) .fail(function (jqXHR, status, error) { showErrorModal(jqXHR, function () { this.hide(); }); }); } resultsJSX () { return (
{ _.map(this.state.error_msgs, _.bind(function (error_msg) { return (

{error_msg[0]}

                                        {error_msg[1]}
                                    
); }, this)) } { _.map(this.state.sequences, _.bind(function (sequence) { return (); }, this)) }
); } loadingJSX () { return (
); } } class SequenceViewer extends React.Component { /** * The CSS class name that will be assigned to the widget container. ID * assigned to the widget container is derived from the same. */ static widgetClass () { return 'biojs-vis-sequence'; } render () { this.widgetID = this.widgetClass + '-' + (new Date().getUTCMilliseconds()); return (

{this.props.sequence.id}   {this.props.sequence.title}

); } componentDidMount () { // attach BioJS sequence viewer var widget = new Sequence({ sequence: this.props.sequence.value, target: this.widgetID, format: 'PRIDE', columns: { size: 40, spacedEach: 0 }, formatOptions: { title: false, footer: false } }); widget.hideFormatSelector(); } }