Skip to content

Commit

Permalink
Merge pull request #414 from coopdevs/develop
Browse files Browse the repository at this point in the history
Release v1.8.0
  • Loading branch information
sauloperez authored Sep 4, 2018
2 parents 0277034 + f7e4537 commit 7e28ed9
Show file tree
Hide file tree
Showing 46 changed files with 383 additions and 145 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ GEM
net-ssh (>= 2.6.5)
net-ssh (2.9.2)
netrc (0.11.0)
nokogiri (1.8.2)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
parallel (1.12.1)
Expand Down
89 changes: 89 additions & 0 deletions app/assets/stylesheets/_to-member-card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
.to-member-card {
& {
margin: 16px 0;
width: 100%;
max-width: 600px;
height: 178px;
background-color: white;
box-shadow: 0 0 3px $palette-grey;
display: inline-block;

@media(max-width: $screen-sm-min) {
height: auto;
margin: 10px 0;
}
}

&__header {
& {
display: flex;
background-color: $palette-dark-turkey;
padding: 10px 20px;
}

&__avatar {
margin-right: 20px;
}

&__text {
h4 {
& {
margin: 4px 0 6px;
}

a {
color: white;
font-size: 18px;
}
}

&__activity {
font-size: 14px;
color: #78adb9;
font-size: 12px;
}
}
}

&__body {
& {
padding: 16px 20px;
}

&__description {
margin-bottom: 10px;
color: #666;
font-size: 15px;
height: 44px;

@media(max-width: $screen-sm-min) {
height: auto;
}
}

&__items {
display: flex;

@media(max-width: $screen-sm-min) {
display: block;
margin-bottom: 2px;
}
}

&__item {
& {
margin-right: 20px;
font-size: 14px;
color: grey;
}

a {
color: grey;
}

.glyphicon {
color: grey;
}
}
}
}
11 changes: 9 additions & 2 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import "bootstrap-sprockets";
@import "bootstrap-custom";
@import "to-categories-dropdown";
@import "to-member-card";
@import "footer";

html {
Expand Down Expand Up @@ -257,6 +258,11 @@ table.users {
h1 {
margin-bottom: 20px;
margin-top: 0;
font-size: 32px;

@media(max-width: $screen-sm-min) {
font-size: 26px;
}
}

img {
Expand Down Expand Up @@ -396,13 +402,14 @@ label[required]::after{

.login-wrapper {
position: absolute;
top: 20%;
top: 51%;
left: 0;
transform: translateY(-50%);
width: 100%;
z-index: 1;

@media(max-width: $screen-sm-min) {
top: 60px;
top: 47%;
}
}

Expand Down
20 changes: 14 additions & 6 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ class UsersController < ApplicationController
before_filter :authenticate_user!

def index
@search = current_organization.members.ransack(search_params)

@members =
@search.result.eager_load(:account, :user).page(params[:page]).per(25)
search_and_load_members current_organization.members.active
end

@member_view_models =
@members.map { |m| MemberDecorator.new(m, self.class.helpers) }
def manage
search_and_load_members current_organization.members
end

def show
Expand Down Expand Up @@ -59,6 +57,16 @@ def update

private

def search_and_load_members(members_scope)
@search = members_scope.ransack(search_params)

@members =
@search.result.eager_load(:account, :user).page(params[:page]).per(25)

@member_view_models =
@members.map { |m| MemberDecorator.new(m, self.class.helpers) }
end

def search_params
{s: 'member_uid asc'}.merge(params.fetch(:q, {}))
end
Expand Down
10 changes: 3 additions & 7 deletions app/decorators/member_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class MemberDecorator < ViewModel
delegate :user, :member_uid, :active?, to: :object
delegate :phone, :alt_phone, :username, to: :user
delegate :phone, :alt_phone, :username, :description, :last_sign_in_at, to: :user

def manager?
!!object.manager
Expand All @@ -23,18 +23,14 @@ def mail_to
view.mail_to(email) if email && !email.end_with?('example.com')
end

def avatar_img
view.image_tag(view.avatar_url(user, 32), width: 32, height: 32)
def avatar_img(size=32)
view.image_tag(view.avatar_url(user, size), width: size, height: size)
end

def account_balance
view.seconds_to_hm(object.account.try(:balance) || 0)
end

def edit_user_path
routes.edit_user_path(user)
end

def toggle_manager_member_path
routes.toggle_manager_member_path(object)
end
Expand Down
5 changes: 3 additions & 2 deletions app/helpers/glyph_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ module GlyphHelper
"organization" => "tower"
}

def glyph(kind)
def glyph(kind, title=nil)
kind = kind.to_s.underscore
content_tag :span, "",
class: "glyphicon glyphicon-#{glyph_name(kind)}"
class: "glyphicon glyphicon-#{glyph_name(kind)}",
title: title
end

private
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module UsersHelper
def phone_to(phone)
link_to phone, "tel://#{phone}"
end

def edit_user_path(user)
can_edit_user?(user) ? super : ""
end
Expand Down
19 changes: 17 additions & 2 deletions app/services/push_notifications/event_notifier/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,28 @@ def initialize(event:)
#
# @return [<DeviceToken>]
def device_tokens
organization = post.organization
DeviceToken.where(user_id: organization.user_ids)
DeviceToken.where(user_id: user_ids)
end

private

attr_accessor :event, :post

# Returns an ActiveRecord relation with the ids of the users
# that comply the following conditions:
#
# - they have an active membership
# - their `push_notification` flag is set to true
#
# @return <User::ActiveRecord_AssociationRelation>
def user_ids
post
.organization
.users
.select(:id)
.where('members.active = true')
.where('users.push_notifications = true')
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<b class="caret"></b>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<%= link_to manage_users_path do %>
<%= glyph :user %>
<%= t "application.navbar.users" %>
<% end %>
</li>
<li>
<%= link_to alpha_grouped_index_tags_path(post_type: "offer") do %>
<%= glyph :tags %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/shared/_post.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
<h3>
<%= t "global.contact_details" %>
</h3>
<% if post.user.email_if_real != "" %>
<% if post.user.has_valid_email? %>
<dt><%= User.human_attribute_name :email %></dt>
<dd><%= post.user.email_if_real %></dd>
<dd><%= post.user.email %></dd>
<% end %>
<% phones = [post.user.phone, post.user.alt_phone].select(&:present?) %>
<% if phones.present? %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_post_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= link_to post, class: "btn btn-warning" do %>
<%= link_to [:edit, post], class: "btn btn-warning" do %>
<%= glyph :pencil %>
<%= t "global.edit" %>
<% end %>
Expand Down
35 changes: 35 additions & 0 deletions app/views/users/_member_card.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="to-member-card">
<div class="to-member-card__header">
<div class="to-member-card__header__avatar"><%= member.avatar_img(48) %></div>
<div class="to-member-card__header__text">
<h4><%= member.link_to_self %></h4>
<div class="to-member-card__header__text__activity">
<%= "##{member.member_uid} — " %>
<% if member.last_sign_in_at %>
<%= t('.active_ago', time: distance_of_time_in_words(Time.now, member.last_sign_in_at)) %>
<% else %>
<%= t('.no_activity') %>
<% end %>
</div>
</div>
</div>
<div class="to-member-card__body">
<div class="to-member-card__body__description">
<%= member.description %>
</div>
<div class="to-member-card__body__items">
<div class="to-member-card__body__item">
<span class="glyphicon glyphicon-earphone"></span>
<%= phone_to member.phone %>
</div>
<div class="to-member-card__body__item">
<span class="glyphicon glyphicon-envelope"></span>
<%= member.mail_to %>
</div>
<div class="to-member-card__body__item">
<%= "Balance: " %>
<%= member.account_balance %>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/users/_toggle_manager_link.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
<%= glyph :arrow_up %>
<%= t 'global.promote' %>
<% end %>
<% end %>
<% end %>
8 changes: 1 addition & 7 deletions app/views/users/_user_rows.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@
<%= member.link_to_self %>
</td>
<td class="hidden-xs"> <%= member.mail_to %> </td>
<td class="hidden-xs hidden-sm"> <%= member.phone %> </td>
<td class="hidden-xs hidden-sm"> <%= member.alt_phone %> </td>
<td class="hidden-xs hidden-sm"> <%= phone_to member.phone %> </td>
<td class="hidden-xs hidden-sm"> <%= member.account_balance %> </td>
<% if current_user.manages?(current_organization) %>
<td class="hover-actions hidden-xs hidden-sm">
<%= link_to member.edit_user_path, class: "action" do %>
<%= glyph :pencil %>
<%= t "global.edit" %>
<% end %>

<% if member.active? %>
<%= render 'toggle_manager_link', member: member if can_toggle_manager?(member) %>
<% else %>
Expand Down
Loading

0 comments on commit 7e28ed9

Please sign in to comment.