Added a bunch of stuff

This commit is contained in:
Dobie Wollert
2015-08-05 06:03:02 -07:00
parent b4e727c0e6
commit fdc8727044
35 changed files with 1815 additions and 276 deletions

View File

@ -0,0 +1,102 @@
angular.module('biomed')
.controller("CheckListIndexCtrl", checkListsIndexController)
.controller("CheckListAddCtrl", checkListsControllerFactory(false))
.controller("CheckListEditCtrl", checkListsControllerFactory(true))
function checkListsIndexController($scope, $filter, $routeParams, CheckLists, LocationBinder) {
$scope.loading = true;
var allData = CheckLists.index(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('orderBy')($filter('filter')(allData, $scope.query), $scope.sort.column, $scope.sort.descending);
index = initialPageSize;
$scope.canLoad = true;
$scope.checkLists = filteredData.slice(0, initialPageSize);
};
$scope.addItems = function() {
$scope.checkLists = $scope.checkLists.concat(filteredData.slice(index, index + pageSize));
index += pageSize;
$scope.canLoad = index < filteredData.length;
}
$scope.sort = {
column: 'name',
descending: false
};
$scope.selectedCls = function(column) {
return column == $scope.sort.column && 'sort-' + $scope.sort.descending;
}
$scope.changeSorting = function(column) {
var sort = $scope.sort;
if (sort.column == column) {
sort.descending = !sort.descending;
} else {
sort.column = column;
sort.descending = false;
}
$scope.filter();
};
}
function checkListsControllerFactory(isEdit) {
return function($scope, CheckLists, $location, $filter, $routeParams) {
function addField() {
$scope.model.fields.push({ type: 'boolean' })
}
function removeField(index) {
console.log('Index: ', index);
if (index != -1) {
$scope.model.fields.splice(index, 1);
}
}
function save() {
if (isEdit) {
CheckLists.update({id: $scope.model._id}, $scope.model);
} else {
CheckLists.create($scope.model, function(result) {
$location.path("/checkLists/" + result._id);
});
}
}
$scope.addField = addField;
$scope.removeField = removeField;
$scope.save = save;
$scope.isEdit = isEdit;
if (!isEdit) {
$scope.model = {
name: '',
fields: []
};
addField();
} else {
$scope.model = CheckLists.get($routeParams);
}
}
}

View File

