boxroom 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21e9f11bc948549ad833330da41139124099fa51
4
- data.tar.gz: 6fcbc3e5f900ad2c032aa8562cb7ebd2d08a1465
3
+ metadata.gz: 2425f21a20fb62edbadae39129d71297a13297dd
4
+ data.tar.gz: b28cc4abc23332bbe28439304d2b9003873aa4d7
5
5
  SHA512:
6
- metadata.gz: a4c1fd13840b7a5aed4e3c496188fad9e7d0a3302fd853728cc17e13d5292fe2fdf546db8c8b01596059a7d97986e7b0d032c334d395f5999103479fe353fd44
7
- data.tar.gz: a1349db39a6ef79da9dce7e9ef0ea125065e8df19b54dea8f27fed7ff661829d5396a2652c139dcf588acfd402cf1ef8a1e8d73225b598ecc4cf92193058ca09
6
+ metadata.gz: aea5a38bcf464ca445bf742d30c7296664e8e02c234dc26c1b5641a11cf8835ced66f2d9f9281349131142a2df8de3f48a00178f4a4c1a5af4c94611cb5fc14e
7
+ data.tar.gz: 9d6fca592719fc908a0efa10ff09bb032c96def05880cc14dc72af49533821f4c80d15e8be2c949d8cb4e088a6f2d50deaca3a8b4a5fcf0860b1c2fc16689646
data/README.md CHANGED
@@ -81,6 +81,7 @@ Please feel free to leave an issue or PR.
81
81
  The engine is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
82
82
 
83
83
  ## Roadmap:
84
+ - tests for sort
84
85
  - support s3
85
86
  - batch actions
86
87
  - tag files
@@ -20,6 +20,23 @@ module Boxroom
20
20
  model
21
21
  end
22
22
 
23
+ def sort_link(field)
24
+ if @options[:sort_field] == field
25
+ sort_dir = @options[:sort_dir] == 'desc' ? 'asc' : 'desc'
26
+ icon_class = sort_dir == 'asc' ? 'fa-caret-up' : 'fa-caret-down'
27
+ else
28
+ sort_dir = 'asc'
29
+ icon_class = 'fa-caret-down'
30
+ end
31
+ span_class = @options[:sort_field] == field ? 'has-text-link' : 'has-text-grey-lighter'
32
+ path = if request.original_url.include? 'search'
33
+ search_path(folder_id: folder.id, term: params[:term], sort_field: field, sort_dir: sort_dir)
34
+ else
35
+ folder_path(folder, sort_field: field, sort_dir: sort_dir)
36
+ end
37
+ link_to "<span class=\"icon is-small #{span_class}\"><i class=\"fa #{icon_class}\"></i></span>", path
38
+ end
39
+
23
40
  end
24
41
  end
25
42
  end
@@ -0,0 +1,9 @@
1
+ module Boxroom::Folder::Contract
2
+ class FilesAndFolders < Reform::Form
3
+ property :folder_id, virtual: true
4
+ property :sort_field, virtual: true
5
+ property :sort_dir, virtual: true
6
+
7
+ validates :folder_id, presence: true
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ module Boxroom
2
+ class Folder < ActiveRecord::Base
3
+ class FilesAndFolders < ::Trailblazer::Operation
4
+ step Trailblazer::Operation::Contract::Build(constant: Boxroom::Folder::Contract::FilesAndFolders)
5
+ step Trailblazer::Operation::Contract::Validate()
6
+ step :get_lists
7
+
8
+ def get_lists(options, params:, **)
9
+ folder = Boxroom::Folder.find(params[:folder_id])
10
+ sort_field, sort_dir = params[:sort_field], params[:sort_dir]
11
+ sort_dir = sort_dir == 'asc' ? 'asc' : 'desc'
12
+ options['folders'] = folder.children
13
+ options['files'] = folder.user_files
14
+ case sort_field
15
+ when 'name'
16
+ options['folders'] = options['folders'].reorder("name #{sort_dir}")
17
+ options['files'] = options['files'].reorder("attachment_file_name #{sort_dir}")
18
+ when 'size'
19
+ options['files'] = options['files'].reorder("attachment_file_size #{sort_dir}")
20
+ when 'date'
21
+ options['folders'] = options['folders'].reorder("updated_at #{sort_dir}")
22
+ options['files'] = options['files'].reorder("updated_at #{sort_dir}")
23
+ end
24
+ true
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,9 +2,9 @@
2
2
  <thead>
3
3
  <tr>
4
4
  <th></th>
5
- <th><%= t :name %></th>
6
- <th><%= t :size %></th>
7
- <th><%= t :date_modified %></th>
5
+ <th><%= t :name %> <%= sort_link 'name' %> </th>
6
+ <th><%= t :size %> <%= sort_link 'size' %> </th>
7
+ <th><%= t :date_modified %> <%= sort_link 'date' %> </th>
8
8
  <th></th>
9
9
  </tr>
10
10
  </thead>
@@ -2,6 +2,8 @@ module Boxroom::Search::Contract
2
2
  class FilesAndFolders < Reform::Form
