diff --git a/amadeus/static/js/pendencies.js b/amadeus/static/js/pendencies.js index 736df31..34eabc2 100644 --- a/amadeus/static/js/pendencies.js +++ b/amadeus/static/js/pendencies.js @@ -65,6 +65,40 @@ $('.pendencies-content').on('hidden.bs.collapse', function(e) { if (h_items > 10) { h_holder.jPages("destroy"); } + + var url = pendencies.find('.view_log_url').val(); + var log_id = pendencies.find('.view_log_id').val(); + + if (typeof(url) != 'undefined') { + $.ajax({ + url: url, + data: {'action': 'close', 'log_id': log_id}, + dataType: 'json', + success: function (data) { + console.log(data.message); + }, + error: function (data) { + console.log(data); + } + }); + } + + var hist_url = history.find('.hist_log_url').val(); + var hist_log_id = history.find('.hist_log_id').val(); + + if (typeof(hist_url) != 'undefined' && hist_log_id != "") { + $.ajax({ + url: hist_url, + data: {'action': 'close', 'log_id': hist_log_id}, + dataType: 'json', + success: function (data) { + console.log(data.message); + }, + error: function (data) { + console.log(data); + } + }); + } } }); @@ -111,6 +145,40 @@ function getPendencies(panel_id) { metaFunctions(); } + var url = list.parent().find('.view_log_url').val(); + var log_input = list.parent().find('.view_log_id'); + + if (typeof(url) != 'undefined') { + $.ajax({ + url: url, + data: {'action': 'open'}, + dataType: 'json', + success: function (data) { + log_input.val(data.log_id); + }, + error: function (data) { + console.log(data); + } + }); + } + + var hist_url = list.parent().parent().find('.hist_log_url').val(); + var hist_log_id = list.parent().parent().find('.hist_log_id').val(); + + if (typeof(hist_url) != 'undefined' && hist_log_id != "") { + $.ajax({ + url: hist_url, + data: {'action': 'close', 'log_id': hist_log_id}, + dataType: 'json', + success: function (data) { + console.log(data.message); + }, + error: function (data) { + console.log(data); + } + }); + } + list.parent().parent().find('.history').attr('style', 'display: none'); list.parent().attr('style', 'display: block'); @@ -166,6 +234,40 @@ function getHistory(panel_id) { } } + var url = container.find('.view_log_url').val(); + var log_id = container.find('.view_log_id').val(); + + if (typeof(url) != 'undefined') { + $.ajax({ + url: url, + data: {'action': 'close', 'log_id': log_id}, + dataType: 'json', + success: function (data) { + console.log(data.message); + }, + error: function (data) { + console.log(data); + } + }); + } + + var hist_url = container.find('.hist_log_url').val(); + var hist_log_input = container.find('.hist_log_id'); + + if (typeof(hist_url) != 'undefined') { + $.ajax({ + url: hist_url, + data: {'action': 'open'}, + dataType: 'json', + success: function (data) { + hist_log_input.val(data.log_id); + }, + error: function (data) { + console.log(data); + } + }); + } + container.find('.pendencies_link').removeClass('active'); container.find('.history_link').addClass('active'); diff --git a/notifications/templates/notifications/index.html b/notifications/templates/notifications/index.html index a19712e..ed8004b 100644 --- a/notifications/templates/notifications/index.html +++ b/notifications/templates/notifications/index.html @@ -41,11 +41,17 @@
+ + +
+ + +
diff --git a/notifications/urls.py b/notifications/urls.py index b26949f..744a414 100644 --- a/notifications/urls.py +++ b/notifications/urls.py @@ -7,6 +7,8 @@ urlpatterns = [ url(r'^set_goal/$', views.set_goal, name='set_goal'), url(r'^ajax/(?P[\w_-]+)/$', views.AjaxNotifications.as_view(), name='ajax_view'), url(r'^ajax_history/(?P[\w_-]+)/$', views.AjaxHistory.as_view(), name='ajax_history'), + url(r'^view_log/(?P[\w_-]+)/$', views.pendencies_view_log, name = 'view_log'), + url(r'^hist_log/(?P[\w_-]+)/$', views.pendencies_hist_log, name = 'hist_log'), url(r'^(?P[\w_-]+)/$', views.SubjectNotifications.as_view(), name='view'), url(r'^(?P[\w_-]+)/history/$', views.SubjectHistory.as_view(), name='history'), ] \ No newline at end of file diff --git a/notifications/views.py b/notifications/views.py index d8ba891..7bfb737 100644 --- a/notifications/views.py +++ b/notifications/views.py @@ -17,10 +17,20 @@ from amadeus.permissions import has_subject_view_permissions, has_category_permi from subjects.models import Subject from categories.models import Category +from log.models import Log +from log.mixins import LogMixin +from log.decorators import log_decorator, log_decorator_ajax +import time + from .models import Notification from .utils import get_order_by, is_date -class SubjectNotifications(LoginRequiredMixin, generic.ListView): +class SubjectNotifications(LoginRequiredMixin, LogMixin, generic.ListView): + log_component = 'pendencies' + log_action = 'view' + log_resource = 'pendencies' + log_context = {} + login_url = reverse_lazy("users:login") redirect_field_name = 'next' @@ -60,9 +70,24 @@ class SubjectNotifications(LoginRequiredMixin, generic.ListView): context['subject'] = subject context['total'] = self.total + self.log_context['subject_id'] = subject.id + self.log_context['subject_name'] = subject.name + self.log_context['subject_slug'] = subject.slug + self.log_context['view_page'] = self.request.GET.get("page", 1) + self.log_context['timestamp_start'] = str(int(time.time())) + + super(SubjectNotifications, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) + + self.request.session['log_id'] = Log.objects.latest('id').id + return context -class SubjectHistory(LoginRequiredMixin, generic.ListView): +class SubjectHistory(LoginRequiredMixin, LogMixin, generic.ListView): + log_component = 'pendencies' + log_action = 'view_history' + log_resource = 'pendencies' + log_context = {} + login_url = reverse_lazy("users:login") redirect_field_name = 'next' @@ -127,6 +152,17 @@ class SubjectHistory(LoginRequiredMixin, generic.ListView): context['rows'] = self.num_rows context['searched'] = self.request.GET.get("search", "") + self.log_context['subject_id'] = subject.id + self.log_context['subject_name'] = subject.name + self.log_context['subject_slug'] = subject.slug + self.log_context['history_page'] = self.request.GET.get("page", 1) + self.log_context['searched'] = self.request.GET.get("search", "") + self.log_context['timestamp_start'] = str(int(time.time())) + + super(SubjectHistory, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) + + self.request.session['log_id'] = Log.objects.latest('id').id + return context class IndexView(LoginRequiredMixin, generic.ListView): @@ -237,6 +273,7 @@ class AjaxHistory(LoginRequiredMixin, generic.ListView): return context @login_required +@log_decorator('pendencies', 'set_goal', 'pendencies') def set_goal(request): if request.method == "POST" and request.is_ajax(): meta = request.POST.get('meta', None) @@ -264,9 +301,59 @@ def set_goal(request): notification.meta = meta notification.save() + log_context = {} + log_context['notification_id'] = notification.id + log_context['notification'] = str(notification) + + request.log_context = log_context + if notification.level == 2: - message = _('Your new goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) + message = _('Your new goal to realize the task %s is %s')%(str(notification), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) else: - message = _('Your goal to realize the task %s is %s')%(str(notification.task), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) + message = _('Your goal to realize the task %s is %s')%(str(notification), formats.date_format(meta, "SHORT_DATETIME_FORMAT")) + + return JsonResponse({'error': False, 'message': message}) + +@log_decorator_ajax('pendencies', 'view', 'pendencies') +def pendencies_view_log(request, subject): + action = request.GET.get('action') + + if action == 'open': + subject = get_object_or_404(Subject, id = subject) + + log_context = {} + log_context['subject_id'] = subject.id + log_context['subject_name'] = subject.name + log_context['subject_slug'] = subject.slug + log_context['timestamp_start'] = str(int(time.time())) + log_context['timestamp_end'] = '-1' + + request.log_context = log_context + + log_id = Log.objects.latest('id').id + + return JsonResponse({'message': 'ok', 'log_id': log_id}) + + return JsonResponse({'message': 'ok'}) + +@log_decorator_ajax('pendencies', 'view_history', 'pendencies') +def pendencies_hist_log(request, subject): + action = request.GET.get('action') + + if action == 'open': + subject = get_object_or_404(Subject, id = subject) + + log_context = {} + log_context['subject_id'] = subject.id + log_context['subject_name'] = subject.name + log_context['subject_slug'] = subject.slug + log_context['timestamp_start'] = str(int(time.time())) + log_context['timestamp_end'] = '-1' + + request.log_context = log_context + + log_id = Log.objects.latest('id').id + + return JsonResponse({'message': 'ok', 'log_id': log_id}) - return JsonResponse({'error': False, 'message': message}) \ No newline at end of file + return JsonResponse({'message': 'ok'}) \ No newline at end of file -- libgit2 0.21.2