Skip to content

Commit aa78acb

Browse files
committed
Merge: fix
2 parents 0dfaa05 + 20b215e commit aa78acb

File tree

14 files changed

+293
-119
lines changed

14 files changed

+293
-119
lines changed

db/changeCardColor.sql

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UPDATE cards SET color = $1 WHERE id = $2

db/changeColor.sql

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UPDATE projects SET color = $1 where id = $2

db/getProjectById.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
SELECT *
22
FROM projects
3-
WHERE owner_id = $1;
3+
WHERE owner_id = $1
4+
ORDER BY id;
45

56

67

server/controllers/projects_controller.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,13 @@ module.exports = {
2727
.getTeamProjects([req.user.id])
2828
.then(response => res.status(200).send(response))
2929
.catch(err => console.log(err));
30-
}
30+
},
31+
changeColor: (req, res, next) => {
32+
const dbInstance = req.app.get('db');
33+
dbInstance
34+
.changeColor([req.body.color, req.body.projectID])
35+
.then(response => res.status(200).send(response))
36+
.catch(err => console.log(err));
37+
},
38+
3139
};

server/controllers/tasks_controller.js

+9
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,13 @@ module.exports = {
193193
})
194194
.catch(console.log)
195195
},
196+
changeCardColor: (req, res, next) => {
197+
const dbInstance = req.app.get('db')
198+
199+
dbInstance.changeCardColor([req.body.color, req.body.cardID])
200+
.then(response => {
201+
res.status(200).send(response)
202+
})
203+
.catch(console.log)
204+
},
196205
}

server/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ app.get('/api/allProjects',projectsController.getAllProjects);
261261
app.get('/api/allTasks', projectsController.getAllTasks);
262262
app.post('/api/addProject', projectsController.addProject);
263263
app.get('/api/allTeamProjects', projectsController.getTeamProjects)
264+
app.post('/api/changeColor', projectsController.changeColor)
264265

265266
///////////////////////////////////////////////////////////////////////////
266267
// Project View Endpoints
@@ -283,6 +284,7 @@ app.post('/api/dragTask', tasksController.dragTask)
283284
app.post('/api/removeCurrentMember', tasksController.removeCurrentMember)
284285

285286
app.put('/api/sendNewTitle/:title/:projectID', tasksController.sendNewTitle)
287+
app.post('/api/changeCardColor', tasksController.changeCardColor)
286288

287289
///////////////////////////////////////////////////////////////////////////
288290
app.post('/api/updateHeader', tasksController.editCardHeader)

src/components/Dashboard/Dashboard.css

+3
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,6 @@ h1 {
104104
.collab-board-container {
105105
margin-top: 50px;
106106
}
107+
.outer-project-box{
108+
position: relative;
109+
}

src/components/Dashboard/Dashboard.js

+32-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import Sidebar from '../Sidebar/Sidebar';
1212
import Header from '../Header/Header';
1313
import {getUserInfo} from './../../ducks/reducers/userReducer'
14+
import ColorPicker from './../tools/ColorPicker/ColorPicker'
1415

1516
import './Dashboard.css';
1617

@@ -19,10 +20,15 @@ class Dashboard extends Component {
1920
super(props);
2021

2122
this.state = {
22-
toolTip: false
23+
toolTip: false,
24+
currColor: '',
25+
colorsOpen: false,
26+
projID: 0
2327
};
2428
this.createProjectToolTip = this.createProjectToolTip.bind(this);
2529
this.sendNewProject = this.sendNewProject.bind(this);
30+
this.pickColor = this.pickColor.bind(this)
31+
this.showColors = this.showColors.bind(this)
2632
}
2733
componentDidMount() {
2834
this.props.getAllProjects();
@@ -46,22 +52,39 @@ class Dashboard extends Component {
4652
});
4753
}
4854

55+
pickColor(color, projectID){
56+
console.log(color, projectID);
57+
axios.post('/api/changeColor', {color, projectID}).then(response => {
58+
this.props.getAllProjects();
59+
this.setState({colorsOpen: !this.state.colorsOpen, projectID})
60+
})
61+
}
62+
showColors(projID){
63+
this.setState({colorsOpen: !this.state.colorsOpen, projID})
64+
console.log("Hit!");
65+
}
66+
4967
render() {
5068
//On page load a box is created and displays information for each project
5169
const projectBox = this.props.projects.map((project, index) => {
5270
return (
53-
<Link to={`/ProjectView/${project.id}/${project.title}`} className="dashboardCards" key={index}>
54-
<div className="project-card">
55-
<div className="card-header">{project.title}</div>
56-
</div>
57-
</Link>
58-
);
71+
<div key={index} className="outer-project-box">
72+
<Link to={`/ProjectView/${project.id}/${project.title}`} key={index}>
73+
<div className="project-card" style={ project.color && {'backgroundColor': `${project.color}`}}>
74+
<div className="card-header">
75+
{project.title}
76+
</div>
77+
</div>
78+
</Link>
79+
<ColorPicker currentID={this.state.projID} colorsOpen={this.state.colorsOpen} showColors={this.showColors} currentItem={project} pickColor={this.pickColor}/>
80+
</div>
81+
)
5982
});
6083

