Refuse to save or fix wrong closing spans.

This commit is contained in:
Sergey Magidovich 2016-05-10 13:13:48 +03:00 committed by Vladimir Byko-Ianko
parent f4866551aa
commit a1edf3069a
2 changed files with 27 additions and 20 deletions

View file

@ -16,16 +16,14 @@
<subviews>
<button opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="DPW-UE-5UN">
<rect key="frame" x="0.0" y="0.0" width="320" height="42"/>
<fontDescription key="fontDescription" name="HelveticaNeue" family="Helvetica Neue" pointSize="17"/>
<state key="normal" title="Add Hours Closed">
<color key="titleColor" red="0.1176470588" green="0.58823529409999997" blue="0.94117647059999998" alpha="1" colorSpace="calibratedRGB"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<state key="normal" title="Add Hours Closed"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="fontName" value="regular17"/>
<userDefinedRuntimeAttribute type="string" keyPath="textColorName" value="linkBlue"/>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="editor_time_add_closed"/>
<userDefinedRuntimeAttribute type="string" keyPath="textColorHighlightedName" value="linkBlueHighlighted"/>
<userDefinedRuntimeAttribute type="string" keyPath="textColorDisabledName" value="linkBlueHighlighted"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="addClosedTap" destination="KGk-i7-Jjw" eventType="touchUpInside" id="HxR-3Y-SiG"/>

View file

@ -118,31 +118,42 @@ using namespace osmoh;
return dateComponentsFromTime(isStart ? span.GetStart() : span.GetEnd());
}
- (void)setTime:(NSDateComponents *)time isStart:(BOOL)isStart isClosed:(BOOL)isClosed
- (void)setStartTime:(NSDateComponents *)startTime endTime:(NSDateComponents *)endTime isClosed:(BOOL)isClosed
{
if (!time)
if (!startTime && !endTime)
return;
HourMinutes hm;
hm.SetHours(HourMinutes::THours(time.hour));
hm.SetMinutes(HourMinutes::TMinutes(time.minute));
TTimeTableProxy tt = [self getTimeTableProxy];
NSUInteger const row = self.selectedRow.unsignedIntegerValue;
NSUInteger const index = isClosed ? [self closedTimeIndex:row] : 0;
Timespan span = isClosed ? tt.GetExcludeTime()[index] : tt.GetOpeningTime();
if (isStart)
span.SetStart(hm);
else
span.SetEnd(hm);
if (startTime)
{
HourMinutes startHM;
startHM.SetHours(HourMinutes::THours(startTime.hour));
startHM.SetMinutes(HourMinutes::TMinutes(startTime.minute));
span.SetStart(startHM);
}
if (endTime)
{
HourMinutes endHM;
endHM.SetHours(HourMinutes::THours(endTime.hour));
endHM.SetMinutes(HourMinutes::TMinutes(endTime.minute));
span.SetEnd(endHM);
}
NSUInteger const closedTimesCountBeforeUpdate = [self closedTimesCount];
if (isClosed)
tt.ReplaceExcludeTime(span, index);
{
if (!tt.ReplaceExcludeTime(span, index))
tt.RemoveExcludeTime(index);
}
else
{
tt.SetOpeningTime(span);
}
tt.Commit();
[self refresh:closedTimesCountBeforeUpdate != [self closedTimesCount]];
@ -378,12 +389,10 @@ using namespace osmoh;
switch ([self cellKeyForRow:self.selectedRow.unsignedIntegerValue])
{
case MWMOpeningHoursEditorTimeSpanCell:
[self setTime:self.cachedStartTime isStart:YES isClosed:NO];
[self setTime:self.cachedEndTime isStart:NO isClosed:NO];
[self setStartTime:self.cachedStartTime endTime:self.cachedEndTime isClosed:NO];
break;
case MWMOpeningHoursEditorClosedSpanCell:
[self setTime:self.cachedStartTime isStart:YES isClosed:YES];
[self setTime:self.cachedEndTime isStart:NO isClosed:YES];
[self setStartTime:self.cachedStartTime endTime:self.cachedEndTime isClosed:YES];
break;
default:
NSAssert(false, @"Invalid case");