This commit is contained in:
2018-07-23 17:36:47 +05:30
parent 88eac3d247
commit 7c40e1e4b1
5 changed files with 110 additions and 20 deletions

View File

@@ -249,6 +249,24 @@
</form> </form>
</div> </div>
</div> </div>
<div id="displaylastcomment" class="card hide widget good">
<div class="card-body">
<h5 class="card-title">Display Last Comment</h5>
<form>
<div class="form-row">
<div class="form-group col-md-6 col-sm-6 col-lg-6 col-xs-6 mb-3">
<label for="repoForCommentView">Repository Name</label>
<input type="text" class="form-control" id="repoForCommentView" placeholder="Repository Name...." required>
</div>
<div class="form-group col-md-6 col-sm-6 col-lg-6 col-xs-6 mb-3">
<label for="issueNumberForCommentView">Issue To Close</label>
<input type="text" class="form-control" id="issueNumberForCommentView" placeholder="Specify issue number..." required>
</div>
</div>
<button class="btn btn-primary" type="button" data-toggle="modal" data-dismiss="modal" id="btnSubmitCommentView" data-target="#submitConfirm">Submit</button>
</form>
</div>
</div>
<div class="line hide" id="underWidgetLine"></div> <div class="line hide" id="underWidgetLine"></div>
</div> </div>
<!-- Modals --> <!-- Modals -->

View File

