Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
may-ben-arie committed Jan 20, 2019
2 parents 4f7d12e + 7a0fb34 commit 9059eee
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="loader"></div>
</div>
<div id="version">
Version 2.0.0 <br>
Version 2.0.1 <br>
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="glyphicon glyphicon-chevron-right"></span>
with <span class="glyphicon glyphicon-heart"></span> by Midburn Tech</div>
Expand Down
16 changes: 16 additions & 0 deletions server/models/TicketsAllocByRound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const TicketsAllocByRoundSchema = new Schema({
_id: String,
eventId: String,
startDate: Date,
endDate: Date,
based_event_id: String,
is_show: Boolean,
description: String
}, {_id: false, timestamps: {createdAt: 'createdAt', updatedAt: 'updatedAt'}});

const TicketsAlloc = mongoose.model('TicketsAlloc', TicketsAllocByRoundSchema);

module.exports = TicketsAlloc;
38 changes: 38 additions & 0 deletions server/routes/departmentForms.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require("express");
const router = express.Router();
const Department = require("../models/deparment");
const DepartmentForm = require("../models/departmentForms");
const DepartmentFormAnswer = require("../models/departmentFormsAnswers");
const co = require("co");
Expand Down Expand Up @@ -51,6 +52,43 @@ router.get("/public/departments/:departmentId/forms", co.wrap(function* (req, re
return res.json(departmentForm ? departmentForm.form : []);
}));

// MANAGER - Returns a depertment form - used to load previous year form
router.post("/departments/search-form", co.wrap(function* (req, res) {
if (!permissionsUtils.isManager(req.userDetails)) {
return res.status(403).json([{"error": "Action is not allowed - User doesn't have manager permissions"}]);
}

const eventId = req.body.eventId;
const nameEn = req.body.nameEn;
const nameHe = req.body.nameHe;

// search by en
let department = yield Department.findOne({
'basicInfo.nameEn': nameEn,
deleted: false,
eventId
});

// search by he
if (!department) {
department = yield Department.findOne({
'basicInfo.nameHe': nameHe,
deleted: false,
eventId
});
}

// not found
if (!department) {
return res.status(404).json([{"error": "not found"}]);
}

// get form
const departmentId = department._id;
const departmentForm = yield getDepartmentFrom(departmentId, eventId);
return res.json(departmentForm ? departmentForm.form : []);
}));

