ditty 0.2.2 → 0.3.0

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: 4e117d869f435ccaf97c5e0ed465a2464695d0e1
4
- data.tar.gz: 0eaa19a3ed0647b95abf5593ca4a89a98f043e5e
3
+ metadata.gz: 671a4f94844586df6b6f93e6b52555b4676c5571
4
+ data.tar.gz: ae067afab7015874c78e682a1ca1cd354860473d
5
5
  SHA512:
6
- metadata.gz: dfe1b8c443b4ae745c8e45c9e660c6819f49d9af0062f486f3c5d24d4f9f2383a52cde548c3dfc6c6f4a2406d21b680af6abba5d85e35120ff9675c8eb087215
7
- data.tar.gz: 076b68ddde52ccdede169bdf493aa63adb1ea28ffcec0f764791e460e4e3e744e382af61d950b0d6b624ef55e9b425a13d9817af3b5b292472dd98f8bc9afd6b
6
+ metadata.gz: 2c55cc8ad699496e26a57ed594da2e5779da9208e172119e8dd9df142ff8ed963ea9f06969846990e10ab3303264bc7038c1586d3a09b232723c6d47d0a9e7e1
7
+ data.tar.gz: 4d7b7e184449f4bac9287ac6588c5b30162617a68e76bf54524a7ad12671c996296fc2bd26c2c3a0ca8f2ca06e9ab7a222ed06f2c60e37c719a550af77b1dd15
data/Contributors.md ADDED
@@ -0,0 +1,5 @@
1
+ # Ditty Contributors
2
+
3
+ * [Jurgens du Toit](https://github.com/jrgns)
4
+ * [Sergey Shkarupa](https://github.com/sshkarupa)
5
+ * [Leonardo Tegon](https://github.com/tegon)
data/Rakefile CHANGED
@@ -2,12 +2,14 @@
2
2
 
3
3
  require 'rake'
4
4
  require 'bundler/gem_tasks'
5
- require 'rspec/core/rake_task'
6
5
  require 'ditty/rake_tasks'
7
6
 
8
7
  require 'ditty'
9
8
  require 'ditty/components/app'
10
9
 
11
- RSpec::Core::RakeTask.new(:spec)
12
-
13
- task default: :spec
10
+ begin
11
+ require 'rspec/core/rake_task'
12
+ RSpec::Core::RakeTask.new(:spec)
13
+ task default: :spec
14
+ rescue LoadError
15
+ end
data/lib/ditty.rb CHANGED
@@ -79,7 +79,7 @@ module Ditty
79
79
  components.inject([]) do |memo, comp|
80
80
  memo.concat comp[1].navigation if comp[1].respond_to?(:navigation)
81
81
  memo
82
- end
82
+ end.sort_by { |v| v[:order] }
83
83
  end
84
84
 
85
85
  def self.migrations
@@ -88,6 +88,12 @@ module Ditty
88
88
  end.compact
89
89
  end
90
90
 
91
+ def self.public_folder
92
+ components.map do |_name, comp|
93
+ comp.public_folder if comp.respond_to?(:public_folder)
94
+ end.compact
95
+ end
96
+
91
97
  def self.seeders
92
98
  components.map do |_name, comp|
93
99
  comp.seeder if comp.respond_to?(:seeder)
@@ -96,7 +102,7 @@ module Ditty
96
102
 
97
103
  def self.workers
98
104
  components.inject([]) do |memo, comp|
99
- memo.concat comp.workers if comp.respond_to?(:workers)
105
+ memo.concat comp[1].workers if comp[1].respond_to?(:workers)
100
106
  memo
101
107
  end
102
108
  end
@@ -45,6 +45,7 @@ module Ditty
45
45
  group: 'User Management',
46
46
  order: 10,
47
47
  icon: 'lock',
48
+ target: ::Ditty::User,
48
49
  items: [
49
50
  { order: 10, link: '/users/', text: 'Users', target: ::Ditty::User, icon: 'user' },
50
51
  { order: 20, link: '/roles/', text: 'Roles', target: ::Ditty::Role, icon: 'check-square' },
@@ -9,7 +9,7 @@ module Ditty
9
9
  include ActiveSupport::Inflector
10
10
 
11
11
  def dataset
12
- filtered(policy_scope(settings.model_class))
12
+ search(filtered(policy_scope(settings.model_class)))
13
13
  end
14
14
 
15
15
  def list
@@ -43,6 +43,10 @@ module Ditty
43
43
  self.class.const_defined?('FILTERS') ? self.class::FILTERS : []
44
44
  end
45
45
 
46
+ def searchable_fields
47
+ self.class.const_defined?('SEARCHABLE') ? self.class::SEARCHABLE : []
48
+ end
49
+
46
50
  def filtered(dataset)
47
51
  filters.each do |filter|
48
52
  next unless params[filter[:name].to_s]
@@ -58,6 +62,14 @@ module Ditty
58
62
  value = value.send(filter[:modifier]) if filter[:modifier]
59
63
  dataset.where(filter[:field].to_sym => value)
60
64
  end
65
+
66
+ def search(dataset)
67
+ return dataset if params['q'] == '' || params['q'].nil?
68
+ return dataset if searchable_fields == []
69
+
70
+ filters = searchable_fields.map { |f| Sequel.ilike(f.to_sym, "%#{params[:q]}%") }
71
+ dataset.where Sequel.|(*filters)
72
+ end
61
73
  end
62
74
  end
63
75
  end
@@ -22,6 +22,16 @@ module Ditty
22
22
  }
23
23
  end
24
24
 
25
+ def filter_control(filter, opts = {})
26
+ meth = "#{filter[:name]}_options".to_sym
27
+ return unless respond_to? meth
28
+ haml :'partials/filter_control', locals: {
29
+ name: filter[:name],
30
+ label: opts[:label] || filter[:name].titlecase,
31
+ options: send(meth)
32
+ }
33
+ end
34
+
25
35
  def flash_messages(key = :flash)
26
36
  return '' if flash(key).empty?
27
37
  id = (key == :flash ? 'flash' : "flash_#{key}")
@@ -23,16 +23,24 @@ module Ditty
23
23
  require 'ditty/seed'
24
24
  end
25
25
 
26
- desc 'Prepare Ditty migrations'
26
+ desc 'Prepare Ditty'
27
27
  task :prep do
28
28
  puts 'Prepare the Ditty folders'
29
29
  Dir.mkdir 'pids' unless File.exist?('pids')
30
30
 
31
+ puts 'Preparing the Ditty public folder'
32
+ Dir.mkdir 'public' unless File.exist?('public')
33
+ ::Ditty::Components.public_folder.each do |path|
34
+ FileUtils.cp_r "#{path}/.", 'public'
35
+ end
36
+
31
37
  puts 'Preparing the Ditty migrations folder'
32
38
  Dir.mkdir 'migrations' unless File.exist?('migrations')
33
39
  ::Ditty::Components.migrations.each do |path|
34
40
  FileUtils.cp_r "#{path}/.", 'migrations'
35
41
  end
42
+ puts 'Migrations added:'
43
+ Dir.foreach('migrations').sort.each { |x| puts x if File.file?("migrations/#{x}") }
36
44
  end
37
45
 
38
46
  desc 'Migrate Ditty database to latest version'
data/lib/ditty/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ditty
4
- VERSION = '0.2.2'.freeze
4
+ VERSION = '0.3.0'.freeze
5
5
  end
@@ -0,0 +1,6 @@
1
+ .form-group
2
+ %label{ for: "filter_#{name}" }= label
3
+ %select.form-control{ name: name, id: "filter_#{name}" }
4
+ %option{ value: '' } -- Select One --
5
+ - options.each do |k,v| k ||= v; v ||= k;
6
+ %option{ value: k, selected: (params[name].eql? k)}= v
@@ -0,0 +1,21 @@
1
+ - if self.class.const_defined?(:SEARCHABLE) || self.class.const_defined?(:FILTERS)
2
+ %form{ method: 'get', action: base_path }
3
+ - if self.class.const_defined?(:SEARCHABLE)
4
+ .form-group
5
+ .input-group
6
+ %input.form-control{ name: 'q', type: 'text', placeholder: 'Search...', value: params['q'] }
7
+ .input-group-btn
8
+ %button.btn.btn-primary{ type: 'submit' }
9
+ %span.fa.fa-search
10
+ - if self.class.const_defined? :FILTERS
11
+ .input-group-btn
12
+ %button.btn.btn-default{ type: 'button', :'data-toggle' => 'collapse', :'data-target' => '#filter-form', :'aria-expanded' => 'false', :'aria-controls' => '#filter-form'}
13
+ %span.fa.fa-arrow-down
14
+
15
+ - if self.class.const_defined?(:FILTERS)
16
+ #filter-form{ class: self.class.const_defined?(:SEARCHABLE) ? 'collapse' : '' }
17
+ .form-inline
18
+ - FILTERS.each do |filter|
19
+ = filter_control(filter)
20
+ - unless self.class.const_defined?(:SEARCHABLE)
21
+ %button.btn.btn-default{ type: 'submit'} Go
@@ -15,10 +15,11 @@
15
15
  %span.fa.arrow
16
16
  %ul.nav.nav-second-level
17
17
  - item[:items].each do |sub_item|
18
- %li
19
- %a{ href: "#{settings.map_path}#{sub_item[:link]}" }
20
- %i.fa.fa-fw{ class: "fa-#{sub_item[:icon]}" }
21
- = sub_item[:text]
18
+ - if sub_item[:target].nil? || policy(sub_item[:target]).list?
19
+ %li
20
+ %a{ href: "#{settings.map_path}#{sub_item[:link]}" }
21
+ %i.fa.fa-fw{ class: "fa-#{sub_item[:icon]}" }
22
+ = sub_item[:text]
22
23
  - else
23
24
  %li
24
25
  %a{ href: "#{settings.map_path}#{item[:link]}" }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ditty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurgens du Toit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-10 00:00:00.000000000 Z
11
+ date: 2017-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -330,6 +330,7 @@ files:
330
330
  - ".rspec"
331
331
  - ".rubocop.yml"
332
332
  - ".travis.yml"
333
+ - Contributors.md
333
334
  - Gemfile.ci
334
335
  - License.txt
335
336
  - Rakefile
@@ -386,11 +387,13 @@ files:
386
387
  - views/index.haml
387
388
  - views/layout.haml
388
389
  - views/partials/delete_form.haml
390
+ - views/partials/filter_control.haml
389
391
  - views/partials/footer.haml
390
392
  - views/partials/form_control.haml
391
393
  - views/partials/navbar.haml
392
394
  - views/partials/notifications.haml
393
395
  - views/partials/pager.haml
396
+ - views/partials/search.haml
394
397
  - views/partials/sidebar.haml
395
398
  - views/roles/display.haml
396
399
  - views/roles/edit.haml