Commit 3e715d53 authored by Martin Urban's avatar Martin Urban
Browse files

File: Symbolview does now append new items (sent by the FileMonitor) without...

File: Symbolview does now append new items (sent by the FileMonitor) without reloading, first step to faster rendering of large filelists ...
parent 48d369d2
......@@ -27,11 +27,13 @@ var Symbolview = Class.extend({
// Get the container, empty it and fill the template
this.fileContentContainer.html(this.template);
if (this.FileBase.instance.getPreference("Open") == "single" || vispa.device.hasTouch) {
//noinspection JSUnresolvedVariable
if (this.FileBase.instance.getPreference("Open") === "single" || vispa.device.hasTouch) {
$(".file-selection-box").css("visibility", "visible");
} else {
$(".file-selection-box").css("visibility", "hidden");
}
//noinspection JSUnresolvedVariable,JSLint
if (vispa.device.hasTouch) {
$(".file-properties").css("visibility", "visible");
}
......@@ -40,7 +42,8 @@ var Symbolview = Class.extend({
this.FileBase.workflow.parentpath = data.parentpath;
// render the content
$(".file-view-symbol", this.fileContentContainer).render(data.filelist, this.FileBase.view.directives);
$(".file-view-symbol", this.fileContentContainer)
.render(data.filelist, this.FileBase.view.directives);
// set icon size
self.setIconSize();
......@@ -58,22 +61,67 @@ var Symbolview = Class.extend({
var filelist = this.FileBase.workflow.data.filelist;
var numberNodes = filelist.length;
var newPosition = {};
for (var j = 0; j < numberNodes; j++)
var j;
for (j = 0; j < numberNodes; j++) {
newPosition[filelist[j].name] = j;
//console.table(newPosition);
}
var name = "";
for (var i = 0; i < len; i++) {
var i;
for (i = 0; i < len; i++) {
name = $(nodes[i]).data().data.name;
$(nodes[i]).css("order", newPosition[name]);
}
},
reactOnChange: function (data) {
//noinspection JSUnresolvedVariable
var changeSize = data.subject_infos.length;
var change = {};
var newNodes = [];
var i;
for (i = 0; i < changeSize; i++) {
//noinspection JSUnresolvedVariable
change = data.subject_infos[i];
if (change.mtime !== undefined) {
newNodes.push(change);
} else {
this.removeNode(change.name);
}
}
if (newNodes.length) {
this.addNodes(newNodes);
}
},
removeNode: function (name) {
var nodes = $(".file-node", this.fileContentContainer);
var i;
for (i = 0; i < nodes.length; i++) {
if ($(nodes[i]).data().data.name === name) {
$(nodes[i]).remove();
break;
}
}
},
addNodes: function (data) {
this.wf = this.FileBase.workflow;
var container = $(this.template).children();
var docFragment = document.createDocumentFragment();
$(docFragment).append(container);
$(docFragment).render(data, this.FileBase.view.directives);
$(".file-view-symbol", this.fileContentContainer).append(docFragment);
this.wf.data.filelist.push.apply(this.wf.data.filelist, data);
this.FileBase.helper.sortItems(this.wf.data, this.wf.sort, this.wf.reverse);
this.reorder();
},
setIconSize: function () {
"use strict";
var iconSize = this.FileBase.instance.getPreference("IconSize");
var container = $(".file-view-symbol", this.fileContentContainer);
["tiny", "small", "medium", "large"].forEach(function (size) {
container.toggleClass("icon-" + size, size == iconSize);
container.toggleClass("icon-" + size, size === iconSize);
});
}
});
var FileExtension = vispa.Extension.extend({
init: function() {
init: function () {
this._super("file");
this.addViews({
"FileBrowser": FileBrowserView,
......@@ -8,8 +8,7 @@ var FileExtension = vispa.Extension.extend({
this.getDefaultPreferences(FileBrowserView).fastMenuEntries.value = [];
this.getDefaultPreferences(FileSelectorView).fastMenuEntries.value = ["Home", "Up", "Upload",
"Refresh"
];
"Refresh"];
// or
// this.addViews({"FileBrowserFullView": FileBrowserView, ...})
......@@ -37,7 +36,7 @@ var FileExtension = vispa.Extension.extend({
type: "string",
value: "single",
description: "Select if you want to open directories or files with a single or a double click/tap." +
" (Valid for all FileBrowsers opened after change of this preference).",
" (Valid for all FileBrowsers opened after change of this preference).",
selection: ["single", "double"]
},
ShowDeleteDialog: {
......@@ -77,7 +76,7 @@ var FileExtension = vispa.Extension.extend({
type: "string",
value: "single",
description: "Select if you want to open directories or files with a single or a double click/tap." +
" (Valid for all FileBrowsers opened after change of this preference).",
" (Valid for all FileBrowsers opened after change of this preference).",
selection: ["single", "double"]
},
ShowDeleteDialog: {
......@@ -105,7 +104,7 @@ var FileExtension = vispa.Extension.extend({
this.addMenuEntry("New Filebrowser", {
iconClass: "glyphicon glyphicon-folder-close",
callback: function(workspaceId) {
callback: function (workspaceId) {
// createInstance creates a new FileBrowserView
// self.createInstance(workspaceId, FileBrowserView);
self.createInstance(workspaceId, FileBrowserView, args);
......@@ -117,7 +116,7 @@ var FileExtension = vispa.Extension.extend({
//noinspection SpellCheckingInspection
var FileBrowserView = vispa.ExtensionView.Center.extend({
// init: function(preferences, shortcuts,a, b) {
init: function(preferences, shortcuts) {
init: function (preferences, shortcuts) {
var self = this;
this._super(preferences, shortcuts);
......@@ -131,7 +130,7 @@ var FileBrowserView = vispa.ExtensionView.Center.extend({
// Add the menu items
var fileMenuEntries = getFileMenuEntries();
$.each(fileMenuEntries, function(key, obj) {
$.each(fileMenuEntries, function (key, obj) {
self.addMenuEntry(key, obj);
});
// Store the FileBrowser so that it is known in the View.
......@@ -140,9 +139,8 @@ var FileBrowserView = vispa.ExtensionView.Center.extend({
this.fb = new FileBrowser(this);
},
setup: function() {
setup: function () {
var self = this;
this._super();
this.setLabel(this.fb.workflow.path, true);
this.setIcon("vispa-icon vispa-icon-folder");
......@@ -157,23 +155,31 @@ var FileBrowserView = vispa.ExtensionView.Center.extend({
}
// console.log(this.getPreference("IconSize"));
// register watch event
this.onSocket("watch", function(data) {
this.onSocket("watch", function (data) {
if (data.event != "change")
return;
self.fb.updateView(100);
// The following two parameters are defined in remote/filesystem.py
// MAX_INLINE_SUBJECTS = 10
// MAX_SUBJECT_NAMES = 25
if (self.fb.workflow.currentView.type == "Symbol" && data.subject_count <= 10) {
self.fb.workflow.currentView.reactOnChange(data);
} else {
self.fb.updateView(100);
}
});
},
// applyPreferences is called when there was a change to the preferences
applyPreferences: function() {
applyPreferences: function () {
this._super();
this.fb.refresh(this.fb.workflow.data);
this.fb.view.toggleViewMenu();
this.fb.sorting.toggleSortButtons();
},
render: function(node) {
render: function (node) {
var self = this;
this.setLoading(true);
......@@ -197,45 +203,46 @@ var FileBrowserView = vispa.ExtensionView.Center.extend({
},
// called when the instance is resized
onResize: function(dimensions) {
onResize: function (dimensions) {
// dimensions contains the new height and width
},
// the following methods are fired before and after certain events
// return false in the "before" methods to prevent the event
onBeforeShow: function() {
onBeforeShow: function () {
//this.fb.updateView();
this.fb.workflow.lazyUpdate = false;
return this;
},
onAfterShow: function() {
onAfterShow: function () {
return this;
},
onBeforeHide: function() {
onBeforeHide: function () {
this.fb.workflow.lazyUpdate = true;
return this;
},
onAfterHide: function() {
onAfterHide: function () {
return this;
},
onBeforeClose: function() {
onBeforeClose: function () {
this.removeSocketListener("watch");
this.GET("/ajax/fs/unwatch", {
watch_id: "0"
});
return this;
},
onAfterClose: function() {
onAfterClose: function () {
return this;
},
_pushMessage: function(data) {
_pushMessage: function (data) {
var self = this;
if (~["confirm", "prompt", "alert"].indexOf(data.method)) {
this._shortcutGroup.disable();
var cb = data.callback || function() {};
data.callback = function() {
var cb = data.callback || function () {
};
data.callback = function () {
cb.apply(self, arguments);
self._shortcutGroup.enable();
};
......@@ -248,13 +255,13 @@ var FileBrowserView = vispa.ExtensionView.Center.extend({
});
var FileSelectorView = vispa.ExtensionView.Dialog.extend({
init: function(preferences, shortcuts) {
init: function (preferences, shortcuts) {
var self = this;
this._super(preferences, shortcuts);
// Add the menu items
var fileMenuEntries = getFileMenuEntries();
$.each(fileMenuEntries, function(key, obj) {
$.each(fileMenuEntries, function (key, obj) {
self.addMenuEntry(key, obj);
});
......@@ -265,7 +272,7 @@ var FileSelectorView = vispa.ExtensionView.Dialog.extend({
this.cb_args = args.cb_args || {};
// Define a default callback if no callback is defined
var defCallback = function(path, obj) {
var defCallback = function (path, obj) {
console.log(path);
console.log(obj);
};
......@@ -275,14 +282,14 @@ var FileSelectorView = vispa.ExtensionView.Dialog.extend({
this.fb = new FileSelector(this, args);
},
setup: function() {
setup: function () {
var self = this;
this._super();
this.setLabel("id: " + this.getId());
// register watch event
this.onSocket("watch", function(data) {
this.onSocket("watch", function (data) {
if (data.event != "change")
return;
self.fb.updateView(100);
......@@ -290,7 +297,7 @@ var FileSelectorView = vispa.ExtensionView.Dialog.extend({
},
render: function(content, footer) {
render: function (content, footer) {
// node.html("I"m a dialog!");
var self = this;
this.selectButton = null;
......@@ -303,7 +310,7 @@ var FileSelectorView = vispa.ExtensionView.Dialog.extend({
content.addClass("fileselector");
this.fb.setContent(content);
this.getTemplate("html/fileselectorBottom.html", function(err, tmpl) {
this.getTemplate("html/fileselectorBottom.html", function (err, tmpl) {
footer.append($(tmpl));
self.selectButton = $(".fs-select", footer);
......@@ -316,10 +323,10 @@ var FileSelectorView = vispa.ExtensionView.Dialog.extend({
self.inputField.css("visibility", "hidden");
}
self.selectButton.on("click", function(event) {
self.selectButton.on("click", function (event) {
event.preventDefault();
if (Object.keys(self.fb.selections.entries).length === 0 && !self.foldermode && self.inputField
.val() === "") {
.val() === "") {
vispa.messenger.info("nothing selected");
self.close();
} else if (Object.keys(self.fb.selections.entries).length === 0 && !self.foldermode) {
......@@ -330,13 +337,13 @@ var FileSelectorView = vispa.ExtensionView.Dialog.extend({
});
var closeBotton = $(".fs-close", footer);
closeBotton.on("click", function(event) {
closeBotton.on("click", function (event) {
event.stopPropagation();
event.preventDefault();
self.close();
});
self.inputField.keypress(function(event) {
self.inputField.keypress(function (event) {
var charCode = (typeof event.which == "undefined") ? event.keyCode : event.which;
// Enter == 13
if (charCode == 13) {
......@@ -361,7 +368,7 @@ var FileSelectorView = vispa.ExtensionView.Dialog.extend({
}
});
self.inputField.keyup(function() {
self.inputField.keyup(function () {
self.fb.selections.toggleSelectionButton();
});
});
......@@ -371,11 +378,11 @@ var FileSelectorView = vispa.ExtensionView.Dialog.extend({
// hide the loader overlay
self.setLoading(false);
},
onBeforeShow: function() {
onBeforeShow: function () {
//this.fb.updateView();
return this;
},
onBeforeClose: function() {
onBeforeClose: function () {
this.removeSocketListener("watch");
this.GET("/ajax/fs/unwatch", {
watch_id: "0"
......@@ -386,16 +393,17 @@ var FileSelectorView = vispa.ExtensionView.Dialog.extend({
// register the extension to the vispa platform at the end using jQuery"s
// loading hook $(function() {...})
$(function() {
$(function () {
vispa.extensions.registerExtension(FileExtension);
// register a callback to easily allow developers to access the FileSelector
// vispa.callbacks.emit("openFileSelector", workspaceId (e.g. 1), args as described in selector.js)
vispa.callbacks.on("openFileSelector", function(workspaceId, args) {
// vispa.callbacks.emit("openFileSelector", workspaceId (e.g. 1),
// args as described in selector.js)
vispa.callbacks.on("openFileSelector", function (workspaceId, args) {
var ext = vispa.extensions.getExtension("file");
ext.createInstance(workspaceId, FileSelectorView, args);
});
vispa.callbacks.on("openFileBrowser", function(workspaceId, args) {
vispa.callbacks.on("openFileBrowser", function (workspaceId, args) {
var ext = vispa.extensions.getExtension("file");
ext.createInstance(workspaceId, FileBrowserView, args);
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment