| 59 | ankerl::unordered_dense::map<std::string, int> const kPriorityWeights = {{"high", 0}, {"", 1}, {"low", 2}}; |
| 60 | |
| 61 | bool TypeDescriptionFromXml(pugi::xml_node const & root, pugi::xml_node const & node, |
| 62 | editor::TypeAggregatedDescription & outDesc) |
| 63 | { |
| 64 | if (!node || strcmp(node.attribute("editable").value(), "no") == 0) |
| 65 | return false; |
| 66 | |
| 67 | auto const handleField = [&outDesc](std::string const & fieldName) |
| 68 | { |
| 69 | if (fieldName == "name") |
| 70 | { |
| 71 | outDesc.m_name = true; |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | if (fieldName == "street" || fieldName == "housenumber" || fieldName == "housename" || fieldName == "postcode") |
| 76 | { |
| 77 | outDesc.m_address = true; |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | if (fieldName == "cuisine") |
| 82 | { |
| 83 | outDesc.m_cuisine = true; |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | // TODO(mgsergio): Add support for non-metadata fields like atm, wheelchair, toilet etc. |
| 88 | auto const it = kNamesToFMD.find(fieldName); |
| 89 | |
| 90 | ASSERT(it != end(kNamesToFMD), ("Wrong field:", fieldName)); |
| 91 | outDesc.m_editableFields.push_back(it->second); |
| 92 | }; |
| 93 | |
| 94 | for (auto const & xNode : node.select_nodes("include[@group]")) |
| 95 | { |
| 96 | auto const node = xNode.node(); |
| 97 | std::string const groupName = node.attribute("group").value(); |
| 98 | |
| 99 | std::string const xpath = "/comaps/editor/fields/field_group[@name='" + groupName + "']"; |
| 100 | auto const group = root.select_node(xpath.data()).node(); |
| 101 | ASSERT(group, ("No such group", groupName)); |
| 102 | |
| 103 | for (auto const & fieldRefXName : group.select_nodes("field_ref/@name")) |
| 104 | { |
| 105 | auto const fieldName = fieldRefXName.attribute().value(); |
| 106 | handleField(fieldName); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | for (auto const & xNode : node.select_nodes("include[@field]")) |
| 111 | { |
| 112 | auto const node = xNode.node(); |
| 113 | std::string const fieldName = node.attribute("field").value(); |
| 114 | handleField(fieldName); |
| 115 | } |
| 116 | |
| 117 | // Ordered by Metadata::EType value, which is also satisfy fields importance. |
| 118 | base::SortUnique(outDesc.m_editableFields); |
no test coverage detected