| @@ -1,5 +1,6 @@ | |||||
| source 'https://rubygems.org' | source 'https://rubygems.org' | ||||
| gem 'paperclip', '~> 5.0.0' | |||||
| # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' | ||||
| gem 'rails', '~> 5.0.0', '>= 5.0.0.1' | gem 'rails', '~> 5.0.0', '>= 5.0.0.1' | ||||
| @@ -42,6 +42,10 @@ GEM | |||||
| bcrypt (3.1.11) | bcrypt (3.1.11) | ||||
| builder (3.2.2) | builder (3.2.2) | ||||
| byebug (9.0.6) | 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-rails (4.2.1) | ||||
| coffee-script (>= 2.2.0) | coffee-script (>= 2.2.0) | ||||
| railties (>= 4.0.0, < 5.2.x) | railties (>= 4.0.0, < 5.2.x) | ||||
| @@ -75,12 +79,19 @@ GEM | |||||
| mime-types (3.1) | mime-types (3.1) | ||||
| mime-types-data (~> 3.2015) | mime-types-data (~> 3.2015) | ||||
| mime-types-data (3.2016.0521) | mime-types-data (3.2016.0521) | ||||
| mimemagic (0.3.2) | |||||
| mini_portile2 (2.1.0) | mini_portile2 (2.1.0) | ||||
| minitest (5.9.1) | minitest (5.9.1) | ||||
| multi_json (1.12.1) | multi_json (1.12.1) | ||||
| nio4r (1.2.1) | nio4r (1.2.1) | ||||
| nokogiri (1.6.8.1) | nokogiri (1.6.8.1) | ||||
| mini_portile2 (~> 2.1.0) | 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) | puma (3.6.2) | ||||
| rack (2.0.1) | rack (2.0.1) | ||||
| rack-test (0.6.3) | rack-test (0.6.3) | ||||
| @@ -161,6 +172,7 @@ DEPENDENCIES | |||||
| jbuilder (~> 2.5) | jbuilder (~> 2.5) | ||||
| jquery-rails | jquery-rails | ||||
| listen (~> 3.0.5) | listen (~> 3.0.5) | ||||
| paperclip (~> 5.0.0) | |||||
| puma (~> 3.0) | puma (~> 3.0) | ||||
| rails (~> 5.0.0, >= 5.0.0.1) | rails (~> 5.0.0, >= 5.0.0.1) | ||||
| sass-rails (~> 5.0) | sass-rails (~> 5.0) | ||||
| @@ -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/ | |||||
| @@ -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/ | |||||
| @@ -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 | |||||
| @@ -8,7 +8,7 @@ class SessionsController < ApplicationController | |||||
| user = User.find_by(name: params[:name]) | user = User.find_by(name: params[:name]) | ||||
| if user&.authenticate(params[:password]) | if user&.authenticate(params[:password]) | ||||
| session[:user_id] = user.id | session[:user_id] = user.id | ||||
| redirect_to admin_url | |||||
| redirect_to documents_url | |||||
| else | else | ||||
| redirect_to login_url | redirect_to login_url | ||||
| end | end | ||||
| @@ -0,0 +1,2 @@ | |||||
| module DocumentsHelper | |||||
| end | |||||
| @@ -0,0 +1,4 @@ | |||||
| class Document < ApplicationRecord | |||||
| has_attached_file :doc | |||||
| validates_attachment_content_type :doc, content_type: 'application/pdf' | |||||
| end | |||||
| @@ -0,0 +1,2 @@ | |||||
| json.extract! document, :id, :name, :created_at, :updated_at | |||||
| json.url document_url(document, format: :json) | |||||
| @@ -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 %> | |||||
| @@ -0,0 +1,6 @@ | |||||
| <h1>Editing Document</h1> | |||||
| <%= render 'form', document: @document %> | |||||
| <%= link_to 'Show', @document %> | | |||||
| <%= link_to 'Back', documents_path %> | |||||
| @@ -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 %> | |||||
| @@ -0,0 +1 @@ | |||||
| json.array! @documents, partial: 'documents/document', as: :document | |||||
| @@ -0,0 +1,5 @@ | |||||
| <h1>New Document</h1> | |||||
| <%= render 'form', document: @document %> | |||||
| <%= link_to 'Back', documents_path %> | |||||
| @@ -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 %> | |||||
| @@ -0,0 +1 @@ | |||||
| json.partial! "documents/document", document: @document | |||||
| @@ -9,6 +9,15 @@ | |||||
| </head> | </head> | ||||
| <body> | <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> | </body> | ||||
| </html> | </html> | ||||
| @@ -1,7 +1,7 @@ | |||||
| Rails.application.routes.draw do | 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 | controller :sessions do | ||||
| get 'login' => :new | get 'login' => :new | ||||
| @@ -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 | |||||
| @@ -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 | |||||
| @@ -10,7 +10,17 @@ | |||||
| # | # | ||||
| # It's strongly recommended that you check this file into your version control system. | # 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| | create_table "users", force: :cascade do |t| | ||||
| t.string "name" | t.string "name" | ||||
| @@ -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> | |||||
| @@ -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 | |||||
| @@ -0,0 +1,7 @@ | |||||
| # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | |||||
| one: | |||||
| name: MyString | |||||
| two: | |||||
| name: MyString | |||||
| @@ -0,0 +1,7 @@ | |||||
| require 'test_helper' | |||||
| class DocumentTest < ActiveSupport::TestCase | |||||
| # test "the truth" do | |||||
| # assert true | |||||
| # end | |||||
| end | |||||