3
3
  property :term, virtual: true
4
4
  property :folder_id, virtual: true
5
+ property :sort_field, virtual: true
6
+ property :sort_dir, virtual: true
5
7
 
6
8
  validates :folder_id, presence: true
7
9
  validates :term, length: {minimum: 3}
@@ -3,6 +3,7 @@ module Boxroom::Search
3
3
  step Trailblazer::Operation::Contract::Build(constant: Boxroom::Search::Contract::FilesAndFolders)
4
4
  step Trailblazer::Operation::Contract::Validate()
5
5
  step :search_tree
6
+ step :sort_results
6
7
 
7
8
  def search_tree(options, params:, **)
8
9
  options['files'], options['folders'] = [], []
@@ -17,5 +18,24 @@ module Boxroom::Search
17
18
  search_folder(term, f, options)
18
19
  end
19
20
  end
21
+
22
+ def sort_results(options, params:, **)
23
+ sort_field, sort_dir = params[:sort_field], params[:sort_dir]
24
+ sort_dir = sort_dir == 'asc' ? 'asc' : 'desc'
25
+ case sort_field
26
+ when 'name'
27
+ options['folders'] = options['folders'].sort_by {|f| f.name}
28
+ options['files'] = options['files'].sort_by {|f| f.attachment_file_name}
29
+ options['folders'] = options['folders'].reverse if sort_dir == 'desc'
30
+ when 'size'
31
+ options['files'] = options['files'].sort_by {|f| f.attachment_file_size}
32
+ when 'date'
33
+ options['folders'] = options['folders'].sort_by {|f| f.updated_at}
34
+ options['files'] = options['files'].sort_by {|f| f.updated_at}
35
+ options['folders'] = options['folders'].reverse if sort_dir == 'desc'
36
+ end
37
+ options['files'] = options['files'].reverse if sort_dir == 'desc'
38
+ true
39
+ end
20
40
  end
21
41
  end
@@ -17,6 +17,10 @@ module Boxroom
17
17
 
18
18
  # Note: @folder is set in require_existing_folder
19
19
  def show
20
+ result = Boxroom::Folder::FilesAndFolders.(params: {folder_id: @folder.id, sort_field: params[:sort_field], sort_dir: params[:sort_dir]})
21
+ if result.success?
22
+ @files, @folders = result['files'], result['folders']
23
+ end
20
24
  end
21
25
 
22
26
  # Note: @target_folder is set in require_existing_target_folder
@@ -5,7 +5,7 @@ module Boxroom
5
5
  def show
6
6
  @folder = get_folder_or_redirect(params[:folder_id])
7
7
  @term = params[:term]
8
- result = Search::FilesAndFolders.(params: {term: @term, folder_id: @folder.id})
8
+ result = Search::FilesAndFolders.(params: {term: @term, folder_id: @folder.id, sort_field: params[:sort_field]})
9
9
  if result.success?
10
10
  @folders = result['folders']
11
11
  @files = result['files']
@@ -56,9 +56,12 @@
56
56
 
57
57
  <div id="files_and_folders">
58
58
  <%= concept(Boxroom::Folder::Cell::Show, @folder,
59
- folders: @folder.children,
60
- files: @folder.user_files,
61
- current_user: boxroom_current_user) %>
59
+ folders: @folders,
60
+ files: @files,
61
+ current_user: boxroom_current_user,
62
+ sort_field: params[:sort_field],
63
+ sort_dir: params[:sort_dir]
64
+ ) %>
62
65
  </div>
63
66
 
64
67
  <% if boxroom_current_user.member_of_admins? -%>
@@ -2,10 +2,12 @@
2
2
 
3
3
  <h1 class="title"><%= "Search `#{@term}` in #{@folder.name}" %></h1>
4
4
 
5
- <%= concept(Boxroom::Folder::Cell::Show, nil,
5
+ <%= concept(Boxroom::Folder::Cell::Show, @folder,
6
6
  folders: @folders,
7
7
  files: @files,
8
- current_user: boxroom_current_user
8
+ current_user: boxroom_current_user,
9
+ sort_field: params[:sort_field],
10
+ sort_dir: params[:sort_dir]
9
11
  ) %>
10
12
 
11
13
  <div class="field">
@@ -1,3 +1,3 @@
1
1
  module Boxroom
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxroom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serge Koba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-17 00:00:00.000000000 Z
11
+ date: 2018-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -333,6 +333,8 @@ files:
333
333
  - app/assets/stylesheets/boxroom/application.scss
334
334
  - app/concepts/boxroom/base_cell.rb
335
335
  - app/concepts/boxroom/folder/cell/show.rb
336
+ - app/concepts/boxroom/folder/contract/files_and_folders.rb
337
+ - app/concepts/boxroom/folder/operations/files_and_folders.rb
336
338
  - app/concepts/boxroom/folder/view/show.erb
337
339
  - app/concepts/boxroom/search/contract/files_and_folders.rb
338
340
  - app/concepts/boxroom/search/operations/files_and_folders.rb