express_admin 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +37 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/fonts/app_express.eot +0 -0
  6. data/app/assets/fonts/app_express.svg +21 -0
  7. data/app/assets/fonts/app_express.ttf +0 -0
  8. data/app/assets/fonts/app_express.woff +0 -0
  9. data/app/assets/fonts/ionicons.eot +0 -0
  10. data/app/assets/fonts/ionicons.svg +1899 -0
  11. data/app/assets/fonts/ionicons.ttf +0 -0
  12. data/app/assets/fonts/ionicons.woff +0 -0
  13. data/app/assets/javascripts/express_admin/admin.js +30 -0
  14. data/app/assets/javascripts/express_admin/dataTables/dataTables.foundation.js +183 -0
  15. data/app/assets/javascripts/express_admin/dataTables/jquery.dataTables.js +14382 -0
  16. data/app/assets/javascripts/express_admin/utility.js +30 -0
  17. data/app/assets/javascripts/express_admin.js +7 -0
  18. data/app/assets/stylesheets/dataTables/dataTables.foundation.css.erb +217 -0
  19. data/app/assets/stylesheets/express_admin/components/_empty_state.sass +10 -0
  20. data/app/assets/stylesheets/express_admin/components/_megadropdown.sass +71 -0
  21. data/app/assets/stylesheets/express_admin/express_icons.sass +56 -0
  22. data/app/assets/stylesheets/express_admin/foundation_and_overrides.scss +1443 -0
  23. data/app/assets/stylesheets/express_admin/globals/_mixins.sass +9 -0
  24. data/app/assets/stylesheets/express_admin/globals/_typography.sass +30 -0
  25. data/app/assets/stylesheets/express_admin/globals/_variables.sass +16 -0
  26. data/app/assets/stylesheets/express_admin/plugins/_dataTables.sass +118 -0
  27. data/app/assets/stylesheets/express_admin/plugins/_select2.sass +91 -0
  28. data/app/assets/stylesheets/express_admin/screen.sass +47 -0
  29. data/app/assets/stylesheets/express_admin/sections/_devise.sass +42 -0
  30. data/app/assets/stylesheets/express_admin/sections/_header.sass +98 -0
  31. data/app/assets/stylesheets/express_admin/sections/_main_content.sass +63 -0
  32. data/app/assets/stylesheets/express_admin/sections/_sidebar.sass +42 -0
  33. data/app/assets/stylesheets/express_admin/shared/_alerts.sass +45 -0
  34. data/app/assets/stylesheets/express_admin/shared/_breadcrumbs.sass +3 -0
  35. data/app/assets/stylesheets/express_admin/shared/_buttons.sass +33 -0
  36. data/app/assets/stylesheets/express_admin/shared/_forms.sass +99 -0
  37. data/app/assets/stylesheets/express_admin/shared/_labels.sass +16 -0
  38. data/app/assets/stylesheets/express_admin/shared/_loading.sass +2 -0
  39. data/app/assets/stylesheets/express_admin/shared/_media_object.sass +23 -0
  40. data/app/assets/stylesheets/express_admin/shared/_messages.sass +12 -0
  41. data/app/assets/stylesheets/express_admin/shared/_navigation.sass +20 -0
  42. data/app/assets/stylesheets/express_admin/shared/_progress.sass +3 -0
  43. data/app/assets/stylesheets/express_admin/shared/_reveal.sass +20 -0
  44. data/app/assets/stylesheets/express_admin/shared/_tables.sass +75 -0
  45. data/app/assets/stylesheets/express_admin/shared/_tabs.sass +25 -0
  46. data/app/assets/stylesheets/express_admin/shared/_widgets.sass +57 -0
  47. data/app/assets/stylesheets/express_admin.css +9 -0
  48. data/app/assets/stylesheets/ionicons/ionicons.css.sass +1873 -0
  49. data/app/components/express_admin/addon_sidebar_component.rb +47 -0
  50. data/app/components/express_admin/flash_message_component.rb +19 -0
  51. data/app/components/express_admin/main_region.rb +9 -0
  52. data/app/components/express_admin/mega_menu_component.rb +68 -0
  53. data/app/components/express_admin/page_header_component.rb +39 -0
  54. data/app/components/express_admin/setting_form.rb +45 -0
  55. data/app/components/express_admin/sidebar_region.rb +11 -0
  56. data/app/components/express_admin/smart_form.rb +70 -0
  57. data/app/components/express_admin/smart_table.rb +97 -0
  58. data/app/components/express_admin/widget_box.rb +22 -0
  59. data/app/helpers/express_admin/admin_helper.rb +104 -0
  60. data/app/helpers/express_admin/module_settings_helper.rb +53 -0
  61. data/app/views/express_admin/dashboard/show.html.et +6 -0
  62. data/app/views/layouts/express_admin/admin.html.et +31 -0
  63. data/app/views/layouts/express_admin/external.html.et +15 -0
  64. data/app/views/shared/express_admin/_messages.html.et +1 -0
  65. data/app/views/shared/express_admin/_navigation_bar.html.et +20 -0
  66. data/app/views/shared/express_admin/_navigation_bar_profile.html.et +8 -0
  67. data/app/views/shared/express_admin/_title.html.et +8 -0
  68. data/config/initializers/gravatar_image_tag.rb +4 -0
  69. data/lib/express_admin/engine.rb +52 -0
  70. data/lib/express_admin/menu.rb +62 -0
  71. data/lib/express_admin/version.rb +3 -0
  72. data/lib/express_admin.rb +4 -0
  73. data/lib/generators/express_admin/install/USAGE +23 -0
  74. data/lib/generators/express_admin/install/install_generator.rb +97 -0
  75. data/lib/generators/express_admin/install/templates/assets/javascripts/application.js +1 -0
  76. data/lib/generators/express_admin/install/templates/assets/stylesheets/application.css +5 -0
  77. data/lib/generators/express_admin/install/templates/config/menu.yml.erb +3 -0
  78. data/lib/generators/express_admin/install/templates/controllers/admin_controller.rb.erb +34 -0
  79. data/lib/generators/express_admin/install/templates/install/USAGE +8 -0
  80. data/lib/generators/express_admin/install/templates/install/installer.rb.erb +10 -0
  81. data/lib/generators/express_admin/install/templates/install/installer_test.rb.erb +16 -0
  82. data/lib/generators/express_admin/install/templates/views/layouts/admin.html.et +1 -0
  83. data/lib/generators/express_admin/scaffold/scaffold_generator.rb +135 -0
  84. data/lib/generators/express_admin/scaffold/templates/controller/controller.rb +14 -0
  85. data/lib/generators/express_admin/scaffold/templates/index.html.et.erb +10 -0
  86. data/lib/generators/express_admin/scaffold/templates/model/model.rb +4 -0
  87. data/lib/generators/express_admin/scaffold/templates/show.html.et.erb +10 -0
  88. data/lib/tasks/express_admin_tasks.rake +4 -0
  89. data/test/bin/run +1 -0
  90. data/test/dummy/README.rdoc +28 -0
  91. data/test/dummy/Rakefile +6 -0
  92. data/test/dummy/app/assets/javascripts/application.js +13 -0
  93. data/test/dummy/app/assets/javascripts/demo.js +2 -0
  94. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  95. data/test/dummy/app/assets/stylesheets/demo.css.scss +3 -0
  96. data/test/dummy/app/controllers/application_controller.rb +5 -0
  97. data/test/dummy/app/controllers/demo_controller.rb +8 -0
  98. data/test/dummy/app/helpers/application_helper.rb +2 -0
  99. data/test/dummy/app/helpers/demo_helper.rb +2 -0
  100. data/test/dummy/app/views/demo/show.html.et +2 -0
  101. data/test/dummy/app/views/demo/sign_in.html.et +30 -0
  102. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  103. data/test/dummy/bin/bundle +3 -0
  104. data/test/dummy/bin/rails +4 -0
  105. data/test/dummy/bin/rake +4 -0
  106. data/test/dummy/config/application.rb +23 -0
  107. data/test/dummy/config/boot.rb +5 -0
  108. data/test/dummy/config/database.yml +25 -0
  109. data/test/dummy/config/environment.rb +5 -0
  110. data/test/dummy/config/environments/development.rb +37 -0
  111. data/test/dummy/config/environments/production.rb +83 -0
  112. data/test/dummy/config/environments/test.rb +43 -0
  113. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  114. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  115. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  116. data/test/dummy/config/initializers/inflections.rb +16 -0
  117. data/test/dummy/config/initializers/mime_types.rb +4 -0
  118. data/test/dummy/config/initializers/session_store.rb +3 -0
  119. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  120. data/test/dummy/config/locales/en.yml +23 -0
  121. data/test/dummy/config/routes.rb +7 -0
  122. data/test/dummy/config/secrets.yml +22 -0
  123. data/test/dummy/config.ru +4 -0
  124. data/test/dummy/db/schema.rb +22 -0
  125. data/test/dummy/db/test.sqlite3 +0 -0
  126. data/test/dummy/log/test.log +3847 -0
  127. data/test/dummy/public/404.html +67 -0
  128. data/test/dummy/public/422.html +67 -0
  129. data/test/dummy/public/500.html +66 -0
  130. data/test/dummy/public/favicon.ico +0 -0
  131. data/test/dummy/test/controllers/demo_controller_test.rb +9 -0
  132. data/test/dummy/test/helpers/demo_helper_test.rb +4 -0
  133. data/test/fixtures/engine.rb +5 -0
  134. data/test/fixtures/express_admin/test_menu.yml +12 -0
  135. data/test/fixtures/routes.rb +2 -0
  136. data/test/generators_test_helper.rb +32 -0
  137. data/test/lib/express_admin/menu_test.rb +18 -0
  138. data/test/lib/generators/express_admin/install_generator_test.rb +72 -0
  139. data/test/lib/generators/express_admin/scaffold_generator_test.rb +67 -0
  140. data/test/test_helper.rb +18 -0
  141. data/vendor/assets/images/dataTables/Sorting icons.psd +0 -0
  142. data/vendor/assets/images/dataTables/back_disabled.png +0 -0
  143. data/vendor/assets/images/dataTables/back_enabled.png +0 -0
  144. data/vendor/assets/images/dataTables/back_enabled_hover.png +0 -0
  145. data/vendor/assets/images/dataTables/favicon.ico +0 -0
  146. data/vendor/assets/images/dataTables/forward_disabled.png +0 -0
  147. data/vendor/assets/images/dataTables/forward_enabled.png +0 -0
  148. data/vendor/assets/images/dataTables/forward_enabled_hover.png +0 -0
  149. data/vendor/assets/images/dataTables/sort_asc.png +0 -0
  150. data/vendor/assets/images/dataTables/sort_asc_disabled.png +0 -0
  151. data/vendor/assets/images/dataTables/sort_both.png +0 -0
  152. data/vendor/assets/images/dataTables/sort_desc.png +0 -0
  153. data/vendor/assets/images/dataTables/sort_desc_disabled.png +0 -0
  154. data/vendor/assets/javascripts/jquery.loadingdotdotdot.js +82 -0
  155. metadata +432 -0
