Fix corpus follower on user page + optgroup models

This commit is contained in:
Inga Kirschnick 2023-05-31 16:10:05 +02:00
parent fab259522e
commit 367c2ce5e0
7 changed files with 53 additions and 13 deletions

View File

@ -71,7 +71,8 @@ def corpus(corpus_id):
users = users
)
if (current_user.is_following_corpus(corpus) or corpus.is_public):
cfas = CorpusFollowerAssociation.query.filter(Corpus.id == corpus_id, CorpusFollowerAssociation.follower_id != current_user.id, CorpusFollowerAssociation. follower_id != corpus.user.id).all()
cfas = CorpusFollowerAssociation.query.filter(Corpus.id == corpus_id, CorpusFollowerAssociation.follower_id != corpus.user.id).all()
print(cfas)
return render_template(
'corpora/public_corpus.html.j2',
title=corpus.title,

View File

@ -168,12 +168,18 @@ class CreateSpacyNLPPipelineJobForm(CreateJobBaseForm):
if 'methods' in service_info:
if 'encoding_detection' in service_info['methods']:
del self.encoding_detection.render_kw['disabled']
models = [
x for x in SpaCyNLPPipelineModel.query.order_by(SpaCyNLPPipelineModel.title).all()
if version in x.compatible_service_versions and (x.is_public == True or x.user == current_user)
user_models = [
x for x in current_user.spacy_nlp_pipeline_models.order_by(SpaCyNLPPipelineModel.title).all()
]
self.model.choices = [('', 'Choose your option')]
self.model.choices += [(x.hashid, f'{x.title} [{x.version}]') for x in models]
models = [
x for x in SpaCyNLPPipelineModel.query.filter(SpaCyNLPPipelineModel.user != current_user, SpaCyNLPPipelineModel.is_public == True).order_by(SpaCyNLPPipelineModel.title).all()
if version in x.compatible_service_versions
]
self.model.choices = {
'': [('', 'Choose your option')],
'Your models': [(x.hashid, f'{x.title} [{x.version}]') for x in user_models],
'Public models': [(x.hashid, f'{x.title} [{x.version}]') for x in models]
}
self.model.default = ''
self.version.choices = [(x, x) for x in service_manifest['versions']]
self.version.data = version

View File

@ -23,8 +23,9 @@ class CorpusFollowerList extends ResourceList {
});
app.getUser(this.userId).then((user) => {
let corpusFollowerAssociations = Object.values(user.corpora[this.corpusId].corpus_follower_associations);
let filteredList = corpusFollowerAssociations.filter(association => association.follower.id != currentUserId);
this.add(filteredList);
// let filteredList = corpusFollowerAssociations.filter(association => association.follower.id != currentUserId);
// this.add(filteredList);
this.add(Object.values(user.corpora[this.corpusId].corpus_follower_associations));
this.isInitialized = true;
});
}
@ -42,7 +43,7 @@ class CorpusFollowerList extends ResourceList {
</td>
<td>
<div class="input-field disable-on-click list-action-trigger" data-list-action="update-role">
<select>
<select ${values['user_id'] === currentUserId ? 'disabled' : ''}>
<option value="Viewer" ${values['role-name'] === 'Viewer' ? 'selected' : ''}>Viewer</option>
<option value="Contributor" ${values['role-name'] === 'Contributor' ? 'selected' : ''}>Contributor</option>
<option value="Administrator" ${values['role-name'] === 'Administrator' ? 'selected' : ''}>Administrator</option>

View File

@ -2,14 +2,37 @@ class PublicCorpusList extends CorpusList {
get item() {
return `
<tr class="list-item clickable hoverable">
<td><a class="btn-floating disabled"><i class="material-icons service-color darken" data-service="corpus-analysis">book</i></a></td>
<td><b class="title"></b><br><i class="description"></i></td>
<td><span class="owner"></span></td>
<td><span class="status badge new corpus-status-color corpus-status-text" data-badge-caption=""></span></td>
<td class="right-align">
<a class="list-action-trigger btn-floating service-color darken waves-effect waves-light" data-list-action="view" data-service="corpus-analysis"><i class="material-icons">send</i></a>
</td>
</tr>
`.trim();
}
initListContainerElement() {
if (!this.listContainerElement.hasAttribute('id')) {
this.listContainerElement.id = Utils.generateElementId('corpus-list-');
}
let listSearchElementId = Utils.generateElementId(`${this.listContainerElement.id}-search-`);
this.listContainerElement.innerHTML = `
<div class="input-field">
<i class="material-icons prefix">search</i>
<input id="${listSearchElementId}" class="search" type="text"></input>
<label for="${listSearchElementId}">Search Corpus</label>
</div>
<table>
<thead>
<tr>
<th>Title and Description</th>
<th>Owner</th>
<th></th>
</tr>
</thead>
<tbody class="list"></tbody>
</table>
<ul class="pagination"></ul>
`.trim();
}
}

View File

@ -85,7 +85,13 @@
for (let optionElement of document.querySelectorAll('option[value=""]')) {
optionElement.disabled = true;
}
for (let optgroupElement of document.querySelectorAll('optgroup[label=""]')) {
for (let c of optgroupElement.children) {
optgroupElement.parentElement.insertAdjacentElement('afterbegin', c);
}
optgroupElement.remove();
}
// Set the data-length attribute on textareas/inputs with the maxlength attribute
for (let inputElement of document.querySelectorAll('textarea[maxlength], input[maxlength]')) {
inputElement.dataset.length = inputElement.getAttribute('maxlength');

View File

@ -8,6 +8,9 @@
<div class="row">
<div class="col s12">
<h1>{{ corpus.title }}</h1>
{% for cfa in cfas %}
{{ cfa.follower.username|tojson }},
{% endfor %}
</div>
<div class="col s12 l7">
<div class="card service-color-border border-darken" data-service="corpus-analysis" style="border-top: 10px solid">

View File

@ -126,7 +126,7 @@ let followedCorpusList = new PublicCorpusList(document.querySelector('.followed-
followedCorpusList.add(
[
{% for corpus in user.followed_corpora %}
{% if (corpus.is_public or corpus.user == current_user) %}
{% if (corpus.is_public or corpus.user == current_user or user == current_user or current_user.is_following_corpus(corpus)) %}
{{ corpus.to_json_serializeable(backrefs=True)|tojson }},
{% endif %}
{% endfor %}