@@ -33,7 +33,7 @@ module.exports = {
"showWidgetOperation": "showCloseIssueWidget", "showWidgetOperation": "showCloseIssueWidget",
"populateDataOperation": "populateCloseIssueData", "populateDataOperation": "populateCloseIssueData",
"successMessage": "Issue Closed!", "successMessage": "Issue Closed!",
"cardMsg": "Issue Closed as requested!", "cardMsg": "Issue Closed as requested, closed issue available at: ",
"cardDataUrl": "html_url", "cardDataUrl": "html_url",
"cardDataName": "title" "cardDataName": "title"
}, },
@@ -49,6 +49,18 @@ module.exports = {
"cardDataUrl": "html_url", "cardDataUrl": "html_url",
"cardDataName": "title" "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' : { 'addcollab' : {
"requestMethod": 'post', "requestMethod": 'post',
"intentMessage": "Add a collaborator", "intentMessage": "Add a collaborator",

View File

@@ -1,4 +1,6 @@
const $config = require('./config.js'); const $config = require('./config.js');
const GithubHelper = require('./helper.js');
const githubHelper = new GithubHelper();
module.exports = class DomManipulator { module.exports = class DomManipulator {
@@ -193,9 +195,9 @@ module.exports = class DomManipulator {
} }
populateRecastData(widgetName, recastResponse) { populateRecastData(widgetName, recastResponse) {
var requestMethod = $config.intentSlugToOperations[widgetName]['requestMethod']; // var requestMethod = $config.intentSlugToOperations[widgetName]['requestMethod'];
if(requestMethod == 'post') { var operation = $config.intentSlugToOperations[widgetName]['populateDataOperation'];
var operation = $config.intentSlugToOperations[widgetName]['populateDataOperation']; if(typeof this[operation] === "function") {
this[operation](recastResponse); 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) { populateAddCollaboratorData(recastResponse) {
var collaboratorNameTextField = document.getElementById('collaboratorName'); var collaboratorNameTextField = document.getElementById('collaboratorName');
var repoForCollabTextField = document.getElementById('repoForCollab'); 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) { isVisible(element) {
return element ? !element.classList.contains('hide') : false; return element ? !element.classList.contains('hide') : false;
} }
@@ -268,9 +300,9 @@ module.exports = class DomManipulator {
var data = {}; var data = {};
var intent = $('#' + $config.costants.hiddenIntentFieldId).val(); var intent = $('#' + $config.costants.hiddenIntentFieldId).val();
var requestMethod = $config.intentSlugToOperations[intent]['requestMethod']; var requestMethod = $config.intentSlugToOperations[intent]['requestMethod'];
if(requestMethod == 'post') { if(intent) {
if(intent) { var operation = $config.intentSlugToOperations[intent]['getDataOperation'];
var operation = $config.intentSlugToOperations[intent]['getDataOperation']; if(typeof this[operation] == "function") {
data = this[operation](); data = this[operation]();
} }
} }
@@ -340,11 +372,22 @@ module.exports = class DomManipulator {
return data; 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) { addGitOperationHistory(data, type) {
var intent = $('#' + $config.costants.hiddenIntentFieldId).val(); var intent = $('#' + $config.costants.hiddenIntentFieldId).val();
var requestMethod = $config.intentSlugToOperations[intent].requestMethod; var requestMethod = $config.intentSlugToOperations[intent].requestMethod;
var conversations = document.getElementById('conversations'); var conversations = document.getElementById('conversations');
var table = undefined; var table = undefined;
var comment = undefined;
// Create Elements // Create Elements
var card = document.createElement('div'); var card = document.createElement('div');
var cardBody = document.createElement('div'); var cardBody = document.createElement('div');
@@ -391,7 +434,12 @@ module.exports = class DomManipulator {
} else if (requestMethod == 'get') { } else if (requestMethod == 'get') {
cardText.innerHTML = $config.intentSlugToOperations[intent]['cardMsg']; cardText.innerHTML = $config.intentSlugToOperations[intent]['cardMsg'];
if(data && data.length && data.length > 0) { 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 { } else {
@@ -404,6 +452,7 @@ module.exports = class DomManipulator {
cardTitle.appendChild(closeAnchor); cardTitle.appendChild(closeAnchor);
cardBody.appendChild(cardTitle); cardBody.appendChild(cardTitle);
cardBody.appendChild(cardText); cardBody.appendChild(cardText);
if(comment) { cardBody.appendChild(comment); }
cardFooter.appendChild(textMuted); cardFooter.appendChild(textMuted);
card.appendChild(cardBody); card.appendChild(cardBody);
if(table) { card.appendChild(table); } if(table) { card.appendChild(table); }
@@ -508,6 +557,14 @@ module.exports = class DomManipulator {
return table; return table;
} }
createCommentBody(data) {
var commentPara = document.createElement('p');
var lastComment = githubHelper.getLatestComment(data);
commentPara.classList.add('card-text');
commentPara.innerHTML = "<strong style='color:black'>COMMENT:</strong> <i>" + lastComment + "</i>";
return commentPara;
}
concealCodeInUrl() { concealCodeInUrl() {
window.location = "http://localhost:8080"; window.location = "http://localhost:8080";
} }
@@ -528,13 +585,16 @@ module.exports = class DomManipulator {
$('#op-msg').text($config.intentSlugToOperations[intent]['successMessage']); $('#op-msg').text($config.intentSlugToOperations[intent]['successMessage']);
$('#successAlert').removeClass('hide'); $('#successAlert').removeClass('hide');
self.addGitOperationHistory(body, "response"); self.addGitOperationHistory(body, "response");
// clear intent
$('#' + $config.costants.hiddenIntentFieldId).val('');
}) })
} else { } else {
$('#widgets').children().addClass('hide'); $('#widgets').children().addClass('hide');
$('#dangerAlert').removeClass('hide'); $('#dangerAlert').removeClass('hide');
self.addGitOperationHistory(response.status); self.addGitOperationHistory(response.status);
// clear intent
$('#' + $config.costants.hiddenIntentFieldId).val('');
} }
$('#' + $config.costants.hiddenIntentFieldId).val('');
} }
display_ct (start, element) { display_ct (start, element) {

View File

@@ -234,8 +234,6 @@ module.exports = class Github {
} }
displayLastComment(repoName, issueNumber) { displayLastComment(repoName, issueNumber) {
repoName = "stack_route_prj7";
issueNumber = 2;
let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/' + issueNumber + "/comments"; let url = 'https://api.github.com/repos/mohiit1502/' + repoName + '/issues/' + issueNumber + "/comments";
var comments = []; var comments = [];
var latestComment = ""; var latestComment = "";
@@ -248,13 +246,13 @@ module.exports = class Github {
} }
) )
.then(function(response) { .then(function(response) {
response.json().then(function(body){ dom.toggleModals(response);
comments = body; // response.json().then(function(body){
latestComment = githubHelper.getLatestComment(comments); // comments = body;
console.log(comments); // latestComment = githubHelper.getLatestComment(comments);
console.log(latestComment); // console.log(comments);
return latestComment; // console.log(latestComment);
}); // });
}) })
.catch(error => console.error('Fetch Error =\n', error)); .catch(error => console.error('Fetch Error =\n', error));
} }

View File

@@ -104,8 +104,10 @@ module.exports = class Microbot {
$github.addIssueComment(requestJson, repoName, issueId); $github.addIssueComment(requestJson, repoName, issueId);
} }
displayLastComment() { displayLastComment(requestData) {
return $github.displayLastComment(); var repoName = requestData.urlParams.repoName;
var issueId = requestData.urlParams.issueId;
return $github.displayLastComment(repoName, issueId);
} }
addCollaborator(requestData) { addCollaborator(requestData) {