Skip to content

Commit

Permalink
Prepping to merge with backend again
Browse files Browse the repository at this point in the history
  • Loading branch information
Vino4 committed Jun 5, 2017
1 parent bc009d4 commit e5a77cb
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 34 deletions.
12 changes: 7 additions & 5 deletions server/models/Participant.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ const ParticipantSchema = new Schema({
required: true,
},

// _creator: {
// type: Schema.ObjectId,
// ref: 'User',
// required: true,
// },
_creator: {
type: Schema.ObjectId,
ref: 'User',
required: true,
},

_activity :{
type: Schema.ObjectId,
Expand Down Expand Up @@ -77,7 +77,9 @@ ParticipantSchema.pre('save', function(next){

ParticipantSchema.methods.getPublicFields = function () {
return {
_id: this._id,
name: this.name,
email: this.email,
image: this.image,
groupNumber: this.groupNumber,
surveyResponses: this.surveyResponses,
Expand Down
3 changes: 1 addition & 2 deletions src/routes/Activity/components/ActivityView.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class ActivityView extends React.Component {
})
}
this.props.participants.forEach((participant) => {
console.log(participant);
let participantGroupNumber = participant.get('groupNumber');
if (participantGroupNumber >= 0 && participantGroupNumber < numOfGroups) {
groups[participantGroupNumber].participants.push(participant);
Expand All @@ -68,7 +67,6 @@ export class ActivityView extends React.Component {
};

let getGroupCards = (groups) => {
console.log(this.props.activityId)
return (
groups.map(
(group, i) => (
Expand All @@ -94,6 +92,7 @@ export class ActivityView extends React.Component {
<ParticipantListSidebar
key={"ParticipantListSidebar_" + this.props.participants.size}
participants={ this.props.participants }
setCurrentlySelected={(v) => {console.log(v)}}
updateParticipantGroupNumber={ this.props.updateParticipantGroupNumber }
activityId={ this.props.activityId }
/>
Expand Down
32 changes: 21 additions & 11 deletions src/routes/Activity/components/GroupCard/GroupCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const transparentImage = 'https://upload.wikimedia.org/wikipedia/commons/thumb/0

const participantCardItemSource = {
beginDrag(props) {
console.log(props);
props.setCurrentlySelected(props.participant.participantId) // set current selected card
return {
participantId: props.participant.participantId,
oldGroupNumber: props.participant.groupNumber
participantId: props.participant.get('participantId'),
oldGroupNumber: props.participant.get('groupNumber')
}
}
}
Expand All @@ -37,14 +38,14 @@ class DraggableCard extends React.Component {
let participantCard =
<div className="card" style={ {cursor: this.props.unlocked ? 'not-allowed' : 'default'} }>
<ParticipantProfilePopup
trigger={ <Image src={ (isDragging) ? transparentImage : participant.image }/> }
trigger={ <Image src={ (isDragging) ? transparentImage : participant.get('image') }/> }
position="top right"
offset={ 0 }
name={ participant.name }
image={ participant.image }
surveyResponses={ this.props.surveyResponses }
groupNumber={participant.groupNumber }
participantId={ participant.participantId }/>
name={ participant.get('name') }
image={ participant.get('image') }
surveyResponses={ participant.get('surveyResponses') }
groupNumber={participant.get('groupNumber') }
participantId={ participant.get('participantId') }/>
</div>
if (this.props.unlocked) {
return ( participantCard )
Expand Down Expand Up @@ -94,7 +95,7 @@ class GroupCard extends React.Component {
const {connectDropTarget, isOver} = this.props

let generateEmptySpots = () => {
let emptyNum = this.props.capacity - this.props.participants.size
let emptyNum = this.props.capacity - this.props.participants.length
let result = []
for (let i = 0; i < emptyNum; i++) {
result.push(
Expand Down Expand Up @@ -161,12 +162,21 @@ class GroupCard extends React.Component {
Group { this.props.groupNumber } &nbsp;
</Label>
<Card.Group itemsPerRow={ this.props.itemsPerRow} stackable>

{ this.props.participants.map((participant) =>
<DraggableCard
participant={ participant }
key={ participant.participantId }
setCurrentlySelected={ (v) => console.log(v) }
unlocked= { this.props.unlocked }
/>
)}
{ generateEmptySpots() }
</Card.Group>

<Label color={ pickCapacityLabelColor(this.props.participants.size, this.props.capacity) }
<Label color={ pickCapacityLabelColor(this.props.participants.length, this.props.capacity) }
attached="top right">
<Icon name='user'/> { this.props.participants.size} / { this.props.capacity }
<Icon name='user'/> { this.props.participants.length} / { this.props.capacity }
</Label>
</Segment>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Participant extends React.Component {
name={ this.props.name }
image={ this.props.image }
surveyResponses={ this.props.surveyResponses }
setCurrentlySelected={(v) => {console.log(v)}}
participantId={ this.props.participantId }
setCurrentlySelected={(v) => {console.log(v)}}/>
)
Expand All @@ -77,6 +78,7 @@ class Participant extends React.Component {
name={ this.props.name }
image={ this.props.image }
surveyResponses={ this.props.surveyResponses }
setCurrentlySelected={(v) => {console.log(v)}}
groupNumber={ this.props.groupNumber }
position="right center"
offset={ 20 }
Expand Down Expand Up @@ -147,6 +149,7 @@ class ParticipantListSidebar extends React.Component {
participantId={ participantObj.get('participantId') }
surveyResponses={ participantObj.get('surveyResponses') }
name={ participantObj.get('name') }
setCurrentlySelected={(v) => {console.log(v)}}
image={ participantObj.get('image') }
groupNumber={ participantObj.get('groupNumber') }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ let updateParticipantGroupNumber = (dispatch) => {
oldGroupNumber: oldGroupNumber,
newGroupNumber: newGroupNumber
};

console.log('-------------------------------');
console.log({groupNumber:payload.newGroupNumber});
dispatch({
type: UPDATE_PARTICIPANT_GROUP_NUMBER,
payload: payload
});

let url = SERVER_URL + "/api/activities/" + activityId + "/participants/" + participantId;
axios.put(url, {
oldGroupsNumber: oldGroupNumber,
newGroupNumber: newGroupNumber
})
let url = SERVER_URL + "/api/activities/" + activityId + "/participants/" + participantId + '/groupNumber';
axios.put(url, {groupNumber:payload.newGroupNumber})
.then((response) => {
dispatch(updateParticipantGroupNumberSuccess(response));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ let handleUpdateParticipantGroupsNumber = (state, payload) => {
console.log(state)
let index = state.get('participants')
.findIndex((participant) => (participant.get('participantId') === payload.participantId))
console.log(payload.participantId)
console.log(index)
let newState = ((index == -1) ?
state.setIn(['participants', index], payload.newGroupNumber)
state
:
state)
state.setIn(['participants', index, 'groupNumber'], payload.newGroupNumber))

return newState;
};
Expand Down
11 changes: 3 additions & 8 deletions src/store/createStore.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {applyMiddleware, compose, createStore} from 'redux'
import { applyMiddleware, compose, createStore } from 'redux'
import thunk from 'redux-thunk'
import baseHistory from './baseHistory'
import makeRootReducer from './reducers'
import { updateLocation } from './location'
import { routerMiddleware } from 'react-router-redux'
import { browserHistory } from 'react-router'
import Immutable from 'immutable';

export default (initialState = {}) => {
// ======================================================
Expand Down Expand Up @@ -34,13 +35,6 @@ export default (initialState = {}) => {
}
}

// ======================================================
// Store Instantiation and HMR Setup
if (typeof composeWithDevToolsExtension === 'function') {
composeEnhancers = composeWithDevToolsExtension
}
}

// ======================================================
// Store Instantiation and HMR Setup
// ======================================================
Expand Down Expand Up @@ -68,3 +62,4 @@ export default (initialState = {}) => {

return store
}

74 changes: 74 additions & 0 deletions src/store/createStore.js.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { applyMiddleware, compose, createStore } from 'redux'
import thunk from 'redux-thunk'
import baseHistory from './baseHistory'
import makeRootReducer from './reducers'
<<<<<<< HEAD
import {updateLocation} from './location'
import Immutable from 'immutable';

import generateUsers from "../routes/Activity/modules/UserGenerator"
=======
import { updateLocation } from './location'
import { routerMiddleware } from 'react-router-redux'
import { browserHistory } from 'react-router'
>>>>>>> fix-login

export default (initialState = {}) => {
// ======================================================
// Middleware Configuration
// ======================================================

// ======================================================
// Store Enhancers
// ======================================================

/* create routing middleware */
const routingMiddleware = routerMiddleware(baseHistory)

const middleware = [thunk]
const enhancers = []

let composeEnhancers = compose

if (__DEV__) {
<<<<<<< HEAD
const composeWithDevToolsExtension = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
serialize: {
immutable: Immutable
}
});
=======
const composeWithDevToolsExtension = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
>>>>>>> fix-login
if (typeof composeWithDevToolsExtension === 'function') {
composeEnhancers = composeWithDevToolsExtension
}
}

// ======================================================
// Store Instantiation and HMR Setup
// ======================================================
const store = createStore(
makeRootReducer(),
initialState,
composeEnhancers(
applyMiddleware(routingMiddleware),
applyMiddleware(...middleware),
...enhancers
)
)

store.asyncReducers = {}

// To unsubscribe, invoke `store.unsubscribeHistory()` anytime
// store.unsubscribeHistory = browserHistory.listen(updateLocation(store))

if (module.hot) {
module.hot.accept('./reducers', () => {
const reducers = require('./reducers').default
store.replaceReducer(reducers(store.asyncReducers))
})
}

return store
}

0 comments on commit e5a77cb

Please sign in to comment.