Commit bda345b3 authored by Fernando Ribeiro's avatar Fernando Ribeiro
Browse files

Revert "Pagination activities discussion into develop"

This reverts commit dc3a398b.
parent 6e5135d4
......@@ -64,6 +64,21 @@ class ClassActivitySerializer(serializers.ModelSerializer):
model = Class
fields = ['id', 'name', 'activity_answers', 'course']
def get_activity_answers(self, obj):
request = self.context.get("request")
activity_id = request.query_params.get('activity', None)
try:
queryset = Answer.objects.filter(
activity=activity_id,
activity__unit__lesson__course=obj.course,
user__in=obj.students.all()
).exclude(user=request.user)
except Answer.DoesNotExist:
return
return AnswerSerializer(
queryset, many=True, **{'context': self.context}).data
class VideoSerializer(serializers.ModelSerializer):
......
......@@ -18,8 +18,6 @@ from rest_framework import viewsets, mixins
from rest_framework.response import Response
from rest_framework import filters
from rest_framework.permissions import IsAuthenticatedOrReadOnly, IsAuthenticated
from rest_framework.pagination import PageNumberPagination
from django_filters.rest_framework import DjangoFilterBackend
from braces.views import LoginRequiredMixin
......
......@@ -35,12 +35,11 @@
'CommentLike',
'CommentFile',
'Progress',
'AnswerPage',
'ClassActivity',
'CurrentUser',
'AnswerNotification',
'ContentFile',
function ($scope, $sce, $routeParams, $anchorScroll, $document, uiTinymceConfig, Forum, Topic, Comment, TopicLike, TopicFile, CommentLike, CommentFile, Progress, AnswerPage, ClassActivity, CurrentUser, AnswerNotification, ContentFile) {
function ($scope, $sce, $routeParams, $anchorScroll, $document, uiTinymceConfig, Forum, Topic, Comment, TopicLike, TopicFile, CommentLike, CommentFile, Progress, ClassActivity, CurrentUser, AnswerNotification, ContentFile) {
$scope.activity_open = true;
$scope.activity_expired = false;
var now = Date.now();
......@@ -180,12 +179,12 @@
}
}
$scope.my_topic_activity = null;
var my_topic_activity = null;
$scope.my_answer = true;
// Load the given answer from other student on screen
$scope.viewAnswer = function(activity_topic){
if($scope.my_topic_activity === null)
$scope.my_topic_activity = $scope.topic;
if(my_topic_activity === null)
my_topic_activity = $scope.topic;
$scope.my_answer = false;
$scope.topic = activity_topic;
$scope.show_answer = true;
......@@ -200,7 +199,7 @@
};
$scope.viewMyAnswer = function(){
$scope.topic = $scope.my_topic_activity;
$scope.topic = my_topic_activity;
$scope.my_answer = true;
// If the user still hasn't created an answer, the editor must be reactivated too
if(!$scope.topic.hasOwnProperty('id')){
......@@ -208,40 +207,24 @@
}
};
// Pagination Controls
$scope.pagination = {
classes_activities_pages_max: 50,
classes_activities_page_size: 30,
currentPage: 1,
}
// Load other students activities
$scope.answers_page = AnswerPage.get({
$scope.classes_activities = ClassActivity.query({
activity: $scope.currentActivity.id,
course: $scope.lesson.course,
ordering: '-last_activity_at',
exclude_cur_user: true,
page: $scope.pagination.currentPage,
}, function (response) {
$scope.activities_loaded = response.$resolved
$scope.activity_answers_total_items = response.count
$scope.answers_page_results = response.results
}, err => console.error(err)
}, function(response){
// Check if there are any activities to show
var acticvities = false;
for (var i = 0; i < response.length; i++) {
if(response[i].activity_answers.length > 0){
acticvities = true;
break;
}
}
$scope.activities_loaded = acticvities;
}
);
$scope.classesActivitiesPageChanged = () => {
$scope.answers_page = AnswerPage.get({
activity: $scope.currentActivity.id,
course: $scope.lesson.course,
ordering: '-last_activity_at',
exclude_cur_user: true,
page: $scope.pagination.currentPage,
}, (response) => {
$scope.forum_page_loaded = response.$resolved;
$scope.activity_answers_total_items = response.count
$scope.answers_page_results = response.results
});
};
$scope.topic_like = function(topic) {
if (topic.user_like) {
......
......@@ -8,9 +8,6 @@
update: {method: 'PUT'}
});
});
app.factory('AnswerPage', function($resource){
return $resource(BASE_API_URL + '/answer_page/', {}, {});
});
app.factory('Progress', ['$resource', function($resource){
var Progress = $resource(BASE_API_URL + '/student_progress/:unit', {}, {
......
......@@ -147,7 +147,7 @@
</form>
</div>
<!-- /Novo comentário -->
<div class="comments" ng-if="topic.comments.length > 0">
<div class="comments">
<h3 class="comments-title">Comentários</h3>
<!-- Exibição de um comentário -->
<div class="thread" ng-repeat="comment in topic.comments">
......@@ -289,13 +289,13 @@
<thead>
<tr>
<th>autor</th>
<!-- <th>turma</th> -->
<th>turma</th>
<th>atividade</th>
<th>reações</th>
</tr>
</thead>
<tbody ng-if="activities_loaded">
<tr class="new" ng-repeat="answer in answers_page_results">
<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}}">
......@@ -305,32 +305,14 @@
<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><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">{{ answer.topic.count_likes }} curtiram</span>
<br/>
<!-- <span class="action liked">{{ activity.count_likes }} curtiram</span> -->
<span class="action replies">{{ answer.topic.count_replies }} comentaram</span>
</td>
</tr>
</tbody>
</table>
<div ng-show="activities_loaded" class="pagination-wrapper">
<!-- Small screens -->
<ul uib-pagination boundary-links="true" total-items="activity_answers_total_items"
ng-model="pagination.currentPage" max-size="3" items-per-page="pagination.classes_activities_page_size"
ng-change="classesActivitiesPageChanged()" class="pagination pagination-sm" previous-text="&lsaquo;" next-text="&rsaquo;"
first-text="&laquo;" last-text="&raquo;"></ul>
<!-- Medium screens -->
<ul uib-pagination boundary-links="true" total-items="activity_answers_total_items"
ng-model="pagination.currentPage" force-ellipses="false" max-size="5"
items-per-page="pagination.classes_activities_page_size" ng-change="classesActivitiesPageChanged()" class="pagination pagination-md"
previous-text="&lsaquo;" next-text="&rsaquo;" first-text="primeira" last-text="última"></ul>
<!-- Large screens -->
<ul uib-pagination boundary-links="true" total-items="activity_answers_total_items" ng-model="pagination.currentPage"
force-ellipses="false" max-size="10" items-per-page="pagination.classes_activities_page_size"
ng-change="classesActivitiesPageChanged()" class="pagination pagination-lg"
previous-text="&lsaquo;" next-text="&rsaquo;" first-text="primeira" last-text="última"></ul>
</div>
</div>
</div>
......@@ -28,7 +28,7 @@ from .core.views import (CourseView, GenericCourseView,
RequestCertificateView,
EmitReceiptView, ProfileViewSet, )
from .activities.views import AnswerViewSet, AnswerPageViewSet, ActivityImageViewSet, SlidesRevealView
from .activities.views import AnswerViewSet, ActivityImageViewSet, SlidesRevealView
from .course_material.views import CourseMaterialView, FileUploadView
from .notes.views import NotesViewSet, CourseNotesView, UserNotesView
from .reports.views import (UserCourseStats, CourseStatsByLessonViewSet, UserCourseLessonsStats, GeneralReportsView, )
......@@ -85,8 +85,6 @@ router.register(r'lessons', LessonViewSet, base_name='lessons')
router.register(r'simple_lessons', SimpleLessonViewSet, base_name='simple_lessons')
router.register(r'unit', UnitViewSet, base_name='unit')
router.register(r'answer', AnswerViewSet, base_name='answer')
router.register(r'answer_page', AnswerPageViewSet, base_name='answer')
router.register(r'activity_image', ActivityImageViewSet, base_name='activity_image')
router.register(r'student_progress', StudentProgressViewSet, base_name='student_progress')
......
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