Skip to content

Commit

Permalink
Add a grid view mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-wu committed Jun 7, 2019
1 parent df99536 commit 9a135a7
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 17 deletions.
9 changes: 8 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"babel-loader": "^8.0.5",
"babel-preset-minify": "^0.5.0",
"better-docs": "^1.0.0",
"css-element-queries": "^1.2.0",
"dialog-polyfill": "^0.4.10",
"file-loader": "^1.1.11",
"html-loader": "^0.5.5",
Expand All @@ -51,9 +52,8 @@
"webpack": "^4.6.0",
"webpack-cli": "^2.1.2",
"webpack-jquery-ui": "^1.0.0",
"zincjs": "^0.29.11"
},
"dependencies": {
"zincjs": "^0.29.11",
"polyfill-array-includes": "^2.0.0"
}
},
"dependencies": {}
}
6 changes: 6 additions & 0 deletions src/snippets/gridView.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="portalGridView">
<div class="portalGridViewContainer">
<div class="Row">
</div>
</div>
</div>
38 changes: 38 additions & 0 deletions src/styles/gridView.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.portalGridView {
position:absolute;
/* Full height */
height: 100%;
left:12%;
width:88%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
overflow-y:hidden;
z-index:1;
}
.portalGridView .Row {
display: grid;
width: 100%; /*Optional*/
border-spacing: 10px; /*Optional*/
grid-template-columns: auto auto;
}
.portalGridView .Row .Column {
transition: transform .2s;
background: rgba(1,1,1,0);
}

.portalGridViewContainer {
width:100%;
height:100%;
z-index:1;
text-align: center;
position: absolute;
overflow-y:auto;
}