6184
const teamProjects = this.props.teamProjects.map((project, index) => {
6285
return (
63-
<Link to={`/ProjectView/${project.id}/${project.title}`} className="dashboardCards" key={index}>
64-
<div className="project-card">
86+
<Link to={`/ProjectView/${project.id}/${project.title}`} key={index}>
87+
<div className="project-card" style={ project.color && {'backgroundColor': `${project.color}`}} >
6588
<div className="card-header">{project.title}</div>
6689
</div>
6790
</Link>

src/components/ProjectView/PVComponents/Card/Card.js

+32-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {connect} from 'react-redux'
44
import { withRouter } from 'react-router-dom'
55
import Task from '../Task/Task'
66

7+
import axios from 'axios'
8+
79

810
///////////////////////////////////////////
911
import { DropTarget } from 'react-dnd'
@@ -26,6 +28,8 @@ import {
2628

2729
import '../../ProjectView.css'
2830

31+
import ColorPicker from './../../../tools/ColorPicker/ColorPicker'
32+
2933

3034
const cardTarget = {
3135
drop(props) {
@@ -46,12 +50,17 @@ class Card extends Component {
4650
super(props)
4751
this.state = {
4852
editOpen: false,
49-
options: false
53+
options: false,
54+
colorsOpen: false,
55+
cardID: 0
56+
5057
}
5158
this.openHeaderEdit = this.openHeaderEdit.bind(this)
5259
this.openEditOptions = this.openEditOptions.bind(this)
5360
this.deleteCard = this.deleteCard.bind(this)
5461
this.closeEditOptions = this.closeEditOptions.bind(this)
62+
this.showColors = this.showColors.bind(this)
63+
this.pickColor = this.pickColor.bind(this)
5564
}
5665

5766
openHeaderEdit(cardID, title){
@@ -106,6 +115,18 @@ class Card extends Component {
106115

107116
}//done
108117

118+
showColors(cardID){
119+
this.setState({colorsOpen: !this.state.colorsOpen, cardID})
120+
console.log("Hit!");
121+
}
122+
123+
pickColor(color, cardID){
124+
console.log(color, cardID);
125+
axios.post('/api/changeCardColor', {color, cardID}).then(response => {
126+
this.props.getNewCards(this.props.match.params.id);
127+
this.setState({colorsOpen: !this.state.colorsOpen, cardID})
128+
})
129+
}
109130

110131

111132

@@ -121,7 +142,6 @@ class Card extends Component {
121142
}
122143

123144
const style = {'backgroundColor': backgroundColor}
124-
125145

126146
return connectDropTarget(
127147
<div id='taskHolder' style={style}>
@@ -167,14 +187,22 @@ class Card extends Component {
167187
}
168188

169189
{
170-
<div id='cardTest'>
190+
// Currently The background color is being changed on this div
191+
<div id='cardTest' style={{'backgroundColor': this.props.card.color}}>
171192
<form onSubmit={e => this.handleAddTask(e, this.props.card.id, this.props.match.params.id)}>
172193
<input type='text'
173194
className='newCard'
174195
onClick={() => this.selectCard(this.props.card.id)}
175196
onChange={this.props.taskInput}
176197
value={this.props.taskInputID === this.props.card.id ? this.props.newTask : ''}/>
177198
</form>
199+
200+
{/* These two divs are allowing us to position the box absoloutely. Do inline style to override component styling */}
201+
<div style={{"position": "relative"}} >
202+
<div style={{'position': "absolute", 'top': '-60px', 'right': '20px'}}>
203+
<ColorPicker currentID={this.props.card.id} colorsOpen={this.state.colorsOpen} showColors={this.showColors} currentItem={this.props.card} pickColor={this.pickColor} />
204+
</div>
205+
</div>
178206
</div>
179207
}
180208
{/* <div id={this.props.inputOpen && this.state.taskCardID === card.cardID ? 'openEditer' : 'cardTest'} onClick={this.addText}>
@@ -188,6 +216,7 @@ class Card extends Component {
188216
type="text"/>
189217
</form>
190218
</div> */}
219+
191220
</div>
192221
);
193222
}

0 commit comments

Comments
 (0)