Skip to content

Commit

Permalink
Added UI for the following/unfollowing of groups
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmartin committed Oct 26, 2012
1 parent bc3ac6a commit beb1542
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 31 deletions.
1 change: 1 addition & 0 deletions ckan/config/routing.py
Expand Up @@ -241,6 +241,7 @@ def make_map():
'followers',
'follow',
'unfollow',
'admins',
]))
)
m.connect('group_read', '/group/{id}', action='read')
Expand Down
17 changes: 15 additions & 2 deletions ckan/controllers/group.py
Expand Up @@ -129,8 +129,6 @@ def read(self, id):
_("Cannot render description")
c.description_formatted = genshi.HTML(error_msg)

c.group_admins = self.authorizer.get_admins(c.group)

context['return_query'] = True

limit = 20
Expand Down Expand Up @@ -548,6 +546,21 @@ def followers(self, id=None):

return render('group/followers.html')

def admins(self, id=None):
context = {'model': model, 'session': model.Session,
'user': c.user or c.author,
'for_view': True}
data_dict = {'id': id}
try:
c.group_dict = get_action('group_show')(context, data_dict)
c.admins = self.authorizer.get_admins(context['group'])
except NotFound:
abort(404, _('Group not found'))
except NotAuthorized:
abort(401, _('Unauthorized to read group %s') % id)

return render('group/admins.html')

def _render_edit_form(self, fs):
# errors arrive in c.error and fs.errors
c.fieldset = fs
Expand Down
7 changes: 5 additions & 2 deletions ckan/lib/activity_streams.py
Expand Up @@ -32,7 +32,10 @@ def get_snippet_tag(activity, detail):
return h.tag_link(detail['data']['tag'])

def get_snippet_group(activity, detail):
return h.group_link(activity['data']['group'])
link = h.group_link(activity['data']['group'])
return literal('''<span data-module="popover-context" data-module-type="group" data-module-id="%s">%s</span>'''
% (activity['object_id'], link)
)

def get_snippet_extra(activity, detail):
return '"%s"' % detail['data']['package_extra']['key']
Expand Down Expand Up @@ -176,7 +179,7 @@ def activity_stream_string_new_related_item():
'deleted related item': 'picture',
'follow dataset': 'sitemap',
'follow user': 'user',
'follow group': 'groups',
'follow group': 'group',
'new related item': 'picture',
}

Expand Down
4 changes: 2 additions & 2 deletions ckan/lib/helpers.py
Expand Up @@ -887,7 +887,7 @@ def tag_link(tag):

def group_link(group):
url = url_for(controller='group', action='read', id=group['name'])
return link_to(group['name'], url)
return link_to(group['title'], url)


def dump_json(obj, **kw):
Expand Down Expand Up @@ -963,7 +963,7 @@ def process_names(items):
return items

# these are the types of objects that can be followed
_follow_objects = ['dataset', 'user']
_follow_objects = ['dataset', 'user', 'group']


def follow_button(obj_type, obj_id):
Expand Down
18 changes: 15 additions & 3 deletions ckan/public/base/javascript/modules/popover-context.js
Expand Up @@ -21,11 +21,13 @@
window.popover_context = {
dict: {
user: {},
dataset: {}
dataset: {},
group: {}
},
render: {
user: {},
dataset: {}
dataset: {},
group: {}
}
};

Expand Down Expand Up @@ -119,7 +121,10 @@ this.ckan.module('popover-context', function($, _) {
var type = this.options.type;
if (typeof window.popover_context.dict[type][id] == 'undefined') {
var client = this.sandbox.client;
var endpoint = ( type == 'user' ) ? 'user_show' : 'package_show';
var endpoint = type + '_show';
if (type == 'dataset') {
endpoint = 'package_show';
}
client.call('GET', endpoint, '?id=' + id, this._onHandleData, this._onHandleError);
} else {
this._onHandleData(window.popover_context.dict[type][id]);
Expand Down Expand Up @@ -180,6 +185,13 @@ this.ckan.module('popover-context', function($, _) {
params.notes = raw.notes;
params.num_resources = raw.resources.length;
params.num_tags = raw.tags.length;
} else if (type == 'group') {
params.id = raw.id;
params.title = raw.title;
params.name = raw.name;
params.description = raw.description;
params.num_datasets = raw.packages.length;
//params.num_followers = raw.num_followers;
}
return params;
},
Expand Down
1 change: 1 addition & 0 deletions ckan/public/base/javascript/resource.config
Expand Up @@ -31,6 +31,7 @@ ckan =
modules/data-viewer.js
modules/resource-form.js
modules/resource-upload-field.js
modules/follow.js
modules/popover-context.js

main =
Expand Down
1 change: 1 addition & 0 deletions ckan/public/base/less/activity.less
Expand Up @@ -77,4 +77,5 @@
&.follow-dataset i { background-color: @activityColorNeutral; }
&.follow-user i { background-color: spin(@activityColorNeutral, 20); }
&.new-related-item i { background-color: spin(@activityColorNew, -60); }
&.follow-group i { background-color: spin(@activityColorNew, -50); }
}
1 change: 0 additions & 1 deletion ckan/public/base/less/ckan.less
Expand Up @@ -14,7 +14,6 @@
@import "masthead.less";
@import "footer.less";
@import "profile.less";
@import "disqus.less";
@import "activity.less";
@import "popover-context.less";
@import "follower-list.less";
Expand Down
24 changes: 24 additions & 0 deletions ckan/templates/ajax_snippets/popover-context-group.html
@@ -0,0 +1,24 @@
<div class="popover-context profile-info">
{% if notes != 'null' %}
<p class="about">
{{ h.truncate(description, length=160, whole_word=True) }}
</p>
{% endif %}
<div class="btn-group">
{{ h.follow_button('group', id) }}
<a href="{{ h.url_for(controller='group', action='read', id=name) }}" class="btn">
<i class="icon-eye-open"></i>
View Group
</a>
</div>
<div class="nums">
<dl>
<dt>{{ _('Followers') }}</dt>
<dd>{{ num_followers }}</dd>
</dl>
<dl>
<dt>{{ _('Datasets') }}</dt>
<dd>{{ num_datasets }}</dd>
</dl>
</div>
</div>
10 changes: 10 additions & 0 deletions ckan/templates/group/admins.html
@@ -0,0 +1,10 @@
{% extends "group/read.html" %}

{% block subtitle %}{{ _('Administrators') }} - {{ c.group_dict.title or c.group_dict.name }}{% endblock %}

{% block primary_content_inner %}
<section class="module-content">
<h1 class="hide-heading">{{ _('Administrators') }}</h1>
{% snippet "user/snippets/followers.html", followers=c.admins %}
</section>
{% endblock %}
4 changes: 2 additions & 2 deletions ckan/templates/group/followers.html
@@ -1,8 +1,8 @@
{% extends "page.html" %}
{% extends "group/read.html" %}

{% block subtitle %}{{ _('Followers') }} - {{ c.group_dict.title or c.group_dict.name }}{% endblock %}

{% block primary_content %}
{% block primary_content_inner %}
<section class="module-content">
<h1 class="hide-heading">{{ _('Followers') }}</h1>
{% snippet "user/snippets/followers.html", followers=c.followers %}
Expand Down
70 changes: 53 additions & 17 deletions ckan/templates/group/read.html
Expand Up @@ -8,33 +8,69 @@
{% endblock %}

{% block actions_content %}
{% if h.check_access('group_update', {'id': c.group.id}) %}
{% if h.check_access('group_update', {'id': c.group_dict.id}) %}
<li>{% link_for _('Add Dataset to Group'), controller='package', action='new', group=c.group_dict.id, class_='btn', icon='plus' %}</li>
<li>{% link_for _('Edit'), controller='group', action='edit', id=c.group_dict.name, class_='btn', icon='cog' %}</li>
<li>{% link_for _('Edit'), controller='group', action='edit', id=c.group_dict.name, class_='btn', icon='wrench' %}</li>
{% endif %}
{# <li>{% link_for _('History'), controller='group', action='history', id=c.group_dict.name, class_='btn', icon='undo' %}</li> #}
<li>{{ h.follow_button('group', c.group_dict.id) }}</li>
{% endblock %}

{% block primary_content %}
<section class="module">
<div class="module-content">
{% include "package/snippets/search_form.html" %}
</div>
{{ c.page.pager(q=c.q) }}
{% block package_header %}
<header class="module-content page-header">
<ul class="nav nav-tabs">
<li{% if c.action == 'read' %} class="active"{% endif %}>
{% link_for _('Datasets'), controller='group', action='read', id=c.group_dict.name, icon='sitemap' %}
</li>
<li{% if c.action == 'followers' %} class="active"{% endif %}>
{% link_for _('Followers'), controller='group', action='followers', id=c.group_dict.name, icon='group' %}
</li>
<li{% if c.action == 'admins' %} class="active"{% endif %}>
{% link_for _('Administrators'), controller='group', action='admins', id=c.group_dict.name, icon='cog' %}
</li>
</ul>
</header>
{% endblock %}
{% block primary_content_inner %}
<div class="module-content">
{% include "package/snippets/search_form.html" %}
</div>
{{ c.page.pager(q=c.q) }}
{% endblock %}
</section>
{% endblock %}

{% block secondary_content %}
{% snippet 'snippets/group.html', group=c.group_dict %}

<section class="module module-narrow module-shallow">
<h2 class="module-heading"><i class="icon-large icon-user"></i> {{ _('Administrators') }}</h2>
<ul class="nav nav-simple">
{% for admin in c.group_admins %}
<li class="nav-item image">{{ h.linked_user(admin, 30) }}</li>
{% endfor %}
</ul>
</section>
<div class="module profile-info">
<section class="module-content">
<div class="avatar">
<a href="{{ c.group_dict.url }}">
<img src="{{ c.group_dict.image_url or h.url_for_static('/base/images/placeholder-group.png') }}" width="200" height="125" alt="{{ c.group_dict.name }}" />
</a>
</div>
<h1 class="heading">{{ c.group_dict.display_name }}</h1>
{% if c.group_dict.description %}
{% if truncate %}
<p>{{ c.group_dict.description }}</p>
{% else %}
<p>{{ h.markdown_extract(c.group_dict.description, truncate) }}</p>
{% endif %}
{% else %}
<p class="empty">{{ _('There is no description for this group') }}</p>
{% endif %}
<div class="nums">
<dl>
<dt>{{ _('Followers') }}</dt>
<dd>{{ c.group_dict.num_followers }}</dd>
</dl>
<dl>
<dt>{{ _('Datasets') }}</dt>
<dd>{{ c.group_dict.packages|length }}</dd>
</dl>
</div>
</section>
</div>

{{ h.snippet('snippets/facet_list.html', title='Tags', name='tags', extras={'id':c.group_dict.id}) }}
{{ h.snippet('snippets/facet_list.html', title='Formats', name='res_format', extras={'id':c.group_dict.id}) }}
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates/user/read.html
Expand Up @@ -74,11 +74,11 @@ <h1 class="heading">{{ user.fullname or _('No full name provided') }}</h1>
</p>
{% endif %}
<div class="nums">
<dl href="{{ h.url_for(controller='user', action='followers', id=user.name) }}">
<dl>
<dt>{{ _('Followers') }}</dt>
<dd>{{ user.num_followers }}</dd>
</dl>
<dl href="{{ h.url_for(controller='user', action='read', id=user.name) }}">
<dl>
<dt>{{ _('Datasets') }}</dt>
<dd>{{ user.number_administered_packages }}</dd>
</dl>
Expand Down

0 comments on commit beb1542

Please sign in to comment.