Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes working with favorite reports. After starting the example the Save button is added in the application window to save report settings and the Add to Favorites button is added, clicking which makes the current report a favorite one, and the first report in the favorites list is removed.
Executing the example requires to place the following code instead of the showReport method of the ViewController class (see the Displaying of Express Report section):
// Displays express report - (void)showReport:(UIViewController *)controller { // Create a toolbar UIToolbar *toolBar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 45)] autorelease]; // Determine button display settings NSDictionary *appearSettings = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Arial" size:14], UITextAttributeFont, nil]; // Create a button for saving report settings to file UIBarButtonItem *saveButton = [[[UIBarButtonItem alloc] initWithTitle: NSLocalizedString(@"SAVE", nil) style:UIBarButtonItemStyleBordered target:self action:@selector(save)] autorelease]; [saveButton setTitleTextAttributes:appearSettings forState:UIControlStateNormal]; // Create a button for saving report to favorites UIBarButtonItem *favoriteButton = [[[UIBarButtonItem alloc] initWithTitle: NSLocalizedString(@"ADD_TO_FAVORITE", nil) style:UIBarButtonItemStyleBordered target:self action:@selector(favorite)] autorelease]; [favoriteButton setTitleTextAttributes:appearSettings forState:UIControlStateNormal]; // Add button to toolbar [toolBar setItems: [NSArray arrayWithObjects: saveButton, favoriteButton, nil]]; [self.view addSubview:toolBar]; } // Saves report settings to file - (void) save { m_metabase->saveReport(m_olapReport); printf("Current time: %s\n", convertDate(NDate::date())); printf("Recent report saving time: %s\n", convertDate(m_olapReport->descriptor()->modifiedDate())); } // Transforms specified date to string const char * convertDate (SNDate date) { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"dd.MM.yyyy hh:mm:ss"]; NSString *stringFromDate = [formatter stringFromDate: (NSDate *)date->nsObject()]; [formatter release]; return NString::stringWithNSString(stringFromDate)->UTF8String(); } // Add report to favorites - (void) favorite { SPPLMetabaseRepositoryFavoriteDescriptor favorite = m_metabase->saveReportAsFavorite(m_olapReportDescriptor, NStr("FavoriteDashboardReport"), false); printf("Repository favorite object identifier: %s \n", favorite->objectId()->UTF8String()); printf("Repository favorite object name: %s \n", favorite->name()->UTF8String()); // Get array of all favorite reports SNArray favorites = m_metabase->favoriteDescriptors(); for (int i = 0; i < favorites->count() - 1; i++) { SPPLMetabaseRepositoryFavoriteDescriptor descriptor = favorites->objectAtIndex<PPLMetabaseRepositoryFavoriteDescriptor>(i); if (descriptor != NULL) { printf("Name: %s \n", descriptor->name()->UTF8String()); } } printf("Number of favorite repository reports before removal: %d \n", favorites->count()); // Remove first favorite report m_metabase->removeFavorite(favorites->objectAtIndex<PPLMetabaseRepositoryFavoriteDescriptor>(0)); printf("Number of favorite repository objects after removal: %d \n", m_metabase->favoriteDescriptors()->count()); }
After executing the example buttons for saving report saving to file and adding report to favorites are added. After pressing the Save Report button the development environment console displays the current time and recent report saving time.
Current time: 05.09.2014 10:15:12
Recent report saving time: 05.09.2014 10:15:12
After pressing the Add to Favorites button the development environment console displays identifier and name of the new favorite report, and also the total number of favorite repository objects before and after removal of the first of them:
Favorite repository object identifier: OLAP_MOB_FavoriteDashboardReport_499A431FE591AE8DCC54490F8C2409B3
Favorite repository object name: FavoriteDashboardReport
Number of favorite repository objects before removal: 1
Number of favorite repository objects after removal: 0
Identical result is obtained if replace the string in the favorite method
SPPLMetabaseRepositoryFavoriteDescriptor favorite = m_metabase->saveReportAsFavorite(olapDescriptor, NStr("FavoriteDashboardReport"), false);
with the following string:
SPPLMetabaseRepositoryFavoriteDescriptor favorite = m_metabase->saveReportAsFavorite(m_olapReport, NStr("FavoriteDashboardReport"));
See also: