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.8KB

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