Skip to content

Commit 2c57097

Browse files
authored
Merge pull request #500 from cbdr/topic/EM-1417/Create-Chart-Widget
topic/EM-1417: Create Charts Widget Support in Cortex Legacy
2 parents a1575f1 + 85a9003 commit 2c57097

File tree

6 files changed

+118
-76
lines changed

6 files changed

+118
-76
lines changed

app/api/v1/entities/webpage.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ class Webpage < Grape::Entity
2121
expose :dynamic_yield_category, documentation: { type: 'String', desc: "Dynamic Yield Webpage Category" }
2222

2323
expose :tables_widget_json, documentation: {type: 'Hash', is_array: true, desc: 'Tables Widget Data as JSON'}
24+
expose :charts_widget_json, documentation: {type: 'Hash', is_array: true, desc: 'Charts Widget Data as JSON'}
2425

2526
with_options if: { full: true } do
2627
expose :user, with: '::V1::Entities::User', documentation: {type: 'User', desc: 'Owner'}
2728
expose :url, documentation: { type: 'String', desc: 'URL of Webpage' }
2829

2930
expose :tables_widget_yaml, documentation: {type: 'Hash', is_array: true, desc: 'Tables Widget Data as YAML'}
31+
expose :charts_widget_yaml, documentation: {type: 'Hash', is_array: true, desc: 'Charts Widget Data as YAML'}
3032
end
3133
end
3234
end

app/assets/legacy_templates/webpages/edit.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@
112112
ng-model="data.webpage.tables_widget_yaml"
113113
placeholder="YAML-formatted table data"></textarea>
114114
</div>
115+
<div class="form-group">
116+
<label for="charts_widget_yaml">Charts Data</label>
117+
<textarea id="charts_widget_yaml" name="charts_widget_yaml" class="form-control" rows="15"
118+
ng-model="data.webpage.charts_widget_yaml"
119+
placeholder="YAML-formatted chart data"></textarea>
120+
</div>
115121
</form>
116122
</div>
117123
</tab>

app/models/concerns/searchable_webpage.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module SearchableWebpage
3030
indexes :noarchive, :type => :boolean, :index => :not_analyzed
3131
indexes :noimageindex, :type => :boolean, :index => :not_analyzed
3232
indexes :tables_widget, :type => :nested, :enabled => false
33+
indexes :charts_widget, :type => :nested, :enabled => false
3334
end
3435

3536
def as_indexed_json(options = {})

app/models/webpage.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class Webpage < ApplicationRecord
33
include SearchableWebpage
44

55
serialize :tables_widget
6+
serialize :charts_widget
67

78
scope :find_by_protocol_agnostic_url, ->(suffix) { where('url LIKE :suffix', suffix: "%#{suffix}") }
89

@@ -30,4 +31,20 @@ def tables_widget_json
3031
def tables_widget_json= p
3132
self.tables_widget = JSON.parse(p, quirks_mode: true) # Quirks mode will let us parse a null JSON object
3233
end
34+
35+
def charts_widget_yaml
36+
charts_widget.to_yaml
37+
end
38+
39+
def charts_widget_yaml= p
40+
self.charts_widget = YAML.load(p)
41+
end
42+
43+
def charts_widget_json
44+
charts_widget.to_json
45+
end
46+
47+
def charts_widget_json= p
48+
self.charts_widget = JSON.parse(p, quirks_mode: true) # Quirks mode will let us parse a null JSON object
49+
end
3350
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddChartsWidgetToWebpage < ActiveRecord::Migration[5.0]
2+
def change
3+
add_column :webpages, :charts_widget, :jsonb
4+
end
5+
end

db/schema.rb

Lines changed: 87 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 20170417185915) do
13+
ActiveRecord::Schema.define(version: 20170519201648) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -58,14 +58,19 @@
5858
end
5959

