<commit_before>'use strict';

var _      = require('lodash');
var React  = require('react');
var Reflux = require('reflux');
var page   = require('page');
var moment = require('moment');

var api           = require('data/api');
var dashboardInit = require('data/dashboardInit');

var TitleMenu           = require('component/TitleMenu.jsx');
var RegionTitleMenu     = require('component/RegionTitleMenu.jsx');
var CampaignTitleMenu   = require('component/CampaignTitleMenu.jsx');
var MenuItem            = require('component/MenuItem.jsx');

var CustomDashboard     = require('dashboard/CustomDashboard.jsx');

var DashboardStore      = require('stores/DashboardStore');
var GeoStore            = require('stores/GeoStore');
var IndicatorStore      = require('stores/IndicatorStore');
var NavigationStore     = require('stores/NavigationStore');

var AppActions          = require('actions/AppActions');
var DashboardActions    = require('actions/DashboardActions');
var DataActions         = require('actions/DataActions');
var GeoActions          = require('actions/GeoActions');

var LAYOUT = {
  'Management Dashboard'    : require('dashboard/ManagementDashboard.jsx'),
  'NGA Campaign Monitoring' : require('dashboard/NCODashboard.jsx'),
  'District Dashboard'      : require('dashboard/District.jsx'),
  'Source Data'             : require('dashboard/SourceDataDashboard.jsx'),
  'ODK Dashboard'             : require('dashboard/ODKDashboard.jsx'),
};

