Commit ffddd12f18e6bb28cec8dc560cf448b1b8849e20

Authored by Alexandre Barbosa
2 parents 2d01f6b8 2308a550
Exists in master and in 66 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_for_sisp, register_page, release-process-v2, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_dev_master, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_to_rails4, stable-4.1, stable-4.2, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_softwares_boxes

Merge branch 'gitlab_view_spb' into 'master'

Gitlab view spb

See merge request !63
src/colab-spb-plugin/src/colab_spb/fixtures/__init__.py 0 → 100644
src/colab-spb-plugin/src/colab_spb/fixtures/colab_spb.json
... ... @@ -379,5 +379,35 @@
379 379 },
380 380 "model": "super_archives.emailaddress",
381 381 "pk": 1
  382 +},
  383 +{
  384 + "fields": {
  385 + "description": null,
  386 + "created_at": "2015-09-29T14:36:58Z",
  387 + "user": null,
  388 + "identifier": "example_community",
  389 + "categories": [],
  390 + "name": "example_community"
  391 + },
  392 + "model": "colab_noosfero.noosferocommunity",
  393 + "pk": 69
  394 +},
  395 +{
  396 + "fields": {
  397 + "path": "example_community",
  398 + "name": "example_community",
  399 + "owner_id": null
  400 + },
  401 + "model": "colab_gitlab.gitlabgroup",
  402 + "pk": 23
  403 +},
  404 +{
  405 + "fields": {
  406 + "mail_list": 1,
  407 + "group": 23,
  408 + "community": 69
  409 + },
  410 + "model": "colab_spb.communityassociations",
  411 + "pk": 2
382 412 }
383 413 ]
... ...
src/colab-spb-plugin/src/colab_spb/migrations/0001_initial.py
... ... @@ -8,7 +8,7 @@ class Migration(migrations.Migration):
8 8  
9 9 dependencies = [
10 10 ('colab_gitlab', '0001_initial'),
11   - ('colab_noosfero', '0001_initial'),
  11 + ('colab_noosfero', '__first__'),
12 12 ('super_archives', '0002_mailinglist_is_private'),
13 13 ]
14 14  
... ...
src/colab-spb-plugin/src/colab_spb/static/spb/js/jquery.timeago.js 0 → 100644
... ... @@ -0,0 +1,223 @@
  1 +/**
  2 + * Timeago is a jQuery plugin that makes it easy to support automatically
  3 + * updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago").
  4 + *
  5 + * @name timeago
  6 + * @version 1.4.2
  7 + * @requires jQuery v1.2.3+
  8 + * @author Ryan McGeary
  9 + * @license MIT License - http://www.opensource.org/licenses/mit-license.php
  10 + *
  11 + * For usage and examples, visit:
  12 + * http://timeago.yarp.com/
  13 + *
  14 + * Copyright (c) 2008-2015, Ryan McGeary (ryan -[at]- mcgeary [*dot*] org)
  15 + */
  16 +
  17 +(function (factory) {
  18 + if (typeof define === 'function' && define.amd) {
  19 + // AMD. Register as an anonymous module.
  20 + define(['jquery'], factory);
  21 + } if (typeof module === 'object' && typeof module.exports === 'object') {
  22 + factory(require('jquery'));
  23 + } else {
  24 + // Browser globals
  25 + factory(jQuery);
  26 + }
  27 +}(function ($) {
  28 + $.timeago = function(timestamp) {
  29 + if (timestamp instanceof Date) {
  30 + return inWords(timestamp);
  31 + } else if (typeof timestamp === "string") {
  32 + return inWords($.timeago.parse(timestamp));
  33 + } else if (typeof timestamp === "number") {
  34 + return inWords(new Date(timestamp));
  35 + } else {
  36 + return inWords($.timeago.datetime(timestamp));
  37 + }
  38 + };
  39 + var $t = $.timeago;
  40 +
  41 + $.extend($.timeago, {
  42 + settings: {
  43 + refreshMillis: 60000,
  44 + allowPast: true,
  45 + allowFuture: false,
  46 + localeTitle: false,
  47 + cutoff: 0,
  48 + strings: {
  49 + prefixAgo: null,
  50 + prefixFromNow: null,
  51 + suffixAgo: "ago",
  52 + suffixFromNow: "from now",
  53 + inPast: 'any moment now',
  54 + seconds: "less than a minute",
  55 + minute: "about a minute",
  56 + minutes: "%d minutes",
  57 + hour: "about an hour",
  58 + hours: "about %d hours",
  59 + day: "a day",
  60 + days: "%d days",
  61 + month: "about a month",
  62 + months: "%d months",
  63 + year: "about a year",
  64 + years: "%d years",
  65 + wordSeparator: " ",
  66 + numbers: []
  67 + }
  68 + },
  69 +
  70 + inWords: function(distanceMillis) {
  71 + if(!this.settings.allowPast && ! this.settings.allowFuture) {
  72 + throw 'timeago allowPast and allowFuture settings can not both be set to false.';
  73 + }
  74 +
  75 + var $l = this.settings.strings;
  76 + var prefix = $l.prefixAgo;
  77 + var suffix = $l.suffixAgo;
  78 + if (this.settings.allowFuture) {
  79 + if (distanceMillis < 0) {
  80 + prefix = $l.prefixFromNow;
  81 + suffix = $l.suffixFromNow;
  82 + }
  83 + }
  84 +
  85 + if(!this.settings.allowPast && distanceMillis >= 0) {
  86 + return this.settings.strings.inPast;
  87 + }
  88 +
  89 + var seconds = Math.abs(distanceMillis) / 1000;
  90 + var minutes = seconds / 60;
  91 + var hours = minutes / 60;
  92 + var days = hours / 24;
  93 + var years = days / 365;
  94 +
  95 + function substitute(stringOrFunction, number) {
  96 + var string = $.isFunction(stringOrFunction) ? stringOrFunction(number, distanceMillis) : stringOrFunction;
  97 + var value = ($l.numbers && $l.numbers[number]) || number;
  98 + return string.replace(/%d/i, value);
  99 + }
  100 +
  101 + var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
  102 + seconds < 90 && substitute($l.minute, 1) ||
  103 + minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
  104 + minutes < 90 && substitute($l.hour, 1) ||
  105 + hours < 24 && substitute($l.hours, Math.round(hours)) ||
  106 + hours < 42 && substitute($l.day, 1) ||
  107 + days < 30 && substitute($l.days, Math.round(days)) ||
  108 + days < 45 && substitute($l.month, 1) ||
  109 + days < 365 && substitute($l.months, Math.round(days / 30)) ||
  110 + years < 1.5 && substitute($l.year, 1) ||
  111 + substitute($l.years, Math.round(years));
  112 +
  113 + var separator = $l.wordSeparator || "";
  114 + if ($l.wordSeparator === undefined) { separator = " "; }
  115 + return $.trim([prefix, words, suffix].join(separator));
  116 + },
  117 +
  118 + parse: function(iso8601) {
  119 + var s = $.trim(iso8601);
  120 + s = s.replace(/\.\d+/,""); // remove milliseconds
  121 + s = s.replace(/-/,"/").replace(/-/,"/");
  122 + s = s.replace(/T/," ").replace(/Z/," UTC");
  123 + s = s.replace(/([\+\-]\d\d)\:?(\d\d)/," $1$2"); // -04:00 -> -0400
  124 + s = s.replace(/([\+\-]\d\d)$/," $100"); // +09 -> +0900
  125 + return new Date(s);
  126 + },
  127 + datetime: function(elem) {
  128 + var iso8601 = $t.isTime(elem) ? $(elem).attr("datetime") : $(elem).attr("title");
  129 + return $t.parse(iso8601);
  130 + },
  131 + isTime: function(elem) {
  132 + // jQuery's `is()` doesn't play well with HTML5 in IE
  133 + return $(elem).get(0).tagName.toLowerCase() === "time"; // $(elem).is("time");
  134 + }
  135 + });
  136 +
  137 + // functions that can be called via $(el).timeago('action')
  138 + // init is default when no action is given
  139 + // functions are called with context of a single element
  140 + var functions = {
  141 + init: function(){
  142 + var refresh_el = $.proxy(refresh, this);
  143 + refresh_el();
  144 + var $s = $t.settings;
  145 + if ($s.refreshMillis > 0) {
  146 + this._timeagoInterval = setInterval(refresh_el, $s.refreshMillis);
  147 + }
  148 + },
  149 + update: function(time){
  150 + var parsedTime = $t.parse(time);
  151 + $(this).data('timeago', { datetime: parsedTime });
  152 + if($t.settings.localeTitle) $(this).attr("title", parsedTime.toLocaleString());
  153 + refresh.apply(this);
  154 + },
  155 + updateFromDOM: function(){
  156 + $(this).data('timeago', { datetime: $t.parse( $t.isTime(this) ? $(this).attr("datetime") : $(this).attr("title") ) });
  157 + refresh.apply(this);
  158 + },
  159 + dispose: function () {
  160 + if (this._timeagoInterval) {
  161 + window.clearInterval(this._timeagoInterval);
  162 + this._timeagoInterval = null;
  163 + }
  164 + }
  165 + };
  166 +
  167 + $.fn.timeago = function(action, options) {
  168 + var fn = action ? functions[action] : functions.init;
  169 + if(!fn){
  170 + throw new Error("Unknown function name '"+ action +"' for timeago");
  171 + }
  172 + // each over objects here and call the requested function
  173 + this.each(function(){
  174 + fn.call(this, options);
  175 + });
  176 + return this;
  177 + };
  178 +
  179 + function refresh() {
  180 + //check if it's still visible
  181 + if(!$.contains(document.documentElement,this)){
  182 + //stop if it has been removed
  183 + $(this).timeago("dispose");
  184 + return this;
  185 + }
  186 +
  187 + var data = prepareData(this);
  188 + var $s = $t.settings;
  189 +
  190 + if (!isNaN(data.datetime)) {
  191 + if ( $s.cutoff == 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
  192 + $(this).text(inWords(data.datetime));
  193 + }
  194 + }
  195 + return this;
  196 + }
  197 +
  198 + function prepareData(element) {
  199 + element = $(element);
  200 + if (!element.data("timeago")) {
  201 + element.data("timeago", { datetime: $t.datetime(element) });
  202 + var text = $.trim(element.text());
  203 + if ($t.settings.localeTitle) {
  204 + element.attr("title", element.data('timeago').datetime.toLocaleString());
  205 + } else if (text.length > 0 && !($t.isTime(element) && element.attr("title"))) {
  206 + element.attr("title", text);
  207 + }
  208 + }
  209 + return element.data("timeago");
  210 + }
  211 +
  212 + function inWords(date) {
  213 + return $t.inWords(distance(date));
  214 + }
  215 +
  216 + function distance(date) {
  217 + return (new Date().getTime() - date.getTime());
  218 + }
  219 +
  220 + // fix for IE6 suckage
  221 + document.createElement("abbr");
  222 + document.createElement("time");
  223 +}));
... ...
src/colab-spb-plugin/src/colab_spb/templates/gitlab_activity.html 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +
  2 +{% load i18n %}
  3 +
  4 +<script type='text/javascript' src='/static/spb/js/jquery-2.0.3.min.js'></script>
  5 +<script type='text/javascript' src='/static/spb/js/jquery.timeago.js'></script>
  6 +
  7 +<div id='spb_content_gitlab_activity'>
  8 + {{message}}
  9 +</div>
  10 +
  11 +<script type='text/javascript'>
  12 + var $tag = $('#spb_content_gitlab_activity');
  13 +
  14 + {% if community_association %}
  15 +
  16 + $.getJSON("{{community_association.repository}}",{limit: {{community_association.limit}}, offset: {{community_association.offset}}},function(msg, e){
  17 + $tag.html(msg.html);
  18 + $tag.append("<div class=\"see-more-repository\">" +
  19 + "<a href={{community_association.repository}}>" +
  20 + "veja toda a atividade no repositório" +
  21 + "</a></div>");
  22 + });
  23 + {% endif %}
  24 +</script>
  25 +
... ...
src/colab-spb-plugin/src/colab_spb/urls.py
... ... @@ -2,4 +2,6 @@ from django.conf.urls import patterns, url
2 2 from . import views
3 3  
4 4 urlpatterns = patterns('',
5   - url(r'^get_list/$', views.get_list, name='get_list'),)
  5 + url(r'^mail_list/$', views.mail_list, name='mail_list'),
  6 + url(r'^gitlab_activity/$', views.gitlab_activity,
  7 + name='gitlab_activity'),)
