Files
memory-infrastructure-palace/docs/projects/memorypalace/Apple Notes/angular.module('crSummariesController', )..md

20 KiB

controller('crSummariesController', function($scope, $http, $rootScope, $sce, $timeout, cr, $q, ) { $rootScope.sidebar = false; $rootScope.rightSidebar = false; $scope.returnedResults = []; //console.log();

var self = this;

Date.prototype.outputUTC = function() {

<span style="color:#000ff;">return Date.UTC(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds(), this.getMilliseconds());</span>

};

self.Initialise = function() { $scope.allresults = []; $scope.summaries = { timeframe: 'Today', workType: 'count', }; $scope.Math = Math;

<span style="color:#000ff;">grabAppData('machine-profile', $rootScope.factoryKey).then(function(machineData) {</span>
  <span style="color:#000ff;">grabAppData('shift-profile', $rootScope.factoryKey).then(function(shiftData) {</span>
    <span style="color:#000ff;">//console.log(machineData);</span>
    <span style="color:#000ff;">//console.log($scope.machineObj);</span>
    <span style="color:#000ff;">$scope.shiftsObj = shiftData;</span>
    <span style="color:#000ff;">angular.forEach($scope.machineObj, function(value, key) {</span>
      <span style="color:#000ff;">value.machineQueries = {};</span>
      <span style="color:#000ff;">value.machineQueries.shiftInfo = [];</span>
      <span style="color:#000ff;">value.machineQueries.workTotal = {</span>
        <span style="color:#000ff;">count: 0,</span>
        <span style="color:#000ff;">timer: 0,</span>
      <span style="color:#000ff;">};</span>
      <span style="color:#000ff;">angular.forEach(machineData, function(profile, machineKey) {</span>
        <span style="color:#000ff;">if (value.Address === profile.remoteAddr) {</span>
          <span style="color:#000ff;">value.machineQueries.machineInfo = profile;</span>
        <span style="color:#000ff;">}</span>
      <span style="color:#000ff;">});</span>
      <span style="color:#000ff;">value.machineQueries.shifts = {};</span>
      <span style="color:#000ff;">tempVar = 0;</span>
      <span style="color:#000ff;">angular.forEach(shiftData, function(shiftProfile, theKeys) {</span>
        <span style="color:#000ff;">value.machineQueries.shifts[tempVar] = {</span>
          <span style="color:#000ff;">name: shiftProfile.name,</span>
          <span style="color:#000ff;">sum: {</span>
            <span style="color:#000ff;">count: '0',</span>
            <span style="color:#000ff;">timer: '0',</span>
          <span style="color:#000ff;">}</span>
        <span style="color:#000ff;">};</span>
        <span style="color:#000ff;">tempVar++;</span>
        <span style="color:#000ff;">angular.forEach(shiftProfile.machines, function(machines, macKeys) {</span>
          <span style="color:#000ff;">if (value.Address === macKeys) {</span>
            <span style="color:#000ff;">value.machineQueries.shiftInfo.push(shiftProfile);</span>
          <span style="color:#000ff;">}</span>
        <span style="color:#000ff;">});</span>
      <span style="color:#000ff;">});</span>
      <span style="color:#000ff;">//console.log($scope.machineObj);</span>
    <span style="color:#000ff;">});</span>
    <span style="color:#000ff;">//console.log($scope.machineObj);</span>
  <span style="color:#000ff;">}, function(error) {</span>
    <span style="color:#000ff;">console.log('Failure...', error);</span>
  <span style="color:#000ff;">});</span>
<span style="color:#000ff;">}, function(error) {</span>
  <span style="color:#000ff;">console.log('Failure...', error);</span>
<span style="color:#000ff;">});</span>

};

$scope.enableWarMachine = function() { $scope.shiftC = 0; alert('You have been warned!'); //console.log($scope.machineObj); var daysOfWeek = { "sunday": 0, "monday": 1, "tuesday": 2, "wednesday": 3, "thursday": 4, "friday": 5, "saturday": 6 }; var inverseDaysOfWeek = { 0: "sunday", 1: "monday", 2: "tuesday", 3: "wednesday", 4: "thursday", 5: "friday", 6: "saturday", }; // $scope.reporting.machineSelect.SoftwareKey, $scope.reporting.machineSelect.Address, // processObj, Math.floor(new Date(d) / 1000), Math.floor(new Date(da) / 1000), // $scope.reporting.hardware // console.log('http://54.213.13.56/api/' + value.SoftwareKey + '/' + value.Address + // '?process[]=' + 'sum' + '&date[]=' + startDate / 1000 + '&date[]=' + endDate / 1000 + '&index=' + // value.machineQueries.machineInfo.inputSelected);

<span style="color:#000ff;">// endDate = new Date();</span>
<span style="color:#000ff;">// startDate = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate(), 0, 0, 0, 0);</span>
<span style="color:#000ff;">// endDate = new Date(startDate.getFullYear(), startDate.getMonth(), endDate.getDate(), 23, 59, 59, 0);</span>
<span style="color:#000ff;">endDate = new Date(1436846399000);</span>
<span style="color:#000ff;">startDate = new Date(1436760000000);</span>
<span style="color:#000ff;">angular.forEach($scope.machineObj, function(value, key) {</span>

  <span style="color:#000ff;">webCall(value.SoftwareKey, value.Address, 'sum', startDate / 1000, endDate / 1000, value.machineQueries.machineInfo.inputSelected).then(function(data) {</span>
    <span style="color:#000ff;">value.machineQueries.workTotal.count = data.sum.count;</span>
    <span style="color:#000ff;">value.machineQueries.workTotal.timer = Math.round((data.sum.timer / 60) * 10) / 10;</span>
    <span style="color:#000ff;">//console.log(value);</span>
  <span style="color:#000ff;">});</span>
<span style="color:#000ff;">});</span>
<span style="color:#000ff;">//var defer;</span>


<span style="color:#000ff;">machineCounter = 0;</span>


<span style="color:#000ff;">function callShifts(machineCount) {</span>
  <span style="color:#000ff;">if (machineCount < $scope.machineObj.length - 1) {</span>
    <span style="color:#000ff;">shiftsCounter = 0;</span>
    <span style="color:#000ff;">var tempCount = 0;</span>
    <span style="color:#000ff;">$scope.counter = 0;</span>
    <span style="color:#000ff;">recurseShifts(shiftsCounter, machineCount, tempCount);</span>
    <span style="color:#000ff;">//console.log($scope.machineObj[machineCount].Name);</span>






    <span style="color:#000ff;">machineCount++;</span>
    <span style="color:#000ff;">callShifts(machineCount);</span>
  <span style="color:#000ff;">} else {</span>
    <span style="color:#000ff;">console.log($scope.returnedResults);</span>
  <span style="color:#000ff;">}</span>
<span style="color:#000ff;">}</span>

<span style="color:#000ff;">function recurseShifts(shiftCounter, machineCount, tmpCnt) {</span>
  <span style="color:#000ff;">//console.log(tmpCnt)</span>
  <span style="color:#000ff;">if (shiftCounter <= $scope.machineObj[machineCount].machineQueries.shiftInfo.length - 1) {</span>
    <span style="color:#000ff;">//console.log($scope.machineObj[machineCount].machineQueries.shiftInfo[shiftCounter].name);</span>
    <span style="color:#000ff;">shiftDaysCounter = 0;</span>
    <span style="color:#000ff;">weeklyCounter = 0;</span>
    <span style="color:#000ff;">recurseDays(shiftDaysCounter, weeklyCounter, shiftCounter, machineCount, tmpCnt);</span>


    <span style="color:#000ff;">$scope.counter = 0;</span>
    <span style="color:#000ff;">shiftCounter++;</span>
    <span style="color:#000ff;">recurseShifts(shiftCounter, machineCount, tmpCnt);</span>
  <span style="color:#000ff;">}</span>
<span style="color:#000ff;">}</span>

<span style="color:#000ff;">function recurseDays(shiftC, weekC, shiftyCounter, machineyCount, tmp) {</span>
  <span style="color:#000ff;">//console.log(_.size($scope.machineObj[machineyCount].machineQueries.shiftInfo[shiftyCounter].days));</span>
  <span style="color:#000ff;">//if (shiftC <= _.size($scope.machineObj[machineyCount].machineQueries.shiftInfo[shiftyCounter].days) - 1) {</span>
  <span style="color:#000ff;">if (weekC < _.size(inverseDaysOfWeek) - 1) {</span>
    <span style="color:#000ff;">if ($scope.machineObj[machineyCount].machineQueries.shiftInfo[shiftyCounter].days[inverseDaysOfWeek[weekC]] === true) {</span>
      <span style="color:#000ff;">if (daysOfWeek[inverseDaysOfWeek[weekC]] === startDate.getDay()) {</span>
        <span style="color:#000ff;">// console.log($scope.machineObj[machineyCount].Name);</span>
        <span style="color:#000ff;">// console.log($scope.machineObj[machineyCount].machineQueries.shiftInfo[shiftyCounter].name);</span>
        <span style="color:#000ff;">// console.log(inverseDaysOfWeek[weekC]);</span>
        <span style="color:#000ff;">$scope.shiftC++;</span>
        <span style="color:#000ff;">//console.log($scope.shiftC);</span>

        <span style="color:#000ff;">tempStartTime = new Date($scope.machineObj[machineyCount].machineQueries.shiftInfo[shiftyCounter].startTime);</span>
        <span style="color:#000ff;">tempStartTime = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate(), tempStartTime.getHours(), tempStartTime.getMinutes(), 0, 0);</span>
        <span style="color:#000ff;">tempEndTime = new Date($scope.machineObj[machineyCount].machineQueries.shiftInfo[shiftyCounter].endTime);</span>
        <span style="color:#000ff;">tempEndTime = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate(), tempEndTime.getHours(), tempEndTime.getMinutes(), 0, 0);</span>


        <span style="color:#000ff;">webCall($scope.machineObj[machineyCount].SoftwareKey, $scope.machineObj[machineyCount].Address, 'sum', tempStartTime / 1000, tempEndTime / 1000, $scope.machineObj[machineyCount].machineQueries.machineInfo.inputSelected).then(function(data) {</span>
          <span style="color:#000ff;">data.shiftName = $scope.machineObj[machineyCount].machineQueries.shiftInfo[shiftyCounter].name;</span>
          <span style="color:#000ff;">data.machine = $scope.machineObj[machineyCount].Address;</span>

          <span style="color:#000ff;">$scope.returnedResults.push(data);</span>
          <span style="color:#000ff;">console.log($scope.counter);</span>
          <span style="color:#000ff;">// for (i = 0; i < $scope.machineObj[machineyCount].machineQueries.shiftInfo.length - 1; i++) {</span>
          <span style="color:#000ff;">//   if ($scope.machineObj[machineyCount].machineQueries.shiftInfo[i].name === data.name && $scope.machineObj[machineyCount].machineQueries.machineInfo.remoteAddr === data.machine) {</span>

              <span style="color:#000ff;">$scope.machineObj[machineyCount].machineQueries.shifts[$scope.counter] = data;</span>
          <span style="color:#000ff;">//   }</span>
          <span style="color:#000ff;">// }</span>

          <span style="color:#000ff;">//console.log(data);</span>
          <span style="color:#000ff;">$scope.counter++;</span>
          <span style="color:#000ff;">//console.log($scope.allresults);</span>
        <span style="color:#000ff;">});</span>
      <span style="color:#000ff;">}</span>

    <span style="color:#000ff;">}</span>
    <span style="color:#000ff;">// if(inverseDaysOfWeek[weekC] === $scope.machineObj[machineyCount].machineQueries.shiftInfo[shiftyCounter].days[inverseDaysOfWeek[weekC]]) {</span>
    <span style="color:#000ff;">//   console.log(inverseDaysOfWeek[weekC]);</span>
    <span style="color:#000ff;">// }</span>
    <span style="color:#000ff;">// console.log(inverseDaysOfWeek[weekC]);</span>
    <span style="color:#000ff;">//console.log($scope.machineObj[machineyCount].machineQueries.shiftInfo[shiftyCounter].days[inverseDaysOfWeek[weekC]]);</span>

    <span style="color:#000ff;">weekC++;</span>

    <span style="color:#000ff;">recurseDays(shiftC, weekC, shiftyCounter, machineyCount);</span>

  <span style="color:#000ff;">} else {</span>
    <span style="color:#000ff;">$scope.counter = 0;</span>
  <span style="color:#000ff;">}</span>
  <span style="color:#000ff;">//console.log(shiftC);</span>
  <span style="color:#000ff;">//shiftC++;</span>
  <span style="color:#000ff;">//recurseDays(shiftC, weekC, shiftyCounter, machineyCount);</span>
  <span style="color:#000ff;">//}</span>

<span style="color:#000ff;">}</span>
<span style="color:#000ff;">callShifts(machineCounter);</span>


<span style="color:#000ff;">// angular.forEach($scope.machineObj, function(machine, machineKey) {</span>
<span style="color:#000ff;">//   var tempCount = 0;</span>
<span style="color:#000ff;">//   angular.forEach(machine.machineQueries.shiftInfo, function(shifts, shiftsKey) {</span>
<span style="color:#000ff;">//     //angular.forEach(shifts.days, function(value, key) {</span>
<span style="color:#000ff;">//       angular.forEach($scope.shiftsObj, function(shiftVal, shiftKay) {</span>
<span style="color:#000ff;">//         //if (daysOfWeek[key] === startDate.getDay()) {</span>
<span style="color:#000ff;">//           tempStartTime = new Date(shifts.startTime);</span>
<span style="color:#000ff;">//           tempEndTime = new Date(shifts.endTime);</span>
<span style="color:#000ff;">//           tempStartTime = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate(), tempStartTime.getHours(), tempStartTime.getMinutes(), 0, 0);</span>
<span style="color:#000ff;">//           tempEndTime = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate(), tempEndTime.getHours(), tempEndTime.getMinutes(), 0, 0);</span>
<span style="color:#000ff;">//           if (shifts.name === shiftVal.name) {</span>
<span style="color:#000ff;">//             //defer = $q.defer();</span>
<span style="color:#000ff;">//             webCall(machine.SoftwareKey, machine.Address, 'sum', tempStartTime / 1000, tempEndTime / 1000, machine.machineQueries.machineInfo.inputSelected).then(function(data) {</span>
<span style="color:#000ff;">//               data.name = shifts.name;</span>
<span style="color:#000ff;">//               data.machine = machine.Address;</span>
<span style="color:#000ff;">//               for (i = 0; i < machine.machineQueries.shiftInfo.length - 1; i++) {</span>
<span style="color:#000ff;">//                 if (machine.machineQueries.shiftInfo[i].name === data.name && machine.machineQueries.machineInfo.remoteAddr === data.machine) {</span>
<span style="color:#000ff;">//</span>
<span style="color:#000ff;">//                   machine.machineQueries.shifts[tempCount] = data;</span>
<span style="color:#000ff;">//                 }</span>
<span style="color:#000ff;">//               }</span>
<span style="color:#000ff;">//</span>
<span style="color:#000ff;">//               tempCount++;</span>
<span style="color:#000ff;">//               $scope.allresults.push(data);</span>
<span style="color:#000ff;">//               //machine.machineQueries.shifts.push(data.sum.timer);</span>
<span style="color:#000ff;">//               //console.log(data);</span>
<span style="color:#000ff;">//             });</span>
<span style="color:#000ff;">//           }</span>
<span style="color:#000ff;">//       //}</span>
<span style="color:#000ff;">//         console.log($scope.allresults);</span>
<span style="color:#000ff;">//</span>
<span style="color:#000ff;">//       });</span>
<span style="color:#000ff;">//     //});</span>
<span style="color:#000ff;">//</span>
<span style="color:#000ff;">//</span>
<span style="color:#000ff;">//   });</span>
<span style="color:#000ff;">// });</span>

};

