keystone_ui-pages 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/keystone_ui/pages/manage/pages_controller.rb +18 -6
- data/app/helpers/keystone_ui/pages/editor_helper.rb +1 -1
- data/app/models/keystone_ui/pages/page.rb +12 -0
- data/app/views/keystone_ui/pages/manage/pages/edit.html.erb +1 -1
- data/app/views/keystone_ui/pages/manage/pages/index.html.erb +3 -3
- data/app/views/keystone_ui/pages/manage/pages/new.html.erb +8 -4
- data/lib/keystone_ui/pages/version.rb +1 -1
- data/lib/keystone_ui/pages.rb +19 -2
- data/the_local/agents/keystone_ui-pages-develop.md +22 -0
- data/the_local/interface.yml +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ebfd45f732eefa22bd08b4a5abd3c13ff88a2fa65c55a5309c89c8b21468c69c
|
|
4
|
+
data.tar.gz: bb309abcbff6e6d5a12aa1096db65c1a3d298ca1db781ed4c3110a5b4e6334a3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 845983515d8a34e9d1c4ef3faff043e2ec832461b4fbf9be78b246d9fc9aba12c9823b69f3b573879df2755dd30e7041a7b1865939cab16d53ee1dad64f6a94e
|
|
7
|
+
data.tar.gz: dc35e48a37f83ed5b6e61d0d41b22e92139017c8b0fa9cb1cabb458e33bb61a69b38d625800a6f7f7113fe5f3ae80689691f5c2b4a2eafbef3f2db8753b3c4cf
|
|
@@ -8,15 +8,21 @@ module KeystoneUi
|
|
|
8
8
|
class PagesController < BaseController
|
|
9
9
|
def index
|
|
10
10
|
@archived = params[:archived].present?
|
|
11
|
+
@place = chosen_place
|
|
11
12
|
@pages = owned_pages.public_send(@archived ? :archived : :current).order(:name)
|
|
13
|
+
@pages = @pages.where(place: @place) if @place
|
|
12
14
|
@printable = Printer.chrome.present?
|
|
13
15
|
end
|
|
14
16
|
|
|
15
17
|
def new
|
|
18
|
+
@place = chosen_place
|
|
19
|
+
@default_name = Page.new(place: @place, owner: page_owner).default_name
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
def create
|
|
19
|
-
page = Page.
|
|
23
|
+
page = Page.new(params.require(:page).permit(:name, :slug, :place).merge(owner: page_owner))
|
|
24
|
+
return render(:new, status: :unprocessable_entity) unless page.save
|
|
25
|
+
|
|
20
26
|
redirect_to manage_page_path(page)
|
|
21
27
|
end
|
|
22
28
|
|
|
@@ -33,7 +39,7 @@ module KeystoneUi
|
|
|
33
39
|
@page = owned_pages.find(params[:id])
|
|
34
40
|
return render(:edit, status: :unprocessable_entity) unless @page.update(params.require(:page).permit(:name, :slug, :place))
|
|
35
41
|
|
|
36
|
-
redirect_to manage_pages_path
|
|
42
|
+
redirect_to manage_pages_path(place: @page.place)
|
|
37
43
|
end
|
|
38
44
|
|
|
39
45
|
def publish
|
|
@@ -49,17 +55,23 @@ module KeystoneUi
|
|
|
49
55
|
end
|
|
50
56
|
|
|
51
57
|
def archive
|
|
52
|
-
owned_pages.find(params[:id])
|
|
53
|
-
|
|
58
|
+
page = owned_pages.find(params[:id])
|
|
59
|
+
page.archive
|
|
60
|
+
redirect_to manage_pages_path(place: page.place)
|
|
54
61
|
end
|
|
55
62
|
|
|
56
63
|
def restore
|
|
57
|
-
owned_pages.find(params[:id])
|
|
58
|
-
|
|
64
|
+
page = owned_pages.find(params[:id])
|
|
65
|
+
page.restore
|
|
66
|
+
redirect_to manage_pages_path(place: page.place)
|
|
59
67
|
end
|
|
60
68
|
|
|
61
69
|
private
|
|
62
70
|
|
|
71
|
+
def chosen_place
|
|
72
|
+
params[:place] if KeystoneUi::Pages.places.key?(params[:place])
|
|
73
|
+
end
|
|
74
|
+
|
|
63
75
|
def local_address?(address)
|
|
64
76
|
address.to_s.match?(%r{\A/(?![/\\])})
|
|
65
77
|
end
|
|
@@ -32,7 +32,7 @@ module KeystoneUi
|
|
|
32
32
|
redo_url: manage_page_redo_path(page),
|
|
33
33
|
undoable: page.undo_history.any?,
|
|
34
34
|
redoable: page.undone_changes.any?,
|
|
35
|
-
back_url: session.dig(:keystone_ui_pages_return_to, page.id.to_s) || manage_pages_path,
|
|
35
|
+
back_url: session.dig(:keystone_ui_pages_return_to, page.id.to_s) || manage_pages_path(place: page.place),
|
|
36
36
|
live_url: (manage_page_live_path(page) if page.live_version),
|
|
37
37
|
token: form_authenticity_token
|
|
38
38
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "securerandom"
|
|
3
4
|
require "keystone_ui/pages/document"
|
|
4
5
|
|
|
5
6
|
module KeystoneUi
|
|
@@ -17,6 +18,11 @@ module KeystoneUi
|
|
|
17
18
|
scope :archived, -> { where.not(archived_at: nil) }
|
|
18
19
|
scope :current, -> { where(archived_at: nil) }
|
|
19
20
|
|
|
21
|
+
before_validation(on: :create) do
|
|
22
|
+
self.name = default_name if name.blank?
|
|
23
|
+
self.slug = SecureRandom.hex(4) if slug.blank?
|
|
24
|
+
end
|
|
25
|
+
|
|
20
26
|
validates :name, :slug, presence: true
|
|
21
27
|
validates :slug, uniqueness: { scope: %i[owner_type owner_id] }
|
|
22
28
|
validates :place, inclusion: { in: -> { KeystoneUi::Pages.places.keys } }, allow_nil: true, if: -> { KeystoneUi::Pages.places.any? }
|
|
@@ -81,6 +87,12 @@ module KeystoneUi
|
|
|
81
87
|
def next_number
|
|
82
88
|
(versions.maximum(:number) || 0) + 1
|
|
83
89
|
end
|
|
90
|
+
|
|
91
|
+
def default_name
|
|
92
|
+
word = KeystoneUi::Pages.place_settings.dig(place, :default_name) || "Page"
|
|
93
|
+
used = Page.where(owner: owner, place: place).pluck(:name).filter_map { |taken| taken[/\A#{Regexp.escape(word)} (\d+)\z/, 1]&.to_i }
|
|
94
|
+
"#{word} #{(used.max || 0) + 1}"
|
|
95
|
+
end
|
|
84
96
|
end
|
|
85
97
|
end
|
|
86
98
|
end
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<label class="ks-label mb-1">Name</label>
|
|
10
10
|
<%= ui_input(name: "page[name]", value: @page.name) %>
|
|
11
11
|
|
|
12
|
-
<label class="ks-label mb-1">
|
|
12
|
+
<label class="ks-label mb-1">URL slug</label>
|
|
13
13
|
<%= ui_input(name: "page[slug]", value: @page.slug) %>
|
|
14
14
|
|
|
15
15
|
<% if KeystoneUi::Pages.places.any? %>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<%= ui_page(max_width: :xl) do %>
|
|
2
|
-
<%= ui_page_header(title: @archived ? "Archived pages" : "Pages", action_url: (new_manage_page_path unless @archived), action_label: "Create") do |header| %>
|
|
3
|
-
<% header.action { ui_button(label: "Create", href: new_manage_page_path) } unless @archived %>
|
|
2
|
+
<%= ui_page_header(title: @archived ? "Archived pages" : "Pages", action_url: (new_manage_page_path(place: @place) unless @archived), action_label: "Create") do |header| %>
|
|
3
|
+
<% header.action { ui_button(label: "Create", href: new_manage_page_path(place: @place)) } unless @archived %>
|
|
4
4
|
<% end %>
|
|
5
5
|
|
|
6
6
|
<p class="mb-4 text-sm">
|
|
7
|
-
<%= @archived ? link_to("Show current pages", manage_pages_path) : link_to("Show archived", manage_pages_path(archived: 1)) %>
|
|
7
|
+
<%= @archived ? link_to("Show current pages", manage_pages_path(place: @place)) : link_to("Show archived", manage_pages_path(archived: 1, place: @place)) %>
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
10
|
<div class="ks-table overflow-x-auto">
|
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
<%= ui_page_header(title: "New page") %>
|
|
3
3
|
|
|
4
4
|
<%= ui_form(action: manage_pages_path, method: :post) do %>
|
|
5
|
+
<%= hidden_field_tag "page[place]", @place if @place %>
|
|
6
|
+
|
|
5
7
|
<label class="ks-label mb-1">Name</label>
|
|
6
|
-
<%= ui_input(name: "page[name]", placeholder:
|
|
8
|
+
<%= ui_input(name: "page[name]", placeholder: @default_name) %>
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
<% if KeystoneUi::Pages.slugged?(@place) %>
|
|
11
|
+
<label class="ks-label mb-1">URL slug</label>
|
|
12
|
+
<%= ui_input(name: "page[slug]", placeholder: "e.g. pricing") %>
|
|
13
|
+
<% end %>
|
|
10
14
|
|
|
11
|
-
<% if KeystoneUi::Pages.places.any? %>
|
|
15
|
+
<% if !@place && KeystoneUi::Pages.places.any? %>
|
|
12
16
|
<label class="ks-label mb-1">Place</label>
|
|
13
17
|
<%= ui_select(name: "page[place]", options: KeystoneUi::Pages.places.invert.to_a) %>
|
|
14
18
|
<% end %>
|
data/lib/keystone_ui/pages.rb
CHANGED
|
@@ -9,7 +9,7 @@ require "keystone_ui/pages/engine"
|
|
|
9
9
|
module KeystoneUi
|
|
10
10
|
module Pages
|
|
11
11
|
class << self
|
|
12
|
-
attr_writer :base_controller, :layout, :editor_layout, :pdf_stylesheet, :
|
|
12
|
+
attr_writer :base_controller, :layout, :editor_layout, :pdf_stylesheet, :access_exceptions
|
|
13
13
|
attr_accessor :edit_check_method, :view_check_method, :values_method, :owner_method, :refusal_method, :chrome_path
|
|
14
14
|
|
|
15
15
|
def base_controller
|
|
@@ -29,7 +29,24 @@ module KeystoneUi
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def places
|
|
32
|
-
@places || {}
|
|
32
|
+
(@places || {}).merge(place_settings.transform_values { |settings| settings[:label] })
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def places=(labels)
|
|
36
|
+
@places = labels
|
|
37
|
+
@place_settings = {}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def register_place(key, label:, default_name: "Page", slug: true)
|
|
41
|
+
place_settings[key.to_s] = { label: label, default_name: default_name, slug: slug }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def place_settings
|
|
45
|
+
@place_settings ||= {}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def slugged?(place)
|
|
49
|
+
place_settings.dig(place.to_s, :slug) != false
|
|
33
50
|
end
|
|
34
51
|
|
|
35
52
|
def access_exceptions
|
|
@@ -51,6 +51,15 @@ inherit from the base controller, so define it there.
|
|
|
51
51
|
When it is not empty, the New page form offers them, a page with a place not
|
|
52
52
|
in it is refused, and the page list shows each page's place. The view check
|
|
53
53
|
reads it as `page.place`. Unset, pages have no place.
|
|
54
|
+
- `KeystoneUi::Pages.register_place("client_report", label: "Client report", default_name: "Report template", slug: false)`
|
|
55
|
+
— adds one place with its own settings, so each part of a host app registers
|
|
56
|
+
the place it uses and two registrations never replace each other. `label:` is
|
|
57
|
+
what editors see. `default_name:` is the word a page created with no name
|
|
58
|
+
starts with, followed by the next number among that owner's pages in that
|
|
59
|
+
place, so "Report template 1", then "Report template 2"; it defaults to
|
|
60
|
+
"Page". `slug:` says whether the place's pages have a URL slug; it defaults to
|
|
61
|
+
true. Registered places are offered alongside any set with `places =`, and
|
|
62
|
+
`places = nil` clears both.
|
|
54
63
|
- `KeystoneUi::Pages.access_exceptions = { "public_preview" => "Public preview" }`
|
|
55
64
|
— a hash of the exceptions an editor can set on a page, each stored value to
|
|
56
65
|
its label. When it is not empty, the builder's top bar has an Access exception
|
|
@@ -312,6 +321,19 @@ The catalog offers these Keystone UI components by default: `button`,
|
|
|
312
321
|
from `--ks-spacing`. The page builder has no setting of its own for these:
|
|
313
322
|
a host changes them through its keystone_ui theme values. A section saved
|
|
314
323
|
without either draws as it did before.
|
|
324
|
+
- **A place's page list** at `/pages/manage/pages?place=client_report` shows
|
|
325
|
+
only that place's pages, and its Create and archived links keep the place.
|
|
326
|
+
With no place, or one the host does not name, the list shows every page. For
|
|
327
|
+
a page with a place, the redirects after saving settings, archiving and
|
|
328
|
+
restoring go to that place's list, and so does the builder's Back link unless
|
|
329
|
+
the host passed its own `return_to`.
|
|
330
|
+
- **The New page form** at `/pages/manage/pages/new` saves a blank name from
|
|
331
|
+
the place's `default_name` and a blank slug as eight random hex characters,
|
|
332
|
+
and shows that name as the Name field's placeholder. A host linking to it
|
|
333
|
+
with `new_manage_page_path(place: "client_report")` creates the page in that
|
|
334
|
+
place and offers no place choice. The URL slug field shows unless the place
|
|
335
|
+
was registered with `slug: false`. A place the host does not name in the link
|
|
336
|
+
is ignored, and one posted to create is refused with the form shown again.
|
|
315
337
|
- **A page's settings** at `/pages/manage/pages/:id/edit` change its name, slug
|
|
316
338
|
and place after it is created. A slug another page of the same owner uses, or
|
|
317
339
|
a place the host does not name, is refused with a message and changes nothing.
|
data/the_local/interface.yml
CHANGED
|
@@ -11,6 +11,7 @@ develop:
|
|
|
11
11
|
- KeystoneUi::Pages.view_check_method
|
|
12
12
|
- KeystoneUi::Pages.places
|
|
13
13
|
- KeystoneUi::Pages.access_exceptions
|
|
14
|
+
- KeystoneUi::Pages.register_place
|
|
14
15
|
- KeystoneUi::Pages.values_method
|
|
15
16
|
- KeystoneUi::Pages.edit_check_method
|
|
16
17
|
- KeystoneUi::Pages.refusal_method
|