@@ -0,0 +1,47 @@
1
+ module ExpressAdmin
2
+ class AddonSidebarComponent < ExpressTemplates::Components::Base
3
+ # Replaces:
4
+ #
5
+ # .sidebar-wrapper
6
+ # %aside.sidebar
7
+ # %h5.title= <addon>::Engine.express_admin_menu.name
8
+ # %ul.side-nav
9
+ # - <addon>::Engine.express_admin_menu.items.each do |item|
10
+ # %li
11
+ # = link_to item.name, eval(item.path)
12
+
13
+ helper :menu_name, &-> { current_menu_name }
14
+
15
+ emits menu_item: -> {
16
+ li {
17
+ link_to "{{item.title}}", "{{eval(item.path)}}"
18
+ }
19
+ },
20
+
21
+ menu_wrapper: -> {
22
+ div._sidebar_wrapper {
23
+ aside.sidebar {
24
+ h1 {
25
+ menu_name
26
+ }
27
+ ul {
28
+ _yield
29
+ }
30
+ }
31
+ }
32
+ }
33
+
34
+ for_each -> { current_menu.items || [] }, as: :item, emit: :menu_item
35
+
36
+ wrap_with :menu_wrapper
37
+
38
+ def compile
39
+ %Q(begin
40
+ render(partial: "shared/\#\{current_module_path_name\}/sidebar")
41
+ rescue => e
42
+ #{super}
43
+ end)
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,19 @@
1
+ module ExpressAdmin
2
+ class FlashMessageComponent < ExpressTemplates::Components::Base
3
+
4
+ helper(:safe_message) {|message| message[1] }
5
+ helper(:classes) {|message| "flash nav-alert alert-box #{flash_class(message[0])}" }
6
+
7
+ emits -> {
8
+ div {
9
+ div(class: ExpressAdmin::FlashMessageComponent.classes('{{flash_message}}'), data: {alert: ''}) {
10
+ safe_message('{{flash_message}}')
11
+ a.close(:href => "#") { "&times;" }
12
+ }
13
+ }
14
+ }
15
+
16
+ for_each -> { flash }, as: :flash_message
17
+
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module ExpressAdmin
2
+ class MainRegion < ExpressTemplates::Components::Container
3
+ emits -> {
4
+ div(:main)._large_8.columns {
5
+ _yield
6
+ }
7
+ }
8
+ end
9
+ end
@@ -0,0 +1,68 @@
1
+ module ExpressAdmin
2
+ class MegaMenuComponent < ExpressTemplates::Components::Base
3
+ # %h1 "Modules"
4
+
5
+ # - if admin_menus.any?
6
+ # %nav
7
+ # %ul
8
+ # - admin_menus.each do |menu|
9
+ # %li
10
+ # = link_to eval(menu.main.path) do
11
+ # %i.icon{class: "icon-express_#{menu.main.title.downcase}"}
12
+ # %span= menu.main.title
13
+ # - else
14
+ # .empty-state-wrapper
15
+ # %p.lead.text-muted No modules added yet.
16
+ # %p
17
+ # = link_to app_express.addons_path, class: 'button success radius' do
18
+ # %span.icon.ion-plus
19
+ # Add Module
20
+
21
+ helper(:extra_menu) {
22
+ render(partial: 'shared/express_admin/express_admin_extra_menu') rescue nil
23
+ }
24
+
25
+ fragments menu_item: -> {
26
+ li {
27
+ a(href: "{{eval(menu.path)}}") {
28
+ i.icon(class: "icon-express_{{menu.title.downcase}}")
29
+ span "{{menu.title}}"
30
+ }
31
+ }
32
+ },
33
+
34
+ empty_state: -> {
35
+ div._empty_state_wrapper {
36
+ p.lead._text_muted "No modules added yet."
37
+ }
38
+ },
39
+
40
+ menu_wrapper: -> {
41
+ li.megamenu._has_dropdown {
42
+ a("Manage", href: '#', onClick: 'return false;')
43
+ ul.dropdown._dropdown_wrapper {
44
+ li._megamenu_overlay {
45
+ div._megamenu_container {
46
+ div.main {
47
+ h1 "Modules"
48
+ nav {
49
+ ul {
50
+ _yield
51
+ }
52
+ }
53
+ }
54
+ div.extra {
55
+ extra_menu
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+
63
+ for_each -> {admin_menus}, as: 'menu', emit: :menu_item, empty: :empty_state
64
+
65
+ wrap_with :menu_wrapper, dont_wrap_if: -> { admin_menus.empty? }
66
+
67
+ end
68
+ end
@@ -0,0 +1,39 @@
1
+ module ExpressAdmin
2
+ class PageHeaderComponent < ExpressTemplates::Components::Base
3
+ ETC = ExpressTemplates::Components
4
+
5
+ class PageHeader < ExpressTemplates::Components::Base
6
+ include ETC::Capabilities::Conditionality
7
+
8
+ emits -> {
9
+ h1 {
10
+ content_for(:page_header)
11
+ }
12
+ }
13
+
14
+ only_if -> { content_for?(:page_header) }
15
+
16
+ end
17
+
18
+ class PageHeaderLead < ExpressTemplates::Components::Base
19
+ include ETC::Capabilities::Conditionality
20
+
21
+ emits -> {
22
+ p.lead {
23
+ content_for(:page_header_lead)
24
+ }
25
+ }
26
+
27
+ only_if -> { content_for?(:page_header_lead) }
28
+
29
+ end
30
+
31
+ emits -> {
32
+ page_header
33
+ page_header_lead
34
+ }
35
+
36
+ end
37
+
38
+
39
+ end
@@ -0,0 +1,45 @@
1
+ module ExpressAdmin
2
+ class SettingForm < ExpressTemplates::Components::Container
3
+ include ExpressTemplates::Components::Capabilities::Configurable
4
+
5
+ # .widget-box
6
+ # %h2.widget-header Blog
7
+ # .widget-body
8
+ # = form_tag admin_blog_settings_path, id: 'blog-setting-form', onSubmit: 'return false;', method: 'patch' do
9
+ # = hidden_field_tag :form_id, 'blog-setting-form'
10
+ # - ExpressBlog.settings.blog_setting.each do |setting|
11
+ # = edit_setting setting
12
+ # .form-group.widget-buttons
13
+ # = submit_tag 'Save', class: 'button tiny right radius ajax-submit'
14
+
15
+
16
+ helper(:save_button) { submit_tag 'Save', class: 'button tiny right radius ajax-submit' }
17
+
18
+ helper(:settings_path) { self.send("admin_#{current_module_path_name.gsub(/express_/, '')}_settings_path") }
19
+
20
+ helper(:settings) { |setting_type|
21
+ current_module.settings.send("#{setting_type}_setting").map do |setting|
22
+ edit_setting(setting)
23
+ end.join()
24
+ }
25
+
26
+ emits -> {
27
+ widget_box(my[:id]) {
28
+ setting_selector = my[:id].to_s.gsub('_', '-')
29
+ form(href: ExpressAdmin::SettingForm.settings_path, id: "#{setting_selector}-setting-form", onSubmit: 'return false;', method: 'POST') {
30
+ form_rails_support(:patch)
31
+ hidden_field_tag :form_id, "#{setting_selector}-setting-form"
32
+ div._form_group {
33
+ _yield
34
+ }
35
+ settings(my[:id])
36
+ div._form_group._widget_buttons {
37
+ save_button
38
+ }
39
+ }
40
+ }
41
+ }
42
+
43
+
44
+ end
45
+ end
@@ -0,0 +1,11 @@
1
+ module ExpressAdmin
2
+ class SidebarRegion < ExpressTemplates::Components::Container
3
+ emits -> {
4
+ div(:sidebar)._large_4.columns {
5
+ div._container {
6
+ _yield
7
+ }
8
+ }
9
+ }
10
+ end
11
+ end
@@ -0,0 +1,70 @@
1
+ require 'rails/generators/generated_attribute'
2
+ module ExpressAdmin
3
+ class SmartForm < ExpressTemplates::Components::Base
4
+ include ExpressTemplates::Components::Capabilities::Configurable
5
+
6
+ emits -> {
7
+ express_form(form_args) {
8
+ attributes.each do |attrib|
9
+ form_field_for(attrib)
10
+ end
11
+ submit(class: "button right tight tiny")
12
+ }
13
+ }
14
+
15
+ TIMESTAMPS = ['updated_at', 'created_at']
16
+
17
+ def form_field_for(attrib)
18
+ field_type_substitutions = {'text_area' => 'textarea',
19
+ 'datetime_select' => 'datetime',
20
+ 'check_box' => 'checkbox'}
21
+ field_type = attrib.field_type.to_s.sub(/_field$/,'')
22
+ case
23
+ when attrib.name.eql?('id')
24
+ hidden(:id)
25
+ when TIMESTAMPS.include?(attrib.name)
26
+ div {
27
+ label {
28
+ "#{attrib.name.titleize}: {{@#{resource_name}.try(:#{attrib.name})}}"
29
+ }
30
+ }
31
+ else
32
+ self.send((field_type_substitutions[field_type] || field_type), attrib.name.to_sym)
33
+ end
34
+ end
35
+
36
+
37
+ protected
38
+
39
+ def form_args
40
+ { id: resource_name,
41
+ action: action_path,
42
+ resource_name: resource_name }
43
+ end
44
+
45
+ def action_path
46
+ "{{resource.persisted? ? resource_path(resource.id) : collection_path}}"
47
+ end
48
+
49
+ def resource_name
50
+ @config[:id].to_s.singularize
51
+ end
52
+
53
+ def columns
54
+ resource_class.constantize.columns
55
+ end
56
+
57
+ def attributes
58
+ columns.map do |attrib|
59
+ field_definition = [attrib.name, attrib.type] # index not important here for now
60
+ Rails::Generators::GeneratedAttribute.parse(field_definition.join(":"))
61
+ end
62
+ end
63
+
64
+ def resource_class
65
+ # TODO: Module namespace needs to be guessed somehow
66
+ @config[:class_name] || "ExpressCms::#{resource_name.classify}"
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,97 @@
1
+ module ExpressAdmin
2
+ class SmartTable < ExpressTemplates::Components::Base
3
+ include ExpressTemplates::Components::Capabilities::Configurable
4
+
5
+ MAX_COLS_TO_SHOW_IDX = 5
6
+
7
+ emits -> {
8
+ table(my[:id], 'data-turbolinks-permanent': nil)._table_hover {
9
+ thead {
10
+ tr {
11
+ display_columns.each do |column|
12
+ th.send(column.name) {
13
+ div { # wrap in div so we can use overflow
14
+ column.name.titleize
15
+ }
16
+ }
17
+ end
18
+ th.actions { 'Actions' }
19
+ show_hidden_columns_header_indicator if columns_hidden?
20
+ }
21
+ }
22
+ tbody {
23
+ for_each(collection_var) {
24
+ tr(id: row_id, 'data-resource-url': resource_link) {
25
+ display_columns.each do |column|
26
+ td.send(column.name) {
27
+ cell_value(column.name)
28
+ }
29
+ end
30
+ td {
31
+ link_to 'Delete', resource_link, method: :delete, data: {confirm: 'Are you sure?'}, class: 'button tiny secondary'
32
+ }
33
+ show_hidden_column_cell if columns_hidden?
34
+ }
35
+ }
36
+ }
37
+ }
38
+ if @config[:show_on_click]
39
+ script {
40
+ %Q(
41
+ $(document).on('click', 'tr', function(e){
42
+ e.preventDefault();
43
+ Turbolinks.visit($(this).attr('data-resource-url'), { cacheRequest: false, change: ['#{collection_member_name}', e.currentTarget.id] });
44
+ })
45
+ )
46
+ }
47
+ end
48
+ }
49
+
50
+ def resource_link
51
+ "{{resource_path(#{collection_member_name}.id)}}"
52
+ end
53
+
54
+ def row_id
55
+ "#{collection_member_name}:{{#{collection_member_name}.id}}"
56
+ end
57
+
58
+ def collection_member_name
59
+ @config[:id].to_s.singularize
60
+ end
61
+
62
+ def collection_var
63
+ "@#{collection_member_name.pluralize}".to_sym
64
+ end
65
+
66
+ def cell_value(column_name)
67
+ "{{#{collection_member_name}.#{column_name}}}"
68
+ end
69
+
70
+ def display_columns
71
+ columns.slice(0..MAX_COLS_TO_SHOW_IDX)
72
+ end
73
+
74
+ def columns_hidden?
75
+ columns.size > MAX_COLS_TO_SHOW_IDX+1
76
+ end
77
+
78
+ def show_hidden_columns_header_indicator
79
+ th._more_columns_indicator {
80
+ "..."
81
+ }
82
+ end
83
+
84
+ def show_hidden_column_cell
85
+ td._more_columns_indicator
86
+ end
87
+
88
+ def columns
89
+ resource_class.constantize.content_columns
90
+ end
91
+
92
+ def resource_class
93
+ # TODO: Module namespace needs to be guessed somehow
94
+ @config[:class_name] || "ExpressCms::#{collection_member_name.classify}"
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,22 @@
1
+ module ExpressAdmin
2
+ class WidgetBox < ExpressTemplates::Components::Column
3
+ emits -> {
4
+ div._widget_box._form_container {
5
+ h2._widget_header(box_title)
6
+ div._widget_body {
7
+ _yield
8
+ }
9
+ }
10
+ }
11
+
12
+ protected
13
+
14
+ def resource_name
15
+ my[:id].to_s.titleize
16
+ end
17
+
18
+ def box_title
19
+ "{{resource.persisted? ? 'Edit #{resource_name}' : 'New #{resource_name}'}}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,104 @@
1
+ module ExpressAdmin
2
+ module AdminHelper
3
+
4
+ # TODO move this out
5
+ #include ExpressMedia::Admin::MediaHelper if Kernel.const_defined?("ExpressMedia::Engine")
6
+
7
+ def title_partial
8
+ (ExpressAdmin::Engine.config.title_partial rescue nil) || 'shared/express_admin/title'
9
+ end
10
+
11
+ def title_partial_or_express_admin
12
+ render(title_partial) rescue 'ExpressAdmin'
13
+ end
14
+
15
+ def sign_in_or_sign_out
16
+ if self.respond_to?(:user_signed_in?)
17
+ if user_signed_in?
18
+ link_to 'Sign out', main_app.destroy_user_session_path, method: :delete
19
+ else
20
+ link_to 'Sign in', main_app.user_session_path
21
+ end
22
+ end
23
+ end
24
+
25
+ def current_module
26
+ controller.class.to_s.split('::').first.constantize
27
+ end
28
+
29
+ def current_module_path_name
30
+ current_module.to_s.underscore
31
+ end
32
+
33
+ def current_engine
34
+ "#{current_module}::Engine".constantize
35
+ end
36
+
37
+ def current_menu
38
+ ExpressAdmin::Menu[current_module_path_name]
39
+ end
40
+
41
+ def current_menu_name
42
+ current_menu.title
43
+ end
44
+
45
+ def current_user_gravatar
46
+ if defined?(current_user) && !current_user.nil?
47
+ gravatar_image_tag current_user.email
48
+ end
49
+ end
50
+
51
+ def title_content
52
+ content_for?(:title) ? yield(:title) : Rails.application.class.parent_name.underscore.titleize
53
+ end
54
+
55
+ def description_meta_content
56
+ content_for?(:description) ? yield(:description) : 'Testapp'
57
+ end
58
+
59
+ def admin_javascript_and_css_includes
60
+ current_module_path = current_module.to_s.underscore
61
+ a = []
62
+ a << stylesheet_link_tag("#{current_module_path}/admin/application")
63
+ a << stylesheet_link_tag("app_express/admin/application") if defined?(AppExpress)
64
+ a << javascript_include_tag("express_admin", 'data-turbolinks-track' => true)
65
+ a << javascript_include_tag("#{current_module_path}/admin/application", 'data-turbolinks-track' => true)
66
+ a.join()
67
+ end
68
+
69
+ def admin_menus
70
+ addons = ExpressAdmin::Engine.all_addons.map do |engine|
71
+ ExpressAdmin::Menu[engine.addon_name.to_s] rescue nil
72
+ end.compact
73
+
74
+ addons.sort do |addonA, addonB|
75
+ if addonA.position == addonB.position
76
+ addonA.title <=> addonB.title
77
+ else
78
+ addonA.position <=> addonB.position
79
+ end
80
+ end
81
+ end
82
+
83
+ def menu_item(name, path)
84
+ content_tag(:li, link_to(name, path), class: is_active?(path))
85
+ end
86
+
87
+ def is_active?(path)
88
+ if request.path.eql?(path)
89
+ "active"
90
+ else
91
+ nil
92
+ end
93
+ end
94
+
95
+ def flash_class(key)
96
+ case key
97
+ when 'notice' then 'info'
98
+ when 'success' then 'success'
99
+ when 'alert' then 'warning'
100
+ when 'error' then 'alert'
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,53 @@
1
+ module ExpressAdmin
2
+ module ModuleSettingsHelper
3
+ def edit_setting(param)
4
+ setting = setting_for(param)
5
+ domkey = param.gsub(/\W/, '_')
6
+
7
+ name = "settings[#{param}]"
8
+ title = param.titlecase
9
+ value = params[param.to_sym].nil? ? setting.value : params[param.to_sym]
10
+ html = ""
11
+
12
+ if setting.boolean?
13
+ html << content_tag(:div, class: 'form-group') do
14
+ hidden_field_tag(name, '0') +
15
+ check_box_tag(name, true, value, class: 'setting', id: domkey) +
16
+ content_tag(:label, title, class: 'checkbox', for: domkey)
17
+ end
18
+
19
+ elsif setting.selector?
20
+ html << content_tag(:div, class: 'form-group') do
21
+ content_tag(:label, title, for: domkey) +
22
+ select_tag(name, options_for_select(setting.definition.selection, value), class: 'setting', id: domkey)
23
+ end
24
+
25
+ else
26
+ html << content_tag(:div, class: 'form-group') do
27
+ content_tag(:label, title, for: domkey) +
28
+ text_field_tag(name, value, class: 'textbox', id: domkey)
29
+ end
30
+
31
+ end
32
+
33
+ if setting.errors.messages[:value]
34
+ html << content_tag(:span, [setting.errors.messages[:value]].flatten.first, class: 'error')
35
+ html = content_tag(:span, html, class: "error-with-field")
36
+ end
37
+
38
+ html.html_safe
39
+
40
+ end
41
+
42
+ def setting_for(setting)
43
+ @editable_setting ||= {}
44
+ @editable_setting[setting] ||= ExpressAdmin.module_name.constantize.settings.find_or_create_by(setting: setting)
45
+ end
46
+
47
+ def definition_for(setting)
48
+ if setting = setting_for(setting)
49
+ setting.definition
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,6 @@
1
+ div.send("small-12").columns
2
+
3
+ content_for(:page_header) {
4
+ h1 "Welcome to ExpressAdmin"
5
+ p.lead "If you see this page it is because your app has not provided a dashboard."
6
+ }
@@ -0,0 +1,31 @@
1
+ doctype
2
+ html {
3
+ head {
4
+ title { title_content }
5
+ meta(name: "description", content: "{{description_meta_content}}")
6
+ meta(name: "viewport", content: "width=device-width, initial-scale=1.0")
7
+ # Modernizr is required for Zurb Foundation
8
+ javascript_include_tag 'vendor/modernizr'
9
+ admin_javascript_and_css_includes
10
+ yield(:page_css)
11
+ csrf_meta_tags
12
+ }
13
+ body {
14
+ header {
15
+ render('shared/express_admin/navigation_bar')
16
+ }
17
+ main(role: "main")._main_container {
18
+ addon_sidebar_component
19
+ div._content_body {
20
+ flash_message_component
21
+ div.row._page_header {
22
+ page_header_component
23
+ }
24
+ div.row._page_body {
25
+ yield
26
+ }
27
+ }
28
+ }
29
+ yield(:page_javascript)
30
+ }
31
+ }
@@ -0,0 +1,15 @@
1
+ html(lang: 'en') {
2
+ head {
3
+ meta charset: 'utf-8'
4
+ meta content: 'width=device-width, initial-scale=1.0', name: 'viewport'
5
+ title { yield(:title) }
6
+ stylesheet_link_tag 'express_admin/application'
7
+ javascript_include_tag :modernizr
8
+ javascript_include_tag 'express_admin/application'
9
+ csrf_meta_tags
10
+ }
11
+ body {
12
+ flash_message_component
13
+ yield
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ flash_message_component
@@ -0,0 +1,20 @@
1
+ # navigation styled for Zurb Foundation 5
2
+ # the syntax for data-topbar may need to change for Zurb Foundation 5
3
+ nav._top_bar(data: {topbar: true, options: "is_hover:false"}) {
4
+ title_partial_or_express_admin
5
+ div._top_bar_section {
6
+ ul {
7
+ li.divider
8
+ mega_menu_component
9
+ }
10
+ }
11
+ section._top_bar_section {
12
+ ul.left {
13
+ li.divider
14
+ li {
15
+ a(href: '/') { "View Site" }
16
+ }
17
+ }
18
+ render partial: 'shared/express_admin/navigation_bar_profile'
19
+ }
20
+ }
@@ -0,0 +1,8 @@
1
+ ul.right {
2
+ li.gravatar {
3
+ current_user_gravatar
4
+ }
5
+ li {
6
+ sign_in_or_sign_out
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ ul(class: 'title-area') {
2
+ li.name {
3
+ a("ExpressAdmin", href: '#', disabled: true)
4
+ }
5
+ li(class:"toggle-topbar menu-icon") {
6
+ a(href: "#") { span { menu } }
7
+ }
8
+ }