Skip to content

Commit

Permalink
Implemented Previous and Next run buttons.
Browse files Browse the repository at this point in the history
Fixed bug - runs in the DB are 0 indexed; in the UI they are 1 based
Cater for missing message tag - replace with a single space
  • Loading branch information
Derek Knight committed Apr 25, 2015
1 parent b3b8222 commit 9fb2bfd
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
@interface LoggerMessageViewController ()
@property (nonatomic, retain) NSFetchedResultsController *messageFetchResultController;
@property (nonatomic, retain) NSDictionary *clientInfo;
@property NSInteger currentRun;
@property NSInteger runCount;
@property uLong currentClientHash;
-(void)readMessages:(NSNotification *)aNotification;
-(void)insertTableViewSection;
-(void)deleteTableViewSection;
Expand Down Expand Up @@ -108,6 +111,9 @@ - (void)viewDidLoad
self.toolBar.noiseBlendMode = kCGBlendModeMultiply;
self.toolBar.noiseOpacity = 0.1;

self.currentRun = -1;
self.runCount = -1;

#ifdef TEST_SHOW
[self readMessages:nil];
#endif
Expand Down Expand Up @@ -160,30 +166,34 @@ -(void)readMessages:(NSNotification *)aNotification

MTLog(@"userInfo %@",userInfo);

NSInteger runCount = [[userInfo objectForKey:kClientRunCount] integerValue];
self.runCount = [[userInfo objectForKey:kClientRunCount] integerValue];
self.currentRun = self.runCount;

self.clientInfo = nil;
self.clientInfo = userInfo;
self.currentClientHash = [[userInfo objectForKey:kClientHash] integerValue];

#endif
self.runCountLabel.text = \
[NSString stringWithFormat:
NSLocalizedString(@"Run %ld of %ld", nil),runCount+1,runCount+1];

[self enableRunControls];
[self fetchDataForRun:self.currentRun
withClientHash:self.currentClientHash];
}

self.previousRunButton.hidden = runCount < 0;
self.nextRunButton.hidden = YES;
- (void)enableRunControls
{
self.runCountLabel.text = \
[NSString stringWithFormat:
NSLocalizedString(@"Run %ld of %ld", nil),self.currentRun+1,self.runCount+1];

[self fetchDataForRun:runCount+1
notification:aNotification];
self.previousRunButton.hidden = self.currentRun <= 0;
self.nextRunButton.hidden = self.currentRun >= self.runCount;
}

- (void)fetchDataForRun:(NSInteger)run
notification:(NSNotification *)aNotification
withClientHash:(uLong)clientHash
{

NSDictionary *userInfo = [aNotification userInfo];

uLong clientHash = [[userInfo objectForKey:kClientHash] integerValue];

assert([self.dataManager messageDisplayContext] != nil);

if(_messageFetchResultController != nil)
Expand Down Expand Up @@ -277,6 +287,27 @@ -(void)deleteTableViewSection
deleteSections:indexSet
withRowAnimation:UITableViewRowAnimationAutomatic];
}
//------------------------------------------------------------------------------
#pragma mark Actions
//------------------------------------------------------------------------------
- (IBAction)didPressPreviousButton:(id)sender {
if (self.currentRun > 0) {
self.currentRun--;
[self enableRunControls];
[self fetchDataForRun:self.currentRun
withClientHash:self.currentClientHash];
}
}

- (IBAction)didPressNextButton:(id)sender {
if (self.currentRun < self.runCount) {
self.currentRun++;
[self enableRunControls];
[self fetchDataForRun:self.currentRun
withClientHash:self.currentClientHash];
}
}

//------------------------------------------------------------------------------
#pragma mark Timer Control
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -324,7 +355,8 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)aTableView
numberOfRowsInSection:(NSInteger)aSection
{
return [[self.messageFetchResultController fetchedObjects] count];
NSArray *records = [self.messageFetchResultController fetchedObjects];
return [records count];
}

