diff --git a/app/components/addeventdialog.jsx b/app/components/addeventdialog.jsx
index bb5fecc..fe3b087 100644
--- a/app/components/addeventdialog.jsx
+++ b/app/components/addeventdialog.jsx
@@ -3,34 +3,69 @@ import React from 'react';
import { Dialog, Input, Dropdown, DatePicker, TimePicker } from 'react-toolbox';
export default class AddEventDialog extends React.Component {
- constructor(props) {
- super(props);
+ constructor(props, context) {
+ super(props, context);
const now = new Date();
this.state = {
group: null,
name: '',
start: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 8),
end: new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 10),
- groups: [
- { value: 1, label: 'M17502' },
- { value: 2, label: 'Infocomm Club' },
- { value: 3, label: 'Youth Flying Club', disabled: true },
- { value: 4, label: 'Engineering Intrest Group' },
- ],
+ groups: [],
};
this.handleGroupChange = this.handleGroupChange.bind(this);
this.handleNameChange = this.handleNameChange.bind(this);
this.handleStartChange = this.handleStartChange.bind(this);
this.handleEndChange = this.handleEndChange.bind(this);
+ this.addEvent = this.addEvent.bind(this);
this.actions = [
{ label: 'Cancel', onClick: this.props.onCancel, accent: true },
{ label: 'Add', onClick: this.addEvent, accent: true },
];
- // pull user groups, together with the relationship attribute role
- // put user groups into state.groups, disabling those not admin
+ this.fetchGroups(context);
+ }
+
+ fetchGroups(context = this.context) {
+ return fetch(`/api/v1/schools/${context.user.school}/users/${context.user.id}/groups/`, {
+ headers: {
+ FakeAuth: true,
+ FakeID: context.user.id,
+ },
+ })
+ .then(data => data.json())
+ .then((data) => {
+ this.setState({
+ groups: data.map(g => ({ value: g.id, label: g.name })),
+ });
+ })
+ .catch((err) => {
+ console.error(err);
+ });
+ }
+
+ addEvent() {
+ const method = 'POST';
+ const headers = new Headers();
+ headers.append('FakeAuth', 'true');
+ headers.append('FakeID', this.context.user.id);
+ headers.append('Content-Type', 'application/json');
+ const body = JSON.stringify({
+ name: this.state.name,
+ start: this.state.start,
+ end: this.state.end,
+ });
+ fetch(`/api/v1/schools/${this.context.user.school}/groups/${this.state.group}/eventsOnce/`, {
+ method, headers, body,
+ })
+ .then(() => {
+ this.props.onDone();
+ })
+ .catch((err) => {
+ console.error(err);
+ });
}
handleGroupChange(value) {
@@ -124,6 +159,7 @@ export default class AddEventDialog extends React.Component {
AddEventDialog.propTypes = {
onCancel: React.PropTypes.func.isRequired,
+ onDone: React.PropTypes.func.isRequired,
};
AddEventDialog.contextTypes = {
diff --git a/app/components/addgroupdialog.jsx b/app/components/addgroupdialog.jsx
index 44fc9a4..5202bc6 100644
--- a/app/components/addgroupdialog.jsx
+++ b/app/components/addgroupdialog.jsx
@@ -4,7 +4,7 @@ import { Dialog, Input, Autocomplete, Dropdown } from 'react-toolbox';
export default class AddGroupDialog extends React.Component {
constructor(props, context) {
- super(props);
+ super(props, context);
this.state = {
name: '',
members: [],
@@ -38,7 +38,7 @@ export default class AddGroupDialog extends React.Component {
const headers = new Headers();
headers.append('FakeAuth', 'true');
headers.append('FakeID', context.user.id);
- fetch(`/api/v1/schools/${context.user.school}/users`, {
+ fetch(`/api/v1/schools/${context.user.school}/users/`, {
headers,
})
.then(data => data.json())
@@ -69,7 +69,7 @@ export default class AddGroupDialog extends React.Component {
mentor_level: this.state.mentor_level,
mentor_year: this.state.mentor_year,
});
- fetch(`/api/v1/schools/${this.context.user.school}/groups`, {
+ fetch(`/api/v1/schools/${this.context.user.school}/groups/`, {
method, headers, body,
})
.then(() => {
diff --git a/app/pages/group.jsx b/app/pages/group.jsx
index ba88c22..1483e0b 100644
--- a/app/pages/group.jsx
+++ b/app/pages/group.jsx
@@ -4,14 +4,14 @@ import { List, ListSubHeader, ListItem } from 'react-toolbox';
export default class PageGroup extends React.Component {
constructor(props, context) {
- super(props);
+ super(props, context);
this.state = {
id: parseInt(props.match.params.id, 10),
group: {},
addGroupDialogActive: false,
};
- this.fetchGroup(context);
+ this.fetchGroup(context); // TODO: split into three backend calls
}
async fetchGroup(context = this.context) {
@@ -41,9 +41,9 @@ export default class PageGroup extends React.Component {
ripple
>
- {this.state.group.events && this.state.group.events.map(e => (
+ {this.state.group.eventsOnce && this.state.group.eventsOnce.map(e => (
diff --git a/app/pages/login.jsx b/app/pages/login.jsx
index 6100950..fe40eec 100644
--- a/app/pages/login.jsx
+++ b/app/pages/login.jsx
@@ -16,7 +16,7 @@ export default class PageLogin extends React.Component {
}
async fetchSchools() {
- return fetch('/api/v1/schools')
+ return fetch('/api/v1/schools/')
.then(data => data.json())
.then((data) => {
this.setState({
diff --git a/server/api.js b/server/api.js
index 365efaf..a858379 100644
--- a/server/api.js
+++ b/server/api.js
@@ -81,7 +81,7 @@ export default class API {
this.database.getUser(req.params.school, req.params.id)
.then((data) => {
res.json(Object.assign(data, {
- pwd: undefined,
+ pwd_hash: undefined,
oid_id: undefined,
}));
})
@@ -118,6 +118,22 @@ export default class API {
.catch(next);
});
+ // Events
+ this.router.post('/schools/:school/groups/:group/eventsOnce/', this.auth, (req, res, next) => {
+ this.database.createEventOnce(req.params.school, req.params.group, req.body)
+ .then((data) => {
+ res.json(data);
+ })
+ .catch(next);
+ });
+ this.router.get('/schools/:school/groups/:group/eventsOnce/:id', this.auth, (req, res, next) => {
+ this.database.getEventOnce(req.params.school, req.params.group, req.params.id)
+ .then((data) => {
+ res.json(data);
+ })
+ .catch(next);
+ });
+
this.router.use('/*', (req, res, next) => {
next(new NotFoundError());
});