diff --git a/app/corpora/json_routes.py b/app/corpora/json_routes.py index 6a3b5f29..4fd3a042 100644 --- a/app/corpora/json_routes.py +++ b/app/corpora/json_routes.py @@ -71,55 +71,55 @@ def get_stopwords(): response_data = stopwords return response_data, 202 -# @bp.route('//generate-share-link', methods=['POST']) -# @corpus_follower_permission_required('MANAGE_FOLLOWERS') -# @content_negotiation(consumes='application/json', produces='application/json') -# def generate_corpus_share_link(corpus_id): -# data = request.json -# if not isinstance(data, dict): -# abort(400) -# expiration = data.get('expiration') -# if not isinstance(expiration, str): -# abort(400) -# role_name = data.get('role') -# if not isinstance(role_name, str): -# abort(400) -# expiration_date = datetime.strptime(expiration, '%b %d, %Y') -# cfr = CorpusFollowerRole.query.filter_by(name=role_name).first() -# if cfr is None: -# abort(400) -# corpus = Corpus.query.get_or_404(corpus_id) -# token = current_user.generate_follow_corpus_token(corpus.hashid, role_name, expiration_date) -# corpus_share_link = url_for( -# 'corpora.follow_corpus', -# corpus_id=corpus_id, -# token=token, -# _external=True -# ) -# response_data = { -# 'message': 'Corpus share link generated', -# 'category': 'corpus', -# 'corpusShareLink': corpus_share_link -# } -# return response_data, 200 +@bp.route('//generate-share-link', methods=['POST']) +@corpus_follower_permission_required('MANAGE_FOLLOWERS') +@content_negotiation(consumes='application/json', produces='application/json') +def generate_corpus_share_link(corpus_id): + data = request.json + if not isinstance(data, dict): + abort(400) + expiration = data.get('expiration') + if not isinstance(expiration, str): + abort(400) + role_name = data.get('role') + if not isinstance(role_name, str): + abort(400) + expiration_date = datetime.strptime(expiration, '%b %d, %Y') + cfr = CorpusFollowerRole.query.filter_by(name=role_name).first() + if cfr is None: + abort(400) + corpus = Corpus.query.get_or_404(corpus_id) + token = current_user.generate_follow_corpus_token(corpus.hashid, role_name, expiration_date) + corpus_share_link = url_for( + 'corpora.follow_corpus', + corpus_id=corpus_id, + token=token, + _external=True + ) + response_data = { + 'message': 'Corpus share link generated', + 'category': 'corpus', + 'corpusShareLink': corpus_share_link + } + return response_data, 200 -# @bp.route('//is_public', methods=['PUT']) -# @corpus_owner_or_admin_required -# @content_negotiation(consumes='application/json', produces='application/json') -# def update_corpus_is_public(corpus_id): -# is_public = request.json -# if not isinstance(is_public, bool): -# abort(400) -# corpus = Corpus.query.get_or_404(corpus_id) -# corpus.is_public = is_public -# db.session.commit() -# response_data = { -# 'message': ( -# f'Corpus "{corpus.title}" is now' -# f' {"public" if is_public else "private"}' -# ), -# 'category': 'corpus' -# } -# return response_data, 200 +@bp.route('//is_public', methods=['PUT']) +@corpus_owner_or_admin_required +@content_negotiation(consumes='application/json', produces='application/json') +def update_corpus_is_public(corpus_id): + is_public = request.json + if not isinstance(is_public, bool): + abort(400) + corpus = Corpus.query.get_or_404(corpus_id) + corpus.is_public = is_public + db.session.commit() + response_data = { + 'message': ( + f'Corpus "{corpus.title}" is now' + f' {"public" if is_public else "private"}' + ), + 'category': 'corpus' + } + return response_data, 200 diff --git a/app/corpora/routes.py b/app/corpora/routes.py index b1b9142d..2db52331 100644 --- a/app/corpora/routes.py +++ b/app/corpora/routes.py @@ -68,20 +68,19 @@ def corpus(corpus_id): corpus=corpus, cfr=cfr, cfrs=cfrs, - users = users + users=users ) if (current_user.is_following_corpus(corpus) or corpus.is_public): - abort(404) - # cfas = CorpusFollowerAssociation.query.filter(Corpus.id == corpus_id, CorpusFollowerAssociation.follower_id != corpus.user.id).all() - # return render_template( - # 'corpora/public_corpus.html.j2', - # title=corpus.title, - # corpus=corpus, - # cfrs=cfrs, - # cfr=cfr, - # cfas=cfas, - # users = users - # ) + cfas = CorpusFollowerAssociation.query.filter(Corpus.id == corpus_id, CorpusFollowerAssociation.follower_id != corpus.user.id).all() + return render_template( + 'corpora/public_corpus.html.j2', + title=corpus.title, + corpus=corpus, + cfrs=cfrs, + cfr=cfr, + cfas=cfas, + users=users + ) abort(403) diff --git a/app/main/routes.py b/app/main/routes.py index 080616ec..faf579b0 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -82,7 +82,9 @@ def terms_of_use(): @register_breadcrumb(bp, '.social_area', 'groupSocial Area') @login_required def social_area(): + print('test') corpora = Corpus.query.filter(Corpus.is_public == True, Corpus.user != current_user).all() + print(corpora) users = User.query.filter(User.is_public == True, User.id != current_user.id).all() return render_template( 'main/social_area.html.j2', diff --git a/app/models.py b/app/models.py index 8121f7a9..91477f92 100644 --- a/app/models.py +++ b/app/models.py @@ -853,7 +853,7 @@ class User(HashidMixin, UserMixin, db.Model): json_serializeable = { 'id': self.hashid, 'confirmed': self.confirmed, - # 'avatar': url_for('users.user_avatar', user_id=self.id), + 'avatar': url_for('users.user_avatar', user_id=self.id), 'email': self.email, 'last_seen': ( None if self.last_seen is None diff --git a/app/static/js/resource-lists/corpus-follower-list.js b/app/static/js/resource-lists/corpus-follower-list.js index b8a4c255..d5636467 100644 --- a/app/static/js/resource-lists/corpus-follower-list.js +++ b/app/static/js/resource-lists/corpus-follower-list.js @@ -18,7 +18,7 @@ ResourceLists.CorpusFollowerList = class CorpusFollowerList extends ResourceList }); }); app.getUser(this.userId).then((user) => { - let corpusFollowerAssociations = Object.values(user.corpora[this.corpusId].corpus_follower_associations); + // let corpusFollowerAssociations = Object.values(user.corpora[this.corpusId].corpus_follower_associations); // let filteredList = corpusFollowerAssociations.filter(association => association.follower.id != currentUserId); // this.add(filteredList); this.add(Object.values(user.corpora[this.corpusId].corpus_follower_associations)); diff --git a/app/static/js/resource-lists/public-corpus-list.js b/app/static/js/resource-lists/public-corpus-list.js index 659dfd09..71eb4fbd 100644 --- a/app/static/js/resource-lists/public-corpus-list.js +++ b/app/static/js/resource-lists/public-corpus-list.js @@ -1,6 +1,11 @@ ResourceLists.PublicCorpusList = class PublicCorpusList extends ResourceLists.ResourceList { static htmlClass = 'public-corpus-list'; + constructor(listContainerElement, options = {}) { + super(listContainerElement, options); + this.listjs.list.addEventListener('click', (event) => {this.onClick(event)}); + } + get item() { return (values) => { return ` @@ -16,6 +21,19 @@ ResourceLists.PublicCorpusList = class PublicCorpusList extends ResourceLists.Re }; } + get valueNames() { + return [ + {data: ['id']}, + {data: ['creation-date']}, + {name: 'status', attr: 'data-status'}, + 'description', + 'title', + 'owner', + 'is-owner', + 'current-user-is-following' + ]; + } + mapResourceToValue(corpus) { return { 'id': corpus.id, @@ -54,4 +72,21 @@ ResourceLists.PublicCorpusList = class PublicCorpusList extends ResourceLists.Re
    `.trim(); } + + onClick(event) { + let listItemElement = event.target.closest('.list-item[data-id]'); + if (listItemElement === null) {return;} + let itemId = listItemElement.dataset.id; + let listActionElement = event.target.closest('.list-action-trigger[data-list-action]'); + let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction; + switch (listAction) { + case 'view': { + window.location.href = `/corpora/${itemId}`; + break; + } + default: { + break; + } + } + } }; diff --git a/app/static/js/resource-lists/user-list.js b/app/static/js/resource-lists/public-user-list.js similarity index 95% rename from app/static/js/resource-lists/user-list.js rename to app/static/js/resource-lists/public-user-list.js index 6ef14e2f..cc56604a 100644 --- a/app/static/js/resource-lists/user-list.js +++ b/app/static/js/resource-lists/public-user-list.js @@ -1,5 +1,5 @@ -ResourceLists.UserList = class UserList extends ResourceLists.ResourceList { - static htmlClass = 'user-list'; +ResourceLists.PublicUserList = class PublicUserList extends ResourceLists.ResourceList { + static htmlClass = 'public-user-list'; constructor(listContainerElement, options = {}) { super(listContainerElement, options); diff --git a/app/templates/_scripts.html.j2 b/app/templates/_scripts.html.j2 index 78b7af60..a1897b56 100644 --- a/app/templates/_scripts.html.j2 +++ b/app/templates/_scripts.html.j2 @@ -80,9 +80,9 @@ 'js/resource-lists/job-list.js', 'js/resource-lists/job-result-list.js', 'js/resource-lists/public-corpus-list.js', + 'js/resource-lists/public-user-list.js', 'js/resource-lists/spacy-nlp-pipeline-model-list.js', - 'js/resource-lists/tesseract-ocr-pipeline-model-list.js', - 'js/resource-lists/user-list.js' + 'js/resource-lists/tesseract-ocr-pipeline-model-list.js' %} {%- endassets %} diff --git a/app/templates/admin/user_settings.html.j2 b/app/templates/admin/user_settings.html.j2 index be2268ea..fb022564 100644 --- a/app/templates/admin/user_settings.html.j2 +++ b/app/templates/admin/user_settings.html.j2 @@ -57,7 +57,7 @@ let userConfirmedSwitchElement = document.querySelector('#user-confirmed-switch'); userConfirmedSwitchElement.addEventListener('change', (event) => { let newConfirmed = userConfirmedSwitchElement.checked; - requests.admin.users.entity.confirmed.update({{ user.hashid|tojson }}, newConfirmed) + Requests.admin.users.entity.confirmed.update({{ user.hashid|tojson }}, newConfirmed) .catch((response) => { userConfirmedSwitchElement.checked = !userConfirmedSwitchElement; }); diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2 index e31ed50c..0a00fbee 100644 --- a/app/templates/corpora/corpus.html.j2 +++ b/app/templates/corpora/corpus.html.j2 @@ -240,7 +240,7 @@ {% if current_user.is_following_corpus(corpus) %} let unfollowRequestElement = document.querySelector('.action-button[data-action="unfollow-request"]'); unfollowRequestElement.addEventListener('click', () => { - requests.corpora.entity.followers.entity.delete({{ corpus.hashid|tojson }}, {{ current_user.hashid|tojson }}) + Requests.corpora.entity.followers.entity.delete({{ corpus.hashid|tojson }}, {{ current_user.hashid|tojson }}) .then((response) => { window.location.reload(); }); @@ -252,7 +252,7 @@ let publishingModalIsPublicSwitchElement = document.querySelector('#publishing-modal-is-public-switch'); publishingModalIsPublicSwitchElement.addEventListener('change', (event) => { let newIsPublic = publishingModalIsPublicSwitchElement.checked; - requests.corpora.entity.isPublic.update({{ corpus.hashid|tojson }}, newIsPublic) + Requests.corpora.entity.isPublic.update({{ corpus.hashid|tojson }}, newIsPublic) .catch((response) => { publishingModalIsPublicSwitchElement.checked = !newIsPublic; }); @@ -262,7 +262,7 @@ publishingModalIsPublicSwitchElement.addEventListener('change', (event) => { // #region Delete let deleteModalDeleteButtonElement = document.querySelector('#delete-modal-delete-button'); deleteModalDeleteButtonElement.addEventListener('click', (event) => { - requests.corpora.entity.delete({{ corpus.hashid|tojson }}) + Requests.corpora.entity.delete({{ corpus.hashid|tojson }}) .then((response) => { window.location.href = {{ url_for('main.dashboard')|tojson }}; }); @@ -281,6 +281,7 @@ let users = { {% if not loop.last %},{% endif %} {% endfor %} }; +console.log(users); let inviteUserModalSearch = M.Chips.init( inviteUserModalSearchElement, @@ -312,7 +313,7 @@ M.Modal.init( inviteUserModalInviteButtonElement.addEventListener('click', (event) => { let usernames = inviteUserModalSearch.chipsData.map((chipData) => chipData.tag); - requests.corpora.entity.followers.add({{ corpus.hashid|tojson }}, usernames); + Requests.corpora.entity.followers.add({{ corpus.hashid|tojson }}, usernames); }); // #endregion Invite user @@ -357,7 +358,7 @@ M.Modal.init( shareLinkModalCreateButtonElement.addEventListener('click', (event) => { let role = shareLinkModalCorpusFollowerRoleSelectElement.value; let expiration = shareLinkModalExpirationDateDatepickerElement.value - requests.corpora.entity.generateShareLink({{ corpus.hashid|tojson }}, role, expiration) + Requests.corpora.entity.generateShareLink({{ corpus.hashid|tojson }}, role, expiration) .then((response) => { response.json() .then((json) => { diff --git a/app/templates/main/social_area.html.j2 b/app/templates/main/social_area.html.j2 index 79b67161..872365cc 100644 --- a/app/templates/main/social_area.html.j2 +++ b/app/templates/main/social_area.html.j2 @@ -40,7 +40,7 @@

    Find other users and see what corpora they have made public.

    -
    +
    @@ -51,7 +51,7 @@
    Public Corpora -
    +
    @@ -62,15 +62,18 @@ {% block scripts %} {{ super() }}