| {{globals | json}} | |
| "data": { | |
| "data": [ | |
| { | |
| "id": "1", | |
| "crop_year": "2015", | |
| "season": "S" | |
| } | |
| ] | |
| }, | |
| "status": 200, | |
| "config": { | |
| "method": "GET", | |
| "transformRequest": [ | |
| null | |
| ], | |
| "transformResponse": [ | |
| null | |
| ], | |
| "url": "http://api.lenda.local:6500/api/globals", | |
| "headers": { | |
| "Accept": "application/json, text/plain, */*" | |
| }, | |
| "cached": false | |
| }, | |
| "statusText": "OK" | |
| } | |
| // controllers/main.js | |
| (function(){ | |
| 'use strict'; | |
| angular.module('ARM') | |
| .controller('MainController', function($scope, $state, GlobalsFactory){ | |
| GlobalsFactory.getGlobals().then(function success(response){ | |
| $scope.globals = response; | |
| }); | |
| }); | |
| })(); | |
| // services/globals.js | |
| (function(){ | |
| 'use strict'; | |
| angular.module('ARM') | |
| .factory('GlobalsFactory', function GlobalsFactory($http, API_URL){ | |
| return { | |
| getGlobals: getGlobals | |
| }; | |
| function getGlobals(){ | |
| return $http.get(API_URL + '/globals') | |
| .success(function(data){ | |
| angular.forEach(data, function(obj, index){ | |
| obj.today = moment().format("MM/DD/YYYY"); | |
| obj.forward3Days = moment().add(72, 'hours').format("MM/DD/YYYY"); | |
| obj.forward14Days = moment().add(14, 'days').format("MM/DD/YYYY"); | |
| obj.CY = parseInt(obj.crop_year); | |
| obj.PY1 = obj.CY - 1; | |
| obj.PY2 = obj.CY - 2; | |
| obj.PY3 = obj.CY - 3; | |
| obj.PY4 = obj.CY - 4; | |
| obj.PY5 = obj.CY - 5; | |
| obj.PY6 = obj.CY - 6; | |
| }); | |
| return obj; | |
| }); | |
| } | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment