Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

upload.controller.js 3.2KB

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