Updated Thread / Messaging to show unread / read messages
Showing subscribers in main.html Messages are considered read when the message is opened by the user. Fixed error left from before where batch date was not updated on updating purchase voucher.
This commit is contained in:
parent
a2587cda60
commit
30a38f7ed9
@ -71,6 +71,8 @@ class Thread(Base):
|
||||
|
||||
@classmethod
|
||||
def by_id(cls, id):
|
||||
if not isinstance(id, uuid.UUID):
|
||||
id = uuid.UUID(id)
|
||||
return DBSession.query(cls).filter(cls.id == id).first()
|
||||
|
||||
@classmethod
|
||||
|
@ -1,6 +1,6 @@
|
||||
CACHE MANIFEST
|
||||
|
||||
# version 2013-06-19.1
|
||||
# version 2013-06-24.1
|
||||
|
||||
CACHE:
|
||||
/partial/404.html
|
||||
|
@ -6,7 +6,7 @@
|
||||
<li ng-class="{active: chosen == 'open'}"><a href ng-click="getMessages('open')">Open</a></li>
|
||||
<li ng-class="{active: chosen == 'closed'}"><a href ng-click="getMessages('closed')">Closed</a></li>
|
||||
<li ng-class="{active: chosen == 'all'}"><a href ng-click="getMessages('all')">All</a></li>
|
||||
<li class="dropdown pull-right active">
|
||||
<li class="dropdown pull-right">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tags
|
||||
<b class="caret"></b>
|
||||
</a>
|
||||
@ -18,24 +18,14 @@
|
||||
</div>
|
||||
<div class="widget-content nopadding">
|
||||
<table class="table table-bordered table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<input type="checkbox" ng-model="allChecked" ng-click="markAll(allChecked)">
|
||||
</th>
|
||||
<th>
|
||||
<h5>Details</h5>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="item in info">
|
||||
<td><input type="checkbox" ng-model="item.selected"></td>
|
||||
<tr ng-repeat="item in info" ng-class="{info: !item.Read}">
|
||||
<td>
|
||||
<span class="user-info">User: {{item.User}} {{item.Age}} ago. Updated {{item.LastUpdated}} ago.</span>
|
||||
|
||||
<p><a href="/Message/{{item.ThreadID}}">{{item.Title}}</a></p>
|
||||
<a class="btn btn-mini" ng-repeat="tag in item.Tags"> {{tag}}</a>
|
||||
<span class="label" ng-repeat="subscriber in item.Subscribers">{{subscriber}}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -8,11 +8,13 @@ overlord_directive.directive('ngAutocomplete', ['$q', '$parse', 'DeepLabel', fun
|
||||
var mappedCache = {},
|
||||
labels = [],
|
||||
mapped = {},
|
||||
deepLabel = DeepLabel;
|
||||
deepLabel = DeepLabel,
|
||||
count = 20;
|
||||
element.typeahead({
|
||||
source: function (query, process) {
|
||||
var Entity = angular.injector(['overlord.service']).get(attrs.resource);
|
||||
Entity.autocomplete({term: query, count: 20}, function (result) {
|
||||
var Entity = angular.injector(['overlord.service']).get(attrs.resource),
|
||||
options = {term: query, count: count};
|
||||
Entity.autocomplete(options, function (result) {
|
||||
labels = [];
|
||||
mapped = {};
|
||||
$.each(result, function (i, item) {
|
||||
@ -25,7 +27,7 @@ overlord_directive.directive('ngAutocomplete', ['$q', '$parse', 'DeepLabel', fun
|
||||
});
|
||||
},
|
||||
minLength: 1,
|
||||
items: 20,
|
||||
items: count,
|
||||
matcher: function (item) {
|
||||
return true;
|
||||
},
|
||||
|
@ -46,7 +46,7 @@ def save(request):
|
||||
if user_name not in request.json_body['Subscribers']:
|
||||
request.json_body['Subscribers'].append(user_name)
|
||||
for item in request.json_body['Subscribers']:
|
||||
subscriber = Subscriber(user_id=User.by_name(item).id, read=False)
|
||||
subscriber = Subscriber(user_id=User.by_name(item).id, read=item == user_name)
|
||||
thread.subscribers.append(subscriber)
|
||||
DBSession.add(subscriber)
|
||||
transaction.commit()
|
||||
@ -57,6 +57,7 @@ def save(request):
|
||||
@TryCatchFunction
|
||||
def update(request):
|
||||
user_id = uuid.UUID(authenticated_userid(request))
|
||||
user_name = User.by_id(user_id).name
|
||||
super_user = 'Messages' in groupfinder(user_id, request)
|
||||
thread = Thread.by_id(uuid.UUID(request.matchdict['id']))
|
||||
public = request.json_body['Public']
|
||||
@ -101,6 +102,8 @@ def update(request):
|
||||
thread.posts.append(post)
|
||||
DBSession.add(post)
|
||||
|
||||
if user_name not in request.json_body['Subscribers']:
|
||||
request.json_body['Subscribers'].append(user_name)
|
||||
newSubscribers = request.json_body['Subscribers']
|
||||
for i in range(len(thread.subscribers), 0, -1):
|
||||
subscriber = thread.subscribers[i - 1]
|
||||
@ -108,9 +111,9 @@ def update(request):
|
||||
thread.subscribers.remove(subscriber)
|
||||
else:
|
||||
newSubscribers.remove(subscriber.user.name)
|
||||
subscriber.read = False
|
||||
subscriber.read = subscriber.user.name == user_name
|
||||
for j in newSubscribers:
|
||||
subscriber = Subscriber(user_id=User.by_name(j).id, read=False)
|
||||
subscriber = Subscriber(user_id=User.by_name(j).id, read=j == user_name)
|
||||
thread.subscribers.append(subscriber)
|
||||
DBSession.add(subscriber)
|
||||
|
||||
@ -127,7 +130,14 @@ def show_blank(request):
|
||||
|
||||
@view_config(request_method='GET', route_name='api_message_id', renderer='json', permission='Authenticated')
|
||||
def show_id(request):
|
||||
return thread_info(uuid.UUID(request.matchdict.get('id', None)))
|
||||
user_id = authenticated_userid(request) and uuid.UUID(authenticated_userid(request))
|
||||
thread = Thread.by_id(request.matchdict['id'])
|
||||
subscriber = [s for s in thread.subscribers if s.user_id == user_id]
|
||||
if len(subscriber) > 0:
|
||||
subscriber[0].read = True
|
||||
info = thread_info(thread)
|
||||
transaction.commit()
|
||||
return info
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='api_message', renderer='json', request_param='list')
|
||||
@ -153,7 +163,7 @@ def show_list(request):
|
||||
tags = {}
|
||||
threads = []
|
||||
for item in list:
|
||||
thread = {'ThreadID': item.id, 'Title': item.title, 'Age': get_age(item.creation_date),
|
||||
thread = {'ThreadID': item.id, 'Title': item.title, 'Age': get_age(item.creation_date), 'Read': False,
|
||||
'CreationDate': item.creation_date.strftime('%d-%b-%Y %H:%M'), 'User': item.user.name,
|
||||
'Priority': item.priority, 'Public': item.public, 'Tags': [], 'Posts': [], 'Subscribers': []}
|
||||
last_updated = item.creation_date
|
||||
@ -168,12 +178,16 @@ def show_list(request):
|
||||
else:
|
||||
tags[tag.name] += 1
|
||||
|
||||
for subscriber in item.subscribers:
|
||||
thread['Subscribers'].append(subscriber.user.name)
|
||||
if subscriber.user_id == user_id:
|
||||
thread['Read'] = subscriber.read
|
||||
threads.append(thread)
|
||||
return {'Tags': tags, 'Threads': threads, 'Type': type}
|
||||
|
||||
|
||||
def thread_info(id):
|
||||
item = Thread.by_id(id)
|
||||
item = id if isinstance(id, Thread) else Thread.by_id(id)
|
||||
thread = {'ThreadID': item.id, 'Title': item.title, 'Closed': item.closed,
|
||||
'CreationDate': item.creation_date.strftime('%d-%b-%Y %H:%M'), 'User': item.user.name,
|
||||
'Priority': item.priority, 'Public': item.public, 'Tags': [], 'Posts': [], 'Subscribers': []}
|
||||
|
@ -103,6 +103,7 @@ def purchase_update_inventory(voucher, newInventories):
|
||||
rate = round(Decimal(i['Rate']), 2)
|
||||
discount = round(Decimal(i['Discount']), 5)
|
||||
tax = round(Decimal(i['Tax']), 5)
|
||||
item.batch.name = voucher.date
|
||||
item.rate = rate
|
||||
item.batch.rate = rate
|
||||
item.discount = discount
|
||||
|
Loading…
Reference in New Issue
Block a user