Commit 7442fd39 authored by Mikaël Salson's avatar Mikaël Salson

Merge branch 'feature-s/cleaner_public_tags' into 'dev'

Feature s/cleaner public tags

See merge request !98
parents a0831c03 39711fe2
......@@ -210,7 +210,7 @@ VidjilAutoComplete.prototype = {
if (res < 0) {
seen.push(elem.name);
}
return res;
return res < 0;
})
$input.atwho('load', at, loaded_data);
......
......@@ -14,4 +14,4 @@ def auto_complete():
group_ids = json.loads(request.vars["group_ids"])
tags = get_tags(db, group_ids)
return tags_to_json(tags)
return tags_to_json(tags, group_ids)
......@@ -93,11 +93,15 @@ def register_tags(db, table, record_id, text, group_id, reset=False):
tags = tag_extractor.execute(table, record_id, text, group_id, reset)
def get_tags(db, group_ids):
pgid = get_public_group_id()
if pgid > 0:
group_ids.append(pgid)
return db((db.tag.id == db.group_tag.tag_id) &
(db.group_tag.group_id.belongs(group_ids))
).select(db.group_tag.group_id, db.tag.ALL)
def tags_to_json(tags):
def tags_to_json(tags, group_ids):
tag_map = {}
prefix = get_tag_prefix()
for row in tags:
......@@ -109,6 +113,25 @@ def tags_to_json(tags):
tag_dict['name'] = row.tag.name
tag_map[group_id].append(tag_dict)
# Public group hackiness. Mainly to clean up some other hackier hackiness
pgid = get_public_group_id()
if pgid > 0 and pgid in tag_map:
for group_id in tag_map:
for tag in tag_map[pgid]:
if tag not in tag_map[group_id]:
tag_map[group_id].append(tag)
# Public group hackiness. Mainly to clean up some other hackier hackiness
pgid = get_public_group_id()
if pgid > 0 and pgid in tag_map:
for group_id in group_ids:
if group_id not in tag_map:
tag_map[group_id] = []
for tag in tag_map[pgid]:
if tag not in tag_map[group_id]:
tag_map[group_id].append(tag)
return json.dumps(tag_map)
def parse_search(search_string):
......@@ -119,3 +142,10 @@ def parse_search(search_string):
searches = [s for s in split if s[:plen] != tag_prefix]
search_string = " ".join(searches)
return search_string, tags
def get_public_group_id():
public_group_name = defs.PUBLIC_GROUP_NAME if hasattr(defs, 'PUBLIC_GROUP_NAME') in defs else 'public'
public_group = db(db.auth_group.role == public_group_name).select()
if (len(public_group) > 0 and public_group.id not in group_ids):
return public_group.id
return -1
......@@ -90,9 +90,6 @@
</tr>
<tr>
<td><label for="file_info" id="file_info__label">info: </label></td>
{{ if 3 not in group_ids:}}
{{group_ids.append(3)}}
{{pass}}
<td><textarea onfocus="new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" data-group-ids="{{=group_ids}}" class="text" id="file_info" name="file_info" cols="60" rows="8"></textarea></td>
<td></td>
</tr>
......
......@@ -98,9 +98,6 @@ info = db.sequence_file[request.vars["id"]]
</tr>
<tr>
<td><label for="file_info" id="file_info__label">info: </label></td>
{{ if 3 not in group_ids:}}
{{group_ids.append(3)}}
{{pass}}
<td><textarea onfocus="new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" data-group-ids="{{=group_ids}}" class="text" id="file_info" name="file_info" cols="60" rows="12">{{=file.info}}</textarea></td>
<td></td>
</tr>
......
......@@ -32,7 +32,7 @@
</tr>
<tr>
<td><label for="patient_info" id="patient_info__label">Info: </label></td>
<td><textarea onfocus="$(this).data('group-ids', [$('#group_select option:selected').val(), 3]); new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" class="text" cols="40" id="patient_info" name="info" rows="10"></textarea></td>
<td><textarea onfocus="$(this).data('group-ids', [$('#group_select option:selected').val()]); new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" class="text" cols="40" id="patient_info" name="info" rows="10"></textarea></td>
<td></td>
</tr>
<tr>
......
......@@ -30,7 +30,7 @@ info = db.patient[request.vars["id"]]
</tr>
<tr>
<td> <label for="patient_info" id="patient_info__label">Info: </label> </td>
<td> <textarea onfocus="new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" data-group-ids="[{{=group_id}}, 3]" class="text" cols="40" id="patient_info" name="info" rows="10">{{=info.info}}</textarea> </td>
<td> <textarea onfocus="new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" data-group-ids="[{{=group_id}}]" class="text" cols="40" id="patient_info" name="info" rows="10">{{=info.info}}</textarea> </td>
<td></td>
</tr>
<tr>
......
......@@ -27,7 +27,7 @@
</tr>
<tr>
<td><label for="run_info" id="run_info__label">Info: </label></td>
<td><textarea onfocus="$(this).data('group-ids', [$('#group_select option:selected').val(), 3]); new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" class="text" cols="40" id="run_info" name="info" rows="10"></textarea></td>
<td><textarea onfocus="$(this).data('group-ids', [$('#group_select option:selected').val()]); new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" class="text" cols="40" id="run_info" name="info" rows="10"></textarea></td>
<td></td>
</tr>
<tr>
......
......@@ -25,7 +25,7 @@ info = db.run[request.vars["id"]]
</tr>
<tr>
<td> <label for="run_info" id="run_info__label">Info: </label> </td>
<td> <textarea onfocus="new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" data-group-ids="[{{=group_id}}, 3]" class="text" cols="40" id="run_info" name="info" rows="10">{{=info.info}}</textarea> </td>
<td> <textarea onfocus="new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" data-group-ids="[{{=group_id}}]" class="text" cols="40" id="run_info" name="info" rows="10">{{=info.info}}</textarea> </td>
<td></td>
</tr>
<tr>
......
......@@ -17,7 +17,7 @@
</tr>
<tr>
<td><label for="sample_set_info" id="sample_set_info__label">Info: </label></td>
<td><textarea onfocus="$(this).data('group-ids', [$('#group_select option:selected').val(), 3]); new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" class="text" cols="40" id="sample_set_info" name="info" rows="10"></textarea></td>
<td><textarea onfocus="$(this).data('group-ids', [$('#group_select option:selected').val()]); new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" class="text" cols="40" id="sample_set_info" name="info" rows="10"></textarea></td>
<td></td>
</tr>
<tr>
......
......@@ -15,7 +15,7 @@ info = db.generic[request.vars["id"]]
</tr>
<tr>
<td> <label for="sample_set_info" id="sample_set_info__label">Info: </label> </td>
<td> <textarea onfocus="new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" data-group-ids="[{{=group_id}}, 3]" class="text" cols="40" id="sample_set_info" name="info" rows="10">{{=info.info}}</textarea> </td>
<td> <textarea onfocus="new VidjilAutoComplete().setupAtWho(this);" data-needs-atwho="true" data-group-ids="[{{=group_id}}]" class="text" cols="40" id="sample_set_info" name="info" rows="10">{{=info.info}}</textarea> </td>
<td></td>
</tr>
<tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment