Commit 9bf09f73 authored by Fernando Ribeiro's avatar Fernando Ribeiro
Browse files

Merge branch '162-blank-ClassActivity' into 'master'

162 blank class activity

See merge request !32
parents 5ef7b7ff 386bd67f
from rest_framework import serializers
from discussion.models import Topic
from discussion.serializers import TopicSerializer
from discussion.serializers import BaseTopicSerializer
from .models import Activity, Answer
......@@ -24,4 +24,4 @@ class AnswerSerializer(serializers.ModelSerializer):
except (Topic.DoesNotExist, AttributeError) as e:
return
return TopicSerializer(instance=topic, **{'context': self.context}).data
return BaseTopicSerializer(instance=topic, **{'context': self.context}).data
......@@ -89,7 +89,8 @@
$scope.save_answer = function() {
// if there is no content, the edit form must not disappear from screen
if($scope.topic.content === undefined || $scope.topic.content === ""){
return;
throw "Content field is empty"
return;
}
$scope.sending = true;
var topic_files = $scope.topic.files;
......@@ -107,6 +108,7 @@
}
});
}, function(error) {
console.error(error)
alert("Não foi possível salvar a sua resposta. Por favor, verifique sua conexão com a internet e tente novamente! Caso o problema persista, salve o seu texto em um arquivo no seu computador para não perder sua atividade.");
});
else
......@@ -130,7 +132,8 @@
}
});
}, function(error) {
alert("Não foi possível salvar a sua resposta. Por favor, verifique sua conexão com a internet e tente novamente! Caso o problema persista, salve o seu texto em um arquivo no seu computador para não perder sua atividade.");
console.error(error)
alert("Não foi possível salvar a sua resposta. Por favor, verifique sua conexão com a internet e tente novamente! Caso o problema persista, salve o seu texto em um arquivo no seu computador para não perder sua atividade.");
});
};
......
......@@ -193,6 +193,7 @@
} else if( data.eventName === 'callback') {
let current_state_formatted = JSON.stringify(state)
if(lastCalbackState === current_state_formatted){
lastCalbackState = {}
scope.nextStep();
scope.$apply();
} else {
......
......@@ -159,7 +159,7 @@
$scope.answer.$save().then(function(answer) {
if(answer.correct) {
$scope.currentUnit.progress = Progress.complete($scope.currentUnit.id);
$scope.nextStep(true);
$scope.nextStep();
}
return answer;
......@@ -173,19 +173,6 @@
$scope.nextUnit();
};
function checkIfShouldChangeUnit () {
// Test if this is the last activity in the currentUnit unit
const index = $scope.currentUnit.activities.indexOf($scope.currentActivity);
if(index === $scope.currentUnit.activities.length - 1){
$scope.currentUnit.progress = Progress.complete($scope.currentUnit.id);
$scope.nextUnit();
} else{
// This is not the last activity in the unit, so the next activity must be shown
$scope.selectActivity(index + 1);
$scope.section = 'activity';
}
}
$scope.nextStep = function(skipComment) {
if($scope.section === 'video') {
// Test if currentUnit has an activity
......@@ -193,14 +180,30 @@
$scope.currentUnit.activities.length > 0) {
$scope.section = 'activity';
} else {
checkIfShouldChangeUnit();
$scope.currentUnit.progress = Progress.complete($scope.currentUnit.id);
$scope.nextUnit();
}
} else {
// Test if must display activity comments
if($scope.section === 'activity' && !skipComment && $scope.currentActivity.comment) {
$scope.section = 'comment';
} else {
checkIfShouldChangeUnit();
var index = $scope.currentUnit.activities.indexOf($scope.currentActivity);
// Test if this is the last activity in the currentUnit unit
if(index === $scope.currentUnit.activities.length)
$scope.currentUnit.progress = Progress.complete($scope.currentUnit.id);
if(index+1 === $scope.currentUnit.activities.length) {
// This is the last activity in the unit
// However, the progress must not be marked as complete if the last activity is of the "discussion" type
// if($scope.currentActivity.type !== 'discussion')
$scope.currentUnit.progress = Progress.complete($scope.currentUnit.id);
$scope.nextUnit();
} else {
// This is not the last activity in the unit, so the next activity must be shown
$scope.selectActivity(index + 1);
$scope.section = 'activity';
}
}
}
};
......
......@@ -9,6 +9,7 @@
var current_user_id = parseInt($window.user_id, 10);
$scope.user_reports_total_items = 0
$scope.duplicatedCounter = 0
$scope.ordering = '-name'
$scope.reverse = false;
$scope.my_classes = [];
......@@ -36,8 +37,8 @@
search: $scope.filters.textsearch,
},
(data) => {
$scope.user_reports_total_items = data.count;
$scope.users_reports = data.results;
$scope.users_reports = removeDuplicated(data)
$scope.user_reports_total_items = data.count-$scope.duplicatedCounter;
$scope.reports_loaded = true;
$scope.users_reports.$resolved = true
})
......@@ -95,14 +96,17 @@
};
$scope.clean_keyword_search = () => {
console.log($scope.filters.textsearch)
$scope.filters.textsearch = ''
$scope.filter_stats()
}
function removeDuplicated (data) {
const dataWithoutDup = data.results.filter((user, index, self) => self.findIndex(t => t.username === user.username && t.course_progress >= user.course_progress) === index)
$scope.duplicatedCounter = data.results.length - dataWithoutDup.length
return dataWithoutDup
}
$scope.filter_stats = function() {
console.log("$scope.pagination.currentPage", $scope.pagination.currentPage)
$scope.filter_stats = function() {
if ($scope.filters.selected_class === 'all') {
$scope.course_stats = CourseStats.get({
courseId: $scope.course_id,
......@@ -112,8 +116,8 @@
page: $scope.pagination.currentPage,
search: $scope.filters.textsearch
}, function(data) {
$scope.user_reports_total_items = data.count;
$scope.users_reports = data.results;
$scope.users_reports = removeDuplicated(data);
$scope.user_reports_total_items = data.count-$scope.duplicatedCounter;
$scope.reports_loaded = true;
});
} else if ($scope.filters.selected_class === 'my_classes') {
......@@ -126,8 +130,8 @@
classes: sortedMyClasses,
search: $scope.filters.textsearch,
}, (data) => {
$scope.user_reports_total_items = data.count
$scope.users_reports = data.results;
$scope.users_reports = removeDuplicated(data);
$scope.user_reports_total_items = data.count-$scope.duplicatedCounter;
$scope.reports_loaded = true;
});
$scope.course_stats = CourseStats.get({
......@@ -144,8 +148,8 @@
page: $scope.pagination.currentPage,
search: $scope.filters.textsearch,
}, (data) => {
$scope.user_reports_total_items = data.count;
$scope.users_reports = data.results;
$scope.users_reports = removeDuplicated(data);
$scope.user_reports_total_items = data.count-$scope.duplicatedCounter;
$scope.reports_loaded = true;
});
$scope.course_stats = CourseStats.get({
......@@ -159,8 +163,8 @@
page: $scope.pagination.currentPage,
search: $scope.filters.textsearch,
}, (data) => {
$scope.user_reports_total_items = data.count;
$scope.users_reports = data.results;
$scope.users_reports = removeDuplicated(data);
$scope.user_reports_total_items = data.count-$scope.duplicatedCounter;
$scope.reports_loaded = true;
});
$scope.course_stats = CourseStats.get({
......
......@@ -132,7 +132,7 @@
<form class="comments-form" ng-if="topic.show_comment_input" ng-init="comment = new_comment()">
<textarea ui-tinymce
ng-model="comment.text"
placeholder="Escreva aqui o seu comentário"></textarea>
placeholder="Escreva aqui o seu comentário" required></textarea>
<button id="select-file-topic"
class="btn btn-xs btn-primary attach pull-left"
ngf-select="uploadCommentFiles($file, comment)"
......@@ -164,7 +164,7 @@
<form class="comments-form" ng-if="comment.updating" ng-init="changed_comment = comment">
<textarea ui-tinymce
ng-model="changed_comment.text"
placeholder="Escreva aqui o seu comentário"></textarea>
placeholder="Escreva aqui o seu comentário" required></textarea>
<button id="select-file-topic"
class="btn btn-xs btn-primary attach pull-left"
ngf-select="uploadCommentFiles($file, changed_comment)"
......@@ -216,7 +216,7 @@
<form class="comments-form" ng-if="reply.updating" ng-init="changed_reply = reply">
<textarea ui-tinymce
ng-model="changed_reply.text"
placeholder="Escreva aqui o seu comentário"></textarea>
placeholder="Escreva aqui o seu comentário" required></textarea>
<button id="select-file-topic"
class="btn btn-xs btn-primary attach pull-left"
ngf-select="uploadCommentFiles($file, changed_reply)"
......@@ -253,7 +253,7 @@
<form class="comments-form" ng-if="comment.show_comment_input" ng-init="reply = new_comment()">
<textarea ui-tinymce
ng-model="reply.text"
placeholder="Escreva aqui o seu comentário"></textarea>
placeholder="Escreva aqui o seu comentário" required></textarea>
<button id="select-file-comment"
class="btn btn-xs btn-primary attach pull-left"
ngf-select="uploadCommentFiles($file, reply)"
......@@ -287,23 +287,23 @@
</tr>
</thead>
<tbody ng-repeat="course_class in classes_activities">
<tr class="new" ng-repeat="answer in course_class.activity_answers">
<td>
<div class="user-icon">
<img ng-src="{{ answer.topic.author.image || '/static/img/avatar-default.png'}}" alt="{{answer.topic.author.name}}">
<tr class="new" ng-repeat="answer in course_class.activity_answers" ng-hide="answer.topic === null">
<td>
<div class="user-icon">
<img ng-src="{{ answer.topic.author.image || '/static/img/avatar-default.png'}}" alt="{{answer.topic.author.name}}">
</div>
<div class="info">
<a ng-click="viewAnswer(answer.topic)"><span class="user-name">{{answer.topic.author.name}}</span></a>
</div>
</td>
<td><b>{{course_class.name}}</b></td>
<td>Última atividade <b>{{answer.topic.last_activity_at | date : 'dd/MM/yyyy' }}</b></td>
<td>
<!-- <span class="action liked">{{ activity.count_likes }} curtiram</span> -->
<span class="action replies">{{ answer.topic.count_replies }} comentaram</span>
</td>
</tr>
</div>
<div class="info">
<a ng-click="viewAnswer(answer.topic)"><span class="user-name">{{answer.topic.author.name}}</span></a>
</div>
</td>
<td><b>{{course_class.name}}</b></td>
<td>Última atividade <b>{{answer.topic.last_activity_at | date : 'dd/MM/yyyy' }}</b></td>
<td>
<!-- <span class="action liked">{{ activity.count_likes }} curtiram</span> -->
<span class="action replies">{{ answer.topic.count_replies }} comentaram</span>
</td>
</tr>
</tbody>
</table>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment