administrate 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of administrate might be problematic. Click here for more details.

Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/administrate/search.svg +6 -0
  3. data/app/assets/images/administrate/sort_arrow.svg +4 -0
  4. data/app/assets/javascripts/administrate/components/_search.js +42 -0
  5. data/app/assets/stylesheets/administrate/_sidebar.scss +0 -10
  6. data/app/assets/stylesheets/administrate/base/_forms.scss +4 -0
  7. data/app/assets/stylesheets/administrate/base/_variables.scss +18 -4
  8. data/app/assets/stylesheets/administrate/components/_cells.scss +49 -1
  9. data/app/assets/stylesheets/administrate/components/_components.scss +3 -1
  10. data/app/assets/stylesheets/administrate/components/_pagination.scss +16 -0
  11. data/app/assets/stylesheets/administrate/components/_search.scss +58 -0
  12. data/app/assets/stylesheets/administrate/layout.scss +4 -1
  13. data/app/controllers/administrate/application_controller.rb +25 -17
  14. data/app/views/administrate/application/_sidebar.html.erb +0 -4
  15. data/app/views/administrate/application/_table.html.erb +14 -2
  16. data/app/views/administrate/application/index.html.erb +20 -0
  17. data/app/views/administrate/application/show.html.erb +3 -3
  18. data/app/views/fields/has_many/_show.html.erb +3 -2
  19. data/app/views/fields/has_one/_form.html.erb +1 -6
  20. data/app/views/layouts/administrate/application.html.erb +8 -6
  21. data/lib/administrate/engine.rb +7 -2
  22. data/lib/administrate/fields/base.rb +4 -0
  23. data/lib/administrate/fields/deferred.rb +6 -1
  24. data/lib/administrate/fields/email.rb +3 -0
  25. data/lib/administrate/fields/has_many.rb +15 -5
  26. data/lib/administrate/fields/has_one.rb +1 -0
  27. data/lib/administrate/fields/string.rb +5 -1
  28. data/lib/administrate/order.rb +45 -0
  29. data/lib/administrate/page/base.rb +3 -2
  30. data/lib/administrate/page/table.rb +12 -0
  31. data/lib/administrate/search.rb +36 -0
  32. data/lib/administrate/version.rb +1 -1
  33. data/lib/generators/administrate/dashboard/dashboard_generator.rb +7 -0
  34. data/lib/generators/administrate/dashboard/templates/controller.rb.erb +19 -0
  35. data/lib/generators/administrate/install/templates/application_controller.rb +6 -10
  36. data/lib/generators/administrate/install/templates/routes.rb +3 -11
  37. metadata +66 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9b9090f8ba59a083ec8484f644561d803062d56
4
- data.tar.gz: fe9a6db1a0702cb0b1459d3b67385d36641dc0b1
3
+ metadata.gz: cd6443bd06d24f63d4f5dcfbb96fd9678a661e54
4
+ data.tar.gz: da323f68c0e013f7eeed53e9522081ef0e1accf6
5
5
  SHA512:
6
- metadata.gz: bd0b3a695b131733a8a2d7a3c433e8babb7afff01acf20655764845bf8baa1f5e3cb847c2262ce566d2de459853dbe71b91a7f1603f24eb918c4234f73ef2288
7
- data.tar.gz: aee894ee80ed845e4adc46a969f04192b59e7550c974de023ddb4cb534f1c4cf5008d74634b9dc0bebf80b85072b33077bc0af65a84fa7dec2d2f7d7b69bf521
6
+ metadata.gz: ffe2364fe45f624b3fb422336cd00cb36fde0ef6217e492a77f5117a05dfe0e1dc69395b3bfdc08c4b94b36a81d7231bb3b7193e5ddafb0b62686b422d054d67
7
+ data.tar.gz: 4e0e7c3d7cdd9dbc45ebe2195c0686f0c9fc852b1e1ffe8c6cd9b3716d61f7a03a801a15a22c25829af360f36eef8ed1af2140bf617a513d12a81182cf0e0461
@@ -0,0 +1,6 @@
1
+ <svg width="48" height="48" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg">
2
+ <title>
3
+ search
4
+ </title>
5
+ <path d="M27.885 32.515c-2.864 1.966-6.333 3.116-10.07 3.116C7.976 35.63 0 27.656 0 17.817 0 7.976 7.976 0 17.816 0S35.63 7.976 35.63 17.816c0 3.736-1.15 7.205-3.115 10.07l14.53 14.53c1.278 1.277 1.275 3.352 0 4.628-1.28 1.278-3.353 1.278-4.63 0l-14.53-14.53zm-10.07-3.736c6.056 0 10.964-4.91 10.964-10.964 0-6.055-4.91-10.964-10.964-10.964-6.055 0-10.964 4.91-10.964 10.964 0 6.055 4.91 10.963 10.964 10.963z" fill="#D8D8D8" fill-rule="evenodd"/>
6
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg width="48" height="48" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg">
2
+ <title>sort_arrow</title>
3
+ <path d="M2.988 33.02c-1.66 0-1.943-.81-.618-1.824l20-15.28c.878-.672 2.31-.67 3.188 0l20.075 15.288c1.316 1.003 1.048 1.816-.62 1.816H2.987z" />
4
+ </svg>
@@ -0,0 +1,42 @@
1
+ $(function() {
2
+ "use strict";
3
+
4
+ var $input = $(".search__input");
5
+ var activeSuffix = "--active";
6
+ var timeout;
7
+
8
+ $.fn.textWidth = function(text, font) {
9
+ if (!$.fn.textWidth.fakeEl) {
10
+ $.fn.textWidth.fakeEl = $("<span>").appendTo(document.body);
11
+ }
12
+
13
+ var htmlText = text || this.val() || this.text();
14
+ htmlText = $.fn.textWidth.fakeEl.text(htmlText).html();
15
+ htmlText = htmlText.replace(/\s/g, "&nbsp;");
16
+ $.fn.textWidth.fakeEl.html(htmlText).css("font", font || this.css("font"));
17
+ return $.fn.textWidth.fakeEl.width();
18
+ };
19
+
20
+ var activate = function(className) {
21
+ $("." + className).addClass(className + activeSuffix);
22
+ };
23
+
24
+ var deactivate = function(className) {
25
+ $("." + className).removeClass(className + activeSuffix);
26
+ };
27
+
28
+ $input.on("focus", function() { activate("search__icon"); });
29
+ $input.on("blur", function() { deactivate("search__icon"); });
30
+ $input.on("keydown", function() { deactivate("search__hint"); });
31
+
32
+ var showHint = function() { activate("search__hint"); };
33
+
34
+ $input.on("keyup", function() {
35
+ clearTimeout(timeout);
36
+
37
+ if($input.val().length) {
38
+ $(".search__hint").css("left", $input.textWidth() + 75);
39
+ timeout = setTimeout(showHint, 250);
40
+ }
41
+ });
42
+ });
@@ -4,16 +4,6 @@
4
4
  overflow-y: auto;
5
5
  padding: 0 $base-spacing;
6
6
 
7
- &__logo {
8
- height: 6em;
9
-
10
- img {
11
- display: block;
12
- height: 100%;
13
- padding-top: $base-spacing;
14
- }
15
- }
16
-
17
7
  &__link {
18
8
  @include fill-parent;
19
9
  color: $base-font-color;
@@ -50,6 +50,10 @@ select {
50
50
  box-shadow: $form-box-shadow-focus;
51
51
  outline: none;
52
52
  }
53
+
54
+ @include placeholder {
55
+ color: $hint-grey;
56
+ }
53
57
  }
54
58
 
