// Copyright 2016 Documize Inc. . All rights reserved. // // This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license // by contacting . // // https://documize.com package gemini import ( "strings" "github.com/documize/community/core/log" "github.com/documize/community/core/section/provider" ) // the HTML that is rendered by this section. const renderTemplate = ` {{if .Authenticated}}

The Gemini workspace {{.Config.WorkspaceName}} contains {{.Config.ItemCount}} items.

{{$wid := .Config.WorkspaceID}} {{$app := .Config.URL}} {{range $item := .Items}} {{end}}
Item Key Title Type Status
{{ $item.IssueKey }} {{ $item.Title }}  {{ $item.Type }}  {{ $item.Status }}
{{else}}

Authenticate with Gemini to see items.

{{end}} ` // Gemini helpers type geminiRender struct { Config geminiConfig Items []geminiItem Authenticated bool } type geminiItem struct { ID int64 IssueKey string Title string Type string TypeImage string Status string StatusImage string } type geminiUser struct { BaseEntity struct { ID int `json:"id"` Username string `json:"username"` Firstname string `json:"firstname"` Surname string `json:"surname"` Email string `json:"email"` } } type geminiConfig struct { URL string `json:"url"` Username string `json:"username"` APIKey string `json:"apikey"` UserID int64 `json:"userId"` WorkspaceID int64 `json:"workspaceId"` WorkspaceName string `json:"workspaceName"` ItemCount int `json:"itemCount"` Filter map[string]interface{} `json:"filter"` } func (c *geminiConfig) Clean(ctx *provider.Context) { if ctx != nil { sec, err := getSecrets(ctx) if err == nil { if len(sec.APIKey) > 0 && len(sec.Username) > 0 && len(sec.URL) > 0 { c.APIKey = strings.TrimSpace(sec.APIKey) c.Username = strings.TrimSpace(sec.Username) c.URL = strings.TrimSpace(sec.URL) } } } c.APIKey = strings.TrimSpace(c.APIKey) c.Username = strings.TrimSpace(c.Username) c.URL = strings.TrimSpace(c.URL) } func (c *geminiConfig) SaveSecrets(ctx *provider.Context) { var sec secrets sec.APIKey = strings.TrimSpace(c.APIKey) sec.Username = strings.TrimSpace(c.Username) sec.URL = strings.TrimSpace(c.URL) log.IfErr(ctx.MarshalSecrets(sec)) } type secrets struct { URL string `json:"url"` Username string `json:"username"` APIKey string `json:"apikey"` } func getSecrets(ctx *provider.Context) (sec secrets, err error) { err = ctx.UnmarshalSecrets(&sec) return }