Skip to content

Commit

Permalink
Merge pull request #59 from Microsoft/users/wismythe/wi-links-fix
Browse files Browse the repository at this point in the history
Fix attachments not getting added as links when creating a new VSTS work item
  • Loading branch information
willsmythe authored May 17, 2018
2 parents d67acc0 + b243a60 commit 2e5a658
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 71 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Visual Studio Team Services App for Zendesk

![master build](https://mseng.visualstudio.com/_apis/public/build/definitions/b924d696-3eae-4116-8443-9a18392d8544/6993/badge)

> Get the [latest version](https://github.com/Microsoft/vsts-zendesk-app/releases) of the app
Unite your customer support and development teams. Quickly create or link work items to tickets, enable efficient two-way communication, and stop using email to check status.
Expand Down Expand Up @@ -38,4 +40,3 @@ See [full instructions](https://www.visualstudio.com/docs/marketplace/integrate/
4. Pick and the Visual Studio Team Services event which will post to Zendesk
5. Tell Zendesk what to do when the event occurs
6. Test the service hook subscription and finish the wizard

2 changes: 1 addition & 1 deletion dist/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"singleInstall": true,
"private": true,
"frameworkVersion": "2.0",
"version": "0.6.1",
"version": "0.6.2",
"parameters": [
{
"name": "vso_account",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
"build": "webpack -p",
"watch": "webpack --watch"
},
"version": "0.6.0"
"version": "0.6.2"
}
62 changes: 0 additions & 62 deletions src/javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,18 +1038,6 @@ const App = (function() {
return _.contains(VSO_WI_TYPES_WHITE_LISTS, wit.name);
});
},
buildPatchToAddWorkItemField: function(fieldName, value) {
// Check if the field type is html to replace newlines by br
if (this.isHtmlContentField(fieldName)) {
value = value.replace(/\n/g, "<br>");
}

return {
op: "add",
path: helpers.fmt("/fields/%@", fieldName),
value: value,
};
},
isHtmlContentField: function(fieldName) {
var field = this.getFieldByFieldRefName(fieldName);

Expand All @@ -1060,26 +1048,6 @@ const App = (function() {
return false;
}
},
buildPatchToAddWorkItemHyperlink: function(url, name, comment) {
return {
op: "add",
path: "/relations/-",
value: {
rel: "Hyperlink",
url: url,
attributes: {
name: name,
comment: comment,
},
},
};
},
buildPatchToRemoveWorkItemHyperlink: function(pos) {
return {
op: "remove",
path: helpers.fmt("/relations/%@", pos),
};
},
getAjaxErrorMessage: function(jqXHR, errMsg) {
errMsg = errMsg || this.I18n.t("errorAjax"); //Let's try get a friendly message based on some cases

Expand All @@ -1094,36 +1062,6 @@ const App = (function() {
var detail = this.I18n.t("errorServer").fmt(jqXHR.status, jqXHR.statusText, serverErrMsg);
return errMsg + " " + detail;
},
buildPatchToAddWorkItemAttachments: async function(attachments) {
const _ticket7 = await wrapZafClient(this.zafClient, "ticket");

return _.map(
attachments,
async function(att) {
return this.buildPatchToAddWorkItemHyperlink(
att.url,
VSO_ZENDESK_LINK_TO_TICKET_ATTACHMENT_PREFIX + _ticket7.id,
att.name,
);
}.bind(this),
);
},
getSelectedAttachments: function($modal) {
var attachments = [];
$modal.find(".attachments input").each(
function(ix, el) {
var $el = this.$(el);

if ($el.is(":checked")) {
attachments.push({
url: $el.val(),
name: $el.data("fileName"),
});
}
}.bind(this),
);
return attachments;
},
buildAccountUrl: function() {
var baseUrl;
var setting = this.setting("vso_account");
Expand Down
38 changes: 34 additions & 4 deletions src/javascripts/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,6 @@ const ModalApp = BaseApp.extend({
}

const description = $modal.find(".description").val();
// var attachments = this.getSelectedAttachments($modal);
let operations = [].concat(
this.buildPatchToAddWorkItemField("System.Title", summary),
this.buildPatchToAddWorkItemField("System.Description", description),
Expand All @@ -642,8 +641,9 @@ const ModalApp = BaseApp.extend({

if (this.hasFieldDefined(workItemType, "Microsoft.VSTS.TCM.ReproSteps")) {
operations.push(this.buildPatchToAddWorkItemField("Microsoft.VSTS.TCM.ReproSteps", description));
} //Set tag

}

//Set tag
if (this.setting("vso_tag")) {
operations.push(this.buildPatchToAddWorkItemField("System.Tags", this.setting("vso_tag")));
}
Expand All @@ -654,7 +654,10 @@ const ModalApp = BaseApp.extend({
);

//Add hyperlinks to attachments
//operations = operations.concat(await this.buildPatchToAddWorkItemAttachments(attachments));
const attachments = this.getSelectedAttachments($modal);
if (attachments.length > 0) {
operations = operations.concat(this.buildPatchToAddWorkItemAttachments(attachments, ticket));
}

try {
const data = await this.execQueryOnSidebar(["ajax", "createVsoWorkItem", proj.id, workItemType.name, operations]);
Expand Down Expand Up @@ -787,6 +790,33 @@ const ModalApp = BaseApp.extend({
},
};
},
buildPatchToAddWorkItemAttachments: function(attachments, ticket) {
return _.map(
attachments,
function(att) {
return this.buildPatchToAddWorkItemHyperlink(
att.url,
VSO_ZENDESK_LINK_TO_TICKET_ATTACHMENT_PREFIX + ticket.id,
att.name,
);
}.bind(this),
);
},
getSelectedAttachments: function($modal) {
var attachments = [];
$modal.find(".attachments input").each(
function(ix, el) {
var $el = this.$(el);
if ($el.is(":checked")) {
attachments.push({
url: $el.val(),
name: $el.attr("data-file-name"),
});
}
}.bind(this),
);
return attachments;
},
buildPatchToRemoveWorkItemHyperlink: function(pos) {
return {
op: "remove",
Expand Down
5 changes: 3 additions & 2 deletions src/templates/notify.hdbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
</p>
<textarea placeholder="{{t "modals.notify.placeholder"}}"></textarea>
<a href="#" class="copyLastComment">{{t "modals.notify.copyLastComment"}}</a>
<!-- Temporarily remove because there isn't support for adding/removing attachment links
{{#if attachments.length}}
<div>
<label>{{t "modals.new.fields.attachments"}}</label>
Expand All @@ -11,7 +12,7 @@
{{#each attachments}}
<li>
<label>
<input type='checkbox' value='{{content_url}}' data-file-name='{{file_name}}'>
<input type='checkbox' value='{{content_url}}' data-file-name='{{file_name}}' checked>
{{#if thumbnails.length}}
<img src="{{thumbnails.0.content_url}}">
{{/if}}
Expand All @@ -22,6 +23,6 @@
</ul>
</div>
</div>
{{/if}}
{{/if}}-->
</form>
<div class="loading" style='display:none'>{{spinner "dotted"}}</div>

0 comments on commit 2e5a658

Please sign in to comment.