Skip to content
Snippets Groups Projects
Commit b0f61b28 authored by Inga Kirschnick's avatar Inga Kirschnick
Browse files

Small changes on the Corpus page

parent e2cdcd3f
No related branches found
No related tags found
No related merge requests found
...@@ -81,10 +81,18 @@ def corpus(corpus_id): ...@@ -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(): ...@@ -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): ...@@ -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 @@ ...@@ -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>&nbsp;</p> <p>&nbsp;</p>
...@@ -90,6 +95,7 @@ ...@@ -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 @@ ...@@ -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,25 +120,56 @@ ...@@ -106,25 +120,56 @@
{{ 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'));
return new Promise((resolve, reject) => { followingUserList.add({{ following_users|tojson }}); #}
fetch(`/corpora/${corpusId}/build`, {method: 'POST', headers: {Accept: 'application/json'}})
.then( corpusFollowingRequest.addEventListener('click', function() {
(response) => { corpusFollowingRequest.innerHTML = '<i class="material-icons left">add</i>Unfollow Corpus';
if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);} if ("{{ current_user.is_following_corpus(corpus) }}" === "False") {
if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);} corpusFollowingRequest.lastChild.textContent = 'Unfollow Corpus';
if (response.status === 409) {app.flash('Conflict', 'error'); reject(response);} return new Promise((resolve, reject) => {
app.flash(`Corpus "${corpus?.title}" marked for building`, 'corpus'); fetch(`/corpora/{{ corpus.hashid }}/follow`, {method: 'POST', headers: {Accept: 'application/json'}})
resolve(response); .then(
}, (response) => {
(response) => { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
app.flash('Something went wrong', 'error'); if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
reject(response); if (response.status === 409) {app.flash('Conflict', 'error'); reject(response);}
} app.flash(`You follow "{{ corpus.title }}" now`, 'corpus');
); window.location.href = '{{ url_for("corpora.corpus", corpus_id=corpus.id) }}'
}); resolve(response);
},
(response) => {
app.flash('Something went wrong', 'error');
reject(response);
}
);
});
} 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 %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment