mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
New public corpus route
This commit is contained in:
parent
96520fa46f
commit
5b6e889443
@ -332,3 +332,12 @@ def remove_permission(corpus_id, user_id, permission):
|
|||||||
a.remove_permission(permission)
|
a.remove_permission(permission)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return 'ok'
|
return 'ok'
|
||||||
|
|
||||||
|
@bp.route('/public/<hashid:corpus_id>')
|
||||||
|
def public_corpus(corpus_id):
|
||||||
|
corpus = Corpus.query.get_or_404(corpus_id)
|
||||||
|
return render_template(
|
||||||
|
'corpora/public_corpus.html.j2',
|
||||||
|
corpus=corpus,
|
||||||
|
title=corpus.title
|
||||||
|
)
|
||||||
|
@ -120,56 +120,5 @@
|
|||||||
{{ super() }}
|
{{ super() }}
|
||||||
<script>
|
<script>
|
||||||
let corpusDisplay = new CorpusDisplay(document.querySelector('#corpus-display'));
|
let corpusDisplay = new CorpusDisplay(document.querySelector('#corpus-display'));
|
||||||
let corpusFollowingRequest = document.querySelector('#follow-corpus-request');
|
|
||||||
|
|
||||||
{# 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) => {
|
|
||||||
fetch(`/corpora/{{ corpus.hashid }}/follow`, {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 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 %}
|
||||||
|
86
app/templates/corpora/public_corpus.html.j2
Normal file
86
app/templates/corpora/public_corpus.html.j2
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
{% extends "base.html.j2" %}
|
||||||
|
{% import "materialize/wtf.html.j2" as wtf %}
|
||||||
|
|
||||||
|
{% block main_attribs %} class="service-scheme" data-service="corpus-analysis"{% endblock main_attribs %}
|
||||||
|
|
||||||
|
{% block page_content %}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col s12">
|
||||||
|
<h1>{{ title }} </h1>
|
||||||
|
<div class="card service-color-border border-darken" data-service="corpus-analysis" style="border-top: 10px solid">
|
||||||
|
<div class="card-content">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col s12">
|
||||||
|
<p><b>Description:</b> {{ corpus.description }}</p>
|
||||||
|
<br>
|
||||||
|
<p></p>
|
||||||
|
</div>
|
||||||
|
<div class="col s6">
|
||||||
|
<p><b>Creation date:</b> {{ corpus.creation_date }}</p>
|
||||||
|
</div>
|
||||||
|
<div class="col s6">
|
||||||
|
<p><b>Number of tokens used:</b> {{ corpus.num_tokens }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock page_content %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
{{ super() }}
|
||||||
|
<script>
|
||||||
|
let corpusFollowingRequest = document.querySelector('#follow-corpus-request');
|
||||||
|
|
||||||
|
{# 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) => {
|
||||||
|
fetch(`/corpora/{{ corpus.hashid }}/follow`, {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 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>
|
||||||
|
{% endblock scripts %}
|
Loading…
Reference in New Issue
Block a user