mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Small changes on the Corpus page
This commit is contained in:
parent
e2cdcd3f7c
commit
b0f61b28fe
@ -81,10 +81,18 @@ def corpus(corpus_id):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Your changes have been saved')
|
flash('Your changes have been saved')
|
||||||
return redirect(url_for('.corpus', corpus_id=corpus.id))
|
return redirect(url_for('.corpus', corpus_id=corpus.id))
|
||||||
|
# if corpus.following_users == [None]:
|
||||||
|
# following_users = []
|
||||||
|
# else:
|
||||||
|
# following_users = [
|
||||||
|
# u.to_json_serializeable() for u
|
||||||
|
# in corpus.following_users
|
||||||
|
# ]
|
||||||
return render_template(
|
return render_template(
|
||||||
'corpora/corpus.html.j2',
|
'corpora/corpus.html.j2',
|
||||||
corpus_settings_form=corpus_settings_form,
|
corpus_settings_form=corpus_settings_form,
|
||||||
corpus=corpus,
|
corpus=corpus,
|
||||||
|
# following_users=following_users,
|
||||||
title='Corpus'
|
title='Corpus'
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -277,10 +285,8 @@ def import_corpus():
|
|||||||
def export_corpus(corpus_id):
|
def export_corpus(corpus_id):
|
||||||
abort(503)
|
abort(503)
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>/follow')
|
@bp.route('/<hashid:corpus_id>/follow', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
# TODO: Wenn Query Paramter genutzt wird, prüfen, ob user_id ungleich current_user.id ist und dann gucken, ob es ein Admin ist.
|
|
||||||
# Sonst 403.
|
|
||||||
def follow_corpus(corpus_id):
|
def follow_corpus(corpus_id):
|
||||||
corpus = Corpus.query.get_or_404(corpus_id)
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
user_hashid = request.args.get('user_id')
|
user_hashid = request.args.get('user_id')
|
||||||
@ -297,7 +303,7 @@ def follow_corpus(corpus_id):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
return {}, 202
|
return {}, 202
|
||||||
|
|
||||||
@bp.route('/<hashid:corpus_id>/unfollow')
|
@bp.route('/<hashid:corpus_id>/unfollow', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def unfollow_corpus(corpus_id):
|
def unfollow_corpus(corpus_id):
|
||||||
corpus = Corpus.query.get_or_404(corpus_id)
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
|
@ -10,10 +10,15 @@
|
|||||||
<div class="col s12" data-corpus-id="{{ corpus.hashid }}" data-user-id="{{ corpus.user.hashid }}" id="corpus-display">
|
<div class="col s12" data-corpus-id="{{ corpus.hashid }}" data-user-id="{{ corpus.user.hashid }}" id="corpus-display">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s8 m9 l10">
|
<div class="col s8 m9 l10">
|
||||||
<h1 id="title"><span class="corpus-title"></span></h1>
|
{# <h1 id="title"><span class="corpus-title"></span></h1> #}
|
||||||
|
<h1 id="title">{{ corpus.title }}</h1>
|
||||||
{% if not corpus.user == current_user %}
|
{% 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>
|
<a class="btn waves-effect waves-light" id="follow-corpus-request"><i class="material-icons left">add</i>Follow Corpus</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col s4 m3 l2 right-align">
|
<div class="col s4 m3 l2 right-align">
|
||||||
<p> </p>
|
<p> </p>
|
||||||
@ -90,6 +95,7 @@
|
|||||||
<br>
|
<br>
|
||||||
<p></p>
|
<p></p>
|
||||||
{{ wtf.render_field(corpus_settings_form.is_public) }}
|
{{ wtf.render_field(corpus_settings_form.is_public) }}
|
||||||
|
<br>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-action right-align">
|
<div class="card-action right-align">
|
||||||
{{ wtf.render_field(corpus_settings_form.submit, material_icon='send') }}
|
{{ wtf.render_field(corpus_settings_form.submit, material_icon='send') }}
|
||||||
@ -98,6 +104,14 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<div class="col s12">
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-content">
|
||||||
|
<span class="card-title" id="files">Corpus followers</span>
|
||||||
|
<div class="user-list no-autoinit"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock page_content %}
|
{% endblock page_content %}
|
||||||
@ -106,17 +120,24 @@
|
|||||||
{{ super() }}
|
{{ super() }}
|
||||||
<script>
|
<script>
|
||||||
let corpusDisplay = new CorpusDisplay(document.querySelector('#corpus-display'));
|
let corpusDisplay = new CorpusDisplay(document.querySelector('#corpus-display'));
|
||||||
let followCorpusRequest = document.querySelector('#follow-corpus-request');
|
let corpusFollowingRequest = document.querySelector('#follow-corpus-request');
|
||||||
|
|
||||||
followCorpusRequest.addEventListener('click', function() {
|
{# let followingUserList = new UserList(document.querySelector('.user-list'));
|
||||||
|
followingUserList.add({{ following_users|tojson }}); #}
|
||||||
|
|
||||||
|
corpusFollowingRequest.addEventListener('click', function() {
|
||||||
|
corpusFollowingRequest.innerHTML = '<i class="material-icons left">add</i>Unfollow Corpus';
|
||||||
|
if ("{{ current_user.is_following_corpus(corpus) }}" === "False") {
|
||||||
|
corpusFollowingRequest.lastChild.textContent = 'Unfollow Corpus';
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fetch(`/corpora/${corpusId}/build`, {method: 'POST', headers: {Accept: 'application/json'}})
|
fetch(`/corpora/{{ corpus.hashid }}/follow`, {method: 'POST', headers: {Accept: 'application/json'}})
|
||||||
.then(
|
.then(
|
||||||
(response) => {
|
(response) => {
|
||||||
if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
|
if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
|
||||||
if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
|
if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
|
||||||
if (response.status === 409) {app.flash('Conflict', 'error'); reject(response);}
|
if (response.status === 409) {app.flash('Conflict', 'error'); reject(response);}
|
||||||
app.flash(`Corpus "${corpus?.title}" marked for building`, 'corpus');
|
app.flash(`You follow "{{ corpus.title }}" now`, 'corpus');
|
||||||
|
window.location.href = '{{ url_for("corpora.corpus", corpus_id=corpus.id) }}'
|
||||||
resolve(response);
|
resolve(response);
|
||||||
},
|
},
|
||||||
(response) => {
|
(response) => {
|
||||||
@ -125,6 +146,30 @@
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
corpusFollowingRequest.innerHTML = '<i class="material-icons left">add</i>Unfollow Corpus';
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
fetch(`/corpora/{{ corpus.hashid }}/unfollow`, {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);}
|
||||||
|
if (response.status === 409) {app.flash('Conflict', 'error'); reject(response);}
|
||||||
|
app.flash(`You are not following "{{ corpus.title }}" anymore`, 'corpus');
|
||||||
|
resolve(response);
|
||||||
|
window.location.href = '{{ url_for("corpora.corpus", corpus_id=corpus.id) }}'
|
||||||
|
},
|
||||||
|
(response) => {
|
||||||
|
app.flash('Something went wrong', 'error');
|
||||||
|
reject(response);
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock scripts %}
|
{% endblock scripts %}
|
||||||
|
Loading…
Reference in New Issue
Block a user