Commit fb729f14fda54d96d51be2c8a00fbd0245fc33eb

Authored by Zambom
1 parent 1651dd2d

Adding goals reports log

amadeus/static/js/goals_reports.js
@@ -40,6 +40,60 @@ function getAnswered() { @@ -40,6 +40,60 @@ function getAnswered() {
40 }); 40 });
41 } 41 }
42 42
  43 +
  44 + var url = container.find('.answ_log_url').val();
  45 + var log_input = container.find('.answ_log_id');
  46 +
  47 + if (typeof(url) != 'undefined') {
  48 + $.ajax({
  49 + url: url,
  50 + data: {'action': 'open'},
  51 + dataType: 'json',
  52 + success: function (data) {
  53 + log_input.val(data.log_id);
  54 + },
  55 + error: function (data) {
  56 + console.log(data);
  57 + }
  58 + });
  59 + }
  60 +
  61 + var unan_url = container.find('.unan_log_url').val();
  62 + var unan_log_id = container.find('.unan_log_id').val();
  63 +
  64 + if (typeof(unan_url) != 'undefined' && unan_log_id != "") {
  65 + $.ajax({
  66 + url: unan_url,
  67 + data: {'action': 'close', 'log_id': unan_log_id},
  68 + dataType: 'json',
  69 + success: function (data) {
  70 + console.log(data.message);
  71 + container.find('.unan_log_id').val("");
  72 + },
  73 + error: function (data) {
  74 + console.log(data);
  75 + }
  76 + });
  77 + }
  78 +
  79 + var hist_url = container.find('.hist_log_url').val();
  80 + var hist_log_id = container.find('.hist_log_id').val();
  81 +
  82 + if (typeof(hist_url) != 'undefined' && hist_log_id != "") {
  83 + $.ajax({
  84 + url: hist_url,
  85 + data: {'action': 'close', 'log_id': hist_log_id},
  86 + dataType: 'json',
  87 + success: function (data) {
  88 + console.log(data.message);
  89 + container.find('.hist_log_id').val("");
  90 + },
  91 + error: function (data) {
  92 + console.log(data);
  93 + }
  94 + });
  95 + }
  96 +
43 container.find('.answered_link').addClass('active'); 97 container.find('.answered_link').addClass('active');
44 container.find('.answered').show(); 98 container.find('.answered').show();
45 99
@@ -103,6 +157,59 @@ function getUnanswered() { @@ -103,6 +157,59 @@ function getUnanswered() {
103 }); 157 });
104 } 158 }
105 159
  160 + var url = container.find('.answ_log_url').val();
  161 + var log_id = container.find('.answ_log_id').val();
  162 +
  163 + if (typeof(url) != 'undefined' && log_id != "") {
  164 + $.ajax({
  165 + url: url,
  166 + data: {'action': 'close', 'log_id': log_id},
  167 + dataType: 'json',
  168 + success: function (data) {
  169 + console.log(data.message);
  170 + container.find('.answ_log_id').val("");
  171 + },
  172 + error: function (data) {
  173 + console.log(data);
  174 + }
  175 + });
  176 + }
  177 +
  178 + var unan_url = container.find('.unan_log_url').val();
  179 + var unan_log_input = container.find('.unan_log_id');
  180 +
  181 + if (typeof(unan_url) != 'undefined') {
  182 + $.ajax({
  183 + url: unan_url,
  184 + data: {'action': 'open'},
  185 + dataType: 'json',
  186 + success: function (data) {
  187 + unan_log_input.val(data.log_id);
  188 + },
  189 + error: function (data) {
  190 + console.log(data);
  191 + }
  192 + });
  193 + }
  194 +
  195 + var hist_url = container.find('.hist_log_url').val();
  196 + var hist_log_id = container.find('.hist_log_id').val();
  197 +
  198 + if (typeof(hist_url) != 'undefined' && hist_log_id != "") {
  199 + $.ajax({
  200 + url: hist_url,
  201 + data: {'action': 'close', 'log_id': hist_log_id},
  202 + dataType: 'json',
  203 + success: function (data) {
  204 + console.log(data.message);
  205 + container.find('.hist_log_id').val("");
  206 + },
  207 + error: function (data) {
  208 + console.log(data);
  209 + }
  210 + });
  211 + }
  212 +
