diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-08-12 07:10:16 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-08-12 07:10:16 -0400 |
commit | c650bee03937bd0e741e701f1fe0bfe5cf8e040e (patch) | |
tree | c0020572ceef21498da9b52851242b22dba7aafe | |
parent | 77e849b66719f5e86762eff4ae23340dab1b32fa (diff) | |
download | thoughts-c650bee03937bd0e741e701f1fe0bfe5cf8e040e.tar.gz thoughts-c650bee03937bd0e741e701f1fe0bfe5cf8e040e.tar.bz2 thoughts-c650bee03937bd0e741e701f1fe0bfe5cf8e040e.zip |
Add link entry type
-rw-r--r-- | app/assets/stylesheets/admin/layout.scss | 10 | ||||
-rw-r--r-- | app/assets/stylesheets/main/records.scss | 4 | ||||
-rw-r--r-- | app/controllers/admin/links_controller.rb | 52 | ||||
-rw-r--r-- | app/models/link.rb | 15 | ||||
-rw-r--r-- | app/views/admin/links/_form.html.haml | 26 | ||||
-rw-r--r-- | app/views/admin/links/edit.html.haml | 3 | ||||
-rw-r--r-- | app/views/admin/links/index.html.haml | 14 | ||||
-rw-r--r-- | app/views/admin/links/new.html.haml | 3 | ||||
-rw-r--r-- | app/views/layouts/admin.html.haml | 4 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | db/migrate/20180811215146_create_links.rb | 10 | ||||
-rw-r--r-- | db/schema.rb | 9 |
12 files changed, 151 insertions, 1 deletions
diff --git a/app/assets/stylesheets/admin/layout.scss b/app/assets/stylesheets/admin/layout.scss index 220dcd5..b2c561b 100644 --- a/app/assets/stylesheets/admin/layout.scss +++ b/app/assets/stylesheets/admin/layout.scss | |||
@@ -111,6 +111,16 @@ body { | |||
111 | } | 111 | } |
112 | } | 112 | } |
113 | 113 | ||
114 | .url-field { | ||
115 | label { | ||
116 | display: none; | ||
117 | } | ||
118 | |||
119 | input { | ||
120 | width: 100%; | ||
121 | } | ||
122 | } | ||
123 | |||
114 | .slug-field { | 124 | .slug-field { |
115 | display: flex; | 125 | display: flex; |
116 | font-size: 0.75em; | 126 | font-size: 0.75em; |
diff --git a/app/assets/stylesheets/main/records.scss b/app/assets/stylesheets/main/records.scss index 47fdfa3..a8b7754 100644 --- a/app/assets/stylesheets/main/records.scss +++ b/app/assets/stylesheets/main/records.scss | |||
@@ -57,6 +57,10 @@ | |||
57 | &.entry-type-stream, &.entry-type-update { | 57 | &.entry-type-stream, &.entry-type-update { |
58 | background-color: #98FB98; | 58 | background-color: #98FB98; |
59 | } | 59 | } |
60 | |||
61 | &.entry-type-link { | ||
62 | background-color: #FFCC99; | ||
63 | } | ||
60 | } | 64 | } |
61 | 65 | ||
62 | &.entry-tag { | 66 | &.entry-tag { |
diff --git a/app/controllers/admin/links_controller.rb b/app/controllers/admin/links_controller.rb new file mode 100644 index 0000000..bda0d49 --- /dev/null +++ b/app/controllers/admin/links_controller.rb | |||
@@ -0,0 +1,52 @@ | |||
1 | class Admin::LinksController < Admin::AdminController | ||
2 | before_action :set_section | ||
3 | |||
4 | def index | ||
5 | @links = Link.order(created_at: :desc) | ||
6 | end | ||
7 | |||
8 | def new | ||
9 | @link = Link.new | ||
10 | end | ||
11 | |||
12 | def create | ||
13 | @link = Link.new(link_params) | ||
14 | |||
15 | if @link.save | ||
16 | flash.notice = "Link created successfully!" | ||
17 | |||
18 | render :edit | ||
19 | else | ||
20 | flash.alert = "Error creating link." | ||
21 | |||
22 | render :new | ||
23 | end | ||
24 | end | ||
25 | |||
26 | def edit | ||
27 | @link = Link.find(params[:id]) | ||
28 | end | ||
29 | |||
30 | def update | ||
31 | @link = Link.find(params[:id]) | ||
32 | |||
33 | if @link.update_attributes(link_params) | ||
34 | flash.notice = "Link updated successfully!" | ||
35 | else | ||
36 | flash.alert = "Error updating link." | ||
37 | end | ||
38 | |||
39 | render :edit | ||
40 | end | ||
41 | |||
42 | private | ||
43 | |||
44 | def link_params | ||
45 | params.require(:link).permit(:title, :url, :tag_list, records_attributes: [:description, :_destroy]) | ||
46 | end | ||
47 | |||
48 | def set_section | ||
49 | @section = "links" | ||
50 | end | ||
51 | |||
52 | end | ||
diff --git a/app/models/link.rb b/app/models/link.rb new file mode 100644 index 0000000..81ffa2b --- /dev/null +++ b/app/models/link.rb | |||
@@ -0,0 +1,15 @@ | |||
1 | class Link < ApplicationRecord | ||
2 | include Recordable | ||
3 | |||
4 | acts_as_taggable | ||
5 | |||
6 | validates :title, :url, presence: true | ||
7 | |||
8 | def path | ||
9 | url | ||
10 | end | ||
11 | |||
12 | def taggable | ||
13 | self | ||
14 | end | ||
15 | end | ||
diff --git a/app/views/admin/links/_form.html.haml b/app/views/admin/links/_form.html.haml new file mode 100644 index 0000000..c624a3d --- /dev/null +++ b/app/views/admin/links/_form.html.haml | |||
@@ -0,0 +1,26 @@ | |||
1 | %fieldset#content | ||
2 | .title-field | ||
3 | = f.label :title | ||
4 | = f.text_field :title, placeholder: "Title" | ||
5 | .url-field | ||
6 | = f.label :url | ||
7 | = f.text_field :url, placeholder: "URL" | ||
8 | %fieldset#details | ||
9 | - if f.object.errors.any? | ||
10 | #errors.details-module | ||
11 | %h3 Error! | ||
12 | %ul | ||
13 | - f.object.errors.full_messages.each do |error| | ||
14 | %li= error | ||
15 | .details-module | ||
16 | .tags-field | ||
17 | = f.label :tag_list, "Tags" | ||
18 | = f.text_field :tag_list, type: :tags, value: f.object.tag_list.join(",") | ||
19 | .details-module | ||
20 | = f.fields_for :records, Record.new do |builder| | ||
21 | .should-create-record-field | ||
22 | = builder.check_box :_destroy, {checked: false}, "0", "1" | ||
23 | = builder.label :_destroy, "Create record?" | ||
24 | .record-description-field | ||
25 | = builder.text_area :description, placeholder: "record text" | ||
26 | .details-module= f.submit | ||
diff --git a/app/views/admin/links/edit.html.haml b/app/views/admin/links/edit.html.haml new file mode 100644 index 0000000..1c6c529 --- /dev/null +++ b/app/views/admin/links/edit.html.haml | |||
@@ -0,0 +1,3 @@ | |||
1 | - title "Editing #{@link.title}" | ||
2 | = form_for @link, url: admin_link_url(@link), html: { id: "entry-form" } do |f| | ||
3 | = render partial: "form", locals: { f: f } | ||
diff --git a/app/views/admin/links/index.html.haml b/app/views/admin/links/index.html.haml new file mode 100644 index 0000000..e66d9b7 --- /dev/null +++ b/app/views/admin/links/index.html.haml | |||
@@ -0,0 +1,14 @@ | |||
1 | - title "Links" | ||
2 | %table#entries | ||
3 | %tr | ||
4 | %th Title | ||
5 | %th Date created | ||
6 | %th | ||
7 | - @links.each do |link| | ||
8 | %tr{ class: cycle("even", "odd") } | ||
9 | %td= link.title | ||
10 | %td= link.created_at.strftime("%B %d, %Y, %l:%M%P") | ||
11 | %td | ||
12 | %ul.admin-actions | ||
13 | %li= link_to "Edit", edit_admin_link_url(link) | ||
14 | %li= link_to "Show", link.url | ||
diff --git a/app/views/admin/links/new.html.haml b/app/views/admin/links/new.html.haml new file mode 100644 index 0000000..accdfd9 --- /dev/null +++ b/app/views/admin/links/new.html.haml | |||
@@ -0,0 +1,3 @@ | |||
1 | - title "New link" | ||
2 | = form_for @link, url: admin_links_url, html: { id: "entry-form" } do |f| | ||
3 | = render partial: "form", locals: { f: f } | ||
diff --git a/app/views/layouts/admin.html.haml b/app/views/layouts/admin.html.haml index bc07335..4bfe60a 100644 --- a/app/views/layouts/admin.html.haml +++ b/app/views/layouts/admin.html.haml | |||
@@ -29,5 +29,9 @@ | |||
29 | = link_to "Streams", admin_streams_url, class: "major-link" | 29 | = link_to "Streams", admin_streams_url, class: "major-link" |
30 | %ul.minors | 30 | %ul.minors |
31 | %li.minor= link_to "New stream", new_admin_stream_url | 31 | %li.minor= link_to "New stream", new_admin_stream_url |
32 | %li{major_sidebar_attrs("links")} | ||
33 | = link_to "Links", admin_links_url, class: "major-link" | ||
34 | %ul.minors | ||
35 | %li.minor= link_to "New link", new_admin_link_url | ||
32 | #main | 36 | #main |
33 | = yield | 37 | = yield |
diff --git a/config/routes.rb b/config/routes.rb index 2d0a4ec..512c319 100644 --- a/config/routes.rb +++ b/config/routes.rb | |||
@@ -11,6 +11,8 @@ Rails.application.routes.draw do | |||
11 | resources :streams, except: [:show] do | 11 | resources :streams, except: [:show] do |
12 | resources :updates, except: [:index, :show] | 12 | resources :updates, except: [:index, :show] |
13 | end | 13 | end |
14 | |||
15 | resources :links, except: [:show] | ||
14 | end | 16 | end |
15 | 17 | ||
16 | mount Ckeditor::Engine => '/ckeditor' | 18 | mount Ckeditor::Engine => '/ckeditor' |
diff --git a/db/migrate/20180811215146_create_links.rb b/db/migrate/20180811215146_create_links.rb new file mode 100644 index 0000000..0e0ca29 --- /dev/null +++ b/db/migrate/20180811215146_create_links.rb | |||
@@ -0,0 +1,10 @@ | |||
1 | class CreateLinks < ActiveRecord::Migration[5.1] | ||
2 | def change | ||
3 | create_table :links do |t| | ||
4 | t.string :title, null: false | ||
5 | t.string :url, null: false | ||
6 | |||
7 | t.timestamps | ||
8 | end | ||
9 | end | ||
10 | end | ||
diff --git a/db/schema.rb b/db/schema.rb index 192c9c1..58891d3 100644 --- a/db/schema.rb +++ b/db/schema.rb | |||
@@ -10,7 +10,7 @@ | |||
10 | # | 10 | # |
11 | # It's strongly recommended that you check this file into your version control system. | 11 | # It's strongly recommended that you check this file into your version control system. |
12 | 12 | ||
13 | ActiveRecord::Schema.define(version: 20180707142420) do | 13 | ActiveRecord::Schema.define(version: 20180811215146) do |
14 | 14 | ||
15 | create_table "blogs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| | 15 | create_table "blogs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
16 | t.string "title" | 16 | t.string "title" |
@@ -35,6 +35,13 @@ ActiveRecord::Schema.define(version: 20180707142420) do | |||
35 | t.index ["type"], name: "index_ckeditor_assets_on_type" | 35 | t.index ["type"], name: "index_ckeditor_assets_on_type" |
36 | end | 36 | end |
37 | 37 | ||
38 | create_table "links", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci" do |t| | ||
39 | t.string "title", null: false | ||
40 | t.string "url", null: false | ||
41 | t.datetime "created_at", null: false | ||
42 | t.datetime "updated_at", null: false | ||
43 | end | ||
44 | |||
38 | create_table "pokeviewer_abilities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| | 45 | create_table "pokeviewer_abilities", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| |
39 | t.string "name", null: false | 46 | t.string "name", null: false |
40 | t.string "description", null: false | 47 | t.string "description", null: false |