diff --git a/public/index.html b/public/index.html index e32abaa..1e8fea4 100644 --- a/public/index.html +++ b/public/index.html @@ -249,6 +249,24 @@ +
diff --git a/src/js/config.js b/src/js/config.js index 3a2594b..3811752 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -33,7 +33,7 @@ module.exports = { "showWidgetOperation": "showCloseIssueWidget", "populateDataOperation": "populateCloseIssueData", "successMessage": "Issue Closed!", - "cardMsg": "Issue Closed as requested!", + "cardMsg": "Issue Closed as requested, closed issue available at: ", "cardDataUrl": "html_url", "cardDataName": "title" }, @@ -49,6 +49,18 @@ module.exports = { "cardDataUrl": "html_url", "cardDataName": "title" }, + 'displaylastcomment' : { + "requestMethod": 'get', + "intentMessage": "Display last comment of an issue in Github", + "getDataOperation": "getDisplayCommentJson", + "githubOperation": "displayLastComment", + "showWidgetOperation": "showDisplayCommentWidget", + "populateDataOperation": "populateDisplayCommentData", + "successMessage": "Comment Retrieved!", + "cardMsg": "Please find requested comment below: ", + "cardDataUrl": "html_url", + "cardDataName": "title" + }, 'addcollab' : { "requestMethod": 'post', "intentMessage": "Add a collaborator", diff --git a/src/js/dom-ops.js b/src/js/dom-ops.js index 3f60d67..5fa0f41 100644 --- a/src/js/dom-ops.js +++ b/src/js/dom-ops.js @@ -1,4 +1,6 @@ const $config = require('./config.js'); +const GithubHelper = require('./helper.js'); +const githubHelper = new GithubHelper(); module.exports = class DomManipulator { @@ -193,9 +195,9 @@ module.exports = class DomManipulator { } populateRecastData(widgetName, recastResponse) { - var requestMethod = $config.intentSlugToOperations[widgetName]['requestMethod']; - if(requestMethod == 'post') { - var operation = $config.intentSlugToOperations[widgetName]['populateDataOperation']; + // var requestMethod = $config.intentSlugToOperations[widgetName]['requestMethod']; + var operation = $config.intentSlugToOperations[widgetName]['populateDataOperation']; + if(typeof this[operation] === "function") { this[operation](recastResponse); } } @@ -224,6 +226,21 @@ module.exports = class DomManipulator { } } + populateCloseIssueData(recastResponse) { + var issueNumberTextField = document.getElementById('issueNumerToClose'); + var issueRepositoryTextField = document.getElementById('repoForIssueClose'); + if(issueNumberTextField && recastResponse && recastResponse.entities['issue_id'] && recastResponse.entities['issue_id'].length > 0 + && recastResponse.entities['issue_id']['0']['value']) { + var issueNumber = recastResponse.entities['issue_id']['0']['value']; + issueNumberTextField.value = issueNumber; + } + if(issueRepositoryTextField && recastResponse && recastResponse.entities['git-repository'] && recastResponse.entities['git-repository'].length > 0 + && recastResponse.entities['git-repository']['0']['value']) { + var repoName = recastResponse.entities['git-repository']['0']['value']; + issueRepositoryTextField.value = repoName; + } + } + populateAddCollaboratorData(recastResponse) { var collaboratorNameTextField = document.getElementById('collaboratorName'); var repoForCollabTextField = document.getElementById('repoForCollab'); @@ -260,6 +277,21 @@ module.exports = class DomManipulator { } } + populateDisplayCommentData(recastResponse) { + var issueNumberTextField = document.getElementById('issueNumberForCommentView'); + var issueRepositoryTextField = document.getElementById('repoForCommentView'); + if(issueNumberTextField && recastResponse && recastResponse.entities['issue_id'] && recastResponse.entities['issue_id'].length > 0 + && recastResponse.entities['issue_id']['0']['value']) { + var issueNumber = recastResponse.entities['issue_id']['0']['value']; + issueNumberTextField.value = issueNumber; + } + if(issueRepositoryTextField && recastResponse && recastResponse.entities['git-repository'] && recastResponse.entities['git-repository'].length > 0 + && recastResponse.entities['git-repository']['0']['value']) { + var repoName = recastResponse.entities['git-repository']['0']['value']; + issueRepositoryTextField.value = repoName; + } + } + isVisible(element) { return element ? !element.classList.contains('hide') : false; } @@ -268,9 +300,9 @@ module.exports = class DomManipulator { var data = {}; var intent = $('#' + $config.costants.hiddenIntentFieldId).val(); var requestMethod = $config.intentSlugToOperations[intent]['requestMethod']; - if(requestMethod == 'post') { - if(intent) { - var operation = $config.intentSlugToOperations[intent]['getDataOperation']; + if(intent) { + var operation = $config.intentSlugToOperations[intent]['getDataOperation']; + if(typeof this[operation] == "function") { data = this[operation](); } } @@ -340,11 +372,22 @@ module.exports = class DomManipulator { return data; } + getDisplayCommentJson() { + var data = {}; + data.urlParams = {}; + if(this.isVisible(document.getElementById("displaylastcomment"))) { + data.urlParams.issueId = document.getElementById("issueNumberForCommentView").value; + data.urlParams.repoName = document.getElementById("repoForCommentView").value; + } + return data; + } + addGitOperationHistory(data, type) { var intent = $('#' + $config.costants.hiddenIntentFieldId).val(); var requestMethod = $config.intentSlugToOperations[intent].requestMethod; var conversations = document.getElementById('conversations'); var table = undefined; + var comment = undefined; // Create Elements var card = document.createElement('div'); var cardBody = document.createElement('div'); @@ -391,7 +434,12 @@ module.exports = class DomManipulator { } else if (requestMethod == 'get') { cardText.innerHTML = $config.intentSlugToOperations[intent]['cardMsg']; if(data && data.length && data.length > 0) { - table = this.createRepoTable(data); + if(intent === "viewrepo") { + table = this.createRepoTable(data); + } + else if(intent === "displaylastcomment") { + comment = this.createCommentBody(data); + } } } } else { @@ -404,6 +452,7 @@ module.exports = class DomManipulator { cardTitle.appendChild(closeAnchor); cardBody.appendChild(cardTitle); cardBody.appendChild(cardText); + if(comment) { cardBody.appendChild(comment); } cardFooter.appendChild(textMuted); card.appendChild(cardBody); if(table) { card.appendChild(table); } @@ -508,6 +557,14 @@ module.exports = class DomManipulator { return table; } + createCommentBody(data) { + var commentPara = document.createElement('p'); + var lastComment = githubHelper.getLatestComment(data); + commentPara.classList.add('card-text'); + commentPara.innerHTML = "COMMENT: " + lastComment + ""; + return commentPara; + } + concealCodeInUrl() { window.location = "http://localhost:8080"; } @@ -528,13 +585,16 @@ module.exports = class DomManipulator { $('#op-msg').text($config.intentSlugToOperations[intent]['successMessage']); $('#successAlert').removeClass('hide'); self.addGitOperationHistory(body, "response"); + // clear intent + $('#' + $config.costants.hiddenIntentFieldId).val(''); }) } else { $('#widgets').children().addClass('hide'); $('#dangerAlert').removeClass('hide'); self.addGitOperationHistory(response.status); + // clear intent + $('#' + $config.costants.hiddenIntentFieldId).val(''); } - $('#' + $config.costants.hiddenIntentFieldId).val(''); } display_ct (start, element) { diff --git a/src/js/github-ops.js b/src/js/github-ops.js index 3db4038..192a8aa 100644 --- a/src/js/github-ops.js +++ b/src/js/github-ops.js @@ -234,8 +234,6 @@ module.exports = class Github { } displayLastComment(repoName, issueNumber) { - repoName = "stack_route_prj7"; - issueNumber = 2; let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/' + issueNumber + "/comments"; var comments = []; var latestComment = ""; @@ -248,13 +246,13 @@ module.exports = class Github { } ) .then(function(response) { - response.json().then(function(body){ - comments = body; - latestComment = githubHelper.getLatestComment(comments); - console.log(comments); - console.log(latestComment); - return latestComment; - }); + dom.toggleModals(response); + // response.json().then(function(body){ + // comments = body; + // latestComment = githubHelper.getLatestComment(comments); + // console.log(comments); + // console.log(latestComment); + // }); }) .catch(error => console.error('Fetch Error =\n', error)); } diff --git a/src/js/microbot-ops.js b/src/js/microbot-ops.js index 12c488f..c8beb66 100644 --- a/src/js/microbot-ops.js +++ b/src/js/microbot-ops.js @@ -104,8 +104,10 @@ module.exports = class Microbot { $github.addIssueComment(requestJson, repoName, issueId); } - displayLastComment() { - return $github.displayLastComment(); + displayLastComment(requestData) { + var repoName = requestData.urlParams.repoName; + var issueId = requestData.urlParams.issueId; + return $github.displayLastComment(repoName, issueId); } addCollaborator(requestData) {