diff --git a/src/migration/migrations/2024-06-30T233630Z_AddPrimaryToLinks.go b/src/migration/migrations/2024-06-30T233630Z_AddPrimaryToLinks.go new file mode 100644 index 00000000..c0dae0e7 --- /dev/null +++ b/src/migration/migrations/2024-06-30T233630Z_AddPrimaryToLinks.go @@ -0,0 +1,48 @@ +package migrations + +import ( + "context" + "time" + + "git.handmade.network/hmn/hmn/src/migration/types" + "git.handmade.network/hmn/hmn/src/utils" + "github.com/jackc/pgx/v5" +) + +func init() { + registerMigration(AddPrimaryToLinks{}) +} + +type AddPrimaryToLinks struct{} + +func (m AddPrimaryToLinks) Version() types.MigrationVersion { + return types.MigrationVersion(time.Date(2024, 6, 30, 23, 36, 30, 0, time.UTC)) +} + +func (m AddPrimaryToLinks) Name() string { + return "AddPrimaryToLinks" +} + +func (m AddPrimaryToLinks) Description() string { + return "Adds 'primary_link' field to links" +} + +func (m AddPrimaryToLinks) Up(ctx context.Context, tx pgx.Tx) error { + utils.Must1(tx.Exec(ctx, + ` + ALTER TABLE link + ADD COLUMN primary_link BOOLEAN NOT NULL DEFAULT false; + `, + )) + return nil +} + +func (m AddPrimaryToLinks) Down(ctx context.Context, tx pgx.Tx) error { + utils.Must1(tx.Exec(ctx, + ` + ALTER TABLE link + DROP COLUMN primary_link; + `, + )) + return nil +} diff --git a/src/models/link.go b/src/models/link.go index 5f9ea617..274347d9 100644 --- a/src/models/link.go +++ b/src/models/link.go @@ -5,6 +5,7 @@ type Link struct { Name string `db:"name"` URL string `db:"url"` Ordering int `db:"ordering"` + Primary bool `db:"primary_link"` UserID *int `db:"user_id"` ProjectID *int `db:"project_id"` } diff --git a/src/templates/mapping.go b/src/templates/mapping.go index b68ca178..c513a52b 100644 --- a/src/templates/mapping.go +++ b/src/templates/mapping.go @@ -335,6 +335,7 @@ func LinkToTemplate(link *models.Link) Link { ServiceName: service.Name, Icon: service.IconName, Username: username, + Primary: link.Primary, } } diff --git a/src/templates/src/include/link_editor.html b/src/templates/src/include/link_editor.html new file mode 100644 index 00000000..acb4baf7 --- /dev/null +++ b/src/templates/src/include/link_editor.html @@ -0,0 +1,177 @@ +
+ diff --git a/src/templates/src/project_edit.html b/src/templates/src/project_edit.html index 8c7c25f4..9ec86e09 100644 --- a/src/templates/src/project_edit.html +++ b/src/templates/src/project_edit.html @@ -155,32 +155,7 @@ {{ end }} - + {{ template "link_editor.html" .ProjectSettings.LinksJSON }} {{ if and .Editing .User.IsStaff }} - + {{ template "link_editor.html" .LinksJSON }}