// MANAGER - Updates a depertment form
router.post("/departments/:departmentId/forms", co.wrap(function* (req, res) {
const eventId = req.userDetails.eventId;
Expand Down
10 changes: 6 additions & 4 deletions src/components/Admin/AdminView.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default class AdminView extends Component {
admins: [],
showAddAdminModal: false,
newAdminEmailInput: null,
generalForm: []
generalForm: [],
generalFormVersion: 0
};

this.handleOnFormSave = this.handleOnFormSave.bind(this);
Expand All @@ -34,7 +35,7 @@ export default class AdminView extends Component {
axios.get("/api/v1/permissions/admins")
.then(res => this.setState({admins: res.data}));
axios.get("/api/v1/public/form")
.then(res => this.setState({generalForm: res.data}));
.then(res => this.setState({generalForm: res.data, generalFormVersion: this.state.generalFormVersion+1}));
};

handleAddDepartment() {
Expand Down Expand Up @@ -72,7 +73,7 @@ export default class AdminView extends Component {

handleOnFormSave(form) {
axios.post("/api/v1/form", {form})
.then(res => this.setState({generalForm: res.data}))
.then(res => this.setState({generalForm: res.data, generalFormVersion: this.state.generalFormVersion+1}))
}

componentDidMount() {
Expand All @@ -93,7 +94,7 @@ export default class AdminView extends Component {
}

render() {
const {departments, generalForm, selectedDepartmentId, addDepartment} = this.state;
const {departments, generalForm, generalFormVersion, selectedDepartmentId, addDepartment} = this.state;

const selectedDepartment =
selectedDepartmentId &&
Expand Down Expand Up @@ -171,6 +172,7 @@ export default class AdminView extends Component {
<div className="card container">
<FormManager showPreview
questions={generalForm}
version={generalFormVersion}
onSave={this.handleOnFormSave}
/>
</div>
Expand Down
14 changes: 10 additions & 4 deletions src/components/Admin/EditDepartment.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import * as Permissions from "../../model/permissionsUtils";
import FormManager from "../FormManager/FormManager";


require('./EditDepartment.css');

const DEFAULT_LOGO = 'https://yt3.ggpht.com/-t7buXM4UqEc/AAAAAAAAAAI/AAAAAAAAAAA/n5U37nYuExw/s900-c-k-no-mo-rj-c0xffffff/photo.jpg';
Expand Down Expand Up @@ -50,6 +51,7 @@ export default class EditDepartment extends Component {
this.state = {
department: props.department || defaultDepartment,
departmentForm: [],
departmentFormVersion: 0,
volunteersAllocations: {},
hasChanges: false
};
Expand All @@ -64,7 +66,7 @@ export default class EditDepartment extends Component {
if (!this.state.department._id) return;

axios.get(`/api/v1/public/departments/${this.state.department._id}/forms`)
.then(res => this.setState({departmentForm: res.data}));
.then(res => this.setState({departmentForm: res.data, departmentFormVersion: this.state.departmentFormVersion+1}));

axios.get(`/api/v1/departments/${this.state.department._id}/volunteersAllocations`)
.then(res => this.setState({volunteersAllocations: res.data}));
Expand Down Expand Up @@ -132,7 +134,7 @@ export default class EditDepartment extends Component {

handleOnDepartmentFormSave(form) {
axios.post(`/api/v1/departments/${this.state.department._id}/forms`, {form})
.then(res => this.setState({departmentForm: res.data}));
.then(res => this.setState({departmentForm: res.data, departmentFormVersion: this.state.departmentFormVersion+1}));
}

delete = _ => {
Expand All @@ -149,7 +151,7 @@ export default class EditDepartment extends Component {
}

render() {
const {department, volunteersAllocations, departmentForm, hasChanges} = this.state;
const {department, volunteersAllocations, departmentForm, departmentFormVersion, hasChanges} = this.state;
const {basicInfo, status, allocationsDetails} = department;
const departmentLogo = basicInfo.imageUrl ? basicInfo.imageUrl : DEFAULT_LOGO;

Expand Down Expand Up @@ -274,7 +276,11 @@ export default class EditDepartment extends Component {
</FormGroup>
</Tab>
{department._id && <Tab eventKey={4} title="Join Form">
<FormManager questions={departmentForm} onSave={this.handleOnDepartmentFormSave}/>
<FormManager
questions={departmentForm}
version={departmentFormVersion}
department={department}
onSave={this.handleOnDepartmentFormSave}/>
</Tab>}
</Tabs>
</Modal.Body>
Expand Down
137 changes: 104 additions & 33 deletions src/components/FormEditor/FormEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,84 +8,151 @@ class FormEditor extends react.Component {
super(props);

this.state = {
questions: [...props.questions],
questions: props.questions,
hasChanges: false,
isVisible: props.isVisible
lastNotFound: false
};

this.handleOnAddQuestion = this.handleOnAddQuestion.bind(this);
this.handleOnQuestionChange = this.handleOnQuestionChange.bind(this);
this.handleOnQuestionTypeChange = this.handleOnQuestionTypeChange.bind(this);
this.deleteQuestion = this.deleteQuestion.bind(this);
this.handleOnOptionsChange = this.handleOnOptionsChange.bind(this);
this.lastEventID = this.lastEventID.bind(this);
this.loadLastForm = this.loadLastForm.bind(this);
}

componentWillReceiveProps(nextProps) {
this.setState({questions: [...nextProps.questions]});
componentDidUpdate(prevProps) {
if (prevProps.version !== this.props.version) {
this.setState({questions: [...this.props.questions]});
}
}

handleOnAddQuestion() {
this.setState({
hasChanges: true,
questions: [
...this.state.questions,
{
question: {
he: "",
en: ""
},
questionType: 'text',
options: [],
optional: true
lastEventID = () => {
if (document.events.events.length < 2) {
return null;
}
return document.events.events[document.events.events.length-2];
}

loadLastForm() {
const body = {
eventId: this.lastEventID(),
nameEn: this.props.department.basicInfo.nameEn,
nameHe: this.props.department.basicInfo.nameHe
}
axios.post(`/api/v1/departments/search-form`, body)
.then(res => {
if (res.data.length) {
this.state.questions = res.data;
this.state.hasChanges = true;
} else {
this.state.lastNotFound = true;
}
]
});
this.setState(this.state);
})
.catch(err => {
this.state.lastNotFound = true;
this.setState(this.state);
});
}

handleOnAddQuestion() {
const questions = [
...this.state.questions,
{
question: {
he: "",
en: ""
},
questionType: 'text',
options: [],
optional: true
}
]

this.state.questions = questions;
this.state.hasChanges = true;
this.setState(this.state);
}

handleOnQuestionChange(index, language, value) {
const questions = [...this.state.questions];
questions[index].question[language] = value;

this.setState({questions: questions, hasChanges: true});
this.state.questions = questions;
this.state.hasChanges = true;
this.setState(this.state);
}

handleOnQuestionTypeChange(index, value) {
const questions = [...this.state.questions];
questions[index].questionType = value;

this.setState({questions: questions, hasChanges: true});
this.state.questions = questions;
this.state.hasChanges = true;
this.setState(this.state);
}

handleOnOptionsChange(index, options) {
const questions = [...this.state.questions];
questions[index]["options"] = options;

this.setState({questions: questions, hasChanges: true});
this.state.questions = questions;
this.state.hasChanges = true;
this.setState(this.state);
}

handleOnQuestionOptionalChange(index, value) {
const questions = [...this.state.questions];
questions[index].optional = value;

this.setState({questions: questions, hasChanges: true});
this.state.questions = questions;
this.state.hasChanges = true;
this.setState(this.state);
}

deleteQuestion(index) {
const questions = [...this.state.questions];
questions.splice(index, 1);
this.setState({hasChanges: true, questions});

this.state.questions = questions;
this.state.hasChanges = true;
this.setState(this.state);
}

componentWillReceiveProps(nextProps){
this.setState({
isVisible: nextProps.isVisible
})
upQuestion(index) {
if (index == 0){
return
}
const questions = [...this.state.questions];
const temp = questions[index];
questions[index] = questions[index-1];
questions[index-1] = temp;
this.state.questions = questions;
this.state.hasChanges = true;
this.setState(this.state);
}

downQuestion(index) {
if (index == this.state.questions.length - 1){
return
}
const questions = [...this.state.questions];
const temp = questions[index];
questions[index] = questions[index+1];
questions[index+1] = temp;
this.state.questions = questions;
this.state.hasChanges = true;
this.setState(this.state);
}

render() {
const {questions, hasChanges} = this.state;
const {questions, hasChanges, lastNotFound} = this.state;
const {department} = this.props;
const lastEventID = this.lastEventID();

if(!this.state.isVisible) {
if(!this.props.isVisible) {
return null
}
return (<div className="form-editor" style={{marginTop: 20}}>
Expand All @@ -94,9 +161,11 @@ class FormEditor extends react.Component {
<ListGroupItem key={index} className="question">
<header>
<h3>{`Question ${index + 1}`}</h3>
<Button bsStyle="danger" onClick={() => this.deleteQuestion(index)}>
Delete
</Button>
<div class="buttons">
<Button bsStyle="link" onClick={() => this.upQuestion(index)}>Up</Button>
<Button bsStyle="link" onClick={() => this.downQuestion(index)}>Down</Button>
<Button bsStyle="danger" onClick={() => this.deleteQuestion(index)}>Delete</Button>
</div>
</header>

<FormGroup>
Expand Down Expand Up @@ -140,6 +209,8 @@ class FormEditor extends react.Component {
</ListGroup>
<footer>
<Button bsStyle="primary" onClick={this.handleOnAddQuestion}>Add Question</Button>
{department && lastEventID && !lastNotFound && <Button bsStyle="link" onClick={this.loadLastForm}>Load {lastEventID} form</Button>}
{department && lastEventID && lastNotFound && <p>Not Found</p>}
<Button bsStyle="primary" disabled={!hasChanges}
onClick={() => this.props.onSave(questions)}>Save</Button>
</footer>
Expand Down
Loading

0 comments on commit 9059eee

Please sign in to comment.