import AboutPage from "./pages/aboutpage.jsx"; import AggregatorPage from "./pages/aggregatorpage.jsx"; import HelpPage from "./pages/helppage.jsx"; import StatisticsPage from "./pages/statisticspage.jsx"; import ErrorPane from "./components/errorpane.jsx"; import Footer from "./components/footer.jsx"; import EmbeddedFooter from "./components/embeddedfooter.jsx"; import PropTypes from "prop-types"; import createReactClass from "create-react-class"; (function() { "use strict"; window.MyAggregator = window.MyAggregator || {}; var VERSION = window.MyAggregator.VERSION = "v.3.0.0-64"; var URLROOT = window.MyAggregator.URLROOT = window.location.pathname.substring(0, window.location.pathname.indexOf("/", 2)) || //window.location.pathname || "/Aggregator"; var PT = PropTypes; /** The FCS Aggregator UI is based on reactjs. - index.html: describes the general page structure, with a push-down footer; on that structure the Main and Footer components are plugged. - main.jsx: composes the simple top components (Main, AggregatorPage, HelpPage, AboutPage, StatisticsPage) in pages/ - pages/aggregatorpage.jsx: defines - the Corpora store of collections - the AggregatorPage component which deals with search and displays the search results - components/corpusview.jsx: defines the CorpusView, rendered when the user views the available collections - plus in components/: various general usage React components The top-most component, Main, tracks of the window's location URL and, depending on the value, renders various components inside its frame: - AggregatorPage is the view corresponding to the normal search UI (search bar and all) This is the most complex component. - HelpPage renders the help page - AboutPage renders the about page - StatisticsPage renders the stats page - another URL, /Aggregator/embed, determines Main and AggregatorPage to render just the search bar. The embedded view is supposed to work like a YouTube embedded clip. */ var Main = createReactClass({ // fixme! - class Main extends React.Component { componentWillMount: function() { routeFromLocation.bind(this)(); }, getInitialState: function () { return { navbarCollapse: false, navbarPageFn: this.renderAggregator, errorMessages: [], }; }, error: function(errObj) { var err = ""; if (typeof errObj === 'string' || errObj instanceof String) { err = errObj; } else if (typeof errObj === 'object' && errObj.statusText) { console.log("ERROR: jqXHR = ", errObj); err = errObj.statusText; } else { return; } var that = this; var errs = this.state.errorMessages.slice(); errs.push(err); this.setState({errorMessages: errs}); setTimeout(function() { var errs = that.state.errorMessages.slice(); errs.shift(); that.setState({errorMessages: errs}); }, 10000); }, ajax: function(ajaxObject) { var that = this; if (!ajaxObject.error) { ajaxObject.error = function(jqXHR, textStatus, error) { if (jqXHR.readyState === 0) { that.error("Network error, please check your internet connection"); } else if (jqXHR.responseText) { that.error(jqXHR.responseText + " ("+error+")"); } else { that.error(error + " ("+textStatus+")"); } console.log("ajax error, jqXHR: ", jqXHR); }; } // console.log("ajax", ajaxObject); jQuery.ajax(ajaxObject); }, toggleCollapse: function() { this.setState({navbarCollapse: !this.state.navbarCollapse}); }, renderAggregator: function() { return ; }, renderHelp: function() { return ; }, renderAbout: function() { return ; }, renderStatistics: function() { return ; }, renderEmbedded: function() { return ; }, getPageFns: function() { return { '': this.renderAggregator, 'help': this.renderHelp, 'about': this.renderAbout, 'stats': this.renderStatistics, 'embed': this.renderEmbedded, }; }, gotoPage: function(doPushHistory, pageFnName) { var pageFn = this.getPageFns()[pageFnName]; if (this.state.navbarPageFn !== pageFn) { if (doPushHistory) { window.history.pushState({page:pageFnName}, '', URLROOT+"/"+pageFnName); } this.setState({navbarPageFn: pageFn}); console.log("new page: " + document.location + ", name: " + pageFnName); } }, toAggregator: function(doPushHistory) { this.gotoPage(doPushHistory, ''); }, toHelp: function(doPushHistory) { this.gotoPage(doPushHistory, 'help'); }, toAbout: function(doPushHistory) { this.gotoPage(doPushHistory, 'about'); }, toStatistics: function(doPushHistory) { this.gotoPage(doPushHistory, 'stats'); }, toEmbedded: function(doPushHistory) { this.gotoPage(doPushHistory, 'embed'); }, renderLogin: function() { return false; // return
  • // LOGIN //
  • ; }, renderCollapsible: function() { var classname = "navbar-collapse collapse " + (this.state.navbarCollapse?"in":""); return (
    • {this.renderLogin()}
    ); }, renderTop: function() { if (this.state.navbarPageFn === this.renderEmbedded) { return false; } return (
    Content Search
    {this.renderCollapsible()}
    ); }, render: function() { return (
    { this.renderTop() }
    {this.state.navbarPageFn()}
    ); } }); // StatisticsPage // HelpPage // AboutPage // Footer // EmbeddedFooter function isEmbeddedView() { var path = window.location.pathname.split('/'); return (path.length >= 3 && path[path.length - 1] === 'embed'); } function endsWith(str, suffix) { return str.indexOf(suffix, str.length - suffix.length) !== -1; } var routeFromLocation = function() { console.log("routeFromLocation: " + document.location); if (!this) throw "routeFromLocation must be bound to main"; var path = window.location.pathname.split('/'); console.log("path: " + path); if (path.length >= 3) { var p = path[path.length - 1]; if (p === 'help') { this.toHelp(false); } else if (p === 'about') { this.toAbout(false); } else if (p === 'stats') { this.toStatistics(false); } else if (p === 'embed') { this.toEmbedded(false); } else { this.toAggregator(false); } } else { this.toAggregator(false); } }; var main = ReactDOM.render(
    , document.getElementById('body')); if (!isEmbeddedView()) { ReactDOM.render(