mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-30 00:45:28 +08:00
prepare data for atwho
This commit is contained in:
parent
eb64162633
commit
94262b56ef
7 changed files with 382 additions and 4 deletions
206
app/assets/javascripts/sitewide/atwho_tasks.js
Normal file
206
app/assets/javascripts/sitewide/atwho_tasks.js
Normal file
|
@ -0,0 +1,206 @@
|
|||
(function() {
|
||||
'use strict';
|
||||
|
||||
function smartAnnotation(field) {
|
||||
|
||||
// Generates resources list items
|
||||
function generateTemplate(map) {
|
||||
var res = '';
|
||||
res += '<li class="atwho-li atwho-li-res" data-path="' +
|
||||
map.path + '" data-id="' + map.id + '">';
|
||||
switch(map.type) {
|
||||
case 'tsk':
|
||||
res += '<span data-type class="res-type">' + map.type + '</span>';
|
||||
break;
|
||||
case 'prj':
|
||||
res += '<span data-type class="res-type">' + map.type + '</span>';
|
||||
break;
|
||||
case 'exp':
|
||||
res += '<span data-type class="res-type">' + map.type + '</span>';
|
||||
break;
|
||||
case 'sam':
|
||||
res += '<span class="glyphicon glyphicon-tint"></span>';
|
||||
break;
|
||||
}
|
||||
|
||||
res += ' ';
|
||||
res += '<span data-name class="res-name">';
|
||||
res += map.name;
|
||||
res += '</span>';
|
||||
res += ' ';
|
||||
|
||||
switch (map.type) {
|
||||
case 'tsk':
|
||||
res += '<span>< ' + map.experimentName +
|
||||
' < ' + map.projectName + '</span>';
|
||||
break;
|
||||
case 'exp':
|
||||
res += '<span>< ' + map.projectName + '</span>';
|
||||
break;
|
||||
case 'sam':
|
||||
res += '<span>' + map.description + '</span>';
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
res += '</li>';
|
||||
return res;
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (_.isUndefined($(field).data('atwho'))) {
|
||||
$(field)
|
||||
.atwho({
|
||||
at: '#',
|
||||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(
|
||||
'/organizations/1/atwho_resources.json',
|
||||
{query: query},
|
||||
function(data) {
|
||||
callback(data.res);
|
||||
}
|
||||
);
|
||||
},
|
||||
tplEval: function(_tpl, map) {
|
||||
var res;
|
||||
try {
|
||||
res = generateTemplate(map);
|
||||
} catch (_error) {
|
||||
res = '';
|
||||
}
|
||||
return res;
|
||||
},
|
||||
},
|
||||
displayTpl: '<span>${type}<span><a href="${path}">${name}</a>',
|
||||
insertTpl: '[${atwho-at}${name}~${id}]',
|
||||
limit: 5,
|
||||
startWithSpace: true
|
||||
})
|
||||
.atwho({
|
||||
at: 'task#',
|
||||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(
|
||||
'/organizations/1/atwho_resources.json',
|
||||
{query: query},
|
||||
function(data) {
|
||||
callback(data.res);
|
||||
}
|
||||
);
|
||||
},
|
||||
tplEval: function(_tpl, map) {
|
||||
var res;
|
||||
try {
|
||||
res = generateTemplate(map);
|
||||
} catch (_error) {
|
||||
res = '';
|
||||
}
|
||||
return res;
|
||||
},
|
||||
},
|
||||
displayTpl: '<span>${type}<span><a href="${path}">${name}</a>',
|
||||
insertTpl: '[${atwho-at}${name}~${id}]',
|
||||
limit: 5,
|
||||
startWithSpace: true
|
||||
})
|
||||
.atwho({
|
||||
at: 'project#',
|
||||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(
|
||||
'/organizations/1/atwho_resources.json',
|
||||
{query: query},
|
||||
function(data) {
|
||||
callback(data.res);
|
||||
}
|
||||
);
|
||||
},
|
||||
tplEval: function(_tpl, map) {
|
||||
var res;
|
||||
try {
|
||||
res = generateTemplate(map);
|
||||
} catch (_error) {
|
||||
res = '';
|
||||
}
|
||||
return res;
|
||||
},
|
||||
},
|
||||
displayTpl: '<span>${type}<span><a href="${path}">${name}</a>',
|
||||
insertTpl: '[${atwho-at}${name}~${id}]',
|
||||
limit: 5,
|
||||
startWithSpace: true
|
||||
})
|
||||
.atwho({
|
||||
at: 'experiment#',
|
||||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(
|
||||
'/organizations/1/atwho_resources.json',
|
||||
{query: query},
|
||||
function(data) {
|
||||
callback(data.res);
|
||||
}
|
||||
);
|
||||
},
|
||||
tplEval: function(_tpl, map) {
|
||||
var res;
|
||||
try {
|
||||
res = generateTemplate(map);
|
||||
} catch (_error) {
|
||||
res = '';
|
||||
}
|
||||
return res;
|
||||
},
|
||||
},
|
||||
displayTpl: '<span>${type}<span><a href="${path}">${name}</a>',
|
||||
insertTpl: '[${atwho-at}${name}~${id}]',
|
||||
limit: 5,
|
||||
startWithSpace: true
|
||||
})
|
||||
.atwho({
|
||||
at: 'sample#',
|
||||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(
|
||||
'/organizations/1/atwho_resources.json',
|
||||
{query: query},
|
||||
function(data) {
|
||||
callback(data.res);
|
||||
}
|
||||
);
|
||||
},
|
||||
tplEval: function(_tpl, map) {
|
||||
var res;
|
||||
try {
|
||||
res = generateTemplate(map);
|
||||
} catch (_error) {
|
||||
res = '';
|
||||
}
|
||||
return res;
|
||||
},
|
||||
},
|
||||
displayTpl: '<span class="glyphicon glyphicon-tint"><span>' +
|
||||
'<a href="${path}">${name}</a>',
|
||||
insertTpl: '[${atwho-at}${name}~${id}]',
|
||||
limit: 5,
|
||||
startWithSpace: true
|
||||
});
|
||||
}
|
||||
}
|
||||
return { init: init };
|
||||
}
|
||||
|
||||
var smartA = new smartAnnotation('#comment_message');
|
||||
|
||||
$(document).ready(function() {
|
||||
setTimeout(function(){
|
||||
|
||||
smartA.init();
|
||||
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
|
||||
})();
|
|
@ -1,6 +1,6 @@
|
|||
class AtWhoController < ApplicationController
|
||||
before_action :load_vars
|
||||
before_action :check_users_permissions, only: :users
|
||||
before_action :check_users_permissions
|
||||
|
||||
def users
|
||||
# Search users
|
||||
|
@ -25,6 +25,18 @@ class AtWhoController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def resources
|
||||
res = SmartAnnotation.new(current_user, @query)
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
res: res.resources,
|
||||
status: :ok
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_vars
|
||||
|
|
149
app/models/smart_annotation.rb
Normal file
149
app/models/smart_annotation.rb
Normal file
|
@ -0,0 +1,149 @@
|
|||
class SmartAnnotation
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
include ActionView::Helpers::TextHelper
|
||||
|
||||
attr_writer :current_user, :query
|
||||
|
||||
def initialize(current_user, query)
|
||||
@current_user = current_user
|
||||
@query = query
|
||||
end
|
||||
|
||||
def resources
|
||||
my_modules
|
||||
.concat(projects)
|
||||
.concat(experiments)
|
||||
.concat(samples)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def my_modules
|
||||
# Search tasks
|
||||
res = MyModule
|
||||
.search(@current_user, true, @query)
|
||||
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
||||
|
||||
modules_list = []
|
||||
res.each do |my_module_res|
|
||||
my_mod = {}
|
||||
my_mod['id'] = my_module_res.id
|
||||
my_mod['name'] = truncate(
|
||||
sanitize(my_module_res.name,
|
||||
length: Constants::NAME_TRUNCATION_LENGTH)
|
||||
)
|
||||
my_mod['path'] = Rails
|
||||
.application
|
||||
.routes
|
||||
.url_helpers
|
||||
.protocols_my_module_path(my_module_res)
|
||||
my_mod['archived'] = my_module_res.archived
|
||||
my_mod['experimentName'] = truncate(
|
||||
sanitize(my_module_res.experiment.name,
|
||||
length: Constants::NAME_TRUNCATION_LENGTH)
|
||||
)
|
||||
my_mod['projectName'] = truncate(
|
||||
sanitize(my_module_res.experiment.project.name,
|
||||
length: Constants::NAME_TRUNCATION_LENGTH)
|
||||
)
|
||||
my_mod['type'] = 'tsk'
|
||||
|
||||
modules_list << my_mod
|
||||
end
|
||||
modules_list
|
||||
end
|
||||
|
||||
def projects
|
||||
# Search projects
|
||||
res = Project
|
||||
.search(@current_user, true, @query)
|
||||
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
||||
|
||||
projects_list = []
|
||||
res.each do |project_res|
|
||||
prj = {}
|
||||
prj['id'] = project_res.id
|
||||
prj['name'] = truncate(
|
||||
sanitize(project_res.name,
|
||||
length: Constants::NAME_TRUNCATION_LENGTH)
|
||||
)
|
||||
prj['path'] = Rails
|
||||
.application
|
||||
.routes
|
||||
.url_helpers
|
||||
.project_path(project_res)
|
||||
prj['type'] = 'prj'
|
||||
projects_list << prj
|
||||
end
|
||||
projects_list
|
||||
end
|
||||
|
||||
def experiments
|
||||
# Search experiments
|
||||
res = Experiment
|
||||
.search(@current_user, true, @query)
|
||||
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
||||
|
||||
experiments_list = []
|
||||
res.each do |experiment_res|
|
||||
exp = {}
|
||||
exp['id'] = experiment_res.id
|
||||
exp['name'] = truncate(
|
||||
sanitize(experiment_res.name,
|
||||
length: Constants::NAME_TRUNCATION_LENGTH)
|
||||
)
|
||||
exp['path'] = Rails
|
||||
.application
|
||||
.routes
|
||||
.url_helpers
|
||||
.canvas_experiment_path(experiment_res)
|
||||
exp['type'] = 'exp'
|
||||
exp['project'] = truncate(
|
||||
sanitize(experiment_res.project.name,
|
||||
length: Constants::NAME_TRUNCATION_LENGTH)
|
||||
)
|
||||
experiments_list << exp
|
||||
end
|
||||
experiments_list
|
||||
end
|
||||
|
||||
def samples
|
||||
# Search samples
|
||||
res = Sample
|
||||
.search(@current_user, true, @query)
|
||||
.limit(Constants::ATWHO_SEARCH_LIMIT)
|
||||
|
||||
samples_list = []
|
||||
res.each do |sample_res|
|
||||
sam = {}
|
||||
sam['id'] = sample_res.id
|
||||
sam['name'] = truncate(
|
||||
sanitize(sample_res.name,
|
||||
length: Constants::NAME_TRUNCATION_LENGTH)
|
||||
)
|
||||
sam['path'] = Rails
|
||||
.application
|
||||
.routes
|
||||
.url_helpers
|
||||
.samples_project_path(sample_res
|
||||
.organization
|
||||
.projects
|
||||
.first)
|
||||
sam['description'] = "#{I18n.t('Added')} #{I18n.l(
|
||||
sample_res.created_at, format: :full_date
|
||||
)} #{I18n.t('by')} #{truncate(
|
||||
sanitize(sample_res.user.full_name,
|
||||
length: Constants::NAME_TRUNCATION_LENGTH)
|
||||
)} #{(',' + truncate(
|
||||
sanitize(sample_res.sample_type.name,
|
||||
length: Constants::NAME_TRUNCATION_LENGTH)
|
||||
)) if sample_res.sample_type}, #{(',' + truncate(
|
||||
sanitize(sample_res.sample_group.name,
|
||||
length: Constants::NAME_TRUNCATION_LENGTH)
|
||||
)) if sample_res.sample_group}"
|
||||
sam['type'] = 'sam'
|
||||
samples_list << sam
|
||||
end
|
||||
samples_list
|
||||
end
|
||||
end
|
|
@ -22,7 +22,13 @@
|
|||
<li>
|
||||
<hr>
|
||||
<%= bootstrap_form_for :comment, url: { format: :json }, method: :post, remote: true, html: { class: 'comment-form' } do |f| %>
|
||||
<%= f.smart_text_area :message, single_line: true, hide_label: true, placeholder: t("general.comment_placeholder"), append: f.submit("+", onclick: "processResult(event, ResultTypeEnum.COMMENT, false);"), help: '.' %>
|
||||
<%= f.smart_text_area :message,
|
||||
single_line: true,
|
||||
hide_label: true,
|
||||
placeholder: t("general.comment_placeholder"),
|
||||
append: f.submit("+", onclick: "processResult(event, ResultTypeEnum.COMMENT, false);"),
|
||||
help: '.',
|
||||
data: { 'atwho-res-edit' => '' } %>
|
||||
<% end %>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
@ -28,7 +28,10 @@
|
|||
<%= f.text_field :name, label: t("protocols.steps.new.name"), placeholder: t("protocols.steps.new.name_placeholder") %>
|
||||
<div class="form-group">
|
||||
<label class="control-label" for="step_description"><%= t('protocols.steps.new.description') %></label>
|
||||
<%= quill_editor nil, { id: 'step_description', name: 'step[description]', value: @step.description } %>
|
||||
<%= quill_editor nil, { id: 'step_description',
|
||||
name: 'step[description]',
|
||||
value: @step.description,
|
||||
data: { 'atwho-res-edit' => '' } } %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane" role="tabpanel" id="new-step-checklists">
|
||||
|
|
|
@ -1513,3 +1513,5 @@ en:
|
|||
Workflow: "Workflow"
|
||||
Workflows: "Workflows"
|
||||
More: "More"
|
||||
Added: 'Added'
|
||||
by: 'by'
|
||||
|
|
|
@ -88,7 +88,7 @@ Rails.application.routes.draw do
|
|||
post 'export_samples'
|
||||
# Used for atwho (smart annotations)
|
||||
get 'atwho_users', to: 'at_who#users'
|
||||
|
||||
get 'atwho_resources', to: 'at_who#resources'
|
||||
end
|
||||
match '*path', :to => 'organizations#routing_error', via: [:get, :post, :put, :patch]
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue