-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add poker story drag and drop arranging (#459)
This resolves #434
- Loading branch information
1 parent
69d2694
commit e1312e1
Showing
12 changed files
with
404 additions
and
113 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
db/migrations/20230820032023_add_poker_story_sorting.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
ALTER TABLE thunderdome.poker_story DROP COLUMN position; | ||
|
||
CREATE OR REPLACE PROCEDURE thunderdome.poker_story_delete(IN pokerid uuid, IN storyid uuid) | ||
LANGUAGE plpgsql | ||
AS $procedure$ | ||
DECLARE | ||
active_storyid UUID; | ||
BEGIN | ||
active_storyid := (SELECT b.active_story_id FROM thunderdome.poker b WHERE b.id = pokerid); | ||
DELETE FROM thunderdome.poker_story WHERE id = storyid; | ||
|
||
IF active_storyid = storyid THEN | ||
UPDATE thunderdome.poker SET last_active = NOW(), voting_locked = true, active_story_id = null | ||
WHERE id = pokerid; | ||
END IF; | ||
|
||
COMMIT; | ||
END$procedure$; |
46 changes: 46 additions & 0 deletions
46
db/migrations/20230820032023_add_poker_story_sorting.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
ALTER TABLE thunderdome.poker_story ADD COLUMN position DOUBLE PRECISION DEFAULT 0 NOT NULL; | ||
|
||
DO $$ DECLARE | ||
story RECORD; | ||
pid UUID; | ||
pos DOUBLE PRECISION = 0; | ||
BEGIN | ||
FOR story IN SELECT id, poker_id, created_date FROM thunderdome.poker_story ORDER BY poker_id, created_date | ||
LOOP | ||
IF pid IS NULL OR story.poker_id <> pid THEN | ||
pid = story.poker_id; | ||
pos = -1; | ||
END IF; | ||
pos = pos + 1; | ||
|
||
UPDATE thunderdome.poker_story SET position = pos WHERE id = story.id; | ||
END LOOP; | ||
END$$; | ||
|
||
ALTER TABLE thunderdome.poker_story ADD CONSTRAINT poker_story_poker_id_position UNIQUE (poker_id, position); | ||
|
||
CREATE OR REPLACE PROCEDURE thunderdome.poker_story_delete(IN pokerid uuid, IN storyid uuid) | ||
LANGUAGE plpgsql | ||
AS $procedure$ | ||
DECLARE | ||
active_storyid UUID; | ||
story RECORD; | ||
pos DOUBLE PRECISION = -1; | ||
BEGIN | ||
active_storyid := (SELECT b.active_story_id FROM thunderdome.poker b WHERE b.id = pokerid); | ||
DELETE FROM thunderdome.poker_story WHERE id = storyid; | ||
|
||
FOR story IN SELECT id, position FROM thunderdome.poker_story WHERE poker_id = pokerid ORDER BY position | ||
LOOP | ||
pos = pos + 1; | ||
|
||
UPDATE thunderdome.poker_story SET position = pos WHERE id = story.id; | ||
END LOOP; | ||
|
||
IF active_storyid = storyid THEN | ||
UPDATE thunderdome.poker SET last_active = NOW(), voting_locked = true, active_story_id = null | ||
WHERE id = pokerid; | ||
END IF; | ||
|
||
COMMIT; | ||
END$procedure$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.