mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-05 04:34:37 +08:00
added xregexp
This commit is contained in:
parent
94262b56ef
commit
53d20df449
6 changed files with 4553 additions and 17 deletions
|
@ -27,6 +27,7 @@
|
|||
//= require bootstrap-checkbox.min
|
||||
//= require typeahead.bundle.min
|
||||
//= require nested_form_fields
|
||||
//= require xregexp-all
|
||||
//= require_directory ./sitewide
|
||||
//= require dataTables.noSearchHidden
|
||||
//= require bootstrap-select
|
||||
|
|
|
@ -3,6 +3,51 @@
|
|||
|
||||
function smartAnnotation(field) {
|
||||
|
||||
// Generates new query when user filters the results
|
||||
function generateNewQuery(link) {
|
||||
|
||||
var regexp = new XRegExp('(\\s+|^)task#|project#|sample#|experiment#(\\p{L}+)$', 'gi');
|
||||
var new_query = regexp.exec($(field).val());
|
||||
debugger;
|
||||
$.getJSON(
|
||||
link,
|
||||
{query: new_query},
|
||||
function(data) {
|
||||
$(field).atwho('load',':', data).atwho('run');
|
||||
});
|
||||
}
|
||||
|
||||
// Generates suggestion dropdown filter
|
||||
function generateFilter(link) {
|
||||
$('.atwho-view ul').prepend('<li id="atwho-filter">' +
|
||||
'<button data-filter="prj" class="btn btn-sm btn-default">project #</button>' +
|
||||
'<button data-filter="exp" class="btn btn-sm btn-default">experiment #</button>' +
|
||||
'<button data-filter="tsk" class="btn btn-sm btn-default">task #</button>' +
|
||||
'<button data-filter="sam" class="btn btn-sm btn-default">#</button></li>');
|
||||
|
||||
$('#atwho-filter .btn').on('click', function(event) {
|
||||
event.stopPropagation();
|
||||
var $button = $(this);
|
||||
switch ($button.attr('data-filter')) {
|
||||
case 'prj':
|
||||
generateNewQuery('/organizations/1/atwho_projects.json');
|
||||
break;
|
||||
case 'exp':
|
||||
generateNewQuery('/organizations/1/atwho_experiments.json');
|
||||
break;
|
||||
case 'tsk':
|
||||
generateNewQuery('/organizations/1/atwho_my_modules.json');
|
||||
break;
|
||||
case 'sam':
|
||||
generateNewQuery('/organizations/1/atwho_samples.json');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Generates resources list items
|
||||
function generateTemplate(map) {
|
||||
var res = '';
|
||||
|
@ -56,7 +101,7 @@
|
|||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(
|
||||
'/organizations/1/atwho_resources.json',
|
||||
'/organizations/1/atwho_samples.json',
|
||||
{query: query},
|
||||
function(data) {
|
||||
callback(data.res);
|
||||
|
@ -72,6 +117,9 @@
|
|||
}
|
||||
return res;
|
||||
},
|
||||
beforeReposition: function(offset) {
|
||||
generateFilter('bleble');
|
||||
}
|
||||
},
|
||||
displayTpl: '<span>${type}<span><a href="${path}">${name}</a>',
|
||||
insertTpl: '[${atwho-at}${name}~${id}]',
|
||||
|
@ -83,7 +131,7 @@
|
|||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(
|
||||
'/organizations/1/atwho_resources.json',
|
||||
'/organizations/1/atwho_my_modules.json',
|
||||
{query: query},
|
||||
function(data) {
|
||||
callback(data.res);
|
||||
|
@ -99,6 +147,9 @@
|
|||
}
|
||||
return res;
|
||||
},
|
||||
beforeReposition: function(offset) {
|
||||
generateFilter('bleble');
|
||||
}
|
||||
},
|
||||
displayTpl: '<span>${type}<span><a href="${path}">${name}</a>',
|
||||
insertTpl: '[${atwho-at}${name}~${id}]',
|
||||
|
@ -110,7 +161,7 @@
|
|||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(
|
||||
'/organizations/1/atwho_resources.json',
|
||||
'/organizations/1/atwho_projects.json',
|
||||
{query: query},
|
||||
function(data) {
|
||||
callback(data.res);
|
||||
|
@ -126,6 +177,10 @@
|
|||
}
|
||||
return res;
|
||||
},
|
||||
beforeReposition: function(offset) {
|
||||
generateFilter('bleble');
|
||||
}
|
||||
|
||||
},
|
||||
displayTpl: '<span>${type}<span><a href="${path}">${name}</a>',
|
||||
insertTpl: '[${atwho-at}${name}~${id}]',
|
||||
|
@ -137,7 +192,7 @@
|
|||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(
|
||||
'/organizations/1/atwho_resources.json',
|
||||
'/organizations/1/atwho_experiments.json',
|
||||
{query: query},
|
||||
function(data) {
|
||||
callback(data.res);
|
||||
|
@ -153,6 +208,9 @@
|
|||
}
|
||||
return res;
|
||||
},
|
||||
beforeReposition: function(offset) {
|
||||
generateFilter('bleble');
|
||||
}
|
||||
},
|
||||
displayTpl: '<span>${type}<span><a href="${path}">${name}</a>',
|
||||
insertTpl: '[${atwho-at}${name}~${id}]',
|
||||
|
@ -164,7 +222,7 @@
|
|||
callbacks: {
|
||||
remoteFilter: function(query, callback) {
|
||||
$.getJSON(
|
||||
'/organizations/1/atwho_resources.json',
|
||||
'/organizations/1/atwho_samples.json',
|
||||
{query: query},
|
||||
function(data) {
|
||||
callback(data.res);
|
||||
|
@ -180,6 +238,9 @@
|
|||
}
|
||||
return res;
|
||||
},
|
||||
beforeReposition: function(offset) {
|
||||
generateFilter('bleble');
|
||||
}
|
||||
},
|
||||
displayTpl: '<span class="glyphicon glyphicon-tint"><span>' +
|
||||
'<a href="${path}">${name}</a>',
|
||||
|
|
|
@ -25,12 +25,48 @@ class AtWhoController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def resources
|
||||
def samples
|
||||
res = SmartAnnotation.new(current_user, @query)
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
res: res.resources,
|
||||
res: res.samples,
|
||||
status: :ok
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def projects
|
||||
res = SmartAnnotation.new(current_user, @query)
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
res: res.projects,
|
||||
status: :ok
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def experiments
|
||||
res = SmartAnnotation.new(current_user, @query)
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
res: res.experiments,
|
||||
status: :ok
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def my_modules
|
||||
res = SmartAnnotation.new(current_user, @query)
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
res: res.my_modules,
|
||||
status: :ok
|
||||
}
|
||||
end
|
||||
|
|
|
@ -9,15 +9,6 @@ class SmartAnnotation
|
|||
@query = query
|
||||
end
|
||||
|
||||
def resources
|
||||
my_modules
|
||||
.concat(projects)
|
||||
.concat(experiments)
|
||||
.concat(samples)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def my_modules
|
||||
# Search tasks
|
||||
res = MyModule
|
||||
|
|
|
@ -88,7 +88,10 @@ 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'
|
||||
get 'atwho_samples', to: 'at_who#samples'
|
||||
get 'atwho_projects', to: 'at_who#projects'
|
||||
get 'atwho_experiments', to: 'at_who#experiments'
|
||||
get 'atwho_my_modules', to: 'at_who#my_modules'
|
||||
end
|
||||
match '*path', :to => 'organizations#routing_error', via: [:get, :post, :put, :patch]
|
||||
end
|
||||
|
|
4444
vendor/assets/javascripts/xregexp-all.js
vendored
Normal file
4444
vendor/assets/javascripts/xregexp-all.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue