Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: data versioning #2068

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ gem 'haml-rails'
gem 'hashie-forbidden_attributes'
gem 'httparty'

gem 'icalendar'
gem 'image_processing', '~> 1.8'
gem 'inchi-gem', '1.06.1', git: 'https://github.com/ComPlat/inchi-gem.git', branch: 'main'

Expand All @@ -60,6 +61,7 @@ gem 'kaminari-grape'
gem 'ketcherails', git: 'https://github.com/complat/ketcher-rails.git', ref: 'd4ae864a0e2d9e853eac8e4fc4ce7e3ab8174f80'

gem 'labimotion', '1.4.0.2'
gem 'logidze'

gem 'mimemagic', '0.3.10'
gem 'mime-types'
Expand Down Expand Up @@ -124,7 +126,6 @@ gem 'whenever', require: false

gem 'yaml_db'

gem 'icalendar'

group :development do
gem 'better_errors' # allows to debug exception on backend from browser
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.0)
logidze (1.3.0)
activerecord (>= 6.0)
railties (>= 6.0)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -845,7 +848,7 @@ GEM
rails (>= 3.0)
rake (>= 0.8.7)
yard (0.9.36)
zeitwerk (2.7.0)
zeitwerk (2.6.18)

PLATFORMS
x86_64-linux
Expand Down Expand Up @@ -916,6 +919,7 @@ DEPENDENCIES
labimotion (= 1.4.0.2)
launchy
listen
logidze
memory_profiler
meta_request
mime-types
Expand Down
3 changes: 3 additions & 0 deletions app/api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require 'grape-swagger'

class API < Grape::API
include LogidzeModule

format :json
prefix :api
version 'v1'
Expand Down Expand Up @@ -208,6 +210,7 @@ def to_json_camel_case(val)
mount Chemotion::AdminDeviceAPI
mount Chemotion::AdminDeviceMetadataAPI
mount Chemotion::ChemicalAPI
mount Chemotion::VersionAPI