- (UITableViewCell *)tableView:(UITableView *)aTableView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
<nil key="highlightedColor"/>
</label>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="22">
<rect key="frame" x="274" y="30" width="20" height="30"/>
<rect key="frame" x="274" y="30" width="30" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="20" id="62"/>
<constraint firstAttribute="width" constant="30" id="62"/>
<constraint firstAttribute="height" constant="30" id="63"/>
</constraints>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
Expand All @@ -86,12 +86,12 @@
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="didPressPreviousButton:" destination="-1" eventType="touchUpInside" id="fdH-YR-YJF"/>
</connections>
</button>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="21">
<rect key="frame" x="474" y="30" width="20" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="20" id="95"/>
</constraints>
<rect key="frame" x="464" y="30" width="30" height="30"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
<state key="normal" image="NSLoggerResource.bundle/button/center_next_run.png">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
Expand All @@ -100,6 +100,9 @@
<state key="highlighted">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="didPressNextButton:" destination="-1" eventType="touchUpInside" id="w1l-gO-V44"/>
</connections>
</button>
<searchBar hidden="YES" contentMode="redraw" translatesAutoresizingMaskIntoConstraints="NO" id="28">
<rect key="frame" x="576" y="13" width="178" height="44"/>
Expand All @@ -125,8 +128,6 @@
<constraint firstItem="29" firstAttribute="top" secondItem="20" secondAttribute="top" id="68"/>
<constraint firstAttribute="bottom" secondItem="26" secondAttribute="bottom" id="69"/>
<constraint firstItem="25" firstAttribute="trailing" secondItem="23" secondAttribute="trailing" id="70"/>
<constraint firstItem="22" firstAttribute="leading" secondItem="20" secondAttribute="leading" constant="274" id="71"/>
<constraint firstAttribute="trailing" secondItem="21" secondAttribute="trailing" constant="274" id="73"/>
<constraint firstItem="25" firstAttribute="leading" secondItem="23" secondAttribute="leading" id="74"/>
<constraint firstItem="26" firstAttribute="top" secondItem="25" secondAttribute="bottom" constant="8" symbolic="YES" id="77"/>
<constraint firstAttribute="trailing" secondItem="26" secondAttribute="trailing" id="78"/>
Expand All @@ -139,11 +140,14 @@
<constraint firstItem="27" firstAttribute="trailing" secondItem="28" secondAttribute="trailing" id="88"/>
<constraint firstItem="22" firstAttribute="centerY" secondItem="25" secondAttribute="centerY" id="1YG-qN-moE"/>
<constraint firstItem="23" firstAttribute="bottom" secondItem="25" secondAttribute="bottom" constant="-4" id="23H-Ky-4IA"/>
<constraint firstItem="25" firstAttribute="trailing" secondItem="21" secondAttribute="trailing" constant="10" id="8da-I0-Vrq"/>
<constraint firstItem="22" firstAttribute="width" secondItem="21" secondAttribute="width" id="HbE-E6-u8P"/>
<constraint firstItem="24" firstAttribute="leading" secondItem="25" secondAttribute="leading" id="X2I-G2-2sK"/>
<constraint firstItem="22" firstAttribute="height" secondItem="21" secondAttribute="height" id="YO3-p0-pR7"/>
<constraint firstAttribute="height" constant="79" id="ae2-hB-sih"/>
<constraint firstItem="24" firstAttribute="top" secondItem="25" secondAttribute="top" constant="4" id="gZ8-BJ-13m"/>
<constraint firstItem="24" firstAttribute="trailing" secondItem="25" secondAttribute="trailing" id="kfB-vM-bac"/>
<constraint firstItem="25" firstAttribute="leading" secondItem="22" secondAttribute="leading" constant="-10" id="lb0-Oj-AiL"/>
<constraint firstItem="25" firstAttribute="centerY" secondItem="21" secondAttribute="centerY" id="lrf-Ha-IwZ"/>
<constraint firstAttribute="centerX" secondItem="25" secondAttribute="centerX" id="rhk-Xz-m3k"/>
<constraint firstItem="25" firstAttribute="top" secondItem="20" secondAttribute="top" constant="20" id="vaX-TB-UGx"/>
Expand Down
5 changes: 4 additions & 1 deletion iPad Viewer/Views & Cells/MessageCell/LoggerMessageCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ -(void)setupForIndexpath:(NSIndexPath *)anIndexPath
NSInteger locTimestamp = 0;

//@@TODO:: timedelta

if (IS_NULL_STRING(aMessageData.tag)) aMessageData.tag = @" ";

NSInteger locTimedelta = locTimestamp + [aMessageData.timestampString length];
NSInteger locThread = locTimedelta;// + [aMessageData.timeDeltaString length];

Expand Down Expand Up @@ -345,7 +348,7 @@ -(void)setupForIndexpath:(NSIndexPath *)anIndexPath
CFAttributedStringReplaceString(as, CFRangeMake(locThread, 0), (CFStringRef)aMessageData.threadID);

// Place Tag
CFAttributedStringReplaceString(as, CFRangeMake(locTag, 0), (CFStringRef)aMessageData.tag);
CFAttributedStringReplaceString(as, CFRangeMake(locTag, 0), (CFStringRef)aMessageData.tag);

// Place level
CFAttributedStringReplaceString(as, CFRangeMake(locLevel, 0), (CFStringRef)[aMessageData.level stringValue]);
Expand Down

0 comments on commit 9fb2bfd

Please sign in to comment.