diff --git a/.babelrc b/.babelrc index 7de7f73a8..60d15b8c6 100644 --- a/.babelrc +++ b/.babelrc @@ -1 +1 @@ -{ "presets": [ "es2015","react" ] } \ No newline at end of file +{ "presets": [ "es2015","react" ] } diff --git a/cloudcvIde/static/cloudcvIde/bundle/bundle.js b/cloudcvIde/static/cloudcvIde/bundle/bundle.js index c17930aa0..e794cc8c2 100644 --- a/cloudcvIde/static/cloudcvIde/bundle/bundle.js +++ b/cloudcvIde/static/cloudcvIde/bundle/bundle.js @@ -27070,7 +27070,7 @@ var _error2 = _interopRequireDefault(_error); - var _panZoom = __webpack_require__(251); + var _panZoom = __webpack_require__(239); var _panZoom2 = _interopRequireDefault(_panZoom); @@ -27955,7 +27955,150 @@ exports.default = Error; /***/ }, -/* 239 */, +/* 239 */ +/***/ function(module, exports) { + + 'use strict'; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + + exports.default = function () { + "use strict"; + + var panZoom = document.getElementById('panZoomContainer'), + canvas = document.getElementById('jsplumbContainer'); + console.log(panZoom.offsetLeft); + if (!canvas) { + return; + } + + var params = { x: getQueryVariable('x'), y: getQueryVariable('y'), zoom: getQueryVariable('zoom') }; + + var current = {}; + current.x = params.x ? parseFloat(params.x) : $(canvas).data('x'); + current.y = params.y ? parseFloat(params.y) : $(canvas).data('y'); + current.zoom = params.zoom ? parseFloat(params.zoom) : $(canvas).data('zoom'); + + canvas.x = 0;canvas.y = 0;canvas.scale = 1; + canvas.updateContainerPosition = function () { + canvas.style.left = canvas.x + 'px';canvas.style.top = canvas.y + 'px'; + }; + canvas.updateContainerScale = function () { + canvas.style.transform = 'scale(' + canvas.scale + ')'; + }; + + canvas.updateContainerPosition(); + canvas.updateContainerScale(); + + function updateTextPosition(e) { + e.style.left = $(e).data("x") / current.zoom + 'px'; + e.style.top = $(e).data("y") / current.zoom + 'px'; + } + + function newText(x, y, size, text) { + var tb = document.createElement('div'); + tb.className = "text"; + tb.contentEditable = true; + tb.innerHTML = text; + $(tb).data("x", x).data("y", y).data("size", size); + updateTextPosition(tb); + canvas.appendChild(tb); + return tb; + } + + var dragging = false, + state = { click: false, pan: false }, + previousMousePosition; + + panZoom.onmousedown = function (e) { + console.log('mouse down'); + e.preventDefault(); + dragging = true; + state.click = true; + previousMousePosition = { x: e.pageX, y: e.pageY }; + }; + + window.onmouseup = function () { + //panZoom.onmouseup = function() { + console.log('mouse up'); + dragging = false; + }; + + panZoom.ondragstart = function (e) { + console.log('on drag start'); + e.preventDefault(); + }; + + panZoom.onmousemove = function (e) { + console.log('on mouse move'); + if (state.click) { + state.pan = true; + } + if (dragging && !e.shiftKey) { + canvas.style.transitionDuration = "0s"; + canvas.x += e.pageX - previousMousePosition.x; + canvas.y += e.pageY - previousMousePosition.y; + canvas.updateContainerPosition(); + previousMousePosition = { x: e.pageX, y: e.pageY }; + //instance.repaintEverything(); + } + }; + + panZoom.ondblclick = function (e) { + e.preventDefault(); + onZoom(e.ctrlKey || e.metaKey ? current.zoom * 1.7 * 1.7 : current.zoom / 1.7 / 1.7, e.clientX - panZoom.offsetLeft, e.clientY - panZoom.offsetTop); + }; + + function onZoom(zoom, cx, cy) { + var dx = cx - canvas.x; + var dy = cy - canvas.y; + var newdx = dx * current.zoom / zoom; + var newdy = dy * current.zoom / zoom; + canvas.x = cx - newdx; + canvas.y = cy - newdy; + canvas.scale = 1 / zoom; + canvas.style.transitionDuration = "0s"; + canvas.updateContainerPosition(); + canvas.updateContainerScale(); + current.zoom = zoom; + instance.setZoom(canvas.scale); + //instance.repaintEverything(); + } + + var mousewheeldelta = 0, + last_e, + mousewheeltimer = null, + mousewheel; + + mousewheel = function mousewheel(e) { + e.preventDefault(); + var delta = Math.max(-1, Math.min(1, e.wheelDelta || -e.detail)); + //onZoom((delta > 0) ? current.zoom / 1.7 : current.zoom * 1.7, e.clientX - panZoom.offsetLeft, e.clientY - panZoom.offsetTop); + onZoom(delta > 0 ? current.zoom / 1.7 : current.zoom * 1.7, e.clientX - panZoom.getBoundingClientRect().left, e.clientY - panZoom.getBoundingClientRect().top); + }; + + if ("onmousewheel" in document) { + panZoom.onmousewheel = mousewheel; + } else { + panZoom.addEventListener('DOMMouseScroll', mousewheel, false); + } + + function getQueryVariable(id) { + var params = window.location.search.substring(1).split("&");for (var i = 0; i < params.length; i++) { + var p = params[i].split("=");if (p[0] == id) { + return p[1]; + } + }return false; + } + + return state; + }; + + ; + +/***/ }, /* 240 */ /***/ function(module, exports, __webpack_require__) { @@ -29233,149 +29376,5 @@ } -/***/ }, -/* 251 */ -/***/ function(module, exports) { - - 'use strict'; - - Object.defineProperty(exports, "__esModule", { - value: true - }); - - exports.default = function () { - "use strict"; - - var panZoom = document.getElementById('panZoomContainer'), - canvas = document.getElementById('jsplumbContainer'); - console.log(panZoom.offsetLeft); - if (!canvas) { - return; - } - - var params = { x: getQueryVariable('x'), y: getQueryVariable('y'), zoom: getQueryVariable('zoom') }; - - var current = {}; - current.x = params.x ? parseFloat(params.x) : $(canvas).data('x'); - current.y = params.y ? parseFloat(params.y) : $(canvas).data('y'); - current.zoom = params.zoom ? parseFloat(params.zoom) : $(canvas).data('zoom'); - - canvas.x = 0;canvas.y = 0;canvas.scale = 1; - canvas.updateContainerPosition = function () { - canvas.style.left = canvas.x + 'px';canvas.style.top = canvas.y + 'px'; - }; - canvas.updateContainerScale = function () { - canvas.style.transform = 'scale(' + canvas.scale + ')'; - }; - - canvas.updateContainerPosition(); - canvas.updateContainerScale(); - - function updateTextPosition(e) { - e.style.left = $(e).data("x") / current.zoom + 'px'; - e.style.top = $(e).data("y") / current.zoom + 'px'; - } - - function newText(x, y, size, text) { - var tb = document.createElement('div'); - tb.className = "text"; - tb.contentEditable = true; - tb.innerHTML = text; - $(tb).data("x", x).data("y", y).data("size", size); - updateTextPosition(tb); - canvas.appendChild(tb); - return tb; - } - - var dragging = false, - state = { click: false, pan: false }, - previousMousePosition; - - panZoom.onmousedown = function (e) { - console.log('mouse down'); - e.preventDefault(); - dragging = true; - state.click = true; - previousMousePosition = { x: e.pageX, y: e.pageY }; - }; - - window.onmouseup = function () { - //panZoom.onmouseup = function() { - console.log('mouse up'); - dragging = false; - }; - - panZoom.ondragstart = function (e) { - console.log('on drag start'); - e.preventDefault(); - }; - - panZoom.onmousemove = function (e) { - console.log('on mouse move'); - if (state.click) { - state.pan = true; - } - if (dragging && !e.shiftKey) { - canvas.style.transitionDuration = "0s"; - canvas.x += e.pageX - previousMousePosition.x; - canvas.y += e.pageY - previousMousePosition.y; - canvas.updateContainerPosition(); - previousMousePosition = { x: e.pageX, y: e.pageY }; - //instance.repaintEverything(); - } - }; - - panZoom.ondblclick = function (e) { - e.preventDefault(); - onZoom(e.ctrlKey || e.metaKey ? current.zoom * 1.7 * 1.7 : current.zoom / 1.7 / 1.7, e.clientX - panZoom.offsetLeft, e.clientY - panZoom.offsetTop); - }; - - function onZoom(zoom, cx, cy) { - var dx = cx - canvas.x; - var dy = cy - canvas.y; - var newdx = dx * current.zoom / zoom; - var newdy = dy * current.zoom / zoom; - canvas.x = cx - newdx; - canvas.y = cy - newdy; - canvas.scale = 1 / zoom; - canvas.style.transitionDuration = "0s"; - canvas.updateContainerPosition(); - canvas.updateContainerScale(); - current.zoom = zoom; - instance.setZoom(canvas.scale); - //instance.repaintEverything(); - } - - var mousewheeldelta = 0, - last_e, - mousewheeltimer = null, - mousewheel; - - mousewheel = function mousewheel(e) { - e.preventDefault(); - var delta = Math.max(-1, Math.min(1, e.wheelDelta || -e.detail)); - //onZoom((delta > 0) ? current.zoom / 1.7 : current.zoom * 1.7, e.clientX - panZoom.offsetLeft, e.clientY - panZoom.offsetTop); - onZoom(delta > 0 ? current.zoom / 1.7 : current.zoom * 1.7, e.clientX - panZoom.getBoundingClientRect().left, e.clientY - panZoom.getBoundingClientRect().top); - }; - - if ("onmousewheel" in document) { - panZoom.onmousewheel = mousewheel; - } else { - panZoom.addEventListener('DOMMouseScroll', mousewheel, false); - } - - function getQueryVariable(id) { - var params = window.location.search.substring(1).split("&");for (var i = 0; i < params.length; i++) { - var p = params[i].split("=");if (p[0] == id) { - return p[1]; - } - }return false; - } - - return state; - }; - - ; - /***/ } /******/ ]); \ No newline at end of file diff --git a/cloudcvIde/views.py b/cloudcvIde/views.py index 12f780568..27249a514 100644 --- a/cloudcvIde/views.py +++ b/cloudcvIde/views.py @@ -1,5 +1,6 @@ from django.shortcuts import render from django.views.decorators.csrf import csrf_exempt +from django.http import JsonResponse import json import yaml from django.http import HttpResponse @@ -390,9 +391,8 @@ def exportToCaffe(request): with open(BASE_DIR+'/cloudcvIde/media/prototxt/'+randomId+'.prototxt', 'w') as f: f.write(prototxt) - return HttpResponse( - json.dumps({'id': randomId, 'name': randomId+'.prototxt', 'url': '/media/prototxt/'+randomId+'.prototxt'}), - content_type="application/json") + return JsonResponse({'id': randomId, 'name': randomId+'.prototxt', 'url': '/media/prototxt/'+randomId+'.prototxt'}) + @csrf_exempt def exportToTensorflow(request): @@ -408,9 +408,7 @@ def exportToTensorflow(request): os.system('python '+BASE_DIR+'/cloudcvIde/caffe-tensorflow-master/convert.py '+BASE_DIR+'/cloudcvIde/media/prototxt/'+randomId+'.prototxt --code-output-path='+BASE_DIR+'/cloudcvIde/media/tensorflow/'+randomId+'.py') - return HttpResponse( - json.dumps({'id': randomId, 'name': randomId+'.py', 'url': '/media/tensorflow/'+randomId+'.py'}), - content_type="application/json") + return JsonResponse({'id': randomId, 'name': randomId+'.py', 'url': '/media/tensorflow/'+randomId+'.py'}) @csrf_exempt @@ -526,6 +524,4 @@ def importModel(request): net[id] = jsonLayer i = i + 1 - return HttpResponse( - json.dumps({'result': 'success', 'net': net}), - content_type="application/json") + return JsonResponse({'result': 'success', 'net': net})