diff --git a/Gemfile b/Gemfile index 9dd0452..dded4ed 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index ff0ff7b..e3e0110 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/assets/javascripts/documents.coffee b/app/assets/javascripts/documents.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/documents.coffee @@ -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/ diff --git a/app/assets/stylesheets/documents.scss b/app/assets/stylesheets/documents.scss new file mode 100644 index 0000000..ec6aac2 --- /dev/null +++ b/app/assets/stylesheets/documents.scss @@ -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/ diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb new file mode 100644 index 0000000..9314e16 --- /dev/null +++ b/app/controllers/documents_controller.rb @@ -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 diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 7383491..e941571 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -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 diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb new file mode 100644 index 0000000..242b4fc --- /dev/null +++ b/app/helpers/documents_helper.rb @@ -0,0 +1,2 @@ +module DocumentsHelper +end diff --git a/app/models/document.rb b/app/models/document.rb new file mode 100644 index 0000000..a39a400 --- /dev/null +++ b/app/models/document.rb @@ -0,0 +1,4 @@ +class Document < ApplicationRecord + has_attached_file :doc + validates_attachment_content_type :doc, content_type: 'application/pdf' +end diff --git a/app/views/documents/_document.json.jbuilder b/app/views/documents/_document.json.jbuilder new file mode 100644 index 0000000..2e9c923 --- /dev/null +++ b/app/views/documents/_document.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! document, :id, :name, :created_at, :updated_at +json.url document_url(document, format: :json) \ No newline at end of file diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb new file mode 100644 index 0000000..cacf85b --- /dev/null +++ b/app/views/documents/_form.html.erb @@ -0,0 +1,27 @@ +<%= form_for document, url: documents_path, html: { multipart: true } do |f| %> + <% if document.errors.any? %> +
+

<%= pluralize(document.errors.count, "error") %> prohibited this document from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :name %> + <%= f.text_field :name %> +
+ +
+ <%= f.label :doc %> + <%= f.file_field :doc %> +
+ +
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/documents/edit.html.erb b/app/views/documents/edit.html.erb new file mode 100644 index 0000000..4e7744e --- /dev/null +++ b/app/views/documents/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Document

+ +<%= render 'form', document: @document %> + +<%= link_to 'Show', @document %> | +<%= link_to 'Back', documents_path %> diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb new file mode 100644 index 0000000..8802042 --- /dev/null +++ b/app/views/documents/index.html.erb @@ -0,0 +1,27 @@ +

<%= notice %>

+ +

Documents

+ + + + + + + + + + + <% @documents.each do |document| %> + + + + + + + <% end %> + +
Name
<%= document.name %><%= link_to 'Show', document %><%= link_to 'Edit', edit_document_path(document) %><%= link_to 'Destroy', document, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Document', new_document_path %> diff --git a/app/views/documents/index.json.jbuilder b/app/views/documents/index.json.jbuilder new file mode 100644 index 0000000..da01985 --- /dev/null +++ b/app/views/documents/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @documents, partial: 'documents/document', as: :document \ No newline at end of file diff --git a/app/views/documents/new.html.erb b/app/views/documents/new.html.erb new file mode 100644 index 0000000..720a73e --- /dev/null +++ b/app/views/documents/new.html.erb @@ -0,0 +1,5 @@ +

New Document

+ +<%= render 'form', document: @document %> + +<%= link_to 'Back', documents_path %> diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb new file mode 100644 index 0000000..2dc5a74 --- /dev/null +++ b/app/views/documents/show.html.erb @@ -0,0 +1,13 @@ +

<%= notice %>

+ +

+ Name: + <%= @document.name %> +

+ +

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

+ +<%= link_to 'Edit', edit_document_path(@document) %> | +<%= link_to 'Back', documents_path %> diff --git a/app/views/documents/show.json.jbuilder b/app/views/documents/show.json.jbuilder new file mode 100644 index 0000000..87dd6eb --- /dev/null +++ b/app/views/documents/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "documents/document", document: @document \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 3738d56..7c5b603 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,6 +9,15 @@ - <%= yield %> +
+
+ <% if session[:user_id] %> + <%= button_to 'Logout', logout_path, method: :delete %> + <% end %> +
+
+ <%= yield %> +
+
diff --git a/config/routes.rb b/config/routes.rb index 0beec77..bdaa0df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20161124130436_create_documents.rb b/db/migrate/20161124130436_create_documents.rb new file mode 100644 index 0000000..702f46a --- /dev/null +++ b/db/migrate/20161124130436_create_documents.rb @@ -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 diff --git a/db/migrate/20161124131141_add_attachment_doc_to_documents.rb b/db/migrate/20161124131141_add_attachment_doc_to_documents.rb new file mode 100644 index 0000000..c6f24ce --- /dev/null +++ b/db/migrate/20161124131141_add_attachment_doc_to_documents.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 6d09b2f..189f3f3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" diff --git a/public/system/documents/docs/000/000/003/original/mymedicaldevicename.xml b/public/system/documents/docs/000/000/003/original/mymedicaldevicename.xml new file mode 100644 index 0000000..e632d76 --- /dev/null +++ b/public/system/documents/docs/000/000/003/original/mymedicaldevicename.xml @@ -0,0 +1,57 @@ + + + + + + CODE_ID + My device description text. + + + uuid-123 + MyManufacturer + MyModelname + MyModelnumber123 + MySN123 + + + + + + CODE_ID_SETM + My set method. + + + + + + CODE_ID_VMD + My vmd descrtiption. + + + + CODE_ID_CHAN + My channel description. + + + + + Get + + + + CODE_ID_METRIC + My metric description. + + + MDC_DIM_DIMLESS + No description for this unit code id. + + Unspec + Intr + + + + + + + diff --git a/public/system/documents/docs/000/000/004/original/02cc55df9b654cefa6c647ecc7a502fa.png b/public/system/documents/docs/000/000/004/original/02cc55df9b654cefa6c647ecc7a502fa.png new file mode 100644 index 0000000..9636b10 Binary files /dev/null and b/public/system/documents/docs/000/000/004/original/02cc55df9b654cefa6c647ecc7a502fa.png differ diff --git a/public/system/documents/docs/000/000/005/original/MyMedicalDeviceName20161119012242.zip b/public/system/documents/docs/000/000/005/original/MyMedicalDeviceName20161119012242.zip new file mode 100644 index 0000000..1e608cb Binary files /dev/null and b/public/system/documents/docs/000/000/005/original/MyMedicalDeviceName20161119012242.zip differ diff --git a/public/system/documents/docs/000/000/006/original/whenType.pdf b/public/system/documents/docs/000/000/006/original/whenType.pdf new file mode 100644 index 0000000..b0b011a Binary files /dev/null and b/public/system/documents/docs/000/000/006/original/whenType.pdf differ diff --git a/test/controllers/documents_controller_test.rb b/test/controllers/documents_controller_test.rb new file mode 100644 index 0000000..d053b12 --- /dev/null +++ b/test/controllers/documents_controller_test.rb @@ -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 diff --git a/test/fixtures/documents.yml b/test/fixtures/documents.yml new file mode 100644 index 0000000..56066c6 --- /dev/null +++ b/test/fixtures/documents.yml @@ -0,0 +1,7 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + +two: + name: MyString diff --git a/test/models/document_test.rb b/test/models/document_test.rb new file mode 100644 index 0000000..fd1570f --- /dev/null +++ b/test/models/document_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class DocumentTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end