... ...
src/colab-spb-plugin/src/colab_spb/views.py
... ... @@ -4,13 +4,15 @@ from django.http import HttpResponse
4 4 from colab.super_archives.models import MailingList, Thread
5 5 from colab.accounts.utils import mailman
6 6 from colab.accounts.models import User
  7 +from colab_spb.models import CommunityAssociations
7 8  
8 9  
9   -def get_list(request):
10   - list_name = request.GET.get('list_name', None)
11   - MAX = request.GET.get('MAX', 7)
  10 +def mail_list(request):
  11 + community = request.GET.get('community', "")
  12 + list_name = get_community_association(community).get("mailman_list", "")
12 13  
13   - if not MAX:
  14 + MAX = request.GET.get('MAX', 7)
  15 + if not MAX or MAX < 0:
14 16 MAX = 7
15 17  
16 18 context = {}
... ... @@ -44,6 +46,37 @@ def get_list(request):
44 46 message = ("Não foi possível encontrada lista de discussão"
45 47 " associada a está comunidade, para mais"
46 48 " detalhes contate o administrador.")
47   - return HttpResponse(message, status=404)
  49 + return HttpResponse(message, status=200)
  50 +
  51 + return render(request, 'discussion.html', context)
  52 +
  53 +
  54 +def gitlab_activity(request):
  55 + community = request.GET.get('community', "")
  56 + limit = request.GET.get('limit', 7)
  57 + offset = request.GET.get('offset', 0)
  58 +
  59 + context = {}
  60 + context['message'] = ("Esta comunidade não está associada a"
  61 + " nenhum repositório no momento, para mais"
  62 + " detalhes contate o administrador.")
  63 +
  64 + association = get_community_association(community, limit, offset)
  65 + context['community_association'] = association
  66 +
  67 + return render(request, 'gitlab_activity.html', context)
  68 +
  69 +
  70 +def get_community_association(community, limit=7, offset=0):
  71 + if not community:
  72 + return {}
