From b0083827f30fccc9aabcabed0557ace83d570b8c Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 30 Jul 2016 05:32:26 -0400 Subject: add sites list and site-add dialog --- src/guff/models/theme.cr | 15 +++ src/guff/views/dialogs/admin/site-add.cr | 5 + src/guff/views/dialogs/admin/site.cr | 21 ++++ src/guff/views/pages/admin.cr | 4 + src/views/dialogs/admin/site-add.ecr | 179 +++++++++++++++++++++++++++++++ 5 files changed, 224 insertions(+) create mode 100644 src/guff/views/dialogs/admin/site-add.cr create mode 100644 src/guff/views/dialogs/admin/site.cr create mode 100644 src/views/dialogs/admin/site-add.ecr (limited to 'src') diff --git a/src/guff/models/theme.cr b/src/guff/models/theme.cr index 5b24a71..2e8730b 100644 --- a/src/guff/models/theme.cr +++ b/src/guff/models/theme.cr @@ -40,6 +40,17 @@ class Guff::Models::ThemeModel < Guff::Models::Model WHERE %s ", + get_default_id: " + SELECT theme_id + + FROM themes + + WHERE is_system + AND theme_slug = 'default' + + LIMIT 1 + ", + get_data: " SELECT a.data_key, a.data_val @@ -247,6 +258,10 @@ class Guff::Models::ThemeModel < Guff::Models::Model @context.dbs.ro.row(SQL[:get] % sql.join(" AND "), args).not_nil! end + def get_default_id : Int64 + @context.dbs.ro.one(SQL[:get_default_id]).not_nil!.to_i64 + end + def templates(theme_id : Int32) unless @cache[:templates].includes?(theme_id) # get theme diff --git a/src/guff/views/dialogs/admin/site-add.cr b/src/guff/views/dialogs/admin/site-add.cr new file mode 100644 index 0000000..894a34a --- /dev/null +++ b/src/guff/views/dialogs/admin/site-add.cr @@ -0,0 +1,5 @@ +require "./site" + +class Guff::Views::Dialogs::Admin::SiteAdd < Guff::Views::Dialogs::Admin::Site + ECR.def_to_s("src/views/dialogs/admin/site-add.ecr") +end diff --git a/src/guff/views/dialogs/admin/site.cr b/src/guff/views/dialogs/admin/site.cr new file mode 100644 index 0000000..1b6419b --- /dev/null +++ b/src/guff/views/dialogs/admin/site.cr @@ -0,0 +1,21 @@ +class Guff::Views::Dialogs::Admin::Site < Guff::Views::HTMLView + TEMPLATES = { + y: "", + n: "", + } + + private def theme_options + @context.models.theme.all.map { |row| + { + id: row["theme_id"], + slug: row["theme_slug"], + name: "%s (%s)" % %w{name version}.map { |k| + row["theme_#{k}"] + }, + } + }.map { |row| + tmpl_id = (row[:slug] == "default") ? :y : :n + TEMPLATES[tmpl_id] % %i{id slug name}.map { |k| row[k] } + }.join("") + end +end diff --git a/src/guff/views/pages/admin.cr b/src/guff/views/pages/admin.cr index 688e715..1c5f795 100644 --- a/src/guff/views/pages/admin.cr +++ b/src/guff/views/pages/admin.cr @@ -28,6 +28,7 @@ class Guff::Views::Pages::Admin < Guff::Views::HTMLView assets/js/admin/tabs/themes.js assets/js/admin/dialogs/user-add.js assets/js/admin/dialogs/user-edit.js + assets/js/admin/dialogs/site-add.js assets/js/admin/dialogs/post-edit.js assets/js/admin/dialogs/blog-edit.js assets/js/admin/dialogs/page-edit.js @@ -95,6 +96,7 @@ class Guff::Views::Pages::Admin < Guff::Views::HTMLView String.build do |io| io << Dialogs::Admin::UserAdd.new(@context) io << Dialogs::Admin::UserEdit.new(@context) + io << Dialogs::Admin::SiteAdd.new(@context) io << Dialogs::Admin::BlogEdit.new(@context) io << Dialogs::Admin::PageEdit.new(@context) io << Dialogs::Admin::ProjectEdit.new(@context) @@ -106,6 +108,8 @@ class Guff::Views::Pages::Admin < Guff::Views::HTMLView post_types: POST_TYPES, sites: @context.models.site.get_sites, default_site_id: @context.models.site.get_default_id, + default_lang: "en-US", + default_theme_id: @context.models.theme.get_default_id, }.to_json end diff --git a/src/views/dialogs/admin/site-add.ecr b/src/views/dialogs/admin/site-add.ecr new file mode 100644 index 0000000..aae2f70 --- /dev/null +++ b/src/views/dialogs/admin/site-add.ecr @@ -0,0 +1,179 @@ + -- cgit v1.2.3