<file_sep># mean-stack-reading-list
Proof of concept to create a personal Reading List using MEAN Stack, Gulp
<file_sep>readingItemsApp.controller('readingItemsCtrl', function($rootScope, $scope, readingItemsFactory) {
 
  $scope.readingItems = [];
  $scope.isEditable = [];
 
  // get all readingItems on Load
  readingItemsFactory.getReadingItems().then(function(data) {
    $scope.readingItems = data.data;
  });
 
  // Save a readingItem to the server
  $scope.save = function($event) {
    if ($event.which == 13 && $scope.readingItemInput) {
 
      readingItemsFactory.saveReadingItem({
        "readingItem": $scope.readingItemInput,
        "isCompleted": false
      }).then(function(data) {
        $scope.readingItems.push(data.data);
      });
      $scope.readingItemInput = '';
    }
  };
 
  //update the status of the readingItem
  $scope.updateStatus = function($event, _id, i) {
    var cbk = $event.target.checked;
    var _t = $scope.readingItems[i];
    readingItemsFactory.updateReadingItem({
      _id: _id,
      isCompleted: cbk,
      readingItem: _t.readingItem
    }).then(function(data) {
      if (data.data.ok && data.data.nModified) {
        _t.isCompleted = cbk;
      } else {
        alert('Oops something went wrong!');
      }
    });
  };
 
  // Update the edited readingItem
  $scope.edit = function($event, i) {
    if ($event.which == 13 && $event.target.value.trim()) {
      var _t = $scope.readingItems[i];
      readingItemsFactory.updateReadingItem({
        _id: _t._id,
        readingItem: $event.target.value.trim(),
        isCompleted: _t.isCompleted
      }).then(function(data) {
        if (data.data.ok && data.data.nModified) {
          _t.readingItem = $event.target.value.trim();
          $scope.isEditable[i] = false;
        } else {
          alert('Oops something went wrong!');
        }
      });
    }
  };
 
  // Delete a readingItem
  $scope.delete = function(i) {
    readingItemsFactory.deleteReadingItem($scope.readingItems[i]._id).then(function(data) {
      if (data.data) {
        $scope.readingItems.splice(i, 1);
      }
    });
  };
 
});<file_sep>{
  "name": "mean-stack-reading-list",
  "version": "1.0.0",
  "description": "Reading List using MEAN Stack",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/krishnavteja/mean-stack-reading-list.git"
  },
  "keywords": [
    "MEAN-Stack"
  ],
  "author": "<NAME>",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/krishnavteja/mean-stack-reading-list/issues"
  },
  "homepage": "https://github.com/krishnavteja/mean-stack-reading-list",
  "dependencies": {
    "body-parser": "^1.13.1",
    "cookie-parser": "^1.3.5",
    "debug": "^2.2.0",
    "ejs": "^2.3.1",
    "express": "^4.13.0",
    "mongojs": "^1.0.1",
    "morgan": "^1.6.0"
  },
  "devDependencies": {
    "gulp": "^3.9.0",
    "gulp-jshint": "^1.11.0",
    "gulp-livereload": "^3.8.0",
    "gulp-nodemon": "^2.0.3",
    "gulp-watch": "^4.2.4"
  }
}
<file_sep>readingItemsApp = angular.module('readingItemsApp', ['ngRoute'])
  .config(function($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: '/partials/readingItems.html',
        controller: 'readingItemsCtrl'
      }).otherwise({
        redirectTo: '/'
      });
  });