This repository has been archived by the owner on Sep 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 194
Persistent State #164
Open
widmoser
wants to merge
12
commits into
angular-ui:master
Choose a base branch
from
tinydesk:feature/localStorage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Persistent State #164
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
867aa3b
style: added consistent formatting and some explanatory comments
widmoser 06c32bb
feat(persistentState): persisting container sizes in local storage
widmoser deaad26
test: added a .bowerrc file to explicitly define the location of bowe…
widmoser 861ca93
test(persistentState): fixed existing tests by clearing local storage…
widmoser b1beee2
test(persistentState): extended existing tests to check if new positi…
widmoser 7d74e0f
test(persistentState): added a test to check if state is persisted
widmoser 0880294
feat(persistentState): improved storage id robustness
widmoser 220cbb7
style(persistentState): fixed jshint problems
widmoser 2e0b7db
style: reset formatting changes to clean up diff
widmoser 6bcba31
refactor: removed .bowerrc file because this change is out of scope f…
widmoser 4bc969e
style: some more formatting fixes to clean up diff
widmoser 35651cb
style: removed TODO and using forEach instead of for loop
widmoser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ angular.module('ui.layout', []) | |
var sizePattern = /\d+\s*(px|%)\s*$/i; | ||
|
||
Layout.addLayout(ctrl); | ||
if ($attrs.layoutId) { | ||
ctrl.id = $attrs.layoutId; | ||
} | ||
|
||
ctrl.containers = []; | ||
ctrl.movingSplitbar = null; | ||
|
@@ -83,7 +86,7 @@ angular.module('ui.layout', []) | |
if(!beforeContainer.collapsed && !afterContainer.collapsed) { | ||
// calculate container positons | ||
var difference = ctrl.movingSplitbar[position] - lastPos; | ||
var newPosition = ctrl.movingSplitbar[position] - difference; | ||
var newPosition = ctrl.movingSplitbar[position] - difference; // TODO: this computation is unnecessary, newPosition === lastPos | ||
|
||
// Keep the bar in the window (no left/top 100%) | ||
newPosition = Math.min(elementSize-dividerSize, newPosition); | ||
|
@@ -120,6 +123,12 @@ angular.module('ui.layout', []) | |
afterContainer.uncollapsedSize = afterContainer.size; | ||
} | ||
|
||
// store the current value in local storage to preserve size also when reloading the window | ||
if($window.localStorage !== undefined) { | ||
$window.localStorage.setItem(beforeContainer.storageId, beforeContainer.uncollapsedSize + 'px'); | ||
$window.localStorage.setItem(afterContainer.storageId, afterContainer.uncollapsedSize + 'px'); | ||
} | ||
|
||
// move the splitbar | ||
ctrl.movingSplitbar[position] = newPosition; | ||
|
||
|
@@ -161,6 +170,27 @@ angular.module('ui.layout', []) | |
} | ||
} | ||
|
||
function loadContainerState(container) { | ||
// load uncollapsedSize from local storage if available: | ||
container.uncollapsedSize = null; | ||
if($window.localStorage !== undefined) { | ||
container.uncollapsedSize = $window.localStorage.getItem(container.storageId); | ||
} | ||
if(container.uncollapsedSize === null) { | ||
container.uncollapsedSize = container.size; | ||
} | ||
} | ||
|
||
/** | ||
* Updates the storage ids of all containers according to the id of this controller and the index of the container. | ||
*/ | ||
function updateContainerStorageIds() { | ||
for (var i = 0; i < ctrl.containers.length; ++i) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason for a |
||
var c = ctrl.containers[i]; | ||
c.storageId = ctrl.id + ':' + i; | ||
} | ||
} | ||
|
||
//================================================================================ | ||
// Public Controller Functions | ||
//================================================================================ | ||
|
@@ -248,7 +278,7 @@ angular.module('ui.layout', []) | |
}; | ||
|
||
/** | ||
* Sets the default size for each container. | ||
* Sets the default size and position (left, top) for each container. | ||
*/ | ||
ctrl.calculate = function() { | ||
var c, i; | ||
|
@@ -363,6 +393,9 @@ angular.module('ui.layout', []) | |
container.index = index; | ||
ctrl.containers.splice(index, 0, container); | ||
|
||
updateContainerStorageIds(); | ||
loadContainerState(container); | ||
|
||
ctrl.calculate(); | ||
}; | ||
|
||
|
@@ -396,6 +429,7 @@ angular.module('ui.layout', []) | |
if(newIndex >= 0) { | ||
ctrl.containers.splice(newIndex, 1); | ||
} | ||
updateContainerStorageIds(); | ||
ctrl.calculate(); | ||
} else { | ||
console.error("removeContainer for container that did not exist!"); | ||
|
@@ -903,7 +937,6 @@ angular.module('ui.layout', []) | |
scope.container.resizable = scope.resizable; | ||
} | ||
scope.container.size = scope.size; | ||
scope.container.uncollapsedSize = scope.size; | ||
scope.container.minSize = scope.minSize; | ||
scope.container.maxSize = scope.maxSize; | ||
ctrl.addContainer(scope.container); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open an issue for this instead of
// TODO