Skip to content
This repository has been archived by the owner on Apr 4, 2018. It is now read-only.

Commit

Permalink
Merge pull request #10 from thesedateone/feature/manual_queuing
Browse files Browse the repository at this point in the history
Feature/manual queuing
  • Loading branch information
jacquesbeukes committed Mar 25, 2015
2 parents b0f8ec3 + a3bf25b commit b32ea45
Show file tree
Hide file tree
Showing 37 changed files with 647 additions and 165 deletions.
4 changes: 4 additions & 0 deletions assets/js/call/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ ecApp.config(['$routeProvider',
templateUrl: djangoStatic + 'partials/call/call.html',
controller: 'callCtrl'
}).
when('/call/:callCat/empty', {
templateUrl: djangoStatic + 'partials/call/call_empty.html',
controller: 'callEmptyCtrl'
}).
otherwise({
redirectTo: '/ready'
});
Expand Down
21 changes: 15 additions & 6 deletions assets/js/call/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ var ecAppControllers = angular.module('ecAppControllers', ['restangular']);


ecAppControllers.controller('readyCtrl',
['$scope', 'Restangular', '$q',
function($scope, Restangular, $q) {
'use strict';

['$scope', 'Restangular',
function($scope, Restangular) {
Restangular.all('list_types/').getList().then(function(types) {
$scope.types = types;
});
}]);


ecAppControllers.controller('callEmptyCtrl',
['$scope', '$routeParams', 'Restangular',
function($scope, $routeParams, Restangular) {
Restangular.one('list_types/' + $routeParams.callCat + '/').get().then(
function(callType) {
$scope.callType = callType;
});
}]);


ecAppControllers.controller('callCtrl',
['$scope', '$routeParams', 'Restangular', '$q',
function($scope, $routeParams, Restangular, $q) {
['$scope', '$routeParams', 'Restangular', '$q', '$window',
function($scope, $routeParams, Restangular, $q, $window) {
'use strict';

Restangular.one('list_types/' + $routeParams.callCat + '/').get().then(
Expand All @@ -35,6 +43,7 @@ ecAppControllers.controller('callCtrl',
}, function (response) {
console.log("Error with status code", response.status);
deferred.reject();
$window.location.href = '#/call/' + $routeParams.callCat + '/empty';
});

return deferred.promise;
Expand Down
6 changes: 6 additions & 0 deletions assets/js/queue/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var ecQueue = angular.module('ecQueue', [
'restangular',
'ecQueueControllers',
'ecQueueDirectives',
'ecQueueServices',
]);
48 changes: 48 additions & 0 deletions assets/js/queue/controllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Controllers */

var ecQueueControllers = angular.module('ecQueueControllers', []);


ecQueueControllers.controller('queueCtrl',
['$scope', 'ListType', 'ListTypeReport',
function($scope, ListType, ListTypeReport) {

$scope.refresh = function() {
ListType.getData().then(
function(list_types) {
$scope.listtypes = {};
list_types.forEach(function(element) {
ListTypeReport.getData(element.slug).then(function(result) {
var typeInfo = {
'slug': element.slug,
'display': element.display_name,
'completed': result.completed,
'dequeued': result.dequeued,
'inprogress': result.inprogress,
'new': result.new,
'queued': result.queued
};
$scope.listtypes[typeInfo.slug] = typeInfo;
});
});
});
};

$scope.doqueue = function(data) {
var slug = data.slug;
ListTypeReport.doQueue(slug).then(
function(result) {
data.completed = result.completed;
data.dequeued = result.dequeued;
data.inprogress = result.inprogress;
data.new = result.new;
data.queued = result.queued;

$scope.listtypes[slug] = data;
});
};

$scope.listtypes = [];
$scope.refresh();

}]);
31 changes: 31 additions & 0 deletions assets/js/queue/directives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Directives */

var ecQueueDirectives = angular.module('ecQueueDirectives', []);


ecQueueDirectives.directive('ecReportRow', function() {
return {
restrict: "A",
scope: {
'data': "=",
'queuefunc': "&",
},
template:
' <th>{{ data.display }}</th>' +
' <td>{{ data.completed }}</td>' +
' <td>{{ data.dequeued }}</td>' +
' <td>{{ data.inprogress }}</td>' +
' <td>{{ data.new }}</td>' +
' <td class="info">{{ data.queued }}</td>' +
' <td>' +
' <button class="btn btn-sm btn-primary pull-right" type="button"' +
' ng-click="queue()">Queue</button>' +
' </td>',

link: function (scope, element, attrs) {
scope.queue = function() {
scope.queuefunc({'list': scope.data});
};
}
};
});
42 changes: 42 additions & 0 deletions assets/js/queue/services.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Services and Factories */

var ecQueueServices = angular.module('ecQueueServices', ['restangular']);


ecQueueServices.factory('ListType',
['$q', 'Restangular',
function($q, Restangular) {
return {
getData: function() {
var deferred = $q.defer();
Restangular.all('list_types/').getList().then(function(result) {
deferred.resolve(result);
});
return deferred.promise;
}
};
}]);


ecQueueServices.factory('ListTypeReport',
['$q', 'Restangular',
function($q, Restangular) {
return {
getData: function(slug) {
var deferred = $q.defer();
Restangular.all('list_types/').one(slug + '/report/').get().then(function(result) {
deferred.resolve(result);
});
return deferred.promise;
},

doQueue: function(slug) {
var deferred = $q.defer();
Restangular.all('list_types/').one(slug + '/report/')
.put({}, {"X-CSRFToken": csrf_token}).then(function(result) {
deferred.resolve(result);
});
return deferred.promise;
}
};
}]);
2 changes: 1 addition & 1 deletion assets/js/search/controllers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Controllers */

var ecSearchControllers = angular.module('ecSearchControllers', ['restangular']);
var ecSearchControllers = angular.module('ecSearchControllers', []);


ecSearchControllers.controller('searchCtrl',
Expand Down
2 changes: 1 addition & 1 deletion assets/js/search/services.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Controllers */
/* Services */

var ecSearchServices = angular.module('ecSearchServices', ['restangular']);

Expand Down
10 changes: 10 additions & 0 deletions assets/partials/call/call_empty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="col-sm-6 col-sm-offset-3 text-center" >

<h2>There are no more records of type:<br>
'{{callType.display_name}}'.</h2>

<h3 class="sub-heading">Please try another List Type or talk to your supervisor.</h3>

<a class="btn btn-lg btn-primary" href="#/ready" role="button">Return</a>

</div>
4 changes: 4 additions & 0 deletions assets/styles/main.sass
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ h2
// margin-right: 15px
color: $dark-grey

h3.sub-heading
color: $very-light-grey


.title
font-size: 90%
font-weight: bolder
Expand Down
10 changes: 9 additions & 1 deletion easyCall/apps/call_records/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from easyCall.apps.call_records.models import CallRecord, UserNote, Call
from easyCall.apps.call_records.models import CallRecord, UserNote
from easyCall.apps.call_records.models import Call, QueueEntry


class UserInline(admin.TabularInline):
Expand All @@ -18,8 +19,15 @@ class CallAdmin(admin.ModelAdmin):
list_filter = ('caller', 'result', 'start_time', 'end_time')


class QueueEntryAdmin(admin.ModelAdmin):
list_display = ('call_record', 'list_type', 'date_added')
list_filter = ('date_added',)
pass


admin.site.register(CallRecord, CallRecordAdmin)
admin.site.register(Call, CallAdmin)
admin.site.register(QueueEntry, QueueEntryAdmin)



41 changes: 12 additions & 29 deletions easyCall/apps/call_records/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from django.utils import timezone

from django.conf import settings
from django.db.models import Q
from django.db import IntegrityError

from easyCall.apps.call_records.models import CallRecord
from easyCall.apps.call_records.models import QueueEntry
from easyCall.apps.call_records.models import ExtraInformation
Expand Down Expand Up @@ -32,7 +35,6 @@ def import_csv(file_name, list_type):
record.save()
save_notes(list_type, row, record)
save_extras(list_type, row, record)
_do_queue_repopulation()


def create_main_record(list_type, row):
Expand Down Expand Up @@ -228,31 +230,12 @@ def save_extras(list_type, row, record):



def populate_queue():
# TODO: things will get hairy if the queue is completely empty
queue_size = QueueEntry.objects.count()

if queue_size > 0:
print("there is something in the queue")
# Figure out the earliest time we can repopulate
timezone.activate(pytz.timezone(settings.TIME_ZONE))
last_update = QueueEntry.objects.last().date_added
print(last_update)
delta = timedelta(minutes=2)
now = timezone.now()

if now < (last_update + delta):
print("too soon, can't repopulate")
return False

# repopulate queue
_do_queue_repopulation()
return True


def _do_queue_repopulation():
records = CallRecord.objects.filter(status=CallRecord.NEW)
for record in records:
entry = QueueEntry(call_record=record,
list_type=record.list_type)
entry.save()
def populate_queue(slug):
records = CallRecord.objects.filter(Q(status=CallRecord.NEW) | Q(status=CallRecord.IN_PROGRESS))
for record in records.filter(list_type=slug):
try:
entry = QueueEntry(call_record=record,
list_type=record.list_type)
entry.save()
except IntegrityError as ie:
pass # Nothing to do
20 changes: 20 additions & 0 deletions easyCall/apps/call_records/migrations/0015_auto_20150323_2221.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('call_records', '0014_auto_20150315_1453'),
]

operations = [
migrations.AlterField(
model_name='queueentry',
name='call_record',
field=models.OneToOneField(to='call_records.CallRecord'),
preserve_default=True,
),
]
10 changes: 6 additions & 4 deletions easyCall/apps/call_records/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def update_status(self, category):

def handle_dequeue(self):
if self.status == self.DEQUEUED:
if self.queueentry_set.exists():
self.queueentry_set.all().delete()
try:
self.queueentry.delete()
except AttributeError:
pass # There is nothing to delete

def __unicode__(self):
"""CallRecord to_string method."""
Expand All @@ -83,11 +85,11 @@ def __unicode__(self):

class QueueEntry(models.Model):
list_type = models.ForeignKey(ListType)
call_record = models.ForeignKey(CallRecord)
call_record = models.OneToOneField(CallRecord)
date_added = models.DateTimeField(auto_now_add=True)

def __unicode__(self):
"""CallRecord to_string method."""
"""QueueEntry to_string method."""
return "{} ({})".format(self.call_record.id, self.list_type.slug)


Expand Down
6 changes: 1 addition & 5 deletions easyCall/apps/call_records/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from easyCall.apps.call_records.models import UserNote
from easyCall.apps.call_records.models import Call
from easyCall.apps.lists.models import CallResult
from easyCall.apps.call_records.importer import populate_queue
from easyCall.apps.call_records.serializers import CallRecordSerializer
from easyCall.apps.call_records.serializers import UserNoteSerializer
from easyCall.apps.call_records.serializers import SystemNoteSerializer
Expand Down Expand Up @@ -232,7 +231,6 @@ def get(self, request, list_type, format=None):
caller = User.objects.get(id=request.user.id)
call = Call(call_record=record, caller=caller)
call.save()
print(call.id)
serializer = CallRecordSerializer(record)
return Response(serializer.data)

Expand All @@ -251,6 +249,4 @@ def _get_object(self, list_type):
# kind of expected, try again
pass
except QueueEntry.DoesNotExist:
could_repopulate = populate_queue()
if not could_repopulate:
raise Http404
raise Http404
Loading

0 comments on commit b32ea45

Please sign in to comment.