self.log = function(message) { console.log(message); };

self.Initialise();

function grabAppData(appKey, factoryKey) { var defer = $q.defer(); console.log('http://54.213.13.56/api/app/' + appKey + '/' + factoryKey); $http.get('http://54.213.13.56/api/app/' + appKey + '/' + factoryKey). success(function(data) { // console.log(data); if (appKey === 'shift-profile') { angular.forEach(data, function(items, key) { angular.forEach(items.days, function(daySelected, day) { items.days[day] = daySelected == "true"; }); //console.log(data); angular.forEach(items.machines, function(machineSelected, machine) { items.machines[machine] = machineSelected == "true"; });

    <span style="color:#000ff;">});</span>
  <span style="color:#000ff;">}</span>
  <span style="color:#000ff;">defer.resolve(data);</span>
<span style="color:#000ff;">}).error(function(data) {</span>
  <span style="color:#000ff;">console.log('Error in grabAppData: ' + data);</span>
<span style="color:#000ff;">});</span>
<span style="color:#000ff;">return defer.promise;</span>

}

function webCall(softwareKey, address, processObj, startDate, endDate, hardware) { var defer = $q.defer(); console.log('http://54.213.13.56/api/' + softwareKey + '/' + address + '?process[]=' + processObj + '&date[]=' + startDate + '&date[]=' + endDate + '&index=' + hardware);

<span style="color:#000ff;">$http.get('http://54.213.13.56/api/' + softwareKey + '/' + address +</span>
  <span style="color:#000ff;">'?process[]=' + processObj + '&date[]=' + startDate + '&date[]=' + endDate + '&index=' +</span>
  <span style="color:#000ff;">hardware).</span>
<span style="color:#000ff;">success(function(data) {</span>
  <span style="color:#000ff;">//console.log('Data: ' + data);</span>
  <span style="color:#000ff;">defer.resolve(data);</span>
<span style="color:#000ff;">}).</span>
<span style="color:#000ff;">error(function(data) {</span>
  <span style="color:#000ff;">alert(data);</span>
<span style="color:#000ff;">});</span>
<span style="color:#000ff;">return defer.promise;</span>

} });