mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
latest changes
This commit is contained in:
@ -61,6 +61,19 @@ angular.module('biomed', ['biomed.filters', 'biomed.services', 'biomed.directive
|
||||
templateUrl: '/partials/clients/edit.html',
|
||||
controller: "ClientEditCtrl"
|
||||
})
|
||||
.when('/devices', {
|
||||
templateUrl: '/partials/devices/index.html',
|
||||
controller: "DeviceIndexCtrl",
|
||||
reloadOnSearch: false
|
||||
})
|
||||
.when('/devices/add', {
|
||||
templateUrl: '/partials/devices/add.html',
|
||||
controller: "DeviceAddCtrl"
|
||||
})
|
||||
.when('/devices/:id', {
|
||||
templateUrl: '/partials/devices/edit.html',
|
||||
controller: "DeviceEditCtrl"
|
||||
})
|
||||
.when('/accounting', {
|
||||
templateUrl: '/partials/accounting/index.html',
|
||||
controller: "AccountingIndexCtrl",
|
||||
|
@ -705,6 +705,257 @@ angular.module('biomed')
|
||||
}
|
||||
})
|
||||
|
||||
.controller("DeviceIndexCtrl", function($scope, $filter, $routeParams, Devices, LocationBinder) {
|
||||
$scope.loading = true;
|
||||
|
||||
var allData = Devices.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.devices = filteredData.slice(0, initialPageSize);
|
||||
};
|
||||
|
||||
$scope.addItems = function() {
|
||||
$scope.devices = $scope.devices.concat(filteredData.slice(index, index + pageSize));
|
||||
index += pageSize;
|
||||
$scope.canLoad = index < filteredData.length;
|
||||
}
|
||||
|
||||
$scope.sort = {
|
||||
column: 'deviceType',
|
||||
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();
|
||||
};
|
||||
})
|
||||
|
||||
.controller("DeviceAddCtrl", function($scope, Devices, $location, $filter) {
|
||||
$scope.model = {};
|
||||
|
||||
$scope.deviceTypes = Devices.deviceTypes();
|
||||
$scope.deviceMakes = Devices.makes();
|
||||
|
||||
$scope.deviceTypeOpts = {
|
||||
containerCssClass: 'input-xxlarge',
|
||||
placeholder: 'Choose a Device Type',
|
||||
query: function(query) {
|
||||
var data = $filter('filter')($scope.deviceTypes, query.term);
|
||||
var results = [];
|
||||
data.forEach(function(item) {
|
||||
results.push({id: item, text: item});
|
||||
});
|
||||
query.callback({results: results });
|
||||
},
|
||||
createSearchChoice: function(term) {
|
||||
return { id: term, text: term };
|
||||
}
|
||||
};
|
||||
|
||||
$scope.makeOpts = {
|
||||
containerCssClass: 'input-xxlarge',
|
||||
placeholder: 'Choose a Device Make',
|
||||
query: function(query) {
|
||||
var data = $filter('filter')($scope.deviceMakes, query.term);
|
||||
var results = [];
|
||||
data.forEach(function(item) {
|
||||
results.push({id: item, text: item});
|
||||
});
|
||||
query.callback({results: results });
|
||||
},
|
||||
createSearchChoice: function(term) {
|
||||
return { id: term, text: term };
|
||||
}
|
||||
};
|
||||
|
||||
var images = {};
|
||||
|
||||
$scope.imageOpts = {
|
||||
options: {
|
||||
url: '/api/devices/images',
|
||||
addRemoveLinks: true
|
||||
},
|
||||
eventHandlers: {
|
||||
success: function(file, response) {
|
||||
file.filename = response.filename;
|
||||
|
||||
if (images[file.filename]) {
|
||||
images[file.filename]++;
|
||||
this.removeFile(file);
|
||||
} else {
|
||||
images[file.filename] = 1;
|
||||
}
|
||||
},
|
||||
removedfile: function(file) {
|
||||
images[file.filename]--;
|
||||
|
||||
if (images[file.filename] <= 0) {
|
||||
delete images[file.filename];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.$watch('deviceTypePicker', function() {
|
||||
if ($scope.deviceTypePicker) {
|
||||
$scope.model.deviceType = $scope.deviceTypePicker.id;
|
||||
} else {
|
||||
$scope.model.deviceType = null;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$watch('makePicker', function() {
|
||||
if ($scope.makePicker) {
|
||||
$scope.model.make = $scope.makePicker.id;
|
||||
} else {
|
||||
$scope.model.make = null;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.save = function() {
|
||||
$scope.model.images = Object.keys(images);
|
||||
|
||||
Devices.create($scope.model, function(result) {
|
||||
// $location.path("/devices/" + result._id);
|
||||
$location.path("/devices/");
|
||||
});
|
||||
};
|
||||
})
|
||||
|
||||
.controller("DeviceEditCtrl", function($scope, Devices, $location, $filter, $routeParams) {
|
||||
var images = {};
|
||||
|
||||
$scope.model = Devices.get($routeParams, function() {
|
||||
$scope.loading = false;
|
||||
|
||||
$scope.existingImages = $scope.model.images;
|
||||
if ($scope.model.images) {
|
||||
for (var i = 0; i < $scope.model.images.length; i++) {
|
||||
images[$scope.model.images[i]] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$scope.deviceTypePicker = {id: $scope.model.deviceType, text: $scope.model.deviceType};
|
||||
$scope.makePicker = {id: $scope.model.make, text: $scope.model.make};
|
||||
});
|
||||
|
||||
$scope.deviceTypes = Devices.deviceTypes();
|
||||
$scope.deviceMakes = Devices.makes();
|
||||
|
||||
$scope.deviceTypeOpts = {
|
||||
containerCssClass: 'input-xxlarge',
|
||||
placeholder: 'Choose a Device Type',
|
||||
query: function(query) {
|
||||
var data = $filter('filter')($scope.deviceTypes, query.term);
|
||||
var results = [];
|
||||
data.forEach(function(item) {
|
||||
results.push({id: item, text: item});
|
||||
});
|
||||
query.callback({results: results });
|
||||
},
|
||||
createSearchChoice: function(term) {
|
||||
return { id: term, text: term };
|
||||
}
|
||||
};
|
||||
|
||||
$scope.makeOpts = {
|
||||
containerCssClass: 'input-xxlarge',
|
||||
placeholder: 'Choose a Device Make',
|
||||
query: function(query) {
|
||||
var data = $filter('filter')($scope.deviceMakes, query.term);
|
||||
var results = [];
|
||||
data.forEach(function(item) {
|
||||
results.push({id: item, text: item});
|
||||
});
|
||||
query.callback({results: results });
|
||||
},
|
||||
createSearchChoice: function(term) {
|
||||
return { id: term, text: term };
|
||||
}
|
||||
};
|
||||
|
||||
$scope.imageOpts = {
|
||||
options: {
|
||||
url: '/api/devices/images',
|
||||
addRemoveLinks: true
|
||||
},
|
||||
eventHandlers: {
|
||||
success: function(file, response) {
|
||||
file.filename = response.filename;
|
||||
|
||||
if (images[file.filename]) {
|
||||
images[file.filename]++;
|
||||
this.removeFile(file);
|
||||
} else {
|
||||
images[file.filename] = 1;
|
||||
}
|
||||
},
|
||||
removedfile: function(file) {
|
||||
images[file.filename]--;
|
||||
|
||||
if (images[file.filename] <= 0) {
|
||||
delete images[file.filename];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.$watch('deviceTypePicker', function() {
|
||||
if ($scope.deviceTypePicker) {
|
||||
$scope.model.deviceType = $scope.deviceTypePicker.id;
|
||||
} else {
|
||||
$scope.model.deviceType = null;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$watch('makePicker', function() {
|
||||
if ($scope.makePicker) {
|
||||
$scope.model.make = $scope.makePicker.id;
|
||||
} else {
|
||||
$scope.model.make = null;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.save = function() {
|
||||
$scope.model.images = Object.keys(images);
|
||||
|
||||
Devices.update({id: $scope.model._id}, $scope.model, function(result) {
|
||||
$location.path("/devices/");
|
||||
});
|
||||
};
|
||||
})
|
||||
|
||||
.controller("AccountingIndexCtrl", function($scope, $filter, $routeParams, Workorders, LocationBinder) {
|
||||
$scope.loading = true;
|
||||
|
||||
|
@ -807,7 +807,8 @@ angular.module('biomed.directives', [])
|
||||
return {
|
||||
scope: {
|
||||
dropzone: '=',
|
||||
existing: '='
|
||||
existing: '=',
|
||||
prefix: '@'
|
||||
},
|
||||
controller: function($scope, $element, $attrs) {
|
||||
var config, dropzone;
|
||||
@ -821,13 +822,16 @@ angular.module('biomed.directives', [])
|
||||
$scope.$watch('existing', function() {
|
||||
var existing = $scope.existing;
|
||||
|
||||
console.log(dropzone);
|
||||
var prefix = "http://atlanticbiomedical.com/images/";
|
||||
if ($scope.prefix) {
|
||||
prefix = prefix + $scope.prefix;
|
||||
}
|
||||
|
||||
if (existing) {
|
||||
for (var i = 0; i < existing.length; i++) {
|
||||
var file = { name: existing[i], size: 0, accepted: true, filename: existing[i] };
|
||||
dropzone.options.addedfile.call(dropzone, file);
|
||||
dropzone.options.thumbnail.call(dropzone, file, "http://atlanticbiomedical.com/images/" + existing[i]);
|
||||
dropzone.options.thumbnail.call(dropzone, file, prefix + existing[i]);
|
||||
dropzone.files.push(file);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,20 @@ angular.module('biomed.services', [])
|
||||
isUnique: { method: 'GET', params: { cmd: 'isUnique' } },
|
||||
});
|
||||
})
|
||||
.factory("Devices", function($resource) {
|
||||
return $resource('/api/devices/:id/:cmd',
|
||||
{ id: "@id", cmd: "@cmd" },
|
||||
{
|
||||
index: { method: 'GET', params: {}, isArray: true },
|
||||
deviceTypes: { method: 'GET', params: { cmd: 'deviceTypes' }, isArray: true },
|
||||
makes: { method: 'GET', params: { cmd: 'makes' }, isArray: true },
|
||||
models: { method: 'GET', params: { cmd: 'models' }, isArray: true },
|
||||
get: { method: 'GET', params: { id: 0} },
|
||||
create: { method: 'POST', params: {} },
|
||||
update: { method: 'POST', params: { id: 0} },
|
||||
destroy: { method: 'DELETE', params: { id: 0 } },
|
||||
});
|
||||
})
|
||||
.factory("Posts", function($resource) {
|
||||
return $resource('/api/posts/:id',
|
||||
{ id: "@id" },
|
||||
|
Reference in New Issue
Block a user