-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
510 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class UserTagsController < ApplicationController | ||
TAGS_PER_PAGE = 100 | ||
|
||
before_action :authenticate_user!, only: [:attach, :detach] | ||
before_action :set_target_user, only: [:attach, :detach] | ||
|
||
layout 'users' | ||
|
||
def attach | ||
@user.tag_keyword(params[:name]) | ||
redirect_to home_path(@user.nick) | ||
end | ||
|
||
def detach | ||
if view_context.myself?(@user) | ||
tag = UserTag.find(params[:tag_id]) | ||
@user.detach(tag) if tag.present? | ||
end | ||
redirect_to home_path(@user.nick) | ||
end | ||
|
||
def index | ||
@tags = UserTag.page(params[:page]).per(TAGS_PER_PAGE) | ||
end | ||
|
||
def show | ||
@tag = UserTag.find(params[:id]) | ||
@members = @tag.users.page(params[:page]).per(UsersController::MEMBERS_PER_PAGE) | ||
end | ||
|
||
private | ||
|
||
def set_target_user | ||
@user = User.find_by(nick: params[:nick]) | ||
raise ActiveRecord::RecordNotFound unless @user | ||
end | ||
|
||
def user_tag_params | ||
params.require(:user_tag).permit(:user_id, :name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class UserTag < ActiveRecord::Base | ||
require 'nkf' | ||
|
||
has_many :user_taggings | ||
has_many :users, through: :user_taggings | ||
|
||
def self.retrieve(name) | ||
keyword = normalize_keyword(name) | ||
return nil if keyword.blank? | ||
create_with(name: keyword).find_or_create_by(search_hash: hash_keyword(name)) | ||
end | ||
|
||
def self.normalize_keyword(keyword) | ||
NKF.nkf('-w -X -Z', keyword.gsub(/[\s ]/, '')) | ||
end | ||
|
||
def self.hash_keyword(keyword) | ||
Digest::SHA256.hexdigest(self.normalize_keyword(keyword).downcase) | ||
end | ||
|
||
def attach(user) | ||
unless (user.tags.include?(self)) | ||
UserTagging.create(user_id: user.id, user_tag_id: self.id) | ||
end | ||
self | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class UserTagging < ActiveRecord::Base | ||
belongs_to :user | ||
belongs_to :tag, class_name: 'UserTag', foreign_key: 'user_tag_id' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
- user ||= user | ||
%div.user_tags | ||
- tags.each do |tag| | ||
%div.user_tag | ||
%i.fa.fa-tag.fa-lg | ||
= link_to tag.name, user_tag_path(tag) | ||
- if user.present? && myself?(user) | ||
= form_tag(user_tag_detach_path(user.nick), method: :delete, class: "tag_detach_form", data: { confirm: "detach tag [#{tag.name}] from you. are yo sure?" }) do | ||
= hidden_field_tag :tag_id, tag.id | ||
= button_tag do | ||
%i.fa.fa-remove.fa-lg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
%div.content.pure-u-1.pure-u-md-3-4 | ||
%div | ||
%div.posts | ||
%h1.content-subhead | ||
%section.post | ||
%header.post-header | ||
%h2 | ||
%i.fa.fa-tags.fa-lg | ||
User Tags | ||
%div.post-description | ||
= render 'tags', tags: @tags | ||
= paginate @tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
%div.content.pure-u-1.pure-u-md-3-4 | ||
%div | ||
%div.posts | ||
%h1.content-subhead | ||
%section.post | ||
%header.post-header | ||
%h2 | ||
%i.fa.fa-tag.fa-lg | ||
= @tag.name | ||
%div.post-description | ||
= render 'users/user_list', members: @members | ||
= paginate @members |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
%table.user_list.pure-table | ||
%thead | ||
%tr | ||
%th icon | ||
%th nick | ||
%th name | ||
%th member number | ||
%th last update | ||
%tbody | ||
- members.each_with_index do |member, line| | ||
%tr{ class: line.odd? ? 'pure-table-odd' : '' } | ||
%td= gravatar_image_tag(member) | ||
%td | ||
= link_to member.nick, home_path(member.nick) | ||
%td= member.name | ||
%td= member.member_number | ||
%td= member.updated_at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class CreateUserTagAndTagging < ActiveRecord::Migration | ||
def change | ||
create_table :user_tags do |t| | ||
t.string :name, null: false | ||
t.string :search_hash, null: false | ||
|
||
t.timestamps null: false | ||
end | ||
|
||
add_index :user_tags, :search_hash, unique: true | ||
|
||
create_table :user_taggings do |t| | ||
t.integer :user_id, null: false | ||
t.integer :user_tag_id, null: false | ||
end | ||
|
||
add_index :user_taggings, :user_id | ||
add_index :user_taggings, :user_tag_id | ||
add_index :user_taggings, [:user_id, :user_tag_id], unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.