Skip to content

Commit

Permalink
fix markdown text activity
Browse files Browse the repository at this point in the history
  • Loading branch information
brunosmartin committed Oct 16, 2015
1 parent 87c5822 commit 93d21d3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
9 changes: 9 additions & 0 deletions activities/static/js/activities/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
};
});

app.directive('textMarkdownReponsePanel', function () {
return {
restrict: 'E',
templateUrl: '/static/templates/directives/text_markdown_response_panel.html',
transclude: true,
replace: true
};
});

app.directive('phpresult', function(){
return {
'restrict': 'A',
Expand Down
12 changes: 3 additions & 9 deletions activities/static/templates/activity_markdown.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
<div class="question textleft">
<h1 class="top">{{ currentActivity.data.question }}</h1>
<h1 class="top">{{ currentActivity.data.question }}</h1>
</div>

<markdowneditor content="answer.given"></markdowneditor>
<div class="col-lg-6 col-md-6 col-sm-6">
<button onClick="ga('send', 'event', 'activity', 'skip activity');" class="btn btn-default" ng-click="nextStep(true)" translate>Skip</button>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 textright">
<button onClick="ga('send', 'event', 'activity', 'rewatch video');" class="btn btn-info" ng-click="play()" translate>Review the video</button>
<button class="btn btn-success" ng-click="sendAnswer()" translate>Send</button>
</div>

<text-markdown-reponse-panel></text-markdown-reponse-panel>
40 changes: 23 additions & 17 deletions core/static/js/lesson/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,37 @@
} else {
$scope.section = 'activity';
}

};

$scope.selectActivity = function(index) {

if($scope.currentUnit.activities && $scope.currentUnit.activities.length) {
$scope.currentActivity = $scope.currentUnit.activities[index];
$scope.activityTemplateUrl = resolveActivityTemplate($scope.currentActivity.type);

console.log($scope.activityTemplateUrl);
ga("send", "event", "activity", "select", $scope.currentActivity.id);

$scope.answer = Answer.get({activityId: $scope.currentActivity.id}, function(answer) {
var exp = $scope.currentActivity.expected;
var giv = answer.given;
// FIXME why this name?
// TODO test if professor changes the activity (create a new alternative, the user lost his answer?
var shouldUseLastAnswer = (exp !== null && exp !== undefined) &&
(angular.isArray(exp) && angular.isArray(giv) && giv.length === exp.length);

console.log(exp, giv, shouldUseLastAnswer);
if (!shouldUseLastAnswer) {
// Initialize empty given answer
if(angular.isArray($scope.currentActivity.expected)) {
answer.given = $scope.currentActivity.expected.map(function(){});

// Test if the answer type is array.
// See https://github.com/hacklabr/timtec/wiki/Atividades for details
if ($scope.currentActivity === 'relationship' ||
$scope.currentActivity === 'trueorfalse' ||
$scope.currentActivity === 'multiplechoice') {
// FIXME why this name?
// TODO test if professor changes the activity (create a new alternative, the user lost his answer?
var shouldUseLastAnswer = (exp !== null && exp !== undefined) &&
(angular.isArray(exp) && angular.isArray(giv) && giv.length === exp.length);

if (!shouldUseLastAnswer) {
// Initialize empty given answer
if(angular.isArray($scope.currentActivity.expected)) {
answer.given = $scope.currentActivity.expected.map(function(){});
}
delete answer.correct;
}
delete answer.correct;
}
},
function (error) {
Expand All @@ -104,12 +109,13 @@
};

$scope.sendAnswer = function() {
console.log('mandando resposta');
$scope.answer.activity = $scope.currentActivity.id;
$scope.answer.$update({activityId: $scope.answer.activity}).then(function(d){
console.log(d, d.correct);
ga('send', 'event', 'activity', 'result', '', d.correct);
$scope.answer.$update({activityId: $scope.answer.activity}).then(function(answer){
console.log(answer, answer.correct);
ga('send', 'event', 'activity', 'result', '', answer.correct);
$scope.currentUnit.progress = Progress.get({unit: $scope.currentUnit.id});
answer.updated = true;
return answer;
});
ga('send', 'event', 'activity', 'submit');
};
Expand Down

0 comments on commit 93d21d3

Please sign in to comment.