serialize creates a map from field to field values
(project *Project)
| 1808 | |
| 1809 | // serialize creates a map from field to field values |
| 1810 | func serializeProjectWithItems(project *Project) []map[string]interface{} { |
| 1811 | fields := make(map[string]string) |
| 1812 | |
| 1813 | // make a map of fields by ID |
| 1814 | for _, f := range project.Fields.Nodes { |
| 1815 | fields[f.ID()] = camelCase(f.Name()) |
| 1816 | } |
| 1817 | itemsSlice := make([]map[string]interface{}, 0) |
| 1818 | |
| 1819 | // for each value, look up the name by ID |
| 1820 | // and set the value to the field value |
| 1821 | for _, i := range project.Items.Nodes { |
| 1822 | o := make(map[string]interface{}) |
| 1823 | o["id"] = i.Id |
| 1824 | if projectItem := i.DetailedItem(); projectItem != nil { |
| 1825 | o["content"] = projectItem.ExportData(nil) |
| 1826 | } else { |
| 1827 | o["content"] = nil |
| 1828 | } |
| 1829 | for _, v := range i.FieldValues.Nodes { |
| 1830 | id := v.ID() |
| 1831 | value := projectFieldValueData(v) |
| 1832 | |
| 1833 | o[fields[id]] = value |
| 1834 | } |
| 1835 | itemsSlice = append(itemsSlice, o) |
| 1836 | } |
| 1837 | return itemsSlice |
| 1838 | } |
| 1839 | |
| 1840 | // camelCase converts a string to camelCase, which is useful for turning Go field names to JSON keys. |
| 1841 | func camelCase(s string) string { |
no test coverage detected