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

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