6060
create_table "categories", force: :cascade do |t|
61-
t.string "name", limit: 255
62-
t.integer "user_id", null: false
61+
t.string "name"
62+
t.integer "user_id", null: false
6363
t.integer "parent_id"
6464
t.integer "lft"
6565
t.integer "rgt"
6666
t.integer "depth"
6767
t.datetime "created_at"
6868
t.datetime "updated_at"
69+
t.index ["depth"], name: "index_categories_on_depth", using: :btree
70+
t.index ["lft"], name: "index_categories_on_lft", using: :btree
71+
t.index ["parent_id"], name: "index_categories_on_parent_id", using: :btree
72+
t.index ["rgt"], name: "index_categories_on_rgt", using: :btree
73+
t.index ["user_id"], name: "index_categories_on_user_id", using: :btree
6974
end
7075

7176
create_table "categories_posts", id: false, force: :cascade do |t|
@@ -208,23 +213,24 @@
208213
end
209214

210215
create_table "media", force: :cascade do |t|
211-
t.string "name", limit: 255
216+
t.string "name"
212217
t.integer "user_id"
213-
t.string "attachment_file_name", limit: 255
214-
t.string "attachment_content_type", limit: 255
218+
t.string "attachment_file_name"
219+
t.string "attachment_content_type"
215220
t.integer "attachment_file_size"
216221
t.datetime "attachment_updated_at"
217-
t.string "dimensions", limit: 255
222+
t.string "dimensions"
218223
t.text "description"
219-
t.string "alt", limit: 255
224+
t.string "alt"
220225
t.boolean "active"
221226
t.datetime "deactive_at"
222227
t.datetime "created_at"
223228
t.datetime "updated_at"
224-
t.string "digest", limit: 255
229+
t.string "digest"
225230
t.datetime "deleted_at"
226231
t.hstore "meta"
227-
t.string "type", limit: 255, default: "Media", null: false
232+
t.string "type", default: "Media", null: false
233+
t.index ["name"], name: "index_media_on_name", using: :btree
228234
t.index ["user_id"], name: "index_media_on_user_id", using: :btree
229235
end
230236

@@ -234,48 +240,48 @@
234240
end
235241

236242
create_table "oauth_access_grants", force: :cascade do |t|
237-
t.integer "resource_owner_id", null: false
238-
t.integer "application_id", null: false
239-
t.string "token", limit: 255, null: false
240-
t.integer "expires_in", null: false
241-
t.text "redirect_uri", null: false
242-
t.datetime "created_at", null: false
243+
t.integer "resource_owner_id", null: false
244+
t.integer "application_id", null: false
245+
t.string "token", null: false
246+
t.integer "expires_in", null: false
247+
t.text "redirect_uri", null: false
248+
t.datetime "created_at", null: false
243249
t.datetime "revoked_at"
244-
t.string "scopes", limit: 255
250+
t.string "scopes"
245251
t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true, using: :btree
246252
end
247253

248254
create_table "oauth_access_tokens", force: :cascade do |t|
249255
t.integer "resource_owner_id"
250256
t.integer "application_id"
251-
t.string "token", limit: 255, null: false
252-
t.string "refresh_token", limit: 255
257+
t.string "token", null: false
258+
t.string "refresh_token"
253259
t.integer "expires_in"
254260
t.datetime "revoked_at"
255-
t.datetime "created_at", null: false
256-
t.string "scopes", limit: 255
261+
t.datetime "created_at", null: false
262+
t.string "scopes"
257263
t.index ["refresh_token"], name: "index_oauth_access_tokens_on_refresh_token", unique: true, using: :btree
258264
t.index ["resource_owner_id"], name: "index_oauth_access_tokens_on_resource_owner_id", using: :btree
259265
t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true, using: :btree
260266
end
261267

262268
create_table "oauth_applications", force: :cascade do |t|
263-
t.string "name", limit: 255, null: false
264-
t.string "uid", limit: 255, null: false
265-
t.string "secret", limit: 255, null: false
266-
t.text "redirect_uri", null: false
269+
t.string "name", null: false
270+
t.string "uid", null: false
271+
t.string "secret", null: false
272+
t.text "redirect_uri", null: false
267273
t.datetime "created_at"
268274
t.datetime "updated_at"
269275
t.integer "owner_id"
270-
t.string "owner_type", limit: 255
271-
t.string "scopes", default: "", null: false
276+
t.string "owner_type"
277+
t.string "scopes", default: "", null: false
272278
t.index ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type", using: :btree
273279
t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true, using: :btree
274280
end
275281

276282
create_table "onet_occupations", force: :cascade do |t|
277-
t.string "soc", limit: 255
278-
t.string "title", limit: 255
283+
t.string "soc"
284+
t.string "title"
279285
t.text "description"
280286
t.datetime "created_at"
281287
t.datetime "updated_at"
@@ -295,44 +301,45 @@
295301
end
296302

297303
create_table "posts", force: :cascade do |t|
298-
t.integer "user_id", null: false
299-
t.string "title", limit: 255
304+
t.integer "user_id", null: false
305+
t.string "title"
300306
t.datetime "published_at"
301307
t.datetime "expired_at"
302308
t.datetime "deleted_at"
303-
t.boolean "draft", default: true, null: false
304-
t.integer "comment_count", default: 0, null: false
309+
t.boolean "draft", default: true, null: false
310+
t.integer "comment_count", default: 0, null: false
305311
t.text "body"
306312
t.datetime "created_at"
307313
t.datetime "updated_at"
308-
t.string "short_description", limit: 255
309-
t.integer "job_phase", null: false
310-
t.integer "display", null: false
314+
t.string "short_description"
315+
t.integer "job_phase", null: false
316+
t.integer "display", null: false
311317
t.text "notes"
312-
t.string "copyright_owner", limit: 255
313-
t.string "seo_title", limit: 255
314-
t.string "seo_description", limit: 255
315-
t.string "seo_preview", limit: 255
316-
t.string "custom_author", limit: 255
317-
t.string "slug", null: false
318+
t.string "copyright_owner"
319+
t.string "seo_title"
320+
t.string "seo_description"
321+
t.string "seo_preview"
322+
t.string "custom_author"
323+
t.string "slug", null: false
318324
t.integer "featured_media_id"
319325
t.integer "primary_industry_id"
320326
t.integer "primary_category_id"
321327
t.integer "tile_media_id"
322328
t.hstore "meta"
323-
t.string "type", default: "Post", null: false
329+
t.string "type", default: "Post", null: false
324330
t.integer "author_id"
325-
t.boolean "is_wysiwyg", default: true
326-
t.boolean "noindex", default: false
327-
t.boolean "nofollow", default: false
328-
t.boolean "nosnippet", default: false
329-
t.boolean "noodp", default: false
330-
t.boolean "noarchive", default: false
331-
t.boolean "noimageindex", default: false
332-
t.boolean "is_sticky", default: false
331+
t.boolean "is_wysiwyg", default: true
332+
t.boolean "noindex", default: false
333+
t.boolean "nofollow", default: false
334+
t.boolean "nosnippet", default: false
335+
t.boolean "noodp", default: false
336+
t.boolean "noarchive", default: false
337+
t.boolean "noimageindex", default: false
338+
t.boolean "is_sticky", default: false
333339
t.index ["author_id"], name: "index_posts_on_author_id", using: :btree
334340
t.index ["slug"], name: "index_posts_on_slug", using: :btree
335341
t.index ["type"], name: "index_posts_on_type", using: :btree
342+
t.index ["user_id"], name: "index_posts_on_user_id", using: :btree
336343
end
337344

338345
create_table "role_permissions", force: :cascade do |t|
@@ -344,10 +351,11 @@
344351

345352
create_table "roles", force: :cascade do |t|
346353
t.string "name"
347-
t.datetime "created_at"
348-
t.datetime "updated_at"
349354
t.string "resource_type"
350-
t.string "resource_id"
355+
t.integer "resource_id"
356+
t.datetime "created_at", null: false
357+
t.datetime "updated_at", null: false
358+
t.index ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id", using: :btree
351359
t.index ["name"], name: "index_roles_on_name", using: :btree
352360
end
353361

@@ -363,10 +371,10 @@
363371

