Skip to content

Commit

Permalink
Editors can add primary link & api link to data set #15
Browse files Browse the repository at this point in the history
  • Loading branch information
rest515 committed Feb 27, 2020
1 parent 53399ef commit c1da917
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/controllers/data_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def set_data_set

def data_set_params
params.require(:data_set).permit(
:title, :body, :tag_list,
:title, :url, :api_url, :body, :tag_list,
links_attributes: [:id, :title, :body, :url, :_destroy]
)
end
Expand Down
1 change: 1 addition & 0 deletions app/models/data_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class DataSet < ApplicationRecord

validates :title, presence: true
validates :body, presence: true
validates :url, presence: true

default_scope { order("updated_at desc") }
end
2 changes: 2 additions & 0 deletions app/views/data_sets/_form.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
= simple_form_for @data_set do |f|
= f.input :title
= f.input :url
= f.input :api_url
= f.input :body, as: :summernote
= f.input :tag_list

Expand Down
31 changes: 21 additions & 10 deletions app/views/data_sets/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,34 @@
.my-4.p-4.border.bg-white
= raw @data_set.body

.py-2
.my-4
%h5= DataSet.human_attribute_name("url")
= link_to @data_set.url, @data_set.url, target: "_blank", class: "text-dark"

- if @data_set.api_url.present?
.my-4
%h5= DataSet.human_attribute_name("api_url")
= link_to @data_set.api_url, @data_set.api_url, target: "_blank", class: "text-dark"

.my-4
%h5= DataSet.human_attribute_name("tags")
- @data_set.tags.each do |tag|
= link_to "##{tag.name}", tag_path(tag), class: "text-dark"

.my-4
%h4.text-muted= t('related_info')
.list-group
- @data_set.links.each do |link|
= link_to link.url, class: "list-group-item" do
%h5.mb-1= link.title
%p.text-muted.mb-1= link.body
- if @data_set.links.any?
.my-4
%h5= DataSet.human_attribute_name("links")
.list-group
- @data_set.links.each do |link|
= link_to link.url, class: "list-group-item" do
%h5.mb-1= link.title
%p.text-muted.mb-1= link.body

.my-4
.d-flex.justify-content-between
%div
- if user_signed_in?
= link_to t('edit'), edit_data_set_path(@data_set), class: "btn btn-outline-secondary"
= link_to t('link.edit'), edit_data_set_path(@data_set), class: "btn btn-outline-secondary"
%div
- if user_signed_in? && @data_set.user == current_user
= link_to t('destroy'), @data_set, method: :delete, data: { confirm: "정말 삭제하시겠습니까?" }, class: "btn btn-outline-danger"
= link_to t('link.destroy'), @data_set, method: :delete, data: { confirm: "정말 삭제하시겠습니까?" }, class: "btn btn-outline-danger"
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- else
= link_to '에디터 등록하기', new_user_registration_path, class: 'btn btn-secondary'

%main
%main.py-2
.container
.row
.col-md-4.order-md-2.mb-4
Expand Down
6 changes: 6 additions & 0 deletions config/locales/ko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ ko:
data_set:
title: 제목
body: 내용
url: 원데이터
api_url: 관련 API
tags: 태그
links: 관련정보
link:
title: 제목
body: 요약
Expand All @@ -28,6 +32,8 @@ ko:
main:
title: 원데이터
link:
edit: 수정
destroy: 삭제
sign_in: 로그인
sign_out: 로그아웃

Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20200227101505_add_columns_to_data_sets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddColumnsToDataSets < ActiveRecord::Migration[5.2]
def change
add_column :data_sets, :url, :string
add_column :data_sets, :api_url, :string
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_02_14_025012) do
ActiveRecord::Schema.define(version: 2020_02_27_101505) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -35,6 +35,8 @@
t.bigint "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "url"
t.string "api_url"
t.index ["user_id"], name: "index_data_sets_on_user_id"
end

Expand Down

0 comments on commit c1da917

Please sign in to comment.