106 container.find('.answered_link').removeClass('active'); 213 container.find('.answered_link').removeClass('active');
107 container.find('.answered').hide(); 214 container.find('.answered').hide();
108 215
@@ -153,6 +260,60 @@ function getHistory() { @@ -153,6 +260,60 @@ function getHistory() {
153 }); 260 });
154 } 261 }
155 262
  263 + var url = container.find('.answ_log_url').val();
  264 + var log_id = container.find('.answ_log_id').val();
  265 +
  266 + if (typeof(url) != 'undefined' && log_id != "") {
  267 + $.ajax({
  268 + url: url,
  269 + data: {'action': 'close', 'log_id': log_id},
  270 + dataType: 'json',
  271 + success: function (data) {
  272 + console.log(data.message);
  273 + container.find('.answ_log_id').val("");
  274 + },
  275 + error: function (data) {
  276 + console.log(data);
  277 + }
  278 + });
  279 + }
  280 +
  281 + var unan_url = container.find('.unan_log_url').val();
  282 + var unan_log_id = container.find('.unan_log_id').val();
  283 +
  284 + if (typeof(unan_url) != 'undefined' && unan_log_id != "") {
  285 + $.ajax({
  286 + url: unan_url,
  287 + data: {'action': 'close', 'log_id': unan_log_id},
  288 + dataType: 'json',
  289 + success: function (data) {
  290 + console.log(data.message);
  291 + container.find('.unan_log_id').val("");
  292 + },
  293 + error: function (data) {
  294 + console.log(data);
  295 + }
  296 +
  297 + });
  298 + }
  299 +
  300 + var hist_url = container.find('.hist_log_url').val();
  301 + var hist_log_input = container.find('.hist_log_id');
  302 +
  303 + if (typeof(hist_url) != 'undefined') {
  304 + $.ajax({
  305 + url: hist_url,
  306 + data: {'action': 'open'},
  307 + dataType: 'json',
  308 + success: function (data) {
  309 + hist_log_input.val(data.log_id);
  310 + },
  311 + error: function (data) {
  312 + console.log(data);
  313 + }
  314 + });
  315 + }
  316 +
