Skip to content

Commit

Permalink
Merge pull request #10 from mlibrary/identifiers
Browse files Browse the repository at this point in the history
Identifiers
  • Loading branch information
gkostin1966 committed Jun 4, 2019
2 parents 512b0c5 + 85f4a61 commit 474d796
Show file tree
Hide file tree
Showing 68 changed files with 1,808 additions and 45 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ AllCops:
Exclude:
- 'db/**/*'

Layout/IndentationConsistency:
EnforcedStyle: rails

Metrics/BlockLength:
Exclude:
- 'spec/**/*'
Expand All @@ -21,5 +24,11 @@ Metrics/LineLength:
Style/Documentation:
Enabled: false

Style/EmptyMethod:
Enabled: false

Style/RegexpLiteral:
Enabled: false

Style/StringLiterals:
Enabled: false
13 changes: 13 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,22 @@ gem 'marc', '~>1.0'
# Use MySQL as the database for Active Record
gem 'mysql2', '~> 0.5'

# Pagination
# https://github.com/kaminari/kaminari
gem 'kaminari', '~> 1.1'

# Bootstrap
# https://github.com/twbs/bootstrap-rubygem
gem 'bootstrap', '~> 4.3'

# Bootstrap JavaScript depends on jQuery. If you're using Rails 5.1+,
# add the jquery-rails gem to your Gemfile:
gem 'jquery-rails', '~> 4.3'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'factory_bot_rails', '~> 5.0'
gem 'rspec-rails', '~> 3.8'
gem 'rubocop-performance', '~> 1.2'
gem 'rubocop-rspec', '~> 1.32'
Expand Down
41 changes: 41 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ GEM
public_suffix (>= 2.0.2, < 4.0)
arel (9.0.0)
ast (2.4.0)
autoprefixer-rails (9.5.1.1)
execjs
bindex (0.7.0)
bootsnap (1.4.4)
msgpack (~> 1.0)
bootstrap (4.3.1)
autoprefixer-rails (>= 9.1.0)
popper_js (>= 1.14.3, < 2)
sassc-rails (>= 2.0.0)
boxr (1.4.0)
addressable (~> 2.3)
hashie (~> 3.5)
Expand Down Expand Up @@ -90,6 +96,11 @@ GEM
ettin (1.2.1)
deep_merge
execjs (2.7.0)
factory_bot (5.0.2)
activesupport (>= 4.2.0)
factory_bot_rails (5.0.2)
factory_bot (~> 5.0.2)
railties (>= 4.2.0)
ffi (1.10.0)
fugit (1.2.1)
et-orbi (~> 1.1, >= 1.1.8)
Expand All @@ -103,8 +114,24 @@ GEM
jaro_winkler (1.5.2)
jbuilder (2.9.0)
activesupport (>= 4.2.0)
jquery-rails (4.3.3)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.2.0)
jwt (1.5.6)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
kaminari-activerecord (= 1.1.1)
kaminari-core (= 1.1.1)
kaminari-actionview (1.1.1)
actionview
kaminari-core (= 1.1.1)
kaminari-activerecord (1.1.1)
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
Expand Down Expand Up @@ -132,6 +159,7 @@ GEM
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
popper_js (1.14.5)
public_suffix (3.0.3)
puma (3.12.1)
raabro (1.1.6)
Expand Down Expand Up @@ -212,6 +240,15 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sassc (2.0.1)
ffi (~> 1.9)
rake
sassc-rails (2.1.1)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
scrub_rb (1.0.1)
selenium-webdriver (3.142.2)
childprocess (>= 0.5, < 2.0)
Expand Down Expand Up @@ -271,13 +308,17 @@ PLATFORMS

DEPENDENCIES
bootsnap (>= 1.1.0)
bootstrap (~> 4.3)
boxr (~> 1.4)
byebug
capybara (>= 2.15)
coffee-rails (~> 4.2)
coveralls (~> 0.8)
ettin (~> 1.2)
factory_bot_rails (~> 5.0)
jbuilder (~> 2.5)
jquery-rails (~> 4.3)
kaminari (~> 1.1)
listen (>= 3.0.5, < 3.2)
marc (~> 1.0)
mysql2 (~> 0.5)
Expand Down
13 changes: 13 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@
//= require activestorage
//= require turbolinks
//= require_tree .

// Bootstrap tooltips and popovers depend on popper.js for positioning.
// The bootstrap gem already depends on the popper_js gem.
// Add Bootstrap dependencies and Bootstrap to your application.js:
//= require jquery3
//= require popper
//= require bootstrap-sprockets

