Advertisement
Guest User

Untitled

a guest
Feb 26th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. var UserSchema = new mongoose.Schema({
  2. username: String,
  3. password: String,
  4. first: String,
  5. last: String,
  6. email: String,
  7. roles: [String],
  8. logs: [{
  9. type: Schema.Types.ObjectId,
  10. ref: 'Log'
  11. }]
  12. });
  13.  
  14.  
  15. var LogSchema = new mongoose.Schema({
  16. posted_by: { type: String, ref: 'User'},
  17. content: String,
  18. date : String,
  19. });
  20.  
  21. var ResourcesSchema = new mongoose.Schema({
  22. name: String,
  23. serialnumber: String,
  24. modelno: String,
  25. description: String,
  26. logs: [LogSchema]
  27. });
  28.  
  29. <select ng-model="selectedResource" ng-options="resource.name for resource in resources" class="form-control" >
  30. </select>
  31. <br/>
  32. <div class="row">
  33. <div class="col-xs-3">
  34. {{selectedResource.logs}}
  35. </div>
  36.  
  37. </div>
  38. <br/>
  39. <br/>
  40.  
  41.  
  42. <textarea rows="3" cols="50" placeholder="content" ng-model="log.content">
  43. </textarea>
  44. <br/>
  45. <br/>
  46.  
  47.  
  48. <button class="btn btn-primary" ng-click="addLog()">Post</button>
  49.  
  50. app.controller("ActivitylogCtrl", function($scope, $http) {
  51.  
  52. $http.get('/activitylog')
  53. .success(function(response) {
  54. $scope.resources = response;
  55. });
  56.  
  57. $scope.all = function(){
  58. $http.get('/activitylog')
  59. .success(function(response) {
  60. var log = "";
  61. $scope.logs = response;
  62. $scope.log = "";
  63. });
  64. };
  65.  
  66. $scope.addLog = function() {
  67. console.log($scope.log);
  68. $http.post('/activitylog', $scope.log)
  69. .success(function(response){
  70. $scope.logs.push(response);
  71. $scope.all();
  72. });
  73. };
  74.  
  75. $scope.all();
  76.  
  77. });
  78.  
  79. app.post("/activitylog", function(req, res){
  80. var selectedResource = req.body.selectedResource;
  81. var content = req.body.content;
  82. var date = new Date().toISOString().replace(/T/,' ').replace(/..+/,'');
  83. Resources.findByIdAndUpdate(
  84. selectedResource,
  85. {$push: {"logs": {content: content, date: date}}},
  86. {safe : true, upsert: true},
  87. function(err, model) {
  88. console.log(err);
  89. }
  90. );
  91. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement