mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 12:22:47 +00:00 
			
		
		
		
	getUser back to CorpusList
This commit is contained in:
		@@ -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'
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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()
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -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() {
 | 
			
		||||
 
 | 
			
		||||
@@ -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-');
 | 
			
		||||
 
 | 
			
		||||
@@ -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 %}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 %}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user