// While bootstrap-sprockets provides individual Bootstrap components for ease of debugging,
// you may alternatively require the concatenated bootstrap for faster compilation:
// = r e q u i r e jquery3
// = r e q u i r e popper
// = r e q u i r e bootstrap
15 changes: 0 additions & 15 deletions app/assets/stylesheets/application.css

This file was deleted.

41 changes: 41 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
* Then, remove all the *= require and *= require_tree statements from the Sass file. Instead,
* use @import to import Sass files.
*
* Do not use *= require in Sass or your other stylesheets will not be able to access the
* Bootstrap mixins and variables.
*/

// Custom bootstrap variables must be set or imported *before* bootstrap.
@import "bootstrap";

/*
* Configuration
* Sass: Autoprefixer
* Bootstrap requires the use of Autoprefixer.
* Autoprefixer adds vendor prefixes to CSS rules using values from Can I Use.
*
* If you are using bootstrap with Rails, autoprefixer is set up for you automatically.
* Otherwise, please consult the Autoprefixer documentation.
*
* Sass: Individual components
* By default all of Bootstrap is imported.
*
* You can also import components explicitly. To start with a full list of modules
* copy _bootstrap.scss file into your assets as _bootstrap-custom.scss. Then
* comment out components you do not want from _bootstrap-custom. In the application Sass file,
* replace @import 'bootstrap' with:
*
* @import 'bootstrap-custom';
*/
112 changes: 112 additions & 0 deletions app/controllers/identifiers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# frozen_string_literal: true

require 'open-uri'

class IdentifiersController < ApplicationController
before_action :set_identifier, only: %i[show edit update destroy]

def index
@identifiers = Identifier.filter(filtering_params(params)).order(name: :asc).page(params[:page])
end

def show
@aliases = @identifier.aliases
end

def new
@identifier = Identifier.new
@aliases = Identifier.all
@alias_id = 0
end

def edit
@aliases = Identifier.all
@alias_id = @identifier.id
end

def create # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
create_identifier_params = identifier_params
create_identifier_params[:uuid] = if create_identifier_params[:uuid].present?
Identifier.find(create_identifier_params[:uuid]).uuid
else
Uuid.generator
end
@identifier = Identifier.new(create_identifier_params)
respond_to do |format|
if @identifier.save
format.html { redirect_to identifier_path(@identifier), notice: 'Identifier was successfully created.' }
format.json { render :show, status: :created, location: @identifier }
else
format.html do
@aliases = Identifier.all
if @identifier.uuid.identifiers.count.positive?
@alias_id = identifier_params[:uuid]
else
@identifier.uuid.destroy
@identifier.uuid = nil
@aliases_id = 0
end
render :new
end
format.json { render json: @identifier.errors, status: :unprocessable_entity }
end
end
end

def update # rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/AbcSize
update_identifier_params = identifier_params
update_identifier_params[:uuid] = if update_identifier_params[:uuid].present?
Identifier.find(update_identifier_params[:uuid]).uuid
else
Uuid.generator
end
unless @identifier.uuid == update_identifier_params[:uuid]
@identifier.uuid.identifiers.delete(@identifier)
@identifier.uuid = nil
end
respond_to do |format|
if @identifier.update(update_identifier_params)
format.html { redirect_to identifier_path(@identifier), notice: 'Identifier was successfully updated.' }
format.json { render :show, status: :ok, location: @identifier }
else
format.html do
@aliases = Identifier.all
if @identifier.uuid.identifiers.count.positive?
@alias_id = identifier_params[:uuid]
else
@identifier.uuid.destroy
@identifier.uuid = nil
@aliases_id = 0
end
render :edit
end
format.json { render json: @identifier.errors, status: :unprocessable_entity }
end
end
end

def destroy # rubocop:disable Metrics/AbcSize
@identifier.uuid.identifiers.delete(@identifier)
@identifier.uuid.destroy unless @identifier.uuid.identifiers.count.positive?
@identifier.uuid = nil
@identifier.destroy
respond_to do |format|
format.html { redirect_to identifiers_url, notice: 'Identifier was successfully destroyed.' }
format.json { head :no_content }
end
end

private

def set_identifier
@identifier = Identifier.find(params[:id])
end

def identifier_params
params.require(:identifier).permit(:name, :uuid)
end

def filtering_params(params)
params.slice(:name_like)
end
end
Loading

0 comments on commit 474d796

Please sign in to comment.