1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-05 05:25:27 +02:00

Fetching Jira issues

This commit is contained in:
HarveyKandola 2018-08-07 19:15:25 +01:00
parent 7878a244d3
commit 0f9602e3a0
8 changed files with 196 additions and 334 deletions

View file

@ -9,9 +9,6 @@
//
// https://documize.com
import $ from 'jquery';
import { set } from '@ember/object';
import { schedule } from '@ember/runloop';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import SectionMixin from '../../../mixins/section';
@ -22,6 +19,7 @@ export default Component.extend(SectionMixin, TooltipMixin, {
isDirty: false,
waiting: false,
authenticated: false,
issuesGrid: '',
init() {
this._super(...arguments);
@ -48,96 +46,16 @@ export default Component.extend(SectionMixin, TooltipMixin, {
}
this.set('config', config);
// let self = this;
// self.set('waiting', true);
// this.get('sectionService').fetch(this.get('page'), "secrets", this.get('config'))
// .then(function (response) {
// self.set('waiting', false);
// self.set('config.APIKey', response.apikey);
// self.set('config.url', response.url);
// self.set('config.username', response.username);
// if (response.apikey.length > 0 && response.url.length > 0 && response.username.length > 0) {
// self.send('auth');
// }
// }, function (reason) { // eslint-disable-line no-unused-vars
// self.set('waiting', false);
// if (self.get('config.userId') > 0) {
// self.send('auth');
// }
// });
},
getWorkspaces() {
let page = this.get('page');
let self = this;
this.set('waiting', true);
this.get('sectionService').fetch(page, "workspace", this.get('config'))
.then(function (response) {
// console.log(response);
let workspaceId = self.get('config.workspaceId');
if (response.length > 0 && workspaceId === 0) {
workspaceId = response[0].Id;
}
self.set("config.workspaceId", workspaceId);
self.set('workspaces', response);
self.selectWorkspace(workspaceId);
schedule('afterRender', () => {
window.scrollTo(0, document.body.scrollHeight);
self.renderTooltips();
});
self.set('waiting', false);
}, function (reason) { // eslint-disable-line no-unused-vars
self.set('workspaces', []);
self.set('waiting', false);
});
},
getItems() {
let page = this.get('page');
let self = this;
this.set('waiting', true);
this.get('sectionService').fetch(page, "items", this.get('config'))
.then(function (response) {
if (self.get('isDestroyed') || self.get('isDestroying')) {
return;
}
self.set('items', response);
self.set('config.itemCount', response.length);
self.set('waiting', false);
}, function (reason) { // eslint-disable-line no-unused-vars
if (self.get('isDestroyed') || self.get('isDestroying')) {
return;
}
self.set('items', []);
self.set('waiting', false);
});
},
selectWorkspace(id) {
let self = this;
let w = this.get('workspaces');
w.forEach(function (w) {
set(w, 'selected', w.Id === id);
if (w.Id === id) {
self.set("config.filter", w.Filter);
self.set("config.workspaceId", id);
self.set("config.workspaceName", w.Title);
// console.log(self.get('config'));
}
this.get('sectionService').fetch(this.get('page'), "auth", this.get('config'))
.then((response) => { // eslint-disable-line no-unused-vars
this.set('authenticated', true);
this.set('waiting', false);
}, (reason) => { // eslint-disable-line no-unused-vars
this.set('authenticated', false);
this.set('waiting', false);
});
this.set('workspaces', w);
this.getItems();
},
actions: {
@ -145,55 +63,20 @@ export default Component.extend(SectionMixin, TooltipMixin, {
return this.get('isDirty');
},
auth() {
// missing data?
if (is.empty(this.get('config.url'))) {
$("#gemini-url").addClass("is-invalid").focus();
return;
}
if (is.empty(this.get('config.username'))) {
$("#gemini-username").addClass("is-invalid").focus();
return;
}
if (is.empty(this.get('config.APIKey'))) {
$("#gemini-apikey").addClass("is-invalid").focus();
return;
}
// knock out spaces
this.set('config.url', this.get('config.url').trim());
this.set('config.username', this.get('config.username').trim());
this.set('config.APIKey', this.get('config.APIKey').trim());
// remove trailing slash in URL
let url = this.get('config.url');
if (url.indexOf("/", url.length - 1) !== -1) {
this.set('config.url', url.substring(0, url.length - 1));
}
let page = this.get('page');
let self = this;
onPreview() {
this.set('waiting', true);
this.get('sectionService').fetch(page, "auth", this.get('config'))
.then(function (response) {
self.set('authenticated', true);
self.set('user', response);
self.set('config.userId', response.BaseEntity.id);
self.set('waiting', false);
self.getWorkspaces();
}, function (reason) { // eslint-disable-line no-unused-vars
self.set('authenticated', false);
self.set('user', null);
self.set('config.userId', 0);
self.set('waiting', false);
});
},
onWorkspaceChange(id) {
this.set('isDirty', true);
this.selectWorkspace(id);
this.get('sectionService').fetchText(this.get('page'), 'preview', this.get('config'))
.then((response) => { // eslint-disable-line no-unused-vars
this.set('issuesGrid', response);
this.set('authenticated', true);
this.set('waiting', false);
}, (reason) => { // eslint-disable-line no-unused-vars
console.log(reason);
this.set('issuesGrid', '');
this.set('authenticated', false);
this.set('waiting', false);
});
},
onCancel() {

View file

@ -9,16 +9,7 @@
//
// https://documize.com
import { inject as service } from '@ember/service';
import Controller from '@ember/controller';
export default Controller.extend({
orgService: service('organization'),
actions: {
save() {
return this.get('orgService').save(this.model.general).then(() => {
});
}
}
});

View file

@ -1 +1 @@
{{customize/integration-settings jira=jira}}
{{customize/integration-settings jira=model.jira}}

View file

@ -47,6 +47,8 @@ export default Service.extend({
getOrgSetting(orgId, key) {
return this.get('ajax').request(`organization/${orgId}/setting?key=${key}`, {
method: 'GET'
}).then((response) => {
return JSON.parse(response);
});
},

View file

@ -48,6 +48,20 @@ export default BaseService.extend({
});
},
// Requests data from the specified section handler, passing the method and document ID
// and POST payload.
fetchText(page, method, data) {
let documentId = page.get('documentId');
let section = page.get('contentType');
let url = `sections?documentID=${documentId}&section=${section}&method=${method}`;
return this.get('ajax').post(url, {
data: JSON.stringify(data),
contentType: "application/json",
dataType: "html"
});
},
// Did any dynamic sections change? Fetch and send up for rendering?
refresh(documentId) {
let url = `sections/refresh?documentID=${documentId}`;

View file

@ -3,3 +3,16 @@
padding: 0;
}
.section-jira-table {
font-size: 1rem;
width: auto !important;
a:hover {
text-decoration: underline;
}
}
.section-jira-icon {
height: 16px;
width: 16px;
}

View file

@ -1,12 +1,17 @@
{{#section/base-editor document=document folder=folder page=page busy=waiting tip="Jira issue tracking" isDirty=(action 'isDirty') onCancel=(action 'onCancel') onAction=(action 'onAction')}}
<div class="row">
<div class="col-12">
{{#unless authenticated}}
<p>Your Documize administrator needs to provide Jira connection details before usage.</p>
{{/unless}}
<div class="col-12 mb-5">
{{#if session.isAdmin}}
{{#link-to 'customize.integrations' class="btn btn-outline-secondary font-weight-bold"}}
Configire Jira Connector
{{/link-to}}
{{else}}
{{#unless authenticated}}
<p>Your Documize administrator needs to provide Jira connection details before usage.</p>
{{/unless}}
{{/if}}
</div>
</div>
@ -15,9 +20,15 @@
<div class="col-12">
<div class="form-group">
<label for="gemini-url">Jira Query Language</label>
{{focus-input id="jira-jql" type="text" value=config.query class="form-control"}}
{{focus-input id="jira-jql" type="text" value=config.jql class="form-control"}}
<small class="form-text text-muted">Find issues using JQL</small>
</div>
<button class="btn btn-secondary font-weight-bold" {{action 'onPreview'}}>Preview</button>
</div>
</div>
<div class="row my-5">
<div class="col-12">
{{{issuesGrid}}}
</div>
</div>
{{/if}}