Selaa lähdekoodia

Something is happening.

master
Nils Dittberner 9 vuotta sitten
vanhempi
commit
c187944b4c
28 muutettua tiedostoa jossa 344 lisäystä ja 5 poistoa
  1. +1
    -0
      Gemfile
  2. +12
    -0
      Gemfile.lock
  3. +3
    -0
      app/assets/javascripts/documents.coffee
  4. +3
    -0
      app/assets/stylesheets/documents.scss
  5. +74
    -0
      app/controllers/documents_controller.rb
  6. +1
    -1
      app/controllers/sessions_controller.rb
  7. +2
    -0
      app/helpers/documents_helper.rb
  8. +4
    -0
      app/models/document.rb
  9. +2
    -0
      app/views/documents/_document.json.jbuilder
  10. +27
    -0
      app/views/documents/_form.html.erb
  11. +6
    -0
      app/views/documents/edit.html.erb
  12. +27
    -0
      app/views/documents/index.html.erb
  13. +1
    -0
      app/views/documents/index.json.jbuilder
  14. +5
    -0
      app/views/documents/new.html.erb
  15. +13
    -0
      app/views/documents/show.html.erb
  16. +1
    -0
      app/views/documents/show.json.jbuilder
  17. +10
    -1
      app/views/layouts/application.html.erb
  18. +2
    -2
      config/routes.rb
  19. +9
    -0
      db/migrate/20161124130436_create_documents.rb
  20. +11
    -0
      db/migrate/20161124131141_add_attachment_doc_to_documents.rb
  21. +11
    -1
      db/schema.rb
  22. +57
    -0
      public/system/documents/docs/000/000/003/original/mymedicaldevicename.xml
  23. BIN
      public/system/documents/docs/000/000/004/original/02cc55df9b654cefa6c647ecc7a502fa.png
  24. BIN
      public/system/documents/docs/000/000/005/original/MyMedicalDeviceName20161119012242.zip
  25. BIN
      public/system/documents/docs/000/000/006/original/whenType.pdf
  26. +48
    -0
      test/controllers/documents_controller_test.rb
  27. +7
    -0
      test/fixtures/documents.yml
  28. +7
    -0
      test/models/document_test.rb

+ 1
- 0
Gemfile Näytä tiedosto

@@ -1,5 +1,6 @@
source 'https://rubygems.org'

gem 'paperclip', '~> 5.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'


+ 12
- 0
Gemfile.lock Näytä tiedosto

@@ -42,6 +42,10 @@ GEM
bcrypt (3.1.11)
builder (3.2.2)
byebug (9.0.6)
climate_control (0.0.3)
activesupport (>= 3.0)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
coffee-rails (4.2.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.2.x)
@@ -75,12 +79,19 @@ GEM
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mimemagic (0.3.2)
mini_portile2 (2.1.0)
minitest (5.9.1)
multi_json (1.12.1)
nio4r (1.2.1)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
paperclip (5.0.0)
activemodel (>= 4.2.0)
activesupport (>= 4.2.0)
cocaine (~> 0.5.5)
mime-types
mimemagic (~> 0.3.0)
puma (3.6.2)
rack (2.0.1)
rack-test (0.6.3)
@@ -161,6 +172,7 @@ DEPENDENCIES
jbuilder (~> 2.5)
jquery-rails
listen (~> 3.0.5)
paperclip (~> 5.0.0)
puma (~> 3.0)
rails (~> 5.0.0, >= 5.0.0.1)
sass-rails (~> 5.0)


+ 3
- 0
app/assets/javascripts/documents.coffee Näytä tiedosto

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

+ 3
- 0
app/assets/stylesheets/documents.scss Näytä tiedosto

@@ -0,0 +1,3 @@
// Place all the styles related to the Documents controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

+ 74
- 0
app/controllers/documents_controller.rb Näytä tiedosto

@@ -0,0 +1,74 @@
class DocumentsController < ApplicationController
before_action :set_document, only: [:show, :edit, :update, :destroy]

# GET /documents
# GET /documents.json
def index
@documents = Document.all
end

# GET /documents/1
# GET /documents/1.json
def show
end

# GET /documents/new
def new
@document = Document.new
end

# GET /documents/1/edit
def edit
end

# POST /documents
# POST /documents.json
def create
@document = Document.new(document_params)

respond_to do |format|
if @document.save
format.html { redirect_to @document, notice: 'Document was successfully created.' }
format.json { render :show, status: :created, location: @document }
else
format.html { render :new }
format.json { render json: @document.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /documents/1
# PATCH/PUT /documents/1.json
def update
respond_to do |format|
if @document.update(document_params)
format.html { redirect_to @document, notice: 'Document was successfully updated.' }
format.json { render :show, status: :ok, location: @document }
else
format.html { render :edit }
format.json { render json: @document.errors, status: :unprocessable_entity }
end
end
end

# DELETE /documents/1
# DELETE /documents/1.json
def destroy
@document.destroy
respond_to do |format|
format.html { redirect_to documents_url, notice: 'Document was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_document
@document = Document.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def document_params
params.require(:document).permit(:name, :doc)
end
end

+ 1
- 1
app/controllers/sessions_controller.rb Näytä tiedosto

@@ -8,7 +8,7 @@ class SessionsController < ApplicationController
user = User.find_by(name: params[:name])
if user&.authenticate(params[:password])
session[:user_id] = user.id
redirect_to admin_url
redirect_to documents_url
else
redirect_to login_url
end


+ 2
- 0
app/helpers/documents_helper.rb Näytä tiedosto

@@ -0,0 +1,2 @@
module DocumentsHelper
end

+ 4
- 0
app/models/document.rb Näytä tiedosto

@@ -0,0 +1,4 @@
class Document < ApplicationRecord
has_attached_file :doc
validates_attachment_content_type :doc, content_type: 'application/pdf'
end

+ 2
- 0
app/views/documents/_document.json.jbuilder Näytä tiedosto

@@ -0,0 +1,2 @@
json.extract! document, :id, :name, :created_at, :updated_at
json.url document_url(document, format: :json)

+ 27
- 0
app/views/documents/_form.html.erb Näytä tiedosto

@@ -0,0 +1,27 @@
<%= form_for document, url: documents_path, html: { multipart: true } do |f| %>
<% if document.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(document.errors.count, "error") %> prohibited this document from being saved:</h2>

<ul>
<% document.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>

<div class="field">
<%= f.label :doc %>
<%= f.file_field :doc %>
</div>

<div class="actions">
<%= f.submit %>
</div>
<% end %>

+ 6
- 0
app/views/documents/edit.html.erb Näytä tiedosto

@@ -0,0 +1,6 @@
<h1>Editing Document</h1>

<%= render 'form', document: @document %>

<%= link_to 'Show', @document %> |
<%= link_to 'Back', documents_path %>

+ 27
- 0
app/views/documents/index.html.erb Näytä tiedosto

@@ -0,0 +1,27 @@
<p id="notice"><%= notice %></p>

<h1>Documents</h1>

<table>
<thead>
<tr>
<th>Name</th>
<th colspan="3"></th>
</tr>
</thead>

<tbody>
<% @documents.each do |document| %>
<tr>
<td><%= document.name %></td>
<td><%= link_to 'Show', document %></td>
<td><%= link_to 'Edit', edit_document_path(document) %></td>
<td><%= link_to 'Destroy', document, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Document', new_document_path %>

+ 1
- 0
app/views/documents/index.json.jbuilder Näytä tiedosto

@@ -0,0 +1 @@
json.array! @documents, partial: 'documents/document', as: :document

+ 5
- 0
app/views/documents/new.html.erb Näytä tiedosto

@@ -0,0 +1,5 @@
<h1>New Document</h1>

<%= render 'form', document: @document %>

<%= link_to 'Back', documents_path %>

+ 13
- 0
app/views/documents/show.html.erb Näytä tiedosto

@@ -0,0 +1,13 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Name:</strong>
<%= @document.name %>
</p>

<p>
<%= link_to @document.doc_file_name, @document.doc.url %>
</p>

<%= link_to 'Edit', edit_document_path(@document) %> |
<%= link_to 'Back', documents_path %>

+ 1
- 0
app/views/documents/show.json.jbuilder Näytä tiedosto

@@ -0,0 +1 @@
json.partial! "documents/document", document: @document

+ 10
- 1
app/views/layouts/application.html.erb Näytä tiedosto

@@ -9,6 +9,15 @@
</head>

<body>
<%= yield %>
<div id="columsn">
<div id="side">
<% if session[:user_id] %>
<%= button_to 'Logout', logout_path, method: :delete %>
<% end %>
</div>
<div id="main">
<%= yield %>
</div>
</div>
</body>
</html>

+ 2
- 2
config/routes.rb Näytä tiedosto

@@ -1,7 +1,7 @@
Rails.application.routes.draw do
root 'users#index', as: 'users_index'
resources :documents

get 'admin/index'
root 'users#index', as: 'users_index'

controller :sessions do
get 'login' => :new


+ 9
- 0
db/migrate/20161124130436_create_documents.rb Näytä tiedosto

@@ -0,0 +1,9 @@
class CreateDocuments < ActiveRecord::Migration[5.0]
def change
create_table :documents do |t|
t.string :name

t.timestamps
end
end
end

+ 11
- 0
db/migrate/20161124131141_add_attachment_doc_to_documents.rb Näytä tiedosto

@@ -0,0 +1,11 @@
class AddAttachmentDocToDocuments < ActiveRecord::Migration
def self.up
change_table :documents do |t|
t.attachment :doc
end
end

def self.down
remove_attachment :documents, :doc
end
end

+ 11
- 1
db/schema.rb Näytä tiedosto

@@ -10,7 +10,17 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20161124123704) do
ActiveRecord::Schema.define(version: 20161124131141) do

create_table "documents", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "doc_file_name"
t.string "doc_content_type"
t.integer "doc_file_size"
t.datetime "doc_updated_at"
end

create_table "users", force: :cascade do |t|
t.string "name"


+ 57
- 0
public/system/documents/docs/000/000/003/original/mymedicaldevicename.xml Näytä tiedosto

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<p1:MDIBContainer xmlns:p1="http://domain-model-uri/15/04" xmlns:p2="http://extension-point-uri/15/03" xmlns:m="http://message-model-uri/15/04" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" p1:MDIBVersion="1">
<p1:MDDescription>
<p1:MDS xsi:type="p1:HydraMDSDescriptor" Handle="my_med_device_handle">
<p1:Type>
<p1:CodeId>CODE_ID</p1:CodeId>
<p1:ConceptDescription>My device description text.</p1:ConceptDescription>
</p1:Type>
<p1:MetaData>
<p1:UDI>uuid-123</p1:UDI>
<p1:Manufacturer>MyManufacturer</p1:Manufacturer>
<p1:ModelName>MyModelname</p1:ModelName>
<p1:ModelNumber>MyModelnumber123</p1:ModelNumber>
<p1:SerialNumber>MySN123</p1:SerialNumber>
</p1:MetaData>
<p1:Context Handle="context"/>
<p1:SCO Handle="sco">
<p1:Operation xsi:type="p1:SetStringOperationDescriptor" Handle="my_set_method_name" OperationTarget="my_metric_handle">
<p1:Type>
<p1:CodeId>CODE_ID_SETM</p1:CodeId>
<p1:ConceptDescription>My set method.</p1:ConceptDescription>
</p1:Type>
</p1:Operation>
</p1:SCO>
<p1:VMD Handle="my_vmd_handle">
<p1:Type>
<p1:CodeId>CODE_ID_VMD</p1:CodeId>
<p1:ConceptDescription>My vmd descrtiption.</p1:ConceptDescription>
</p1:Type>
<p1:Channel Handle="my_channel_handle">
<p1:Type>
<p1:CodeId>CODE_ID_CHAN</p1:CodeId>
<p1:ConceptDescription>My channel description.</p1:ConceptDescription>
</p1:Type>
<p1:Metric xsi:type="p1:StringMetricDescriptor" Handle="my_metric_handle">
<p2:Extension>
<m:Retrievability>
<m:By>Get</m:By>
</m:Retrievability>
</p2:Extension>
<p1:Type>
<p1:CodeId>CODE_ID_METRIC</p1:CodeId>
<p1:ConceptDescription>My metric description.</p1:ConceptDescription>
</p1:Type>
<p1:Unit>
<p1:CodeId>MDC_DIM_DIMLESS</p1:CodeId>
<p1:ConceptDescription>No description for this unit code id.</p1:ConceptDescription>
</p1:Unit>
<p1:MetricCategory>Unspec</p1:MetricCategory>
<p1:Availability>Intr</p1:Availability>
</p1:Metric>
</p1:Channel>
</p1:VMD>
</p1:MDS>
</p1:MDDescription>
<p1:MDState/>
</p1:MDIBContainer>

BIN
public/system/documents/docs/000/000/004/original/02cc55df9b654cefa6c647ecc7a502fa.png Näytä tiedosto

Before After
Leveys: 728  |  Korkeus: 90  |  Koko: 53 KiB

BIN
public/system/documents/docs/000/000/005/original/MyMedicalDeviceName20161119012242.zip Näytä tiedosto


BIN
public/system/documents/docs/000/000/006/original/whenType.pdf Näytä tiedosto


+ 48
- 0
test/controllers/documents_controller_test.rb Näytä tiedosto

@@ -0,0 +1,48 @@
require 'test_helper'

class DocumentsControllerTest < ActionDispatch::IntegrationTest
setup do
@document = documents(:one)
end

test "should get index" do
get documents_url
assert_response :success
end

test "should get new" do
get new_document_url
assert_response :success
end

test "should create document" do
assert_difference('Document.count') do
post documents_url, params: { document: { name: @document.name } }
end

assert_redirected_to document_url(Document.last)
end

test "should show document" do
get document_url(@document)
assert_response :success
end

test "should get edit" do
get edit_document_url(@document)
assert_response :success
end

test "should update document" do
patch document_url(@document), params: { document: { name: @document.name } }
assert_redirected_to document_url(@document)
end

test "should destroy document" do
assert_difference('Document.count', -1) do
delete document_url(@document)
end

assert_redirected_to documents_url
end
end

+ 7
- 0
test/fixtures/documents.yml Näytä tiedosto

@@ -0,0 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
name: MyString

two:
name: MyString

+ 7
- 0
test/models/document_test.rb Näytä tiedosto

@@ -0,0 +1,7 @@
require 'test_helper'

class DocumentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

Ladataan…
Peruuta
Tallenna