364372
create_table "taggings", force: :cascade do |t|
365373
t.integer "tag_id"
374+
t.string "taggable_type"
366375
t.integer "taggable_id"
367-
t.string "taggable_type", limit: 255
376+
t.string "tagger_type"
368377
t.integer "tagger_id"
369-
t.string "tagger_type", limit: 255
370378
t.string "context", limit: 128
371379
t.datetime "created_at"
372380
t.index ["context"], name: "index_taggings_on_context", using: :btree
@@ -381,9 +389,8 @@
381389
end
382390

383391
create_table "tags", force: :cascade do |t|
384-
t.string "name", limit: 255
385-
t.integer "taggings_count", default: 0
386-
t.integer "tenant_id", default: 1
392+
t.string "name"
393+
t.integer "taggings_count", default: 0
387394
t.index ["name"], name: "index_tags_on_name", unique: true, using: :btree
388395
end
389396

@@ -398,43 +405,47 @@
398405
t.string "contact_email", limit: 200
399406
t.string "contact_phone", limit: 20
400407
t.datetime "deleted_at"
401-
t.string "contract", limit: 255
402-
t.string "did", limit: 255
408+
t.string "contract"
409+
t.string "did"
403410
t.datetime "active_at"
404411
t.datetime "deactive_at"
405412
t.integer "owner_id"
406413
t.datetime "created_at"
407414
t.datetime "updated_at"
415+
t.index ["did"], name: "index_tenants_on_did", using: :btree
416+
t.index ["owner_id"], name: "index_tenants_on_owner_id", using: :btree
408417
t.index ["parent_id"], name: "index_tenants_on_parent_id", using: :btree
409418
end
410419

411420
create_table "users", force: :cascade do |t|
412-
t.string "email", limit: 255, default: "", null: false
421+
t.string "email", default: "", null: false
413422
t.datetime "created_at"
414423
t.datetime "updated_at"
415-
t.integer "tenant_id", null: false
416-
t.string "encrypted_password", limit: 255, default: "", null: false
417-
t.string "reset_password_token", limit: 255
424+
t.integer "tenant_id", null: false
425+
t.string "encrypted_password", default: "", null: false
426+
t.string "reset_password_token"
418427
t.datetime "reset_password_sent_at"
419428
t.datetime "remember_created_at"
420-
t.integer "sign_in_count", default: 0, null: false
429+
t.integer "sign_in_count", default: 0, null: false
421430
t.datetime "current_sign_in_at"
422431
t.datetime "last_sign_in_at"
423-
t.string "current_sign_in_ip", limit: 255
424-
t.string "last_sign_in_ip", limit: 255
425-
t.string "firstname", limit: 255, null: false
426-
t.string "lastname", limit: 255
427-
t.string "locale", limit: 30, default: "en_US", null: false
428-
t.string "timezone", limit: 30, default: "EST", null: false
429-
t.boolean "admin", default: false, null: false
432+
t.string "current_sign_in_ip"
433+
t.string "last_sign_in_ip"
434+
t.string "firstname", null: false
435+
t.string "lastname"
436+
t.string "locale", limit: 30, default: "en_US", null: false
437+
t.string "timezone", limit: 30, default: "EST", null: false
438+
t.boolean "admin", default: false, null: false
430439
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
431440
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
432441
t.index ["tenant_id"], name: "index_users_on_tenant_id", using: :btree
433442
end
434443

435444
create_table "users_roles", id: false, force: :cascade do |t|
436-
t.integer "user_id"
437-
t.integer "role_id"
445+
t.integer "user_id"
446+
t.integer "role_id"
447+
t.datetime "created_at", null: false
448+
t.datetime "updated_at", null: false
438449
t.index ["user_id", "role_id"], name: "index_users_roles_on_user_id_and_role_id", using: :btree
439450
end
440451

@@ -457,10 +468,10 @@
457468
t.boolean "noodp", default: false
458469
t.boolean "noarchive", default: false
459470
t.boolean "noimageindex", default: false
460-
t.text "seo_keywords"
461471
t.string "dynamic_yield_sku"
462472
t.string "dynamic_yield_category"
463473
t.jsonb "tables_widget"
474+
t.jsonb "charts_widget"
464475
t.index ["user_id"], name: "index_webpages_on_user_id", using: :btree
465476
end
466477

0 commit comments

Comments
 (0)