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,11 +36,11 @@ define([ ...@@ -37,11 +36,11 @@ 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);
}); });
...@@ -114,7 +113,9 @@ define([ ...@@ -114,7 +113,9 @@ define([
sendThumbnail(); 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(){
// Window Resize event (debounced version)
// -------------------
(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(); adjustCanvasToImage();
_$mainNavBar.find(".adim-image-name .text").css("max-width", _$w.width() - _navBarTitleDelta); _$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({
// Fullscreen mode placement: 'bottom',
(function(enabled){ delay: { "show": 500, "hide": 50 }
if (!enabled) return;
var el = $('body').get(0);
var requestFullscreen =
el.requestFullscreen ? el.requestFullscreen :
el.mozRequestFullScreen ? el.mozRequestFullScreen :
el.webkitRequestFullscreen ? el.webkitRequestFullscreen :
el.msRequestFullscreen ? el.msRequestFullscreen : null;
;
if (requestFullscreen) {
$("#navbut-fullscreen").removeClass("hidden")
.find("a").click(function(event){
event.preventDefault;
requestFullscreen.call($('body').get(0));
return false;
}); });
}
})(); //// Fullscreen mode
//(function(enabled){
// if (!enabled) return;
// var el = $('body').get(0);
// var requestFullscreen =
// el.requestFullscreen ? el.requestFullscreen :
// el.mozRequestFullScreen ? el.mozRequestFullScreen :
// el.webkitRequestFullscreen ? el.webkitRequestFullscreen :
// el.msRequestFullscreen ? el.msRequestFullscreen : null;
// ;
// if (requestFullscreen) {
// $("#navbut-fullscreen").removeClass("hidden")
// .find("a").click(function(event){
// event.preventDefault;
// requestFullscreen.call($('body').get(0));
// 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(){
var colTop = $("#canvas-col").offset().top,
toolsWidth = _toolsCol.outerWidth(),
tbHeight = _canvasToolBar.outerHeight();
updateReservedSpace = function () {
//if (!colTop) colTop = $("#canvas-col").offset().top;
_reservedWidth = ( _reservedWidth = (
// Tools column // Tools column
( _toolsCol.is(":visible") ? _toolsCol.outerWidth() : 0 ) + ( _toolsCol.is(":visible") ? toolsWidth : 0 ) +
// Side column // Side column
( ! config.ui.show_side_col ? 50 : ( ! config.ui.show_side_col ? 50 :
_sideCol.is(".collapsed") ? 32 : _sideCol.outerWidth() _sideCol.is(".collapsed") ? 32 : _sideCol.outerWidth()
) + ) +
24 24
); );
_reservedHeight = ( $("#canvas-col").offset().top + _canvasToolBar.outerHeight() + 20 ); _reservedHeight = (colTop + tbHeight + 20 );
} };
updateReservedSpace();
};
/** /**
* Update the view mode: 'edit' or 'review' * Update the view mode: 'edit' or 'review'
...@@ -892,6 +935,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -892,6 +935,7 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
// Auto adjust zoom to fit content // Auto adjust zoom to fit content
var imageLayer = view.getLayerByName('image'); var imageLayer = view.getLayerByName('image');
var raster = imageLayer.children[1]; var raster = imageLayer.children[1];
if (!raster) return;
var s = paper.view.viewSize.divide(raster.size); var s = paper.view.viewSize.divide(raster.size);
attributes.setZoom(Math.min(s.width, s.height), 'center'); attributes.setZoom(Math.min(s.width, s.height), 'center');
paper.view.draw(); paper.view.draw();
...@@ -915,6 +959,35 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -915,6 +959,35 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
].join("")); ].join(""));
/**
* Build the list of users' layer in the Users Panel
*/
function updateUserLayers() {
if (!config.ui.show_users_results) return;
$.each(view.getAllUsersLayers(), function(i, layer) {
if (annotList.find("li[data-layer-id=" + layer.id + "]").length == 0)
$(layerListItemTpl({
id:layer.id,
visibleClass:visibleClass,
name: layer.data.owner || layer.name
}))
.prependTo(annotList);
});
}
var getListItem = _.memoize(
function (layer) {
return annotList.find("li[data-layer-id=" + layer.id + "]");
},
function(l){ return l.id }
);
function onUserLayerVisChange(layer, visible) {
updateUserLayerState(getListItem(layer), visible);
}
function selectLayerListItem(item, exclusive) { function selectLayerListItem(item, exclusive) {
var $item = $(item); var $item = $(item);
//if ($item.hasClass("selected")) { //if ($item.hasClass("selected")) {
...@@ -931,14 +1004,12 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -931,14 +1004,12 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
selectedItems.removeClass("selected"); selectedItems.removeClass("selected");
$item.addClass("selected"); $item.addClass("selected");
//} //}
var layer = view.getLayerByName("id:" + $item.data("layerId")); var layer = view.getLayerByName($item.data("layerId"));
if (layer) if (layer)
layer.activate(); layer.activate();
} }
function updateUserLayerState(listItem, visible) {
function toggleLayer(listItem, show) {
var visible = view.toggleLayer("id:" + listItem.data("layerId"), show);
listItem listItem
.toggleClass("layer-hidden", !visible) .toggleClass("layer-hidden", !visible)
.find(".layer-status") .find(".layer-status")
...@@ -947,6 +1018,10 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -947,6 +1018,10 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
; ;
} }
function toggleLayer(listItem, show) {
view.toggleLayer(listItem.data("layerId"), show);
}
function toggleAll(show) { function toggleAll(show) {
var s = show; var s = show;
annotList.find(".list-group-item").each(function(i, layer){ annotList.find(".list-group-item").each(function(i, layer){
...@@ -955,7 +1030,8 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -955,7 +1030,8 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
}); });
} }
// Annotation List Event listeners // Bind event handlers to Users Panel layers elements
// ---------------------------------------------------
annotList.on('click', ".layer-status", function(evt) { annotList.on('click', ".layer-status", function(evt) {
evt.stopPropagation(); evt.stopPropagation();
var $this = $(this); var $this = $(this);
...@@ -971,6 +1047,8 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export ...@@ -971,6 +1047,8 @@ function($, _, Signal, paper, config, view, io, tools, attributes, Users, export
}); });