synergia-jira-connector
Version:
Easy to use NodeJS wrapper for the Jira REST API.
334 lines (303 loc) • 13.5 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: api/screens.js</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: api/screens.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>"use strict";
module.exports = ScreensClient;
/**
* Used to access Jira REST endpoints in '/rest/api/2/screens'
*
* @param {JiraClient} jiraClient
* @constructor ScreensClient
*/
function ScreensClient(jiraClient) {
this.jiraClient = jiraClient;
/**
* Gets available fields for screen. i.e ones that haven't already been added.
*
* @method getAvailableFields
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to Jira
* @param {number} opts.screenId The id of the screen to retrieve.
* @param callback Called when the available fields have been retrieved
*/
this.getAvailableFields = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/availableFields', 'GET');
this.jiraClient.makeRequest(options, callback);
};
/**
* Returns a list of all tabs for the given screen.
*
* @method getTabs
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to Jira
* @param {number} opts.screenId The id of the screen to retrieve.
* @param callback Called when the tabs have been retrieved.
*/
this.getTabs = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/tabs', 'GET');
this.jiraClient.makeRequest(options, callback);
};
/**
* Creates tab for given screen
*
* @method createTab
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to Jira
* @param {number} opts.screenId The id of the screen in which to create a tab.
* @param {string} opts.name The name of the tab to add. Minimum required to create a tab.
* @param callback Called when the tab has been created.
*/
this.createTab = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/tabs', 'POST', {name: opts.name});
this.jiraClient.makeRequest(options, callback);
};
/**
* Renames the given tab on the given screen.
*
* @method renameTab
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to the jira API
* @param {number} opts.screenId The id of the screen containing the tab to rename.
* @param {number} opts.tabId The id of the tab to rename
* @param {string} opts.name The new name of the tab.
* @param callback
*/
this.renameTab = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/tabs/' + opts.tabId, 'PUT', {name: opts.name});
this.jiraClient.makeRequest(options, callback);
};
/**
* Deletes the given tab from the given screen.
*
* @method deleteTab
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to the jira API
* @param {number} opts.screenId The id of the screen containing the tab to delete.
* @param {number} opts.tabId The id of the tab to delete
* @param callback
*/
this.deleteTab = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/tabs/' + opts.tabId, 'DELETE');
this.jiraClient.makeRequest(options, callback, 'Tab Deleted');
};
/**
* Adds field to the given tab
*
* @method addFieldToTab
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to the Jira API
* @param {number} opts.screenId The id of the screen containing the tab.
* @param {number} opts.tabId the id of the tab to which the fields will be added.
* @param {string} opts.fieldId The field to add
* @param callback Called when the fields have been added to the tab.
*/
this.addFieldToTab = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/tabs/' + opts.tabId + '/fields', 'POST', opts.fieldId);
this.jiraClient.makeRequest(options, callback);
};
/**
* Gets all fields for a given tab.
*
* @method getFieldsInTab
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to the Jira API
* @param {number} opts.screenId The id of the screen containing the tab.
* @param {number} opts.tabId the id of the tab for which to retrieve fields.
* @param callback Called when the fields have been retrieved.
*/
this.getFieldsInTab = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/tabs/' + opts.tabId + '/fields', 'GET');
this.jiraClient.makeRequest(options, callback);
};
/**
* Remove the given field from the given tab.
*
* @method removeFieldFromTab
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to the Jira API
* @param {number} opts.screenId The id of the screen containing the tab.
* @param {number} opts.tabId the id of the tab from which to remove the field.
* @param {string} opts.fieldId The id of the field to remove from the tab.
* @param callback Called when the field has been removed.
*/
this.removeFieldFromTab = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/tabs/' + opts.tabId + '/fields/' + opts.fieldId, 'DELETE');
this.jiraClient.makeRequest(options, callback, 'Field Removed From Tab');
};
/**
* Move the given field on the given tab
*
* @method moveFieldOnTab
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to the Jira API
* @param {number} opts.screenId The id of the screen containing the tab.
* @param {number} opts.tabId the id of the tab containing the field.
* @param {string} opts.fieldId The id of the field to remove from the tab.
* @param {number} opts.newPosition The position to which the field should be moved. May be one of:
* * Earlier
* * Later
* * First
* * Last
* @param callback Called when the field has been removed.
*/
this.moveFieldOnTab = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/tabs/' + opts.tabId + '/fields/' + opts.fieldId + '/move',
'POST', {position: opts.newPosition});
this.jiraClient.makeRequest(options, callback, 'Field Moved');
};
/**
* Moves tab position
*
* @method moveTabPosition
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to the Jira API.
* @param {number} opts.screenId The id of the screen containing the tab.
* @param {number} opts.tabId the id of the tab to move.
* @param {number} opts.newPosition The new (zero-indexed) position of the tab.
* @param callback Called when the tab has been moved.
*/
this.moveTabPosition = function (opts, callback) {
var options = this.buildRequestOptions(opts, '/tabs/' + opts.tabId + '/move/' + opts.newPosition, 'POST');
this.jiraClient.makeRequest(options, callback, 'Tab Moved');
};
/**
* Adds field or custom field to the default tab
*
* @method addFieldToDefaultTab
* @memberOf ScreensClient#
* @param {Object} opts The request options sent to the Jira API.
* @param {string} opts.fieldId The id of the field to add to the default tab.
* @param callback Called when the tab has been moved.
*/
this.addFieldToDefaultTab = function (opts, callback) {
var options = {
uri: this.jiraClient.buildURL('/screens/addToDefault/' + opts.fieldId),
method: 'POST',
json: true,
followAllRedirects: true
};
this.jiraClient.makeRequest(options, callback);
};
/**
* Build out the request options necessary to make a particular API call.
*
* @private
* @method buildRequestOptions
* @memberOf FilterClient#
* @param {Object} opts The arguments passed to the method.
* @param {number} opts.screenId The id of the screen to use in the path.
* @param {Array} [opts.fields] The fields to include
* @param {Array} [opts.expand] The fields to expand
* @param {string} path The path of the endpoint following /screen/{id}
* @param {string} method The request method.
* @param {Object} [body] The request body, if any.
* @param {Object} [qs] The querystring, if any. opts.expand and opts.fields arrays will be automagically added.
* @returns {{uri: string, method: string, body: Object, qs: Object, followAllRedirects: boolean, json: boolean}}
*/
this.buildRequestOptions = function (opts, path, method, body, qs) {
var basePath = '/screens/' + opts.screenId;
if (!qs) qs = {};
if (!body) body = {};
if (opts.fields) {
qs.fields = '';
opts.fields.forEach(function (field) {
qs.fields += field + ','
});
qs.fields = qs.fields.slice(0, -1);
}
if (opts.expand) {
qs.expand = '';
opts.expand.forEach(function (ex) {
qs.expand += ex + ','
});
qs.expand = qs.expand.slice(0, -1);
}
return {
uri: this.jiraClient.buildURL(basePath + path),
method: method,
body: body,
qs: qs,
followAllRedirects: true,
json: true
};
};
}</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2>
<h3>Classes</h3>
<ul>
<li><a href="ApplicationPropertiesClient.html">ApplicationPropertiesClient</a></li>
<li><a href="AttachmentClient.html">AttachmentClient</a></li>
<li><a href="AuditingClient.html">AuditingClient</a></li>
<li><a href="AvatarClient.html">AvatarClient</a></li>
<li><a href="CommentClient.html">CommentClient</a></li>
<li><a href="ComponentClient.html">ComponentClient</a></li>
<li><a href="CustomFieldOptionClient.html">CustomFieldOptionClient</a></li>
<li><a href="DashboardClient.html">DashboardClient</a></li>
<li><a href="FieldClient.html">FieldClient</a></li>
<li><a href="FilterClient.html">FilterClient</a></li>
<li><a href="GroupClient.html">GroupClient</a></li>
<li><a href="GroupsClient.html">GroupsClient</a></li>
<li><a href="GroupUserPickerClient.html">GroupUserPickerClient</a></li>
<li><a href="IssueClient.html">IssueClient</a></li>
<li><a href="IssueLinkClient.html">IssueLinkClient</a></li>
<li><a href="IssueLinkTypeClient.html">IssueLinkTypeClient</a></li>
<li><a href="IssueTypeClient.html">IssueTypeClient</a></li>
<li><a href="JiraClient.html">JiraClient</a></li>
<li><a href="JqlClient.html">JqlClient</a></li>
<li><a href="LicenseRoleClient.html">LicenseRoleClient</a></li>
<li><a href="LicenseValidatorClient.html">LicenseValidatorClient</a></li>
<li><a href="MyPermissionsClient.html">MyPermissionsClient</a></li>
<li><a href="MyPreferencesClient.html">MyPreferencesClient</a></li>
<li><a href="MyselfClient.html">MyselfClient</a></li>
<li><a href="PasswordClient.html">PasswordClient</a></li>
<li><a href="PriorityClient.html">PriorityClient</a></li>
<li><a href="ProjectCategoryClient.html">ProjectCategoryClient</a></li>
<li><a href="ProjectClient.html">ProjectClient</a></li>
<li><a href="ProjectValidateClient.html">ProjectValidateClient</a></li>
<li><a href="ReindexClient.html">ReindexClient</a></li>
<li><a href="ResolutionClient.html">ResolutionClient</a></li>
<li><a href="ScreensClient.html">ScreensClient</a></li>
<li><a href="SearchClient.html">SearchClient</a></li>
<li><a href="SecurityLevelClient.html">SecurityLevelClient</a></li>
<li><a href="ServerInfoClient.html">ServerInfoClient</a></li>
<li><a href="SettingsClient.html">SettingsClient</a></li>
<li><a href="StatusCategoryClient.html">StatusCategoryClient</a></li>
<li><a href="StatusClient.html">StatusClient</a></li>
<li><a href="UserClient.html">UserClient</a></li>
<li><a href="VersionClient.html">VersionClient</a></li>
<li><a href="WorkflowClient.html">WorkflowClient</a></li>
<li><a href="WorkflowSchemeClient.html">WorkflowSchemeClient</a></li>
</ul>
<h3>Namespaces</h3>
<ul>
<li><a href="OauthUtil.html">OauthUtil</a></li>
</ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha13</a> on Fri Oct 16 2015
13:33:15 GMT-0500 (CDT)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"></script>
</body>
</html>