github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/core/section/papertrail/model.go (about) 1 // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved. 2 // 3 // This software (Documize Community Edition) is licensed under 4 // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html 5 // 6 // You can operate outside the AGPL restrictions by purchasing 7 // Documize Enterprise Edition and obtaining a commercial license 8 // by contacting <sales@documize.com>. 9 // 10 // https://documize.com 11 12 package papertrail 13 14 import "strings" 15 16 // the HTML that is rendered by this section. 17 const renderTemplate = ` 18 {{if .HasData}} 19 <p class="margin-left-20">The <a href="https://papertrailapp.com">Papertrail log</a> for query <em>{{.Config.Query}}</em> contains {{.Count}} entries.</p> 20 <table class="basic-table section-papertrail-table"> 21 <thead> 22 <tr> 23 <th class="bordered no-width">Date</th> 24 <th class="bordered no-width">Severity</th> 25 <th class="bordered">Message</th> 26 </tr> 27 </thead> 28 <tbody> 29 {{range $item := .Events}} 30 <tr> 31 <td class="bordered no-width color-gray">{{ $item.Dated }}</td> 32 <td class="bordered no-width">{{ $item.Severity }}</td> 33 <td class="bordered width-90">{{ $item.Message }}</td> 34 </tr> 35 {{end}} 36 </tbody> 37 </table> 38 {{else}} 39 <p>There are no Papertrail log entries to see.</p> 40 {{end}} 41 ` 42 43 // Papertrail helpers 44 type papertrailRender struct { 45 Config papertrailConfig 46 Events []papertrailEvent 47 Count int 48 Authenticated bool 49 HasData bool 50 } 51 52 type papertrailSearch struct { 53 Events []papertrailEvent `json:"events"` 54 } 55 56 type papertrailEvent struct { 57 ID string `json:"id"` 58 Dated string `json:"display_received_at"` 59 Message string `json:"message"` 60 Severity string `json:"severity"` 61 } 62 63 type papertrailConfig struct { 64 APIToken string `json:"APIToken"` // only contains the correct token just after it is typed in 65 Query string `json:"query"` 66 Max int `json:"max"` 67 Group papertrailOption `json:"group"` 68 System papertrailOption `json:"system"` 69 } 70 71 func (c *papertrailConfig) Clean() { 72 c.APIToken = strings.TrimSpace(c.APIToken) 73 c.Query = strings.TrimSpace(c.Query) 74 } 75 76 type papertrailOption struct { 77 ID int `json:"id"` 78 Name string `json:"name"` 79 } 80 81 type papertrailOptions struct { 82 Groups []papertrailOption `json:"groups"` 83 Systems []papertrailOption `json:"systems"` 84 }