index.js 1.81 KB
// import { InviteSignupController } from '/imports/client/views/invite/signup/index'
import _                                  from 'lodash';
import {
         composeWithTracker,
         compose,
         composeAll
       }                                  from 'react-komposer';
import { Loading }                        from '/imports/client/components/Loading';

import { Orgs }                           from '/imports/collections/orgs/index';
import { Users }                          from '/imports/collections/users/index';
import { Teachers }                       from '/imports/collections/teachers/index';
import { TeachersView }                   from './TeachersView';

const meteorTick = (props, onData) => {

  const handles = [
    Meteor.subscribe('users.current'),
    Meteor.subscribe('orgs.current')
  ];

  if(_.every(handles, (handle) => (handle.ready()) )) {
    const user = Users.current();
    const org = Orgs.current();
    teachers = Users.find({"role":"TEACHER"}).fetch() ? Users.find({"role":"TEACHER"}).fetch() : "";
    teachersData = Teachers.find().fetch() ? Teachers.find().fetch() : "";
    for(var i=0; i< teachers.length; i++){
      for(var j=0; j< teachers.length; j++){
        if(teachers[i]._id == teachersData[j].userId){
          teachers[i].class = teachersData[j].class;
          teachers[i].dob = teachersData[j].dob;
        }
      }
    }
    onData(null, {
      data: {
        user: user,
        org: org,
        teachersData: teachersData,
        teachers: teachers
      },
    });
  }

  return () => {
    _.each(handles, (handle) => handle.stop() );
  };
};


const reduxTick = (props, onData) => {
  onData(null, {
    data: {}
  });
};


export const teachersViewController = composeAll(
  composeWithTracker(meteorTick, Loading),
  compose(reduxTick, Loading),
)(TeachersView);