From 2c317a880f392693d1d4ee64cd76d526c9692ac6 Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Dec 04 2017 11:15:48 +0000 Subject: [PATCH 1/4] remove placekittin from model, update populate.py Removes the automatic setting of a placekitten URL from the model, and update populate.py so one has a placekitten url, the rest are blank. Signed-off-by: Ryan Lerch --- diff --git a/hubs/models.py b/hubs/models.py index 49abbb8..023db77 100644 --- a/hubs/models.py +++ b/hubs/models.py @@ -70,9 +70,6 @@ BASE = declarative_base(cls=HubsBase) log = logging.getLogger(__name__) -placekitten = "https://placekitten.com/g/320/320" - - def randomheader(): location = '/static/img/headers/' header_dir = os.path.dirname(__file__) + location @@ -358,7 +355,7 @@ class HubConfig(BASE): summary = sa.Column(sa.String(128)) left_width = sa.Column(sa.Integer, nullable=False, default=8) # A URL to the "avatar" for this hub. - avatar = sa.Column(sa.String(256), default=placekitten) + avatar = sa.Column(sa.String(256), default="") header_img = sa.Column(sa.String(256), default=randomheader) chat_channel = sa.Column(sa.String(256), nullable=True) chat_domain = sa.Column(sa.String(256), nullable=True) diff --git a/populate.py b/populate.py index f3cea45..87efc8f 100755 --- a/populate.py +++ b/populate.py @@ -14,14 +14,15 @@ fedmsg_config = get_fedmsg_config() session = hubs.models.init(fedmsg_config['hubs.sqlalchemy.uri'], True, True) +placekitten = "https://placekitten.com/g/320/320" + # Register widgets we will use hubs.widgets.registry.register_list([ - "hubs.widgets.contact:Contact", "hubs.widgets.rules:Rules", "hubs.widgets.meetings:Meetings", "hubs.widgets.about:About", "hubs.widgets.sticky:Sticky", - "hubs.widgets.dummy:Dummy", + "hubs.widgets.feed:Feed", ]) users = ['mrichard', 'duffy', 'ryanlerch', 'gnokii', 'nask0', @@ -39,10 +40,8 @@ session.commit() hub = hubs.models.Hub(name='i18n', archived=True) session.add(hub) session.add(hubs.models.HubConfig( - hub=hub, summary='The Internationalization Team')) + hub=hub, summary='The Internationalization Team', avatar=placekitten)) -widget = hubs.models.Widget(plugin='contact', index=0) -hub.widgets.append(widget) widget = hubs.models.Widget( plugin='rules', index=1, _config=json.dumps({ 'link': 'https://fedoraproject.org/wiki/I18N', @@ -78,7 +77,7 @@ infrastructure of the Fedora Localization Project """, })) hub.widgets.append(widget) -widget = hubs.models.Widget(plugin='dummy', index=2, left=True) +widget = hubs.models.Widget(plugin='feed', index=2, left=True) hub.widgets.append(widget) @@ -96,8 +95,6 @@ session.add(hub) session.add(hubs.models.HubConfig( hub=hub, summary='The Fedora Community Operations Team')) -widget = hubs.models.Widget(plugin='contact', index=0) -hub.widgets.append(widget) widget = hubs.models.Widget( plugin='rules', index=1, _config=json.dumps({ 'link': 'https://fedoraproject.org/wiki/CommOps', @@ -128,7 +125,7 @@ widget = hubs.models.Widget( "communities that build things.'", })) hub.widgets.append(widget) -widget = hubs.models.Widget(plugin='dummy', index=2, left=True) +widget = hubs.models.Widget(plugin='feed', index=2, left=True) hub.widgets.append(widget) @@ -148,8 +145,6 @@ session.add(hub) session.add(hubs.models.HubConfig( hub=hub, summary='The Fedora Marketing Team')) -widget = hubs.models.Widget(plugin='contact', index=0) -hub.widgets.append(widget) widget = hubs.models.Widget( plugin='rules', index=1, _config=json.dumps({ 'link': 'https://fedoraproject.org/wiki/Marketing', @@ -186,7 +181,7 @@ Fedora Project to interact directly with its existing and prospective users. """, })) hub.widgets.append(widget) -widget = hubs.models.Widget(plugin='dummy', index=2, left=True) +widget = hubs.models.Widget(plugin='feed', index=2, left=True) hub.widgets.append(widget) @@ -207,8 +202,6 @@ session.add(hub) session.add(hubs.models.HubConfig( hub=hub, summary='The Fedora Design Team')) -widget = hubs.models.Widget(plugin='contact', index=0) -hub.widgets.append(widget) widget = hubs.models.Widget( plugin='rules', index=1, _config=json.dumps({ 'link': 'https://fedoraproject.org/wiki/Design', @@ -241,7 +234,7 @@ advocating the use of the creative tools that are a part of Fedora. """, })) hub.widgets.append(widget) -widget = hubs.models.Widget(plugin='dummy', index=2, left=True) +widget = hubs.models.Widget(plugin='feed', index=2, left=True) hub.widgets.append(widget) @@ -263,8 +256,6 @@ session.add(hub) session.add(hubs.models.HubConfig( hub=hub, summary='The Fedora Infra Team')) -widget = hubs.models.Widget(plugin='contact', index=0) -hub.widgets.append(widget) widget = hubs.models.Widget( plugin='rules', index=1, _config=json.dumps({ 'link': 'https://fedoraproject.org/wiki/Infrastructure', @@ -299,7 +290,7 @@ over the globe and communicate primarily by IRC and e-mail. """, })) hub.widgets.append(widget) -widget = hubs.models.Widget(plugin='dummy', index=3, left=True) +widget = hubs.models.Widget(plugin='feed', index=3, left=True) hub.widgets.append(widget) vc = hubs.models.VisitCounter().get_or_create(session, 'ralph', 'mrichard') From a49c25dfde86a689615ea34a51beee7bea990db5 Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Dec 04 2017 12:01:20 +0000 Subject: [PATCH 2/4] make myhubs widget use either the avatar URL or the monogram Previously, the myhubs widget used only the monogram, not the user-selectable avatar URL in the config. This abstracts out the monogram creation code into a utils method that is also used as a filter in jinja, and shows the avatar image if it is set. Signed-off-by: Ryan Lerch --- diff --git a/hubs/app.py b/hubs/app.py index 56173d1..52512ef 100644 --- a/hubs/app.py +++ b/hubs/app.py @@ -10,7 +10,7 @@ import munch from flask_oidc import OpenIDConnect import hubs.models -from hubs.utils import get_fedmsg_config, username2avatar +from hubs.utils import get_fedmsg_config, username2avatar, hub2groupavatar app = flask.Flask(__name__) @@ -22,6 +22,8 @@ def days_since(then): app.template_filter('days_since')(days_since) app.template_filter('avatar')(username2avatar) +app.template_filter('hub2groupavatar')(hub2groupavatar) + logging.basicConfig() diff --git a/hubs/static/css/style.css b/hubs/static/css/style.css index 19fd9f2..dae5273 100644 --- a/hubs/static/css/style.css +++ b/hubs/static/css/style.css @@ -392,10 +392,10 @@ header h5.m-b-1 { } .monogram-avatar{ - width:64px; - height:64px; + width:60px; + height:60px; font-size:54px; - line-height: 64px; + line-height: 58px; font-weight: 700; text-align: center; } diff --git a/hubs/tests/widgets/test_my_hubs.py b/hubs/tests/widgets/test_my_hubs.py index 3c249d9..3041250 100644 --- a/hubs/tests/widgets/test_my_hubs.py +++ b/hubs/tests/widgets/test_my_hubs.py @@ -20,6 +20,8 @@ class MyHubsTest(WidgetTest): self.session.add(hubs.models.Hub(name="designteam")) hub = hubs.models.Hub.by_name('designteam') + self.session.add( + hubs.models.HubConfig(hub=hub, summary="the designteam team")) hub.subscribe(hubs.models.User.by_username('ralph'), 'member') def test_view_authz(self): diff --git a/hubs/utils/__init__.py b/hubs/utils/__init__.py index 26341d3..ed94362 100755 --- a/hubs/utils/__init__.py +++ b/hubs/utils/__init__.py @@ -37,3 +37,12 @@ def hubname2monogramcolour(hubname): colours = ["blue", "green", "magenta", "orange", "purple"] colour_index = int(md5(hubname.encode('utf8')).hexdigest(), 16) % 5 return colours[colour_index] + + +def hub2groupavatar(hub): + if hub.config.avatar != "": + return '' % (hub.config.avatar) + return ("
" + "%s
") % (hubname2monogramcolour(hub.name), + hubname2monogramcolour(hub.name), + hub.name[0].upper()) diff --git a/hubs/widgets/base.py b/hubs/widgets/base.py index 0155b0f..3e67205 100644 --- a/hubs/widgets/base.py +++ b/hubs/widgets/base.py @@ -10,6 +10,7 @@ from importlib import import_module from .caching import CachedFunction from .view import WidgetView from .parameters import WidgetParameter +from hubs.utils import hub2groupavatar log = logging.getLogger(__name__) @@ -136,6 +137,7 @@ class Widget(object): trim_blocks=True, ) env.filters['tojson'] = flask.json.tojson_filter + env.filters['hub2groupavatar'] = hub2groupavatar env.globals.update({ 'session': flask.app.session, 'g': flask.g, diff --git a/hubs/widgets/my_hubs/__init__.py b/hubs/widgets/my_hubs/__init__.py index d040753..96b9370 100644 --- a/hubs/widgets/my_hubs/__init__.py +++ b/hubs/widgets/my_hubs/__init__.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals import hubs.models -from hubs.utils import get_fedmsg_config, hubname2monogramcolour +from hubs.utils import get_fedmsg_config from hubs.widgets.base import Widget from hubs.widgets.view import RootWidgetView @@ -25,37 +25,25 @@ class BaseView(RootWidgetView): username = instance.hub.name user = hubs.models.User.by_username(username) - monograms = {} ownerships = [] assoc = [] for hub in user.ownerships: if not hub.user_hub: ownerships.append(hub) assoc.append(hub.name) - monograms[hub.name] = generate_monogram(hub.name) memberships = [] for hub in user.memberships: if not hub.user_hub: if hub.name not in assoc: memberships.append(hub) assoc.append(hub.name) - monograms[hub.name] = generate_monogram(hub.name) subscriptions = [] for hub in user.subscriptions: if not hub.user_hub: if hub.name not in assoc: subscriptions.append(hub) - monograms[hub.name] = generate_monogram(hub.name) return dict( ownerships=ownerships, memberships=memberships, subscriptions=subscriptions, - monograms=monograms, ) - - -def generate_monogram(hubname): - return ("
" - "%s
") % (hubname2monogramcolour(hubname), - hubname2monogramcolour(hubname), - hubname[0].upper()) diff --git a/hubs/widgets/my_hubs/templates/root.html b/hubs/widgets/my_hubs/templates/root.html index a1f4311..8f509a6 100644 --- a/hubs/widgets/my_hubs/templates/root.html +++ b/hubs/widgets/my_hubs/templates/root.html @@ -3,7 +3,7 @@ {% for ownership in ownerships %}
  • - {{monograms[ownership.name]}} + {{ownership|hub2groupavatar}}
    @@ -16,7 +16,7 @@ {% for membership in memberships %}
  • - {{monograms[membership.name]}} + {{membership|hub2groupavatar}}
    @@ -29,7 +29,7 @@ {% for subscription in subscriptions %}
  • - {{monograms[subscription.name]}} + {{subscription|hub2groupavatar}}
    From e9181f323336c6a0d3efef9b5cf61347996ed4bf Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Dec 04 2017 12:01:31 +0000 Subject: [PATCH 3/4] add avatar to group hubs, add star to user hubs Signed-off-by: Ryan Lerch --- diff --git a/hubs/static/client/app/components/HubHeader.css b/hubs/static/client/app/components/HubHeader.css index 384a99f..73ba27c 100644 --- a/hubs/static/client/app/components/HubHeader.css +++ b/hubs/static/client/app/components/HubHeader.css @@ -9,8 +9,9 @@ */ } -.HubHeader img.avatar { +.HubHeader .avatar { width: 70px; + height: 70px; float: left; margin-right: 15px; display: inline; diff --git a/hubs/static/client/app/components/HubHeader.js b/hubs/static/client/app/components/HubHeader.js index 8edb1db..fe1e2ee 100644 --- a/hubs/static/client/app/components/HubHeader.js +++ b/hubs/static/client/app/components/HubHeader.js @@ -7,11 +7,11 @@ import EditModeButton from './EditModeButton'; import HubStats from './HubStats'; import HubMembership from './HubMembership'; import HubStar from './HubStar'; +import { monogramColour } from '../core/utils'; import "./HubHeader.css"; class HubHeader extends React.Component { - render() { return (
    @@ -20,35 +20,30 @@ class HubHeader extends React.Component { } { this.props.hub.name &&
    -
    +
    - { this.props.hub.user_hub ?
    + { !this.props.hub.config.avatar ? +
    + {this.props.hub.name.charAt(0).toUpperCase()} +
    + : + }

    {this.props.hub.name} +

    {this.props.hub.config.summary}
    - : -
    - -

    - {this.props.hub.name} -

    -
    - {this.props.hub.config.summary} -
    -
    - }
    diff --git a/hubs/static/client/app/components/HubStar.css b/hubs/static/client/app/components/HubStar.css index 320ea4e..63a8d08 100644 --- a/hubs/static/client/app/components/HubStar.css +++ b/hubs/static/client/app/components/HubStar.css @@ -1,8 +1,7 @@ .HubStar { - position: absolute; - left: -1.2rem; line-height: 2rem; font-size: 1.2rem; - color: #000; + color: #aaa; z-index: 1; /* Above the left menu */ + vertical-align: middle; } diff --git a/hubs/static/client/app/components/HubStar.js b/hubs/static/client/app/components/HubStar.js index 1274727..6419a12 100644 --- a/hubs/static/client/app/components/HubStar.js +++ b/hubs/static/client/app/components/HubStar.js @@ -37,10 +37,6 @@ class HubStar extends React.Component { } render() { - if (!this.props.hub.name || this.props.hub.user_hub) { - // Only for team hubs - return null; - } const icon = this.isStarred() ? "star" : "star-o"; let otherProps = {} if (!this.props.currentUser.logged_in) { diff --git a/hubs/static/client/app/core/utils.js b/hubs/static/client/app/core/utils.js index f3ee5bd..9a44d56 100644 --- a/hubs/static/client/app/core/utils.js +++ b/hubs/static/client/app/core/utils.js @@ -1,5 +1,6 @@ import React from 'react'; import fetch from 'isomorphic-fetch'; +import md5 from 'js-md5'; import universal from 'react-universal-component' @@ -93,3 +94,9 @@ function makeSyncLoadable(loader) { } return SyncLoadable; } + +export function monogramColour(hubname) { + var colours = ["blue", "green", "magenta", "orange", "purple"] + var index = parseInt(md5(hubname).substring(0,4), 16) % 5; + return colours[index]; +} diff --git a/hubs/static/client/package.json b/hubs/static/client/package.json index fdb5d95..00402c6 100644 --- a/hubs/static/client/package.json +++ b/hubs/static/client/package.json @@ -9,6 +9,7 @@ "dependencies": { "babel-polyfill": "^6.26.0", "isomorphic-fetch": "^2.2.1", + "js-md5": "^0.7.2", "prop-types": "^15.5.10", "react": "^15.6.1", "react-autosuggest": "^9.3.2", diff --git a/hubs/utils/__init__.py b/hubs/utils/__init__.py index ed94362..4e5493b 100755 --- a/hubs/utils/__init__.py +++ b/hubs/utils/__init__.py @@ -35,7 +35,7 @@ def username2avatar(username, s=312): def hubname2monogramcolour(hubname): colours = ["blue", "green", "magenta", "orange", "purple"] - colour_index = int(md5(hubname.encode('utf8')).hexdigest(), 16) % 5 + colour_index = int(md5(hubname.encode('utf8')).hexdigest()[:4], 16) % 5 return colours[colour_index] From bbc163d09d88d48239cca4c0cb4debdb2a7b9ba2 Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Dec 04 2017 12:01:31 +0000 Subject: [PATCH 4/4] make hub avatars show in search if they are set Signed-off-by: Ryan Lerch --- diff --git a/hubs/static/js/search.js b/hubs/static/js/search.js index c6db7b3..f316c77 100644 --- a/hubs/static/js/search.js +++ b/hubs/static/js/search.js @@ -35,8 +35,8 @@ $(document).ready(function() { ].join('\n'), suggestion: function(datum) { output = '
    ' - if (datum.user_hub){ - output = output+'' + if (datum.config.avatar){ + output = output+'' } else { output = output+'
    '+datum.name.charAt(0).toUpperCase()+'
    ' }