From c9ba4153eaca24312196c98a372deb1174c41d62 Mon Sep 17 00:00:00 2001 From: prathambatra Date: Sat, 6 Jun 2020 01:42:07 +0530 Subject: [PATCH] Added Conflict count pill on view page Signed-off-by: prathambatra --- routes/root.js | 68 +++++++++++++++++++++++++------------ utils/datautils.js | 23 ++++++++++++- views/pages/claims/id.hbs | 2 -- views/pages/claims/view.hbs | 3 ++ 4 files changed, 71 insertions(+), 25 deletions(-) diff --git a/routes/root.js b/routes/root.js index 0e9b722..b0579e5 100644 --- a/routes/root.js +++ b/routes/root.js @@ -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) + 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) diff --git a/utils/datautils.js b/utils/datautils.js index 503a30f..d41d76f 100644 --- a/utils/datautils.js +++ b/utils/datautils.js @@ -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', @@ -252,5 +272,6 @@ module.exports = { updateClaim, getCounts, getConflictedClaims, - getResourceFromUrl + getResourceFromUrl, + getConflictsCount } diff --git a/views/pages/claims/id.hbs b/views/pages/claims/id.hbs index db0a943..fc2a6d9 100644 --- a/views/pages/claims/id.hbs +++ b/views/pages/claims/id.hbs @@ -153,8 +153,6 @@ {{/each}} - {{else}} -

No Conflicted claims

{{/if}} diff --git a/views/pages/claims/view.hbs b/views/pages/claims/view.hbs index e3d3a52..2f837b7 100644 --- a/views/pages/claims/view.hbs +++ b/views/pages/claims/view.hbs @@ -59,6 +59,9 @@ {{#if claim.reason}} Reason: {{claim.reason}} {{/if}} + {{#if claim.conflictCount}} + Conflicts {{claim.conflictCount}} + {{/if}}
Project : {{claim.repo}}