~netlandish/links

64ad65a80f461c889f3b6137d20523e98cebf924 — Yader Velasquez 9 months ago ec597c7
Export for notes
Add unread, starred, note_hash columns
4 files changed, 34 insertions(+), 3 deletions(-)

M core/export.go
M models/models.go
M models/org_link.go
M templates/export_sample.html
M core/export.go => core/export.go +17 -1
@@ 22,6 22,7 @@ const (

type ExportElements struct {
	Links  []*models.ExportOrgLink   `json:"links"`
	Notes  []*models.ExportOrgLink   `json:"notes"`
	Shorts []*models.ExportLinkShort `json:"shorts"`
	Lists  []*models.ExportListing   `json:"lists"`
}


@@ 29,7 30,10 @@ type ExportElements struct {
func Export(c echo.Context, org *models.Organization, format int) error {
	elements := &ExportElements{}
	opts := &database.FilterOptions{
		Filter: sq.Eq{"ol.org_id": org.ID},
		Filter: sq.And{
			sq.Eq{"ol.org_id": org.ID},
			sq.Eq{"ol.type": models.OrgLinkType},
		},
	}
	links, err := models.ExportOrgLinks(c.Request().Context(), opts)
	if err != nil {


@@ 38,6 42,18 @@ func Export(c echo.Context, org *models.Organization, format int) error {
	elements.Links = links

	opts = &database.FilterOptions{
		Filter: sq.And{
			sq.Eq{"ol.org_id": org.ID},
			sq.Eq{"ol.type": models.NoteType},
		},
	}
	notes, err := models.ExportOrgLinks(c.Request().Context(), opts)
	if err != nil {
		return err
	}
	elements.Notes = notes

	opts = &database.FilterOptions{
		Filter: sq.Eq{"l.org_id": org.ID},
	}
	shorts, err := models.ExportLinkShorts(c.Request().Context(), opts)

M models/models.go => models/models.go +3 -0
@@ 336,6 336,9 @@ type ExportOrgLink struct {
	Description string      `db:"description" json:"description"`
	URL         string      `db:"url" json:"url"`
	Visibility  int         `db:"visibility" json:"visibility"`
	Unread      bool        `db:"unread" json:"unread"`
	Starred     bool        `db:"starred" json:"starred"`
	NoteHash    string      `db:"note_hash" json:"note_hash"`
	Tags        []ExportTag `db:"-" json:"tags"`
	CreatedOn   time.Time   `db:"created_on" json:"created_on"`
}

M models/org_link.go => models/org_link.go +4 -2
@@ 270,7 270,8 @@ func ExportOrgLinks(ctx context.Context, opts *database.FilterOptions) ([]*Expor
	if err := database.WithTx(ctx, database.TxOptionsRO, func(tx *sql.Tx) error {
		q := opts.GetBuilder(nil)
		rows, err := q.
			Columns("ol.id", "ol.title", "ol.url", "ol.description", "ol.visibility", "ol.created_on", "json_agg(t)::jsonb").
			Columns("ol.id", "ol.title", "ol.url", "ol.description", "ol.visibility",
				"ol.unread", "ol.starred", "ol.note_hash", "ol.created_on", "json_agg(t)::jsonb").
			From("org_links ol").
			LeftJoin("tag_links tl ON tl.org_link_id = ol.id").
			LeftJoin("tags t ON t.id = tl.tag_id").


@@ 290,7 291,8 @@ func ExportOrgLinks(ctx context.Context, opts *database.FilterOptions) ([]*Expor
		for rows.Next() {
			var o ExportOrgLink
			var tags string
			if err = rows.Scan(&o.ID, &o.Title, &o.URL, &o.Description, &o.Visibility, &o.CreatedOn, &tags); err != nil {
			if err = rows.Scan(&o.ID, &o.Title, &o.URL, &o.Description, &o.Visibility,
				&o.Unread, &o.Starred, &o.NoteHash, &o.CreatedOn, &tags); err != nil {
				return err
			}
			re := regexp.MustCompile(`(,\s)?null,?`)

M templates/export_sample.html => templates/export_sample.html +10 -0
@@ 16,6 16,16 @@
    </DL><p>
    {{end}}

    {{if .elements.Notes  }}
    <DT><H3 FOLDED ADD_DATE="0">Notes</H3>
    <DL><p>
        {{range .elements.Notes}}
            <DT><A HREF="{{.URL}}" ADD_DATE="{{.CreatedOn}}">{{.Title}}</A>
            <DD>{{.Description}}
        {{end}}
    </DL><p>
    {{end}}

    {{if .elements.Shorts  }}
    <DT><H3 FOLDED ADD_DATE="0">Shorts</H3>
    <DL><p>