156 container.find('.answered_link').removeClass('active'); 317 container.find('.answered_link').removeClass('active');
157 container.find('.answered').hide(); 318 container.find('.answered').hide();
158 319
amadeus/static/js/pendencies.js
@@ -172,6 +172,7 @@ function getPendencies(panel_id) { @@ -172,6 +172,7 @@ function getPendencies(panel_id) {
172 dataType: 'json', 172 dataType: 'json',
173 success: function (data) { 173 success: function (data) {
174 console.log(data.message); 174 console.log(data.message);
  175 + list.parent().parent().find('.hist_log_id').val("");
175 }, 176 },
176 error: function (data) { 177 error: function (data) {
177 console.log(data); 178 console.log(data);
@@ -244,6 +245,7 @@ function getHistory(panel_id) { @@ -244,6 +245,7 @@ function getHistory(panel_id) {
244 dataType: 'json', 245 dataType: 'json',
245 success: function (data) { 246 success: function (data) {
246 console.log(data.message); 247 console.log(data.message);
  248 + container.find('.view_log_id').val("");
247 }, 249 },
248 error: function (data) { 250 error: function (data) {
249 console.log(data); 251 console.log(data);
goals/templates/goals/reports.html
@@ -61,14 +61,23 @@ @@ -61,14 +61,23 @@
61 </div> 61 </div>
62 62
63 <div class="answered" data-url="{% url 'goals:answered_report' goal.slug %}"> 63 <div class="answered" data-url="{% url 'goals:answered_report' goal.slug %}">
  64 + <input type="hidden" class="answ_log_url" value="{% url 'goals:reports_log' goal.slug 'answered' %}" />
  65 + <input type="hidden" class="answ_log_id" value="" />
  66 +
64 <div class="answered_data"></div> 67 <div class="answered_data"></div>
65 </div> 68 </div>
66 69
67 <div class="unanswered" data-url="{% url 'goals:unanswered_report' goal.slug %}"> 70 <div class="unanswered" data-url="{% url 'goals:unanswered_report' goal.slug %}">
  71 + <input type="hidden" class="unan_log_url" value="{% url 'goals:reports_log' goal.slug 'unanaswered' %}" />
  72 + <input type="hidden" class="unan_log_id" value="" />
  73 +
68 <div class="unanswered_data"></div> 74 <div class="unanswered_data"></div>
69 </div> 75 </div>
70 76
71 <div class="history" data-url="{% url 'goals:history_report' goal.slug %}"> 77 <div class="history" data-url="{% url 'goals:history_report' goal.slug %}">
  78 + <input type="hidden" class="hist_log_url" value="{% url 'goals:reports_log' goal.slug 'history' %}" />
  79 + <input type="hidden" class="hist_log_id" value="" />
  80 +
72 <div class="history_data"></div> 81 <div class="history_data"></div>
73 </div> 82 </div>
74 </div> 83 </div>
@@ -15,4 +15,5 @@ urlpatterns = [ @@ -15,4 +15,5 @@ urlpatterns = [
15 url(r'^answered_report/(?P<slug>[\w_-]+)/$', views.AnsweredReport.as_view(), name = 'answered_report'), 15 url(r'^answered_report/(?P<slug>[\w_-]+)/$', views.AnsweredReport.as_view(), name = 'answered_report'),
16 url(r'^unanswered_report/(?P<slug>[\w_-]+)/$', views.UnansweredReport.as_view(), name = 'unanswered_report'), 16 url(r'^unanswered_report/(?P<slug>[\w_-]+)/$', views.UnansweredReport.as_view(), name = 'unanswered_report'),
17 url(r'^history_report/(?P<slug>[\w_-]+)/$', views.HistoryReport.as_view(), name = 'history_report'), 17 url(r'^history_report/(?P<slug>[\w_-]+)/$', views.HistoryReport.as_view(), name = 'history_report'),
  18 + url(r'^view_log/(?P<goal>[\w_-]+)/(?P<report>[\w_-]+)/$', views.reports_log, name = 'reports_log'),
18 ] 19 ]
goals/views.py
@@ -5,6 +5,7 @@ from django.core.urlresolvers import reverse, reverse_lazy @@ -5,6 +5,7 @@ from django.core.urlresolvers import reverse, reverse_lazy
5 from django.utils.translation import ugettext_lazy as _ 5 from django.utils.translation import ugettext_lazy as _
6 from django.contrib.auth.mixins import LoginRequiredMixin 6 from django.contrib.auth.mixins import LoginRequiredMixin
7 from django.forms import formset_factory, modelformset_factory 7 from django.forms import formset_factory, modelformset_factory
  8 +from django.http import JsonResponse
8 9
9 from log.models import Log 10 from log.models import Log
10 from log.mixins import LogMixin 11 from log.mixins import LogMixin
@@ -155,7 +156,7 @@ class HistoryReport(LoginRequiredMixin, generic.ListView): @@ -155,7 +156,7 @@ class HistoryReport(LoginRequiredMixin, generic.ListView):
155 slug = self.kwargs.get('slug', '') 156 slug = self.kwargs.get('slug', '')
156 goal = get_object_or_404(Goals, slug = slug) 157 goal = get_object_or_404(Goals, slug = slug)
157 158
158 - rows = Log.objects.filter(context__contains = {"goals_id": goal.id}) 159 + rows = Log.objects.filter(context__contains = {"goals_id": goal.id}).exclude(action = 'view_reports')
159 160
160 return rows 161 return rows
161 162
@@ -929,4 +930,36 @@ class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): @@ -929,4 +930,36 @@ class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView):
929 930
930 super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) 931 super(DeleteView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context)
931 932
932 - return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug})  
933 \ No newline at end of file 933 \ No newline at end of file
  934 + return reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug})
  935 +
  936 +@log_decorator_ajax('resources', 'view_reports', 'goals')
  937 +def reports_log(request, goal, report):
  938 + action = request.GET.get('action')
  939 +
  940 + if action == 'open':
  941 + goals = get_object_or_404(Goals, slug = goal)
  942 +
  943 + log_context = {}
  944 + log_context['category_id'] = goals.topic.subject.category.id
  945 + log_context['category_name'] = goals.topic.subject.category.name
  946 + log_context['category_slug'] = goals.topic.subject.category.slug
  947 + log_context['subject_id'] = goals.topic.subject.id
  948 + log_context['subject_name'] = goals.topic.subject.name
  949 + log_context['subject_slug'] = goals.topic.subject.slug
  950 + log_context['topic_id'] = goals.topic.id
  951 + log_context['topic_name'] = goals.topic.name
  952 + log_context['topic_slug'] = goals.topic.slug
  953 + log_context['goals_id'] = goals.id
  954 + log_context['goals_name'] = goals.name
  955 + log_context['goals_slug'] = goals.slug
  956 + log_context['goals_report'] = report
  957 + log_context['timestamp_start'] = str(int(time.time()))
  958 + log_context['timestamp_end'] = '-1'
  959 +
  960 + request.log_context = log_context
  961 +
  962 + log_id = Log.objects.latest('id').id
  963 +
  964 + return JsonResponse({'message': 'ok', 'log_id': log_id})
  965 +
  966 + return JsonResponse({'message': 'ok'})
934 \ No newline at end of file 967 \ No newline at end of file