48 73  
49   - return render(request, "discussion.html", context)
  74 + association = CommunityAssociations.objects.filter(
  75 + community__identifier=community).first()
  76 + if association:
  77 + return {'community': association.community.identifier,
  78 + 'repository': association.group.url,
  79 + 'mailman_list': association.mail_list.name,
  80 + 'limit': limit,
  81 + 'offset': offset}
  82 + return {}
... ...
src/colab-spb-plugin/tests/plugins.d/gitlab.py
... ... @@ -10,7 +10,7 @@ name = &#39;colab_gitlab&#39;
10 10 verbose_name = 'Gitlab Plugin'
11 11  
12 12 upstream = 'localhost'
13   -#middlewares = []
  13 +# middlewares = []
14 14  
15 15 urls = {
16 16 'include': 'colab_gitlab.urls',
... ...
src/colab-spb-plugin/tests/plugins.d/noosfero.py
... ... @@ -10,7 +10,7 @@ name = &#39;colab_noosfero&#39;
10 10 verbose_name = 'Noosfero Plugin'
11 11  
12 12 upstream = 'localhost'
13   -#middlewares = []
  13 +# middlewares = []
14 14  
15 15 urls = {
16 16 'include': 'colab_noosfero.urls',
... ...
src/colab-spb-plugin/tests/plugins.d/spb.py
1   -from django.utils.translation import ugettext_lazy as _
2   -from colab.plugins.utils.menu import colab_url_factory
3   -
  1 +from colab.plugins.utils.menu import colab_url_factory
  2 +
4 3 name = "colab_spb"
5 4 verbose_name = "SPB Plugin"
6 5  
7 6 middlewares = ['colab_spb.middleware.ForceLangMiddleware']
8 7  
9   -urls = {
10   - "include":"colab_spb.urls",
11   - "prefix": '^spb/',
12   - "namespace":"colab_spb"
13   - }
  8 +urls = {"include": "colab_spb.urls",
  9 + "prefix": '^spb/',
  10 + "namespace": "colab_spb"}
14 11  
15 12 url = colab_url_factory('colab_spb')
... ...
src/colab-spb-plugin/tests/test_colab_integration.py 0 → 100644
... ... @@ -0,0 +1,80 @@
  1 +# -*- coding: utf-8 -*-
  2 +
  3 +from django.test import TestCase, Client
  4 +
  5 +
  6 +class SPBTest(TestCase):
  7 +
  8 + fixtures = ['colab_spb.json']
  9 +
  10 + def setUp(self):
  11 + super(SPBTest, self).setUp()
  12 + self.client = Client()
  13 +
  14 + def tearDown(self):
  15 + pass
  16 +
  17 + def test_mail_list_without_list(self):
  18 + response = self.client.get("/spb/mail_list/?community=")
  19 + message = ("Não foi possível encontrada lista de discussão"
  20 + " associada a está comunidade, para mais"
  21 + " detalhes contate o administrador.")
  22 + self.assertEqual(message, response.content)
  23 + self.assertEqual(200, response.status_code)
  24 +
  25 + def test_mail_list_with_list(self):
  26 + response = self.client.get("/spb/mail_list/"
  27 + "?community=example_community&MAX=5")
  28 + self.assertEqual(5, len(response.context[1]['latest']))
  29 +
  30 + def test_mail_list_default_MAX(self):
  31 + response = self.client.get("/spb/mail_list/"
  32 + "?community=example_community")
  33 + self.assertEqual(7, len(response.context[1]['latest']))
  34 +
  35 + def test_mail_list_invalid_MAX(self):
  36 + response = self.client.get("/spb/mail_list/"
  37 + "?community=example_community&MAX=")
  38 + self.assertEqual(7, len(response.context[1]['latest']))
  39 +
  40 + def test_gitlab_community_association_with_invalid_community(self):
  41 + response = self.client.get("/spb/gitlab_activity/?community=")
  42 + message = ("Esta comunidade não está associada a"
  43 + " nenhum repositório no momento, para mais"
  44 + " detalhes contate o administrador.")
  45 + self.assertIn(message, response.content)
  46 + self.assertEqual(dict(), response.context['community_association'])
  47 + self.assertEqual(200, response.status_code)
  48 +
  49 + def test_gitlab_community_association_with_valid_community(self):
  50 + response = self.client.get("/spb/gitlab_activity/"
  51 + "?community=example_community")
  52 +
  53 + result = response.context['community_association']
  54 +
  55 + self.assertEqual(type(result), dict)
  56 + self.assertEqual(result['community'], 'example_community')
  57 + self.assertEqual(result['limit'], 7)
  58 + self.assertEqual(result['offset'], 0)
  59 + self.assertEqual(result['repository'],
  60 + '/gitlab/groups/example_community')
  61 + self.assertEqual(result['mailman_list'], 'ListA')
  62 +
  63 + def test_gitlab_community_association_with_no_default_limit(self):
  64 + response = self.client.get("/spb/gitlab_activity/"
  65 + "?community=example_community"
  66 + "&limit=5")
  67 +
  68 + result = response.context['community_association']
  69 +
  70 + self.assertEqual(type(result), dict)
  71 + self.assertEqual(result['limit'], "5")
  72 +
  73 + def test_gitlab_community_association_with_no_default_offset(self):
  74 + response = self.client.get("/spb/gitlab_activity/"
  75 + "?community=example_community"
  76 + "&offset=5")
  77 +
  78 + result = response.context['community_association']
  79 +
  80 + self.assertEqual(result['offset'], "5")
... ...
src/colab-spb-plugin/tests/test_get_list.py
... ... @@ -1,34 +0,0 @@
1   -# -*- coding: utf-8 -*-
2   -from django.test import TestCase, Client
3   -
4   -
5   -class SPBTest(TestCase):
6   -
7   - fixtures = ['colab_spb.json']
8   -
9   - def setUp(self):
10   - super(SPBTest, self).setUp()
11   - self.client = Client()
12   -
13   - def tearDown(self):
14   - pass
15   -
16   - def test_getlist_without_list(self):
17   - response = self.client.get("/spb/get_list/?list_name=")
18   - message = ("Não foi possível encontrada lista de discussão"
19   - " associada a está comunidade, para mais"
20   - " detalhes contate o administrador.")
21   - self.assertEqual(message, response.content)
22   - self.assertEqual(404, response.status_code)
23   -
24   - def test_getlist_with_list(self):
25   - response = self.client.get("/spb/get_list/?list_name=ListA&MAX=5")
26   - self.assertEqual(5, len(response.context[1]['latest']))
27   -
28   - def test_getlist_default_MAX(self):
29   - response = self.client.get("/spb/get_list/?list_name=ListA")
30   - self.assertEqual(7, len(response.context[1]['latest']))
31   -
32   - def test_getlist_invalid_MAX(self):
33   - response = self.client.get("/spb/get_list/?list_name=ListA&MAX=")
34   - self.assertEqual(7, len(response.context[1]['latest']))