Merge pull request #222 from biosistemika/modular-tasks

Merge global team switch into master
This commit is contained in:
Luka Murn 2016-10-18 11:39:09 +02:00 committed by GitHub
commit 640a575a3a
35 changed files with 273 additions and 139 deletions

View file

@ -80,8 +80,23 @@
}
function initGlobalSwitchForm() {
var teamSwitch = $('#team-switch');
teamSwitch
.find('.dropdown-menu a')
.on('click', function(){
$('#user_current_organization_id')
.val($(this).attr('data-id'));
teamSwitch
.find('form')
.submit();
});
}
// init
loadDropdownNotifications();
loadUnseenNotificationsNumber();
toggleNotificationBellPosition();
initGlobalSwitchForm();
})();

View file

@ -554,6 +554,35 @@ a[data-toggle="tooltip"] {
}
}
// Global team switch
#team-switch {
word-wrap: break-word;
i {
margin-right: 5px;
}
li {
display: block;
text-align: left;
word-wrap: break-word;
&:hover {
background-color: $color-concrete;
}
a {
color: $color-emperor;
display: block;
line-height: 1.6em;
padding: 3px 20px;
text-align: left;
text-decoration: none;
word-wrap: break-word;
}
}
}
/** Settings */
.nav-settings {
margin-top: 15px;

View file

@ -6,9 +6,10 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :authenticate_user!
helper_method :current_organization
before_action :generate_intro_tutorial, if: :is_current_page_root?
around_action :set_time_zone, if: :current_user
layout "main"
layout 'main'
def forbidden
render_403
@ -19,7 +20,12 @@ class ApplicationController < ActionController::Base
end
def is_current_page_root?
controller_name == "projects" && action_name == "index"
controller_name == 'projects' && action_name == 'index'
end
# Sets current organization for all controllers
def current_organization
Organization.find_by_id(current_user.current_organization_id)
end
protected

View file

@ -1,5 +1,7 @@
class ExperimentsController < ApplicationController
include PermissionHelper
include OrganizationsHelper
before_action :set_experiment,
except: [:new, :create]
before_action :set_project,
@ -55,6 +57,7 @@ class ExperimentsController < ApplicationController
def canvas
@project = @experiment.project
current_organization_switch(@project.organization)
end
def edit

View file

@ -1,5 +1,6 @@
class MyModulesController < ApplicationController
include SampleActions
include OrganizationsHelper
before_action :load_vars, only: [
:show, :edit, :update, :destroy,
@ -232,10 +233,14 @@ class MyModulesController < ApplicationController
def protocols
@protocol = @my_module.protocol
current_organization_switch(@protocol.organization)
end
def results
current_organization_switch(@my_module
.experiment
.project
.organization)
end
def samples
@ -245,6 +250,10 @@ class MyModulesController < ApplicationController
def archive
@archived_results = @my_module.archived_results
current_organization_switch(@my_module
.experiment
.project
.organization)
end
# Submit actions

View file

@ -1,6 +1,7 @@
class ProjectsController < ApplicationController
include SampleActions
include RenamingUtil
include OrganizationsHelper
before_action :load_vars, only: [:show, :edit, :update,
:notifications, :reports,
@ -23,10 +24,16 @@ class ProjectsController < ApplicationController
DELETE_SAMPLES = I18n.t("samples.delete_samples")
def index
@current_organization_id = params[:organization].to_i
if params[:organization]
current_organization_switch(Organization
.find_by_id(params[:organization]))
end
@current_organization_id = current_organization.id
@current_sort = params[:sort].to_s
@projects_by_orgs = current_user.projects_by_orgs(
@current_organization_id, @current_sort, @filter_by_archived)
@projects_by_orgs = current_user.projects_by_orgs(@current_organization_id,
@current_sort,
@filter_by_archived)
@organizations = current_user.organizations
# New project for create new project modal
@ -40,14 +47,14 @@ class ProjectsController < ApplicationController
def new
@project = Project.new
@organizations = current_user.organizations
end
def create
@project = Project.new(project_params)
@project.created_by = current_user
@project.created_by = current_user
@project.last_modified_by = current_user
if @project.save
if current_organization.id == project_params[:organization_id].to_i &&
@project.save
# Create user-project association
up = UserProject.new(
role: :owner,
@ -237,6 +244,7 @@ class ProjectsController < ApplicationController
def show
# This is the "info" view
current_organization_switch(@project.organization)
end
def notifications
@ -261,6 +269,7 @@ class ProjectsController < ApplicationController
end
def experiment_archive
current_organization_switch(@project.organization)
end
def samples_index

View file

@ -741,9 +741,7 @@ class ProtocolsController < ApplicationController
end
def load_organization_and_type
@organizations = current_user.organizations.order(name: :asc)
@current_organization = @organizations.select{ |org| org.id == params[:organization].to_i }.first
@current_organization ||= @organizations.first
@current_organization = current_organization
# :public, :private or :archive
@type = (params[:type] || "public").to_sym
end

View file

@ -1,4 +1,5 @@
class ReportsController < ApplicationController
include OrganizationsHelper
# Ignore CSRF protection just for PDF generation (because it's
# used via target='_blank')
protect_from_forgery with: :exception, :except => :generate
@ -99,9 +100,10 @@ class ReportsController < ApplicationController
def edit
# cleans all the deleted report
current_organization_switch(@report.project.organization)
@report.cleanup_report
load_markdown
render "reports/new.html.erb"
render 'reports/new.html.erb'
end
# Updating existing report from the _save modal of the new page

View file

@ -1,10 +1,15 @@
class SampleMyModulesController < ApplicationController
include OrganizationsHelper
before_action :load_vars
def index
@number_of_samples = @my_module.number_of_samples
@samples = @my_module.first_n_samples
current_organization_switch(@my_module
.experiment
.project
.organization)
respond_to do |format|
format.json {
render :json => {

View file

@ -279,7 +279,7 @@ class SamplesController < ApplicationController
def load_vars
@sample = Sample.find_by_id(params[:id])
@organization = @sample.organization
@organization = current_organization
unless @sample
render_404

View file

@ -158,6 +158,10 @@ class Users::RegistrationsController < Devise::RegistrationsController
organization: @org,
role: :admin
)
# set current organization to new user
resource.current_organization_id = @org.id
resource.save
end
end

View file

@ -10,7 +10,8 @@ class Users::SettingsController < ApplicationController
:organization_users_datatable,
:tutorial,
:reset_tutorial,
:notifications_settings
:notifications_settings,
:user_current_organization
]
before_action :check_organization_permission, only: [
@ -445,7 +446,8 @@ class Users::SettingsController < ApplicationController
end
def reset_tutorial
if @user.update(tutorial_status: 0) && params[:org][:id]
if @user.update(tutorial_status: 0) && params[:org][:id].present?
@user.update(current_organization_id: params[:org][:id])
cookies.delete :tutorial_data
cookies.delete :current_tutorial_step
cookies[:repeat_tutorial_org_id] = {
@ -491,6 +493,19 @@ class Users::SettingsController < ApplicationController
end
end
def user_current_organization
@user.current_organization_id = params[:user][:current_organization_id]
@changed_org = Organization.find_by_id(@user.current_organization_id)
if params[:user][:current_organization_id].present? && @user.save
flash[:success] = t('users.settings.changed_org_flash',
team: @changed_org.name)
redirect_to root_path
else
flash[:alert] = t('users.settings.changed_org_error_flash')
redirect_to :back
end
end
private
def load_user

View file

@ -1,2 +1,18 @@
module OrganizationsHelper
# resets the current organization if needed
def current_organization_switch(org)
if org != current_organization
current_user.current_organization_id = org.id
current_user.save
end
end
def truncate_organization_name(name, len = Constants::NAME_TRUNCATION_LENGTH)
if name.length > len
"<div class='modal-tooltip'>#{truncate(name, length: len)}
<span class='modal-tooltiptext'>#{name}</span></div>".html_safe
else
name
end
end
end

View file

@ -6,4 +6,15 @@ module SearchHelper
end
experiments.uniq
end
def route_to_other_org(path, search_org, text)
if search_org != current_organization
link_to text,
path,
data: { confirm: t('users.settings.changed_org_in_search',
team: search_org.name) }
else
link_to text, path
end
end
end

View file

@ -56,6 +56,10 @@ module UsersGenerator
end
end
# Assign user organization as user current organization
nu.current_organization_id = nu.organizations.first.id
nu.save!
nu.reload
return nu
end
@ -85,4 +89,4 @@ module UsersGenerator
full_name.split(" ").collect{ |n| n.capitalize[0] }.join[0..3]
end
end
end

View file

@ -1,15 +1,7 @@
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<%= form.text_field :name, label: t("projects.index.modal_new_project.name"), autofocus: true, placeholder: t("projects.index.modal_new_project.name_placeholder") %>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<div class="form-group">
<%= form.label t("projects.index.modal_new_project.organization") %>
<%= collection_select(:project, :organization_id, @organizations, :id, :name, {}, { :class => "form-control"} ) %>
</div>
<%= hidden_field :project, :organization_id, value: current_organization.id %>
</div>
</div>

View file

@ -77,27 +77,6 @@
</a>
<% end %>
<!-- organization filter -->
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="organizationMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="hidden-xs"><%= t('projects.index.organization_filter') %></span>
<span class="visible-xs-inline"><i class="glyphicon glyphicon-folder-open"></i></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<% if @current_organization_id > 1 %>
<li><a href="?<%= {sort: @current_sort}.reject{|k,v| v.blank?}.to_query %>"><%= t'projects.index.all_filter' %></a></li>
<% end %>
<% @organizations.each do |org| %>
<% if org.id == @current_organization_id %>
<li class="disabled"><a href="#"><%= org.name %></a></li>
<% else %>
<li><a href="?<%= {organization: org.id, sort: @current_sort}.reject{|k,v| v.blank?}.to_query %>"><%= org.name %></a></li>
<% end %>
<% end %>
</ul>
</div>
<!-- project sort -->
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="sortMenu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
@ -130,11 +109,14 @@
<%= link_to t("projects.index.no_orgs.btn"), organizations_path, class: "btn btn-primary" %>
</p>
</div>
<% else %>
<h2 class="page-header"><%= current_organization.name %></h2>
<% end %>
<% if @projects_by_orgs.length > 0 %>
<% @projects_by_orgs.each do |org, projects| %>
<%= render partial: "projects/index/org_projects", locals: {org: org, projects: projects} %>
<% end %>
<% if current_organization.projects.length > 0 %>
<%= render partial: "projects/index/org_projects",
locals: { org: current_organization,
projects: current_organization.projects } %>
<% end %>
<%= javascript_include_tag "projects/index", "data-turbolinks-track" => true %>

View file

@ -1,5 +1,3 @@
<h2 class="page-header"><%= org.name %></h2>
<div class="row">
<% projects.each_index do |i| project = projects[i] %>
<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">

View file

@ -1,20 +1,7 @@
<ol class="breadcrumb breadcrumb-protocols-manager">
<% if action_name == "index" %>
<li class="active"><%= t("protocols.nav.breadcrumbs.manager") %></li>
<li class="dropdown">
<a class="dropdown-toggle" id="organizations-dropdown-a" role="button" data-toggle="dropdown" href="#"><%= current_organization.name %> <span class="caret"></span></a>
<ul id="organizations-dropdown" class="dropdown-menu">
<% organizations.each do |org| %>
<% if org != current_organization %>
<li>
<%= link_to org.name, protocols_path(organization: org, type: type) %>
</li>
<% else %>
<li class="disabled"><a href="#"><%= org.name %></a></li>
<% end %>
<% end %>
</ul>
</li>
<li class="disabled"><%= current_organization.name %></li>
<% else %>
<li><%= link_to t("protocols.nav.breadcrumbs.manager"), protocols_path(organization: current_organization, type: type) %></li>
<li class="active"><%= current_organization.name %></li>
@ -24,4 +11,4 @@
<%= t("protocols.nav.breadcrumbs.edit") %>
</li>
<% end %>
</ol>
</ol>

View file

@ -1,6 +1,6 @@
<% provide(:head_title, t("protocols.index.head_title")) %>
<% if @organizations.count > 0 %>
<% if current_organization %>
<%= render partial: "protocols/breadcrumbs.html.erb", locals: { organizations: @organizations, current_organization: @current_organization, type: @type } %>
<ul class="nav nav-tabs nav-settings">

View file

@ -11,4 +11,4 @@
</a>
<% else %>
<%= text %>
<% end %>
<% end %>

View file

@ -4,17 +4,15 @@
<% if experiment.archived? %>
<span class="label label-warning"><%=t "search.index.archived" %></span>
<% if can_view_experiment(experiment) and can_restore_experiment(experiment.project) %>
<a href="/">
<%= text %>
</a>
<%= route_to_other_org root_path, experiment.project.organization, text %>
<% else %>
<%= text %>
<% end %>
<% else %>
<% if can_view_experiment(experiment) %>
<a href="<%= canvas_experiment_path(experiment) %>">
<%= text %>
</a>
<%= route_to_other_org canvas_experiment_path(experiment),
experiment.project.organization,
text %>
<% else %>
<%= text %>
<% end %>

View file

@ -5,9 +5,9 @@
<% if my_module.archived? %>
<span class="label label-warning"><%=t "search.index.archived" %></span>
<% if can_view_experiment_archive(my_module.experiment) and can_restore_module(my_module) %>
<a href="<%= module_archive_experiment_url(my_module.experiment) %>">
<%= text %>
</a>
<%= route_to_other_org module_archive_experiment_url(my_module.experiment),
my_module.experiment.project.organization,
text %>
<% else %>
<%= text %>
<% end %>
@ -15,21 +15,21 @@
<% if can_view_module(my_module) %>
<% case link_to_page %>
<% when :samples %>
<a href="<%= samples_my_module_path(my_module) %>">
<%= text %>
</a>
<%= route_to_other_org samples_my_module_path(my_module),
my_module.experiment.project.organization,
text %>
<% when :protocols %>
<a href="<%= protocols_my_module_path(my_module) %>">
<%= text %>
</a>
<%= route_to_other_org protocols_my_module_path(my_module),
my_module.experiment.project.organization,
text %>
<% when :canvas %>
<a href="<%= canvas_experiment_path(my_module.experiment) %>">
<%= text %>
</a>
<%= route_to_other_org canvas_experiment_path(my_module.experiment),
my_module.experiment.project.organization,
text %>
<% when :results %>
<a href="<%= results_my_module_path(my_module) %>">
<%= text %>
</a>
<%= route_to_other_org results_my_module_path(my_module),
my_module.experiment.project.organization,
text %>
<% else %>
<%= text %>
<% end %>

View file

@ -1,7 +1,7 @@
<% if can_view_projects(organization) %>
<a href="<%= projects_path :organization => organization.id %>">
<%= organization.name %>
</a>
<%= route_to_other_org projects_path(organization: organization.id),
organization,
organization.name %>
<% else %>
<%= organization.name %>
<% end %>
<% end %>

View file

@ -5,24 +5,24 @@
<% if project.archived? %>
<span class="label label-warning"><%=t "search.index.archived" %></span>
<% if can_view_projects(project.organization) and can_restore_project(project) %>
<a href="<%= projects_archive_path(organization: project.organization) %>">
<%= text %>
</a>
<%= route_to_other_org projects_archive_path(organization: project.organization),
project.organization,
text %>
<% else %>
<%= text %>
<% end %>
<% else %>
<% if can_view_project(project) %>
<% if link_to_page == :show %>
<a href="<%= project_path(project) %>">
<%= text %>
</a>
<%= route_to_other_org project_path(project),
project.organization,
text %>
<% else %>
<a href="<%= root_path %>">
<%= text %>
</a>
<%= route_to_other_org root_path,
nil,
text %>
<% end %>
<% else %>
<%= text %>
<% end %>
<% end %>
<% end %>

View file

@ -7,9 +7,9 @@
</span>
&nbsp;
<% if can_view_steps_in_protocol(protocol) %>
<a href="<%= protocols_my_module_path(protocol.my_module) %>">
<%= text %>
</a>
<%= route_to_other_org protocols_my_module_path(protocol.my_module),
protocol.organization,
text %>
<% else %>
<%= text %>
<% end %>
@ -31,9 +31,9 @@
&nbsp;
<% end %>
<% if can_edit_protocol(protocol) %>
<a href="<%= edit_protocol_path(protocol) %>">
<%= text %>
</a>
<%= route_to_other_org edit_protocol_path(protocol),
protocol.organization,
text %>
<% else %>
<%= text %>
<% end %>

View file

@ -2,9 +2,9 @@
<% text = query.present? ? highlight(report.name, query.strip.split(/\s+/)) : report.name %>
<% if can_view_reports(report.project) %>
<a href="<%= edit_project_report_path(report.project, report) %>">
<%= text %>
</a>
<%= route_to_other_org edit_project_report_path(report.project, report),
report.project.organization,
text %>
<% else %>
<%= text %>
<% end %>
<% end %>

View file

@ -6,13 +6,14 @@
<span class="label label-warning"><%=t "search.index.archived" %></span>
<% if can_view_module_archive(result.my_module) %>
<% if target == :comment %>
<%= link_to archive_my_module_path(result.my_module, ctarget: "result-panel-#{result.id}") do %>
<%= text %>
<% end %>
<%= route_to_other_org archive_my_module_path(result.my_module, ctarget: "result-panel-#{result.id}"),
result.my_module.experiment.project.organization,
text %>
<% else %>
<a href="<%= archive_my_module_path(result.my_module) %>">
<%= text %>
</a>
<%= route_to_other_org archive_my_module_path(result.my_module),
result.my_module.experiment.project.organization,
text %>
<% end %>
<% else %>
<%= text %>
@ -20,13 +21,13 @@
<% else %>
<% if can_view_results_in_module(result.my_module) %>
<% if target == :comment %>
<%= link_to results_my_module_path(result.my_module, ctarget: "result-panel-#{result.id}") do %>
<%= text %>
<% end %>
<%= route_to_other_org results_my_module_path(result.my_module, ctarget: "result-panel-#{result.id}"),
result.my_module.experiment.project.organization,
text %>
<% else %>
<a href="<%= results_my_module_path(result.my_module) %>">
<%= text %>
</a>
<%= route_to_other_org results_my_module_path(result.my_module),
result.my_module.experiment.project.organization,
text %>
<% end %>
<% else %>
<%= text %>

View file

@ -5,18 +5,18 @@
<% if can_view_steps_in_protocol(step.protocol) %>
<% if step.protocol.in_module? %>
<% if target == :comment %>
<%= link_to protocols_my_module_path(step.protocol.my_module, ctarget: "step-panel-#{step.id}") do %>
<%= text %>
<% end %>
<%= route_to_other_org protocols_my_module_path(step.protocol.my_module, ctarget: "step-panel-#{step.id}"),
step.protocol.organization,
text %>
<% else %>
<a href="<%= protocols_my_module_path(step.protocol.my_module) %>">
<%= text %>
</a>
<%= route_to_other_org protocols_my_module_path(step.protocol.my_module),
step.protocol.organization,
text %>
<% end %>
<% elsif can_edit_protocol(step.protocol) %>
<a href="<%= edit_protocol_path(step.protocol) %>">
<%= text %>
</a>
<%= route_to_other_org edit_protocol_path(step.protocol),
step.protocol.organization,
text %>
<% else %>
<%= text %>
<% end %>

View file

@ -100,6 +100,34 @@
</ul>
</li>
<!-- Global team switch -->
<% if current_user.organizations.length > 1 %>
<li class="dropdown" id="team-switch">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<%= fa_icon 'users' %>
<span>
<%= truncate_organization_name(current_organization.name) %>
</span>
</a>
<ul class="dropdown-menu ">
<%= form_for(current_user,
url: user_current_organization_path,
method: :post) do |f| %>
<%= hidden_field(:user, :current_organization_id) %>
<% current_user.organizations.each do |org| %>
<% next unless org != current_organization %>
<li>
<a href="#" data-id="<%= org.id %>" class="text-center">
<%= org.name %>
</a>
</li>
<% end %>
<% end %>
</ul>
</li>
<% end %>
<!-- greetings -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">

View file

@ -1118,6 +1118,9 @@ en:
team_name_label: "Team name"
team_name_help: "Team name is required in order to create your own team."
settings:
changed_org_flash: "You are working on %{team} now!"
changed_org_error_flash: "Something went wrong! Try again later."
changed_org_in_search: "The searched item is not in your current team. You will be redirected to %{team} team!"
navigation:
preferences: "My preferences"
organizations: "My teams"

View file

@ -19,6 +19,9 @@ Rails.application.routes.draw do
to: 'users/settings#notifications_settings',
as: 'notifications_settings',
defaults: { format: 'json' }
post 'users/settings/user_current_organization',
to: 'users/settings#user_current_organization',
as: 'user_current_organization'
get "users/settings/organizations", to: "users/settings#organizations", as: "organizations"
get "users/settings/organizations/new", to: "users/settings#new_organization", as: "new_organization"
post "users/settings/organizations/new", to: "users/settings#create_organization", as: "create_organization"

View file

@ -0,0 +1,14 @@
class AddCurrentOrganizationToUser < ActiveRecord::Migration
def up
add_column :users, :current_organization_id, :integer
add_foreign_key :users, :organizations, column: :current_organization_id
User.find_each do |user|
user.update(current_organization_id: user.organizations.first.id)
end
end
def down
remove_column :users, :current_organization_id
end
end

View file

@ -664,6 +664,7 @@ ActiveRecord::Schema.define(version: 20161012112900) do
t.boolean "recent_notification", default: true
t.boolean "assignments_notification_email", default: false
t.boolean "recent_notification_email", default: false
t.integer "current_organization_id"
t.boolean "system_message_notification_email", default: false
end
@ -795,4 +796,5 @@ ActiveRecord::Schema.define(version: 20161012112900) do
add_foreign_key "user_projects", "projects"
add_foreign_key "user_projects", "users"
add_foreign_key "user_projects", "users", column: "assigned_by_id"
add_foreign_key "users", "organizations", column: "current_organization_id"
end

View file

@ -1,10 +1,10 @@
include UsersGenerator
# Create admin user
admin_password = "inHisHouseAtRlyehDeadCthulhuWaitsDreaming"
admin_password = 'inHisHouseAtRlyehDeadCthulhuWaitsDreaming'
create_user(
"Admin",
"admin@scinote.net",
'Admin',
'admin@scinote.net',
admin_password,
true,
Constants::DEFAULT_PRIVATE_ORG_NAME,