Skip to content

Commit

Permalink
Fixes #408 - drag and sorting issues on mobile devices; updated LiteDB
Browse files Browse the repository at this point in the history
  • Loading branch information
genemars committed Jun 4, 2020
1 parent 5f1b526 commit 582cb9c
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 118 deletions.
182 changes: 88 additions & 94 deletions BaseFiles/Common/html/pages/control/_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ HG.WebApp.Control = HG.WebApp.Control || new function() { var $$ = this;
$$.ConfigureGroup = function () {
HG.WebApp.GroupsList.ConfigureGroup(HG.WebApp.Data._CurrentGroupIndex);
};

$$.ShowAltToolbar = function(callback) {
$$.field('#control_actionmenu', true).popup('close');
$('[data-ui-field=homegenie_panel_button]').addClass('ui-disabled');
Expand Down Expand Up @@ -293,129 +293,128 @@ HG.WebApp.Control = HG.WebApp.Control || new function() { var $$ = this;
} else {
$$._grid = $$.field('#groupdiv_modules_' + HG.WebApp.Data._CurrentGroupIndex, true).isotope({
itemSelector: '.freewall',
layoutMode: 'fitRows',
}).isotope().addClass('isotope');
layoutMode: 'fitRows'
}).isotope({transitionDuration: '300ms'}).addClass('isotope');
$$._grid.on( 'arrangeComplete', function() {
$$._grid.find('.freewall').removeClass('drag-collide drag-collide-target');
});
setTimeout(function() {
$$._grid.isotope('layout');
}, 50);
$$.SetupWidgetsDrag();
$$.UpdateActionsMenu();
$.mobile.loading('hide');
}

};


$$.SetupWidgetsDrag = function () {
$$.WidgetsManager_dragStartHandler = function(event, pointer) {
var $item = $(this);
// insert placeholder div before dragged element
$$._placeHolder.css('left', $item.css('left'));
$$._placeHolder.css('top', $item.css('top'));
$$._placeHolder.css('width', $item.width());
$$._placeHolder.css('height', $item.height());
$$._placeHolder.insertBefore($item);
// remove dragged item
$item.removeClass('freewall').addClass('drag-collide');
$item.attr('old-z-index', $item.css('z-index'));
$item.css('z-index', 1000);
};
$$.WidgetsManager_dragMoveHandler = function(event, pointer, moveVector) {
var $item = $(this);
var gid = HG.WebApp.Data._CurrentGroupIndex;
var currentGroup = HG.WebApp.Data.Groups[gid];
var grid = $$.field('#groupdiv_modules_' + HG.WebApp.Data._CurrentGroupIndex, true);
grid.find('.modules-grid-item').each(function(i, gridItem) {
var $item = $(gridItem);
if (!$item.data('draggabilly')) {
if (!$item.attr('data-index')) {
$item.attr('data-index', $item.index());
}
$item.draggabilly({});
$item.draggabilly('disable');
$item.on('dragStart', function(event, pointer) {
// insert placeholder div before dragged element
$$._placeHolder.css('left', $item.css('left'));
$$._placeHolder.css('top', $item.css('top'));
$$._placeHolder.css('width', $item.width());
$$._placeHolder.css('height', $item.height());
$$._placeHolder.insertBefore($item);
// remove dragged item
$item.removeClass('freewall').addClass('drag-collide');
$item.attr('old-z-index', $item.css('z-index'));
$item.css('z-index', 1000);
});
$item.on('dragMove', function(event, pointer, moveVector) {
var gid = HG.WebApp.Data._CurrentGroupIndex;
var currentGroup = HG.WebApp.Data.Groups[gid];
grid.find('.modules-grid-item').each(function(i2, gridItem2) {
if ($item.get(0) !== gridItem2) {
var hitTestResult = $item.hitTestObject(gridItem2, 0.5);
if (hitTestResult) {
var $target = $(gridItem2);
// re-arrange elements (insert sourceIndex before/after targetIndex)
var sourceIndex = +$item.attr('data-index');
var targetIndex = +$target.attr('data-index');
if (hitTestResult === 2 && !$target.hasClass('drag-collide-target')) {
$target.addClass('drag-collide drag-collide-target');
if ($item.index() < $target.index()) { // insert after
currentGroup.Modules.move(sourceIndex, targetIndex);
$item.insertAfter($target);
} else { // inser before
currentGroup.Modules.move(sourceIndex, targetIndex);
$item.insertBefore($target);
}
// move placeholder div before $item
$$._placeHolder.insertBefore($item);
// update data-indexes
$item.attr('data-index', targetIndex); // (the element being dragged has `.freewall` class disabled)
grid.find('.freewall').each((function(is, nextElement) {
$(nextElement).attr('data-index', is);
}));
// wait for target element animation to complete
$target.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(e) {
$target.removeClass('drag-collide');
$target.removeClass('drag-collide-target');
});
// relayout
if ($$._relayoutTimeout) {
clearTimeout($$._relayoutTimeout);
}
$$._relayoutTimeout = setTimeout(function() {
$$._grid.isotope('reloadItems');
$$._grid.isotope();
}, 350);
return false;
}
} else {
$(gridItem2).removeClass('drag-collide');
$(gridItem2).removeClass('drag-collide-target');
}
grid.find('.modules-grid-item').each(function(i2, gridItem2) {
if ($item.get(0) !== gridItem2) {
var hitTestResult = $item.hitTestObject(gridItem2, 0.5);
if (hitTestResult) {
var $target = $(gridItem2);
// re-arrange elements (insert sourceIndex before/after targetIndex)
var sourceIndex = +$item.attr('data-index');
var targetIndex = +$target.attr('data-index');
if (hitTestResult === 2 && !$target.hasClass('drag-collide-target')) {
$target.addClass('drag-collide drag-collide-target');
if ($item.index() < $target.index()) { // insert after
currentGroup.Modules.move(sourceIndex, targetIndex);
$item.insertAfter($target);
} else { // inser before
currentGroup.Modules.move(sourceIndex, targetIndex);
$item.insertBefore($target);
}
});
});
$item.on('dragEnd', function(event, pointer) {
// remove placeholder div
$$._placeHolder.remove();
$$._placeHolder.css('transform', 'translate3d(0px, 0px, 0px)');
// restore dragged item
$$._grid.find('.freewall').removeClass('drag-collide');
$item.addClass('freewall').removeClass('drag-collide');
// relayout
$$._grid.isotope('reloadItems');
$$._grid.isotope();
$item.css('z-index', $item.attr('old-z-index'));
});
// move placeholder div before $item
$$._placeHolder.insertBefore($item);
// update data-indexes
$item.attr('data-index', targetIndex); // (the element being dragged has `.freewall` class disabled)
grid.find('.freewall').each((function(is, nextElement) {
$(nextElement).attr('data-index', is);
}));
// wait for target element animation to complete
$target.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(e) {
$target.removeClass('drag-collide');
$target.removeClass('drag-collide-target');
});
// relayout
if ($$._relayoutTimeout) {
clearTimeout($$._relayoutTimeout);
}
$$._relayoutTimeout = setTimeout(function() {
$$._grid.isotope('reloadItems');
$$._grid.isotope({transitionDuration: '300ms'});
}, 350);
return false;
}
} else {
$(gridItem2).removeClass('drag-collide');
$(gridItem2).removeClass('drag-collide-target');
}
}
});
};
$$.WidgetsManager_dragEndHandler = function(event, pointer) {
var $item = $(this);
// remove placeholder div
$$._placeHolder.remove();
$$._placeHolder.css('transform', 'translate3d(0px, 0px, 0px)');
// restore dragged item
$$._grid.find('.freewall').removeClass('drag-collide');
$item.addClass('freewall').removeClass('drag-collide');
// relayout
$$._grid.isotope('reloadItems');
$$._grid.isotope({transitionDuration: '300ms'});
$item.css('z-index', $item.attr('old-z-index'));
};

$$.WidgetsManager = function () {
$$.ShowAltToolbar(function () {
$$.toolbarWidgetsSort.show('slideup');
});
//$$._packeryGrid.packery();
var grid = $$.field('#groupdiv_modules_' + HG.WebApp.Data._CurrentGroupIndex, true);
grid.find('.modules-grid-item').each(function(i, gridItem) {
var $item = $(gridItem);
if (!$item.data('draggabilly')) {
if (!$item.attr('data-index')) {
$item.attr('data-index', $item.index());
}
$item.draggabilly({});
}
// enable dragging
$item.draggabilly('enable');
$item.on('dragStart', $$.WidgetsManager_dragStartHandler);
$item.on('dragMove', $$.WidgetsManager_dragMoveHandler);
$item.on('dragEnd', $$.WidgetsManager_dragEndHandler);
});
};
$$.WidgetsManagerCancel = function() {
$$._grid.find('.modules-grid-item').each(function(i, gridItem) {
var $item = $(gridItem);
// disable dragging
$item.draggabilly('disable');
$item.off('dragStart', $$.WidgetsManager_dragStartHandler);
$item.off('dragMove', $$.WidgetsManager_dragMoveHandler);
$item.off('dragEnd', $$.WidgetsManager_dragEndHandler);
$item.draggabilly('destroy');
});
$$._grid.isotope('reloadItems');
$$._grid.isotope({transitionDuration: 0});
$$.toolbarWidgetsSort.hide('slidedown', function () {
$$.HideAltToolbar();
});
Expand Down Expand Up @@ -508,11 +507,6 @@ HG.WebApp.Control = HG.WebApp.Control || new function() { var $$ = this;
};

$$.RenderGroupModules = function (groupIndex) {
if (widgetsloadqueue.length > 0) {
$$.RenderGroupModules(groupIndex);
return;
}
//
var groupmodules = HG.Configure.Groups.GetGroupModules(HG.WebApp.Data.Groups[groupIndex].Name);
var grp = $$.field('#groupdiv_modules_' + groupmodules.Index, true);
for (var m = 0; m < groupmodules.Modules.length; m++) {
Expand Down
22 changes: 11 additions & 11 deletions HomeGenie/Automation/Scripting/EventsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with HomeGenie. If not, see <http://www.gnu.org/licenses/>.
along with HomeGenie. If not, see <http://www.gnu.org/licenses/>.
*/

/*
Expand Down Expand Up @@ -57,15 +57,15 @@ public EventsHelper(HomeGenieService hg, int programId)
/// Program.Say("HomeGenie is now ready!");
/// // returning false will prevent this event from being routed to other listeners
/// return false;
/// });
/// });
/// </code></example>
public EventsHelper SystemStarted(Func<bool> handler)
{
var program = homegenie.ProgramManager.Programs.Find(p => p.Address.ToString() == myProgramId.ToString());
program.Engine.SystemStarted = handler;
return this;
}

/// <summary>
/// Call the specified `handler` when HomeGenie service is stopping.
/// </summary>
Expand All @@ -80,15 +80,15 @@ public EventsHelper SystemStarted(Func<bool> handler)
/// Program.Say("See ya soon!");
/// // returning true will route this event to other listeners
/// return true;
/// });
/// });
/// </code></example>
public EventsHelper SystemStopping(Func<bool> handler)
{
var program = homegenie.ProgramManager.Programs.Find(p => p.Address.ToString() == myProgramId.ToString());
program.Engine.SystemStopping = handler;
return this;
}

/// <summary>
/// Call the specified `handler` when the program is beign stopped.
/// </summary>
Expand All @@ -103,7 +103,7 @@ public EventsHelper SystemStopping(Func<bool> handler)
/// Program.Say("Oh-oh! I'm quitting!");
/// // returning true will route this event to other listeners
/// return true;
/// });
/// });
/// </code></example>
public EventsHelper ProgramStopping(Func<bool> handler)
{
Expand All @@ -130,7 +130,7 @@ public EventsHelper ProgramStopping(Func<bool> handler)
/// return false;
/// }
/// return true;
/// });
/// });
/// </code></example>
/// <seealso cref="ModuleParameterIsChanging"/>
public EventsHelper ModuleParameterChanged(Func<ModuleHelper, ModuleParameter, bool> handler)
Expand All @@ -141,7 +141,7 @@ public EventsHelper ModuleParameterChanged(Func<ModuleHelper, ModuleParameter, b
}

/// <summary>
/// Call the specified `handler` function when a parameter of a module is changing.
/// Call the specified `handler` function when a parameter of a module is changing.
/// If either the `handler` returns false or changes the event value, the propagation will stop.
/// </summary>
/// <returns>EventsHelper</returns>
Expand All @@ -160,7 +160,7 @@ public EventsHelper ModuleParameterChanged(Func<ModuleHelper, ModuleParameter, b
/// }
/// // continue event propagation
/// return true;
/// });
/// });
/// </code></example>
/// <seealso cref="ModuleParameterChanged"/>
public EventsHelper ModuleParameterIsChanging(Func<ModuleHelper, ModuleParameter, bool> handler)
Expand All @@ -184,12 +184,12 @@ public EventsHelper ModuleParameterIsChanging(Func<ModuleHelper, ModuleParameter
/// When.WebServiceCallReceived( "Hello.World", (args) =>
/// {
/// var returnstring = "";
/// if (args == "Greet")
/// if (args == "Hello.World/Greet")
/// {
/// returnstring = "Hello HomeGenie World!";
/// }
/// return returnstring;
/// });
/// });
/// </code>
/// In the snippet above, if we wanted to create an "Hello World" program that respond to the custom API call:
/// \n
Expand Down
51 changes: 51 additions & 0 deletions HomeGenie/Data/LoggerEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
This file is part of HomeGenie Project source code.
HomeGenie is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
HomeGenie is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with HomeGenie. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* Author: Generoso Martello <[email protected]>
* Project Homepage: http://homegenie.it
*/

using System;

namespace HomeGenie.Data
{
[Serializable()]
public class LoggerEvent
{
public LoggerEvent()
{
// default constructor
}

public LoggerEvent(Module module, ModuleParameter parameter)
{
this.Domain = module.Domain;
this.Address = module.Address;
this.Description = module.Name;
this.Parameter = parameter.Name;
this.Value = parameter.Value;
this.Date = parameter.UpdateTime;
}
public string Domain { get; set; }
public string Address { get; set; }
public string Description { get; set; }
public string Parameter { get; set; }
public object Value { get; set; }
public DateTime Date { get; set; }
}
}
Loading

0 comments on commit 582cb9c

Please sign in to comment.