mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
sync
This commit is contained in:
@ -22,8 +22,9 @@ angular.module('biomed', ['biomed.filters', 'biomed.services', 'biomed.directive
|
||||
data = data.replace(PROTECTION_PREFIX, '');
|
||||
if (JSON_START.test(data) && JSON_END.test(data)) {
|
||||
data = JSON.parse(data, function(key, val) {
|
||||
if (DATE_MATCHER.test(val))
|
||||
return new Date(val);
|
||||
if (DATE_MATCHER.test(val)) {
|
||||
return new moment(val).zone(-5).toDate();
|
||||
}
|
||||
return val;
|
||||
})
|
||||
}
|
||||
@ -68,6 +69,15 @@ angular.module('biomed', ['biomed.filters', 'biomed.services', 'biomed.directive
|
||||
templateUrl: '/partials/workorders/edit.html',
|
||||
controller: biomed.WorkorderEditCtrl
|
||||
})
|
||||
.when('/techs/:id', {
|
||||
templateUrl: '/partials/techs/schedule.html',
|
||||
controller: biomed.TechScheduleCtrl
|
||||
})
|
||||
.when('/admin', {
|
||||
templateUrl: '/partials/users/index.html',
|
||||
controller: biomed.UsersIndexCtrl,
|
||||
reloadOnSearch: false
|
||||
})
|
||||
.otherwise({
|
||||
redirectTo: '/schedule'
|
||||
});
|
||||
|
@ -1,5 +1,29 @@
|
||||
biomed.AccountCtrl = function($scope, Account) {
|
||||
$scope.account = Account.get();
|
||||
|
||||
biomed.TechScheduleCtrl = function($scope, $routeParams, $location, Schedule, Users, LocationBinder) {
|
||||
|
||||
if (!$scope.date) {
|
||||
$scope.date = new Date();
|
||||
}
|
||||
|
||||
Users.index({userid: $routeParams.id}, function(result) {
|
||||
$scope.tech = result[0];
|
||||
});
|
||||
|
||||
$scope.$watch('date', updateDate);
|
||||
|
||||
$scope.onEntryClick = function(entry) {
|
||||
$location.path('/workorders/' + entry.workorder._id);
|
||||
};
|
||||
|
||||
function updateDate() {
|
||||
Schedule.index({
|
||||
tech: $routeParams.id,
|
||||
start: $scope.date.toJSON(),
|
||||
end: moment($scope.date).add('days', 7).toDate().toJSON()
|
||||
}, function(result) {
|
||||
$scope.schedule = result;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
biomed.ScheduleIndexCtrl = function($scope, $location, Users, Schedule, LocationBinder) {
|
||||
@ -64,6 +88,90 @@ biomed.SchedulePmsCtrl = function($scope, Clients) {
|
||||
$scope.$watch('month', filter);
|
||||
};
|
||||
|
||||
biomed.UsersIndexCtrl = function($scope, $filter, $routeParams, $location, Users, LocationBinder) {
|
||||
$scope.loading = true;
|
||||
|
||||
$scope.account.$then(function(value) {
|
||||
if (!$scope.accountHasPermission('system.admin'))
|
||||
return $location.path('/');
|
||||
});
|
||||
|
||||
|
||||
var allData = Users.details(function() {
|
||||
$scope.loading = false;
|
||||
$scope.filter();
|
||||
});
|
||||
|
||||
var filteredData = [];
|
||||
var index = 0;
|
||||
var initialPageSize = 100;
|
||||
var pageSize = 5;
|
||||
|
||||
$scope.canLoad = true;
|
||||
$scope.$watch('query', function() {
|
||||
$scope.filter();
|
||||
});
|
||||
|
||||
LocationBinder($scope, ['query']);
|
||||
|
||||
$scope.filter = function() {
|
||||
filteredData = $filter('filter')(allData, $scope.query);
|
||||
index = initialPageSize;
|
||||
$scope.canLoad = true;
|
||||
$scope.users = filteredData.slice(0, initialPageSize);
|
||||
};
|
||||
|
||||
$scope.addItems = function() {
|
||||
$scope.users = $scope.users.concat(filteredData.slice(index, index + pageSize));
|
||||
index += pageSize;
|
||||
$scope.canLoad = index < filteredData.length;
|
||||
};
|
||||
|
||||
function save(user) {
|
||||
if ('_id' in user) {
|
||||
Users.update({id: user._id}, user, function(result) {
|
||||
angular.copy(result, user);
|
||||
});
|
||||
} else {
|
||||
Users.create(user, function(result) {
|
||||
angular.copy(result, user);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$scope.toggleGroup = function(user, group) {
|
||||
var index = user.groups.indexOf(group);
|
||||
if (index > -1)
|
||||
user.groups.splice(index, 1);
|
||||
else
|
||||
user.groups.push(group);
|
||||
|
||||
save(user);
|
||||
}
|
||||
|
||||
$scope.checkGroup = function(user, group) {
|
||||
return $.inArray(group, user.groups) > -1;
|
||||
};
|
||||
|
||||
$scope.togglePerm = function(user, perm) {
|
||||
var index = user.perms.indexOf(perm);
|
||||
if (index > -1)
|
||||
user.perms.splice(index, 1);
|
||||
else
|
||||
user.perms.push(perm);
|
||||
|
||||
save(user);
|
||||
};
|
||||
|
||||
$scope.checkPerm = function(user, perm) {
|
||||
return $.inArray(perm, user.perms) > -1;
|
||||
};
|
||||
|
||||
$scope.isNew = function(user) {
|
||||
return !('_id' in user);
|
||||
};
|
||||
};
|
||||
|
||||
biomed.ClientIndexCtrl = function($scope, $filter, $routeParams, Clients, LocationBinder) {
|
||||
$scope.loading = true;
|
||||
|
||||
@ -295,13 +403,21 @@ biomed.WorkorderIndexCtrl = function($scope, $filter, $routeParams, Workorders,
|
||||
|
||||
biomed.WorkorderAddCtrl = function($scope, $location, Workorders, Schedule, Clients, Users) {
|
||||
|
||||
$scope.emailsOptions = {
|
||||
'multiple': true,
|
||||
'simple_tags': true,
|
||||
'tags': [],
|
||||
'formatNoMatches': function() { return 'Type an e-mail address and press return to add it.'; }
|
||||
};
|
||||
|
||||
$scope.group = 'all';
|
||||
$scope.model = {};
|
||||
$scope.picker = {
|
||||
start: '09:00:00',
|
||||
end: '17:00:00'
|
||||
startTime: '09:00:00',
|
||||
endTime: '09:45:00'
|
||||
};
|
||||
$scope.picker.date = new Date();
|
||||
$scope.picker.startDate = new Date();
|
||||
$scope.picker.endDate = new Date();
|
||||
|
||||
var search = $location.search();
|
||||
|
||||
@ -311,6 +427,13 @@ biomed.WorkorderAddCtrl = function($scope, $location, Workorders, Schedule, Clie
|
||||
$scope.model.maintenanceType = search.type;
|
||||
|
||||
$scope.workorderType = 'pm';
|
||||
} else if (search.workorderType == "meeting") {
|
||||
$scope.model.reason = "Meeting";
|
||||
$scope.workorderType = 'meeting';
|
||||
|
||||
if (search.clientId) {
|
||||
$scope.model.client = search.clientId;
|
||||
}
|
||||
} else {
|
||||
if (search.clientId) {
|
||||
$scope.model.client = search.clientId;
|
||||
@ -334,23 +457,94 @@ biomed.WorkorderAddCtrl = function($scope, $location, Workorders, Schedule, Clie
|
||||
$scope.clients = result;
|
||||
});
|
||||
|
||||
$scope.$watch('picker.date', function() {
|
||||
function convertToDate(date, time) {
|
||||
return moment(moment(date).format('YYYY-MM-DD') + 'T' + time).toDate();
|
||||
}
|
||||
|
||||
function datesOverlap() {
|
||||
var start = convertToDate($scope.picker.startDate, $scope.picker.startTime);
|
||||
var end = convertToDate($scope.picker.endDate, $scope.picker.endTime);
|
||||
return start >= end;
|
||||
}
|
||||
|
||||
function updateDuration() {
|
||||
var start = convertToDate($scope.picker.startDate, $scope.picker.startTime);
|
||||
var end = convertToDate($scope.picker.endDate, $scope.picker.endTime);
|
||||
|
||||
var duration = moment.duration(end - start);
|
||||
|
||||
var days = duration.days()
|
||||
var hours = duration.hours();
|
||||
var minutes = duration.minutes();
|
||||
|
||||
var result = "";
|
||||
|
||||
if (days == 1) {
|
||||
result += "1 Day ";
|
||||
}
|
||||
if (days > 1) {
|
||||
result += days + " Days ";
|
||||
}
|
||||
if (hours == 1) {
|
||||
result += "1 Hour ";
|
||||
}
|
||||
if (hours > 1) {
|
||||
result += hours + " Hours ";
|
||||
}
|
||||
if (minutes > 0) {
|
||||
result += minutes + " Minutes";
|
||||
}
|
||||
|
||||
$scope.picker.duration = result;
|
||||
}
|
||||
|
||||
|
||||
$scope.$watch('picker.startDate', function() {
|
||||
Schedule.index({
|
||||
date: $scope.picker.date.toJSON()
|
||||
date: $scope.picker.startDate.toJSON()
|
||||
}, function(result) {
|
||||
$scope.schedule = result;
|
||||
});
|
||||
|
||||
if (datesOverlap()) {
|
||||
$scope.picker.endDate = $scope.picker.startDate;
|
||||
}
|
||||
updateDuration();
|
||||
});
|
||||
|
||||
$scope.save = function() {
|
||||
$scope.$watch('picker.endDate', function() {
|
||||
if (datesOverlap()) {
|
||||
$scope.picker.startDate = $scope.picker.endDate;
|
||||
}
|
||||
updateDuration();
|
||||
});
|
||||
|
||||
$scope.$watch('picker.startTime', function() {
|
||||
$scope.picker.endTime = moment($scope.picker.startTime, "HH:mm:ss").add('minutes', 45).format("HH:mm:ss");
|
||||
$scope.picker.endDate = $scope.picker.startDate;
|
||||
updateDuration();
|
||||
});
|
||||
|
||||
$scope.$watch('picker.endTime', function() {
|
||||
if (datesOverlap()) {
|
||||
$scope.picker.startTime = moment($scope.picker.endTime, "HH:mm:ss").subtract('minutes', 15).format("HH:mm:ss");
|
||||
}
|
||||
updateDuration();
|
||||
});
|
||||
|
||||
$scope.save = function(notify) {
|
||||
var picker = $scope.picker;
|
||||
var model = $scope.model;
|
||||
|
||||
var date = moment(picker.date).format('YYYY-MM-DD');
|
||||
var startDate = moment(picker.startDate).format('YYYY-MM-DD');
|
||||
var endDate = moment(picker.endDate).format('YYYY-MM-DD');
|
||||
|
||||
model.status = 'scheduled';
|
||||
model.scheduling = {};
|
||||
model.scheduling.start = moment(date + 'T' + picker.start).toDate();
|
||||
model.scheduling.end = moment(date + 'T' + picker.end).toDate();
|
||||
model.scheduling.start = moment(startDate + 'T' + picker.startTime).toDate();
|
||||
model.scheduling.end = moment(endDate + 'T' + picker.endTime).toDate();
|
||||
|
||||
model._notify = notify;
|
||||
|
||||
Workorders.create(model, function(result) {
|
||||
$location.path("/workorders/" + result._id);
|
||||
@ -368,6 +562,14 @@ biomed.WorkorderAddCtrl = function($scope, $location, Workorders, Schedule, Clie
|
||||
var criteria = {};
|
||||
|
||||
Users.index(criteria, function(result) {
|
||||
result.sort(function(a,b) {
|
||||
var r = a.name.first.localeCompare(b.name.first);
|
||||
if (r == 0) {
|
||||
r = a.name.last.localeCompare(b.name.last);
|
||||
}
|
||||
return r;
|
||||
});
|
||||
|
||||
$scope.allUsers = result;
|
||||
|
||||
$scope.usersMap = {};
|
||||
@ -379,6 +581,13 @@ biomed.WorkorderAddCtrl = function($scope, $location, Workorders, Schedule, Clie
|
||||
}
|
||||
|
||||
biomed.WorkorderEditCtrl = function($scope, $routeParams, Workorders, Schedule, Users) {
|
||||
$scope.emailsOptions = {
|
||||
'multiple': true,
|
||||
'simple_tags': true,
|
||||
'tags': [],
|
||||
'formatNoMatches': function() { return 'Type an e-mail address and press return to add it.'; }
|
||||
};
|
||||
|
||||
$scope.group = 'all';
|
||||
$scope.route = $routeParams;
|
||||
$scope.loading = true;
|
||||
@ -390,8 +599,13 @@ biomed.WorkorderEditCtrl = function($scope, $routeParams, Workorders, Schedule,
|
||||
|
||||
$scope.master = Workorders.get($routeParams, function() {
|
||||
$scope.loading = false;
|
||||
|
||||
if ($scope.master.reason == "Meeting") {
|
||||
$scope.workorderType = "meeting";
|
||||
}
|
||||
});
|
||||
|
||||
$scope.emails = createController();
|
||||
$scope.status = createController();
|
||||
$scope.remarks = createController();
|
||||
$scope.scheduling = createSchedulingController();
|
||||
@ -410,7 +624,9 @@ biomed.WorkorderEditCtrl = function($scope, $routeParams, Workorders, Schedule,
|
||||
$scope.editing = true;
|
||||
}
|
||||
},
|
||||
save: function() {
|
||||
save: function(notify) {
|
||||
controller.model._notify = notify;
|
||||
|
||||
Workorders.update({id: $scope.master._id}, controller.model);
|
||||
angular.copy(controller.model, $scope.master);
|
||||
controller.visible = false;
|
||||
@ -434,9 +650,11 @@ biomed.WorkorderEditCtrl = function($scope, $routeParams, Workorders, Schedule,
|
||||
if (!$scope.editing) {
|
||||
angular.copy($scope.master, controller.model);
|
||||
|
||||
controller.date = moment(controller.model.scheduling.start).startOf('day').toDate();
|
||||
controller.start = moment(controller.model.scheduling.start).format('HH:mm:ss');
|
||||
controller.end = moment(controller.model.scheduling.end).format('HH:mm:ss');
|
||||
controller.startDate = moment(controller.model.scheduling.start).startOf('day').toDate();
|
||||
controller.endDate = moment(controller.model.scheduling.end).startOf('day').toDate();
|
||||
|
||||
controller.startTime = moment(controller.model.scheduling.start).format('HH:mm:ss');
|
||||
controller.endTime = moment(controller.model.scheduling.end).format('HH:mm:ss');
|
||||
|
||||
controller.techs = controller.model.techs.map(function(t) { return t._id; });
|
||||
|
||||
@ -444,13 +662,17 @@ biomed.WorkorderEditCtrl = function($scope, $routeParams, Workorders, Schedule,
|
||||
$scope.editing = true;
|
||||
}
|
||||
},
|
||||
save: function() {
|
||||
var date = moment(controller.date).format('YYYY-MM-DD');
|
||||
controller.model.scheduling.start = moment(date + 'T' + controller.start).toDate();
|
||||
controller.model.scheduling.end = moment(date + 'T' + controller.end).toDate();
|
||||
save: function(notify) {
|
||||
var startDate = moment(controller.startDate).format('YYYY-MM-DD');
|
||||
var endDate = moment(controller.endDate).format('YYYY-MM-DD');
|
||||
|
||||
controller.model.scheduling.start = moment(startDate + 'T' + controller.startTime).toDate();
|
||||
controller.model.scheduling.end = moment(endDate + 'T' + controller.endTime).toDate();
|
||||
|
||||
controller.model.techs = controller.techs.map(function(t) { return $scope.usersMap[t]; });
|
||||
|
||||
controller.model._notify = notify;
|
||||
|
||||
Workorders.update({id: $scope.master._id}, controller.model);
|
||||
angular.copy(controller.model, $scope.master);
|
||||
controller.visible = false;
|
||||
@ -466,15 +688,80 @@ biomed.WorkorderEditCtrl = function($scope, $routeParams, Workorders, Schedule,
|
||||
};
|
||||
|
||||
|
||||
$scope.$watch('scheduling.date', function() {
|
||||
function convertToDate(date, time) {
|
||||
return moment(moment(date).format('YYYY-MM-DD') + 'T' + time).toDate();
|
||||
}
|
||||
|
||||
function datesOverlap() {
|
||||
var start = convertToDate($scope.scheduling.startDate, $scope.scheduling.startTime);
|
||||
var end = convertToDate($scope.scheduling.endDate, $scope.scheduling.endTime);
|
||||
return start >= end;
|
||||
}
|
||||
|
||||
function updateDuration() {
|
||||
var start = convertToDate($scope.scheduling.startDate, $scope.scheduling.startTime);
|
||||
var end = convertToDate($scope.scheduling.endDate, $scope.scheduling.endTime);
|
||||
|
||||
var duration = moment.duration(end - start);
|
||||
|
||||
var days = duration.days()
|
||||
var hours = duration.hours();
|
||||
var minutes = duration.minutes();
|
||||
|
||||
var result = "";
|
||||
|
||||
if (days == 1) {
|
||||
result += "1 Day ";
|
||||
}
|
||||
if (days > 1) {
|
||||
result += days + " Days ";
|
||||
}
|
||||
if (hours == 1) {
|
||||
result += "1 Hour ";
|
||||
}
|
||||
if (hours > 1) {
|
||||
result += hours + " Hours ";
|
||||
}
|
||||
if (minutes > 0) {
|
||||
result += minutes + " Minutes";
|
||||
}
|
||||
|
||||
$scope.scheduling.duration = result;
|
||||
}
|
||||
|
||||
$scope.$watch('scheduling.startDate', function() {
|
||||
Schedule.index({
|
||||
date: $scope.scheduling.date.toJSON()
|
||||
date: $scope.scheduling.startDate.toJSON()
|
||||
}, function(result) {
|
||||
$scope.scheduling.schedule = result;
|
||||
});
|
||||
|
||||
if (datesOverlap()) {
|
||||
$scope.scheduling.endDate = $scope.scheduling.startDate;
|
||||
}
|
||||
updateDuration();
|
||||
});
|
||||
|
||||
$scope.$watch('scheduling.endDate', function() {
|
||||
if (datesOverlap()) {
|
||||
$scope.scheduling.startDate = $scope.scheduling.endDate;
|
||||
}
|
||||
updateDuration();
|
||||
});
|
||||
|
||||
$scope.$watch('scheduling.startTime', function() {
|
||||
$scope.scheduling.endTime = moment($scope.scheduling.startTime, "HH:mm:ss").add('minutes', 45).format("HH:mm:ss");
|
||||
$scope.scheduling.endDate = $scope.scheduling.startDate;
|
||||
updateDuration();
|
||||
});
|
||||
|
||||
$scope.$watch('scheduling.endTime', function() {
|
||||
if (datesOverlap()) {
|
||||
$scope.scheduling.startTime = moment($scope.scheduling.endTime, "HH:mm:ss").subtract('minutes', 15).format("HH:mm:ss");
|
||||
}
|
||||
updateDuration();
|
||||
});
|
||||
|
||||
return controller;
|
||||
}
|
||||
|
||||
@ -488,6 +775,14 @@ biomed.WorkorderEditCtrl = function($scope, $routeParams, Workorders, Schedule,
|
||||
var criteria = {};
|
||||
|
||||
Users.index(criteria, function(result) {
|
||||
result.sort(function(a,b) {
|
||||
var r = a.name.first.localeCompare(b.name.first);
|
||||
if (r == 0) {
|
||||
r = a.name.last.localeCompare(b.name.last);
|
||||
}
|
||||
return r;
|
||||
});
|
||||
|
||||
$scope.allUsers = result;
|
||||
|
||||
$scope.usersMap = {};
|
||||
@ -499,7 +794,7 @@ biomed.WorkorderEditCtrl = function($scope, $routeParams, Workorders, Schedule,
|
||||
};
|
||||
|
||||
|
||||
biomed.PageCtrl = function($scope, $dialog) {
|
||||
biomed.PageCtrl = function($scope, $dialog, Account) {
|
||||
$scope.opts = {
|
||||
backdrop: true,
|
||||
keyboard: true,
|
||||
@ -514,6 +809,17 @@ biomed.PageCtrl = function($scope, $dialog) {
|
||||
var d = $dialog.dialog($scope.opts);
|
||||
d.open();
|
||||
};
|
||||
|
||||
$scope.accountHasPermission = function(perm) {
|
||||
console.log($scope);
|
||||
if ($scope.account && $scope.account.perms) {
|
||||
return $scope.account.perms.indexOf(perm) > -1;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
$scope.account = Account.get();
|
||||
};
|
||||
|
||||
biomed.MessagesCtrl = function($scope, dialog, Users, Messages) {
|
||||
|
@ -168,16 +168,16 @@ angular.module('biomed.directives', [])
|
||||
}
|
||||
|
||||
// Use native interface for touch devices
|
||||
if(isTouch && element.prop('type') === 'text') {
|
||||
// if(isTouch && element.prop('type') === 'text') {
|
||||
//
|
||||
// element.prop('type', 'date');
|
||||
// element.on('change', function(ev) {
|
||||
// scope.$apply(function () {
|
||||
// controller.$setViewValue(moment(element.val()).toDate());
|
||||
// });
|
||||
// });
|
||||
|
||||
element.prop('type', 'date');
|
||||
element.on('change', function(ev) {
|
||||
scope.$apply(function () {
|
||||
controller.$setViewValue(moment(element.val()).toDate());
|
||||
});
|
||||
});
|
||||
|
||||
} else {
|
||||
// } else {
|
||||
|
||||
// If we have a controller (i.e. ngModelController) then wire it up
|
||||
if(controller) {
|
||||
@ -208,7 +208,7 @@ angular.module('biomed.directives', [])
|
||||
forceParse: attrs.forceParse || false
|
||||
});
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
// Support add-on
|
||||
var component = element.siblings('[data-toggle="datepicker"]');
|
||||
@ -219,8 +219,143 @@ angular.module('biomed.directives', [])
|
||||
}
|
||||
};
|
||||
})
|
||||
.directive('techpicker', function() {
|
||||
.directive('techschedule', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
schedule: '=',
|
||||
date: '=',
|
||||
onEntryClick: '&'
|
||||
},
|
||||
templateUrl: '/partials/techSchedule.html',
|
||||
replace: true,
|
||||
link: function($scope, element, attrs) {
|
||||
var x, rangeDate, rangeStart, rangeEnd;
|
||||
|
||||
function setupScale() {
|
||||
x = d3.scale.linear()
|
||||
.range([0, 100])
|
||||
.domain([420, 1320])
|
||||
.clamp(true);
|
||||
}
|
||||
|
||||
setupScale();
|
||||
|
||||
var color = d3.scale.category20();
|
||||
var hourWidth = 100 / 15;
|
||||
|
||||
$scope.hourMarkers = [];
|
||||
for (var i = 7; i < 22; i++) {
|
||||
$scope.hourMarkers.push({
|
||||
date: moment({ hour: i }).toDate(),
|
||||
style: {
|
||||
left: x(i * 60) + '%',
|
||||
width: hourWidth + '%'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$scope.$watch('schedule', function(newVal, oldVal) {
|
||||
generateDate();
|
||||
});
|
||||
|
||||
$scope.$watch('date', function(newVal, oldVal) {
|
||||
setupScale();
|
||||
});
|
||||
|
||||
function generateDate() {
|
||||
var range = moment($scope.date);
|
||||
var data = {};
|
||||
|
||||
for (var i = 0; i < 7; i++) {
|
||||
var day = range.clone().add(i, 'days');
|
||||
var key = day.format('MM-DD-YYYY');
|
||||
var label = day.format('ddd MMM Do YYYY');
|
||||
|
||||
data[key] = {
|
||||
label: label,
|
||||
values: []
|
||||
};
|
||||
}
|
||||
|
||||
var c = 0;
|
||||
|
||||
angular.forEach($scope.schedule, function(workorder) {
|
||||
var start = moment(workorder.scheduling.start);
|
||||
var startMinutes = start.diff(start.clone().startOf('day'), 'minutes');
|
||||
|
||||
var end = moment(workorder.scheduling.end);
|
||||
var endMinutes = end.diff(end.clone().startOf('day'), 'minutes');
|
||||
|
||||
var length = end.diff(start, 'days') + 1;
|
||||
|
||||
console.log('length: ' + length + ' start: ' + startMinutes + ' end: ' + endMinutes);
|
||||
|
||||
var backgroundColor = color(c++);
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
var adjStart, adjEnd;
|
||||
|
||||
var key = start.clone().add(i, 'days').format('MM-DD-YYYY');
|
||||
|
||||
if (i == 0) {
|
||||
adjStart = startMinutes;
|
||||
} else {
|
||||
adjStart = 420;
|
||||
}
|
||||
|
||||
if (i == length - 1) {
|
||||
adjEnd = endMinutes;
|
||||
} else {
|
||||
adjEnd = 1320;
|
||||
}
|
||||
|
||||
if (data[key]) {
|
||||
data[key].values.push({
|
||||
style: {
|
||||
backgroundColor: color(c),
|
||||
left: x(adjStart) + '%',
|
||||
width: (x(adjEnd) - x(adjStart)) + '%'
|
||||
},
|
||||
workorder: workorder
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
angular.forEach(workorder.techs, function(tech) {
|
||||
var key = tech.name.first + ' ' + tech.name.last;
|
||||
|
||||
if (!data[key])
|
||||
return;
|
||||
|
||||
var start = moment(workorder.scheduling.start);
|
||||
var end = moment(workorder.scheduling.end);
|
||||
|
||||
data[key].values.push({
|
||||
style: {
|
||||
backgroundColor: color(key),
|
||||
left: x(start) + "%",
|
||||
width: (x(end) - x(start)) + "%"
|
||||
},
|
||||
workorder: workorder
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
$scope.data = data;
|
||||
}
|
||||
}
|
||||
};
|
||||
})
|
||||
.filter('pretty', function() {
|
||||
return function(input) {
|
||||
return "\n" + angular.toJson(input, true);
|
||||
}
|
||||
})
|
||||
.directive('techpicker', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
@ -232,24 +367,31 @@ angular.module('biomed.directives', [])
|
||||
templateUrl: '/partials/techPicker.html',
|
||||
replace: true,
|
||||
link: function($scope, element, attrs) {
|
||||
var timePickerParser = d3.time.format('%I:%M%p');
|
||||
|
||||
var rangeStart = timePickerParser.parse('7:00am');
|
||||
var rangeEnd = timePickerParser.parse('10:00pm');
|
||||
var x, rangeDate, rangeStart, rangeEnd;
|
||||
|
||||
var x = d3.time.scale()
|
||||
.range([0, 100])
|
||||
.domain([rangeStart, rangeEnd]);
|
||||
function setupScale() {
|
||||
rangeDate = moment($scope.date).startOf('day');
|
||||
|
||||
rangeStart = moment(rangeDate).add('hours', 7);
|
||||
rangeEnd = moment(rangeDate).add('hours', 22);
|
||||
|
||||
x = d3.time.scale()
|
||||
.range([0, 100])
|
||||
.domain([rangeStart.toDate(), rangeEnd.toDate()])
|
||||
.clamp(true);
|
||||
}
|
||||
|
||||
setupScale();
|
||||
|
||||
var color = d3.scale.category20();
|
||||
|
||||
var totalHours = moment.duration(moment(rangeEnd) - moment(rangeStart)).hours();
|
||||
var totalHours = moment.duration(rangeEnd - rangeStart).hours();
|
||||
var hourWidth = 100 / totalHours;
|
||||
|
||||
$scope.hourMarkers = [];
|
||||
for (var i = 0; i < totalHours; i++) {
|
||||
var date = moment(rangeStart).add('hours', i).toDate();
|
||||
|
||||
$scope.hourMarkers.push({
|
||||
date: date,
|
||||
style: {
|
||||
@ -267,6 +409,10 @@ angular.module('biomed.directives', [])
|
||||
generateDate();
|
||||
});
|
||||
|
||||
$scope.$watch('date', function(newVal, oldVal) {
|
||||
setupScale();
|
||||
});
|
||||
|
||||
function generateDate() {
|
||||
var data = {};
|
||||
|
||||
@ -275,7 +421,10 @@ angular.module('biomed.directives', [])
|
||||
angular.forEach($scope.users, function(user) {
|
||||
var key = user.name.first + ' ' + user.name.last;
|
||||
labels.push(key);
|
||||
data[key] = [];
|
||||
data[key] = {
|
||||
id: user._id,
|
||||
values: []
|
||||
};
|
||||
});
|
||||
|
||||
labels.sort();
|
||||
@ -285,13 +434,13 @@ angular.module('biomed.directives', [])
|
||||
angular.forEach(workorder.techs, function(tech) {
|
||||
var key = tech.name.first + ' ' + tech.name.last;
|
||||
|
||||
if (!data[key])
|
||||
return;
|
||||
if (!data[key])
|
||||
return;
|
||||
|
||||
var start = moment(workorder.scheduling.start).year(1900).month(0).date(1).toDate();
|
||||
var end = moment(workorder.scheduling.end).year(1900).month(0).date(1).toDate();
|
||||
var start = moment(workorder.scheduling.start);
|
||||
var end = moment(workorder.scheduling.end);
|
||||
|
||||
data[key].push({
|
||||
data[key].values.push({
|
||||
style: {
|
||||
backgroundColor: color(key),
|
||||
left: x(start) + "%",
|
||||
@ -306,7 +455,224 @@ angular.module('biomed.directives', [])
|
||||
}
|
||||
};
|
||||
})
|
||||
.directive('uiSelect2', function ($timeout) {
|
||||
.value('uiSelect2Config', {})
|
||||
.directive('uiSelect2', ['uiSelect2Config', '$timeout', function (uiSelect2Config, $timeout) {
|
||||
var options = {};
|
||||
if (uiSelect2Config) {
|
||||
angular.extend(options, uiSelect2Config);
|
||||
}
|
||||
return {
|
||||
require: 'ngModel',
|
||||
priority: 1,
|
||||
compile: function (tElm, tAttrs) {
|
||||
var watch,
|
||||
repeatOption,
|
||||
repeatAttr,
|
||||
isSelect = tElm.is('select'),
|
||||
isMultiple = angular.isDefined(tAttrs.multiple);
|
||||
|
||||
// Enable watching of the options dataset if in use
|
||||
if (tElm.is('select')) {
|
||||
repeatOption = tElm.find( 'optgroup[ng-repeat], optgroup[data-ng-repeat], option[ng-repeat], option[data-ng-repeat]');
|
||||
|
||||
if (repeatOption.length) {
|
||||
repeatAttr = repeatOption.attr('ng-repeat') || repeatOption.attr('data-ng-repeat');
|
||||
watch = jQuery.trim(repeatAttr.split('|')[0]).split(' ').pop();
|
||||
}
|
||||
}
|
||||
|
||||
return function (scope, elm, attrs, controller) {
|
||||
// instance-specific options
|
||||
var opts = angular.extend({}, options, scope.$eval(attrs.uiSelect2));
|
||||
|
||||
/*
|
||||
Convert from Select2 view-model to Angular view-model.
|
||||
*/
|
||||
var convertToAngularModel = function(select2_data) {
|
||||
var model;
|
||||
if (opts.simple_tags) {
|
||||
model = [];
|
||||
angular.forEach(select2_data, function(value, index) {
|
||||
model.push(value.id);
|
||||
});
|
||||
} else {
|
||||
model = select2_data;
|
||||
}
|
||||
return model;
|
||||
};
|
||||
|
||||
/*
|
||||
Convert from Angular view-model to Select2 view-model.
|
||||
*/
|
||||
var convertToSelect2Model = function(angular_data) {
|
||||
var model = [];
|
||||
if (!angular_data) {
|
||||
return model;
|
||||
}
|
||||
|
||||
if (opts.simple_tags) {
|
||||
model = [];
|
||||
angular.forEach(
|
||||
angular_data,
|
||||
function(value, index) {
|
||||
model.push({'id': value, 'text': value});
|
||||
});
|
||||
} else {
|
||||
model = angular_data;
|
||||
}
|
||||
return model;
|
||||
};
|
||||
|
||||
if (isSelect) {
|
||||
// Use <select multiple> instead
|
||||
delete opts.multiple;
|
||||
delete opts.initSelection;
|
||||
} else if (isMultiple) {
|
||||
opts.multiple = true;
|
||||
}
|
||||
if (controller) {
|
||||
// Watch the model for programmatic changes
|
||||
scope.$watch(tAttrs.ngModel, function(current, old) {
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
if (current === old) {
|
||||
return;
|
||||
}
|
||||
blah();
|
||||
// controller.$render();
|
||||
}, true);
|
||||
|
||||
var blah = controller.$render = function () {
|
||||
if (isSelect) {
|
||||
elm.select2('val', controller.$viewValue);
|
||||
} else {
|
||||
if (opts.multiple) {
|
||||
var viewValue = controller.$viewValue;
|
||||
if (angular.isString(viewValue)) {
|
||||
viewValue = viewValue.split(',');
|
||||
}
|
||||
elm.select2(
|
||||
'data', convertToSelect2Model(viewValue));
|
||||
} else {
|
||||
if (angular.isObject(controller.$viewValue)) {
|
||||
elm.select2('data', controller.$viewValue);
|
||||
} else if (!controller.$viewValue) {
|
||||
elm.select2('data', null);
|
||||
} else {
|
||||
elm.select2('val', controller.$viewValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Watch the options dataset for changes
|
||||
if (watch) {
|
||||
scope.$watch(watch, function (newVal, oldVal, scope) {
|
||||
if (angular.equals(newVal, oldVal)) {
|
||||
return;
|
||||
}
|
||||
// Delayed so that the options have time to be rendered
|
||||
$timeout(function () {
|
||||
elm.select2('val', controller.$viewValue);
|
||||
// Refresh angular to remove the superfluous option
|
||||
elm.trigger('change');
|
||||
if(newVal && !oldVal && controller.$setPristine) {
|
||||
controller.$setPristine(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Update valid and dirty statuses
|
||||
controller.$parsers.push(function (value) {
|
||||
var div = elm.prev();
|
||||
div
|
||||
.toggleClass('ng-invalid', !controller.$valid)
|
||||
.toggleClass('ng-valid', controller.$valid)
|
||||
.toggleClass('ng-invalid-required', !controller.$valid)
|
||||
.toggleClass('ng-valid-required', controller.$valid)
|
||||
.toggleClass('ng-dirty', controller.$dirty)
|
||||
.toggleClass('ng-pristine', controller.$pristine);
|
||||
return value;
|
||||
});
|
||||
|
||||
if (!isSelect) {
|
||||
// Set the view and model value and update the angular template manually for the ajax/multiple select2.
|
||||
elm.bind("change", function (e) {
|
||||
e.stopImmediatePropagation();
|
||||
|
||||
if (scope.$$phase || scope.$root.$$phase) {
|
||||
return;
|
||||
}
|
||||
scope.$apply(function () {
|
||||
controller.$setViewValue(
|
||||
convertToAngularModel(elm.select2('data')));
|
||||
});
|
||||
});
|
||||
|
||||
if (opts.initSelection) {
|
||||
var initSelection = opts.initSelection;
|
||||
opts.initSelection = function (element, callback) {
|
||||
initSelection(element, function (value) {
|
||||
var isPristine = controller.$pristine;
|
||||
controller.$setViewValue(convertToAngularModel(value));
|
||||
callback(value);
|
||||
if (isPristine) {
|
||||
controller.$setPristine();
|
||||
}
|
||||
elm.prev().toggleClass('ng-pristine', controller.$pristine);
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
elm.bind("$destroy", function() {
|
||||
elm.select2("destroy");
|
||||
});
|
||||
|
||||
attrs.$observe('disabled', function (value) {
|
||||
elm.select2('enable', !value);
|
||||
});
|
||||
|
||||
attrs.$observe('readonly', function (value) {
|
||||
elm.select2('readonly', !!value);
|
||||
});
|
||||
|
||||
if (attrs.ngMultiple) {
|
||||
scope.$watch(attrs.ngMultiple, function(newVal) {
|
||||
attrs.$set('multiple', !!newVal);
|
||||
elm.select2(opts);
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize the plugin late so that the injected DOM does not disrupt the template compiler
|
||||
$timeout(function () {
|
||||
elm.select2(opts);
|
||||
|
||||
// Set initial value - I'm not sure about this but it seems to need to be there
|
||||
elm.select2('data', controller.$modelValue);
|
||||
// important!
|
||||
controller.$render();
|
||||
|
||||
// Not sure if I should just check for !isSelect OR if I should check for 'tags' key
|
||||
if (!opts.initSelection && !isSelect) {
|
||||
var isPristine = controller.$pristine;
|
||||
controller.$setViewValue(
|
||||
convertToAngularModel(elm.select2('data'))
|
||||
);
|
||||
if (isPristine) {
|
||||
controller.$setPristine();
|
||||
}
|
||||
elm.prev().toggleClass('ng-pristine', controller.$pristine);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
}])
|
||||
.directive('uiSelect2-old', function ($timeout) {
|
||||
var options = {};
|
||||
|
||||
return {
|
||||
@ -421,4 +787,4 @@ angular.module('biomed.directives', [])
|
||||
};
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
|
@ -12,5 +12,13 @@ angular.module('biomed.filters', [])
|
||||
return function(time) {
|
||||
return moment(time).format('h:mma');
|
||||
};
|
||||
})
|
||||
.filter('email', function() {
|
||||
return function(email) {
|
||||
var parts = email.split("@", 2);
|
||||
if (parts[1].toLowerCase() == "atlanticbiomedical.com")
|
||||
return parts[0] + "@";
|
||||
else
|
||||
return email;
|
||||
}
|
||||
});
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -25,9 +25,13 @@ angular.module('biomed.services', [])
|
||||
});
|
||||
})
|
||||
.factory("Users", function($resource) {
|
||||
return $resource('/api/users', { },
|
||||
return $resource('/api/users/:id/:cmd',
|
||||
{ id: "@id", cmd: "@cmd" },
|
||||
{
|
||||
index: { method: 'GET', isArray: true },
|
||||
details: { method: 'GET', params: { cmd: 'details' }, isArray: true },
|
||||
create: { method: 'POST', params: {} },
|
||||
update: { method: 'POST', params: { id: 0 } },
|
||||
});
|
||||
})
|
||||
.factory("Schedule", function($resource) {
|
||||
@ -112,4 +116,4 @@ angular.module('biomed.services', [])
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user