| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- app.controller('uploadCtrl', function ($scope, $http,video,notify) {
- $scope.profesor="";
- $scope.texto1="";
- $scope.texto2="";
- $scope.video = video;
- $scope.diapos = [];
- var canvas = document.getElementById('c');
- var container = canvas.parentNode;
- var ctx = canvas.getContext('2d');
- var dpr = window.devicePixelRatio || 1;
- var img = new Image();
- var diapos = [];
- img.src="https://curso.especificosba.com.ar/diapo/EBA/1.png"; //Cargo la imagen inicial, a espera de informacion
- img.onload=function(){ //Cuando una imagen carga en mi obj imagen, quiero que se dibuje en canvas
- ctx.drawImage(img,0,0,canvas.width, canvas.height);
- }
- $scope.updateDiapos = function(d) {
- diapos = JSON.parse(d);
- parseMessage(diapos[0]);
- }
- function respondCanvas(){
- canvas.setAttribute('width', container.offsetWidth);
- canvas.setAttribute('height', container.offsetWidth/4*3);
- }
-
- respondCanvas();
- if (!String.prototype.format) {
- String.prototype.format = function() {
- var args = arguments;
- return this.replace(/{(\d+)}/g, function(match, number) {
- return
- ( typeof args[number] != 'undefined' ? args[number] : match );
- });
- };
- }
- function parseMessage(msg){
- if (msg==undefined)
- return;
- switch(msg.type){
- case "draw":
- drawOnCanvas(msg.points,msg.color);
- break;
- case "clean":
- ctx.drawImage(img,0,0,canvas.width, canvas.height);
- break;
- case "diapo":
- img.src="https://curso.especificosba.com.ar/diapo/{0}/{1}.png".format(msg.PDF,msg.slide);
- break;
- }
- }
- function drawOnCanvas(points,color) {
- if(points.length==0) return;
- ctx.strokeStyle = color;
- ctx.beginPath();
- ctx.moveTo(points[0].x, points[0].y);
-
- for(var i=1; i<points.length; i++) {
- ctx.lineTo(points[i].x, points[i].y);
- }
- ctx.stroke();
- }
- $scope.post = function() {
- var data = {
- prof: $scope.profesor,
- texto1: $scope.texto1,
- texto2: $scope.texto2,
- id: $scope.video._id,
- diapos: diapos
- };
- $http.post('/back/upload/', data)
- .success(function(data,state) {
- notify({message:data.status,classes:"alert"});
- })
- .error(function(data) {
- notify({message:data.status,classes:"alert alert-danger"});
- });
- };
- });
|