Merge branch 'bugfix/optional_modules' into 'develop'

Bugfix/optional modules

See merge request BPHV_MIPS/mvm_core!142
This commit is contained in:
Pfeil, Scott Robert 2021-02-08 10:08:12 -05:00
commit 847334d55a
3 changed files with 44 additions and 25 deletions

View File

@ -191,29 +191,32 @@
// Never use the cache.
completionHandler(nil,nil);
} else if (requestParameters.pageType.length != 0 && requestParameters.modules.count > 0) {
} else {
NSArray *modules = [requestParameters allModules];
if (requestParameters.pageType.length != 0 && modules.count > 0) {
// Check cache function for page json is already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
// Check cache function for page json is already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
// Check cache function for modules already in the cache.
NSDictionary *pageDictionary = jsonDictionary;
[[MVMCoreCache sharedCache] fetchJSONForModules:requestParameters.modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(pageDictionary,jsonDictionary);
// Check cache function for modules already in the cache.
NSDictionary *pageDictionary = jsonDictionary;
[[MVMCoreCache sharedCache] fetchJSONForModules:modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(pageDictionary,jsonDictionary);
}];
}];
}];
} else if (requestParameters.pageType.length != 0) {
} else if (requestParameters.pageType.length != 0) {
// Check cache function if page json is already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(jsonDictionary,nil);
}];
} else if (requestParameters.modules.count > 0) {
// Check cache function if modules already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForModules:requestParameters.modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(nil,jsonDictionary);
}];
// Check cache function if page json is already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(jsonDictionary,nil);
}];
} else if (modules > 0) {
// Check cache function if modules already in the cache.
[[MVMCoreCache sharedCache] fetchJSONForModules:modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
completionHandler(nil,jsonDictionary);
}];
}
}
}
@ -239,16 +242,21 @@
// Check if the page was found in the cache.
BOOL pageNotInCache = loadObject.operation.requestParameters.pageType && !loadObject.pageDataFromCache;
// Check all modules were found in the cache
// Check all required modules were found in the cache
NSMutableArray *modulesNotInCache = [NSMutableArray array];
for (NSString *module in loadObject.operation.requestParameters.modules) {
NSMutableArray *requiredModules = [NSMutableArray arrayWithArray:loadObject.operation.requestParameters.modules];
for (NSString *module in [loadObject.operation.requestParameters allModules]) {
if (![loadObject.modulesJSON objectForKey:module]) {
// Missing a module.
[modulesNotInCache addObject:module];
} else {
// Received a required module.
[requiredModules removeObject:module];
}
}
MVMCoreRequestParameters *requestParametersForServer = nil;
if (pageNotInCache || modulesNotInCache.count > 0) {
if (pageNotInCache || requiredModules.count > 0) {
// We are missing data, will need to go to server.
requestParametersForServer = [loadObject.operation.requestParameters copy];

View File

@ -29,7 +29,8 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) {
// request parameters
@property (nullable, strong, nonatomic) NSString *pageType;
@property (nullable, strong, nonatomic) NSArray *modules;
@property (nullable, strong, nonatomic) NSArray<NSString *> *optionalModules;
@property (nullable, strong, nonatomic) NSArray<NSString *> *modules;
@property (nullable, strong, nonatomic) NSDictionary *parameters;
@property (nullable, strong, nonatomic) NSData *imageData;
@ -120,4 +121,7 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) {
// Sets the load style based on the server sent presentationStyle
- (void)setMFLoadStyleBasedOnPresentationStyle:(nonnull NSString *)presentationStyle;
/// Returns optional and required modules
- (nullable NSArray<NSString *> *)allModules;
@end

View File

@ -33,7 +33,8 @@
- (nullable instancetype)initWithPageType:(nonnull NSString *)pageType extraParameters:(nullable NSDictionary *)extraParameters {
if (self = [self initWithExtraParameters:extraParameters]) {
self.pageType = pageType;
self.modules = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] allModulesForPageType:pageType];
self.optionalModules = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] modulesOptionalForPageType:pageType];
self.modules = [[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] modulesRequiredForPageType:pageType];
}
return self;
}
@ -116,12 +117,18 @@
}
}
- (nullable NSArray *)allModules {
NSMutableSet *set = [NSMutableSet setWithArray:self.optionalModules];
[set addObjectsFromArray:self.modules];
return [set allObjects];
}
- (id)copyWithZone:(nullable NSZone *)zone {
MVMCoreRequestParameters *copyObject = [[MVMCoreRequestParameters alloc] init];
copyObject.pageType = [self.pageType copy];
copyObject.parentPageType = self.parentPageType;
copyObject.optionalModules = [self.optionalModules copy];
copyObject.modules = [self.modules copy];
copyObject.parameters = [self.parameters copy];
copyObject.contextRoot = [self.contextRoot copy];