mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Merge branch 'public-corpus' of gitlab.ub.uni-bielefeld.de:sfb1288inf/nopaque into public-corpus
This commit is contained in:
commit
dabf0d1344
@ -59,7 +59,6 @@ def create_corpus():
|
||||
@bp.route('/<hashid:corpus_id>', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def corpus(corpus_id):
|
||||
print(corpus_id)
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user
|
||||
or current_user.is_administrator()
|
||||
@ -89,7 +88,6 @@ def corpus(corpus_id):
|
||||
if corpus.user == current_user:
|
||||
return render_template(
|
||||
'corpora/corpus.html.j2',
|
||||
corpus_settings_form=corpus_settings_form,
|
||||
corpus=corpus,
|
||||
token=token,
|
||||
title='Corpus'
|
||||
@ -119,18 +117,26 @@ def share_corpus(token):
|
||||
corpus_id = hashids.decode(corpus_hashid)
|
||||
return redirect(url_for('.corpus', corpus_id=corpus_id))
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/enable_is_public', methods=['POST'])
|
||||
@login_required
|
||||
def enable_corpus_is_public(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
corpus.is_public = True
|
||||
db.session.commit()
|
||||
return '', 204
|
||||
|
||||
# @bp.route('/<hashid:corpus_id>/update')
|
||||
# @login_required
|
||||
# def update_corpus(corpus_id):
|
||||
# corpus = Corpus.query.get_or_404(corpus_id)
|
||||
# if not (corpus.user == current_user or current_user.is_administrator()):
|
||||
# abort(403)
|
||||
# return render_template(
|
||||
# 'corpora/update_corpus.html.j2',
|
||||
# corpus=corpus,
|
||||
# title='Corpus'
|
||||
# )
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/disable_is_public', methods=['POST'])
|
||||
@login_required
|
||||
def disable_corpus_is_public(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.user == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
corpus.is_public = False
|
||||
db.session.commit()
|
||||
return '', 204
|
||||
|
||||
|
||||
@bp.route('/<hashid:corpus_id>', methods=['DELETE'])
|
||||
|
@ -12,12 +12,23 @@ class CorpusDisplay extends RessourceDisplay {
|
||||
.addEventListener('click', (event) => {
|
||||
Utils.deleteCorpusRequest(this.userId, this.corpusId);
|
||||
});
|
||||
this.displayElement
|
||||
.querySelector('.action-switch[data-action="toggle-is-public"]')
|
||||
.addEventListener('click', (event) => {
|
||||
if (event.target.tagName !== 'INPUT') {return;}
|
||||
if (event.target.checked) {
|
||||
Utils.enableCorpusIsPublicRequest(this.userId, this.corpusId);
|
||||
} else {
|
||||
Utils.disableCorpusIsPublicRequest(this.userId, this.corpusId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
init(user) {
|
||||
let corpus = user.corpora[this.corpusId];
|
||||
this.setCreationDate(corpus.creation_date);
|
||||
this.setDescription(corpus.description);
|
||||
this.setIsPublic(corpus.is_public);
|
||||
this.setStatus(corpus.status);
|
||||
this.setTitle(corpus.title);
|
||||
this.setNumTokens(corpus.num_tokens);
|
||||
|
@ -69,6 +69,88 @@ class Utils {
|
||||
return Utils.mergeObjectsDeep(mergedObject, ...objects.slice(2));
|
||||
}
|
||||
|
||||
static enableCorpusIsPublicRequest(userId, corpusId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let corpus;
|
||||
try {
|
||||
corpus = app.data.users[userId].corpora[corpusId];
|
||||
} catch (error) {
|
||||
corpus = {};
|
||||
}
|
||||
|
||||
let modalElement = Utils.HTMLToElement(
|
||||
`
|
||||
<div class="modal">
|
||||
<div class="modal-content">
|
||||
<h4>Hier könnte eine Warnung stehen</h4>
|
||||
<p></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a class="action-button btn modal-close waves-effect waves-light" data-action="cancel">Cancel</a>
|
||||
<a class="action-button btn modal-close red waves-effect waves-light" data-action="confirm">Confirm</a>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
);
|
||||
document.querySelector('#modals').appendChild(modalElement);
|
||||
let modal = M.Modal.init(
|
||||
modalElement,
|
||||
{
|
||||
dismissible: false,
|
||||
onCloseEnd: () => {
|
||||
modal.destroy();
|
||||
modalElement.remove();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
let confirmElement = modalElement.querySelector('.action-button[data-action="confirm"]');
|
||||
confirmElement.addEventListener('click', (event) => {
|
||||
let corpusTitle = corpus?.title;
|
||||
fetch(`/corpora/${corpusId}/enable_is_public`, {method: 'POST', headers: {Accept: 'application/json'}})
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
|
||||
if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
|
||||
app.flash(`Corpus "${corpusTitle}" is public now`, 'corpus');
|
||||
resolve(response);
|
||||
},
|
||||
(response) => {
|
||||
app.flash('Something went wrong', 'error');
|
||||
reject(response);
|
||||
}
|
||||
);
|
||||
});
|
||||
modal.open();
|
||||
});
|
||||
}
|
||||
|
||||
static disableCorpusIsPublicRequest(userId, corpusId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let corpus;
|
||||
try {
|
||||
corpus = app.data.users[userId].corpora[corpusId];
|
||||
} catch (error) {
|
||||
corpus = {};
|
||||
}
|
||||
|
||||
let corpusTitle = corpus?.title;
|
||||
fetch(`/corpora/${corpusId}/disable_is_public`, {method: 'POST', headers: {Accept: 'application/json'}})
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
|
||||
if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
|
||||
app.flash(`Corpus "${corpusTitle}" is private now`, 'corpus');
|
||||
resolve(response);
|
||||
},
|
||||
(response) => {
|
||||
app.flash('Something went wrong', 'error');
|
||||
reject(response);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
static buildCorpusRequest(userId, corpusId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let corpus;
|
||||
|
@ -11,13 +11,6 @@
|
||||
<div class="row">
|
||||
<div class="col s8 m9 l10">
|
||||
<h1 id="title"><span class="corpus-title"></span></h1>
|
||||
{% if not corpus.user == current_user %}
|
||||
{% if current_user.is_following_corpus(corpus) %}
|
||||
<a class="btn waves-effect waves-light" id="follow-corpus-request"><i class="material-icons left">add</i>Unfollow Corpus</a>
|
||||
{% elif not current_user.is_following_corpus(corpus) %}
|
||||
<a class="btn waves-effect waves-light" id="follow-corpus-request"><i class="material-icons left">add</i>Follow Corpus</a>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col s4 m3 l2 right-align">
|
||||
<p> </p>
|
||||
@ -64,7 +57,18 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-action right-align">
|
||||
<div class="card-action">
|
||||
<div class="left-align">
|
||||
<div class="action-switch switch center-align" data-action="toggle-is-public">
|
||||
<span class="share"></span>
|
||||
<label>
|
||||
<input class="corpus-is-public" {% if corpus.is_public %}checked{% endif %} type="checkbox">
|
||||
<span class="lever"></span>
|
||||
public
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="right-align">
|
||||
<a class="btn corpus-analyse-trigger disabled waves-effect waves-light" href="{{ url_for('corpora.analyse_corpus', corpus_id=corpus.id) }}"><i class="material-icons left">search</i>Analyze</a>
|
||||
<a class="action-button btn disabled waves-effect waves-light" data-action="build-request"><i class="nopaque-icons left">K</i>Build</a>
|
||||
<a class="btn disabled export-corpus-trigger waves-effect waves-light" href="{{ url_for('corpora.export_corpus', corpus_id=corpus.id) }}"><i class="material-icons left">import_export</i>Export</a>
|
||||
@ -72,6 +76,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col s12">
|
||||
<div class="card">
|
||||
@ -95,6 +100,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="col s12">
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
|
@ -24,6 +24,6 @@ pyScss
|
||||
python-dotenv
|
||||
pyyaml
|
||||
redis
|
||||
SQLAlchemy==1.4.46
|
||||
SQLAlchemy==1.4.45
|
||||
tqdm
|
||||
wtforms[email]
|
||||
|
Loading…
Reference in New Issue
Block a user