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