Skip to content

Commit

Permalink
Implement possibility to reset local variable changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannu Pelkonen committed Nov 4, 2014
1 parent c4e1c7c commit c757070
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/app/js/directives/design.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ angular.module('sgApp')
Variables.saveVariables();
}

scope.resetLocal = function() {
Variables.resetLocal();
}

scope.isColor = function(value) {
if (/^(#|rgb)/.test(value)) return true;
return false;
Expand Down
10 changes: 10 additions & 0 deletions lib/app/js/services/Variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
return this;
};

this.resetLocal = function() {
var _this = this;
// We need to remove each key individually to keep the object reference the same
angular.forEach(this.variables, function(value, key) {
delete _this.variables[key];
});
// Call setValues so that the server data is used
this.setValues({});
};

this.setSocket = function(newSocket) {
var _this = this;
this.socket = newSocket;
Expand Down
1 change: 1 addition & 0 deletions lib/app/views/partials/design.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ul>
<div class="sg action-footer">
<button class="sg button primary" ng-click="saveVariables()">Save changes</button>
<button class="sg button" ng-click="resetLocal()">Reset local changes</button>
</div>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions test/angular/services/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ describe('Service: Variables', function() {
expect(Variables.variables).to.eql({setting2: 'value2'});
});

it('should properly reset local changes', function() {
rootScope.$digest();
Variables.setValues({setting1: 'changed', setting2: 'changed'});
rootScope.$digest();
Variables.resetLocal();
rootScope.$digest();
expect(Variables.variables).to.eql({setting1: 'value1', setting2: 'value2'});
});

it('should allow new server side keys with new values', function() {
rootScope.$digest();
styleguideMock.config.data = {
Expand Down

0 comments on commit c757070

Please sign in to comment.