Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add list view for grants and migrate to vue #7336

Merged
merged 9 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions app/assets/v2/js/grants/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Vue.component('grant-card', {
delimiters: [ '[[', ']]' ],
props: [ 'grant', 'cred', 'token', 'view', 'short', 'show_contributions', 'contributions' ],
props: [ 'grant', 'cred', 'token', 'view', 'short', 'show_contributions', 'contributions', 'toggle_following' ],
methods: {
get_clr_prediction: function(indexA, indexB) {
if (this.grant.clr_prediction_curve && this.grant.clr_prediction_curve.length) {
Expand Down Expand Up @@ -248,6 +248,21 @@ $(document).ready(() => {
vm.page = vm.page + 1;
}
}
},
toggleFollowingGrant: async function(grantId, event) {
event.preventDefault();

const favorite_url = `/grants/${grantId}/favorite`;
let response = await fetchData(favorite_url, 'POST');

console.log(favorite_url);
if (response.action === 'follow') {
this.$set(this.grants[grantId], 'favorite', true);
} else {
this.$set(this.grants[grantId], 'favorite', false);
}

return true;
}
},
mounted() {
Expand Down Expand Up @@ -353,7 +368,7 @@ $('#minimize').on('click', () => {
});
});

$(document).on('click', '.star-action', async(e) => {
$(document).on('click', '.following-action', async(e) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that was moved into vue this still needed for others areas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh I saw it is on funding.html right?

e.preventDefault();
const element = (e.target.tagName === 'BUTTON') ? $(e.target) : $(e.target.parentElement);
const grantId = element.data('grant');
Expand Down
2 changes: 1 addition & 1 deletion app/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ def presave_contrib(sender, instance, **kwargs):

def next_month():
"""Get the next month time."""
return (timezone.now() + timedelta(days=30))
return localtime(timezone.now() + timedelta(days=30))


class CLRMatch(SuperModel):
Expand Down
8 changes: 4 additions & 4 deletions app/grants/templates/grants/components/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% endcomment %}
{% load i18n static humanize grants_extra %}
<grant-card inline-template :grant="grant" :cred="credentials" :view="view" :short="shortView"
:contributions='contributions' :show_contributions="show_contributions">
:contributions='contributions' :show_contributions="show_contributions" :toggle_following="toggleFollowingGrant">
<template>
<div v-if="view == 'list'">
<div class="grant-item grant-item--list flex-md-row flex-column" >
Expand Down Expand Up @@ -84,7 +84,7 @@ <h2 class="grant-item__title font-subheader">
</div>
</div>
<template v-if="cred.is_authenticated">
<button :class="`ml-3 text-decoration-none btn btn-link star-action m-0 p-0 font-smaller-3 gc-text-blue ${!grant.favorite ? 'text-muted' : ''}`" :data-grant="grant.id">
<button @click="toggle_following(grant.id, $event)" :class="`ml-3 text-decoration-none btn btn-link star-action m-0 p-0 font-smaller-3 gc-text-blue ${!grant.favorite ? 'text-muted' : ''}`" :data-grant="grant.id">
<i :class="`${!grant.favorite ? 'far' : 'fa' } fa-star`" ></i>
<span class="ml-1 font-body">[[ !grant.favorite ? 'Follow' : 'Following' ]]</span>
</button>
Expand Down Expand Up @@ -156,8 +156,8 @@ <h2 class="grant-item__title font-subheader">
</a>
</div>
<template v-if="cred.is_authenticated">
<button :class="`text-decoration-none btn btn-link star-action m-0 p-0 mr-4 mt-3 gc-text-blue ${!grant.favorite ? 'text-muted' : ''}`" :data-grant="grant.id">
<i :class="`${!grant.favorite ? 'far' : 'fa' } fa-star`" ></i>
<button @click="toggle_following(grant.id, $event)" :class="`text-decoration-none btn btn-link star-action m-0 p-0 mr-4 mt-3 gc-text-blue ${!grant.favorite ? 'text-muted' : ''}`" :data-grant="grant.id">
<i :class="`${!grant.favorite ? 'far' : 'fa' } fa-star`" ></i> [[ toggleFollowingGrant ]]
<span class="ml-1 font-body">[[ !grant.favorite ? 'Follow' : 'Following' ]]</span>
</button>
</template>
Expand Down
2 changes: 1 addition & 1 deletion app/grants/templates/grants/detail/funding.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h2 class="font-title font-weight-bold amount pt-1 mb-0">
<div class="pt-2 mb-1 d-flex justify-content-between">
{% is_favorite grant profile.user as is_grant_favorite %}
{% if profile.user.is_authenticated %}
<button class="text-decoration-none btn btn-link star-action m-0 p-0 mr-4 gc-text-blue {% if not is_grant_favorite %}text-muted{% endif %}" data-grant="{{ grant.id }}">
<button class="text-decoration-none btn btn-link following-action m-0 p-0 mr-4 gc-text-blue {% if not is_grant_favorite %}text-muted{% endif %}" data-grant="{{ grant.id }}">
{% if not is_grant_favorite %}
<i class="far fa-star" ></i><span class="ml-1 font-body">Follow</span>
{% else %}
Expand Down