serialize creates a map from field to field values
(project *Project)
| 1761 | |
| 1762 | // serialize creates a map from field to field values |
| 1763 | func serializeProjectWithItems(project *Project) []map[string]interface{} { |
| 1764 | fields := make(map[string]string) |
| 1765 | |
| 1766 | // make a map of fields by ID |
| 1767 | for _, f := range project.Fields.Nodes { |
| 1768 | fields[f.ID()] = camelCase(f.Name()) |
| 1769 | } |
| 1770 | itemsSlice := make([]map[string]interface{}, 0) |
| 1771 | |
| 1772 | // for each value, look up the name by ID |
| 1773 | // and set the value to the field value |
| 1774 | for _, i := range project.Items.Nodes { |
| 1775 | o := make(map[string]interface{}) |
| 1776 | o["id"] = i.Id |
| 1777 | if projectItem := i.DetailedItem(); projectItem != nil { |
| 1778 | o["content"] = projectItem.ExportData(nil) |
| 1779 | } else { |
| 1780 | o["content"] = nil |
| 1781 | } |
| 1782 | for _, v := range i.FieldValues.Nodes { |
| 1783 | id := v.ID() |
| 1784 | value := projectFieldValueData(v) |
| 1785 | |
| 1786 | o[fields[id]] = value |
| 1787 | } |
| 1788 | itemsSlice = append(itemsSlice, o) |
| 1789 | } |
| 1790 | return itemsSlice |
| 1791 | } |
| 1792 | |
| 1793 | // camelCase converts a string to camelCase, which is useful for turning Go field names to JSON keys. |
| 1794 | func camelCase(s string) string { |
no test coverage detected