mirror of
https://github.com/documize/community.git
synced 2025-07-23 07:09:43 +02:00
Render Jira issues
This commit is contained in:
parent
0f9602e3a0
commit
7b178a76b2
3 changed files with 122 additions and 85 deletions
|
@ -145,7 +145,6 @@ func (p *Provider) Refresh(ctx *provider.Context, config, data string) (newData
|
||||||
}
|
}
|
||||||
|
|
||||||
j, err := json.Marshal(items)
|
j, err := json.Marshal(items)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.Runtime.Log.Error("unable to marshal gemini items", err)
|
p.Runtime.Log.Error("unable to marshal gemini items", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -49,73 +49,68 @@ func (*Provider) Meta() provider.TypeMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render converts Jira data into HTML suitable for browser rendering.
|
// Render converts Jira data into HTML suitable for browser rendering.
|
||||||
func (*Provider) Render(ctx *provider.Context, config, data string) string {
|
func (p *Provider) Render(ctx *provider.Context, config, data string) string {
|
||||||
return "<p>Something</p>"
|
// issues := []jira.Issue{}
|
||||||
|
// var c = jiraConfig{}
|
||||||
|
|
||||||
|
// json.Unmarshal([]byte(data), &issues)
|
||||||
|
// json.Unmarshal([]byte(config), &c)
|
||||||
|
|
||||||
|
var c = jiraConfig{}
|
||||||
|
err := json.Unmarshal([]byte(config), &c)
|
||||||
|
if err != nil {
|
||||||
|
p.Runtime.Log.Error("Unable to read Jira config", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
creds, err := getCredentials(ctx, p.Store)
|
||||||
|
if err != nil {
|
||||||
|
p.Runtime.Log.Error("unable to fetch Jira connector configuration", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
client, _, err := authenticate(creds)
|
||||||
|
if err != nil {
|
||||||
|
p.Runtime.Log.Error("unable to authenticate with Jira", err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
issues, err := getIssues(c, client)
|
||||||
|
|
||||||
|
return generateGrid(issues)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh fetches latest issues list.
|
// Refresh fetches latest issues list.
|
||||||
func (p *Provider) Refresh(ctx *provider.Context, config, data string) (newData string) {
|
func (p *Provider) Refresh(ctx *provider.Context, config, data string) (newData string) {
|
||||||
// var c = geminiConfig{}
|
var c = jiraConfig{}
|
||||||
// err := json.Unmarshal([]byte(config), &c)
|
err := json.Unmarshal([]byte(config), &c)
|
||||||
|
if err != nil {
|
||||||
|
p.Runtime.Log.Error("Unable to read Jira config", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// if err != nil {
|
creds, err := getCredentials(ctx, p.Store)
|
||||||
// p.Runtime.Log.Error("Unable to read Gemini config", err)
|
if err != nil {
|
||||||
// return
|
p.Runtime.Log.Error("unable to fetch Jira connector configuration", err)
|
||||||
// }
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// c.Clean(ctx, p.Store)
|
client, _, err := authenticate(creds)
|
||||||
|
if err != nil {
|
||||||
|
p.Runtime.Log.Error("unable to authenticate with Jira", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// if len(c.URL) == 0 {
|
issues, err := getIssues(c, client)
|
||||||
// p.Runtime.Log.Info("Gemini.Refresh received empty URL")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if len(c.Username) == 0 {
|
j, err := json.Marshal(issues)
|
||||||
// p.Runtime.Log.Info("Gemini.Refresh received empty username")
|
if err != nil {
|
||||||
// return
|
p.Runtime.Log.Error("unable to marshal Jira items", err)
|
||||||
// }
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// if len(c.APIKey) == 0 {
|
newData = string(j)
|
||||||
// p.Runtime.Log.Info("Gemini.Refresh received empty API key")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/items/card/%d", c.URL, c.WorkspaceID), nil)
|
|
||||||
// // req.Header.Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
// creds := []byte(fmt.Sprintf("%s:%s", c.Username, c.APIKey))
|
|
||||||
// req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString(creds))
|
|
||||||
|
|
||||||
// client := &http.Client{}
|
|
||||||
// res, err := client.Do(req)
|
|
||||||
|
|
||||||
// if err != nil {
|
|
||||||
// fmt.Println(err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if res.StatusCode != http.StatusOK {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// defer res.Body.Close()
|
|
||||||
// var items []geminiItem
|
|
||||||
|
|
||||||
// dec := json.NewDecoder(res.Body)
|
|
||||||
// err = dec.Decode(&items)
|
|
||||||
// if err != nil {
|
|
||||||
// p.Runtime.Log.Error("unable to Decode gemini items", err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// j, err := json.Marshal(items)
|
|
||||||
|
|
||||||
// if err != nil {
|
|
||||||
// p.Runtime.Log.Error("unable to marshal gemini items", err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// newData = string(j)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,8 +125,10 @@ func (p *Provider) Command(ctx *provider.Context, w http.ResponseWriter, r *http
|
||||||
}
|
}
|
||||||
|
|
||||||
switch method {
|
switch method {
|
||||||
case "preview":
|
case "previewIssues":
|
||||||
preview(ctx, p.Store, w, r)
|
previewIssues(ctx, p.Store, w, r)
|
||||||
|
case "previewGrid":
|
||||||
|
previewGrid(ctx, p.Store, w, r)
|
||||||
case "auth":
|
case "auth":
|
||||||
auth(ctx, p.Store, w, r)
|
auth(ctx, p.Store, w, r)
|
||||||
}
|
}
|
||||||
|
@ -155,7 +152,33 @@ func auth(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *
|
||||||
provider.WriteJSON(w, "OK")
|
provider.WriteJSON(w, "OK")
|
||||||
}
|
}
|
||||||
|
|
||||||
func preview(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) {
|
func previewIssues(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) {
|
||||||
|
creds, err := getCredentials(ctx, store)
|
||||||
|
if err != nil {
|
||||||
|
provider.WriteForbidden(w)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client, _, err := authenticate(creds)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
provider.WriteError(w, logID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
config, err := readConfig(ctx, store, w, r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
provider.WriteError(w, logID, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
issues, err := getIssues(config, client)
|
||||||
|
|
||||||
|
provider.WriteJSON(w, issues)
|
||||||
|
}
|
||||||
|
|
||||||
|
func previewGrid(ctx *provider.Context, store *domain.Store, w http.ResponseWriter, r *http.Request) {
|
||||||
creds, err := getCredentials(ctx, store)
|
creds, err := getCredentials(ctx, store)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
provider.WriteForbidden(w)
|
provider.WriteForbidden(w)
|
||||||
|
@ -245,16 +268,18 @@ func generateGrid(issues []jira.Issue) string {
|
||||||
payload.Issues = issues
|
payload.Issues = issues
|
||||||
|
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
t.Execute(buffer, payload)
|
err := t.Execute(buffer, payload)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Jira render error", err)
|
||||||
|
}
|
||||||
|
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type jiraConfig struct {
|
type jiraConfig struct {
|
||||||
JQL string `json:"jql"`
|
JQL string `json:"jql"`
|
||||||
ItemCount int `json:"itemCount"`
|
ItemCount int `json:"itemCount"`
|
||||||
Filter map[string]interface{} `json:"filter"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type jiraLogin struct {
|
type jiraLogin struct {
|
||||||
|
@ -270,7 +295,7 @@ type jiraGrid struct {
|
||||||
|
|
||||||
// the HTML that is rendered by this section.
|
// the HTML that is rendered by this section.
|
||||||
const renderTemplate = `
|
const renderTemplate = `
|
||||||
<p>Showing {{.ItemCount}} Jira issues</p>
|
<p>{{.ItemCount}} items</p>
|
||||||
<table class="basic-table section-jira-table">
|
<table class="basic-table section-jira-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -20,6 +20,7 @@ export default Component.extend(SectionMixin, TooltipMixin, {
|
||||||
waiting: false,
|
waiting: false,
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
issuesGrid: '',
|
issuesGrid: '',
|
||||||
|
issuesList: null,
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
@ -52,48 +53,60 @@ export default Component.extend(SectionMixin, TooltipMixin, {
|
||||||
.then((response) => { // eslint-disable-line no-unused-vars
|
.then((response) => { // eslint-disable-line no-unused-vars
|
||||||
this.set('authenticated', true);
|
this.set('authenticated', true);
|
||||||
this.set('waiting', false);
|
this.set('waiting', false);
|
||||||
|
|
||||||
|
this.generatePreview();
|
||||||
}, (reason) => { // eslint-disable-line no-unused-vars
|
}, (reason) => { // eslint-disable-line no-unused-vars
|
||||||
this.set('authenticated', false);
|
this.set('authenticated', false);
|
||||||
this.set('waiting', false);
|
this.set('waiting', false);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
generatePreview() {
|
||||||
|
this.set('waiting', true);
|
||||||
|
|
||||||
|
this.get('sectionService').fetch(this.get('page'), 'previewIssues', this.get('config'))
|
||||||
|
.then((response) => { // eslint-disable-line no-unused-vars
|
||||||
|
this.set('issuesList', response);
|
||||||
|
this.set('authenticated', true);
|
||||||
|
this.set('waiting', false);
|
||||||
|
|
||||||
|
this.get('sectionService').fetchText(this.get('page'), 'previewGrid', this.get('config'))
|
||||||
|
.then((response) => { // eslint-disable-line no-unused-vars
|
||||||
|
this.set('issuesGrid', response);
|
||||||
|
}, (reason) => { // eslint-disable-line no-unused-vars
|
||||||
|
console.log(reason); // eslint-disable-line no-console
|
||||||
|
this.set('issuesGrid', '');
|
||||||
|
});
|
||||||
|
}, (reason) => { // eslint-disable-line no-unused-vars
|
||||||
|
console.log(reason); // eslint-disable-line no-console
|
||||||
|
this.set('issuesList', []);
|
||||||
|
this.set('authenticated', false);
|
||||||
|
this.set('waiting', false);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
isDirty() {
|
isDirty() {
|
||||||
return this.get('isDirty');
|
return this.get('isDirty');
|
||||||
},
|
},
|
||||||
|
|
||||||
onPreview() {
|
onPreview() {
|
||||||
this.set('waiting', true);
|
this.generatePreview();
|
||||||
|
|
||||||
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() {
|
onCancel() {
|
||||||
let cb = this.get('onCancel');
|
this.get('onCancel')();
|
||||||
cb();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onAction(title) {
|
onAction(title) {
|
||||||
let page = this.get('page');
|
let page = this.get('page');
|
||||||
let meta = this.get('meta');
|
let meta = this.get('meta');
|
||||||
page.set('title', title);
|
page.set('title', title);
|
||||||
meta.set('rawBody', JSON.stringify(this.get("items")));
|
meta.set('rawBody', JSON.stringify(this.get("issuesList")));
|
||||||
meta.set('config', JSON.stringify(this.get('config')));
|
meta.set('config', JSON.stringify(this.get('config')));
|
||||||
meta.set('externalSource', true);
|
meta.set('externalSource', true);
|
||||||
|
|
||||||
let cb = this.get('onAction');
|
this.get('onAction')(page, meta);
|
||||||
cb(page, meta);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue