You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

upload.controller.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. angular.module('app')
  2. .controller('UploadController', ['$scope', '$state', '$mdDialog', 'EffectsBusiness', 'ImagesBusiness', 'luticateAuthCache', 'errorDialogMd',
  3. function($scope, $state, $mdDialog, EffectsBusiness, ImagesBusiness, luticateAuthCache, errorDialogMd) {
  4. $scope.image = null;
  5. $scope.effects = [
  6. {
  7. name: "Black and White",
  8. id: "BlackAndWhite"
  9. },
  10. {
  11. name: "GrayScale",
  12. id: "GrayScale"
  13. }
  14. ];
  15. var promiseImage = {
  16. id: "promiseImage",
  17. loaderGroups: ["imageView"]
  18. };
  19. $scope.input = angular.element(angular.element("#filePicker")[0]);
  20. $scope.input.on("change", function (e) {
  21. var reader = new FileReader();
  22. var f = e.target.files[0];
  23. reader.readAsBinaryString(f);
  24. reader.onload = (function(file) {
  25. return function(e) {
  26. $scope.$apply(function() {
  27. $scope.fileLoaded(e.target.result, file);
  28. });
  29. };
  30. })(f);
  31. });
  32. $scope.fileLoaded = function(content, file)
  33. {
  34. $scope.image = {
  35. content: content,
  36. name: file.name
  37. };
  38. };
  39. $scope.pickFile = function()
  40. {
  41. $scope.input.click();
  42. };
  43. $scope.applyEffect = function(effect, data)
  44. {
  45. EffectsBusiness.apply({
  46. effect: effect,
  47. image: $scope.image.content,
  48. data: data
  49. }, promiseImage).then(function(data)
  50. {
  51. $scope.image.content = data.image;
  52. }, errorDialogMd.errorDialog);
  53. };
  54. $scope.isUploadVisible = function () {
  55. return luticateAuthCache.getUser() != null;
  56. };
  57. $scope.canUpload = function () {
  58. return $scope.image != null;
  59. };
  60. $scope.upload = function()
  61. {
  62. ImagesBusiness.upload({
  63. image: $scope.image.content,
  64. name: $scope.image.name
  65. }, promiseImage).then(function(data)
  66. {
  67. $state.go("images");
  68. }, errorDialogMd.errorDialog);
  69. };
  70. $scope.test = function()
  71. {
  72. $scope.applyEffect("BlackAndWhite", null);
  73. };
  74. }]);