Skip to content

Commit

Permalink
big refactor !
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixH committed Feb 22, 2020
1 parent 9db0b65 commit 2f7310c
Show file tree
Hide file tree
Showing 9 changed files with 504 additions and 365 deletions.
49 changes: 29 additions & 20 deletions back-end/server/controller/PluginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
console.log(err);
next(err);
} else {
res.json({ status: "success", message: "Plugin found!!!", data: { plugins: pluginInfo } });
res.json({status: "success", message: "Plugin found!!!", data: {plugins: pluginInfo}});
}
});
},
Expand All @@ -24,7 +24,7 @@ module.exports = {
for (let plugin of plugins) {
pluginsList.push(plugin);
}
res.json({ status: "success", message: "Plugin list found!!!", data: { plugins: pluginsList } });
res.json({status: "success", message: "Plugin list found!!!", data: {plugins: pluginsList}});

}
});
Expand All @@ -47,14 +47,15 @@ module.exports = {
if (err)
next(err);
else {
res.json({ status: "success", message: "Plugin deleted successfully!!!", data: null });
res.json({status: "success", message: "Plugin deleted successfully!!!", data: null});
}
});
},

create: function (req, res, next) {
console.log("createPlugin");


Plugin.create({
name: req.body.name, description: req.body.description, version: req.body.version,
author: req.body.author, updated_on: req.body.updated_on, video_url: req.body.video_url,
Expand All @@ -64,13 +65,13 @@ module.exports = {
if (err)
next(err);
else
res.json({ status: "success", message: "Plugin added successfully!!!", data: null });
res.json({status: "success", message: "Plugin added successfully!!!", data: null});
});
},

/**
* Add rating to one plugin's rating list
*/
*/
rate: (req, res, next) => {
console.log(">>> rate plugin <<<");

Expand All @@ -81,18 +82,22 @@ module.exports = {
* Reminder:
** Plugin.findOne{filter} returns one single plugin that matches the filter
** Plugin.find{filter} returns a list containing one single plugin that matches the filter
*/
Plugin.findOne({ _id: pluginId }, (err, plugin) => {
*/
Plugin.findOne({_id: pluginId}, (err, plugin) => {
if (err) {
next(err);
} else {
let newRatings = plugin.ratings;
newRatings.push(note);
Plugin.updateOne({ _id: plugin._id }, { ratings: newRatings }, (error, p) => {
Plugin.updateOne({_id: plugin._id}, {ratings: newRatings}, (error, p) => {
if (error) {
next(error);
} else {
res.json({ status: "Success", message: `Plugin ${plugin.name} has been rated ${note}`, data: null });
res.json({
status: "Success",
message: `Plugin ${plugin.name} has been rated ${note}`,
data: null
});
}
});
}
Expand All @@ -101,13 +106,13 @@ module.exports = {

/**
* Get plugin's score
*/
*/
getScore: (req, res, next) => {
console.log(">>> getScore <<<");

let pluginId = req.body.pluginId;

Plugin.findOne({ _id: pluginId }, (err, plugin) => {
Plugin.findOne({_id: pluginId}, (err, plugin) => {
if (err) {
next(err);
} else {
Expand All @@ -117,34 +122,38 @@ module.exports = {
if (ratings.length > 0) {
/**
* Sum all the ratings into score
*/
*/
score = ratings.reduce((a, b) => a + b, 0) / ratings.length;
}
res.json({ status: "Success", data: { score: score } });
res.json({status: "Success", data: {score: score}});
}
});
},

/**
* Get plugin's score
*/
*/
comment: (req, res, next) => {
console.log(">>> comment <<<");

let pluginId = req.body.pluginId;
let commentText = req.body.commentText;

Plugin.findOne({ _id: pluginId }, (err, plugin) => {
Plugin.findOne({_id: pluginId}, (err, plugin) => {
if (err) {
next(err);
} else {
let comments = plugin.comments;
comments.push(commentText);
Plugin.updateOne({ _id: plugin._id }, { comments: comments }, (error, p) => {
Plugin.updateOne({_id: plugin._id}, {comments: comments}, (error, p) => {
if (error) {
next(error);
} else {
res.json({ status: "Success", message: `Comment ${commentText} has been added to plugin ${plugin.name}`, data: null });
res.json({
status: "Success",
message: `Comment ${commentText} has been added to plugin ${plugin.name}`,
data: null
});
}
});
}
Expand All @@ -153,13 +162,13 @@ module.exports = {

/**
* Get Zip File by pluginId
*/
*/
getZipFile: (req, res, next) => {
console.log(">>> commentgetZipFile <<<");

let pluginId = req.query.pluginId;

Plugin.findOne({ _id: pluginId }, (err, plugin) => {
Plugin.findOne({_id: pluginId}, (err, plugin) => {
if (err) {
next(err);
} else {
Expand All @@ -176,7 +185,7 @@ module.exports = {

/**
* Echapper les caractères spéciaux HTML
*/
*/
let escapeHtml = (unsafe) => {
return unsafe
.replace(/&/g, "&amp;")
Expand Down
2 changes: 0 additions & 2 deletions back-end/server/models/Plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const pluginSchema = mongoose.Schema({
author: {
type: String,
trim: true,
required: true,
},
updated_on: {
type: Date,
Expand All @@ -39,7 +38,6 @@ const pluginSchema = mongoose.Schema({
zip_url: {
type: String,
trim: true,
required: true
},
category: {
type: String,
Expand Down
13 changes: 12 additions & 1 deletion front-end/src/Components/LoginForm/LoginForm.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ label {
font-weight: bold;
}

#skip_login{
color: royalblue;
text-decoration: underline;
font-size: 15px;
margin-top: 2%;
} #skip_login:hover{
cursor: pointer;
}


.message {
font-size: 25px;
Expand All @@ -24,7 +33,7 @@ label {

.input {
width: 80%;
margin-bottom:5%;
margin-top:5%;
padding: 2%;
size: 20px;
padding:0;
Expand All @@ -45,6 +54,7 @@ label {
justify-content: space-evenly;
align-items: center;
width: 80%;
margin-top: 5%;
}


Expand All @@ -58,6 +68,7 @@ label {
background-color: #68585f ;
}


.card {
width: 30%;
min-width: 400px;
Expand Down
9 changes: 8 additions & 1 deletion front-end/src/Components/LoginForm/LoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import TextField from '@material-ui/core/TextField';
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import Button from "@material-ui/core/Button";
import {useHistory} from 'react-router-dom';

function LoginForm() {

const [email, setEmail] = useState("");
const [password,setEPassword] = useState("");
const dispatch = useDispatch();
const history = useHistory();

function register() {
console.log("Unavailable feature : Register new user ! It should arrive soon !")
Expand Down Expand Up @@ -102,6 +104,10 @@ function LoginForm() {
});
}

function skipLogin() {
history.push('/home')
}

return (
<div className="rootDiv">
<Card raised={"true"} className={"card"} color="primary">
Expand All @@ -111,6 +117,7 @@ function LoginForm() {
<TextField
className={"field"}
required
id={"email"}
placeholder={"Mail"}
type="email"
defaultValue=""
Expand Down Expand Up @@ -149,7 +156,7 @@ function LoginForm() {
</Button>
</div>
</div>

<p onClick={() => skipLogin()} id={"skip_login"}>Continuer en tant que visiteur</p>
</form>
</CardContent>
</Card>
Expand Down
9 changes: 5 additions & 4 deletions front-end/src/Components/Navbar/NavBar.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@


#logout_button{
background-color: #F50057;
color: whitesmoke;
background-color: whitesmoke ;
}

#upload_button{
background-color: white;
background-color: #F50057;
margin-right: 3%;
color: whitesmoke;
}

#buttons{
Expand All @@ -44,6 +44,7 @@
}

#login_button{
background-color: whitesmoke;
background-color: #F50057;
color: whitesmoke;
}

89 changes: 84 additions & 5 deletions front-end/src/Components/PluginUploadForm/PluginUploadForm.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,100 @@
.card{
#card{
height: 100%;
padding: 2%;
width: 60%;
}

#wrapper{
height: 100%;
#plugin_upload_page{
display: flex;
flex-direction: row;
justify-content: center;
padding-top: 4%;
}

#plugin_upload_page{
.tag{

}

#zip_section{
display: flex;
flex-direction: column;
width: 80%;
}

#file_section{
display: flex;
flex-direction: row;
justify-content: center;
align-items: baseline;
}

#check_icon{
font-size: 100px;
}

#validation{
display: flex;
flex-direction: column;
align-items: center;
}

.textField {
width: 100%;
padding: 1%;
}

#bottom_buttons{
display: flex;
flex-direction: row;
justify-content: space-evenly;
width: 30%;
}


#zip_button{
margin-bottom: 5%;
}

#upload_form{
width: 70%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
#tags_input{
width: 100%;
}

#tags{
width: 100%;
}
#upload_form_content{
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}

.upload_input{
width:45%;
size: 12px;
}

#desc{
width: 100%;
}

.button {
width: 100%;
}

#select{
width: 290px;
}

#stepper{
padding: 0;
margin-bottom: 5%;
width: 80%;
}
Loading

0 comments on commit 2f7310c

Please sign in to comment.