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

Added Conflicting Claims count pill on Claims listing #405

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
68 changes: 46 additions & 22 deletions routes/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,53 @@ route.get('/claims/view', (req, res) => {
})
})

res.render('pages/claims/view', {
prevPage: options.page - 1,
nextPage: options.page + 1,
pagination: pagination,
isFirstPage: options.page == 1,
isLastPage: lastPage == options.page,
page: options.page,
size: options.size,
claims: data[1].rows,
menu: {
claims_view: 'active',
claims: 'claims-active'
},
status: options.status,
menuH,
current,
filter: filter,
filterproj: filterproj,
username: options.username,
projectname: options.projectname,
minbounty: options.minbounty,
maxbounty: options.maxbounty
const conflictCounts = {}

const conflictsLoader = async() => {
for (claim of data[1].rows) {
pullUrlDetail = getUrlDetails(claim["pullUrl"])
issueUrlDetail = getUrlDetails(claim["issueUrl"])
conflictKey = issueUrlDetail.project + '/' + pullUrlDetail.type + '/' +issueUrlDetail.id
if(conflictCounts[conflictKey] === undefined) {
const c = await du.getConflictsCount(claim,issueUrlDetail,pullUrlDetail.type)
Copy link
Contributor

Choose a reason for hiding this comment

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

How can a query inside a loop be a single query. Try to write a separate raw query for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok so you mean, there is no need for a loop just a query wich groups all conflicts for all claims. ??

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

conflictCounts[conflictKey] = c
}
if(conflictCounts[conflictKey] !== 0)
claim["conflictCount"] = conflictCounts[conflictKey]
}
}

conflictsLoader()
.then(()=> {
res.render('pages/claims/view', {
prevPage: options.page - 1,
nextPage: options.page + 1,
pagination: pagination,
isFirstPage: options.page == 1,
isLastPage: lastPage == options.page,
page: options.page,
size: options.size,
claims: data[1].rows,
menu: {
claims_view: 'active',
claims: 'claims-active'
},
status: options.status,
menuH,
current,
filter: filter,
filterproj: filterproj,
username: options.username,
projectname: options.projectname,
minbounty: options.minbounty,
maxbounty: options.maxbounty
})
})
.catch((err)=> {
console.log(err)
res.send('Error in Conflict Loader')
})

})
.catch(err => {
console.log(err)
Expand Down
23 changes: 22 additions & 1 deletion utils/datautils.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,26 @@ function getConflictedClaims(claim,issueUrlDetail,pullUrlType) {
})
}

function getConflictsCount(claim,issueUrlDetail,pullUrlType) {
projectName = '/' + issueUrlDetail.project + '/'
issueId = '/' + issueUrlDetail.id
pullUrlType = projectName + pullUrlType + '/'
return db.Claim.count({
where : {
[Op.and] : [
{
[Op.or] : [
{ issueUrl: { [Op.like]: '%' + projectName + '%' + issueId } },
{ issueUrl: { [Op.like]: '%' + projectName + '%' + issueId + '/' } }
]
},
{ pullUrl: { [Op.like]: '%' + pullUrlType + '%' } },
{ id : { [Op.ne] : claim.id } }
]
}
})
}

function updateClaim(claimId, { status, reason, bounty }) {
const claim = {
action: 'update',
Expand Down Expand Up @@ -252,5 +272,6 @@ module.exports = {
updateClaim,
getCounts,
getConflictedClaims,
getResourceFromUrl
getResourceFromUrl,
getConflictsCount
}
2 changes: 0 additions & 2 deletions views/pages/claims/id.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@
</div>
</div>
{{/each}}
{{else}}
<h3 style="margin-top: 1em;">No Conflicted claims</h3>
{{/if}}
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions views/pages/claims/view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
{{#if claim.reason}}
<small class="text-muted">Reason: {{claim.reason}}</small>
{{/if}}
{{#if claim.conflictCount}}
<span class="badge badge-danger">Conflicts <span class="badge badge-light">{{claim.conflictCount}}</span></span>
{{/if}}
<br />
<small class="text-muted">Project : <a
href="https://www.github.com/coding-blocks/{{claim.repo}}">{{claim.repo}}</a></small>
Expand Down