diff --git a/app/corpora/routes.py b/app/corpora/routes.py index ffdb375c..1a05722e 100644 --- a/app/corpora/routes.py +++ b/app/corpora/routes.py @@ -54,7 +54,7 @@ def create_corpus(): def corpus(corpus_id): corpus = Corpus.query.get_or_404(corpus_id) corpus_follower_roles = CorpusFollowerRole.query.all() - users = [u.to_json_serializeable() for u in User.query.filter(User.is_public == True, User.id != current_user.id).all()] + users = User.query.filter(User.is_public == True, User.id != current_user.id).all() # TODO: Add URL query option to toggle view if corpus.user == current_user or current_user.is_administrator(): return render_template( @@ -66,14 +66,10 @@ def corpus(corpus_id): ) if current_user.is_following_corpus(corpus) or corpus.is_public: cfa = CorpusFollowerAssociation.query.filter_by(corpus_id=corpus_id, follower_id=current_user.id).first_or_404() - corpus_files = [x.to_json_serializeable() for x in corpus.files] - owner = corpus.user.to_json_serializeable() return render_template( 'corpora/public_corpus.html.j2', corpus=corpus, - corpus_files=corpus_files, cfa=cfa, - owner=owner, title=corpus.title ) abort(403) diff --git a/app/main/routes.py b/app/main/routes.py index 5a23858b..edca61d5 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -61,14 +61,16 @@ def terms_of_use(): @bp.route('/social-area') @register_breadcrumb(bp, '.social_area', 'groupSocial Area') def social_area(): - users = [ - u.to_json_serializeable(relationships=True, filter_by_privacy_settings=True,) for u - in User.query.filter(User.is_public == True, User.id != current_user.id).all() - ] - corpora = [ - c.to_json_serializeable() for c - in Corpus.query.filter(Corpus.is_public == True, Corpus.user != current_user).all() - ] + # corpora = [ + # c.to_json_serializeable() for c + # in Corpus.query.filter(Corpus.is_public == True, Corpus.user != current_user).all() + # ] + corpora = Corpus.query.filter(Corpus.is_public == True, Corpus.user != current_user).all() + # users = [ + # u.to_json_serializeable(relationships=True, filter_by_privacy_settings=True,) for u + # in User.query.filter(User.is_public == True, User.id != current_user.id).all() + # ] + users = User.query.filter(User.is_public == True, User.id != current_user.id).all() return render_template( 'main/social_area.html.j2', users=users, diff --git a/app/templates/admin/corpora.html.j2 b/app/templates/admin/corpora.html.j2 index cc4a177c..e3f89d98 100644 --- a/app/templates/admin/corpora.html.j2 +++ b/app/templates/admin/corpora.html.j2 @@ -21,8 +21,7 @@ corpusList.add( [ {% for corpus in corpora %} - {{ corpus.to_json_serializeable(backrefs=True)|tojson }} - {% if not loop.last %},{% endif %} + {{ corpus.to_json_serializeable(backrefs=True)|tojson }}, {% endfor %} ] ); diff --git a/app/templates/admin/users.html.j2 b/app/templates/admin/users.html.j2 index a71c8f59..2ccd8ee9 100644 --- a/app/templates/admin/users.html.j2 +++ b/app/templates/admin/users.html.j2 @@ -26,8 +26,7 @@ adminUserList.add( [ {% for user in users %} - {{ user.to_json_serializeable(backrefs=True)|tojson }} - {% if not loop.last %},{% endif %} + {{ user.to_json_serializeable(backrefs=True)|tojson }}, {% endfor %} ] ); diff --git a/app/templates/corpora/corpus.html.j2 b/app/templates/corpora/corpus.html.j2 index ce954697..a064190f 100644 --- a/app/templates/corpora/corpus.html.j2 +++ b/app/templates/corpora/corpus.html.j2 @@ -216,3 +216,137 @@ {% endblock modals %} + +{% block scripts %} +{{ super() }} + +{% endblock scripts %} diff --git a/app/templates/corpora/corpus.js.j2 b/app/templates/corpora/corpus.js.j2 deleted file mode 100644 index 016b0b6a..00000000 --- a/app/templates/corpora/corpus.js.j2 +++ /dev/null @@ -1,128 +0,0 @@ -let corpusId = {{ corpus.hashid|tojson }}; -let corpusDisplay = new CorpusDisplay(document.querySelector('#corpus-display')); - -// #region Publishing -let publishingModalIsPublicSwitchElement = document.querySelector('#publishing-modal-is-public-switch'); -publishingModalIsPublicSwitchElement.addEventListener('change', (event) => { - let newIsPublic = publishingModalIsPublicSwitchElement.checked; - Requests.corpora.entity.isPublic.update(corpusId, newIsPublic) - .catch((response) => { - publishingModalIsPublicSwitchElement.checked = !newIsPublic; - }); -}); -// #endregion Publishing - -// #region Delete -let deleteModalDeleteButtonElement = document.querySelector('#delete-modal-delete-button'); -deleteModalDeleteButtonElement.addEventListener('click', (event) => { - Requests.corpora.entity.delete(corpusId) - .then((response) => { - window.location.href = {{ url_for('main.dashboard')|tojson }}; - }); -}); -// #endregion Delete - -// #region Invite users -let inviteUserModalElement = document.querySelector('#invite-user-modal'); -let inviteUserModalSearchElement = document.querySelector('#invite-user-modal-search'); -let inviteUserModalInviteButtonElement = document.querySelector('#invite-user-modal-invite-button'); -const users = {}; - -for (let user of {{ users|tojson }}) { - users[user.username] = user.avatar ? `/users/${user.id}/avatar` : '/static/images/user_avatar.png'; -} - -let inviteUserModalSearch = M.Chips.init( - inviteUserModalSearchElement, - { - autocompleteOptions: { - data: users - }, - limit: 3, - onChipAdd: (a, chipElement) => { - if (!(chipElement.firstChild.data in inviteUserModalSearch.autocomplete.options.data)) { - chipElement.firstElementChild.click(); - } - }, - placeholder: 'Enter username', - secondaryPlaceholder: 'Add more users' - } -); - -M.Modal.init( - inviteUserModalElement, - { - onOpenStart: (modalElement, modalTriggerElement) => { - while (inviteUserModalSearch.chipsData.length > 0) { - inviteUserModalSearch.deleteChip(0); - } - } - } -) - -inviteUserModalInviteButtonElement.addEventListener('click', (event) => { - let usernames = inviteUserModalSearch.chipsData.map((chipData) => chipData.tag); - Requests.corpora.entity.followers.add(corpusId, usernames); -}); -// #endregion Invite users - -// #region Share link -let shareLinkModalElement = document.querySelector('#share-link-modal'); -let shareLinkModalCorpusFollowerRoleSelectElement = document.querySelector('#share-link-modal-corpus-follower-role-select'); -let shareLinkModalExpirationDateDatepickerElement = document.querySelector('#share-link-modal-expiration-date-datepicker'); -let shareLinkModalCreateButtonElement = document.querySelector('#share-link-modal-create-button'); -let shareLinkModalOutputContainerElement = document.querySelector('#share-link-modal-output-container'); -let shareLinkModalOutputFieldElement = document.querySelector('#share-link-modal-output-field'); -let shareLinkModalOutputCopyButtonElement = document.querySelector('#share-link-modal-output-copy-button'); - -let today = new Date(); -let tomorrow = new Date(); -tomorrow.setDate(today.getDate() + 1); -let oneWeekLater = new Date(); -oneWeekLater.setDate(today.getDate() + 7); -let fourWeeksLater = new Date(); -fourWeeksLater.setDate(today.getDate() + 28); - -M.Datepicker.init( - shareLinkModalExpirationDateDatepickerElement, - { - container: document.querySelector('main'), - defaultDate: oneWeekLater, - setDefaultDate: true, - minDate: tomorrow, - maxDate: fourWeeksLater - } -); - -M.Modal.init( - shareLinkModalElement, - { - onOpenStart: (modalElement, modalTriggerElement) => { - shareLinkModalOutputFieldElement.value = ''; - shareLinkModalOutputContainerElement.classList.add('hide'); - } - } -) - -shareLinkModalCreateButtonElement.addEventListener('click', (event) => { - let role = shareLinkModalCorpusFollowerRoleSelectElement.value; - let expiration = shareLinkModalExpirationDateDatepickerElement.value - Requests.corpora.entity.generateShareLink(corpusId, role, expiration) - .then((response) => { - response.json() - .then((json) => { - shareLinkModalOutputContainerElement.classList.remove('hide'); - shareLinkModalOutputFieldElement.value = json.corpusShareLink; - }); - }); -}); - -shareLinkModalOutputCopyButtonElement.addEventListener('click', (event) => { - navigator.clipboard.writeText(shareLinkModalOutputFieldElement.value) - .then( - () => {app.flash('Copied!');}, - () => {app.flash('Could not copy to clipboard. Please copy manually.', 'error');} - ); - -}); -// #endregion Share link diff --git a/app/templates/corpora/public_corpus.html.j2 b/app/templates/corpora/public_corpus.html.j2 index 77e3ea4b..531b3cea 100644 --- a/app/templates/corpora/public_corpus.html.j2 +++ b/app/templates/corpora/public_corpus.html.j2 @@ -53,12 +53,12 @@