diff --git a/app/main/routes.py b/app/main/routes.py index 56c37116806e05d76d4804fb7cd505458292ebdc..080616ec8157d1093e4081bc525f16e594d25212 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -39,10 +39,8 @@ def faq(): @register_breadcrumb(bp, '.dashboard', '<i class="material-icons left">dashboard</i>Dashboard') @login_required def dashboard(): - corpora = Corpus.query.filter(or_(Corpus.followers.any(id=current_user.id), Corpus.user == current_user)).all() return render_template( 'main/dashboard.html.j2', - corpora=corpora, title='Dashboard' ) diff --git a/app/models.py b/app/models.py index b3294b000314a621cb66f6cbb00fe41703b9f6bb..5b8a469458bcee4f359834d689b7f0a6c59335bf 100644 --- a/app/models.py +++ b/app/models.py @@ -493,7 +493,7 @@ class CorpusFollowerAssociation(HashidMixin, db.Model): def to_json_serializeable(self, backrefs=False, relationships=False): json_serializeable = { 'id': self.hashid, - 'corpus': self.corpus.to_json_serializeable(), + 'corpus': self.corpus.to_json_serializeable(backrefs=True), 'follower': self.follower.to_json_serializeable(), 'role': self.role.to_json_serializeable() } diff --git a/app/static/js/ResourceLists/CorpusList.js b/app/static/js/ResourceLists/CorpusList.js index 0a8905c51a779a16335cd4b6e74db65261f2db2c..c4caa399361937135cc5a9e15eaae5a1e1baa599 100644 --- a/app/static/js/ResourceLists/CorpusList.js +++ b/app/static/js/ResourceLists/CorpusList.js @@ -20,6 +20,43 @@ class CorpusList extends ResourceList { if (this.isInitialized) {this.onPatch(patch);} }); }); + app.getUser(this.userId).then((user) => { + this.add(this.equalizer(user)); + this.isInitialized = true; + }); + } + + equalizer(user) { + const equalizedData = []; + for (let corpus of Object.values(user.corpora)) { + equalizedData.push( + { + 'id': corpus.id, + 'creation-date': corpus.creation_date, + 'description': corpus.description, + 'status': corpus.status, + 'title': corpus.title, + 'owner': user.username, + 'is-owner': true, + 'current-user-is-following': false + } + ); + } + for (let cfa of Object.values(user.corpus_follower_associations)) { + equalizedData.push( + { + 'id': cfa.corpus.id, + 'creation-date': cfa.corpus.creation_date, + 'description': cfa.corpus.description, + 'status': cfa.corpus.status, + 'title': cfa.corpus.title, + 'owner': cfa.corpus.user.username, + 'is-owner': false, + 'current-user-is-following': true + } + ); + } + return equalizedData; } // #region Mandatory getters and methods to implement @@ -93,17 +130,8 @@ class CorpusList extends ResourceList { `.trim(); } - mapResourceToValue(corpus) { - return { - 'id': corpus.id, - 'creation-date': corpus.creation_date, - 'description': corpus.description, - 'status': corpus.status, - 'title': corpus.title, - 'owner': corpus.user.username, - 'is-owner': corpus.user.id === this.userId ? true : false, - 'current-user-is-following': Object.values(corpus.corpus_follower_associations).some(association => association.follower.id === currentUserId) - }; + mapResourceToValue(equalizedData) { + return equalizedData; } sort() { diff --git a/app/static/js/ResourceLists/PublicCorpusList.js b/app/static/js/ResourceLists/PublicCorpusList.js index ce2c9cbd5f151ca7f9716e3c2030e7518467df50..1ef98273dd1f185f3408d82679cd706d759043db 100644 --- a/app/static/js/ResourceLists/PublicCorpusList.js +++ b/app/static/js/ResourceLists/PublicCorpusList.js @@ -1,6 +1,6 @@ class PublicCorpusList extends CorpusList { get item() { - return (values) => { + return (values) => { return ` <tr class="list-item clickable hoverable"> <td><b class="title"></b><br><i class="description"></i></td> @@ -14,6 +14,19 @@ class PublicCorpusList extends CorpusList { }; } + mapResourceToValue(corpus) { + return { + 'id': corpus.id, + 'creation-date': corpus.creation_date, + 'description': corpus.description, + 'status': corpus.status, + 'title': corpus.title, + 'owner': corpus.user.username, + 'is-owner': corpus.user.id === this.userId ? true : false, + 'current-user-is-following': Object.values(corpus.corpus_follower_associations).some(association => association.follower.id === currentUserId) + }; + } + initListContainerElement() { if (!this.listContainerElement.hasAttribute('id')) { this.listContainerElement.id = Utils.generateElementId('corpus-list-'); diff --git a/app/templates/main/dashboard.html.j2 b/app/templates/main/dashboard.html.j2 index 7c36ff3a9e8f3e1bea3154aaaf31a7ee67ffeb88..54f91eaac6032ee32c49fdb7804da042b6e020ca 100644 --- a/app/templates/main/dashboard.html.j2 +++ b/app/templates/main/dashboard.html.j2 @@ -15,7 +15,7 @@ <div class="col s12"> <div class="card"> <div class="card-content"> - <div class="corpus-list no-autoinit" data-user-id="{{ current_user.hashid }}"></div> + <div class="corpus-list" data-user-id="{{ current_user.hashid }}"></div> </div> <div class="card-action right-align"> <a class="btn disabled waves-effect waves-light" href="{{ url_for('corpora.import_corpus') }}">Import Corpus<i class="material-icons right">import_export</i></a> @@ -135,17 +135,3 @@ </div> </div> {% endblock modals %} - -{% block scripts %} -{{ super() }} -<script> - let corpusList = new CorpusList(document.querySelector('.corpus-list')); - corpusList.add( - [ - {% for corpus in corpora %} - {{ corpus.to_json_serializeable(backrefs=True, relationships=True)|tojson }}, - {% endfor %} - ] - ); -</script> -{% endblock scripts %} diff --git a/app/templates/main/social_area.html.j2 b/app/templates/main/social_area.html.j2 index 8b8528fc1afdd77df1970ff375e5b9d965758bd9..5ce67bebeebaecbd032fb45074b0dfad8ed40284 100644 --- a/app/templates/main/social_area.html.j2 +++ b/app/templates/main/social_area.html.j2 @@ -70,7 +70,7 @@ {% endfor %} ] ); - let publicCorpusList = new DetailledPublicCorpusList(document.querySelector('.public-corpus-list')); + let publicCorpusList = new PublicCorpusList(document.querySelector('.public-corpus-list')); publicCorpusList.add( [ {% for corpus in corpora %}