Skip to content

Commit 0703ab3

Browse files
committed
Merge pull request #142 from hannu/initial-progress
Refactor localstorage handling. Persist designer tool visibility
2 parents d093487 + 71fa947 commit 0703ab3

File tree

8 files changed

+31
-55
lines changed

8 files changed

+31
-55
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ When using the build as a subfolder of your application, tune your server to res
174174
will let Angular application to deal with routing itself. However, the static files should be resolved as they are
175175
stored.
176176

177-
**sassVariables** (string, optional)
177+
**styleVariables** (string, optional)
178178

179179
Path to the file containing SASS variables that can be used as modifiers in the KSS notation.
180180

lib/app/js/controllers/main.js

+6-19
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,10 @@ angular.module('sgApp')
77
var socket;
88

99
$scope.isNavCollapsed = false;
10-
11-
// Because localStorage only saves String type values, try to convert to boolean
12-
$scope.checkIfMarkupVisible = function() {
13-
var showAllMarkup = localStorageService.get('showAllMarkup');
14-
if (showAllMarkup == null) {
15-
$scope.showAllMarkup = true;
16-
} else {
17-
if (showAllMarkup == 'false' || showAllMarkup === false) {
18-
$scope.showAllMarkup = false;
19-
} else {
20-
$scope.showAllMarkup = true;
21-
}
22-
}
23-
}
24-
25-
$scope.checkIfMarkupVisible();
10+
$scope.markup = {isVisible: true};
11+
$scope.designerTool = {isVisible: false};
12+
localStorageService.bind($scope, 'markup', {isVisible: true});
13+
localStorageService.bind($scope, 'designerTool', {isVisible: false});
2614

2715
// Fetch styleguide data
2816
Styleguide.get()
@@ -57,11 +45,10 @@ angular.module('sgApp')
5745

5846
// Toggle all markup boxes visible/hidden state
5947
$scope.toggleMarkup = function() {
60-
$scope.showAllMarkup = !$scope.showAllMarkup;
48+
$scope.markup.isVisible = !$scope.markup.isVisible;
6149
for (var i = 0; i < $scope.sections.length; i++) {
62-
$scope.sections[i].showMarkup = $scope.showAllMarkup;
50+
$scope.sections[i].showMarkup = $scope.markup.isVisible;
6351
}
64-
localStorageService.add('showAllMarkup', $scope.showAllMarkup);
6552
}
6653

6754
// Change route to /all when searching

lib/app/js/directives/design.js

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ angular.module('sgApp')
55
return {
66
replace: true,
77
restrict: 'A',
8-
scope: {
9-
cfg: '='
10-
},
118
templateUrl: 'views/partials/design.html',
129
link: function(scope) {
1310
scope.onChange = function(key, value) {

lib/app/js/directives/section.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ angular.module('sgApp')
99
link: function(scope, element, attrs) {
1010

1111
//init setting based on global 'showAllMarkup' value
12-
scope.section.showMarkup = scope.$parent.$parent.showAllMarkup;
12+
scope.section.showMarkup = scope.markup.isVisible;
1313

1414
scope.showSingleMarkupBox = function(index) {
1515
if (!scope.section.showMarkup) {

lib/app/sass/app.scss

-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ $mobile: new-breakpoint(max-width 480px);
332332
height: $header-height;
333333
background: rgba($primary-color, 1);
334334
color: rgba(#fff, 1);
335-
padding: 0;
336335

337336
.inner {
338337
@include outer-container;

lib/app/views/main.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ <h1 class="sg">{{ $root.config.title }}</h1>
5050
</li>
5151
</ul>
5252
<p class="sg option">
53-
<a class="sg" ng-click="toggleMarkup()" ng-show="showAllMarkup">Hide all markup</a>
54-
<a class="sg" ng-click="toggleMarkup()" ng-hide="showAllMarkup">Show all markup</a>
53+
<a class="sg" ng-click="toggleMarkup()" ng-show="markup.isVisible">Hide all markup</a>
54+
<a class="sg" ng-click="toggleMarkup()" ng-hide="markup.isVisible">Show all markup</a>
5555
</p>
5656
</nav>
5757

lib/app/views/partials/design.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="sg design"
2-
ng-class="isDesignVisible ? 'sg-visible' : 'sg-hidden' ">
2+
ng-class="designerTool.isVisible ? 'sg-visible' : 'sg-hidden' ">
33
<div class="handle"
4-
ng-click="isDesignVisible = !isDesignVisible">
4+
ng-click="designerTool.isVisible = !designerTool.isVisible">
55
Designer Tools
66
</div>
77
<div class="sg design-content" ng-click="$event.stopPropagation()">

test/angular/controllers/mainCtrl.js

+19-26
Original file line numberDiff line numberDiff line change
@@ -65,35 +65,28 @@ describe('Controller: MainCtrl', function() {
6565
expect(scope.sections).to.eql(json.sections);
6666
});
6767

68-
describe('getting markup visibility state from localstorage', function() {
69-
it('should return true with true values', function() {
70-
sinon.stub(localstorage, 'get').returns(true);
71-
scope.checkIfMarkupVisible();
72-
expect(scope.showAllMarkup).to.eql(true);
73-
});
68+
it('should have markup shown by default', function() {
69+
expect(scope.markup.isVisible).to.eql(true);
70+
});
7471

75-
it('should return true by default', function() {
76-
sinon.stub(localstorage, 'get');
77-
scope.checkIfMarkupVisible();
78-
expect(scope.showAllMarkup).to.eql(true);
79-
});
72+
it('should change markup visibility when toggling state', function() {
73+
scope.toggleMarkup();
74+
expect(scope.markup.isVisible).to.eql(false);
75+
});
8076

81-
it('should return false with false string value', function() {
82-
sinon.stub(localstorage, 'get').returns('false');
83-
scope.checkIfMarkupVisible();
84-
expect(scope.showAllMarkup).to.eql(false);
85-
});
77+
it('should persist new state when toggling state', function() {
78+
scope.toggleMarkup();
79+
scope.$digest();
80+
expect(localstorage.get('markup').isVisible).to.eql(false);
81+
});
8682

87-
it('should return false with false boolean value', function() {
88-
sinon.stub(localstorage, 'get').returns(false);
89-
scope.checkIfMarkupVisible();
90-
expect(scope.showAllMarkup).to.eql(false);
91-
});
83+
it('should hide designer tool by default', function() {
84+
expect(scope.designerTool.isVisible).to.eql(false);
85+
});
9286

93-
it('should return true with unknown values', function() {
94-
sinon.stub(localstorage, 'get').returns('foobar');
95-
scope.checkIfMarkupVisible();
96-
expect(scope.showAllMarkup).to.eql(true);
97-
});
87+
it('should persist new state when designer tool visibility is changed', function() {
88+
scope.designerTool.isVisible = true;
89+
scope.$digest();
90+
expect(localstorage.get('designerTool').isVisible).to.eql(true);
9891
});
9992
});

0 commit comments

Comments
 (0)