var Dashboard = React.createClass({

  mixins : [
    Reflux.ListenerMixin,
    Reflux.connect(require('stores/DataStore'))
  ],

  getInitialState : function () {
    return {
      regions      : [],
      campaigns    : [],
      region       : null,
      campaign     : null,
      dashboard    : null,
    };
  },

  componentWillMount : function () {
    page('/datapoints/:dashboard/:year/:month/:region_id/:doc_tab/:doc_id', this._showSourceData);
    page('/datapoints/:dashboard/:year/:month/:region_id', this._show);
    page('/datapoints/:dashboard', this._showDefault);
    AppActions.init()
  },

  componentWillUpdate : function (nextProps, nextState) {
    if (!(nextState.campaign && nextState.region && nextState.dashboard)) {
      return;
    }

    var campaign = moment(nextState.campaign.start_date).format('MM/YYYY')
    var title = [
      nextState.dashboard.title,
      [nextState.region.name, campaign].join(' '),
      'RhizomeDB'
    ].join(' - ');

    if (document.title !== title) {
      document.title = title;
    }
  },

  render : function () {

    if (!(this.state.loaded && this.state.dashboard)) {
      var style = {
        fontSize      : '2rem',
      };

      return (
        <div style={style} className='overlay'>
          <div>
            <div><i className='fa fa-spinner fa-spin'></i>&ensp;Loading</div>
          </div>
        </div>
      );
    }

    var region = this.state.region;

    console.log('region in render.. this.state.region')
    console.log(region)

    var campaign      = this.state.campaign;
    var dashboardDef  = this.state.dashboard;
    var loading       = this.state.loading;
    var dashboardName = _.get(dashboardDef, 'title', '');
    var doc_id        = this.state.doc_id;
    var doc_tab        = this.state.doc_tab;

    var indicatorIds = _(_.get(dashboardDef, 'charts', []))
      .pluck('indicators')
      .flatten()
      .uniq()
      .value()

    var indicators = IndicatorStore.getById.apply(indicatorIds);
    // var indicators = IndicatorStore.getById();
    // var indicators = []
    var data = dashboardInit(
      dashboardDef,
      this.state.data,
      region,
      campaign,
      this.state.regions,
      indicators,
      GeoStore.features
    );

    console.log('== DATA ===')
    console.log(data)
    console.log('===')

    var dashboardProps = {
      campaign   : campaign,
      dashboard  : dashboardDef,
      data       : data,
      indicators : indicators,
      loading    : loading,<commit_msg>get the campaign monitoring data to render after setting regions = this.state.dashboard.regions<commit_after>'use strict';

var _      = require('lodash');
var React  = require('react');
var Reflux = require('reflux');
var page   = require('page');
var moment = require('moment');

var api           = require('data/api');
var dashboardInit = require('data/dashboardInit');

var TitleMenu           = require('component/TitleMenu.jsx');
var RegionTitleMenu     = require('component/RegionTitleMenu.jsx');
var CampaignTitleMenu   = require('component/CampaignTitleMenu.jsx');
var MenuItem            = require('component/MenuItem.jsx');

var CustomDashboard     = require('dashboard/CustomDashboard.jsx');

var DashboardStore      = require('stores/DashboardStore');
var GeoStore            = require('stores/GeoStore');
var IndicatorStore      = require('stores/IndicatorStore');
var NavigationStore     = require('stores/NavigationStore');

var AppActions          = require('actions/AppActions');
var DashboardActions    = require('actions/DashboardActions');
var DataActions         = require('actions/DataActions');
var GeoActions          = require('actions/GeoActions');

var LAYOUT = {
  'Management Dashboard'    : require('dashboard/ManagementDashboard.jsx'),
  'NGA Campaign Monitoring' : require('dashboard/NCODashboard.jsx'),
  'District Dashboard'      : require('dashboard/District.jsx'),
  'Source Data'             : require('dashboard/SourceDataDashboard.jsx'),
  'ODK Dashboard'             : require('dashboard/ODKDashboard.jsx'),
};

var Dashboard = React.createClass({

  mixins : [
    Reflux.ListenerMixin,
    Reflux.connect(require('stores/DataStore'))
  ],

  getInitialState : function () {
    return {
      regions      : [],
      campaigns    : [],
      region       : null,
      campaign     : null,
      dashboard    : null,
    };
  },

  componentWillMount : function () {
    page('/datapoints/:dashboard/:year/:month/:region_id/:doc_tab/:doc_id', this._showSourceData);
    page('/datapoints/:dashboard/:year/:month/:region_id', this._show);
    page('/datapoints/:dashboard', this._showDefault);
    AppActions.init()
  },

  componentWillUpdate : function (nextProps, nextState) {
    if (!(nextState.campaign && nextState.region && nextState.dashboard)) {
      return;
    }

    var campaign = moment(nextState.campaign.start_date).format('MM/YYYY')
    var title = [
      nextState.dashboard.title,
      [nextState.region.name, campaign].join(' '),
      'RhizomeDB'
    ].join(' - ');

    if (document.title !== title) {
      document.title = title;
    }
  },

  render : function () {

    if (!(this.state.loaded && this.state.dashboard)) {
      var style = {
        fontSize      : '2rem',
      };

      return (
        <div style={style} className='overlay'>
          <div>
            <div><i className='fa fa-spinner fa-spin'></i>&ensp;Loading</div>
          </div>
        </div>
      );
    }

    var region = this.state.region;
    var regions = this.state.dashboard.regions
    console.log('regions')
    console.log(region)

    var campaign      = this.state.campaign;
    var dashboardDef  = this.state.dashboard;
    var loading       = this.state.loading;
    var dashboardName = _.get(dashboardDef, 'title', '');
    var doc_id        = this.state.doc_id;
    var doc_tab        = this.state.doc_tab;

    var indicatorIds = _(_.get(dashboardDef, 'charts', []))
      .pluck('indicators')
      .flatten()
      .uniq()
      .value()

    var indicators = IndicatorStore.getById.apply(indicatorIds);
    // var indicators = IndicatorStore.getById();
    // var indicators = []
    var data = dashboardInit(
      dashboardDef,
      this.state.data,
      region,
      campaign,
      regions,
      indicators,
      GeoStore.features
    );

    console.log('== DATA ===')
    console.log(data)
    console.log('===')

    var dashboardProps = {
      campaign   : campaign,
      dashboard  : dashboardDef,
      data       : data,
      indicators : indicators,
      loading    : loading,
{'fraction_non_alphanumeric': 0.14072970960536113, 'fraction_numerical': 0.0002482005460412013, 'mean_word_length': 2.7379406307977736, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '4986020', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2407, 'n_words': 445}