diff --git a/app/main/routes.py b/app/main/routes.py index 56c37116..080616ec 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -39,10 +39,8 @@ def faq(): @register_breadcrumb(bp, '.dashboard', 'dashboardDashboard') @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 b3294b00..5b8a4694 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 0a8905c5..c4caa399 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 ce2c9cbd..1ef98273 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 `
@@ -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 7c36ff3a..54f91eaa 100644 --- a/app/templates/main/dashboard.html.j2 +++ b/app/templates/main/dashboard.html.j2 @@ -15,7 +15,7 @@
-
+
Import Corpusimport_export @@ -135,17 +135,3 @@
{% endblock modals %} - -{% block scripts %} -{{ super() }} - -{% endblock scripts %} diff --git a/app/templates/main/social_area.html.j2 b/app/templates/main/social_area.html.j2 index 8b8528fc..5ce67beb 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 %}