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 = '' + + '
'+ + ' ' + + ' ' + + //' advanced' + + ' ' + + '
'; + + $(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 = '' + ' + + +
+
+ +
+
+ +
+ + +
+ add +
+ + + + + + + + + \ No newline at end of file