Created
August 16, 2013 17:46
-
-
Save josephwegner/6251949 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Schedule Controller | |
PlanApp.controller "ScheduleCtrl", ($scope, api, $filter) -> | |
$scope.page = "schedule" | |
deals = [] | |
stages = [] | |
api.stages.getAll (err, data) -> | |
if err | |
console.log err | |
return false | |
for stage in data.data | |
stages[stage.id] = stage | |
if deals.length | |
console.log buildDeals | |
buildDeals() | |
api.deals.getAll (err, data) -> | |
if err | |
console.log err | |
return false | |
deals = data.data | |
if stages.length | |
console.log buildDeals | |
buildDeals() | |
$scope.employees = {} | |
$scope.availableEmployees = [ | |
"Schuyler" | |
"Chris" | |
"Joe" | |
"Nato" | |
"Mark" | |
"John" | |
"Jenny" | |
"Kendal" | |
"Nick" | |
] | |
$scope.filteredEmployees = {} | |
$scope.modals = | |
create: false | |
update: false | |
## Scope Functions | |
$scope.removeEvent = (event) -> | |
api.events.remove event['_id'], (err) -> | |
if err | |
console.log err | |
else | |
$scope.pollEvents = true | |
$scope.eventUpdate = (events) -> | |
$scope.editableEvents = events | |
$scope.modals.update = true | |
$scope.filterAllEmployees = () -> | |
for emp in $scope.availableEmployees | |
$scope.filteredEmployees[emp] = true | |
$scope.filterAllEmployees() | |
$scope.getMonthlyEvents = (dateHash, skipCache, cb) -> | |
api.events.get dateHash, cb, skipCache | |
$scope.setCurrentDeal = (deal) -> | |
$scope.currentDeal = deal | |
$scope.createSchedule = (startDate, endDate) -> | |
$scope.schStart = startDate | |
$scope.schEnd = endDate | |
$scope.modals.create = true | |
$scope.saveSchedule = () -> | |
$scope.modals.create = false | |
people = [] | |
for emp, include of $scope.employees | |
console.log emp, include | |
if include | |
people.push emp | |
$scope.employees = {} | |
api.events.create | |
start: $scope.schStart.getTime() | |
end: $scope.schEnd.getTime() | |
people: people | |
title: $scope.currentDeal.name | |
, (error, data) -> | |
if error | |
console.log error | |
else | |
$scope.pollEvents = true | |
## Unscoped Functions ## | |
buildDeals = () -> | |
$scope.deals = [] | |
lowestStage = 99999; | |
for deal in deals | |
if deal['6294897a118c1a2c4d297a24d43dce166c70e6d6']? and deal['6294897a118c1a2c4d297a24d43dce166c70e6d6_until']? | |
start = deal['6294897a118c1a2c4d297a24d43dce166c70e6d6'].split "-" | |
end = deal['6294897a118c1a2c4d297a24d43dce166c70e6d6_until'].split "-" | |
startDate = new Date start[0], start[1]-1, start[2] | |
endDate = new Date end[0], end[1]-1, end[2] | |
if !$scope.deals[deal.stage_id]? | |
$scope.deals[deal.stage_id] = | |
name: stages[deal.stage_id].name | |
deals: [] | |
if deal.stage_id < lowestStage | |
lowestStage = deal.stage_id | |
$scope.deals[deal.stage_id].deals.push | |
name: deal.title | |
start: startDate | |
end: endDate | |
$scope.currentDeal = $scope.deals[lowestStage][0] | |
deals = [] | |
return true | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PlanApp.controller("ScheduleCtrl", function($scope, api, $filter) { | |
var buildDeals, deals, stages; | |
$scope.page = "schedule"; | |
deals = []; | |
stages = []; | |
api.stages.getAll(function(err, data) { | |
var stage, _i, _len, _ref; | |
if (err) { | |
console.log(err); | |
return false; | |
} | |
_ref = data.data; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
stage = _ref[_i]; | |
stages[stage.id] = stage; | |
} | |
if (deals.length) { | |
console.log(buildDeals); | |
return buildDeals(); | |
} | |
}); | |
api.deals.getAll(function(err, data) { | |
if (err) { | |
console.log(err); | |
return false; | |
} | |
deals = data.data; | |
if (stages.length) { | |
console.log(buildDeals); | |
return buildDeals(); | |
} | |
}); | |
$scope.employees = {}; | |
$scope.availableEmployees = ["Schuyler", "Chris", "Joe", "Nato", "Mark", "John", "Jenny", "Kendal", "Nick"]; | |
$scope.filteredEmployees = {}; | |
$scope.modals = { | |
create: false, | |
update: false | |
}; | |
$scope.removeEvent = function(event) { | |
return api.events.remove(event['_id'], function(err) { | |
if (err) { | |
return console.log(err); | |
} else { | |
return $scope.pollEvents = true; | |
} | |
}); | |
}; | |
$scope.eventUpdate = function(events) { | |
$scope.editableEvents = events; | |
return $scope.modals.update = true; | |
}; | |
$scope.filterAllEmployees = function() { | |
var emp, _i, _len, _ref, _results; | |
_ref = $scope.availableEmployees; | |
_results = []; | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
emp = _ref[_i]; | |
_results.push($scope.filteredEmployees[emp] = true); | |
} | |
return _results; | |
}; | |
$scope.filterAllEmployees(); | |
$scope.getMonthlyEvents = function(dateHash, skipCache, cb) { | |
return api.events.get(dateHash, cb, skipCache); | |
}; | |
$scope.setCurrentDeal = function(deal) { | |
return $scope.currentDeal = deal; | |
}; | |
$scope.createSchedule = function(startDate, endDate) { | |
$scope.schStart = startDate; | |
$scope.schEnd = endDate; | |
return $scope.modals.create = true; | |
}; | |
$scope.saveSchedule = function() { | |
var emp, include, people, _ref; | |
$scope.modals.create = false; | |
people = []; | |
_ref = $scope.employees; | |
for (emp in _ref) { | |
include = _ref[emp]; | |
console.log(emp, include); | |
if (include) { | |
people.push(emp); | |
} | |
} | |
$scope.employees = {}; | |
return api.events.create({ | |
start: $scope.schStart.getTime(), | |
end: $scope.schEnd.getTime(), | |
people: people, | |
title: $scope.currentDeal.name | |
}, function(error, data) { | |
if (error) { | |
return console.log(error); | |
} else { | |
return $scope.pollEvents = true; | |
} | |
}); | |
}; | |
buildDeals = function() { | |
var deal, end, endDate, lowestStage, start, startDate, _i, _len; | |
$scope.deals = []; | |
lowestStage = 99999; | |
for (_i = 0, _len = deals.length; _i < _len; _i++) { | |
deal = deals[_i]; | |
if ((deal['6294897a118c1a2c4d297a24d43dce166c70e6d6'] != null) && (deal['6294897a118c1a2c4d297a24d43dce166c70e6d6_until'] != null)) { | |
start = deal['6294897a118c1a2c4d297a24d43dce166c70e6d6'].split("-"); | |
end = deal['6294897a118c1a2c4d297a24d43dce166c70e6d6_until'].split("-"); | |
startDate = new Date(start[0], start[1] - 1, start[2]); | |
endDate = new Date(end[0], end[1] - 1, end[2]); | |
if (!($scope.deals[deal.stage_id] != null)) { | |
$scope.deals[deal.stage_id] = { | |
name: stages[deal.stage_id].name, | |
deals: [] | |
}; | |
if (deal.stage_id < lowestStage) { | |
lowestStage = deal.stage_id; | |
} | |
} | |
$scope.deals[deal.stage_id].deals.push({ | |
name: deal.title, | |
start: startDate, | |
end: endDate | |
}); | |
} | |
} | |
$scope.currentDeal = $scope.deals[lowestStage][0]; | |
return deals = []; | |
}; | |
return true; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment