diff --git a/Angular_Full_Project_GULP/app.js b/Angular_Full_Project_GULP/app.js index 7f5ab37..72a7bcb 100644 --- a/Angular_Full_Project_GULP/app.js +++ b/Angular_Full_Project_GULP/app.js @@ -18,15 +18,9 @@ app.use(cors({ 'http://localhost:3000', 'google.com' ] })); -//var server = require('http').Server(app); var id; app.use(urlencodedParser); app.use(bodyParser.json()); - -/*router.get('/user',function(req,res){ - //console.log("Hi"); -});*/ - router.get('/user/:id',function(req,res){ id= req.params.id; @@ -41,21 +35,27 @@ router.get('/user/:id',function(req,res){ ); }); router.post('/user/:id',function(req,res){ + user2.findById(id,function(err,user) { + console.log(id); + if (err) { + res.send(err); + } console.log("hi"); user.name=req.body.name; user.email=req.body.email; user.state=req.body.state; user.city= req.body.city; user.Gender=req.body.gender; + user.Dob=req.body.daterange; user.IsDeleted=req.body.active; - user.save(function(err,user2){ + user.save(function(err){ if(err) {console.log(err);} else{ console.log("no err"); - }}) - res.sendStatus(200); -}) + }})}) + res.sendStatus(200);} +) router.get('/user',function(req,res){ user2.find({},function(err,users){ @@ -65,7 +65,7 @@ router.get('/user',function(req,res){ } }); }); -router.delete('',function(req,res){ +router.delete('/user/:id',function(req,res){ id=req.params.id; user2.findByIdAndRemove(req.params.id,function(err,tasks){console.log(tasks);}); }); diff --git a/Angular_Full_Project_GULP/index.html b/Angular_Full_Project_GULP/index.html index 423bb49..128cfeb 100644 --- a/Angular_Full_Project_GULP/index.html +++ b/Angular_Full_Project_GULP/index.html @@ -48,7 +48,7 @@ - + diff --git a/Angular_Full_Project_GULP/js/app.js b/Angular_Full_Project_GULP/js/app.js index 41480fd..acccb0c 100644 --- a/Angular_Full_Project_GULP/js/app.js +++ b/Angular_Full_Project_GULP/js/app.js @@ -19,8 +19,8 @@ angular 'ncy-angular-breadcrumb', 'angular-loading-bar', 'ngSanitize', - 'ngAnimate'//, - //'daterangepicker' + 'ngAnimate', + 'ui.bootstrap' ]) .config(function ($httpProvider) { diff --git a/Angular_Full_Project_GULP/js/controllers.js b/Angular_Full_Project_GULP/js/controllers.js index 2f6fbb2..40fd7c3 100644 --- a/Angular_Full_Project_GULP/js/controllers.js +++ b/Angular_Full_Project_GULP/js/controllers.js @@ -1,8 +1,70 @@ // controller.js -angular - .module('app') +function userService($http){ + this.getUser=function (){ + return $http + .get('http://localhost:8001/api/user') + .then(function (d) { + console.log(d); + return d.data; + }, function (err) { + console.log(err); + } + );} +} +angular.module('app'/*,['ui.bootstrap']*/) .controller('languageCtrl', languageCtrl) - .controller('addController', addController) + .service('userService',userService) + .service('modalService', ['$uibModal', +// NB: For Angular-bootstrap 0.14.0 or later, use $uibModal above instead of $modal + function ($uibModal) { + + var modalDefaults = { + backdrop: true, + keyboard: true, + modalFade: true, + templateUrl: 'views/modal.html' + }; + + var modalOptions = { + closeButtonText: 'Close', + actionButtonText: 'OK', + headerText: 'Proceed?', + bodyText: 'Perform this action?' + }; + + this.showModal = function (customModalDefaults, customModalOptions) { + if (!customModalDefaults) customModalDefaults = {}; + customModalDefaults.backdrop = 'static'; + return this.show(customModalDefaults, customModalOptions); + }; + + this.show = function (customModalDefaults, customModalOptions) { + //Create temp objects to work with since we're in a singleton service + var tempModalDefaults = {}; + var tempModalOptions = {}; + + //Map angular-ui modal custom defaults to modal defaults defined in service + angular.extend(tempModalDefaults, modalDefaults, customModalDefaults); + + //Map modal.html $scope custom properties to defaults defined in service + angular.extend(tempModalOptions, modalOptions, customModalOptions); + + if (!tempModalDefaults.controller) { + tempModalDefaults.controller = function ($scope, $modalInstance) { + $scope.modalOptions = tempModalOptions; + $scope.modalOptions.ok = function (result) { + $modalInstance.close(result); + }; + $scope.modalOptions.close = function (result) { + $modalInstance.dismiss('cancel'); + }; + }; + } + + return $uibModal.open(tempModalDefaults).result; + }; + + }]) .service('fileUpload', ['$http', function ($http) { this.uploadFileToUrl = function(file, uploadUrl){ var fd = new FormData(); @@ -20,8 +82,11 @@ angular }); } }]) + .controller('addController', addController) + -addController.$inject=['$http','$scope','fileUpload']; + +addController.$inject=['$http','$scope','fileUpload','userService']; languageCtrl.$inject = ['$translate', '$scope']; function languageCtrl($translate, $scope) { function checkLanguage(languages, langKey) { @@ -61,8 +126,39 @@ function languageCtrl($translate, $scope) { checkLanguage(languages, langKey) }; } -function addController($http,$scope,fileUpload) { +/*function ModalDemoCtrl($rootScope, $scope, $log, $uibModal){ + $scope.open = function(size, template) { + var modalInstance = $uibModal.open({ + animation: $scope.animationsEnabled, + templateUrl: template || 'myModalContent.html', + controller: 'ModalInstanceCtrl', + size: size + }); +} + $scope.toggleAnimation = function() { + $scope.animationsEnabled = !$scope.animationsEnabled; + }; + +}*/ +/* +ModalInstanceCtrl.$inject=['$scope', '$uibModalInstance', 'modalFactory'] +function ModalInstanceCtrl($scope, $uibModalInstance, modalFactory) { + + //$scope.searchTerm = term; + + $scope.ok = function() { + modalFactory.open('lg', 'result.html', {searchTerm: $scope.searchTerm}); + //$uibModalInstance.close($scope.searchTerm); + }; + + $scope.cancel = function() { + $uibModalInstance.dismiss('cancel'); + }; +} +*/ +function addController($http,$scope,fileUpload,userService) { +//var users=[] $scope.displayForm = false; this.array = ['Gujarat', 'Maharashtra', 'Uttarakhand']; this.Myobject = { @@ -70,22 +166,32 @@ function addController($http,$scope,fileUpload) { Maharashtra: ["Mumbai", "pune", "Aurangabad"], Uttarakhand: ["Haridwar", "Hrishikesh", "Mussorie"] }; + this.getUser = function () { $scope.users = []; - $http.get('http://localhost:8001/api/user').then(function (d) { - console.log(d); - for (i in d.data) { - $scope.users[i] = d.data[i]; - } - - }, function (err) { - console.log(err); - } - ); + userService.getUser() + .then(function(d){ + $scope.users= angular.copy[d]; + $scope.users=d; + }); }; + $scope.deleteItem = function (data) { + + var modalOptions = { + closeButtonText: 'Cancel', + actionButtonText: 'Delete the user', + headerText: 'Delete ', + bodyText: 'Are you sure you want to delete' + }; + + modalService.showModal({}, modalOptions) + .then(function (result) { + //your-custom-logic + }); + } this.editItem = function (data) { $scope.user = []; $http.get('http://localhost:8001/api/user/' + data).then(function (d) { @@ -99,6 +205,14 @@ function addController($http,$scope,fileUpload) { // $scope.employee = data; $scope.displayForm = true; }; + + this.deleteitem=function(data){ + $http + .delete("http://localhost:8001/api/user/"+data); + this.getUser() + }; + + this.addUser = function () { $http({ url: 'http://localhost:8001/api/user', @@ -124,7 +238,7 @@ function addController($http,$scope,fileUpload) { fileUpload.uploadFileToUrl(file, uploadUrl); } } -} + /*.directive('fileModel', ['$parse', function ($parse) { return { restrict: 'A', @@ -144,10 +258,10 @@ function addController($http,$scope,fileUpload) { - /*this.saveitem=function(data1){ - console.log(data1); + this.saveitem=function(data){ + console.log(data); $http({ - url: 'http://localhost:8001/api/user/'+data1, + url: 'http://localhost:8001/api/user/'+data, method: 'POST', data: { 'name': $scope.user.name, @@ -155,14 +269,92 @@ function addController($http,$scope,fileUpload) { 'state': $scope.user.state, 'city': $scope.user.city, 'gender': $scope.user.gender, - 'daterange': $scope.user.date, + 'daterange': $scope.user.Dob, 'active': $scope.active - //'dob': $scope.newprofile.dob, - //'stateid': $scope.newprofile.stateid, - //'cityid': $scope.newprofile.cityid, - //'profileimg': $scope.newprofile.profileimg, - //'status': $scope.newprofile.status - }}) + }}); + $scope.users = []; + userService.getUser() + .then(function(d){ + $scope.users=d; + }); + + }} + +/* +angular.module('app1', ['ui.bootstrap'])*/ + + + +/*var modalController = function ($scope, $uibModalInstance) { + $scope.yes = function() { + $uibModalInstance.close(); + }; + + $scope.cancel = function() { + $uibModalInstance.dismiss('cancel'); + }; +}; + +modalController.$inject = ['$scope', '$uibModalInstance'];*/ +/* +function MyModalController($uibModalInstance, items) { + var vm = this; + vm.content = items; + vm.confirm = $uibModalInstance.close; + vm.cancel = $uibModalInstance.dismiss; +}; + +function modalTriggerDirective($myModal) { + function postLink(scope, iElement, iAttrs) { + function onClick() { + var size = scope.$eval(iAttrs.size) || 'lg'; // default to large size + var title = scope.$eval(iAttrs.title) || 'Default Title'; + var message = scope.$eval(iAttrs.message) || 'Default Message'; + $myModal.open(size, title, message); + } + iElement.on('click', onClick); + scope.$on('$destroy', function() { + iElement.off('click', onClick); + }); + } + + return { + link: postLink + }; +} + +function myModalFactory($uibModal) { + var open = function (size, title, message) { + return $uibModal.open({ + controller: 'MyModalController', + controllerAs: 'vm', + templateUrl: 'templates/CustomModal.html', + size: size, + resolve: { + items: function () { + return { + title: title, + message: message + }; + } + } + }); + }}; +var modalScope = $scope.$new(); + +/!* +var modalInstance = $uibModal.open({ + templateUrl: 'foo-as-modal.html', + controller: 'fooController', + scope: modalScope +}); +*!/ - }*/ +modalScope.modalInstance = modalInstance; +/!*var modalInstance = $uibModal.open({ + animation: true, + templateUrl: '../Template/ConfirmForm.tpl.html', + controller: modalController, +});*!/ +*/ diff --git a/Angular_Full_Project_GULP/js/routes.js b/Angular_Full_Project_GULP/js/routes.js index 59bdd00..ad3e5b4 100644 --- a/Angular_Full_Project_GULP/js/routes.js +++ b/Angular_Full_Project_GULP/js/routes.js @@ -56,13 +56,22 @@ angular ncyBreadcrumb: { label: 'Add your Profile' } + + }) + .state('app.modal', { + url: '/modal', + templateUrl: 'views/modal.html', + ncyBreadcrumb: { + label: 'Add your Profile' + } + }) .state('app.main', { url: '/dashboard', templateUrl: 'views/main.html', //page title goes here ncyBreadcrumb: { - label: 'Home', + label: 'Home' }, //page subtitle goes here params: { subtitle: 'Welcome to Real Bootstrap 4 Admin Template' }, diff --git a/Angular_Full_Project_GULP/views/add.html b/Angular_Full_Project_GULP/views/add.html index 3718836..c98f121 100644 --- a/Angular_Full_Project_GULP/views/add.html +++ b/Angular_Full_Project_GULP/views/add.html @@ -1,13 +1,15 @@ + -
+
+

Add your post

@@ -91,12 +93,16 @@

Add your post

- +
+ + @@ -119,7 +125,6 @@

Add your post

+ + {{user.name}}
-
+ + \ No newline at end of file diff --git a/Angular_Full_Project_GULP/views/modal.html b/Angular_Full_Project_GULP/views/modal.html new file mode 100644 index 0000000..37f10e2 --- /dev/null +++ b/Angular_Full_Project_GULP/views/modal.html @@ -0,0 +1,12 @@ + + + \ No newline at end of file