@ -56,12 +56,14 @@ angular.module('biomed')
};
})
.controller("DeviceTypeAddCtrl", function($scope, DeviceTypes, $location, $filter) {
.controller("DeviceTypeAddCtrl", function($scope, DeviceTypes, CheckLists, $location, $filter) {
$scope.model = {};
$scope.categories = DeviceTypes.categories();
$scope.deviceMakes = DeviceTypes.makes();
$scope.checkLists = CheckLists.index();
$scope.categoryOpts = {
containerCssClass: 'input-xxlarge',
placeholder: 'Choose a Device Type',
@ -147,7 +149,7 @@ angular.module('biomed')
};
})
.controller("DeviceTypeEditCtrl", function($scope, DeviceTypes, $location, $filter, $routeParams) {
.controller("DeviceTypeEditCtrl", function($scope, DeviceTypes, Devices, CheckLists, $location, $filter, $routeParams) {
var images = {};
$scope.model = DeviceTypes.get($routeParams, function() {
@ -164,9 +166,16 @@ angular.module('biomed')
$scope.makePicker = {id: $scope.model.make, text: $scope.model.make};
});
console.log($routeParams);
$scope.devices = Devices.index({ deviceType: $routeParams.id });
$scope.categories = DeviceTypes.categories();
$scope.deviceMakes = DeviceTypes.makes();
$scope.checkLists = CheckLists.index();
$scope.categoryOpts = {
containerCssClass: 'input-xxlarge',
placeholder: 'Choose a Device Type',

View File

@ -1 +1,160 @@
angular.module('biomed')
.controller("DeviceAddCtrl", devicesControllerFactory(false))
.controller("DeviceEditCtrl", devicesControllerFactory(true))
function devicesControllerFactory(isEdit) {
return function($scope, Devices, DeviceTypes, $location, $filter, $routeParams) {
function buildDeviceTypeFilterQuery(ignore) {
var query = {};
_.each(['category', 'make', 'model'], function(key) {
if (key == ignore)
return;
if ($scope.deviceTypes[key].picker) {
query[key] = $scope.deviceTypes[key].picker.id;
}
})
return query;
}
function filterDeviceTypeSelectors() {
console.log('Filtering Device Data');
var data = {};
_.each(['category', 'make', 'model'], function(key) {
var query = buildDeviceTypeFilterQuery(key);
var filteredResults = $filter('filter')(deviceTypesList, query);
data[key] = [];
_.each(filteredResults, function(entry) {
data[key].push(entry[key]);
});
});
_.each(['category', 'make', 'model'], function(key) {
$scope.deviceTypes[key].data = _.uniq(data[key]);
if (data[key].length == 1) {
var value = data[key][0];
$scope.deviceTypes[key].picker = { id: value, text: value };
}
});
}
function deviceTypePickerFactory(key, label) {
var optsKey = key + 'Opts';
$scope.deviceTypes[key] = {};
$scope.deviceTypes[key].opts = {
containerCssClass: 'input-xxlarge',
placeholder: 'Choose a ' + label,
query: function(query) {
var data = $filter('filter')($scope.deviceTypes[key].data, query.term);
query.callback({
results: _.map(data, function(entry) {
return { id: entry, text: entry }
})
});
}
};
$scope.$watch('deviceTypes.' + key + '.picker',function() {
filterDeviceTypeSelectors();
updateDeviceTypeSelection();
}, true);
}
function clearDeviceTypePickers() {
_.each(['category', 'make', 'model'], function(key) {
$scope.deviceTypes[key].picker = null;
});
}
function updateDeviceTypeSelection() {
var query = buildDeviceTypeFilterQuery();
var results = $filter('filter')(deviceTypesList, query);
$scope.model.deviceType = (results.length == 1) ? results[0]._id : null;
}
function generateRandomIdentifier() {
$scope.model.biomedId = hashids.encode(Date.now());
}
function toggleFrequency(index) {
$scope.model.frequencySchedule[index] = !$scope.model.frequencySchedule[index];
console.log($scope.model);
}
function create() {
Devices.create($scope.model, function(result) {
console.log('here');
$location.path("/devices/" + result._id);
});
}
function update() {
Devices.update({id: $scope.model._id}, $scope.model);
}
var hashids = new Hashids("biomed");
var search = $location.search();
$scope.model = {
frequencySchedule: [false, false, false, false, false, false, false, false, false, false, false, false]
};
$scope.toggleFrequency = toggleFrequency;
$scope.deviceTypes = {};
$scope.deviceTypes.reset = clearDeviceTypePickers;
$scope.biomedId = {};
$scope.biomedId.reset = generateRandomIdentifier;
$scope.create = create;
$scope.update = update;
deviceTypePickerFactory('category', 'Device Type');
deviceTypePickerFactory('make', 'Make');
deviceTypePickerFactory('model', 'Model');
var deviceTypesList = DeviceTypes.index(filterDeviceTypeSelectors)
console.log((isEdit ? "Edit" : "Create") + " Mode");
if (isEdit) {
$scope.model = Devices.get($routeParams, function() {
$scope.loading = false;
var deviceType = $scope.model.deviceType;
_.each(['category', 'make', 'model'], function(key) {
$scope.deviceTypes[key].picker = { id: deviceType[key], text: deviceType[key] };
});
$scope.model.client = $scope.model.client._id;
$scope.model.deviceType = $scope.model.deviceType._id;
$scope.testRuns = Devices.testRuns($routeParams, function() {
console.log($scope.testRuns);
});
});
} else {
if (search.clientId) {
$scope.model.client = search.clientId;
} else {
$location.path("/deviceTypes");
return;
}
generateRandomIdentifier();
}
}
}

View File

@ -0,0 +1,58 @@
angular.module('biomed')
.controller("TestRunAddCtrl", testRunAddController)
.controller("TestRunViewCtrl", testRunViewController)
function testRunAddController($scope, Devices, CheckLists, TestRuns, $location, $filter, $routeParams) {
var search = $location.search();
console.log(search);
$scope.device = Devices.get({id: search.deviceId}, function() {
console.log($scope.device);
$scope.checkList = CheckLists.get({id: $scope.device.deviceType.checkList}, function() {
$scope.loading = false;
$scope.model = {
device: $scope.device._id,
date: new Date(),
fields: []
};
_.each($scope.checkList.fields, function(field) {
if (field.type == 'boolean') {
field.value = 'false'
}
field.result = false;
$scope.model.fields.push(field);
});
})
});
$scope.$watch('model', function() {
$scope.model.result = true;
_.each($scope.model.fields, function(field) {
if (field.type == 'boolean') {
field.result = (field.value == 'true');
} else if (field.type == 'range') {
field.result = field.value >= field.min && field.value <= field.max;
}
$scope.model.result &= field.result;
})
}, true);
$scope.save = function() {
TestRuns.create($scope.model, function(result) {
$location.path("/testRuns/" + result._id);
});
}
}
function testRunViewController($scope, Devices, CheckLists, TestRuns, $location, $filter, $routeParams) {
$scope.model = TestRuns.get($routeParams);
}