Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var UserSchema = new mongoose.Schema({
- username: String,
- password: String,
- first: String,
- last: String,
- email: String,
- roles: [String],
- logs: [{
- type: Schema.Types.ObjectId,
- ref: 'Log'
- }]
- });
- var LogSchema = new mongoose.Schema({
- posted_by: { type: String, ref: 'User'},
- content: String,
- date : String,
- });
- var ResourcesSchema = new mongoose.Schema({
- name: String,
- serialnumber: String,
- modelno: String,
- description: String,
- logs: [LogSchema]
- });
- <select ng-model="selectedResource" ng-options="resource.name for resource in resources" class="form-control" >
- </select>
- <br/>
- <div class="row">
- <div class="col-xs-3">
- {{selectedResource.logs}}
- </div>
- </div>
- <br/>
- <br/>
- <textarea rows="3" cols="50" placeholder="content" ng-model="log.content">
- </textarea>
- <br/>
- <br/>
- <button class="btn btn-primary" ng-click="addLog()">Post</button>
- app.controller("ActivitylogCtrl", function($scope, $http) {
- $http.get('/activitylog')
- .success(function(response) {
- $scope.resources = response;
- });
- $scope.all = function(){
- $http.get('/activitylog')
- .success(function(response) {
- var log = "";
- $scope.logs = response;
- $scope.log = "";
- });
- };
- $scope.addLog = function() {
- console.log($scope.log);
- $http.post('/activitylog', $scope.log)
- .success(function(response){
- $scope.logs.push(response);
- $scope.all();
- });
- };
- $scope.all();
- });
- app.post("/activitylog", function(req, res){
- var selectedResource = req.body.selectedResource;
- var content = req.body.content;
- var date = new Date().toISOString().replace(/T/,' ').replace(/..+/,'');
- Resources.findByIdAndUpdate(
- selectedResource,
- {$push: {"logs": {content: content, date: date}}},
- {safe : true, upsert: true},
- function(err, model) {
- console.log(err);
- }
- );
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement