HTTP library users will now see the generic fields in the components' properties in the correct order as submitted by the API.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/17584
This commit is contained in:
parent
315ad0e071
commit
058b337b00
|
@ -204,7 +204,7 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json response = nlohmann::json::parse( res );
|
nlohmann::ordered_json response = nlohmann::ordered_json::parse( res );
|
||||||
std::string key = "";
|
std::string key = "";
|
||||||
std::string value = "";
|
std::string value = "";
|
||||||
|
|
||||||
|
@ -253,6 +253,9 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
|
||||||
aFetchedPart.exclude_from_sim = boolFromString( exclude, false );
|
aFetchedPart.exclude_from_sim = boolFromString( exclude, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove previously loaded fields
|
||||||
|
aFetchedPart.fields.clear();
|
||||||
|
|
||||||
// Extract available fields
|
// Extract available fields
|
||||||
for( const auto& field : response.at( "fields" ).items() )
|
for( const auto& field : response.at( "fields" ).items() )
|
||||||
{
|
{
|
||||||
|
@ -274,10 +277,8 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add field to fields list
|
// Add field to fields list
|
||||||
if( key.length() )
|
aFetchedPart.fields.push_back(
|
||||||
{
|
std::make_pair( key, std::make_tuple( value, visible ) ) );
|
||||||
aFetchedPart.fields[key] = std::make_tuple( value, visible );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( const std::exception& e )
|
catch( const std::exception& e )
|
||||||
|
@ -321,8 +322,6 @@ bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory,
|
||||||
res = curl->GetBuffer();
|
res = curl->GetBuffer();
|
||||||
|
|
||||||
nlohmann::json response = nlohmann::json::parse( res );
|
nlohmann::json response = nlohmann::json::parse( res );
|
||||||
std::string key = "";
|
|
||||||
std::string value = "";
|
|
||||||
|
|
||||||
for( nlohmann::json& item : response )
|
for( nlohmann::json& item : response )
|
||||||
{
|
{
|
||||||
|
@ -334,7 +333,8 @@ bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory,
|
||||||
if( item.contains( "description" ) )
|
if( item.contains( "description" ) )
|
||||||
{
|
{
|
||||||
// At this point we don't display anything so just set it to false
|
// At this point we don't display anything so just set it to false
|
||||||
part.fields["description"] = std::make_tuple( item.at( "description" ), false );
|
part.fields.push_back( std::make_pair(
|
||||||
|
"description", std::make_tuple( item.at( "description" ), false ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// API might not want to return an optional name.
|
// API might not want to return an optional name.
|
||||||
|
|
|
@ -54,7 +54,8 @@ struct HTTP_LIB_PART
|
||||||
|
|
||||||
std::time_t lastCached = 0;
|
std::time_t lastCached = 0;
|
||||||
|
|
||||||
std::map<std::string, std::tuple<std::string, bool>> fields; ///< additional generic fields
|
std::vector<std::pair<std::string, std::tuple<std::string, bool>>>
|
||||||
|
fields; ///< additional generic fields
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue