diff --git a/com.yasoon.jira/Dialogs/AddCommentDialog.html b/com.yasoon.jira/Dialogs/AddCommentDialog.html
index a952909..9bee2e0 100644
--- a/com.yasoon.jira/Dialogs/AddCommentDialog.html
+++ b/com.yasoon.jira/Dialogs/AddCommentDialog.html
@@ -36,13 +36,6 @@
diff --git a/com.yasoon.jira/Dialogs/jiraAddCommentDialog.js b/com.yasoon.jira/Dialogs/jiraAddCommentDialog.js
index 1c2cf14..8df227e 100644
--- a/com.yasoon.jira/Dialogs/jiraAddCommentDialog.js
+++ b/com.yasoon.jira/Dialogs/jiraAddCommentDialog.js
@@ -21,30 +21,30 @@ yasoon.dialog.load(new function () { //jshint ignore:line
this.settings = null;
this.mail = null;
+ this.issue = null;
this.mailConversationData = null;
- this.selectedIssue = null;
this.addedAttachmentIds = [];
this.selectedAttachments = [];
this.projects = [];
this.selectedProjectId = null;
this.selectedProjectKey = null;
- this.issueSelect2 = null;
this.mailAsMarkup = '';
this.recentIssues = [];
this.recentProjects = [];
this.projectIssues = [];
this.cacheProjects = [];
this.fieldTypes = {};
+
this.init = function (initParams) {
//Parameter taken over from Main JIRA
self.mail = initParams.mail;
- self.selectedIssue = initParams.issue;
self.isEditMode = false;
self.settings = initParams.settings;
self.selectedText = initParams.text;
self.cacheProjects = initParams.projects;
+ self.issue = initParams.issue;
//Register Close Handler
yasoon.dialog.onClose(self.cleanup);
@@ -178,8 +178,13 @@ yasoon.dialog.load(new function () { //jshint ignore:line
self.createProjectLoader(self.projects);
+ //Issue is provided by Task Object
+ if (self.issue) {
+ $('#project').val(self.issue.fields.project.id).trigger('change');
+ return;
+ }
//If mail is provided && subject contains reference to project, pre-select that
- if (self.mail) {
+ else if (self.mail) {
var convData = self.getConversationData(self.mail);
if(convData) {
//Try to find project that matches
@@ -363,10 +368,15 @@ yasoon.dialog.load(new function () { //jshint ignore:line
jira.selectedProjectKey = $('#project').find(':selected').data('key');
jira.selectedProjectId = $('#project').val();
+ //Self.issue is provided by task object
+ var issueKey = null;
+ if (self.issue) {
+ issueKey = self.issue.key;
+
//If mail is provided && subject contains reference to issue, pre-select that
- if (self.mail) {
+ } else if (self.mail) {
var convData = self.getConversationData(self.mail);
- var issueKey = null;
+
if (convData) {
//Try to find issue key that is in selected project
for (var id in convData.issues) {
@@ -385,34 +395,34 @@ yasoon.dialog.load(new function () { //jshint ignore:line
if (match && match.length > 0) {
issueKey = match[0];
}
- }
-
- if (issueKey) {
- $('#IssueSpinner').css('display', 'inline');
- return jiraGet('/rest/api/2/issue/' + issueKey)
- .then(function (data) {
- var issue = JSON.parse(data);
-
- //Add the issue to the dropdown
- self.projectIssues.push({
- id: issue.id,
- key: issue.key,
- text: issue.fields.summary + ' (' + issue.key + ')',
- summary: issue.fields.summary,
- project: { id: issue.fields.project.id, key: issue.fields.project.key }
- });
+ }
+ }
- //Rebuild select2
- self.createIssueLoader(issue);
- })
- .catch(function () {
- yasoon.util.log('Couldn\'t find issue: ' + issueKey, yasoon.util.severity.warning);
- //Issue not found? Ignore..
- })
- .finally(function () {
- $('#IssueSpinner').css('display', 'none');
+ if (issueKey) {
+ $('#IssueSpinner').css('display', 'inline');
+ return jiraGet('/rest/api/2/issue/' + issueKey)
+ .then(function (data) {
+ var issue = JSON.parse(data);
+
+ //Add the issue to the dropdown
+ self.projectIssues.push({
+ id: issue.id,
+ key: issue.key,
+ text: issue.fields.summary + ' (' + issue.key + ')',
+ summary: issue.fields.summary,
+ project: { id: issue.fields.project.id, key: issue.fields.project.key }
});
- }
+
+ //Rebuild select2
+ self.createIssueLoader(issue);
+ })
+ .catch(function () {
+ yasoon.util.log('Couldn\'t find issue: ' + issueKey, yasoon.util.severity.warning);
+ //Issue not found? Ignore..
+ })
+ .finally(function () {
+ $('#IssueSpinner').css('display', 'none');
+ });
}
};
@@ -428,146 +438,16 @@ yasoon.dialog.load(new function () { //jshint ignore:line
}
};
- var lastQuery = '';
- var searchIssue = debounce(function searchIssue(term, callback) {
- console.log('Debounced searchIssue called');
- //Concat JQL
-
- var jql = '';
-
- if(term) {
- jql += 'Summary ~ "' + term + '"';
- }
- if (jira.selectedProjectKey) {
- jql += ((jql) ? 'AND' : '') + ' project = "' + jira.selectedProjectKey + '"';
- }
- if (self.settings.hideResolvedIssues) {
- jql += ((jql) ? 'AND' : '') + ' status != "resolved"';
- }
-
- jql = '( ' + jql + ' )';
-
- if(term) {
- jql += 'OR key = "' + term + '"';
- }
-
- console.log('JQL' + jql);
-
- return jiraGet('/rest/api/2/search?jql=' + encodeURIComponent(jql) + '&maxResults=20&fields=summary,project&validateQuery=false')
- .then(function (data) {
- if (term === lastQuery) {
- var jqlResult = JSON.parse(data);
- var result = [];
- //Transform Data
- jqlResult.issues.forEach(function (issue) {
- result.push({ id: issue.id, text: issue.fields.summary + ' (' + issue.key + ')', key: issue.key, summary: issue.fields.summary, project: issue.fields.project });
- });
-
- console.log('Result for ' + term, result);
- callback(result);
- }
- })
- .catch(function () {
- if (term === lastQuery) {
- $('#IssueSpinner').css('display', 'none');
- }
- yasoon.util.log('Couldn\'t find issues for Project' + jira.selectedProjectKey + ' || Term: ' + term, yasoon.util.severity.warning);
- callback([]);
- });
- }, 250);
-
this.createIssueLoader = function createIssueLoader(issue) {
- //First Clear DOM
- if ($('issue').data('select2')) {
- $('#issue').empty();
- $('#issue').select2("destroy");
- //Second Clear Data
- $('#issue').removeData();
- }
+ var issueRenderer = new IssuePickerRenderer();
+
+ issueRenderer.render('issue', { required: true }, $('#IssueArea'));
//Create Initial Selection
if (issue) {
console.log('Init Selection' , issue);
- $('#issue').append('
');
- $('#issue').data('id', issue.id)
- .data('text', issue.fields.summary + ' (' + issue.key + ')')
- .data('key', issue.key)
- .data('summary', issue.fields.summary)
- .data('projectId', issue.fields.project.id)
- .data('projectKey', issue.fields.project.key);
- }
-
- $('#issue').select2({
- placeholder: yasoon.i18n('dialog.placeholderSelectIssue'),
- templateResult: formatIssue,
- templateSelection: formatIssue,
- ajax: {
- url: 'dummy',
- transport: function (params, success, failure) {
- console.log('Query Issue Data', params);
- var queryTerm = '';
- if (params && params.data && params.data.q) {
- queryTerm = params.data.q;
- }
-
- //Set last Quety term so we know when the REST Call returns, if it has been the latest result for the correct term.
- lastQuery = queryTerm;
-
- if (queryTerm) {
- //Case 1: A Query term has been entered.
- //Search for all issues (filtered by settings and selectedProject)
- console.log('Query JIRA Issue Data');
- $('#IssueSpinner').css('display', 'inline');
- searchIssue(queryTerm, function (params) {
- $('#IssueSpinner').css('display', 'none');
- success([{
- id: 'Results',
- text: yasoon.i18n('dialog.titleSearchResults', { term: queryTerm }),
- children: params
- }]);
- });
- } else if (jira.selectedProjectId && jira.projectIssues.length <= 1) {
- //Case 2: A project has been selected without query term, but the project issues have not been loaded yet.
- $('#IssueSpinner').css('display', 'inline');
- searchIssue(queryTerm, function (params) {
- $('#IssueSpinner').css('display', 'none');
- jira.projectIssues = params;
- success([{
- id: 'Recent',
- text: yasoon.i18n('dialog.recentIssues'),
- children: jira.recentIssues
- }, {
- id: 'ProjectIssues',
- text: yasoon.i18n('dialog.projectIssues'),
- children: params
- }]);
- });
- } else {
- //Case 3: Default just show local data
- console.log('Query Result Default data');
- var result = [];
- result.push({
- id: 'Recent',
- text: yasoon.i18n('dialog.recentIssues'),
- children: jira.recentIssues
- });
-
- if (jira.selectedProjectId) {
- result.push ({
- id: 'ProjectIssues',
- text: yasoon.i18n('dialog.projectIssues'),
- children: jira.projectIssues
- });
- }
-
- success(result);
- }
- },
- processResults: function (data, page) {
- return { results: data };
- }
- }
- });
+ issueRenderer.setValue('issue', issue);
+ }
};
this.createProjectLoader = function createProjectLoader(projects) {
@@ -699,23 +579,4 @@ function resizeWindow() {
}
}
-function formatIssue(issue) {
- if (!issue)
- return '';
-
- if (issue.element)
- $(issue.element).removeData();
-
- if (issue.element && issue.id && issue.project) {
- $(issue.element).data('id', issue.id)
- .data('text', issue.text)
- .data('key', issue.key)
- .data('summary', issue.summary)
- .data('projectId', issue.project.id)
- .data('projectKey', issue.project.key);
- }
- return issue.text;
-
-}
-
//@ sourceURL=http://Jira/Dialog/jiraAddCommentDialog.js
\ No newline at end of file
diff --git a/com.yasoon.jira/Dialogs/jiraDialog.js b/com.yasoon.jira/Dialogs/jiraDialog.js
index 646b53e..0ad5951 100644
--- a/com.yasoon.jira/Dialogs/jiraDialog.js
+++ b/com.yasoon.jira/Dialogs/jiraDialog.js
@@ -123,6 +123,12 @@ yasoon.dialog.load(new function () { //jshint ignore:line
self.recentProjects = JSON.parse(projectsString);
}
+ //Load Recent Issues from DB
+ var issuesString = yasoon.setting.getAppParameter('recentIssues');
+ if (issuesString) {
+ self.recentIssues = JSON.parse(issuesString);
+ }
+
//Load DB settings
var fieldOrderString = yasoon.setting.getAppParameter('fieldOrder');
if (fieldOrderString) {
@@ -381,6 +387,15 @@ yasoon.dialog.load(new function () { //jshint ignore:line
id: $('#issuetype').val()
};
+ // 2.1 Issue if it's a subtask
+ if (jira.currentMeta.subtask) {
+ var parent = $('#issue').val();
+ if (parent) {
+ result.fields.parent = {
+ key: parent
+ };
+ }
+ }
//Increment transaction for Greenhopper API
jira.transaction.currentCallCounter++;
//Get Generated Fields
@@ -594,11 +609,10 @@ yasoon.dialog.load(new function () { //jshint ignore:line
//Render Issue Types
$.each(self.selectedProject.issueTypes, function (i, type) {
- if (!type.subtask) {
- type.iconUrl = jira.icons.mapIconUrl(type.iconUrl);
- $('#issuetype').append('
');
- }
+ type.iconUrl = jira.icons.mapIconUrl(type.iconUrl);
+ $('#issuetype').append('
');
});
+
$('#issuetype').select2("destroy");
$("#issuetype").select2({
templateResult: formatIcon,
@@ -736,8 +750,18 @@ yasoon.dialog.load(new function () { //jshint ignore:line
this.renderIssue = function (meta) {
//Set this as current meta
jira.currentMeta = meta;
-
- return self.renderIssueUser()
+ $('#SubtaskArea').addClass('hidden');
+ return Promise.resolve()
+ .then(function() {
+ //If currentMeta is a subtask, render Issue Renderer
+ if (jira.currentMeta.subtask) {
+ new IssuePickerRenderer().render('issue', { required: true }, $('#SubtaskArea'));
+ $('#SubtaskArea').removeClass('hidden');
+ }
+ })
+ .then(function() {
+ return self.renderIssueUser();
+ })
.catch(function (e) {
console.log('Error in new renderLogic - switch to old one', e);
return self.renderIssueFixed(meta);
@@ -794,7 +818,7 @@ yasoon.dialog.load(new function () { //jshint ignore:line
return;
//Check if userPrefences allow current field
- if (renderData.userPreferences.useQuickForm && renderData.userPreferences.fields.indexOf(field.id) == -1) {
+ if (renderData.userPreferences.useQuickForm && (renderData.userPreferences.fields.indexOf(field.id) === -1 && field.required === false)) {
return;
}
diff --git a/com.yasoon.jira/Dialogs/jiraFieldRenderer.js b/com.yasoon.jira/Dialogs/jiraFieldRenderer.js
index 5f55680..c905c7f 100644
--- a/com.yasoon.jira/Dialogs/jiraFieldRenderer.js
+++ b/com.yasoon.jira/Dialogs/jiraFieldRenderer.js
@@ -1606,6 +1606,205 @@ function GroupSingleRenderer() {
};
}
+function IssuePickerRenderer() {
+
+ this.getValue = function (id) {
+ return $('#' + id).val();
+ };
+
+ this.setValue = function (id, value) {
+ if (value) {
+ //We can only select elements that have an rendered option tag.
+ if ($('#' + id).find('option[value="' + value.id + '"]').length === 0) {
+ $('#' + id).append('
');
+ $('#' + id).data('id', value.id)
+ .data('text', value.fields.summary + ' (' + issue.key + ')')
+ .data('key', value.key)
+ .data('summary', value.fields.summary)
+ .data('projectId', value.fields.project.id)
+ .data('projectKey', value.fields.project.key);
+ }
+
+ $('#' + id)
+ .val(value.id)
+ .trigger('change');
+ } else {
+ $('#' + id).removeData();
+
+ $('#' + id)
+ .val('')
+ .trigger('change');
+ }
+ };
+
+ var lastQuery = '';
+ var searchIssue = debounce(function searchIssue(term, callback) {
+ console.log('Debounced searchIssue called');
+ //Concat JQL
+
+ var jql = '';
+
+ if (term) {
+ jql += 'Summary ~ "' + term + '"';
+ }
+ if (jira.selectedProjectKey) {
+ jql += ((jql) ? 'AND' : '') + ' project = "' + jira.selectedProjectKey + '"';
+ }
+ if (jira.settings.hideResolvedIssues) {
+ jql += ((jql) ? 'AND' : '') + ' status != "resolved" AND status != "closed" AND status != "done"';
+ }
+
+ jql = '( ' + jql + ' )';
+
+ if (term) {
+ jql += 'OR key = "' + term + '"';
+ }
+
+ console.log('JQL' + jql);
+
+ return jiraGet('/rest/api/2/search?jql=' + encodeURIComponent(jql) + '&maxResults=20&fields=summary,project&validateQuery=false')
+ .then(function (data) {
+ if (term === lastQuery) {
+ var jqlResult = JSON.parse(data);
+ var result = [];
+ //Transform Data
+ jqlResult.issues.forEach(function (issue) {
+ result.push({ id: issue.id, text: issue.fields.summary + ' (' + issue.key + ')', key: issue.key, summary: issue.fields.summary, project: issue.fields.project });
+ });
+
+ console.log('Result for ' + term, result);
+ callback(result);
+ }
+ })
+ .catch(function () {
+ if (term === lastQuery) {
+ $('#IssueSpinner').css('display', 'none');
+ }
+ yasoon.util.log('Couldn\'t find issues for Project' + jira.selectedProjectKey + ' || Term: ' + term, yasoon.util.severity.warning);
+ callback([]);
+ });
+ }, 250);
+
+ this.render = function (id, field, container) {
+ if ($('#' + id).data('select2')) {
+ $('#' + id).select2("destroy");
+
+ $('#' + id + '-Container').remove();
+
+ //Second Clear Data
+ $('#' + id).removeData();
+ }
+
+ //Render Issue Picker
+ var html = '' +
+ '
';
+
+ $(container).append(html);
+
+ //Render Issue Advanced Search Dialog
+ //var path = yasoon.io.getLinkPath('templates/advancedIssueSearch.hbs');
+ //$.get(path, function (template) {
+ // var issueAdvancedTemplate = Handlebars.compile(template);
+ // $('body').append(template());
+ //});
+
+ //Register JS
+ $('#' + id).select2({
+ placeholder: yasoon.i18n('dialog.placeholderSelectIssue'),
+ templateResult: formatIssue,
+ templateSelection: formatIssue,
+ ajax: {
+ url: 'dummy',
+ transport: function (params, success, failure) {
+ console.log('Query Issue Data', params);
+ var queryTerm = '';
+ if (params && params.data && params.data.q) {
+ queryTerm = params.data.q;
+ }
+
+ //Set last Quety term so we know when the REST Call returns, if it has been the latest result for the correct term.
+ lastQuery = queryTerm;
+
+ if (queryTerm) {
+ //Case 1: A Query term has been entered.
+ //Search for all issues (filtered by settings and selectedProject)
+ console.log('Query JIRA Issue Data');
+ $('#IssueSpinner').css('display', 'inline');
+ searchIssue(queryTerm, function (params) {
+ $('#IssueSpinner').css('display', 'none');
+ success([{
+ id: 'Results',
+ text: yasoon.i18n('dialog.titleSearchResults', { term: queryTerm }),
+ children: params
+ }]);
+ });
+ } else if (jira.selectedProjectId && jira.projectIssues.length <= 1) {
+ //Case 2: A project has been selected without query term, but the project issues have not been loaded yet.
+ $('#' + id + '-Spinner').css('display', 'inline');
+ searchIssue(queryTerm, function (params) {
+ $('#' + id + '-Spinner').css('display', 'none');
+ jira.projectIssues = params;
+ success([{
+ id: 'Recent',
+ text: yasoon.i18n('dialog.recentIssues'),
+ children: jira.recentIssues
+ }, {
+ id: 'ProjectIssues',
+ text: yasoon.i18n('dialog.projectIssues'),
+ children: params
+ }]);
+ });
+ } else {
+ //Case 3: Default just show local data
+ console.log('Query Result Default data');
+ var result = [];
+ result.push({
+ id: 'Recent',
+ text: yasoon.i18n('dialog.recentIssues'),
+ children: jira.recentIssues
+ });
+
+ if (jira.selectedProjectId) {
+ result.push({
+ id: 'ProjectIssues',
+ text: yasoon.i18n('dialog.projectIssues'),
+ children: jira.projectIssues
+ });
+ }
+
+ success(result);
+ }
+ },
+ processResults: function (data, page) {
+ return { results: data };
+ }
+ }
+ });
+
+ var isLoaded = false;
+ $('#' + id + '-advancedLink').unbind().click(function () {
+ if (!isLoaded) {
+ $('#' + id + '-Spinner').show();
+ jiraGet('/rest/api/2/jql/autocompletedata').then(function (data) {
+ var jqlData = JSON.parse(data);
+
+ });
+ }
+
+ });
+ };
+}
+
function renderSelectField(id, field, style) {
var html = '' +
'
+
Service Desk assignments make the issue visible for the reporter in the Service Desk as "Own Request""
diff --git a/com.yasoon.jira/functions.js b/com.yasoon.jira/functions.js
index 8f62f44..d2dc643 100644
--- a/com.yasoon.jira/functions.js
+++ b/com.yasoon.jira/functions.js
@@ -142,7 +142,7 @@ function JiraRibbonController() {
id: 'jiraOpenTask',
size: 'large',
label: 'Open Issue',
- image: 'brandedlogo-64',
+ image: 'images/ribbonOpen.png',
visible: 'appItem',
onAction: self.ribbonOpenIssue
}, {
@@ -153,6 +153,13 @@ function JiraRibbonController() {
image: 'brandedlogo-64',
visible: 'appItem',
onAction: self.ribbonEditIssue
+ }, {
+ id: 'jiraAddTask',
+ type: 'button',
+ size: 'large',
+ image: 'images/ribbonAdd.png',
+ label: yasoon.i18n('ribbon.addToIssue'),
+ onAction: self.ribbonOnAddToIssue
}]
}]
}]
@@ -251,6 +258,9 @@ function JiraRibbonController() {
if (!item)
return;
+ if (!item.getConversationData)
+ return;
+
//This method can be called with or without inspector. In inspector it has another method to call(updateSingle instead of update) and different Ids
var where = (inspectorId) ? 'MailRead' : 'MailMain';
var ribbonButton = 'openIssueFrom' + where;
@@ -546,6 +556,11 @@ function JiraRibbonController() {
initParams.mail = ribbonCtx.items[ribbonCtx.readingPaneItem];
yasoon.dialog.open(dialogOptions);
return;
+ } else if (ribbonId == 'jiraAddTask') {
+ var task = ribbonCtx.items[ribbonCtx.readingPaneItem];
+ initParams.issue = JSON.parse(task.externalData);
+ yasoon.dialog.open(dialogOptions);
+ return;
} else {
var selection = '';
try {
diff --git a/com.yasoon.jira/jira.js b/com.yasoon.jira/jira.js
index 06b9653..165b32f 100644
--- a/com.yasoon.jira/jira.js
+++ b/com.yasoon.jira/jira.js
@@ -29,6 +29,7 @@ yasoon.app.load("com.yasoon.jira", new function () { //jshint ignore:line
this.init = function init () {
jira.settings = new JiraSettingController();
jira.notifications = new JiraNotificationController();
+ jira.tasks = new JiraTaskController();
jira.ribbons = new JiraRibbonController();
jira.contacts = new JiraContactController();
jira.icons = new JiraIconController();
@@ -278,7 +279,7 @@ yasoon.app.load("com.yasoon.jira", new function () { //jshint ignore:line
jira.contacts.updateOwn(jira.data.ownUser);
})
.then(jira.filter.reIndex)
- .then(self.syncTasks)
+ .then(jira.tasks.syncTasks)
.then(function () {
//Second get all projects
jiraLog('Get Projects');
@@ -431,57 +432,6 @@ yasoon.app.load("com.yasoon.jira", new function () { //jshint ignore:line
});
};
- this.syncTasks = function syncTasks() {
- var updatedIssues = [];
- var ownUserKey = jira.data.ownUser.key || jira.data.ownUser.name; //Depending on version >.<
- return jiraGet('/rest/api/2/search?jql=assignee%20%3D%20%22' + ownUserKey + '%22%20AND%20status%20!%3D%20%22resolved%22%20ORDER%20BY%20created%20DESC&maxResults=200&expand=transitions,renderedFields')
- .then(function (data) {
- var ownIssues = JSON.parse(data);
- if (ownIssues.total > 0) {
- return ownIssues.issues;
- }
- return [];
- })
- .each(function (issue) {
- console.log('Create Task for issue', issue);
- return new JiraIssueTask(issue).save()
- .then(function () {
- updatedIssues.push(issue.key);
- })
- .catch(function (e) {
- yasoon.util.log('Error while updating task' + e);
- });
- })
- .then(function () {
- //Check other way around and look for resolved or reassigned issues
- return jiraAllFolders()
- .each(function (folder) {
- return jiraGetFolderTasks(folder.externalId)
- .each(function (task) {
- //First check if it has already been updated
- if (updatedIssues.indexOf(task.externalId) > -1)
- return;
-
- //If we are here, we need to update the issue. it has either been assigned to someone else or it has been resolved
- return jira.issues.get(task.externalId)
- .then(function (issue) {
- var taskIssue = new JiraIssueTask(issue);
- if (!jira.settings.removeCompletedTasks && taskIssue.isSyncNeeded()) {
- //Probably resolved or something. will be fixed with sync
- return taskIssue.save();
- } else {
- jiraRemoveTask(task);
- }
- })
- .catch(function (e) {
- yasoon.util.log('Error while removing task' + e);
- });
- });
- });
-
- });
- };
-
this.downloadCustomScript = function () {
if (jira.downloadScript) {
var customScriptUrl = yasoon.setting.getAppParameter('customScript');
diff --git a/com.yasoon.jira/notifications.js b/com.yasoon.jira/notifications.js
index a28971d..c7d4638 100644
--- a/com.yasoon.jira/notifications.js
+++ b/com.yasoon.jira/notifications.js
@@ -3,7 +3,7 @@ function JiraNotificationController() {
var notificationCounter = 0;
var notification = null;
var notificationEvent = null;
-
+ var queueProcessingRunning = false;
var childQueue = [];
self.worklogTemplateLoaded = false;
@@ -79,7 +79,8 @@ function JiraNotificationController() {
};
self.addDesktopNotification = function (notif, event) {
- if (jira.settings.showDesktopNotif && notif.contactId != jira.data.ownUser.key) {
+ if (jira.settings.showDesktopNotif && notif.contactId != jira.data.ownUser.key && !queueProcessingRunning) {
+ yasoon.notification.incrementCounter();
notificationCounter++;
notification = notif;
notificationEvent = event;
@@ -124,6 +125,8 @@ function JiraNotificationController() {
if (childQueue.length === 0) {
return;
}
+
+ queueProcessingRunning = true;
return Promise.resolve(childQueue)
.each(function (entry) {
return jira.syncStream('/activity?streams=issue-key+IS+' + entry.key, 500)
@@ -138,6 +141,7 @@ function JiraNotificationController() {
});
})
.then(function () {
+ queueProcessingRunning = false;
childQueue = [];
});
};
@@ -661,7 +665,7 @@ function JiraIssueNotification(issue) {
})
.then(function (notif) {
//Save tasks and return the notif again for outside usage
- return new JiraIssueTask(self.issue).save()
+ return jira.tasks.handleTask(self.issue)
.return(notif);
});
};
@@ -973,13 +977,11 @@ function JiraIssueActionNotification(event) {
if (creation) {
return jiraAddNotification(yEvent)
.then(function (newNotif) {
- yasoon.notification.incrementCounter();
jira.notifications.addDesktopNotification(newNotif, self.event);
});
} else {
return jiraSaveNotification(yEvent)
.then(function (newNotif) {
- yasoon.notification.incrementCounter();
jira.notifications.addDesktopNotification(newNotif, self.event);
});
}
@@ -1057,6 +1059,8 @@ function JiraIssueTask(issue) {
return false;
if (!self.issue.fields.assignee || jira.data.ownUser.name != self.issue.fields.assignee.name)
return false;
+ if (jira.issues.isResolved(issue) && jira.settings.deleteCompletedTasks)
+ return false;
return true;
};
@@ -1069,7 +1073,6 @@ function JiraIssueTask(issue) {
return jiraGetTask(self.issue.key)
.then(function (dbItem) {
//Check if it's an update or creation
- console.log('Task save', dbItem);
var creation = false;
if (!dbItem) {
//Creation
@@ -1083,13 +1086,12 @@ function JiraIssueTask(issue) {
}
}
- console.log('Task save 2', dbItem);
dbItem.externalId = self.issue.key;
dbItem.subject = self.issue.key + ': ' + self.issue.fields.summary;
dbItem.body = self.issue.renderedFields.description.replace(/\s*\
/g, '
'); //jshint ignore:line
//dbItem.body = '
' + dbItem.body + '';
dbItem.isHtmlBody = true;
- if(self.issue.fields.status === 'resolved') {
+ if (jira.issues.isResolved(self.issue)) {
dbItem.completionState = yasoon.outlook.task.completionState.Completed;
dbItem.completionPercent = 100;
} else if (dbItem.completionState == yasoon.outlook.task.completionState.Completed) {
@@ -1099,11 +1101,6 @@ function JiraIssueTask(issue) {
dbItem.completionPercent = 0;
}
- if (dbItem.externalId == 'DEMO-212') {
- window.demo212 = dbItem.body;
- console.log(dbItem.body);
- }
-
if (self.issue.fields.duedate) {
//We need to use momentJS to parse the date correctly
// Wunderlist JSON contains "2014-04-14"
@@ -1131,7 +1128,6 @@ function JiraIssueTask(issue) {
return jiraAddFolder(self.issue.fields.project.key, self.issue.fields.project.name, JSON.stringify(self.issue.fields.project), 'Jira');
})
.then(function () {
- console.log('Task save 3. Add? ' + creation, dbItem);
if (creation)
return jiraAddTask(dbItem, self.issue.fields.project.key);
else
@@ -1181,6 +1177,83 @@ function JiraIssueController() {
self.all = function () {
return issues;
};
+
+ self.isResolved = function isResolved(issue) {
+ if(issue.fields && issue.fields.resolution) {
+ return true;
+ }
+ return false;
+ };
}
+function JiraTaskController() {
+ var self = this;
+
+ this.handleTask = function handleTask(issue, task) {
+ return Promise.resolve()
+ .then(function () {
+ if (task)
+ return task;
+ else
+ return jiraGetTask(issue.key);
+ })
+ .then(function (dbTask) {
+ var taskIssue = new JiraIssueTask(issue);
+ if (taskIssue.isSyncNeeded()) {
+ return taskIssue.save();
+ } else if(dbTask){
+ return jiraRemoveTask(dbTask);
+ }
+ });
+ };
+
+ this.syncTasks = function () {
+ if (!jira.settings.syncTask) {
+ return Promise.resolve();
+ }
+
+ var updatedIssues = [];
+ var ownUserKey = jira.data.ownUser.key || jira.data.ownUser.name; //Depending on version >.<
+ var jql = 'assignee="' + ownUserKey + '" AND status != "resolved" AND status != "closed" AND status != "done" ORDER BY created DESC';
+ return jiraGet('/rest/api/2/search?jql=' + encodeURI(jql) + '&maxResults=200&expand=transitions,renderedFields')
+ .then(function (data) {
+ var ownIssues = JSON.parse(data);
+ if (ownIssues.total > 0) {
+ return ownIssues.issues;
+ }
+ return [];
+ })
+ .each(function (issue) {
+ return new JiraIssueTask(issue).save()
+ .then(function () {
+ updatedIssues.push(issue.key);
+ })
+ .catch(function (e) {
+ yasoon.util.log('Error while updating task' + e);
+ });
+ })
+ .then(function () {
+ //Check other way around and look for resolved or reassigned issues
+ return jiraAllFolders()
+ .each(function (folder) {
+ return jiraGetFolderTasks(folder.externalId)
+ .each(function (task) {
+ //First check if it has already been updated
+ if (updatedIssues.indexOf(task.externalId) > -1)
+ return;
+
+ //If we are here, we need to update the issue. it has either been assigned to someone else or it has been resolved
+ return jira.issues.get(task.externalId)
+ .then(function (issue) {
+ return jira.tasks.handleTask(issue, task);
+ })
+ .catch(function (e) {
+ yasoon.util.log('Error while removing task' + e);
+ });
+ });
+ });
+
+ });
+ };
+}
//@ sourceURL=http://Jira/notifications.js
\ No newline at end of file
diff --git a/com.yasoon.jira/templates/advancedIssueSearch.hbs b/com.yasoon.jira/templates/advancedIssueSearch.hbs
new file mode 100644
index 0000000..5268842
--- /dev/null
+++ b/com.yasoon.jira/templates/advancedIssueSearch.hbs
@@ -0,0 +1,46 @@
+
+
\ No newline at end of file