Browse Source

delete project and join project added (frontend and backend)

master
nau 8 years ago
parent
commit
48eb01dd5e
5 changed files with 104 additions and 17 deletions
  1. +35
    -5
      controllers/projectController.js
  2. +3
    -3
      models/projectModel.js
  3. +3
    -0
      server.js
  4. +53
    -7
      webapp/controllers.js
  5. +10
    -2
      webapp/dashboard.html

+ 35
- 5
controllers/projectController.js

@ -61,7 +61,31 @@ exports.addProject = function(req, res) {
project.save(function(err, project) { project.save(function(err, project) {
if(err) return res.send(500, err.message); if(err) return res.send(500, err.message);
res.status(200).jsonp(project);
/*res.status(200).jsonp(project);*/
projectModel.find(function(err, projects) {
if(err) res.send(500, err.message);
res.status(200).jsonp(projects);
});
});
};
exports.addUserToProject = function(req, res) {
console.log("addUserToProject");
console.log(req.body);
projectModel.findById(req.params.id, function(err, project) {
console.log(project);
project.users.push(req.body.username);
console.log(project.users);
project.save(function(err) {
if(err) return res.send(500, err.message);
projectModel.find(function(err, projects) {
if(err) res.send(500, err.message);
res.status(200).jsonp(projects);
});
});
}); });
}; };
@ -85,11 +109,17 @@ exports.updateProject = function(req, res) {
//DELETE //DELETE
exports.deleteProject = function(req, res) { exports.deleteProject = function(req, res) {
ActivityModel.findById(req.params.id, function(err, activity) {
activity.remove(function(err) {
projectModel.findById(req.params.id, function(err, project) {
project.remove(function(err) {
if(err) return res.send(500, err.message); if(err) return res.send(500, err.message);
res.status(200).jsonp(req.params.id);
console.log('DELETE /activities/' + req.params.id);
/*res.status(200).jsonp(req.params.id);*/
console.log('DELETE /projects/' + req.params.id);
projectModel.find(function(err, projects) {
if(err) res.send(500, err.message);
res.status(200).jsonp(projects);
});
}) })
}); });
}; };

+ 3
- 3
models/projectModel.js

@ -2,17 +2,17 @@ var mongoose = require('mongoose'),
Schema = mongoose.Schema; Schema = mongoose.Schema;
var travelSchema = new Schema({
var projectSchema = new Schema({
title: { type: String }, title: { type: String },
description: { type: String }, description: { type: String },
icon: { type: String }, icon: { type: String },
users: { type: String },
users: [{ type: String }],
chart: { type: String }, chart: { type: String },
dateCreation: { type: Date }, dateCreation: { type: Date },
github: { type: String }, github: { type: String },
refnum: { type: String } refnum: { type: String }
}) })
module.exports = mongoose.model('projectModel', travelSchema);
module.exports = mongoose.model('projectModel', projectSchema);
//modality can be: offering, asking, package //modality can be: offering, asking, package

+ 3
- 0
server.js

@ -124,6 +124,9 @@ apiRoutes.route('/projects/:id')
.put(projectCtrl.updateProject) .put(projectCtrl.updateProject)
.delete(projectCtrl.deleteProject); .delete(projectCtrl.deleteProject);
apiRoutes.route('/projects/:id/adduser')
.put(projectCtrl.addUserToProject);
app.use('/api', apiRoutes); app.use('/api', apiRoutes);
// end of API routes ------------------------------------- // end of API routes -------------------------------------

+ 53
- 7
webapp/controllers.js

@ -9,21 +9,28 @@ angular.module('workApp', ['chart.js'])
$scope.users={}; $scope.users={};
$scope.projects={}; $scope.projects={};
$scope.currentInclude='login.html'; $scope.currentInclude='login.html';
var refreshTime=20000;
/* DASHBOARD initialization */ /* DASHBOARD initialization */
$scope.dashboardInit = function(){ $scope.dashboardInit = function(){
if(localStorage.getItem('owt_token')){// adding token to the headers if(localStorage.getItem('owt_token')){// adding token to the headers
$http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('owt_token'); $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('owt_token');
$http.defaults.headers.post['Content-Type'] = 'application/json';
$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('owt_token'); $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('owt_token');
} }
if(localStorage.getItem("owt_user")){
$scope.user=JSON.parse(localStorage.getItem("owt_user"));
}else{
$scope.currentInclude="login.html";
}
//getting users //getting users
$http.get(urlapi + 'users') $http.get(urlapi + 'users')
.success(function(data, status, headers,config){ .success(function(data, status, headers,config){
if(data.success==false){ if(data.success==false){
localStorage.removeItem("owt_token");
/*localStorage.removeItem("owt_token");
localStorage.removeItem("owt_user"); localStorage.removeItem("owt_user");
$scope.currentInclude="login.html"; $scope.currentInclude="login.html";
console.log("token ended");
console.log("token ended");*/
}else{ }else{
console.log(data); console.log(data);
$scope.users=data; $scope.users=data;
@ -64,7 +71,7 @@ angular.module('workApp', ['chart.js'])
$scope.dashboardInit(); $scope.dashboardInit();
intervalGetData = $interval(function(){ intervalGetData = $interval(function(){
$scope.dashboardInit(); $scope.dashboardInit();
}, 2000);
}, refreshTime);
}else{ }else{
$scope.currentInclude="login.html"; $scope.currentInclude="login.html";
} }
@ -107,7 +114,7 @@ angular.module('workApp', ['chart.js'])
intervalGetData = $interval(function(){ intervalGetData = $interval(function(){
$scope.dashboardInit(); $scope.dashboardInit();
}, 2000);
}, refreshTime);
}else{ }else{
toastr.error(response.data.message); toastr.error(response.data.message);
} }
@ -159,6 +166,7 @@ angular.module('workApp', ['chart.js'])
}).then(function(response) { }).then(function(response) {
console.log("project posted"); console.log("project posted");
console.log(response); console.log(response);
$scope.projects=response.data;
toastr.success("project created at server"); toastr.success("project created at server");
$scope.newproject={}; $scope.newproject={};
}, },
@ -179,14 +187,43 @@ angular.module('workApp', ['chart.js'])
$scope.editingProject=false; $scope.editingProject=false;
}; };
$scope.removeProject = function(index){ $scope.removeProject = function(index){
$scope.projects.splice(index, 1);
localStorage.setItem("w_l_projects", angular.toJson($scope.projects));
$scope.projectSelect(0);
/*$scope.projects.splice(index, 1);
localStorage.setItem("w_l_projects", angular.toJson($scope.projects));*/
$http({
url: urlapi + 'projects/' + $scope.projects[index]._id,
method: "DELETE",
data: $scope.user._id
}).then(function(response) {
console.log(response);
$scope.projects=response.data;
$scope.projectSelect(null);
},
function(response) {// failed
});
}; };
$scope.currentprojectIndex;
$scope.projectSelect = function(index){ $scope.projectSelect = function(index){
$scope.btnStop(); $scope.btnStop();
$scope.currentprojectIndex=index;
$scope.currentproject=$scope.projects[index]; $scope.currentproject=$scope.projects[index];
}; };
$scope.joinProject = function(){
console.log($scope.user);
$http({
url: urlapi + 'projects/'+$scope.currentproject._id+'/adduser',
method: "PUT",
data: $scope.user
}).then(function(response) {
console.log("project joined");
$scope.projects=response.data;
//re select currentproject
$scope.currentproject=$scope.projects[$scope.currentprojectIndex];
toastr.success("project joined");
},
function(response) {// failed
});
};
var interval; var interval;
$scope.currentStrike=0; $scope.currentStrike=0;
$scope.btnWork = function(){ $scope.btnWork = function(){
@ -197,6 +234,15 @@ angular.module('workApp', ['chart.js'])
$scope.currentStrike++; $scope.currentStrike++;
$scope.currentproject.totaltime++; $scope.currentproject.totaltime++;
}, 1000); }, 1000);
$http({
url: urlapi + 'users',
method: "POST",
data: $scope.user
}).then(function(response) {
$scope.currentInclude="login.html";
},
function(response) {// failed
});
}; };
$scope.btnStop = function(){ $scope.btnStop = function(){
$interval.cancel(interval); $interval.cancel(interval);

+ 10
- 2
webapp/dashboard.html

@ -78,6 +78,9 @@
<span class="title">{{project.title}}</span> <span class="title">{{project.title}}</span>
<p class="grey-text">{{project.description}}</p> <p class="grey-text">{{project.description}}</p>
<p class="grey-text">{{project.totaltime | secondsToDateTime | date:'HH:mm:ss'}}</p> <p class="grey-text">{{project.totaltime | secondsToDateTime | date:'HH:mm:ss'}}</p>
<p class="grey-text">
<div ng-repeat="user in project.users">{{user}}</div>
</p>
</a> </a>
</div> </div>
</div> </div>
@ -125,8 +128,13 @@
</div> </div>
<div class="card-action"> <div class="card-action">
<a ng-click="btnWork()" ng-show="!working" class="waves-effect waves-light btn green lighten-2">Work!</a>
<a ng-click="btnStop()" ng-show="working" class="waves-effect waves-light btn red lighten-2">Stop!</a>
<div ng-show="currentproject.users.indexOf(user.username)!=-1">
<a ng-click="btnWork()" ng-show="!working" class="waves-effect waves-light btn green lighten-2">Work!</a>
<a ng-click="btnStop()" ng-show="working" class="waves-effect waves-light btn red lighten-2">Stop!</a>
</div>
<div ng-show="currentproject.users.indexOf(user.username)==-1">
<a ng-click="joinProject()" class="waves-effect waves-light btn blue lighten-2">Join!</a>
</div>
<!--<a class="waves-effect waves-light btn deep-orange lighten-2">Stop working!</a>--> <!--<a class="waves-effect waves-light btn deep-orange lighten-2">Stop working!</a>-->
</div> </div>

Loading…
Cancel
Save