mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
New Public Corpus Page
This commit is contained in:
parent
5b6e889443
commit
f06508b412
@ -298,6 +298,7 @@ def follow_corpus(corpus_id):
|
||||
if not user.is_following_corpus(corpus):
|
||||
user.follow_corpus(corpus)
|
||||
db.session.commit()
|
||||
# flash('Hallo Inga Kirschnick')
|
||||
return {}, 202
|
||||
|
||||
@bp.route('/<hashid:corpus_id>/unfollow', methods=['GET', 'POST'])
|
||||
@ -336,8 +337,10 @@ def remove_permission(corpus_id, user_id, permission):
|
||||
@bp.route('/public/<hashid:corpus_id>')
|
||||
def public_corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
corpus_files = [cf.to_json_serializeable() for cf in CorpusFile.query.filter_by(corpus_id = corpus_id).all()]
|
||||
return render_template(
|
||||
'corpora/public_corpus.html.j2',
|
||||
corpus=corpus,
|
||||
corpus_files=corpus_files,
|
||||
title=corpus.title
|
||||
)
|
||||
|
15
app/static/js/ResourceLists/PublicCorpusFileList.js
Normal file
15
app/static/js/ResourceLists/PublicCorpusFileList.js
Normal file
@ -0,0 +1,15 @@
|
||||
class PublicCorpusFileList extends CorpusFileList {
|
||||
get item() {
|
||||
return `
|
||||
<tr class="list-item clickable hoverable">
|
||||
<td><span class="filename"></span></td>
|
||||
<td><span class="author"></span></td>
|
||||
<td><span class="title"></span></td>
|
||||
<td><span class="publishing-year"></span></td>
|
||||
<td class="right-align">
|
||||
<a class="list-action-trigger btn-floating service-color darken waves-effect waves-light" data-list-action="download" data-service="corpus-analysis"><i class="material-icons">file_download</i></a>
|
||||
</td>
|
||||
</tr>
|
||||
`.trim();
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
'js/RessourceDisplays/JobDisplay.js',
|
||||
'js/ResourceLists/ResourceList.js',
|
||||
'js/ResourceLists/CorpusFileList.js',
|
||||
'js/ResourceLists/PublicCorpusFileList.js',
|
||||
'js/ResourceLists/CorpusList.js',
|
||||
'js/ResourceLists/JobList.js',
|
||||
'js/ResourceLists/JobInputList.js',
|
||||
|
@ -10,8 +10,7 @@
|
||||
<div class="col s12" data-corpus-id="{{ corpus.hashid }}" data-user-id="{{ corpus.user.hashid }}" id="corpus-display">
|
||||
<div class="row">
|
||||
<div class="col s8 m9 l10">
|
||||
{# <h1 id="title"><span class="corpus-title"></span></h1> #}
|
||||
<h1 id="title">{{ corpus.title }}</h1>
|
||||
<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>
|
||||
|
@ -8,9 +8,27 @@
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<h1>{{ title }} </h1>
|
||||
<div class="row">
|
||||
<div class="col s8 m9 l10">
|
||||
{% if not corpus.user == current_user %}
|
||||
<a class="btn waves-effect waves-light" id="follow-corpus-request">
|
||||
{% if current_user.is_following_corpus(corpus) %}
|
||||
<i class="material-icons left">add</i>Unfollow Corpus
|
||||
{% else %}
|
||||
<i class="material-icons left">add</i>Follow Corpus
|
||||
{% endif %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<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>Status:</b> <span class="chip corpus-status-text corpus-status-color white-text" data-status="{{ corpus.status.name }}"></span></p>
|
||||
<p></p>
|
||||
<br>
|
||||
</div>
|
||||
<div class="col s12">
|
||||
<p><b>Description:</b> {{ corpus.description }}</p>
|
||||
<br>
|
||||
@ -25,6 +43,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-content">
|
||||
<span class="card-title" id="files">Corpus files</span>
|
||||
<div class="corpus-file-list no-autoinit" data-user-id="{{ corpus.user.hashid }}" data-corpus-id="{{ corpus.hashid }}"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -33,45 +58,42 @@
|
||||
{% block scripts %}
|
||||
{{ super() }}
|
||||
<script>
|
||||
let corpusFileList = new PublicCorpusFileList(document.querySelector('.corpus-file-list'));
|
||||
corpusFileList.add({{ corpus_files|tojson }});
|
||||
|
||||
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';
|
||||
corpusFollowingRequest.addEventListener('click', () => {
|
||||
if ({{ current_user.is_following_corpus(corpus)|tojson }}) {
|
||||
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');
|
||||
{# app.flash(`You are not following "{{ corpus.title }}" anymore`, 'corpus'); #}
|
||||
resolve(response);
|
||||
window.location.href = '{{ url_for("corpora.public_corpus", corpus_id=corpus.id) }}';
|
||||
},
|
||||
(response) => {
|
||||
app.flash('Something went wrong', 'error');
|
||||
reject(response);
|
||||
}
|
||||
);
|
||||
});
|
||||
} else {
|
||||
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);}
|
||||
{# app.flash(`You follow "{{ corpus.title }}" now`, 'corpus'); #}
|
||||
window.location.href = '{{ url_for("corpora.public_corpus", corpus_id=corpus.id) }}';
|
||||
resolve(response);
|
||||
window.location.href = '{{ url_for("corpora.corpus", corpus_id=corpus.id) }}'
|
||||
},
|
||||
(response) => {
|
||||
app.flash('Something went wrong', 'error');
|
||||
@ -79,7 +101,6 @@
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user