()
| 260 | } |
| 261 | |
| 262 | func (page *Page) Serialize() string { |
| 263 | |
| 264 | pageData := "{}" |
| 265 | |
| 266 | pageData, _ = sjson.Set(pageData, "id", page.ID) |
| 267 | pageData, _ = sjson.Set(pageData, "pan", page.Pan) |
| 268 | pageData, _ = sjson.Set(pageData, "zoom", page.Zoom) |
| 269 | |
| 270 | // Sort the cards by their position so the serialization is more stable. (Otherwise, clicking on |
| 271 | // a Card adjusts the sort order, and therefore the order in which Cards are serialized.) |
| 272 | cards := append([]*Card{}, page.Cards...) |
| 273 | |
| 274 | sort.Slice(cards, func(i, j int) bool { |
| 275 | return cards[i].Rect.Y < cards[j].Rect.Y || (cards[i].Rect.Y == cards[j].Rect.Y && cards[i].Rect.X < cards[j].Rect.X) |
| 276 | }) |
| 277 | |
| 278 | for _, card := range cards { |
| 279 | pageData, _ = sjson.SetRaw(pageData, "cards.-1", card.Serialize(true)) |
| 280 | } |
| 281 | |
| 282 | return pageData |
| 283 | |
| 284 | } |
| 285 | |
| 286 | func (page *Page) DeserializePageData(data string) { |
| 287 |
no test coverage detected