@media only screen and (max-width: 600px) {
.portalGridView .Row {
grid-template-columns: auto;
}
}
12 changes: 9 additions & 3 deletions src/ui/BaseDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BaseDialog.prototype.close = function(myInstance) {
return function(event, ui) {
myInstance.container.dialog('destroy').remove();
for (var i = 0; i < myInstance.onCloseCallbacks.length; i++) {
myInstance.onCloseCallbacks[i]( this);
myInstance.onCloseCallbacks[i]( myInstance);
}
if (myInstance.destroyModuleOnClose) {
if (myInstance.module) {
Expand All @@ -47,7 +47,7 @@ BaseDialog.prototype.close = function(myInstance) {
BaseDialog.prototype.beforeClose = function(myInstance) {
return function(event, ui) {
for (var i = 0; i < myInstance.beforeCloseCallbacks.length; i++) {
myInstance.beforeCloseCallbacks[i]( this );
myInstance.beforeCloseCallbacks[i]( myInstance );
}
}
}
Expand All @@ -60,7 +60,7 @@ BaseDialog.prototype.resizeStopCallback = function(myInstance) {

$(this).width($(this).parent().width() - widthPadding);
for (var i = 0; i < myInstance.resizeStopCallbacks.length; i++) {
myInstance.resizeStopCallbacks[i]( this );
myInstance.resizeStopCallbacks[i]( myInstance );
}
}
}
Expand Down Expand Up @@ -96,11 +96,17 @@ BaseDialog.prototype.undock = function() {
});
}

BaseDialog.prototype.getContainment = function() {
return this.containment;
}

BaseDialog.prototype.create = function(htmlData) {
this.container = $('<div></div>');
this.container.attr('title', this.title);
if (this.parent === undefined)
this.parent = $('body');
if (this.containment === undefined)
this.containment = $('body');
this.container.dialog({
appendTo: this.parent,
show: "blind",
Expand Down
107 changes: 107 additions & 0 deletions src/ui/gridView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
require("../styles/gridView.css")
var ResizeSensor = require('css-element-queries/src/ResizeSensor');

exports.GridView = function(containerIn) {
var container = containerIn;
var parent = undefined;
var rowElement = undefined;
var template = require("../snippets/gridView.html");
var _this = this;
var dialogs = [];
var sensor = undefined;
this.isEnabled = false;

this.enable = function(managerItems) {
if (_this.isEnabled == false) {
parent[0].style.display = "block";
_this.isEnabled = true;
for (var i = 0; i < managerItems.length; i++) {
_this.addManagerItem(managerItems[i]);
}
}
}

this.disable = function() {
parent[0].style.display = "none";
_this.isEnabled = false;
for (var i = 0; i < dialogs.length; i++) {
dialogs[i].undock();
}
dialogs = [];
rowElement.innerHTML = "";
}

var getNewItemContainer = function() {
var itemTemplate = '<div class="Column"><div class="itemContainment" style="height:800px;"></div></div>';
var item = $(itemTemplate);
var itemContainment = item.find(".itemContainment")[0];
rowElement.appendChild(item[0]);
return itemContainment;
}

var removeContainer = function(containment) {
if (containment.parentNode.parentNode === rowElement) {
rowElement.removeChild(containment.parentNode);
return true;
}
return false;
}

var updateSize = function() {
if (_this.isEnabled) {
for (var i = 0; i < dialogs.length; i++) {
dialogs[i].setWidth("100%");
dialogs[i].setHeight("100%");
}
}
}

this.addManagerItem = function(item) {
if (_this.isEnabled) {
var dialog = item.getDialog();
if (dialog && (dialogs.includes(dialog)== false)) {
var containment = getNewItemContainer();
dialog.dockToContainment(containment);
dialogs.push(dialog);
updateSize();
}
}
}


var removeDialog = function(dialog) {
if (dialog && (dialogs.includes(dialog) == true)) {
var containment = dialog.getContainment();
if (removeContainer(containment)) {
dialog.undock();
var index = dialogs.indexOf(dialog);
if (index > -1) {
dialogs.splice(index, 1);
}
updateSize();
}
}
}

this.removeManagerItem = function(item) {
var dialog = item.getDialog();
removeDialog(dialog);
}

var resize = function() {
return function() {
updateSize();
}
}

var setup = function() {
parent = $(template);
rowElement = parent.find(".Row")[0];
container.appendChild(parent[0]);
parent.find(".portalGridViewContainer")[0].onscroll = resize();
sensor = new ResizeSensor(parent[0], resize());
}

setup();
}

43 changes: 34 additions & 9 deletions src/utilities/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ exports.ModuleManager = function() {
var ready = false;
var moduleCounter = 0;
var name = "Default Manager";
var gridView = undefined;
var constructors = new function() {
this["Body Viewer"] = [];
this["Body Viewer"].module = function() {
Expand Down Expand Up @@ -51,8 +52,8 @@ exports.ModuleManager = function() {
console.log(module);
return module;
}
constructors[name].dialog = function(module, parent) {
var dialog = new dialogConstructor(module, parent);
constructors[name].dialog = function(module, parent, options) {
var dialog = new dialogConstructor(module, parent, options);
return dialog;
}
}
Expand Down Expand Up @@ -128,14 +129,14 @@ exports.ModuleManager = function() {
this.manageDialog = function(dialogIn) {
if (dialogIn) {
var moduleIn = dialogIn.getModule();
var item = undefined;
if (moduleIn) {
var item = findManagerItemWithModule(moduleIn);
item = findManagerItemWithModule(moduleIn);
if (item) {
if (item.getDialog() === undefined) {
item.setDialog(dialogIn);
dialogIn.addBeforeCloseCallback(dialogDestroyCallback());
}
return item;
} else {
var managerItem = new ManagerItem();
managerItem.setDialog(dialogIn);
Expand All @@ -144,20 +145,23 @@ exports.ModuleManager = function() {
managerItems.push(managerItem);
for (var i = 0; i < itemChangedCallbacks.length; i++)
itemChangedCallbacks[i](managerItem, MANAGER_ITEM_CHANGE.ADDED)
return managerItem;
item = managerItem;
}
} else {
var item = findManagerItemWithDialog(dialogIn);
item = findManagerItemWithDialog(dialogIn);
if (item === undefined) {
var managerItem = new ManagerItem();
managerItem.setDialog(dialogIn);
dialogIn.addBeforeCloseCallback(dialogDestroyCallback());
managerItems.push(managerItem);
for (var i = 0; i < itemChangedCallbacks.length; i++)
itemChangedCallbacks[i](managerItem, MANAGER_ITEM_CHANGE.ADDED)
return managerItem;
item = managerItem;
}
return item;
}
//if gridVIew is defined and enabled, the dialog will be added to a grid
if (item && gridView) {
gridView.addManagerItem(item);
}
}
}
Expand All @@ -166,6 +170,8 @@ exports.ModuleManager = function() {
if (dialogIn) {
var item = findManagerItemWithDialog(dialogIn);
if (item) {
if (gridView)
gridView.removeManagerItem(item);
item.setDialog(undefined);
}
}
Expand Down Expand Up @@ -215,7 +221,9 @@ exports.ModuleManager = function() {
}
if (index > -1) {
moduleIn.removeChangedCallback(moduleChangedCallback());
managerItems[index].getDialog().removeBeforeCloseCallback(dialogDestroyCallback());
var dialog = managerItems[index].getDialog();
if (dialog)
dialog.removeBeforeCloseCallback(dialogDestroyCallback());
for (var i = 0; i < itemChangedCallbacks.length; i++) {
itemChangedCallbacks[i]( managerItems[index], MANAGER_ITEM_CHANGE.REMOVED);
}
Expand Down Expand Up @@ -299,6 +307,23 @@ exports.ModuleManager = function() {
this.isReady = function() {
return ready;
}

this.initialiseGridView = function(container) {
if (gridView === undefined)
gridView = new (require("../ui/gridView").GridView)(container);
}

this.enableGridView = function() {
if (gridView) {
gridView.enable(managerItems);
}
}

this.disableGridView = function() {
if (gridView) {
gridView.disable();
}
}

var systemMetaReadyCallback = function() {
return function() {
Expand Down

0 comments on commit 9a135a7

Please sign in to comment.