55
59
  textarea {
@@ -47,18 +47,32 @@ $white: #fff;
47
47
  $grey-0: #f6f7f7;
48
48
  $grey-1: #dfe0e1;
49
49
  $grey-2: #cfd8dc;
50
- $grey-3: #90acad;
51
- $grey-4: #7b808c;
52
- $grey-5: #4e6a68;
53
- $grey-6: #344346;
54
50
  $grey-7: #293f54;
55
51
 
52
+ $hint-grey: #7b808c;
53
+
56
54
  $base-background-color: $grey-0;
57
55
 
58
56
  // Font Colors
59
57
  $base-font-color: $grey-7;
60
58
  $base-accent-color: $blue;
61
59
 
60
+ // Override text inputs for lower specificity
61
+ $all-text-inputs: '[type="color"]',
62
+ '[type="date"]',
63
+ '[type="datetime"]',
64
+ '[type="datetime-local"]',
65
+ '[type="email"]',
66
+ '[type="month"]',
67
+ '[type="number"]',
68
+ '[type="password"]',
69
+ '[type="search"]',
70
+ '[type="tel"]',
71
+ '[type="text"]',
72
+ '[type="time"]',
73
+ '[type="url"]',
74
+ '[type="week"]';
75
+
62
76
  // Link Colors
63
77
  $base-link-color: $blue;
64
78
  $hover-link-color: shade($blue, 10);
@@ -1,10 +1,58 @@
1
1
  .cell-label,
2
2
  .attribute-label {
3
- color: $grey-4;
3
+ color: $hint-grey;
4
4
  font-size: $small-font-size;
5
5
  font-weight: $normal-font-weight;
6
6
  letter-spacing: 0.0357em;
7
+ position: relative;
7
8
  text-transform: uppercase;
9
+
10
+ a {
11
+ @include fill-parent;
12
+ color: inherit;
13
+ display: inline-block;
14
+ transition: $base-transition;
15
+ }
16
+
17
+ &--asc,
18
+ &--desc {
19
+ font-weight: bold;
20
+ }
21
+
22
+ &__sort-indicator {
23
+ display: inline-block;
24
+ height: 1em;
25
+ overflow: hidden;
26
+ position: absolute;
27
+ right: 0;
28
+
29
+ &--desc {
30
+ transform: rotate(180deg);
31
+ }
32
+
33
+ svg {
34
+ height: 100%;
35
+ transition: $base-transition;
36
+ }
37
+
38
+ path {
39
+ fill: $hint-grey;
40
+ }
41
+ }
42
+
43
+ &:hover {
44
+ a {
45
+ color: $base-accent-color;
46
+ }
47
+
48
+ path {
49
+ fill: $base-accent-color;
50
+ }
51
+
52
+ svg {
53
+ transform: rotate(180deg);
54
+ }
55
+ }
8
56
  }
9
57
 
10
58
  .cell-data--number,
@@ -1,6 +1,8 @@
1
1
  @import "attributes";
2
2
  @import "cells";
3
- @import "form";
4
3
  @import "date_time_picker";
4
+ @import "form";
5
5
  @import "header";
6
+ @import "search";
7
+ @import "pagination";
6
8
  @import "table";
@@ -0,0 +1,16 @@
1
+ .pagination {
2
+ margin: $base-spacing 0;
3
+ text-align: center;
4
+
5
+ .first,
6
+ .prev,
7
+ .page,
8
+ .next,
9
+ .last {
10
+ margin: $small-spacing;
11
+ }
12
+
13
+ .current {
14
+ font-weight: bold;
15
+ }
16
+ }
@@ -0,0 +1,58 @@
1
+ .search {
2
+ align-items: center;
3
+ border-bottom: $base-border;
4
+ display: flex;
5
+ flex-direction: row;
6
+ justify-content: flex-start;
7
+ padding: 0 $base-spacing;
8
+ position: relative;
9
+ width: 100%;
10
+ }
11
+
12
+ .search__icon {
13
+ svg {
14
+ @include size(1em);
15
+ }
16
+
17
+ path {
18
+ @include transition($base-transition);
19
+ fill: $hint-grey;
20
+ }
21
+
22
+ &--active path {
23
+ fill: $base-accent-color;
24
+ }
25
+ }
26
+
27
+ .search__input {
28
+ appearance: none;
29
+ border: none;
30
+ box-shadow: none;
31
+ flex-grow: 1;
32
+ margin: 0;
33
+ padding: ($small-spacing * 1.5) $small-spacing;
34
+
35
+ &:focus {
36
+ box-shadow: none;
37
+ }
38
+ }
39
+
40
+ .search__hint {
41
+ @include position(absolute, 1em null null null);
42
+ @include transition($base-transition);
43
+ color: $hint-grey;
44
+ opacity: 0;
45
+
46
+ svg {
47
+ @include size(100%);
48
+ }
49
+
50
+ path,
51
+ rect {
52
+ fill: $base-accent-color;
53
+ }
54
+
55
+ &--active {
56
+ opacity: 1;
57
+ }
58
+ }
@@ -17,10 +17,13 @@ body {
17
17
  max-width: 100em;
18
18
  }
19
19
 
20
- .content {
20
+ .container {
21
21
  @include card(1);
22
22
  background-color: $white;
23
23
  flex: 1;
24
24
  overflow-y: auto;
25
+ }
26
+
27
+ .content {
25
28
  padding: $base-spacing;
26
29
  }
@@ -1,8 +1,11 @@
1
1
  module Administrate
2
2
  class ApplicationController < ActionController::Base
3
3
  def index
4
- @resources = resolver.resource_class.all
5
- @page = Administrate::Page::Table.new(dashboard)
4
+ @search_term = params[:search].to_s.strip
5
+ @resources = Administrate::Search.new(resource_resolver, @search_term).run
6
+ @resources = order.apply(@resources)
7
+ @resources = @resources.page(params[:page]).per(records_per_page)
8
+ @page = Administrate::Page::Table.new(dashboard, order: order)
6
9
  end
7
10
 
8
11
  def show
@@ -12,9 +15,7 @@ module Administrate
12
15
  end
13
16
 
14
17
  def new
15
- @page = Administrate::Page::Form.new(
16
- dashboard, resolver.resource_class.new
17
- )
18
+ @page = Administrate::Page::Form.new(dashboard, resource_class.new)
18
19
  end
19
20
 
20
21
  def edit
@@ -24,7 +25,7 @@ module Administrate
24
25
  end
25
26
 
26
27
  def create
27
- set_resource(resolver.resource_class.new(resource_params))
28
+ set_resource(resource_class.new(resource_params))
28
29
 
29
30
  if resource.save
30
31
  redirect_to(
@@ -63,15 +64,23 @@ module Administrate
63
64
 
64
65
  helper_method :nav_link_state
65
66
  def nav_link_state(resource)
66
- if resolver.resource_name.to_s.pluralize == resource.to_s
67
+ if resource_name.to_s.pluralize == resource.to_s
67
68
  :active
68
69
  else
69
70
  :inactive
70
71
  end
71
72
  end
72
73
 
74
+ def records_per_page
75
+ params[:per_page] || 20
76
+ end
77
+
78
+ def order
79
+ @order ||= Administrate::Order.new(params[:order], params[:direction])
80
+ end
81
+
73
82
  def dashboard
74
- @dashboard ||= resolver.dashboard_class.new
83
+ @dashboard ||= resource_resolver.dashboard_class.new
75
84
  end
76
85
 
77
86
  def set_resource(resource = nil)
@@ -80,7 +89,7 @@ module Administrate
80
89
  end
81
90
 
82
91
  def find_resource(param)
83
- resolver.resource_class.find(param)
92
+ resource_class.find(param)
84
93
  end
85
94
 
86
95
  def resource
@@ -88,7 +97,7 @@ module Administrate
88
97
  end
89
98
 
90
99
  def resource_params
91
- params.require(resolver.resource_name).permit(*permitted_attributes)
100
+ params.require(resource_name).permit(*permitted_attributes)
92
101
  end
93
102
 
94
103
  def permitted_attributes
@@ -96,21 +105,20 @@ module Administrate
96
105
  end
97
106
 
98
107
  def instance_variable
99
- "@#{resolver.resource_name}"
108
+ "@#{resource_name}"
100
109
  end
101
110
 
102
- def resolver
103
- @resolver ||= Administrate::ResourceResolver.new(resource_class)
104
- end
111
+ delegate :resource_class, :resource_name, to: :resource_resolver
105
112
 
106
- def resource_class
107
- params.fetch(:resource_class, controller_path).to_s
113
+ def resource_resolver
114
+ @resource_resolver ||=
115
+ Administrate::ResourceResolver.new(controller_path)
108
116
  end
109
117
 
110
118
  def translate(key)
111
119
  t(
112
120
  "administrate.controller.#{key}",
113
- resource: resolver.resource_title,
121
+ resource: resource_resolver.resource_title,
114
122
  )
115
123
  end
116
124
  end
@@ -1,8 +1,4 @@
1
1
  <ul class="sidebar__list">
2
- <div class="sidebar__logo">
3
- <%= image_tag "logo.svg" %>
4
- </div>
5
-
6
2
  <% DashboardManifest::DASHBOARDS.each do |resource| %>
7
3
  <li>
8
4
  <%= link_to(
@@ -2,8 +2,20 @@
2
2
  <thead>
3
3
  <tr>
4
4
  <% table_presenter.attribute_types.each do |attr_name, attr_type| %>
5
- <th class="cell-label cell-label--<%= attr_type.html_class %>">
6
- <%= attr_name.to_s.titleize %>
5
+ <th class="cell-label cell-label--<%= attr_type.html_class %>
6
+ cell-label--<%= table_presenter.ordered_html_class(attr_name) %>
7
+ ">
8
+ <%= link_to(params.merge(
9
+ table_presenter.order_params_for(attr_name)
10
+ )) do %>
11
+ <%= attr_name.to_s.titleize %>
12
+
13
+ <% if table_presenter.ordered_by?(attr_name) %>
14
+ <span class="cell-label__sort-indicator cell-label__sort-indicator--<%= table_presenter.ordered_html_class(attr_name) %>">
15
+ <%= inline_svg("administrate/sort_arrow.svg") %>
16
+ </span>
17
+ <% end %>
18
+ <% end %>
7
19
  </th>
8
20
  <% end %>
9
21
  <th colspan="2"></th>
@@ -1,3 +1,21 @@
1
+ <% content_for(:search) do %>
2
+ <form class="search">
3
+ <span class="search__icon">
4
+ <%= inline_svg "administrate/search.svg" %>
5
+ </span>
6
+ <input
7
+ type="text"
8
+ name="search"
9
+ class="search__input"
10
+ placeholder="Search"
11
+ value="<%= @search_term %>"
12
+ />
13
+ <span class="search__hint">
14
+ Press enter to search
15
+ </span>
16
+ </form>
17
+ <% end %>
18
+
1
19
  <header class="header">
2
20
  <h1 class="header-heading"><%= @page.resource_name.pluralize.titleize %></h1>
3
21
  <%= link_to(
@@ -8,3 +26,5 @@
8
26
  </header>
9
27
 
10
28
  <%= render "table", table_presenter: @page, resources: @resources %>
29
+
30
+ <%= paginate @resources %>
@@ -10,8 +10,8 @@
10
10
  <dl>
11
11
  <% @page.attributes.each do |attribute| %>
12
12
  <dt class="attribute-label"><%= attribute.name.titleize %></dt>
13
- <dd class="attribute-data--<%=attribute.html_class%>">
14
- <%= render_field attribute %>
15
- </dd>
13
+
14
+ <dd class="attribute-data--<%=attribute.html_class%>"
15
+ ><%= render_field attribute %></dd>
16
16
  <% end %>
17
17
  </dl>
@@ -1,9 +1,10 @@
1
- <% if field.data.any? %>
1
+ <% if field.resources.any? %>
2
2
  <%= render(
3
3
  "table",
4
4
  table_presenter: field.associated_table,
5
- resources: field.data
5
+ resources: field.resources
6
6
  ) %>
7
+ <span>Showing <%= field.limit %> of <%= field.data.count %>.</span>
7
8
  <% else %>
8
9
  <%= t("administrate.fields.has_many.none") %>
9
10
  <% end %>
@@ -1,7 +1,2 @@
1
1
  <%= f.label field.permitted_attribute %>
2
- <%= f.collection_select(
3
- field.permitted_attribute,
4
- field.candidate_records,
5
- :id,
6
- :to_s,
7
- ) %>
2
+ HasOne relationship forms are not supported yet. Sorry!
@@ -16,13 +16,15 @@
16
16
  <%= render "sidebar" -%>
17
17
  </div>
18
18
 
19
- <div class="content">
20
- <%= render "flashes" -%>
21
-
22
- <%= yield %>
23
-
24
- <%= render "javascript" %>
19
+ <div class="container">
20
+ <%= content_for(:search) %>
21
+ <div class="content">
22
+ <%= render "flashes" -%>
23
+ <%= yield %>
24
+ </div>
25
25
  </div>
26
26
  </main>
27
+
28
+ <%= render "javascript" %>
27
29
  </body>
28
30
  </html>
@@ -1,14 +1,19 @@
1
+ require "datetime_picker_rails"
2
+ require "inline_svg"
3
+ require "kaminari"
4
+ require "momentjs-rails"
1
5
  require "neat"
6
+ require "inline_svg"
2
7
  require "normalize-rails"
3
8
  require "selectize-rails"
4
- require "momentjs-rails"
5
- require "datetime_picker_rails"
6
9
 
7
10
  require "administrate/namespace"
8
11
  require "administrate/page/form"
9
12
  require "administrate/page/show"
10
13
  require "administrate/page/table"
14
+ require "administrate/order"
11
15
  require "administrate/resource_resolver"
16
+ require "administrate/search"
12
17
 
13
18
  module Administrate
14
19
  class Engine < ::Rails::Engine
@@ -11,6 +11,10 @@ module Administrate
11
11
  field_type.dasherize
12
12
  end
13
13
 
14
+ def self.searchable?
15
+ false
16
+ end
17
+
14
18
  def initialize(attribute, data, page, options = {})
15
19
  @attribute = attribute
16
20
  @data = data
@@ -16,7 +16,12 @@ module Administrate
16
16
  deferred_class == other.deferred_class && options == other.options
17
17
  end
18
18
 
19
- delegate :html_class, :permitted_attribute, to: :deferred_class
19
+ delegate(
20
+ :html_class,
21
+ :permitted_attribute,
22
+ :searchable?,
23
+ to: :deferred_class,
24
+ )
20
25
  end
21
26
  end
22
27
  end
@@ -3,6 +3,9 @@ require_relative "base"
3
3
  module Administrate
4
4
  module Field
5
5
  class Email < Field::Base
6
+ def self.searchable?
7
+ true
8
+ end
6
9
  end
7
10
  end
8
11
  end
@@ -4,16 +4,14 @@ require "administrate/page/table"
4
4
  module Administrate
5
5
  module Field
6
6
  class HasMany < Field::Base
7
- def associated_table
8
- Administrate::Page::Table.new(associated_dashboard)
9
- end
7
+ DEFAULT_LIMIT = 5
10
8
 
11
9
  def self.permitted_attribute(attribute)
12
10
  { "#{attribute.to_s.singularize}_ids".to_sym => [] }
13
11
  end
14
12
 
15
- def permitted_attribute
16
- self.class.permitted_attribute(attribute)
13
+ def associated_table
14
+ Administrate::Page::Table.new(associated_dashboard)
17
15
  end
18
16
 
19
17
  def attribute_key
@@ -24,6 +22,18 @@ module Administrate
24
22
  Object.const_get(associated_class_name).all
25
23
  end
26
24
 
25
+ def limit
26
+ options.fetch(:limit, DEFAULT_LIMIT)
27
+ end
28
+
29
+ def permitted_attribute
30
+ self.class.permitted_attribute(attribute)
31
+ end
32
+
33
+ def resources
34
+ data.limit(limit)
35
+ end
36
+
27
37
  private
28
38
 
29
39
  def associated_dashboard
@@ -1,4 +1,5 @@
1
1
  require_relative "base"
2
+ require_relative "belongs_to"
2
3
 
3
4
  module Administrate
4
5
  module Field
@@ -3,8 +3,12 @@ require_relative "base"
3
3
  module Administrate
4
4
  module Field
5
5
  class String < Field::Base
6
+ def self.searchable?
7
+ true
8
+ end
9
+
6
10
  def truncate
7
- data[0...truncation_length]
11
+ data.to_s[0...truncation_length]
8
12
  end
9
13
 
10
14
  private
@@ -0,0 +1,45 @@
1
+ module Administrate
2
+ class Order
3
+ def initialize(attribute = nil, direction = nil)
4
+ @attribute = attribute
5
+ @direction = direction || :asc
6
+ end
7
+
8
+ def apply(relation)
9
+ if relation.columns_hash.keys.include?(attribute.to_s)
10
+ relation.order(attribute => direction)
11
+ else
12
+ relation
13
+ end
14
+ end
15
+
16
+ def ordered_by?(attr)
17
+ attr.to_s == attribute.to_s
18
+ end
19
+
20
+ def order_params_for(attr)
21
+ {
22
+ order: attr,
23
+ direction: reversed_direction_param_for(attr)
24
+ }
25
+ end
26
+
27
+ attr_reader :direction
28
+
29
+ private
30
+
31
+ attr_reader :attribute
32
+
33
+ def reversed_direction_param_for(attr)
34
+ if ordered_by?(attr)
35
+ opposite_direction
36
+ else
37
+ :asc
38
+ end
39
+ end
40
+
41
+ def opposite_direction
42
+ direction.to_sym == :asc ? :desc : :asc
43
+ end
44
+ end
45
+ end
@@ -1,8 +1,9 @@
1
1
  module Administrate
2
2
  module Page
3
3
  class Base
4
- def initialize(dashboard)
4
+ def initialize(dashboard, options = {})
5
5
  @dashboard = dashboard
6
+ @options = options
6
7
  end
7
8
 
8
9
  def resource_name
@@ -26,7 +27,7 @@ module Administrate
26
27
  nil
27
28
  end
28
29
 
29
- attr_reader :dashboard
30
+ attr_reader :dashboard, :options
30
31
  end
31
32
  end
32
33
  end
@@ -20,6 +20,18 @@ module Administrate
20
20
  def to_partial_path
21
21
  "/dashboard/table"
22
22
  end
23
+
24
+ def ordered_html_class(attr)
25
+ ordered_by?(attr) && order.direction
26
+ end
27
+
28
+ delegate :ordered_by?, :order_params_for, to: :order
29
+
30
+ private
31
+
32
+ def order
33
+ options[:order] || Order.new
34
+ end
23
35
  end
24
36
  end
25
37
  end
@@ -0,0 +1,36 @@
1
+ module Administrate
2
+ class Search
3
+ def initialize(resolver, term)
4
+ @resolver = resolver
5
+ @term = term
6
+ end
7
+
8
+ def run
9
+ if @term.blank?
10
+ resource_class.all
11
+ else
12
+ resource_class.where(query, *search_terms)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ delegate :resource_class, to: :resolver
19
+
20
+ def query
21
+ search_attributes.map { |attr| "#{attr} ILIKE ?" }.join(" OR ")
22
+ end
23
+
24
+ def search_terms
25
+ ["%#{term}%"] * search_attributes.count
26
+ end
27
+
28
+ def search_attributes
29
+ resolver.dashboard_class::ATTRIBUTE_TYPES.select do |_, type|
30
+ type.searchable?
31
+ end.keys
32
+ end
33
+
34
+ attr_reader :resolver, :term
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -25,6 +25,13 @@ module Administrate
25
25
  template "dashboard.rb.erb", "app/dashboards/#{file_name}_dashboard.rb"
26
26
  end
27
27
 
28
+ def create_resource_controller
29
+ template(
30
+ "controller.rb.erb",
31
+ "app/controllers/admin/#{file_name.pluralize}_controller.rb",
32
+ )
33
+ end
34
+
28
35
  private
29
36
 
30
37
  def attributes
@@ -0,0 +1,19 @@
1
+ module Admin
2
+ class <%= class_name.pluralize %>Controller < Admin::ApplicationController
3
+ # To customize the behavior of this controller,
4
+ # simply overwrite any of the RESTful actions. For example:
5
+ #
6
+ # def index
7
+ # super
8
+ # @resources = <%= class_name %>.all.paginate(10, params[:page])
9
+ # end
10
+
11
+ # Define a custom finder by overriding the `find_resource` method:
12
+ # def find_resource(param)
13
+ # <%= class_name %>.find_by!(slug: param)
14
+ # end
15
+
16
+ # See https://administrate-docs.herokuapp.com/customizing_controller_actions
17
+ # for more information
18
+ end
19
+ end
@@ -1,4 +1,4 @@
1
- # All Administrate controllers inherit from this `ApplicationController`,
1
+ # All Administrate controllers inherit from this `Admin::ApplicationController`,
2
2
  # making it the ideal place to put authentication logic or other
3
3
  # before_filters.
4
4
  #
@@ -11,13 +11,9 @@ class Admin::ApplicationController < Administrate::ApplicationController
11
11
  # TODO Add authentication logic here.
12
12
  end
13
13
 
14
- def index
15
- super
16
-
17
- flash.now[:alert] =
18
- "For performance, Administrate limits the index page to show 20 items.
19
- Customize this action to update/remove the limit,
20
- or implement the pagination library of your choice."
21
- @resources = @resources.limit(20)
22
- end
14
+ # Override this value to specify the number of elements to display at a time
15
+ # on index pages. Defaults to 20.
16
+ # def records_per_page
17
+ # params[:per_page] || 20
18
+ # end
23
19
  end
@@ -1,15 +1,7 @@
1
1
  namespace :admin do
2
- DashboardManifest::DASHBOARDS.each do |resource_class|
3
- resources(
4
- resource_class,
5
- controller: :application,
6
- resource_class: resource_class,
7
- )
2
+ DashboardManifest::DASHBOARDS.each do |dashboard_resource|
3
+ resources dashboard_resource
8
4
  end
9
5
 
10
- root(
11
- action: :index,
12
- controller: :application,
13
- resource_class: DashboardManifest::ROOT_DASHBOARD,
14
- )
6
+ root controller: DashboardManifest::ROOT_DASHBOARD, action: :index
15
7
  end
metadata CHANGED
@@ -1,127 +1,155 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson Wright
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-16 00:00:00.000000000 Z
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: neat
14
+ name: autoprefixer-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: datetime_picker_rails
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.1'
33
+ version: 0.0.4
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.1'
40
+ version: 0.0.4
27
41
  - !ruby/object:Gem::Dependency
28
- name: sass
42
+ name: inline_svg
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '3.4'
47
+ version: '0.6'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '3.4'
54
+ version: '0.6'
41
55
  - !ruby/object:Gem::Dependency
42
- name: normalize-rails
56
+ name: kaminari
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '3.0'
61
+ version: '0.16'
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '3.0'
68
+ version: '0.16'
55
69
  - !ruby/object:Gem::Dependency
56
- name: rails
70
+ name: momentjs-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.9.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.9.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: neat
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - "~>"
60
88
  - !ruby/object:Gem::Version
61
- version: '4.2'
89
+ version: '1.1'
62
90
  type: :runtime
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
94
  - - "~>"
67
95
  - !ruby/object:Gem::Version
68
- version: '4.2'
96
+ version: '1.1'
69
97
  - !ruby/object:Gem::Dependency
70
- name: selectize-rails
98
+ name: normalize-rails
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - "~>"
74
102
  - !ruby/object:Gem::Version
75
- version: '0.6'
103
+ version: '3.0'
76
104
  type: :runtime
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: '0.6'
110
+ version: '3.0'
83
111
  - !ruby/object:Gem::Dependency
84
- name: momentjs-rails
112
+ name: rails
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - ">="
115
+ - - "~>"
88
116
  - !ruby/object:Gem::Version
89
- version: 2.9.0
117
+ version: '4.2'
90
118
  type: :runtime
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - ">="
122
+ - - "~>"
95
123
  - !ruby/object:Gem::Version
96
- version: 2.9.0
124
+ version: '4.2'
97
125
  - !ruby/object:Gem::Dependency
98
- name: datetime_picker_rails
126
+ name: sass
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - "~>"
102
130
  - !ruby/object:Gem::Version
103
- version: 0.0.4
131
+ version: '3.4'
104
132
  type: :runtime
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
136
  - - "~>"
109
137
  - !ruby/object:Gem::Version
110
- version: 0.0.4
138
+ version: '3.4'
111
139
  - !ruby/object:Gem::Dependency
112
- name: autoprefixer-rails
140
+ name: selectize-rails
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
- - - ">="
143
+ - - "~>"
116
144
  - !ruby/object:Gem::Version
117
- version: '0'
145
+ version: '0.6'
118
146
  type: :runtime
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
- - - ">="
150
+ - - "~>"
123
151
  - !ruby/object:Gem::Version
124
- version: '0'
152
+ version: '0.6'
125
153
  description: |
126
154
  Administrate is heavily inspired by projects like Rails Admin and ActiveAdmin,
127
155
  but aims to provide a better user experience for site admins,
@@ -143,7 +171,10 @@ extra_rdoc_files: []
143
171
  files:
144
172
  - LICENSE
145
173
  - Rakefile
174
+ - app/assets/images/administrate/search.svg
175
+ - app/assets/images/administrate/sort_arrow.svg
146
176
  - app/assets/javascripts/administrate/application.js
177
+ - app/assets/javascripts/administrate/components/_search.js
147
178
  - app/assets/javascripts/administrate/components/date_time_picker.js
148
179
  - app/assets/javascripts/administrate/components/has_many_form.js
149
180
  - app/assets/javascripts/administrate/components/table.js
@@ -169,6 +200,8 @@ files:
169
200
  - app/assets/stylesheets/administrate/components/_date_time_picker.scss
170
201
  - app/assets/stylesheets/administrate/components/_form.scss
171
202
  - app/assets/stylesheets/administrate/components/_header.scss
203
+ - app/assets/stylesheets/administrate/components/_pagination.scss
204
+ - app/assets/stylesheets/administrate/components/_search.scss
172
205
  - app/assets/stylesheets/administrate/components/_table.scss
173
206
  - app/assets/stylesheets/administrate/layout.scss
174
207
  - app/assets/stylesheets/administrate/mixins/_mixins.scss
@@ -233,15 +266,18 @@ files:
233
266
  - lib/administrate/fields/polymorphic.rb
234
267
  - lib/administrate/fields/string.rb
235
268
  - lib/administrate/namespace.rb
269
+ - lib/administrate/order.rb
236
270
  - lib/administrate/page.rb
237
271
  - lib/administrate/page/base.rb
238
272
  - lib/administrate/page/form.rb
239
273
  - lib/administrate/page/show.rb
240
274
  - lib/administrate/page/table.rb
241
275
  - lib/administrate/resource_resolver.rb
276
+ - lib/administrate/search.rb
242
277
  - lib/administrate/version.rb
243
278
  - lib/generators/administrate/dashboard/USAGE
244
279
  - lib/generators/administrate/dashboard/dashboard_generator.rb
280
+ - lib/generators/administrate/dashboard/templates/controller.rb.erb
245
281
  - lib/generators/administrate/dashboard/templates/dashboard.rb.erb
246
282
  - lib/generators/administrate/install/install_generator.rb
247
283
  - lib/generators/administrate/install/templates/application_controller.rb