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 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. name: "Sepia",
  16. id: "Sepia"
  17. },
  18. {
  19. name: "Increase Contrast",
  20. id: "ContrastInc"
  21. },
  22. {
  23. name: "Decrease Contrast",
  24. id: "ContrastDec"
  25. }
  26. ];
  27. var promiseImage = {
  28. id: "promiseImage",
  29. loaderGroups: ["imageView"]
  30. };
  31. $scope.input = angular.element(angular.element("#filePicker")[0]);
  32. $scope.input.on("change", function (e) {
  33. var reader = new FileReader();
  34. var f = e.target.files[0];
  35. reader.readAsBinaryString(f);
  36. reader.onload = (function(file) {
  37. return function(e) {
  38. $scope.$apply(function() {
  39. $scope.fileLoaded(e.target.result, file);
  40. });
  41. };
  42. })(f);
  43. });
  44. $scope.fileLoaded = function(content, file)
  45. {
  46. $scope.image = {
  47. content: content,
  48. name: file.name
  49. };
  50. };
  51. $scope.pickFile = function()
  52. {
  53. $scope.input.click();
  54. };
  55. $scope.applyEffect = function(effect, data)
  56. {
  57. EffectsBusiness.apply({
  58. effect: effect,
  59. image: $scope.image.content,
  60. data: data
  61. }, promiseImage).then(function(data)
  62. {
  63. $scope.image.content = data.image;
  64. }, errorDialogMd.errorDialog);
  65. };
  66. $scope.isUploadVisible = function () {
  67. return luticateAuthCache.getUser() != null;
  68. };
  69. $scope.canUpload = function () {
  70. return $scope.image != null;
  71. };
  72. $scope.upload = function()
  73. {
  74. ImagesBusiness.upload({
  75. image: $scope.image.content,
  76. name: $scope.image.name
  77. }, promiseImage).then(function(data)
  78. {
  79. $state.go("images");
  80. }, errorDialogMd.errorDialog);
  81. };
  82. $scope.test = function()
  83. {
  84. $scope.applyEffect("BlackAndWhite", null);
  85. };
  86. }]);