angular.module('kalgudiApp.myconnects').controller('requirementStatsController', ["$scope", "$rootScope", "$http","kalgudiLiterals", "$injector", function($scope, $rootScope, $http, kalgudiLiterals, $injector) { if (!window.detectmob()) { $uibModal = $injector.get("$uibModal"); } $scope.productDisplayLimit = 15; $scope.statsURL = "https://kalgudi.com/rest/v1/misc/postStats"; $scope.dataURL = "https://kalgudi.com/rest/v1/misc/postStats/recentPosts"; $scope.request = { offset : 0, limit : 10 } $scope.dateRange = { from : '', to : '' } /*To initiate the page*/ function init () { /*if(env.isProduction) { getStats(); getPostData(); } else { $scope.requirementStats = {"postCounts":{"totalQuantity":"330","postsCreated":"300","totalQuantityUnit":"Kg","numOfParticipants":"10","numOfproductsInvolved":"25","productsInvolved":["Astral Carrot","Banana Flower","Watermelon","Papaya","Orange","Starfruit","Persimmon","Dwarapudi Sapota"]}} $scope.response = {"recentPosts":[{"loginId":"M010ujr0PRFREG2018041339836594UNH001","name":"Gopal Rao","location":"Krishna, Andhra Pradesh IND","postDetails":{"imageUrl":"https://d3haud5theow5m.cloudfront.net/commodities/000000004018_1.jpg","description":"Want to sell 20 ton of chinna rasalu mango","title":"Want to sell 20 ton of chinna rasalu mango","productName":"Mango"}},{"loginId":"M00py0e0PRFREG2018011252453992UNH001","name":"Sri Ramakrishna CPC","location":"West Godavari, Andhra Pradesh IND","postDetails":{"imageUrl":"https://d3haud5theow5m.cloudfront.net/commodities/000000004109_1.jpg","description":"Want to sell 5000 numbers of Coconut","title":"Want to sell 5000 numbers of Coconut","productName":"Coconut"}},{"loginId":"M010ujk0PRFREG2018041334344940UNH001","name":"Suraksha horti solutions","location":"Krishna, Andhra Pradesh IND","postDetails":{"description":"Fruit cover and mulching sheets","title":"Fruit cover and mulching sheets"}},{"loginId":"M010ujk0PRFREG2018041334344940UNH001","name":"Suraksha horti solutions","location":"Krishna, Andhra Pradesh IND","postDetails":{"description":"Fruit cover and mulching sheets","title":"Fruit cover and mulching sheets"}},{"loginId":"M010ujk0PRFREG2018041334344940UNH001","name":"Suraksha horti solutions","location":"Krishna, Andhra Pradesh IND","postDetails":{"description":"Fruit cover and mulching sheets","title":"Fruit cover and mulching sheets"}},{"loginId":"M010ujh0PRFREG2018041328596004UNH001","name":"Pelican Transcontinental","location":"Chennai, Tamil Nadu IND","postDetails":{"description":"Rice, Icumsa 45 Sugar,Raw Brown Sugar, Palm Oil, Iron ore, Coal & Used Cooking Oil","title":"Rice, Icumsa 45 Sugar,Raw Brown Sugar, Palm Oil, Iron ore, Coal & Used Cooking Oil"}},{"loginId":"M010ujb0PRFREG2018041324498428UNH001","name":"Kanakaparthi Bhaskara rao","location":"Khammam, Andhra Pradesh IND","postDetails":{"imageUrl":"https://d3haud5theow5m.cloudfront.net/commodities/000000038245_1.jpg","description":"Want to sell 8 ton of Purely Organic Totapuri Mango","title":"Want to sell 8 ton of Purely Organic Totapuri Mango","productName":"Totapuri"}},{"loginId":"M010ujc0PRFREG2018041325675177UNH001","name":"Rajesh","location":"Krishna, Andhra Pradesh IND","postDetails":{"imageUrl":"https://d3haud5theow5m.cloudfront.net/commodities/000000004018_1.jpg","description":"Want to sell 15 ton of purely organic suwarnarekha Mango","title":"Want to sell 15 ton of purely organic suwarnarekha Mango","productName":"https://d3haud5theow5m.cloudfront.net/commodities/000000004018_1.jpg"}},{"loginId":"M010ujb0PRFREG2018041324498428UNH001","name":"Kanakaparthi Bhaskara rao","location":"Khammam, Andhra Pradesh IND","postDetails":{"imageUrl":"https://d3haud5theow5m.cloudfront.net/commodities/000000004025_1.jpg","description":"Want to sell 10 ton of Purely Organic Banganpalli Mango","title":"Want to sell 10 ton of Purely Organic Banganpalli Mango","productName":"Banganpalli"}},{"loginId":"M010ujb0PRFREG2018041324498428UNH001","name":"Kanakaparthi Bhaskara rao","location":"Khammam, Andhra Pradesh IND","postDetails":{"imageUrl":"https://d3haud5theow5m.cloudfront.net/commodities/000000004018_1.jpg","description":"Want to sell 15 ton of Sundhari Mango","title":"Want to sell 15 ton of Sundhari Mango","productName":"Mango"}}]} $scope.postCounts = $scope.requirementStats.postCounts || {}; $scope.businessRequirements = $scope.response.recentPosts || {}; }*/ } /*To get post stats data*/ function getStats () { $rootScope.spinerisActive = true; // var URL = $scope.statsURL + '?fromDate=' + $scope.dateRange.from + "&toDate=" + $scope.dateRange.to; var URL = $scope.statsURL + '?searchString=' + $scope.query; $http.get(URL).then(function(result) { $rootScope.spinerisActive = false; if(result.data.code == 200) { $scope.requirementStats = result.data.data || {}; $scope.postCounts = $scope.requirementStats.postCounts || {}; } }, function(error) { $rootScope.spinerisActive = false; console.log("Unable to fetch stats", error); }); } /*To get recent posts*/ function getPostData () { $rootScope.spinerisActive = true; var URL = $scope.dataURL + '?searchString=' + $scope.query + '&offset=' + $scope.request.offset + "&limit=" + $scope.request.limit; $http.get(URL).then(function(result) { $rootScope.spinerisActive = false; if(result.data.code == 200) { $scope.response = result.data.data || {}; $scope.businessRequirements = $scope.response.recentPosts || {}; } }, function(error) { $rootScope.spinerisActive = false; console.log("Unable to fetch recent posts", error); }); } /*To load new data on table*/ $scope.loadMore = function (loadType) { if(loadType == 'Next') { $scope.request.offset += $scope.request.limit; } else { $scope.request.offset -= $scope.request.limit; } getPostData(); } /*Date picker configurations*/ var today = new Date(); $scope.endDate = today; $scope.ExpireDate =today; $scope.dateFormat = 'dd-MMM-yy'; $scope.selectedMessageId = ""; $scope.rangeDate = { fromDate : '', toDate : '' } $scope.availableDateOptionsForToDate = { formatYear: 'yy', startingDay: 1, minDate: new Date(1995, 5, 22), maxDate: today }; $scope.expireDateOptionsForToDate = { formatYear: 'yy', startingDay: 1, minDate: today, maxDate: new Date(2030, 5, 22) }; $scope.availableDatePopupForToDate = { opened : false } $scope.availableDatePopupForFromDate = { opened : false } $scope.availableDateOptionsForFromDate = { formatYear: 'yy', startingDay: 1, minDate: new Date(1995, 5, 22), maxDate: today }; $scope.expireDateOptionsForFromDate = { formatYear: 'yy', startingDay: 1, minDate: today, maxDate: new Date(2030, 5, 22) }; $scope.OpenAvailableDateForToDate = function() { $scope.availableDatePopupForToDate.opened = !$scope.availableDatePopupForToDate.opened; }; $scope.OpenAvailableDateForFromDate = function() { $scope.availableDatePopupForFromDate.opened = !$scope.availableDatePopupForFromDate.opened; }; $scope.ChangeDateForFromDate = function(){ $scope.selectedMessageId = ""; $scope.availableDateOptionsForToDate.minDate = $scope.rangeDate.fromDate; /*$scope.getMetricsData();*/ } $scope.ChangeDateForToDate = function(){ $scope.selectedMessageId = ""; $scope.availableDateOptionsForFromDate.maxDate = $scope.rangeDate.toDate; /*$scope.getMetricsData();*/ } $scope.getStats = function() { $scope.dateRange.from = $scope.rangeDate.fromDate ? JSON.stringify($scope.rangeDate.fromDate) : ''; $scope.dateRange.to = $scope.rangeDate.toDate ? JSON.stringify($scope.rangeDate.toDate) : ''; getStats(); getPostData(); } $scope.setQuery = function(query) { $scope.query = query; } $scope.showFullView = function(imageUrl) { var object = { url : imageUrl } var modalInstance = $uibModal.open({ templateUrl: $rootScope.themebasepathvalue+'newsFeed/shareAthoughtFullview.html', controller: 'sharefullviewController', size: 'md', windowClass:'share-full', resolve: { items: function () { return object; } } }); } init(); } ]);