glib-web 8.1.0 → 8.2.1
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/concerns/glib/json/libs.rb +16 -0
- data/app/controllers/glib/glib_direct_uploads_controller.rb +2 -1
- data/app/helpers/glib/app_feature_support_helper.rb +33 -8
- data/app/helpers/glib/json_ui/view_builder/fields.rb +110 -9
- data/app/helpers/glib/json_ui/view_builder.rb +29 -0
- data/app/jobs/glib/scheduled_job.rb +581 -0
- data/app/jobs/glib/scheduled_job_tick.rb +21 -0
- data/app/models/glib/scheduled_job_run.rb +16 -0
- data/app/views/json_ui/garage/actions/sheet_content.json.jbuilder +1 -1
- data/app/views/json_ui/garage/forms/_action_text_conversion.json.jbuilder +12 -0
- data/app/views/json_ui/garage/forms/action_text.json.jbuilder +57 -0
- data/app/views/json_ui/garage/forms/action_text_attachment.json.jbuilder +7 -0
- data/app/views/json_ui/garage/forms/action_text_conversion.json.jbuilder +5 -0
- data/app/views/json_ui/garage/forms/action_text_library.json.jbuilder +26 -0
- data/app/views/json_ui/garage/forms/action_text_mentions.json.jbuilder +4 -0
- data/app/views/json_ui/garage/forms/action_text_preview.json.jbuilder +9 -0
- data/app/views/json_ui/garage/forms/dialogs_form.json.jbuilder +10 -10
- data/app/views/json_ui/garage/forms/dirty_prompt.json.jbuilder +1 -1
- data/app/views/json_ui/garage/forms/dynamic_group.json.jbuilder +1 -1
- data/app/views/json_ui/garage/forms/index.json.jbuilder +6 -0
- data/app/views/json_ui/garage/forms/pickers.json.jbuilder +7 -0
- data/app/views/json_ui/garage/forms/show_hide.json.jbuilder +1 -1
- data/app/views/json_ui/garage/test_page/_header.json.jbuilder +6 -0
- data/app/views/json_ui/garage/test_page/charts.json.jbuilder +4 -2
- data/app/views/json_ui/garage/test_page/fields_actionText.json.jbuilder +189 -0
- data/app/views/json_ui/garage/test_page/fields_richText.json.jbuilder +45 -1
- data/app/views/json_ui/garage/test_page/fields_sign.json.jbuilder +34 -3
- data/app/views/json_ui/garage/test_page/form_dirty_fields.json.jbuilder +1 -1
- data/app/views/json_ui/garage/test_page/form_dirty_hooks.json.jbuilder +22 -0
- data/app/views/json_ui/garage/test_page/form_hidden_panels.json.jbuilder +105 -0
- data/app/views/json_ui/garage/views/charts.json.jbuilder +4 -2
- data/app/views/layouts/json_ui/renderer.html.erb +11 -1
- data/engines/blog/README.md +172 -0
- data/engines/blog/app/assets/stylesheets/glib/blog/admin.css +855 -0
- data/engines/blog/app/assets/stylesheets/glib/blog/themes/clean.css +816 -0
- data/engines/blog/app/assets/stylesheets/glib/blog/themes/editorial.css +631 -0
- data/engines/blog/app/controllers/concerns/glib/blog/admin/media_listing.rb +27 -0
- data/engines/blog/app/controllers/concerns/glib/blog/pagination.rb +14 -0
- data/engines/blog/app/controllers/glib/blog/admin/application_controller.rb +28 -0
- data/engines/blog/app/controllers/glib/blog/admin/authors_controller.rb +55 -0
- data/engines/blog/app/controllers/glib/blog/admin/categories_controller.rb +53 -0
- data/engines/blog/app/controllers/glib/blog/admin/comment_replies_controller.rb +34 -0
- data/engines/blog/app/controllers/glib/blog/admin/comments_controller.rb +50 -0
- data/engines/blog/app/controllers/glib/blog/admin/dashboards_controller.rb +34 -0
- data/engines/blog/app/controllers/glib/blog/admin/direct_uploads_controller.rb +30 -0
- data/engines/blog/app/controllers/glib/blog/admin/editor_attachments_controller.rb +16 -0
- data/engines/blog/app/controllers/glib/blog/admin/media_item_trashes_controller.rb +43 -0
- data/engines/blog/app/controllers/glib/blog/admin/media_items_controller.rb +61 -0
- data/engines/blog/app/controllers/glib/blog/admin/media_picks_controller.rb +19 -0
- data/engines/blog/app/controllers/glib/blog/admin/post_bulk_actions_controller.rb +33 -0
- data/engines/blog/app/controllers/glib/blog/admin/posts_controller.rb +79 -0
- data/engines/blog/app/controllers/glib/blog/admin/settings_controller.rb +27 -0
- data/engines/blog/app/controllers/glib/blog/admin/tags_controller.rb +46 -0
- data/engines/blog/app/controllers/glib/blog/application_controller.rb +90 -0
- data/engines/blog/app/controllers/glib/blog/authors_controller.rb +15 -0
- data/engines/blog/app/controllers/glib/blog/categories_controller.rb +15 -0
- data/engines/blog/app/controllers/glib/blog/comments_controller.rb +41 -0
- data/engines/blog/app/controllers/glib/blog/posts_controller.rb +47 -0
- data/engines/blog/app/controllers/glib/blog/tags_controller.rb +15 -0
- data/engines/blog/app/helpers/glib/blog/admin_helper.rb +57 -0
- data/engines/blog/app/helpers/glib/blog/comments_helper.rb +16 -0
- data/engines/blog/app/helpers/glib/blog/post_list_helper.rb +26 -0
- data/engines/blog/app/helpers/glib/blog/theme_helper.rb +85 -0
- data/engines/blog/app/jobs/glib/blog/purge_trash_job.rb +13 -0
- data/engines/blog/app/models/concerns/glib/blog/sluggable.rb +72 -0
- data/engines/blog/app/models/concerns/glib/blog/uses_media.rb +35 -0
- data/engines/blog/app/models/glib/blog/application_record.rb +7 -0
- data/engines/blog/app/models/glib/blog/author.rb +47 -0
- data/engines/blog/app/models/glib/blog/category.rb +53 -0
- data/engines/blog/app/models/glib/blog/comment.rb +66 -0
- data/engines/blog/app/models/glib/blog/comment_token.rb +30 -0
- data/engines/blog/app/models/glib/blog/media_item.rb +121 -0
- data/engines/blog/app/models/glib/blog/media_upload.rb +97 -0
- data/engines/blog/app/models/glib/blog/media_usage.rb +10 -0
- data/engines/blog/app/models/glib/blog/post.rb +110 -0
- data/engines/blog/app/models/glib/blog/post_view.rb +24 -0
- data/engines/blog/app/models/glib/blog/setting.rb +55 -0
- data/engines/blog/app/models/glib/blog/slug_redirect.rb +7 -0
- data/engines/blog/app/models/glib/blog/tag.rb +15 -0
- data/engines/blog/app/models/glib/blog/tagging.rb +10 -0
- data/engines/blog/app/policies/glib/blog/admin/author_policy.rb +11 -0
- data/engines/blog/app/policies/glib/blog/admin/category_policy.rb +11 -0
- data/engines/blog/app/policies/glib/blog/admin/comment_policy.rb +16 -0
- data/engines/blog/app/policies/glib/blog/admin/comment_reply_policy.rb +12 -0
- data/engines/blog/app/policies/glib/blog/admin/dashboard_policy.rb +11 -0
- data/engines/blog/app/policies/glib/blog/admin/direct_upload_policy.rb +11 -0
- data/engines/blog/app/policies/glib/blog/admin/editor_attachment_policy.rb +11 -0
- data/engines/blog/app/policies/glib/blog/admin/media_item_policy.rb +20 -0
- data/engines/blog/app/policies/glib/blog/admin/media_item_trash_policy.rb +11 -0
- data/engines/blog/app/policies/glib/blog/admin/media_pick_policy.rb +11 -0
- data/engines/blog/app/policies/glib/blog/admin/post_bulk_action_policy.rb +12 -0
- data/engines/blog/app/policies/glib/blog/admin/post_policy.rb +16 -0
- data/engines/blog/app/policies/glib/blog/admin/setting_policy.rb +11 -0
- data/engines/blog/app/policies/glib/blog/admin/tag_policy.rb +11 -0
- data/engines/blog/app/policies/glib/blog/application_policy.rb +16 -0
- data/engines/blog/app/policies/glib/blog/author_policy.rb +9 -0
- data/engines/blog/app/policies/glib/blog/category_policy.rb +9 -0
- data/engines/blog/app/policies/glib/blog/comment_policy.rb +11 -0
- data/engines/blog/app/policies/glib/blog/post_policy.rb +9 -0
- data/engines/blog/app/policies/glib/blog/tag_policy.rb +9 -0
- data/engines/blog/app/views/glib/blog/admin/_delete_button.json.jbuilder +24 -0
- data/engines/blog/app/views/glib/blog/admin/_nav.json.jbuilder +45 -0
- data/engines/blog/app/views/glib/blog/admin/_status_chip.json.jbuilder +2 -0
- data/engines/blog/app/views/glib/blog/admin/authors/_form.json.jbuilder +17 -0
- data/engines/blog/app/views/glib/blog/admin/authors/edit.json.jbuilder +7 -0
- data/engines/blog/app/views/glib/blog/admin/authors/index.json.jbuilder +50 -0
- data/engines/blog/app/views/glib/blog/admin/authors/new.json.jbuilder +11 -0
- data/engines/blog/app/views/glib/blog/admin/categories/_form.json.jbuilder +13 -0
- data/engines/blog/app/views/glib/blog/admin/categories/edit.json.jbuilder +7 -0
- data/engines/blog/app/views/glib/blog/admin/categories/index.json.jbuilder +68 -0
- data/engines/blog/app/views/glib/blog/admin/categories/new.json.jbuilder +7 -0
- data/engines/blog/app/views/glib/blog/admin/comments/_moderation_buttons.json.jbuilder +35 -0
- data/engines/blog/app/views/glib/blog/admin/comments/index.json.jbuilder +59 -0
- data/engines/blog/app/views/glib/blog/admin/dashboards/show.json.jbuilder +109 -0
- data/engines/blog/app/views/glib/blog/admin/media_item_trashes/index.json.jbuilder +32 -0
- data/engines/blog/app/views/glib/blog/admin/media_items/_rows.json.jbuilder +32 -0
- data/engines/blog/app/views/glib/blog/admin/media_items/edit.json.jbuilder +68 -0
- data/engines/blog/app/views/glib/blog/admin/media_items/index.json.jbuilder +68 -0
- data/engines/blog/app/views/glib/blog/admin/media_items/new.json.jbuilder +18 -0
- data/engines/blog/app/views/glib/blog/admin/media_picks/index.json.jbuilder +29 -0
- data/engines/blog/app/views/glib/blog/admin/posts/_form.json.jbuilder +104 -0
- data/engines/blog/app/views/glib/blog/admin/posts/edit.json.jbuilder +1 -0
- data/engines/blog/app/views/glib/blog/admin/posts/index.json.jbuilder +109 -0
- data/engines/blog/app/views/glib/blog/admin/posts/new.json.jbuilder +1 -0
- data/engines/blog/app/views/glib/blog/admin/settings/edit.json.jbuilder +55 -0
- data/engines/blog/app/views/glib/blog/admin/tags/_form.json.jbuilder +6 -0
- data/engines/blog/app/views/glib/blog/admin/tags/edit.json.jbuilder +7 -0
- data/engines/blog/app/views/glib/blog/admin/tags/index.json.jbuilder +30 -0
- data/engines/blog/app/views/glib/blog/admin/tags/new.json.jbuilder +7 -0
- data/engines/blog/app/views/glib/blog/authors/show.json.jbuilder +4 -0
- data/engines/blog/app/views/glib/blog/categories/show.json.jbuilder +4 -0
- data/engines/blog/app/views/glib/blog/comments/pending.json.jbuilder +7 -0
- data/engines/blog/app/views/glib/blog/media_items/_media_item.html.erb +14 -0
- data/engines/blog/app/views/glib/blog/posts/_comment.json.jbuilder +23 -0
- data/engines/blog/app/views/glib/blog/posts/_comment_form.json.jbuilder +14 -0
- data/engines/blog/app/views/glib/blog/posts/_comments.json.jbuilder +21 -0
- data/engines/blog/app/views/glib/blog/posts/index.json.jbuilder +4 -0
- data/engines/blog/app/views/glib/blog/posts/show.json.jbuilder +5 -0
- data/engines/blog/app/views/glib/blog/shared/errors.json.jbuilder +5 -0
- data/engines/blog/app/views/glib/blog/tags/show.json.jbuilder +3 -0
- data/engines/blog/app/views/glib/blog/themes/_nav_links.json.jbuilder +12 -0
- data/engines/blog/app/views/glib/blog/themes/clean/_brand.json.jbuilder +11 -0
- data/engines/blog/app/views/glib/blog/themes/clean/_card.json.jbuilder +15 -0
- data/engines/blog/app/views/glib/blog/themes/clean/_featured.json.jbuilder +23 -0
- data/engines/blog/app/views/glib/blog/themes/clean/_footer.json.jbuilder +15 -0
- data/engines/blog/app/views/glib/blog/themes/clean/_header.json.jbuilder +9 -0
- data/engines/blog/app/views/glib/blog/themes/clean/_post.json.jbuilder +98 -0
- data/engines/blog/app/views/glib/blog/themes/clean/_post_list.json.jbuilder +40 -0
- data/engines/blog/app/views/glib/blog/themes/clean/_post_rows.json.jbuilder +10 -0
- data/engines/blog/app/views/glib/blog/themes/editorial/_footer.json.jbuilder +15 -0
- data/engines/blog/app/views/glib/blog/themes/editorial/_header.json.jbuilder +11 -0
- data/engines/blog/app/views/glib/blog/themes/editorial/_post.json.jbuilder +62 -0
- data/engines/blog/app/views/glib/blog/themes/editorial/_post_list.json.jbuilder +25 -0
- data/engines/blog/app/views/glib/blog/themes/editorial/_post_rows.json.jbuilder +18 -0
- data/engines/blog/config/locales/en.yml +500 -0
- data/engines/blog/config/routes.rb +33 -0
- data/engines/blog/db/migrate/20261103090000_create_glib_blog_tables.rb +70 -0
- data/engines/blog/db/migrate/20261104090000_create_glib_blog_media_tables.rb +44 -0
- data/engines/blog/db/migrate/20261104120000_create_glib_blog_comments.rb +23 -0
- data/engines/blog/db/migrate/20261105090000_add_glib_blog_comment_moderation.rb +16 -0
- data/engines/blog/db/migrate/20261105100000_add_deleted_at_to_glib_blog_posts.rb +6 -0
- data/engines/blog/db/migrate/20261105110000_add_parent_and_default_to_glib_blog_categories.rb +10 -0
- data/engines/blog/db/migrate/20261105120000_create_glib_blog_post_views.rb +13 -0
- data/engines/blog/db/migrate/20261105130000_create_glib_blog_settings.rb +26 -0
- data/engines/blog/db/migrate/20261106090000_add_theme_to_glib_blog_settings.rb +7 -0
- data/engines/blog/lib/tasks/glib_blog_tasks.rake +32 -0
- data/lib/generators/glib/blog/install_generator.rb +44 -0
- data/lib/generators/glib/blog/templates/initializer.rb +22 -0
- data/lib/generators/glib/scheduled_jobs_generator.rb +30 -0
- data/lib/generators/templates/scheduled_jobs/create_glib_scheduled_job_runs.rb +22 -0
- data/lib/glib/blog/engine.rb +20 -0
- data/lib/glib/blog/theme.rb +35 -0
- data/lib/glib/blog.rb +50 -0
- data/lib/glib/engine.rb +17 -0
- data/lib/glib/scheduled_jobs/config.rb +36 -0
- data/lib/glib/scheduled_jobs/loader.rb +98 -0
- data/lib/glib-web.rb +2 -0
- metadata +177 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Glib
|
|
2
|
+
module Blog
|
|
3
|
+
# Anyone may comment. Whether a post still takes comments is a validation on the comment, so
|
|
4
|
+
# a guest on a closed post gets a message instead of a sign-in page.
|
|
5
|
+
class CommentPolicy < ApplicationPolicy
|
|
6
|
+
authorize :create do
|
|
7
|
+
everyone
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Locals: menu, name, url, and optionally `text`, which shows a labelled button instead of an icon,
|
|
2
|
+
# or `icon` (default `delete`).
|
|
3
|
+
confirm = ->(action) do
|
|
4
|
+
action.dialogs_show content: ->(dialog) do
|
|
5
|
+
dialog.body padding: glib_json_padding_body, styleClasses: ['admin-dialog'], childViews: ->(res) do
|
|
6
|
+
res.label text: t('.confirm', name: name)
|
|
7
|
+
res.spacer height: 16
|
|
8
|
+
res.panels_flow innerPadding: { bottom: 0 }, childViews: ->(flow) do
|
|
9
|
+
flow.button text: t('.cancel'), styleClasses: ['text'], onClick: ->(subaction) do
|
|
10
|
+
subaction.dialogs_close
|
|
11
|
+
end
|
|
12
|
+
flow.button text: t('.delete'), styleClasses: ['error'], onClick: ->(subaction) do
|
|
13
|
+
subaction.http_delete url: url, formData: { authenticity_token: form_authenticity_token }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
if local_assigns[:text]
|
|
21
|
+
menu.button text: text, styleClasses: ['text', 'error'], onClick: confirm
|
|
22
|
+
else
|
|
23
|
+
menu.button icon: local_assigns.fetch(:icon, 'delete'), styleClasses: ['icon', 'text', 'x-small'], onClick: confirm
|
|
24
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Locals: page, and `active`, the key of the current section.
|
|
2
|
+
items = [
|
|
3
|
+
[:dashboard, 'dashboard', admin_dashboard_url],
|
|
4
|
+
[:posts, 'article', admin_posts_url],
|
|
5
|
+
[:new_post, 'edit', new_admin_post_url],
|
|
6
|
+
[:comments, 'chat_bubble_outline', admin_comments_url],
|
|
7
|
+
[:media, 'image', admin_media_items_url]
|
|
8
|
+
]
|
|
9
|
+
items << [:categories_and_tags, 'sell', admin_categories_url] if current_blog_author&.manages_all_content?
|
|
10
|
+
items << [:authors, 'group', admin_authors_url] if current_blog_author&.admin?
|
|
11
|
+
items << [:settings, 'settings', edit_admin_settings_url] if current_blog_author&.admin?
|
|
12
|
+
setting = Glib::Blog::Setting.current
|
|
13
|
+
|
|
14
|
+
page.leftDrawer styleClasses: ['admin-nav', 'permanent'], drawerWidth: 240, content: ->(drawer) do
|
|
15
|
+
drawer.header styleClasses: ['admin-nav__brand'], childViews: ->(header) do
|
|
16
|
+
header.panels_horizontal align: 'middle', childViews: ->(brand) do
|
|
17
|
+
if (logo = setting.logo_media_item)
|
|
18
|
+
brand.image url: logo.url(:thumb), width: 32, height: 32, styleClasses: ['admin-nav__logo-image']
|
|
19
|
+
else
|
|
20
|
+
brand.label text: setting.title.first, styleClasses: ['admin-nav__logo']
|
|
21
|
+
end
|
|
22
|
+
brand.label text: setting.title, styleClasses: ['admin-nav__name']
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
pending_comments = current_blog_author&.manageable_comments&.pending&.count.to_i
|
|
27
|
+
|
|
28
|
+
drawer.rows builder: ->(menu) do
|
|
29
|
+
items.each do |key, icon, url|
|
|
30
|
+
options = { text: t(".#{key}"), icon: icon, styleClasses: key == active ? ['active'] : [] }
|
|
31
|
+
# Comments waiting for review are counted on the item, which then opens straight on them.
|
|
32
|
+
if key == :comments && pending_comments.positive?
|
|
33
|
+
options[:badge] = { text: pending_comments.to_s }
|
|
34
|
+
url = admin_comments_url(status: 'pending')
|
|
35
|
+
end
|
|
36
|
+
menu.button(**options, onClick: ->(action) { action.windows_open url: url })
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
drawer.footer childViews: ->(footer) do
|
|
41
|
+
footer.button text: t('.view_blog'), icon: 'open_in_new', styleClasses: ['text', 'admin-nav__footer'], onClick: ->(action) do
|
|
42
|
+
action.windows_open url: root_url
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
view.panels_form model: @author, url: url, method: method, width: 'matchParent', childViews: ->(form) do
|
|
2
|
+
if users
|
|
3
|
+
form.fields_select \
|
|
4
|
+
prop: :user_id,
|
|
5
|
+
width: 'matchParent',
|
|
6
|
+
options: users.map { |user| { text: Glib::Blog.user_label.call(user), value: user.id } }
|
|
7
|
+
end
|
|
8
|
+
form.fields_text prop: :display_name, width: 'matchParent'
|
|
9
|
+
form.fields_text prop: :slug, width: 'matchParent'
|
|
10
|
+
form.fields_select \
|
|
11
|
+
prop: :role,
|
|
12
|
+
width: 'matchParent',
|
|
13
|
+
options: Glib::Blog::Author.roles.keys.map { |role| { text: t("glib.blog.admin.roles.#{role}"), value: role } }
|
|
14
|
+
form.fields_textarea prop: :bio, width: 'matchParent'
|
|
15
|
+
form.spacer height: 16
|
|
16
|
+
form.fields_submit text: t('.save'), styleClasses: ['primary', 'flat']
|
|
17
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
page = json_ui_page json
|
|
2
|
+
|
|
3
|
+
glib_blog_admin_page json, page, active: :authors, title: t('.title') do |res|
|
|
4
|
+
res.panels_vertical width: 'matchParent', styleClasses: ['admin-card', 'admin-form'], childViews: ->(card) do
|
|
5
|
+
render 'glib/blog/admin/authors/form', json: json, view: card, url: admin_author_url(@author), method: :patch, users: nil
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
page = json_ui_page json
|
|
2
|
+
|
|
3
|
+
actions = ->(flow) do
|
|
4
|
+
flow.button text: t('.new'), icon: 'add', styleClasses: ['primary', 'flat'], onClick: ->(action) do
|
|
5
|
+
action.windows_open url: new_admin_author_url
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
glib_blog_admin_page json, page, active: :authors, title: t('.title'), subtitle: t('.subtitle'), actions: actions do |res|
|
|
10
|
+
res.panels_vertical width: 'matchParent', styleClasses: ['admin-card'], childViews: ->(card) do
|
|
11
|
+
if @authors.empty?
|
|
12
|
+
card.label text: t('.empty'), styleClasses: ['admin-empty']
|
|
13
|
+
else
|
|
14
|
+
card.panels_table width: 'matchParent', styleClasses: ['admin-table'], firstSection: ->(section) do
|
|
15
|
+
section.header cellViews: ->(header) do
|
|
16
|
+
%w[name role posts actions].each { |column| header.label text: t(".columns.#{column}") }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
section.rows objects: @authors, builder: ->(row, author, _index) do
|
|
20
|
+
name = author == current_blog_author ? t('.you', name: author.display_name) : author.display_name
|
|
21
|
+
|
|
22
|
+
row.default onClick: ->(action) { action.windows_open url: edit_admin_author_url(author) }, cellViews: ->(cell) do
|
|
23
|
+
cell.panels_horizontal align: 'middle', childViews: ->(person) do
|
|
24
|
+
person.label text: author.initials, styleClasses: ['admin-avatar']
|
|
25
|
+
person.panels_vertical childViews: ->(vertical) do
|
|
26
|
+
vertical.label text: name, styleClasses: ['admin-table__primary']
|
|
27
|
+
vertical.label text: Glib::Blog.user_label.call(author.user), styleClasses: ['admin-muted', 'admin-small']
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
render 'glib/blog/admin/status_chip', json: json, view: cell, status: author.role, text: t("glib.blog.admin.roles.#{author.role}")
|
|
31
|
+
cell.label text: author.posts_count.to_s, styleClasses: ['admin-mono']
|
|
32
|
+
render 'glib/blog/admin/delete_button', json: json, menu: cell, name: author.display_name, url: admin_author_url(author)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
res.panels_vertical width: 'matchParent', styleClasses: ['admin-card', 'admin-card--padded'], childViews: ->(card) do
|
|
40
|
+
card.h2 text: t('.roles_title')
|
|
41
|
+
card.panels_grid width: 'matchParent', boxMinWidth: 220, columnGap: 16, rowGap: 16, childViews: ->(grid) do
|
|
42
|
+
Glib::Blog::Author.roles.each_key do |role|
|
|
43
|
+
grid.panels_vertical styleClasses: ['admin-role'], childViews: ->(vertical) do
|
|
44
|
+
vertical.label text: t("glib.blog.admin.roles.#{role}"), styleClasses: ['admin-table__primary']
|
|
45
|
+
vertical.p text: t(".role_descriptions.#{role}"), styleClasses: ['admin-muted', 'admin-small']
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
page = json_ui_page json
|
|
2
|
+
|
|
3
|
+
glib_blog_admin_page json, page, active: :authors, title: t('.title') do |res|
|
|
4
|
+
res.panels_vertical width: 'matchParent', styleClasses: ['admin-card', 'admin-form'], childViews: ->(card) do
|
|
5
|
+
if @users.empty?
|
|
6
|
+
card.label text: t('.no_users')
|
|
7
|
+
else
|
|
8
|
+
render 'glib/blog/admin/authors/form', json: json, view: card, url: admin_authors_url, method: :post, users: @users
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
view.panels_form model: @category, url: url, method: method, width: 'matchParent', childViews: ->(form) do
|
|
2
|
+
form.fields_text prop: :name, width: 'matchParent'
|
|
3
|
+
form.fields_text prop: :slug, width: 'matchParent'
|
|
4
|
+
form.fields_select \
|
|
5
|
+
prop: :parent_id,
|
|
6
|
+
width: 'matchParent',
|
|
7
|
+
options: [{ text: t('.no_parent'), value: '' }] + @parents.map { |parent| { text: parent.name, value: parent.id } }
|
|
8
|
+
form.fields_textarea prop: :description, width: 'matchParent'
|
|
9
|
+
form.fields_number prop: :position, width: 'matchParent'
|
|
10
|
+
form.fields_check prop: :default, checkValue: true, uncheckValue: false
|
|
11
|
+
form.spacer height: 16
|
|
12
|
+
form.fields_submit text: t('.save'), styleClasses: ['primary', 'flat']
|
|
13
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
page = json_ui_page json
|
|
2
|
+
|
|
3
|
+
glib_blog_admin_page json, page, active: :categories_and_tags, title: t('.title') do |res|
|
|
4
|
+
res.panels_vertical width: 'matchParent', styleClasses: ['admin-card', 'admin-form'], childViews: ->(card) do
|
|
5
|
+
render 'glib/blog/admin/categories/form', json: json, view: card, url: admin_category_url(@category), method: :patch
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
page = json_ui_page json
|
|
2
|
+
|
|
3
|
+
actions = ->(flow) do
|
|
4
|
+
flow.button text: t('.new'), icon: 'add', styleClasses: ['primary', 'flat'], onClick: ->(action) do
|
|
5
|
+
action.windows_open url: new_admin_category_url
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
glib_blog_admin_page json, page, active: :categories_and_tags, title: t('.title'), subtitle: t('.subtitle'), actions: actions do |res|
|
|
10
|
+
res.panels_vertical width: 'matchParent', styleClasses: ['admin-card'], childViews: ->(card) do
|
|
11
|
+
card.panels_split width: 'matchParent', align: 'middle', styleClasses: ['admin-card__header'], content: ->(split) do
|
|
12
|
+
split.left childViews: ->(left) { left.h2 text: t('.categories') }
|
|
13
|
+
split.right childViews: ->(right) { right.label text: t('.count', count: @categories.size), styleClasses: ['admin-muted'] }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
if @categories.empty?
|
|
17
|
+
card.label text: t('.empty'), styleClasses: ['admin-empty']
|
|
18
|
+
else
|
|
19
|
+
card.panels_table width: 'matchParent', styleClasses: ['admin-table'], firstSection: ->(section) do
|
|
20
|
+
section.header cellViews: ->(header) do
|
|
21
|
+
%w[name slug posts actions].each { |column| header.label text: t(".columns.#{column}") }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
section.rows objects: @categories, builder: ->(row, category, _index) do
|
|
25
|
+
row.default onClick: ->(action) { action.windows_open url: edit_admin_category_url(category) }, cellViews: ->(cell) do
|
|
26
|
+
name = category.default? ? t('.default', name: category.name) : category.name
|
|
27
|
+
if category.parent_id
|
|
28
|
+
cell.label text: "— #{name}", styleClasses: ['admin-table__child']
|
|
29
|
+
else
|
|
30
|
+
cell.label text: name, styleClasses: ['admin-table__primary']
|
|
31
|
+
end
|
|
32
|
+
cell.label text: category.slug, styleClasses: ['admin-mono', 'admin-muted']
|
|
33
|
+
cell.label text: category.posts_count.to_s, styleClasses: ['admin-mono']
|
|
34
|
+
render 'glib/blog/admin/delete_button', json: json, menu: cell, name: category.name, url: admin_category_url(category)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
res.panels_vertical width: 'matchParent', styleClasses: ['admin-card'], childViews: ->(card) do
|
|
42
|
+
card.panels_split width: 'matchParent', align: 'middle', styleClasses: ['admin-card__header'], content: ->(split) do
|
|
43
|
+
split.left childViews: ->(left) { left.h2 text: t('.tags') }
|
|
44
|
+
split.right childViews: ->(right) do
|
|
45
|
+
right.panels_flow innerPadding: { bottom: 0, right: 8 }, childViews: ->(flow) do
|
|
46
|
+
flow.button text: t('.all_tags'), styleClasses: ['text'], onClick: ->(action) do
|
|
47
|
+
action.windows_open url: admin_tags_url
|
|
48
|
+
end
|
|
49
|
+
flow.button text: t('.new_tag'), icon: 'add', styleClasses: ['outlined'], onClick: ->(action) do
|
|
50
|
+
action.windows_open url: new_admin_tag_url
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
if @tags.empty?
|
|
57
|
+
card.label text: t('.no_tags'), styleClasses: ['admin-empty']
|
|
58
|
+
else
|
|
59
|
+
card.panels_flow width: 'matchParent', innerPadding: { bottom: 8, right: 8 }, styleClasses: ['admin-chips'], childViews: ->(flow) do
|
|
60
|
+
@tags.each do |tag|
|
|
61
|
+
flow.chip text: "#{tag.name} #{tag.taggings_count}", styleClasses: ['admin-tag'], onClick: ->(action) do
|
|
62
|
+
action.windows_open url: edit_admin_tag_url(tag)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
page = json_ui_page json
|
|
2
|
+
|
|
3
|
+
glib_blog_admin_page json, page, active: :categories_and_tags, title: t('.title') do |res|
|
|
4
|
+
res.panels_vertical width: 'matchParent', styleClasses: ['admin-card', 'admin-form'], childViews: ->(card) do
|
|
5
|
+
render 'glib/blog/admin/categories/form', json: json, view: card, url: admin_categories_url, method: :post
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Locals: menu, comment, and `return_params`, which tell the controller where to go afterwards.
|
|
2
|
+
set_status = lambda do |status|
|
|
3
|
+
lambda do |action|
|
|
4
|
+
action.http_patch url: admin_comment_url(comment), formData: {
|
|
5
|
+
'glib_blog_comment[status]' => status, 'authenticity_token' => form_authenticity_token, **return_params
|
|
6
|
+
}
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
unless comment.spam? || comment.trash?
|
|
11
|
+
menu.button styleClasses: ['icon', 'text', 'x-small'], icon: 'reply', tooltip: { text: t('.reply') }, onClick: lambda { |action|
|
|
12
|
+
action.dialogs_show content: lambda { |dialog|
|
|
13
|
+
dialog.body padding: glib_json_padding_body, styleClasses: ['admin-dialog'], childViews: lambda { |body|
|
|
14
|
+
body.h3 text: t('.reply_to', name: comment.author_name)
|
|
15
|
+
body.p text: comment.body.truncate(200)
|
|
16
|
+
body.panels_form url: admin_comment_replies_url(comment), method: :post, width: 'matchParent', childViews: lambda { |form|
|
|
17
|
+
form.fields_textarea name: 'comment[body]', label: t('.reply_body'), width: 'matchParent', maxLength: Glib::Blog::Comment::MAX_BODY_LENGTH
|
|
18
|
+
form.fields_submit text: t('.send_reply'), styleClasses: ['primary', 'flat']
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
{ approved: 'check_circle', spam: 'report', trash: 'delete_outline' }.each do |status, icon|
|
|
26
|
+
next if comment.status == status
|
|
27
|
+
|
|
28
|
+
menu.button styleClasses: ['icon', 'text', 'x-small', "admin-moderate-#{status}"], icon: icon,
|
|
29
|
+
tooltip: { text: t(".to.#{status}") }, onClick: set_status.call(status)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if comment.spam? || comment.trash?
|
|
33
|
+
render 'glib/blog/admin/delete_button', json: json, menu: menu, name: comment.author_name, url: admin_comment_url(comment),
|
|
34
|
+
icon: 'delete_forever'
|
|
35
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
page = json_ui_page json
|
|
2
|
+
status_filter = params[:status].to_s if Glib::Blog::Comment.statuses.key?(params[:status].to_s)
|
|
3
|
+
filters = { status: status_filter, q: params[:q].presence }.compact
|
|
4
|
+
next_page = { url: admin_comments_url(filters.merge(page: @next_page, section_only: 'v1')), autoload: 'asNeeded' } if @next_page
|
|
5
|
+
|
|
6
|
+
rows = lambda do |section|
|
|
7
|
+
section.rows builder: ->(template) do
|
|
8
|
+
@comments.each do |comment|
|
|
9
|
+
status_label = t("glib.blog.admin.comment_statuses.#{comment.status}") unless comment.approved?
|
|
10
|
+
template.thumbnail(
|
|
11
|
+
styleClasses: ['admin-comment', "admin-comment--#{comment.status}"],
|
|
12
|
+
avatar: { initials: { text: comment.initials, color: '#FFFFFF' }, backgroundColor: comment.avatar_color },
|
|
13
|
+
title: [comment.author_name, comment.author_email, status_label].compact.join(' · '),
|
|
14
|
+
subtitle: comment.body.truncate(160),
|
|
15
|
+
subsubtitle: t('.posted_on', title: comment.post.title, date: l(comment.created_at, format: :long)),
|
|
16
|
+
onClick: ->(action) { action.windows_open url: post_url(comment.post.slug) },
|
|
17
|
+
rightButtons: lambda { |menu|
|
|
18
|
+
render 'glib/blog/admin/comments/moderation_buttons', json: json, menu: menu, comment: comment,
|
|
19
|
+
return_params: { 'return_status' => status_filter }.compact
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Infinite scroll asks for just the next section.
|
|
27
|
+
if params[:section_only].present?
|
|
28
|
+
json.nextPage next_page if next_page
|
|
29
|
+
json.sections do
|
|
30
|
+
json.child! { rows.call(page.list_section_builder) }
|
|
31
|
+
end
|
|
32
|
+
else
|
|
33
|
+
glib_blog_admin_page json, page, active: :comments, title: t('.title'), subtitle: t('.subtitle') do |res|
|
|
34
|
+
res.panels_flow width: 'matchParent', innerPadding: { bottom: 0, right: 4 }, styleClasses: ['admin-tabs'], childViews: ->(tabs) do
|
|
35
|
+
[nil, *Glib::Blog::Comment.statuses.keys].each do |status|
|
|
36
|
+
tabs.button \
|
|
37
|
+
text: "#{status ? t("glib.blog.admin.comment_statuses.#{status}") : t('.all')} #{@status_counts[status || 'all'] || 0}",
|
|
38
|
+
styleClasses: ['text', 'admin-tab', (status == status_filter ? 'active' : nil)].compact,
|
|
39
|
+
onClick: ->(action) { action.windows_open url: admin_comments_url(status: status, q: params[:q].presence) }
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
res.panels_form url: admin_comments_url, method: :get, width: 'matchParent', styleClasses: ['admin-filters'], childViews: ->(form) do
|
|
44
|
+
form.fields_hidden name: 'status', value: status_filter if status_filter
|
|
45
|
+
form.panels_flow innerPadding: { bottom: 0, right: 8 }, width: 'matchParent', childViews: ->(flow) do
|
|
46
|
+
flow.fields_text name: 'q', placeholder: t('.search'), value: params[:q], width: 320, leftIcon: 'search', styleClasses: ['compact']
|
|
47
|
+
flow.fields_submit text: t('.filter'), styleClasses: ['text']
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
if @comments.empty?
|
|
52
|
+
res.panels_vertical width: 'matchParent', styleClasses: ['admin-card'], childViews: ->(card) do
|
|
53
|
+
card.label text: t('.empty'), styleClasses: ['admin-empty']
|
|
54
|
+
end
|
|
55
|
+
else
|
|
56
|
+
res.panels_list width: 'matchParent', styleClasses: ['admin-comments'], nextPage: next_page, firstSection: rows
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
page = json_ui_page json
|
|
2
|
+
|
|
3
|
+
views_note =
|
|
4
|
+
if @previous_views.zero?
|
|
5
|
+
t('.stats.views_note_none')
|
|
6
|
+
else
|
|
7
|
+
t('.stats.views_note', change: format('%+d%%', ((@views - @previous_views) * 100.0 / @previous_views).round))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
stats = [
|
|
11
|
+
[t('.stats.published'), @stats[:live], t('.stats.published_note', count: @stats[:live_this_month])],
|
|
12
|
+
[t('.stats.drafts'), @stats[:drafts], t('.stats.drafts_note', count: @stats[:scheduled])],
|
|
13
|
+
[t('.stats.views'), @views, views_note],
|
|
14
|
+
[t('.stats.pending'), @stats[:pending_comments], t('.stats.pending_note', count: @stats[:approved_this_month])]
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
actions = ->(flow) do
|
|
18
|
+
flow.button text: t('.new'), icon: 'add', styleClasses: ['primary', 'flat'], onClick: ->(action) do
|
|
19
|
+
action.windows_open url: new_admin_post_url
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
card_header = ->(card, title, url) do
|
|
24
|
+
card.panels_split width: 'matchParent', align: 'middle', styleClasses: ['admin-card__header'], content: ->(split) do
|
|
25
|
+
split.left childViews: ->(left) { left.h2 text: title }
|
|
26
|
+
split.right childViews: ->(right) do
|
|
27
|
+
right.button text: t('.view_all'), styleClasses: ['text', 'admin-link'], onClick: ->(action) { action.windows_open url: url }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
glib_blog_admin_page json, page, active: :dashboard, title: t('.title'), subtitle: t('.subtitle'), actions: actions do |res|
|
|
33
|
+
res.panels_grid width: 'matchParent', boxMinWidth: 200, columnGap: 16, rowGap: 16, childViews: ->(grid) do
|
|
34
|
+
stats.each do |label, value, note|
|
|
35
|
+
grid.panels_vertical styleClasses: ['admin-card', 'admin-stat'], childViews: ->(card) do
|
|
36
|
+
card.label text: label, styleClasses: ['admin-muted', 'admin-small']
|
|
37
|
+
card.label text: number_with_delimiter(value), styleClasses: ['admin-stat__value', 'admin-mono']
|
|
38
|
+
card.label text: note, styleClasses: ['admin-muted', 'admin-small']
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
res.panels_responsive width: 'matchParent', childViews: ->(columns) do
|
|
44
|
+
columns.panels_column md: { cols: 8 }, xs: { cols: 12 }, styleClasses: ['admin-column'], childViews: ->(column) do
|
|
45
|
+
column.panels_vertical width: 'matchParent', styleClasses: ['admin-card'], childViews: ->(card) do
|
|
46
|
+
card_header.call(card, t('.recent_posts'), admin_posts_url)
|
|
47
|
+
|
|
48
|
+
if @recent_posts.empty?
|
|
49
|
+
card.label text: t('.no_posts'), styleClasses: ['admin-empty']
|
|
50
|
+
else
|
|
51
|
+
card.panels_table width: 'matchParent', styleClasses: ['admin-table'], firstSection: ->(section) do
|
|
52
|
+
section.header cellViews: ->(header) do
|
|
53
|
+
%w[title status views comments date].each { |key| header.label text: t(".columns.#{key}") }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
section.rows objects: @recent_posts, builder: ->(row, post, _index) do
|
|
57
|
+
status = glib_blog_post_status(post)
|
|
58
|
+
row.default onClick: ->(action) { action.windows_open url: edit_admin_post_url(post) }, cellViews: ->(cell) do
|
|
59
|
+
cell.label text: post.title, styleClasses: ['admin-table__primary']
|
|
60
|
+
render 'glib/blog/admin/status_chip', json: json, view: cell, status: status, text: t("glib.blog.admin.statuses.#{status}")
|
|
61
|
+
cell.label text: number_with_delimiter(@recent_post_views.fetch(post.id, 0)), styleClasses: ['admin-mono']
|
|
62
|
+
cell.label text: post.comments_count.to_s, styleClasses: ['admin-mono']
|
|
63
|
+
cell.label text: glib_blog_post_date(post), styleClasses: ['admin-muted']
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
columns.panels_column md: { cols: 4 }, xs: { cols: 12 }, styleClasses: ['admin-column'], childViews: ->(column) do
|
|
72
|
+
column.panels_vertical width: 'matchParent', styleClasses: ['admin-card', 'admin-card--padded'], childViews: ->(card) do
|
|
73
|
+
card.h2 text: t('.quick_draft')
|
|
74
|
+
card.panels_form \
|
|
75
|
+
model: Glib::Blog::Post.new,
|
|
76
|
+
url: admin_posts_url,
|
|
77
|
+
method: :post,
|
|
78
|
+
width: 'matchParent',
|
|
79
|
+
autofocus: false,
|
|
80
|
+
childViews: ->(form) do
|
|
81
|
+
form.fields_hidden prop: :status, value: 'draft'
|
|
82
|
+
form.fields_text prop: :title, width: 'matchParent'
|
|
83
|
+
form.fields_textarea name: 'glib_blog_post[body]', label: t('.idea'), width: 'matchParent'
|
|
84
|
+
form.fields_submit text: t('.save_draft'), styleClasses: ['outlined']
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
column.panels_vertical width: 'matchParent', styleClasses: ['admin-card', 'admin-dashboard-comments'], childViews: ->(card) do
|
|
89
|
+
card_header.call(card, t('.pending_comments'), admin_comments_url(status: 'pending'))
|
|
90
|
+
|
|
91
|
+
if @pending_comments.empty?
|
|
92
|
+
card.label text: t('.no_pending'), styleClasses: ['admin-empty']
|
|
93
|
+
else
|
|
94
|
+
@pending_comments.each do |comment|
|
|
95
|
+
card.panels_vertical width: 'matchParent', styleClasses: ['admin-dashboard-comment'], childViews: ->(item) do
|
|
96
|
+
item.label text: t('.comment_on', name: comment.author_name, title: comment.post.title), styleClasses: ['admin-small']
|
|
97
|
+
item.label text: t('.ago', time: time_ago_in_words(comment.created_at)), styleClasses: ['admin-muted', 'admin-small']
|
|
98
|
+
item.p text: comment.body.truncate(140)
|
|
99
|
+
item.panels_flow innerPadding: { bottom: 0, right: 4 }, childViews: ->(flow) do
|
|
100
|
+
render 'glib/blog/admin/comments/moderation_buttons', json: json, menu: flow, comment: comment,
|
|
101
|
+
return_params: { 'return_to' => 'dashboard' }
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
page = json_ui_page json
|
|
2
|
+
subtitle = t('.retention', days: Glib::Blog::MediaItem::TRASH_RETENTION.in_days.to_i)
|
|
3
|
+
|
|
4
|
+
glib_blog_admin_page json, page, active: :media, title: t('.title'), subtitle: subtitle do |res|
|
|
5
|
+
if @media_items.empty?
|
|
6
|
+
res.panels_vertical width: 'matchParent', styleClasses: ['admin-card'], childViews: ->(card) do
|
|
7
|
+
card.label text: t('.empty'), styleClasses: ['admin-empty']
|
|
8
|
+
end
|
|
9
|
+
else
|
|
10
|
+
res.panels_list width: 'matchParent', styleClasses: ['admin-card', 'admin-rows'], firstSection: ->(section) do
|
|
11
|
+
section.rows builder: ->(template) do
|
|
12
|
+
@media_items.each do |media_item|
|
|
13
|
+
preview = media_item.image? ? { avatar: { url: media_item.url(:thumb) } } : { icon: 'description' }
|
|
14
|
+
template.thumbnail(
|
|
15
|
+
**preview,
|
|
16
|
+
title: media_item.title_or_filename,
|
|
17
|
+
subtitle: t('.trashed_at', date: l(media_item.deleted_at.to_date, format: :long)),
|
|
18
|
+
rightButtons: ->(menu) do
|
|
19
|
+
menu.button styleClasses: ['icon', 'text', 'x-small'], icon: 'restore_from_trash', tooltip: { text: t('.restore') }, onClick: ->(action) do
|
|
20
|
+
action.http_delete url: admin_media_item_trash_url(media_item), formData: { authenticity_token: form_authenticity_token }
|
|
21
|
+
end
|
|
22
|
+
if current_blog_author.manages_all_content?
|
|
23
|
+
render 'glib/blog/admin/delete_button', json: json, menu: menu, name: media_item.title_or_filename,
|
|
24
|
+
url: admin_media_item_url(media_item)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Locals: section, media_items, and either `pick: { mode:, target: }` for the picker dialog or
|
|
2
|
+
# nothing for the library grid.
|
|
3
|
+
pick = local_assigns[:pick]
|
|
4
|
+
|
|
5
|
+
section.rows builder: ->(template) do
|
|
6
|
+
media_items.each do |media_item|
|
|
7
|
+
usage = media_item.usages_count.zero? ? t('.unused') : t('.used', count: media_item.usages_count)
|
|
8
|
+
preview = media_item.image? ? { avatar: { url: media_item.url(:thumb) } } : { icon: 'description' }
|
|
9
|
+
template.thumbnail(
|
|
10
|
+
**preview,
|
|
11
|
+
recordId: media_item.id.to_s,
|
|
12
|
+
title: media_item.title_or_filename,
|
|
13
|
+
subtitle: [media_item.filename, number_to_human_size(media_item.byte_size), usage].join(' · '),
|
|
14
|
+
onClick: lambda { |action|
|
|
15
|
+
if pick.nil?
|
|
16
|
+
action.windows_open url: edit_admin_media_item_url(media_item)
|
|
17
|
+
elsif pick[:mode] != :body
|
|
18
|
+
action.runMultiple childActions: lambda { |multiple|
|
|
19
|
+
multiple.logics_set targetId: "#{pick[:target]}_id", data: { value: media_item.id }
|
|
20
|
+
multiple.logics_set targetId: "#{pick[:target]}_preview", data: { url: media_item.url(:medium) }
|
|
21
|
+
multiple.dialogs_close
|
|
22
|
+
}
|
|
23
|
+
else
|
|
24
|
+
action.runMultiple childActions: lambda { |multiple|
|
|
25
|
+
multiple.components_invoke targetId: pick[:target], name: 'insertAttachment', arguments: media_item.trix_attachment_attributes
|
|
26
|
+
multiple.dialogs_close
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
end
|