Gitlab CSE Unil

Commit 7059eafd authored by Julien Furrer's avatar Julien Furrer
Browse files

Tons of optimizations and small fixes

parent 5b1a198c
...@@ -43,8 +43,6 @@ class AnObjViewSet(viewsets.ModelViewSet): ...@@ -43,8 +43,6 @@ class AnObjViewSet(viewsets.ModelViewSet):
Return only owner's anobjs for write actions and Return only owner's anobjs for write actions and
return also shared anobjs to guests for read actions return also shared anobjs to guests for read actions
""" """
# return AnObj.objects.filter(owner=self.request.user)
user = self.request.user user = self.request.user
q = Q(owner=user) q = Q(owner=user)
if self.action == 'list': if self.action == 'list':
......
...@@ -11,7 +11,10 @@ module.exports = function(grunt) { ...@@ -11,7 +11,10 @@ module.exports = function(grunt) {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %> - ' +
'Copyright (C) <%= grunt.template.today("yyyy") %> Université de Lausanne - ' + 'Copyright (C) <%= grunt.template.today("yyyy") %> Université de Lausanne - ' +
'see licence */' + grunt.util.linefeed 'see licence */' + grunt.util.linefeed,
compress: {
drop_console: false
}
}, },
files: [{ files: [{
expand: true, expand: true,
......
...@@ -165,10 +165,12 @@ function ($, paper, Signal, Config, view) { ...@@ -165,10 +165,12 @@ function ($, paper, Signal, Config, view) {
getAutoSave: function() { return _autoSave; }, getAutoSave: function() { return _autoSave; },
loadData: function (url) { loadData: function (url) {
console.time("loadData");
$.ajax({ $.ajax({
url: url, url: url,
dataType: "json", dataType: "json",
success: function(annotableData) { success: function(annotableData) {
console.timeEnd("loadData");
_events.annotableLoaded.dispatch(annotableData); _events.annotableLoaded.dispatch(annotableData);
}, },
error: function(){ error: function(){
......
...@@ -76,25 +76,31 @@ define([ ...@@ -76,25 +76,31 @@ define([
}); });
var ADIM = { // The ``adim_global_varname`` var in not used in the code.
events: { // The global ADIM var is neither used directly (window.ADIM or just ADIM)
imageLoaded: view.events.imageLoaded // The idea of passing an ADIM object to a callback defined in config was interesting
}, // but is currently not used. The whole stuff will be commented for now.
view: { //
_view: view, //var ADIM = {
resize: view.resize, // events: {
showLayer: view.showLayer, // imageLoaded: view.events.imageLoaded
hideLayer: view.hideLayer, // },
toggleLayer: view.toggleLayer // view: {
}, // _view: view,
io: io, // resize: view.resize,
ui: ui, // showLayer: view.showLayer,
tools: tools, // hideLayer: view.hideLayer,
config: config // toggleLayer: view.toggleLayer
}; // },
window[config.adim_global_varname] = ADIM; // io: io,
// ui: ui,
if (config.ready && typeof config.ready === 'function') { // tools: tools,
config.ready(ADIM); // config: config
} //};
//
//// window[config.adim_global_varname] = ADIM; // <-- FIXME: should be removed, it could be a security issue
//
//if (config.ready && typeof config.ready === 'function') {
// config.ready(ADIM);
//}
}); });
\ No newline at end of file
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
* @CREATION-DATE: 01.09.14 * @CREATION-DATE: 01.09.14
* *
*/ */
define([ define([
"jquery", "jquery",
"paper", "paper",
...@@ -37,84 +36,86 @@ define([ ...@@ -37,84 +36,86 @@ define([
"helper/exporter" "helper/exporter"
], ],
function ($, paper, Signal, config, view, io, tools, attributes, ui, Users, theme, fileUploader, exporter) { function ($, paper, Signal, config, view, io, tools, attributes, ui, Users, theme, fileUploader, exporter) {
var _events = {}; var _events = {};
var CANVAS_EL_ID = 'my-canvas'; var CANVAS_EL_ID = 'my-canvas';
console.timeEnd("main app loading");
function initSignalRouting() {
// ----- Events Listeners ----------------------------- tools.events.annotationAdded.add(function(annotation) {
tools.events.annotationAdded.add(function(annotation) { io.saveAnnotations(annotation);
io.saveAnnotations(annotation); });
});
tools.events.annotationChanged.add(function(annotations) {
io.saveAnnotations(annotations);
});
attributes.events.annotationChanged.add(function(annotations, forceAll) { tools.events.annotationChanged.add(function(annotations) {
if (forceAll) {
io.saveUserAnnotations();
} else {
io.saveAnnotations(annotations); io.saveAnnotations(annotations);
} });
});
view.events.annotationPropertyChanged.add(function(annotation){ attributes.events.annotationChanged.add(function(annotations, forceAll) {
io.saveAnnotations([annotation]); if (forceAll) {
}); io.saveUserAnnotations();
} else {
io.saveAnnotations(annotations);
}
});
view.events.annotationRemoved.add(function(annotId) { view.events.annotationPropertyChanged.add(function(annotation){
io.removeAnnotation(annotId); io.saveAnnotations([annotation]);
}); });
ui.events.saveButClick.add(function(){ view.events.annotationRemoved.add(function(annotId) {
io.saveUserAnnotations(); io.removeAnnotation(annotId);
}); });
ui.events.autoSaveChanged.add(function(autoSave){ ui.events.saveButClick.add(function(){
//io.setAutoSave(autoSave); io.saveUserAnnotations();
}); });
/** ui.events.autoSaveChanged.add(function(autoSave){
* When an annotation is created, it has a temporary id until it is saved //io.setAutoSave(autoSave);
* to the DB. After saving, we use the temporary id to retrieve the Annotation });
* and give it the new id, generated by th DB
*/
io.events.annotationAdded.add(function(data){
// Unserialize item
var itemData = JSON.parse(data.item);
// PlacedSymbol are serialized as an array of two items,
// We want the second one
if ($.isArray(itemData[0])) {
itemData = itemData[1];
}
var tId = itemData[1].data.tId; /**
if (tId) { * When an annotation is created, it has a temporary id until it is saved
var item = view.getItemByTempId(tId); * to the DB. After saving, we use the temporary id to retrieve the Annotation
if (item) { * and give it the new id, generated by th DB
item.data.id = data.id; */
delete(item.data.tId); // FIXME: It doesn't work, tID is still in the data io.events.annotationAdded.add(function(data){
// Unserialize item
var itemData = JSON.parse(data.item);
// PlacedSymbol are serialized as an array of two items,
// We want the second one
if ($.isArray(itemData[0])) {
itemData = itemData[1];
} }
}
if (config.autoSaveThumbnail) {
sendThumbnail();
}
});
var tId = itemData[1].data.tId;
if (tId) {
var item = view.getItemByTempId(tId);
if (item) {
item.data.id = data.id;
delete(item.data.tId); // FIXME: It doesn't work, tID is still in the data
}
}
if (config.autoSaveThumbnail) {
sendThumbnail();
}
});
io.events.annotationSaved.add(function(data){
if (config.autoSaveThumbnail) {
sendThumbnail();
}
});
io.events.annotationRemoved.add(function(){ io.events.annotationSaved.add(function(data){
if (config.autoSaveThumbnail) { if (config.autoSaveThumbnail) {
sendThumbnail(); sendThumbnail();
} }
}); });
io.events.annotationRemoved.add(function(){
if (config.autoSaveThumbnail) {
sendThumbnail();
}
});
}
initSignalRouting();
var sendThumbnail = (function() { var sendThumbnail = (function() {
var throttleDelay = 5 * 1000, // Waiting time before executing job var throttleDelay = 5 * 1000, // Waiting time before executing job
...@@ -164,6 +165,7 @@ define([ ...@@ -164,6 +165,7 @@ define([
$(function(){ $(function(){
console.time("main dom ready");
//theme.updateTheme(); //theme.updateTheme();
if (!view.init(CANVAS_EL_ID)) { if (!view.init(CANVAS_EL_ID)) {
...@@ -171,11 +173,6 @@ define([ ...@@ -171,11 +173,6 @@ define([
return; return;
} }
if (config.mode === config.MODE_EDIT) {
var userLayer = view.getOrCreateUserLayer(config.user.id, config.user.username);
userLayer.opacity = 1;
}
attributes.init(); attributes.init();
ui.init(); ui.init();
...@@ -296,50 +293,59 @@ define([ ...@@ -296,50 +293,59 @@ define([
} }
}); });
// Stries // FIXME: A supprimer
var concordantstrTool = tools.tools['concordantstr']; //// Stries
var discordantstrTool = tools.tools['discordantstr']; //var concordantstrTool = tools.tools['concordantstr'];
var cmsareaTool = tools.tools['cmsarea']; //var discordantstrTool = tools.tools['discordantstr'];
//var cmsareaTool = tools.tools['cmsarea'];
// ----- Initialise les tools avec les données de l'annotable ----- // ----- Initialise les tools avec les données de l'annotable -----
io.events.annotableLoaded.add(function(annotableData){ io.events.annotableLoaded.add(function(annotableData){
// Load the image // Add known users to the Users module
// view.loadImage({url: annotableData.image_url, bgUrl: annotableData.image_bg_url},
Users.addUsers([{id: annotableData.owner, username: annotableData.owner_name}]); Users.addUsers([{id: annotableData.owner, username: annotableData.owner_name}]);
//Users.addUsers(annotableData.members); //Users.addUsers(annotableData.members); // members are only loaded if needed. this statement should be removed
// Load the image
console.time("loadImage");
view.loadImage({url: config.annotable.image}, view.loadImage({url: config.annotable.image},
function(){ function(){
console.timeEnd("loadImage");
console.time("loadAnnotations");
view.loadAnnotations(annotableData.annotations, config.user.id); view.loadAnnotations(annotableData.annotations, config.user.id);
console.timeEnd("loadAnnotations");
} }
); );
}); });
console.timeEnd("main dom ready");
}); });
var ADIM = { // The ``adim_global_varname`` var in not used in the code.
events: { // The global ADIM var is neither used directly (window.ADIM or just ADIM)
imageLoaded: view.events.imageLoaded // The idea of passing an ADIM object to a callback defined in config was interesting
}, // but is currently not used. The whole stuff will be commented for now.
view: {
_view: view, //var ADIM = {
resize: view.resize, // events: {
showLayer: view.showLayer, // imageLoaded: view.events.imageLoaded
hideLayer: view.hideLayer, // },
toggleLayer: view.toggleLayer // view: {
}, // _view: view,
io: io, // resize: view.resize,
ui: ui, // showLayer: view.showLayer,
tools: tools, // hideLayer: view.hideLayer,
config: config // toggleLayer: view.toggleLayer
}; // },
window[config.adim_global_varname] = ADIM; // io: io,
window.DBG = Users; // ui: ui,
// tools: tools,
if (config.ready && typeof config.ready === 'function') { // config: config
config.ready(ADIM); //};
} //
// window[config.adim_global_varname] = ADIM; // <-- FIXME: should be removed, it could be a security issue
//
//if (config.ready && typeof config.ready === 'function') {
// config.ready(ADIM);
//}
}); });
\ No newline at end of file
...@@ -119,6 +119,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -119,6 +119,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
view.events.imageLoaded.add(function(evt) { view.events.imageLoaded.add(function(evt) {
adjustCanvasToImage(evt.raster); adjustCanvasToImage(evt.raster);
$("#page-loader").remove(); $("#page-loader").remove();
console.timeEnd("complete app");
}); });
view.events.annotationsLoaded.add(function() { view.events.annotationsLoaded.add(function() {
...@@ -129,6 +130,8 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -129,6 +130,8 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
updateSaveButState(); updateSaveButState();
}); });
view.events.userLayerVisibilityChanged.add(onUserLayerVisChange);
tools.events.annotationSelected.add(function(item) { tools.events.annotationSelected.add(function(item) {
// ----- Update Properties Panel ----- // ----- Update Properties Panel -----
// disable properties panel if there is no item or more than one // disable properties panel if there is no item or more than one
...@@ -201,7 +204,6 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -201,7 +204,6 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
} }
}); });
io.events.loadingError.add(function(err){ io.events.loadingError.add(function(err){
var pageLoader = $("#page-loader"); var pageLoader = $("#page-loader");
if (pageLoader.length) { if (pageLoader.length) {
...@@ -275,10 +277,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -275,10 +277,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
// Initialize reserved width and height // Initialize reserved width and height
updateReservedSpace(); updateReservedSpace();
//_reservedWidth = ( (config.mode === config.MODE_EDIT ? _toolsCol.outerWidth() : 0 ) +
// ( (config.ui.show_side_col) ? _sideCol.outerWidth() + 24 : 50 )
//);
//_reservedHeight = ( $("#canvas-col").offset().top + _canvasToolBar.outerHeight() + 20 );
// The amount of window width needed for navbar elements other than anobj title // The amount of window width needed for navbar elements other than anobj title
var _$mainNavBar = $("#main-navbar"); var _$mainNavBar = $("#main-navbar");
...@@ -296,12 +295,44 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -296,12 +295,44 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
return value; return value;
})(); })();
_$w.on('resize', function(){
adjustCanvasToImage(); // Window Resize event (debounced version)
_$mainNavBar.find(".adim-image-name .text").css("max-width", _$w.width() - _navBarTitleDelta); // -------------------
(function(){ // isolate to avoid useless pollution of current scope
var $b = $("body"),
bW = $b.outerWidth(), bH = $b.outerHeight(),
startResize = _.debounce(function(){
if (!$b.data("resize-fixed")) {
$b.css({
width: bW, maxWidth: bW, minWidth: bW,
height: bH, maxHeight: bH, minHeight: bH
});
$b.data("resize-fixed", true);
}
}, 50, true),
afterResize = _.debounce(function(){
$b.css({
width: "auto", maxWidth: "none", minWidth: 0,
height: "auto", maxHeight: "none", minHeight: 0
});
$b.data("resize-fixed", false);
bW = $b.outerWidth();
bH = $b.outerHeight();
adjustCanvasToImage();
_$mainNavBar.find(".adim-image-name .text").css("max-width", _$w.width() - _navBarTitleDelta);
}, 100)
;
_$w.on('resize', function(event){
startResize();
afterResize();
//adjustCanvasToImage();
//_$mainNavBar.find(".adim-image-name .text").css("max-width", _$w.width() - _navBarTitleDelta);
}); });
})();
// TODO: à quoi sert ce code ?
// Update the scrollbar of the panels that needs it. Depends on the available height
$("#side-col-panel-group .panel-collapse") $("#side-col-panel-group .panel-collapse")
.on('hidden.bs.collapse shown.bs.collapse', function () { .on('hidden.bs.collapse shown.bs.collapse', function () {
_adjustCanvasFrame(); _adjustCanvasFrame();
...@@ -321,27 +352,31 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -321,27 +352,31 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
updateViewMode(mode); updateViewMode(mode);
}); });
$(".adim-view-mod-tabs").find("[data-toggle=tooltip]").tooltip({
placement: 'bottom',
delay: { "show": 500, "hide": 50 }
});
// Fullscreen mode //// Fullscreen mode
(function(enabled){ //(function(enabled){
if (!enabled) return; // if (!enabled) return;
var el = $('body').get(0); // var el = $('body').get(0);
var requestFullscreen = // var requestFullscreen =
el.requestFullscreen ? el.requestFullscreen : // el.requestFullscreen ? el.requestFullscreen :
el.mozRequestFullScreen ? el.mozRequestFullScreen : // el.mozRequestFullScreen ? el.mozRequestFullScreen :
el.webkitRequestFullscreen ? el.webkitRequestFullscreen : // el.webkitRequestFullscreen ? el.webkitRequestFullscreen :
el.msRequestFullscreen ? el.msRequestFullscreen : null; // el.msRequestFullscreen ? el.msRequestFullscreen : null;
; // ;
if (requestFullscreen) { // if (requestFullscreen) {
$("#navbut-fullscreen").removeClass("hidden") // $("#navbut-fullscreen").removeClass("hidden")
.find("a").click(function(event){ // .find("a").click(function(event){
event.preventDefault; // event.preventDefault;
requestFullscreen.call($('body').get(0)); // requestFullscreen.call($('body').get(0));
return false; // return false;
}); // });
} // }
//
})(); //})();
$("#but-zoom-fit").on('click', zoomFitContent); $("#but-zoom-fit").on('click', zoomFitContent);
$("#but-zoom-100").on('click', function(event) { $("#but-zoom-100").on('click', function(event) {
...@@ -515,18 +550,26 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -515,18 +550,26 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
* Theses values are used to resize the canvas when the size of the window is changed. * Theses values are used to resize the canvas when the size of the window is changed.
* used by adjustCanvasToImage() * used by adjustCanvasToImage()
*/ */
function updateReservedSpace() { var updateReservedSpace = function(){
_reservedWidth = ( var colTop = $("#canvas-col").offset().top,
// Tools column toolsWidth = _toolsCol.outerWidth(),
( _toolsCol.is(":visible") ? _toolsCol.outerWidth() : 0 ) + tbHeight = _canvasToolBar.outerHeight();
// Side column updateReservedSpace = function () {
( ! config.ui.show_side_col ? 50 : //if (!colTop) colTop = $("#canvas-col").offset().top;
_sideCol.is(".collapsed") ? 32 : _sideCol.outerWidth() _reservedWidth = (
) + // Tools column
24 ( _toolsCol.is(":visible") ? toolsWidth : 0 ) +
); // Side column
_reservedHeight = ( $("#canvas-col").offset().top + _canvasToolBar.outerHeight() + 20 ); ( ! config.ui.show_side_col ? 50 :
} _sideCol.is(".collapsed") ? 32 : _sideCol.outerWidth()
) +
24