github.com/elliott5/community@v0.14.1-0.20160709191136-823126fb026a/documize/section/trello/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 trello
    13  
    14  import "strings"
    15  
    16  const renderTemplate = `
    17  <p class="non-printable-message">Non-printable</p>
    18  <div class="section-trello-render non-printable">
    19  	<p>There are {{ .CardCount }} cards across {{ .ListCount }} lists for board <a href="{{ .Board.URL }}">{{.Board.Name}}.</a></p>
    20  	<div class="trello-board" style="background-color: {{.Board.Prefs.BackgroundColor}}">
    21  		<a href="{{ .Board.URL }}"><div class="trello-board-title">{{.Board.Name}}</div></a>
    22  		{{range $data := .Data}}
    23  			<div class="trello-list">
    24  				<div class="trello-list-title">{{ $data.List.Name }}</div>
    25  				{{range $card := $data.Cards}}
    26  					<a href="{{ $card.URL }}">
    27  						<div class="trello-card">
    28  							{{ $card.Name }}
    29  						</div>
    30  					</a>
    31  				{{end}}
    32  			</div>
    33  		{{end}}
    34  	</div>
    35  </div>
    36  `
    37  
    38  type secrets struct {
    39  	Token  string `json:"token"`
    40  }
    41  
    42  type trelloConfig struct {
    43  	AppKey string       `json:"appKey"`
    44  	Token  string       `json:"token"`
    45  	Board  trelloBoard  `json:"board"`
    46  	Lists  []trelloList `json:"lists"`
    47  }
    48  
    49  func (c *trelloConfig) Clean() {
    50  	c.AppKey = strings.TrimSpace(c.AppKey)
    51  	c.Token = strings.TrimSpace(c.Token)
    52  }
    53  
    54  // Trello objects based upon https://github.com/VojtechVitek/go-trello
    55  type trelloMember struct {
    56  	ID         string `json:"id"`
    57  	AvatarHash string `json:"avatarHash"`
    58  	Bio        string `json:"bio"`
    59  	BioData    struct {
    60  		Emoji interface{} `json:"emoji,omitempty"`
    61  	} `json:"bioData"`
    62  	Confirmed                bool     `json:"confirmed"`
    63  	FullName                 string   `json:"fullName"`
    64  	PremOrgsAdminID          []string `json:"idPremOrgsAdmin"`
    65  	Initials                 string   `json:"initials"`
    66  	MemberType               string   `json:"memberType"`
    67  	Products                 []int    `json:"products"`
    68  	Status                   string   `json:"status"`
    69  	URL                      string   `json:"url"`
    70  	Username                 string   `json:"username"`
    71  	AvatarSource             string   `json:"avatarSource"`
    72  	Email                    string   `json:"email"`
    73  	GravatarHash             string   `json:"gravatarHash"`
    74  	BoardsID                 []string `json:"idBoards"`
    75  	BoardsPinnedID           []string `json:"idBoardsPinned"`
    76  	OrganizationsID          []string `json:"idOrganizations"`
    77  	LoginTypes               []string `json:"loginTypes"`
    78  	NewEmail                 string   `json:"newEmail"`
    79  	OneTimeMessagesDismissed []string `json:"oneTimeMessagesDismissed"`
    80  	Prefs                    struct {
    81  		SendSummaries                 bool   `json:"sendSummaries"`
    82  		MinutesBetweenSummaries       int    `json:"minutesBetweenSummaries"`
    83  		MinutesBeforeDeadlineToNotify int    `json:"minutesBeforeDeadlineToNotify"`
    84  		ColorBlind                    bool   `json:"colorBlind"`
    85  		Locale                        string `json:"locale"`
    86  	} `json:"prefs"`
    87  	Trophies           []string `json:"trophies"`
    88  	UploadedAvatarHash string   `json:"uploadedAvatarHash"`
    89  	PremiumFeatures    []string `json:"premiumFeatures"`
    90  }
    91  
    92  type trelloBoard struct {
    93  	ID             string `json:"id"`
    94  	Name           string `json:"name"`
    95  	Closed         bool   `json:"closed"`
    96  	OrganizationID string `json:"idOrganization"`
    97  	Pinned         bool   `json:"pinned"`
    98  	URL            string `json:"url"`
    99  	ShortURL       string `json:"shortUrl"`
   100  	Desc           string `json:"desc"`
   101  	DescData       struct {
   102  		Emoji struct{} `json:"emoji"`
   103  	} `json:"descData"`
   104  	Prefs struct {
   105  		PermissionLevel       string                  `json:"permissionLevel"`
   106  		Voting                string                  `json:"voting"`
   107  		Comments              string                  `json:"comments"`
   108  		Invitations           string                  `json:"invitations"`
   109  		SelfJoin              bool                    `json:"selfjoin"`
   110  		CardCovers            bool                    `json:"cardCovers"`
   111  		CardAging             string                  `json:"cardAging"`
   112  		CalendarFeedEnabled   bool                    `json:"calendarFeedEnabled"`
   113  		Background            string                  `json:"background"`
   114  		BackgroundColor       string                  `json:"backgroundColor"`
   115  		BackgroundImage       string                  `json:"backgroundImage"`
   116  		BackgroundImageScaled []trelloBoardBackground `json:"backgroundImageScaled"`
   117  		BackgroundTile        bool                    `json:"backgroundTile"`
   118  		BackgroundBrightness  string                  `json:"backgroundBrightness"`
   119  		CanBePublic           bool                    `json:"canBePublic"`
   120  		CanBeOrg              bool                    `json:"canBeOrg"`
   121  		CanBePrivate          bool                    `json:"canBePrivate"`
   122  		CanInvite             bool                    `json:"canInvite"`
   123  	} `json:"prefs"`
   124  	LabelNames struct {
   125  		Red    string `json:"red"`
   126  		Orange string `json:"orange"`
   127  		Yellow string `json:"yellow"`
   128  		Green  string `json:"green"`
   129  		Blue   string `json:"blue"`
   130  		Purple string `json:"purple"`
   131  	} `json:"labelNames"`
   132  }
   133  
   134  type trelloBoardBackground struct {
   135  	Width  int    `json:"width"`
   136  	Height int    `json:"height"`
   137  	URL    string `json:"url"`
   138  }
   139  
   140  type trelloList struct {
   141  	ID       string  `json:"id"`
   142  	Name     string  `json:"name"`
   143  	Closed   bool    `json:"closed"`
   144  	BoardID  string  `json:"idBoard"`
   145  	Pos      float32 `json:"pos"`
   146  	Included bool    `json:"included"` // indicates whether we display cards from this list
   147  }
   148  
   149  type trelloCard struct {
   150  	ID                    string   `json:"id"`
   151  	Name                  string   `json:"name"`
   152  	Email                 string   `json:"email"`
   153  	ShortID               int      `json:"idShort"`
   154  	AttachmentCoverID     string   `json:"idAttachmentCover"`
   155  	CheckListsID          []string `json:"idCheckLists"`
   156  	BoardID               string   `json:"idBoard"`
   157  	ListID                string   `json:"idList"`
   158  	MembersID             []string `json:"idMembers"`
   159  	MembersVotedID        []string `json:"idMembersVoted"`
   160  	ManualCoverAttachment bool     `json:"manualCoverAttachment"`
   161  	Closed                bool     `json:"closed"`
   162  	Pos                   float32  `json:"pos"`
   163  	ShortLink             string   `json:"shortLink"`
   164  	DateLastActivity      string   `json:"dateLastActivity"`
   165  	ShortURL              string   `json:"shortUrl"`
   166  	Subscribed            bool     `json:"subscribed"`
   167  	URL                   string   `json:"url"`
   168  	Due                   string   `json:"due"`
   169  	Desc                  string   `json:"desc"`
   170  	DescData              struct {
   171  		Emoji struct{} `json:"emoji"`
   172  	} `json:"descData"`
   173  	CheckItemStates []struct {
   174  		CheckItemID string `json:"idCheckItem"`
   175  		State       string `json:"state"`
   176  	} `json:"checkItemStates"`
   177  	Badges struct {
   178  		Votes              int    `json:"votes"`
   179  		ViewingMemberVoted bool   `json:"viewingMemberVoted"`
   180  		Subscribed         bool   `json:"subscribed"`
   181  		Fogbugz            string `json:"fogbugz"`
   182  		CheckItems         int    `json:"checkItems"`
   183  		CheckItemsChecked  int    `json:"checkItemsChecked"`
   184  		Comments           int    `json:"comments"`
   185  		Attachments        int    `json:"attachments"`
   186  		Description        bool   `json:"description"`
   187  		Due                string `json:"due"`
   188  	} `json:"badges"`
   189  	Labels []struct {
   190  		Color string `json:"color"`
   191  		Name  string `json:"name"`
   192  	} `json:"labels"`
   193  }
   194  
   195  type trelloListCards struct {
   196  	List  trelloList
   197  	Cards []trelloCard
   198  }
   199  
   200  type trelloRender struct {
   201  	Board     trelloBoard
   202  	Data      []trelloListCards
   203  	CardCount int
   204  	ListCount int
   205  }