From 015677a24be6c60d29977f06c8a3e600928148dc Mon Sep 17 00:00:00 2001 From: Peter Halloran Date: Fri, 19 May 2017 15:24:52 -0500 Subject: [PATCH 1/7] feat: add charts_widget column to webpages --- ...0519201648_add_charts_widget_to_webpage.rb | 5 + db/schema.rb | 163 ++++++++++-------- 2 files changed, 92 insertions(+), 76 deletions(-) create mode 100644 db/migrate/20170519201648_add_charts_widget_to_webpage.rb diff --git a/db/migrate/20170519201648_add_charts_widget_to_webpage.rb b/db/migrate/20170519201648_add_charts_widget_to_webpage.rb new file mode 100644 index 000000000..5d88d8c10 --- /dev/null +++ b/db/migrate/20170519201648_add_charts_widget_to_webpage.rb @@ -0,0 +1,5 @@ +class AddChartsWidgetToWebpage < ActiveRecord::Migration[5.0] + def change + add_column :webpages, :charts_widget, :jsonb + end +end diff --git a/db/schema.rb b/db/schema.rb index db1c93dc3..7b9f6d4cc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170417185915) do +ActiveRecord::Schema.define(version: 20170519201648) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -58,14 +58,19 @@ end create_table "categories", force: :cascade do |t| - t.string "name", limit: 255 - t.integer "user_id", null: false + t.string "name" + t.integer "user_id", null: false t.integer "parent_id" t.integer "lft" t.integer "rgt" t.integer "depth" t.datetime "created_at" t.datetime "updated_at" + t.index ["depth"], name: "index_categories_on_depth", using: :btree + t.index ["lft"], name: "index_categories_on_lft", using: :btree + t.index ["parent_id"], name: "index_categories_on_parent_id", using: :btree + t.index ["rgt"], name: "index_categories_on_rgt", using: :btree + t.index ["user_id"], name: "index_categories_on_user_id", using: :btree end create_table "categories_posts", id: false, force: :cascade do |t| @@ -208,23 +213,24 @@ end create_table "media", force: :cascade do |t| - t.string "name", limit: 255 + t.string "name" t.integer "user_id" - t.string "attachment_file_name", limit: 255 - t.string "attachment_content_type", limit: 255 + t.string "attachment_file_name" + t.string "attachment_content_type" t.integer "attachment_file_size" t.datetime "attachment_updated_at" - t.string "dimensions", limit: 255 + t.string "dimensions" t.text "description" - t.string "alt", limit: 255 + t.string "alt" t.boolean "active" t.datetime "deactive_at" t.datetime "created_at" t.datetime "updated_at" - t.string "digest", limit: 255 + t.string "digest" t.datetime "deleted_at" t.hstore "meta" - t.string "type", limit: 255, default: "Media", null: false + t.string "type", default: "Media", null: false + t.index ["name"], name: "index_media_on_name", using: :btree t.index ["user_id"], name: "index_media_on_user_id", using: :btree end @@ -234,48 +240,48 @@ end create_table "oauth_access_grants", force: :cascade do |t| - t.integer "resource_owner_id", null: false - t.integer "application_id", null: false - t.string "token", limit: 255, null: false - t.integer "expires_in", null: false - t.text "redirect_uri", null: false - t.datetime "created_at", null: false + t.integer "resource_owner_id", null: false + t.integer "application_id", null: false + t.string "token", null: false + t.integer "expires_in", null: false + t.text "redirect_uri", null: false + t.datetime "created_at", null: false t.datetime "revoked_at" - t.string "scopes", limit: 255 + t.string "scopes" t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true, using: :btree end create_table "oauth_access_tokens", force: :cascade do |t| t.integer "resource_owner_id" t.integer "application_id" - t.string "token", limit: 255, null: false - t.string "refresh_token", limit: 255 + t.string "token", null: false + t.string "refresh_token" t.integer "expires_in" t.datetime "revoked_at" - t.datetime "created_at", null: false - t.string "scopes", limit: 255 + t.datetime "created_at", null: false + t.string "scopes" t.index ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true, using: :btree t.index ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id", using: :btree t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true, using: :btree end create_table "oauth_applications", force: :cascade do |t| - t.string "name", limit: 255, null: false - t.string "uid", limit: 255, null: false - t.string "secret", limit: 255, null: false - t.text "redirect_uri", null: false + t.string "name", null: false + t.string "uid", null: false + t.string "secret", null: false + t.text "redirect_uri", null: false t.datetime "created_at" t.datetime "updated_at" t.integer "owner_id" - t.string "owner_type", limit: 255 - t.string "scopes", default: "", null: false + t.string "owner_type" + t.string "scopes", default: "", null: false t.index ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type", using: :btree t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true, using: :btree end create_table "onet_occupations", force: :cascade do |t| - t.string "soc", limit: 255 - t.string "title", limit: 255 + t.string "soc" + t.string "title" t.text "description" t.datetime "created_at" t.datetime "updated_at" @@ -295,44 +301,45 @@ end create_table "posts", force: :cascade do |t| - t.integer "user_id", null: false - t.string "title", limit: 255 + t.integer "user_id", null: false + t.string "title" t.datetime "published_at" t.datetime "expired_at" t.datetime "deleted_at" - t.boolean "draft", default: true, null: false - t.integer "comment_count", default: 0, null: false + t.boolean "draft", default: true, null: false + t.integer "comment_count", default: 0, null: false t.text "body" t.datetime "created_at" t.datetime "updated_at" - t.string "short_description", limit: 255 - t.integer "job_phase", null: false - t.integer "display", null: false + t.string "short_description" + t.integer "job_phase", null: false + t.integer "display", null: false t.text "notes" - t.string "copyright_owner", limit: 255 - t.string "seo_title", limit: 255 - t.string "seo_description", limit: 255 - t.string "seo_preview", limit: 255 - t.string "custom_author", limit: 255 - t.string "slug", null: false + t.string "copyright_owner" + t.string "seo_title" + t.string "seo_description" + t.string "seo_preview" + t.string "custom_author" + t.string "slug", null: false t.integer "featured_media_id" t.integer "primary_industry_id" t.integer "primary_category_id" t.integer "tile_media_id" t.hstore "meta" - t.string "type", default: "Post", null: false + t.string "type", default: "Post", null: false t.integer "author_id" - t.boolean "is_wysiwyg", default: true - t.boolean "noindex", default: false - t.boolean "nofollow", default: false - t.boolean "nosnippet", default: false - t.boolean "noodp", default: false - t.boolean "noarchive", default: false - t.boolean "noimageindex", default: false - t.boolean "is_sticky", default: false + t.boolean "is_wysiwyg", default: true + t.boolean "noindex", default: false + t.boolean "nofollow", default: false + t.boolean "nosnippet", default: false + t.boolean "noodp", default: false + t.boolean "noarchive", default: false + t.boolean "noimageindex", default: false + t.boolean "is_sticky", default: false t.index ["author_id"], name: "index_posts_on_author_id", using: :btree t.index ["slug"], name: "index_posts_on_slug", using: :btree t.index ["type"], name: "index_posts_on_type", using: :btree + t.index ["user_id"], name: "index_posts_on_user_id", using: :btree end create_table "role_permissions", force: :cascade do |t| @@ -344,10 +351,11 @@ create_table "roles", force: :cascade do |t| t.string "name" - t.datetime "created_at" - t.datetime "updated_at" t.string "resource_type" - t.string "resource_id" + t.integer "resource_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree t.index ["name"], name: "index_roles_on_name", using: :btree end @@ -363,10 +371,10 @@ create_table "taggings", force: :cascade do |t| t.integer "tag_id" + t.string "taggable_type" t.integer "taggable_id" - t.string "taggable_type", limit: 255 + t.string "tagger_type" t.integer "tagger_id" - t.string "tagger_type", limit: 255 t.string "context", limit: 128 t.datetime "created_at" t.index ["context"], name: "index_taggings_on_context", using: :btree @@ -381,9 +389,8 @@ end create_table "tags", force: :cascade do |t| - t.string "name", limit: 255 - t.integer "taggings_count", default: 0 - t.integer "tenant_id", default: 1 + t.string "name" + t.integer "taggings_count", default: 0 t.index ["name"], name: "index_tags_on_name", unique: true, using: :btree end @@ -398,43 +405,47 @@ t.string "contact_email", limit: 200 t.string "contact_phone", limit: 20 t.datetime "deleted_at" - t.string "contract", limit: 255 - t.string "did", limit: 255 + t.string "contract" + t.string "did" t.datetime "active_at" t.datetime "deactive_at" t.integer "owner_id" t.datetime "created_at" t.datetime "updated_at" + t.index ["did"], name: "index_tenants_on_did", using: :btree + t.index ["owner_id"], name: "index_tenants_on_owner_id", using: :btree t.index ["parent_id"], name: "index_tenants_on_parent_id", using: :btree end create_table "users", force: :cascade do |t| - t.string "email", limit: 255, default: "", null: false + t.string "email", default: "", null: false t.datetime "created_at" t.datetime "updated_at" - t.integer "tenant_id", null: false - t.string "encrypted_password", limit: 255, default: "", null: false - t.string "reset_password_token", limit: 255 + t.integer "tenant_id", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip", limit: 255 - t.string "last_sign_in_ip", limit: 255 - t.string "firstname", limit: 255, null: false - t.string "lastname", limit: 255 - t.string "locale", limit: 30, default: "en_US", null: false - t.string "timezone", limit: 30, default: "EST", null: false - t.boolean "admin", default: false, null: false + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "firstname", null: false + t.string "lastname" + t.string "locale", limit: 30, default: "en_US", null: false + t.string "timezone", limit: 30, default: "EST", null: false + t.boolean "admin", default: false, null: false t.index ["email"], name: "index_users_on_email", unique: true, using: :btree t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree t.index ["tenant_id"], name: "index_users_on_tenant_id", using: :btree end create_table "users_roles", id: false, force: :cascade do |t| - t.integer "user_id" - t.integer "role_id" + t.integer "user_id" + t.integer "role_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree end @@ -457,10 +468,10 @@ t.boolean "noodp", default: false t.boolean "noarchive", default: false t.boolean "noimageindex", default: false - t.text "seo_keywords" t.string "dynamic_yield_sku" t.string "dynamic_yield_category" t.jsonb "tables_widget" + t.jsonb "charts_widget" t.index ["user_id"], name: "index_webpages_on_user_id", using: :btree end From 2587d210229f4b133683444ece4586eab3dc9a11 Mon Sep 17 00:00:00 2001 From: Peter Halloran Date: Fri, 19 May 2017 15:33:20 -0500 Subject: [PATCH 2/7] feat: copy tables widget methods in Webpage model --- app/models/webpage.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/models/webpage.rb b/app/models/webpage.rb index 8a414ca97..1ee3c9fa6 100644 --- a/app/models/webpage.rb +++ b/app/models/webpage.rb @@ -3,6 +3,7 @@ class Webpage < ApplicationRecord include SearchableWebpage serialize :tables_widget + serialize :charts_widget scope :find_by_protocol_agnostic_url, ->(suffix) { where('url LIKE :suffix', suffix: "%#{suffix}") } @@ -30,4 +31,20 @@ def tables_widget_json def tables_widget_json= p self.tables_widget = JSON.parse(p, quirks_mode: true) # Quirks mode will let us parse a null JSON object end + + def charts_widget_yaml + charts_widget.to_yaml + end + + def charts_widget_yaml= p + self.charts_widget = YAML.load(p) + end + + def charts_widget_json + charts_chart.to_json + end + + def charts_widget_json= p + self.charts_widget = JSON.parse(p, quirks_mode: true) # Quirks mode will let us parse a null JSON object + end end From 56c54773eb78baee87f1475ff79dfd5d7b47ae40 Mon Sep 17 00:00:00 2001 From: Peter Halloran Date: Fri, 19 May 2017 15:37:56 -0500 Subject: [PATCH 3/7] feat: copy table widget api config in grape webpage entity --- app/api/v1/entities/webpage.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/api/v1/entities/webpage.rb b/app/api/v1/entities/webpage.rb index d1d15701c..12930a721 100644 --- a/app/api/v1/entities/webpage.rb +++ b/app/api/v1/entities/webpage.rb @@ -21,12 +21,14 @@ class Webpage < Grape::Entity expose :dynamic_yield_category, documentation: { type: 'String', desc: "Dynamic Yield Webpage Category" } expose :tables_widget_json, documentation: {type: 'Hash', is_array: true, desc: 'Tables Widget Data as JSON'} + expose :charts_widget_json, documentation: {type: 'Hash', is_array: true, desc: 'Charts Widget Data as JSON'} with_options if: { full: true } do expose :user, with: '::V1::Entities::User', documentation: {type: 'User', desc: 'Owner'} expose :url, documentation: { type: 'String', desc: 'URL of Webpage' } expose :tables_widget_yaml, documentation: {type: 'Hash', is_array: true, desc: 'Tables Widget Data as YAML'} + expose :charts_widget_yaml, documentation: {type: 'Hash', is_array: true, desc: 'Charts Widget Data as YAML'} end end end From 8cf63bd6c5a916fd1022c897888fd83e572bafc0 Mon Sep 17 00:00:00 2001 From: Peter Halloran Date: Mon, 22 May 2017 09:09:35 -0500 Subject: [PATCH 4/7] feat: add markup for chartwidget input --- app/assets/legacy_templates/webpages/edit.html | 8 ++++++++ app/models/webpage.rb | 2 +- content-snippets-edit | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) create mode 120000 content-snippets-edit diff --git a/app/assets/legacy_templates/webpages/edit.html b/app/assets/legacy_templates/webpages/edit.html index 873988a3b..443dbabc4 100644 --- a/app/assets/legacy_templates/webpages/edit.html +++ b/app/assets/legacy_templates/webpages/edit.html @@ -113,6 +113,14 @@ placeholder="YAML-formatted table data"> +
+
+ + +
+
diff --git a/app/models/webpage.rb b/app/models/webpage.rb index 1ee3c9fa6..9cc3b6168 100644 --- a/app/models/webpage.rb +++ b/app/models/webpage.rb @@ -41,7 +41,7 @@ def charts_widget_yaml= p end def charts_widget_json - charts_chart.to_json + charts_widget.to_json end def charts_widget_json= p diff --git a/content-snippets-edit b/content-snippets-edit new file mode 120000 index 000000000..b3dcb96a5 --- /dev/null +++ b/content-snippets-edit @@ -0,0 +1 @@ +/Users/phalloran/Users/phalloran/employer/content-snippets-edit \ No newline at end of file From 170eaa4172f3c1a186c81f432d27c031e9f47850 Mon Sep 17 00:00:00 2001 From: Peter Halloran Date: Mon, 22 May 2017 12:40:06 -0500 Subject: [PATCH 5/7] fix: place charts_widget_yaml in the same form as tabels_widget_yaml --- app/assets/legacy_templates/webpages/edit.html | 2 -- content-snippets-edit | 1 - public/ipe/content-snippets-edit | 1 + 3 files changed, 1 insertion(+), 3 deletions(-) delete mode 120000 content-snippets-edit create mode 120000 public/ipe/content-snippets-edit diff --git a/app/assets/legacy_templates/webpages/edit.html b/app/assets/legacy_templates/webpages/edit.html index 443dbabc4..c3a968934 100644 --- a/app/assets/legacy_templates/webpages/edit.html +++ b/app/assets/legacy_templates/webpages/edit.html @@ -112,8 +112,6 @@ ng-model="data.webpage.tables_widget_yaml" placeholder="YAML-formatted table data"> - -