final
This commit is contained in:
@@ -249,6 +249,24 @@
|
||||
</form>
|
||||
</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>
|
||||
<!-- Modals -->
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 = "<strong style='color:black'>COMMENT:</strong> <i>" + lastComment + "</i>";
|
||||
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) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user