Skip to content

Commit

Permalink
Merge 2b73e8e into 9fd5de8
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergeykot committed Nov 10, 2016
2 parents 9fd5de8 + 2b73e8e commit 4b7f78a
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/assets/javascripts/components/UserAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export default class UserAuth extends Component {
{templatesLink}
<MenuItem eventKey="2" href="users/edit" >Change Password</MenuItem>
<MenuItem eventKey="3" href="pages/profiles" >Change profiles</MenuItem>
<MenuItem eventKey="4" href="pages/groups" >My groups</MenuItem>
<MenuItem eventKey="4" href="pages/user" >Change counters and prefixes</MenuItem>
<MenuItem eventKey="5" href="pages/groups" >My groups</MenuItem>
</NavDropdown>
<NavItem onClick={() => this.logout()} style={style} className='' title='Log out'> <Glyphicon glyph="log-out" /> </NavItem>
</Nav>
Expand Down
4 changes: 3 additions & 1 deletion app/assets/javascripts/components/models/Reaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export default class Reaction extends Element {
if(!currentUser) {
return 'New Reaction';
} else {
return `${currentUser.initials}-R${currentUser.reactions_count + 1}`;
let number = currentUser.reactions_count + 1;
let prefix = currentUser.reaction_name_prefix;
return `${currentUser.initials}-${prefix}${number}`;
}
}

Expand Down
Empty file removed app/assets/javascripts/pages.js
Empty file.
12 changes: 12 additions & 0 deletions app/assets/javascripts/pages.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

showExampleLabel = function() {
var prefix = $('input#reaction-name-prefix').val();
var counter = parseInt($('input#reactions-count').val());
var user_name_abbr = $('input#name_abbreviation').val();
var reaction_label = user_name_abbr + '-' + prefix + (counter + 1)
$('p#reaction-label-example').text(reaction_label);
}

$(function() {
showExampleLabel();
});
16 changes: 16 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ class PagesController < ApplicationController
def welcome
end

def user
end

def update_user
@user = current_user
@user.counters['reactions'] = params[:reactions_count].to_i
@user.reaction_name_prefix = params[:reaction_name_prefix]
if @user.save
flash["success"] = "User settings is successfully saved!"
redirect_to root_path
else
flash.now["danger"] = "Not saved! Please check input fields."
render "user"
end
end

def profiles
current_user.has_profile
@profile = current_user.profile
Expand Down
3 changes: 2 additions & 1 deletion app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class UserSerializer < ActiveModel::Serializer
attributes :id, :name, :initials, :samples_count, :reactions_count, :type
attributes :id, :name, :initials, :samples_count, :reactions_count, :type,
:reaction_name_prefix

def samples_count
object.counters['samples'].to_i
Expand Down
38 changes: 38 additions & 0 deletions app/views/pages/user.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.container
%h2
Change your user settings

%br/
%br/
.jumbotron
.row
= form_for current_user, url: pages_update_user_path do |f|
.field
= text_field_tag :reaction_name_prefix,
current_user.reaction_name_prefix,
maxlength: 3,
id: 'reaction-name-prefix',
oninput: 'showExampleLabel();'
= f.label :reaction_name_prefix
.field
= number_field_tag :reactions_count,
current_user.counters['reactions'],
min: 0,
id: 'reactions-count',
oninput: 'showExampleLabel();'
= f.label :reactions_counter
= hidden_field_tag :name_abbreviation, current_user.name_abbreviation

%br/

%h3
Your next reaction label:
%p{id: 'reaction-label-example'}

.actions
= f.submit "Update user settings", class: "btn btn-primary"

%br/
%br/

= link_to "Back", root_path
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
get 'pages/settings', to: 'pages#settings'
get 'pages/profiles', to: 'pages#profiles'
patch 'pages/update_profiles', to: 'pages#update_profiles'
get 'pages/user', to: 'pages#user'
patch 'pages/update_user', to: 'pages#update_user'
get 'pages/groups', to: 'pages#groups'
end

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20161109141353_add_reaction_name_prefix_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddReactionNamePrefixToUser < ActiveRecord::Migration
def change
add_column :users, :reaction_name_prefix, :string, default: 'R', limit: 3
end
end
42 changes: 39 additions & 3 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20161024083139) do
ActiveRecord::Schema.define(version: 20161109141353) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "pg_trgm"
enable_extension "hstore"
enable_extension "pg_trgm"

create_table "authentication_keys", force: :cascade do |t|
t.string "token", null: false
Expand Down Expand Up @@ -218,6 +218,19 @@
add_index "molecules", ["deleted_at"], name: "index_molecules_on_deleted_at", using: :btree
add_index "molecules", ["inchikey", "is_partial"], name: "index_molecules_on_inchikey_and_is_partial", unique: true, using: :btree

create_table "nmr_sim_nmr_simulations", force: :cascade do |t|
t.integer "molecule_id"
t.text "path_1h"
t.text "path_13c"
t.text "source"
t.datetime "deleted_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "nmr_sim_nmr_simulations", ["deleted_at"], name: "index_nmr_sim_nmr_simulations_on_deleted_at", using: :btree
add_index "nmr_sim_nmr_simulations", ["molecule_id", "source"], name: "index_nmr_sim_nmr_simulations_on_molecule_id_and_source", unique: true, using: :btree

create_table "pg_search_documents", force: :cascade do |t|
t.text "content"
t.integer "searchable_id"
Expand Down Expand Up @@ -358,6 +371,28 @@
add_index "samples", ["molecule_id"], name: "index_samples_on_sample_id", using: :btree
add_index "samples", ["user_id"], name: "index_samples_on_user_id", using: :btree

create_table "scifinding_credentials", force: :cascade do |t|
t.string "username"
t.string "encrypted_password"
t.string "encrypted_current_token"
t.string "encrypted_refreshed_token"
t.datetime "token_expires_at"
t.datetime "token_requested_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.string "encrypted_password_iv"
t.string "encrypted_current_token_iv"
t.string "encrypted_refreshed_token_iv"
end

create_table "scifinding_tags", force: :cascade do |t|
t.integer "molecule_id"
t.integer "count"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "screens", force: :cascade do |t|
t.string "description"
t.string "name"
Expand Down Expand Up @@ -417,8 +452,9 @@
t.datetime "deleted_at"
t.hstore "counters", default: {"samples"=>"0", "reactions"=>"0", "wellplates"=>"0"}, null: false
t.string "name_abbreviation", limit: 5
t.string "type", default: "Person"
t.boolean "is_templates_moderator", default: false, null: false
t.string "type", default: "Person"
t.string "reaction_name_prefix", limit: 3, default: "R"
end

add_index "users", ["deleted_at"], name: "index_users_on_deleted_at", using: :btree
Expand Down
2 changes: 1 addition & 1 deletion spec/api/user_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe Chemotion::UserAPI do
let(:json_options) {
{
only: [:id,:is_templates_moderator,:type],
only: [:id,:is_templates_moderator,:type, :reaction_name_prefix],
methods: [:name, :initials]
}
}
Expand Down

0 comments on commit 4b7f78a

Please sign in to comment.