Allow filtering of Threads based on open / closed / all on home.html
This commit is contained in:
parent
970eea2979
commit
0ff8108ebe
|
@ -1,6 +1,6 @@
|
||||||
CACHE MANIFEST
|
CACHE MANIFEST
|
||||||
|
|
||||||
# version 2013-06-06.3
|
# version 2013-06-07.1
|
||||||
|
|
||||||
CACHE:
|
CACHE:
|
||||||
/partial/404.html
|
/partial/404.html
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
<div class="widget-box">
|
<div class="widget-box">
|
||||||
<div class="widget-title">
|
<div class="widget-title">
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
<li><a href="#">Open</a></li>
|
<li ng-class="{active: chosen == 'open'}"><a href ng-click="getMessages('open')">Open</a></li>
|
||||||
<li><a href="#">Closed</a></li>
|
<li ng-class="{active: chosen == 'closed'}"><a href ng-click="getMessages('closed')">Closed</a></li>
|
||||||
<li><a href="#">All</a></li>
|
<li ng-class="{active: chosen == 'all'}"><a href ng-click="getMessages('all')">All</a></li>
|
||||||
<li class="dropdown pull-right">
|
<li class="dropdown pull-right">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tags
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tags
|
||||||
<b class="caret"></b>
|
<b class="caret"></b>
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var HomeCtrl = ['$scope', '$location', 'messages', function ($scope, $location, messages) {
|
var HomeCtrl = ['$scope', '$location', 'messages', 'Message', function ($scope, $location, messages, Message) {
|
||||||
|
$scope.chosen = messages.Type;
|
||||||
$scope.info = messages.Threads;
|
$scope.info = messages.Threads;
|
||||||
$scope.tags = messages.Tags
|
$scope.tags = messages.Tags
|
||||||
$scope.openMessage = function (item) {
|
$scope.getMessages = function (type) {
|
||||||
$location.path('/Message/' + item.ThreadID);
|
Message.query({type: type}, function (result) {
|
||||||
|
$scope.info = result.Threads;
|
||||||
|
$scope.tags = result.Tags;
|
||||||
|
$scope.chosen = result.Type;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}];
|
}];
|
||||||
HomeCtrl.resolve = {
|
HomeCtrl.resolve = {
|
||||||
messages: ['$q', '$route', 'Message', function ($q, $route, Message) {
|
messages: ['$q', '$route', 'Message', function ($q, $route, Message) {
|
||||||
|
@ -16,7 +20,7 @@ HomeCtrl.resolve = {
|
||||||
deferred.resolve(result);
|
deferred.resolve(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
Message.query({}, successCb);
|
Message.query({type: 'open'}, successCb);
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}]
|
}]
|
||||||
};
|
};
|
|
@ -54,12 +54,13 @@ def save(request):
|
||||||
@TryCatchFunction
|
@TryCatchFunction
|
||||||
def update(request):
|
def update(request):
|
||||||
user_id = uuid.UUID(authenticated_userid(request))
|
user_id = uuid.UUID(authenticated_userid(request))
|
||||||
|
super_user = 'Messages' in groupfinder(user_id, request)
|
||||||
thread = Thread.by_id(uuid.UUID(request.matchdict['id']))
|
thread = Thread.by_id(uuid.UUID(request.matchdict['id']))
|
||||||
public = request.json_body['Public']
|
public = request.json_body['Public']
|
||||||
closed = request.json_body['Closed']
|
closed = request.json_body['Closed']
|
||||||
if thread.public and not public:
|
if super_user or (thread.public and not public):
|
||||||
thread.public = False
|
thread.public = False
|
||||||
if not thread.closed and closed:
|
if super_user or (not thread.closed and closed):
|
||||||
thread.closed = True
|
thread.closed = True
|
||||||
thread.priority = request.json_body['Priority']
|
thread.priority = request.json_body['Priority']
|
||||||
|
|
||||||
|
@ -105,12 +106,23 @@ def show_id(request):
|
||||||
|
|
||||||
@view_config(request_method='GET', route_name='api_message', renderer='json', request_param='list')
|
@view_config(request_method='GET', route_name='api_message', renderer='json', request_param='list')
|
||||||
def show_list(request):
|
def show_list(request):
|
||||||
user_id = None if authenticated_userid(request) is None else uuid.UUID(authenticated_userid(request))
|
user_id = authenticated_userid(request) and uuid.UUID(authenticated_userid(request))
|
||||||
list = Thread.query().filter(Thread.closed == False)
|
list = Thread.query()
|
||||||
|
|
||||||
|
type = request.params.get('type', 'open')
|
||||||
|
if type == 'all':
|
||||||
|
pass
|
||||||
|
elif type == 'closed':
|
||||||
|
list = list.filter(Thread.closed == True)
|
||||||
|
else:
|
||||||
|
type = 'open'
|
||||||
|
list = list.filter(Thread.closed == False)
|
||||||
|
|
||||||
if user_id is None:
|
if user_id is None:
|
||||||
list = list.filter(Thread.public == True)
|
list = list.filter(Thread.public == True)
|
||||||
elif 'Messages' not in groupfinder(user_id, request):
|
elif 'Messages' not in groupfinder(user_id, request):
|
||||||
list = list.filter(Thread.subscribers.any(Subscriber.user_id == user_id))
|
list = list.filter(Thread.subscribers.any(Subscriber.user_id == user_id))
|
||||||
|
|
||||||
list = list.order_by(Thread.priority).all()
|
list = list.order_by(Thread.priority).all()
|
||||||
tags = {}
|
tags = {}
|
||||||
threads = []
|
threads = []
|
||||||
|
@ -118,24 +130,18 @@ def show_list(request):
|
||||||
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),
|
||||||
'CreationDate': item.creation_date.strftime('%d-%b-%Y %H:%M'), 'User': item.user.name,
|
'CreationDate': item.creation_date.strftime('%d-%b-%Y %H:%M'), 'User': item.user.name,
|
||||||
'Priority': item.priority, 'Public': item.public, 'Tags': [], 'Posts': [], 'Subscribers': []}
|
'Priority': item.priority, 'Public': item.public, 'Tags': [], 'Posts': [], 'Subscribers': []}
|
||||||
|
last_updated = max(post.creation_date for post in item.posts) or item.creation_date
|
||||||
|
thread['LastUpdated'] = get_age(last_updated)
|
||||||
|
|
||||||
for tag in item.tags:
|
for tag in item.tags:
|
||||||
thread['Tags'].append(tag.name)
|
thread['Tags'].append(tag.name)
|
||||||
if not tag.name in tags:
|
if not tag.name in tags:
|
||||||
tags[tag.name] = 1
|
tags[tag.name] = 1
|
||||||
else:
|
else:
|
||||||
tags[tag.name] += 1
|
tags[tag.name] += 1
|
||||||
for subscriber in item.subscribers:
|
|
||||||
thread['Subscribers'].append(subscriber.user.name)
|
|
||||||
last_updated = item.creation_date
|
|
||||||
for post in item.posts:
|
|
||||||
if post.creation_date > last_updated:
|
|
||||||
last_updated = post.creation_date
|
|
||||||
# thread['Posts'].append({'PostID': post.id, 'Content': post.content, 'User': post.user.name,
|
|
||||||
# 'Date': post.date.strftime('%d-%b-%Y %H:%M'),
|
|
||||||
# 'CreationDate': post.creation_date.strftime('%d-%b-%Y %H:%M')})
|
|
||||||
threads.append(thread)
|
threads.append(thread)
|
||||||
thread['LastUpdated'] = get_age(last_updated)
|
return {'Tags': tags, 'Threads': threads, 'Type': type}
|
||||||
return {'Tags': tags, 'Threads': threads}
|
|
||||||
|
|
||||||
|
|
||||||
def thread_info(id):
|
def thread_info(id):
|
||||||
|
|
Loading…
Reference in New Issue