Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
Use translation strings to lookup text for yes/no buttons closes #94
Browse files Browse the repository at this point in the history
  • Loading branch information
rikkertkoppes committed Dec 31, 2014
1 parent 24884b3 commit 4e4b88a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
14 changes: 14 additions & 0 deletions spec/views/scoresheetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ describe('scoresheet',function() {
});
});

describe('getString',function() {
beforeEach(function() {
$scope.strings = {
foo:'bar'
};
});
it('should get a string from defined strings',function() {
expect($scope.getString('foo')).toBe('bar');
});
it('should return the key if string not found',function() {
expect($scope.getString('baz')).toBe('baz');
});
});

describe('score',function() {
it('should return undefined if there are no missions',function() {
$scope.missions = undefined;
Expand Down
1 change: 1 addition & 0 deletions src/js/services/ng-challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ define('services/ng-challenge',[
return {
field: field,
missions: field.missions,
strings: field.strings,
objectiveIndex: indexObjectives(field.missions)
};
}
Expand Down
6 changes: 6 additions & 0 deletions src/js/views/scoresheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ define('views/scoresheet',[
// Set up defaults
$scope.settings = {};
$scope.missions = [];
$scope.strings = [];

// add teams and stages to scope for selection
$scope.teams = $teams.teams;
Expand All @@ -45,6 +46,7 @@ define('views/scoresheet',[
return $challenge.load($scope.settings.challenge).then(function(defs) {
$scope.field = defs.field;
$scope.missions = defs.missions;
$scope.strings = defs.strings;
$scope.objectiveIndex = defs.objectiveIndex;
angular.forEach($scope.missions,process);
$scope.$apply();
Expand All @@ -56,6 +58,10 @@ define('views/scoresheet',[
});
};

$scope.getString = function(key) {
return $scope.strings[key]||key;
};

function getObjectives(names) {
return names.map(function(dep) {
return $scope.objectiveIndex[dep].value;
Expand Down
4 changes: 2 additions & 2 deletions src/views/scoresheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ <h2>
<span class="field" ng-switch-when="yesno">
{{objective.title}}
<div class="btn-group">
<label class="btn btn-enum" ng-model="objective.value" btn-radio="'yes'">yes</label>
<label class="btn btn-enum" ng-model="objective.value" btn-radio="'no'">no</label>
<label class="btn btn-enum" ng-model="objective.value" btn-radio="'yes'">{{getString('yes')}}</label>
<label class="btn btn-enum" ng-model="objective.value" btn-radio="'no'">{{getString('no')}}</label>
</div>
</span>
<span class="field" ng-switch-when="number">
Expand Down

0 comments on commit 4e4b88a

Please sign in to comment.