-
Notifications
You must be signed in to change notification settings - Fork 1
Phase 1 enahancement 72 #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 7 commits
bbefc45
7880073
4f4e5a1
2e26380
4d6cd66
a1af633
a6b1487
0b1031b
939c5dc
dc2a956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| require 'will_paginate/array' | ||
| class LinksController < ApplicationController | ||
| before_filter :authenticate_user! | ||
| before_filter :assign_link, only: [:update, :destroy, :edit] | ||
|
|
@@ -9,9 +10,9 @@ class LinksController < ApplicationController | |
| def index | ||
| selected_tag = params[:tag] | ||
| if selected_tag | ||
| @links = current_user_links.tagged_with(selected_tag).order(:created_at => :desc).paginate(page: page) | ||
| @links = current_user_links.tagged_with(selected_tag).order(created_at: :desc).paginate(page: page) | ||
| else | ||
| @links = current_user_links.order(:created_at => :desc).paginate(page: page) | ||
| @links = current_user_links.order(created_at: :desc).paginate(page: page) | ||
| end | ||
| respond_to do |format| | ||
| format.html | ||
|
|
@@ -20,13 +21,28 @@ def index | |
| end | ||
| end | ||
|
|
||
| def sort_links | ||
| case params[:sort_by] | ||
| when 'Added On' | ||
| @sorted_links = params[:search_string].empty? ? current_user_links.order_by_created_at.paginate(page: page) : search_list.reorder('created_at DESC').paginate(page: page) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| when 'Updated On' | ||
| @sorted_links = params[:search_string].empty? ? current_user_links.order_by_updated_at.paginate(page: page) : search_list.reorder('updated_at DESC').paginate(page: page) | ||
| when 'Recently Learned' | ||
| @sorted_links = params[:search_string].empty? ? current_user.user_learned_links.paginate(page: page) : search_list.reorder('last_learned_at DESC').reject{|link| link.last_learned_at.nil? }.paginate(page: page) | ||
| when 'Learn Count' | ||
| @sorted_links = params[:search_string].empty? ? @current_user_links.sort_by{ |link| link.learn_time.count }.reverse.paginate(page: page) : search_list.reorder('learn_times_count DESC').paginate(page: page) | ||
| end | ||
| end | ||
|
|
||
|
|
||
|
|
||
| def new | ||
| @link = Link.new | ||
| end | ||
|
|
||
| def create | ||
| @link = Link.new(link_params.merge({ user_id: current_user.id }).except!(:tag_list)) | ||
| current_user.tag(@link, :with => link_params[:tag_list], :on => :tags) | ||
| current_user.tag(@link, with: link_params[:tag_list], on: :tags) | ||
|
|
||
| if @link.save | ||
| redirect_to root_path | ||
|
|
@@ -43,7 +59,7 @@ def edit | |
| def update | ||
| if @link.present? | ||
| @link.update(link_params.merge({user_id: current_user.id}).except!(:tag_list)) | ||
| current_user.tag(@link, :with => link_params[:tag_list], :on => :tags) | ||
| current_user.tag(@link, with: link_params[:tag_list], on: :tags) | ||
| flash[:success] = 'Successfully Updated!!' | ||
| redirect_to root_path | ||
| else | ||
|
|
@@ -60,7 +76,7 @@ def destroy | |
| end | ||
|
|
||
| def favourites | ||
| @links = current_user.links.where(favourite: true).order(:created_at => :desc).paginate(page: page) | ||
| @links = current_user.links.where(favourite: true).order(created_at: :desc).paginate(page: page) | ||
| render 'links/index' | ||
| end | ||
|
|
||
|
|
@@ -75,12 +91,17 @@ def import | |
| end | ||
|
|
||
| def search | ||
| @search_list = params[:search_string].empty? ? current_user_links.order(:created_at => :desc).paginate(page: page) : Link.search(params[:search_string]).paginate(page: page) | ||
| @search_list = params[:search_string].empty? ? current_user_links.order(created_at: :desc).paginate(page: page) : | ||
| search_list.paginate(page: page) | ||
| end | ||
|
|
||
| def search_list | ||
| Link.search(params[:search_string]) | ||
| end | ||
|
|
||
| private | ||
| def link_params | ||
| params.require(:link).permit(:title, :url, :learning_status_id, :description, :category_id, :user_id, :link_type_id, :tag_list => []) | ||
| params.require(:link).permit(:title, :url, :learning_status_id, :description, :category_id, :user_id, :link_type_id, tag_list: []) | ||
| end | ||
|
|
||
| def assign_link | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,6 @@ | ||
| class LearnTime < ActiveRecord::Base | ||
|
|
||
| belongs_to :user | ||
| belongs_to :link | ||
|
|
||
| def self.report_of_learn_time(user_id, date) | ||
| LearnTime.where("user_id = ? and created_at >= ?", user_id, date ).group('date(created_at)').count | ||
| end | ||
| belongs_to :link, counter_cache: true | ||
|
|
||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,15 +11,19 @@ class User < ActiveRecord::Base | |
| has_many :links | ||
| has_many :learn_time | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't |
||
|
|
||
| def self.get_all_link(user, date) | ||
| user.links.where("created_at >= ?", date).group('date(created_at)').count | ||
| def links_till( date) | ||
| links.where("created_at >= ?", date).group('date(created_at)').count | ||
| end | ||
|
|
||
| def favourite_links | ||
| self.links.where(favourite: true) | ||
| end | ||
|
|
||
| def current_user_links | ||
| self.links | ||
| def user_learned_links | ||
| learn_time.order(created_at: :desc).map { |link| link.link }.uniq | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you try to use |
||
| end | ||
|
|
||
| def user_learn_count_till(date) | ||
| learn_time.where("created_at >= ?", date).group('date(created_at)').count | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| </div> | ||
| <%= link_to 'Learning Path', root_path, class: 'logo' %> | ||
| <div class="search_bar"> | ||
| <%= form_tag links_search_path, remote: true, id: 'search' do %> | ||
| <%= form_tag links_search_path, method: :get, remote: true, id: 'search' do %> | ||
| <%= text_field_tag 'search_string', nil, class: 'search_box' %> | ||
| <button class='fa fa-search search_button' style='width:40px;'> | ||
| </button> | ||
|
|
@@ -19,4 +19,11 @@ | |
| <% end %> | ||
| </ul> | ||
| </div> | ||
| </header> | ||
| </header> | ||
| <script> | ||
| $(document).ready(function(){ | ||
| $('#search').submit(function(){ | ||
| $('.links').empty(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As suggested elsewhere move it to a common function |
||
| }); | ||
| }); | ||
| </script> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,17 +3,31 @@ | |
| <% if @links.blank? %> | ||
| <div class="no_links_msg">You do not have anything to display at this time. <%= link_to 'Start saving one now!', new_link_path%></div> | ||
| <% else %> | ||
| <div class="col-lg-8 col-md-8 col-sm-8 links" id="links-list"> | ||
| <%= render partial: 'links/links_list', locals: { links: @links}%> | ||
| <div class="col-lg-8 col-md-8 col-sm-8" id="links-list"> | ||
| <%= form_tag sort_links_path, remote: true, method: :get, id: 'sorting_form' do %> | ||
| <%= hidden_field_tag :search_string, '', class: 'search_field_val' %> | ||
| <%= select_tag :sort_by, options_for_sorting, class: "select_box" %> | ||
| <% end %> | ||
| <div class="links"> | ||
| <%= render partial: 'links/links_list', locals: { links: @links }%> | ||
| </div> | ||
| </div> | ||
| <div class="col-lg-3 col-md-3 col-sm-3 showback tag-cloud-width"> | ||
| <% tag_cloud Link.tag_counts, %w{s m l} do |tag, css_class| %> | ||
| <%= link_to tag.name, links_path(tag: tag.name), class: css_class %> | ||
| <% end %> | ||
| </div> | ||
| <div class="link_pagination"> | ||
| <%= will_paginate @links || @search_list %> | ||
| <%= will_paginate @links %> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
| </section> | ||
| </section> | ||
| <script type="text/javascript"> | ||
| $(document).ready(function(){ | ||
| $('.select_box').change(function(){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Binding |
||
| $('#sorting_form').submit(); | ||
| $('.links').empty(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to common function |
||
| }); | ||
| }); | ||
| </script> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| $('.links').html("<%= escape_javascript(render partial: 'links/links_list', locals: { links: @links = @search_list})%>"); | ||
| $('.links').append("<%= escape_javascript(render partial: 'links/links_list', locals: { links: @links = @search_list})%>"); | ||
| $('.search_field_val').val("<%= params[:search_string]%>"); | ||
| $('.pagination').replaceWith('<%= escape_javascript(will_paginate(@search_list) )%>'); | ||
| $('.flash_msg').remove(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| $('.links').append("<%= escape_javascript(render partial: 'links/links_list', locals: { links: @links = @sorted_links })%>"); | ||
| $('.pagination').replaceWith('<%= escape_javascript(will_paginate(@sorted_links) )%>'); | ||
| $('.flash_msg').remove(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LearnTimecreation andlast_learned_atshould be wrapped in a transaction.Check http://api.rubyonrails.org/classes/ActiveRecord/Transactions/ClassMethods.html