if Rails.env.development?
add_swagger_documentation(info: {
Expand Down
118 changes: 118 additions & 0 deletions app/api/chemotion/version_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# frozen_string_literal: true

require 'open-uri'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing frozen string literal comment.


module Chemotion
class VersionAPI < Grape::API
include Grape::Kaminari
helpers ParamsHelpers

namespace :versions do
resource :samples do
desc 'Return versions of the given sample'

params do
requires :id, type: Integer, desc: 'Sample id'
end

paginate per_page: 10, offset: 0, max_per_page: 100

route_param :id do
get do
sample = Sample.with_log_data.find(params[:id])
versions = Versioning::Fetcher.call(sample)

{ versions: paginate(Kaminari.paginate_array(versions)) }
end
end
end

resource :reactions do
desc 'Return versions of the given reaction'

params do
requires :id, type: Integer, desc: 'Reaction id'
end

paginate per_page: 10, offset: 0, max_per_page: 100

route_param :id do
get do
reaction = Reaction.with_log_data.find(params[:id])
versions = Versioning::Fetcher.call(reaction)

{ versions: paginate(Kaminari.paginate_array(versions)) }
end
end
end

resource :research_plans do
desc 'Return versions of the given research plan'

params do
requires :id, type: Integer, desc: 'Research plan id'
end

paginate per_page: 10, offset: 0, max_per_page: 100

route_param :id do
get do
research_plan = ResearchPlan.with_log_data.find(params[:id])
versions = Versioning::Fetcher.call(research_plan)

{ versions: paginate(Kaminari.paginate_array(versions)) }
end
end
end

resource :screens do
desc 'Return versions of the given screen'

params do
requires :id, type: Integer, desc: 'Screen id'
end

paginate per_page: 10, offset: 0, max_per_page: 100

route_param :id do
get do
screen = Screen.with_log_data.find(params[:id])
versions = Versioning::Fetcher.call(screen)

{ versions: paginate(Kaminari.paginate_array(versions)) }
end
end
end

resource :wellplates do
desc 'Return versions of the given wellplate'

params do
requires :id, type: Integer, desc: 'Wellplate id'
end

paginate per_page: 10, offset: 0, max_per_page: 100

route_param :id do
get do
wellplate = Wellplate.with_log_data.find(params[:id])
versions = Versioning::Fetcher.call(wellplate)
{ versions: paginate(Kaminari.paginate_array(versions)) }
end
end
end

resource :revert do
desc 'Revert selected changes'

params do
requires :changes, type: JSON, desc: 'Changes hash'
end

post do
Versioning::Reverter.call(params[:changes])
end
end
end
end
end
21 changes: 21 additions & 0 deletions app/api/modules/logidze_module.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

# A helper to help logidize track current_user
module LogidzeModule
extend ActiveSupport::Concern

included do
before do
if current_user.present? && request.request_method.in?(%w[PATCH POST PUT DELETE])
@logidze_meta_set ||= begin
Logidze.with_responsible!(current_user.id)
true
end
end
end

after do
Logidze.clear_responsible! if @logidze_meta_set.present?
end
end
end
3 changes: 3 additions & 0 deletions app/assets/stylesheets/components/svg_with_popver.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.image-with-full-width {
width: 100%;
}
126 changes: 126 additions & 0 deletions app/assets/stylesheets/history.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
.history-legend {
display: flex;
justify-content: flex-end;
list-style: none;
padding: 0;
margin: 2px 2px 10px 0;

&__item {
font-size: 10px;
padding-left: .5em;

&::before {
content: "\f0c8";
font-family: FontAwesome;
display: inline-block;
padding: 0 0.2em;
}

&--old {
&::before {
color: #f2dede;
}
}

&--new {
&::before {
color: #dff0d8;
}
}

&--current {
&::before {
color: #f5f5f5;
}
}
}
}

.history-modal .modal-dialog {
top: 0;
transform: translate(-50%, 0) !important;
}

.history-alert {
margin-bottom: 0;
margin-top: 20px;
}

.history-checkbox-label {
margin-bottom: 0;
display: flex;
gap: 5px;
cursor: pointer;

input {
margin-top: 0 !important;
}
}

.history-table {
&__caret {
transition: transform .1s ease-out;
}

&__row {
cursor: pointer;

&.active {
.history-table__caret {
transform: rotate(90deg);
}
}
}

&-breadcrumb {
font-size: 13px;
padding: 8px 15px;
margin: 0;
list-style: none;
background-color: #f5f5f5;
border-radius: 4px;

&:not(:first-child) {
margin-top: 10px;
}

&__element {
display: inline-block;
}

&__element + &__element:before {
padding: 0 5px;
color: #ccc;
content: "/ ";
}
}

.bg-current {
background-color: #f5f5f5;
}

.row-change {
display: flex;
flex-wrap: wrap;
font-size: 10px;
margin: 10px 0 0;
word-break: break-all;

& > [class*="col-"] {
padding: 6px;
}

.ql-container {
font-size: 10px;
}

.ql-editor {
padding: 0;
}

.ql-tooltip.ql-hidden {
height: 0;
padding-top: 10px;
}
}
}
3 changes: 2 additions & 1 deletion app/models/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
# index_attachments_on_identifier (identifier) UNIQUE
#

class Attachment < ApplicationRecord
class Attachment < ApplicationRecord # rubocop:disable Metrics/ClassLength
has_logidze
include AttachmentJcampAasm
include AttachmentJcampProcess
include Labimotion::AttachmentConverter
Expand Down
2 changes: 2 additions & 0 deletions app/models/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#

class Container < ApplicationRecord
has_logidze
acts_as_paranoid
include ElementCodes
include Labimotion::Datasetable

Expand Down
2 changes: 2 additions & 0 deletions app/models/container_hierarchy.rb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this stub?

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ContainerHierarchy < ApplicationRecord

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/FrozenStringLiteralComment: Missing frozen string literal comment.

end
2 changes: 2 additions & 0 deletions app/models/elemental_composition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#

class ElementalComposition < ApplicationRecord
has_logidze

belongs_to :sample

TYPES = {
Expand Down
1 change: 1 addition & 0 deletions app/models/reaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

# rubocop:disable Metrics/ClassLength
class Reaction < ApplicationRecord
has_logidze
acts_as_paranoid
include ElementUIStateScopes
include PgSearch::Model
Expand Down
2 changes: 2 additions & 0 deletions app/models/reactions_product_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# created_at :datetime default(LOCALTIMESTAMP), not null
# updated_at :datetime default(LOCALTIMESTAMP), not null
#
# Indexes
#
Expand Down
2 changes: 2 additions & 0 deletions app/models/reactions_purification_solvent_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# created_at :datetime default(LOCALTIMESTAMP), not null
# updated_at :datetime default(LOCALTIMESTAMP), not null
#
# Indexes
#
Expand Down
Loading
Loading