uploadCtrl.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. app.controller('uploadCtrl', function ($scope, $http,video,notify) {
  2. $scope.profesor="";
  3. $scope.texto1="";
  4. $scope.texto2="";
  5. $scope.video = video;
  6. $scope.diapos = [];
  7. var canvas = document.getElementById('c');
  8. var container = canvas.parentNode;
  9. var ctx = canvas.getContext('2d');
  10. var dpr = window.devicePixelRatio || 1;
  11. var img = new Image();
  12. var diapos = [];
  13. img.src="https://curso.especificosba.com.ar/diapo/EBA/1.png"; //Cargo la imagen inicial, a espera de informacion
  14. img.onload=function(){ //Cuando una imagen carga en mi obj imagen, quiero que se dibuje en canvas
  15. ctx.drawImage(img,0,0,canvas.width, canvas.height);
  16. }
  17. $scope.updateDiapos = function(d) {
  18. diapos = JSON.parse(d);
  19. parseMessage(diapos[0]);
  20. }
  21. function respondCanvas(){
  22. canvas.setAttribute('width', container.offsetWidth);
  23. canvas.setAttribute('height', container.offsetWidth/4*3);
  24. }
  25. respondCanvas();
  26. if (!String.prototype.format) {
  27. String.prototype.format = function() {
  28. var args = arguments;
  29. return this.replace(/{(\d+)}/g, function(match, number) {
  30. return
  31. ( typeof args[number] != 'undefined' ? args[number] : match );
  32. });
  33. };
  34. }
  35. function parseMessage(msg){
  36. if (msg==undefined)
  37. return;
  38. switch(msg.type){
  39. case "draw":
  40. drawOnCanvas(msg.points,msg.color);
  41. break;
  42. case "clean":
  43. ctx.drawImage(img,0,0,canvas.width, canvas.height);
  44. break;
  45. case "diapo":
  46. img.src="https://curso.especificosba.com.ar/diapo/{0}/{1}.png".format(msg.PDF,msg.slide);
  47. break;
  48. }
  49. }
  50. function drawOnCanvas(points,color) {
  51. if(points.length==0) return;
  52. ctx.strokeStyle = color;
  53. ctx.beginPath();
  54. ctx.moveTo(points[0].x, points[0].y);
  55. for(var i=1; i<points.length; i++) {
  56. ctx.lineTo(points[i].x, points[i].y);
  57. }
  58. ctx.stroke();
  59. }
  60. $scope.post = function() {
  61. var data = {
  62. prof: $scope.profesor,
  63. texto1: $scope.texto1,
  64. texto2: $scope.texto2,
  65. id: $scope.video._id
  66. };
  67. $http.post('/back/upload/', data)
  68. .success(function(data,state) {
  69. notify({message:data.status,classes:"alert"});
  70. })
  71. .error(function(data) {
  72. notify({message:data.status,classes:"alert alert-danger"});
  73. });
  74. };
  75. });