1
00:00:01,440 --> 00:00:06,300
So now that we have all the information we need to render the information on the calendar, let's do

2
00:00:06,300 --> 00:00:08,100
so and we'll start with the blocks.

3
00:00:08,100 --> 00:00:15,270
So I'm going to go back to my template, which is right here, and find the part where I'm rendering

4
00:00:15,270 --> 00:00:16,910
the TD with a checkbox.

5
00:00:16,920 --> 00:00:23,070
So this input type equals checkbox is what appears right here on both of these rows.

6
00:00:23,460 --> 00:00:28,850
And I want to display a checked checkbox if there is a block and leave it unchecked.

7
00:00:28,860 --> 00:00:34,800
If there's not now, because this is a form, each of these inputs is going to have to have a meaningful

8
00:00:34,800 --> 00:00:35,370
name.

9
00:00:35,370 --> 00:00:38,660
And that's something I'll also take care of in this step.

10
00:00:38,700 --> 00:00:39,480
So let's get started.

11
00:00:40,170 --> 00:00:47,250
So right now, inside this range Rum's, I want to each time I iterate through this, pull the appropriate

12
00:00:47,250 --> 00:00:52,580
values for my reservation blocks, reservations and blocks out of my data variable.

13
00:00:52,590 --> 00:00:53,880
So let's do that to start with.

14
00:00:54,810 --> 00:01:02,670
So we'll create a variable called blocks and that will be equal to or assign the value of index from

15
00:01:02,670 --> 00:01:03,360
my data.

16
00:01:03,360 --> 00:01:07,490
And I can't just go data here because I'm inside this range.

17
00:01:07,860 --> 00:01:11,700
So this variable is not part of the rooms.

18
00:01:11,710 --> 00:01:17,820
So I need to tell somehow, tell the template, get the value of data from outside of this loop, and

19
00:01:17,820 --> 00:01:19,650
you do that by putting a dollar sign in front of it.

20
00:01:19,770 --> 00:01:27,630
So from index dollar sign dot data, I want to get the block map, which is name something like this

21
00:01:27,960 --> 00:01:29,310
block map.

22
00:01:31,680 --> 00:01:33,790
Underscore one for the first time through.

23
00:01:33,810 --> 00:01:38,790
Well actually I need to put that as a to the second time through or whatever the remedy is.

24
00:01:39,300 --> 00:01:45,960
So what I really need is access to that format dot s print f function that's available to me and regular

25
00:01:45,960 --> 00:01:46,530
go code.

26
00:01:46,530 --> 00:01:52,530
And fortunately there is an alias for that available to us in Goldwing templates and it's just called

27
00:01:52,530 --> 00:02:00,810
print F, so print F and I'm going to give it my string with a placeholder and it's a present D because

28
00:02:00,810 --> 00:02:08,610
the remedy is an aunt and I need to put in the variable ID or the value of ID so that will get block

29
00:02:08,610 --> 00:02:14,730
underscore map underscore one for remedy one and block block underscore map underscore two for remedy

30
00:02:14,730 --> 00:02:15,000
two.

31
00:02:15,000 --> 00:02:20,340
So that gets my blocks and I'll duplicate this and do the same thing for reservations.

32
00:02:21,510 --> 00:02:24,420
But of course that's called reservation underscore map.

33
00:02:26,220 --> 00:02:33,030
OK, so now I have this information now down here I need to make a determination and my determination

34
00:02:33,030 --> 00:02:33,840
is a really simple one.

35
00:02:33,840 --> 00:02:35,040
I'm doing blocks first.

36
00:02:35,340 --> 00:02:42,510
If there is an entry in the blocks map for the current date that has a value of greater than zero for

37
00:02:42,510 --> 00:02:46,460
a block, then display a checkmark, otherwise don't.

38
00:02:46,890 --> 00:02:51,990
So I can really just kind of put my if statement right inside this input tag.

39
00:02:53,010 --> 00:03:00,030
And what I want to check here is to see in my block map do I have an entry for the current date that

40
00:03:00,030 --> 00:03:02,070
has a value of greater than zero.

41
00:03:02,310 --> 00:03:03,270
So which is right.

42
00:03:03,270 --> 00:03:13,470
And if statement if greater than and in parentheses I'm going to put index block map of blocks and I'm

43
00:03:13,470 --> 00:03:16,620
looking for the value of print F.

44
00:03:19,280 --> 00:03:25,070
And my string will be a string followed by a hyphen and then another string followed by a hyphen and

45
00:03:25,070 --> 00:03:33,590
then an ENT, and I'm going to replace those values with no comma career, which I got from my string

46
00:03:33,590 --> 00:03:39,560
map per month, which I got from my string map right up here per month and career.

47
00:03:40,730 --> 00:03:44,270
And then the current index added with one added to it.

48
00:03:46,490 --> 00:03:52,550
So let's count our we have one opening to opening three openings.

49
00:03:52,560 --> 00:03:54,650
So one, two, three closing parentheses.

50
00:03:55,220 --> 00:03:56,710
And that has to be greater than zero.

51
00:03:57,740 --> 00:03:58,850
If that is true.

52
00:04:01,010 --> 00:04:07,150
And I'll put in ELT's here, then give this thing a name, give this thing a value and check it.

53
00:04:07,460 --> 00:04:08,870
So let's first all check it.

54
00:04:08,880 --> 00:04:09,860
That's easy checked.

55
00:04:10,040 --> 00:04:13,460
That will make sure it's checked and let's give it a name.

56
00:04:13,910 --> 00:04:18,950
And this name is going to be because this is an existing block that I want to remove.

57
00:04:19,220 --> 00:04:20,750
I will say remove.

58
00:04:20,900 --> 00:04:21,830
I'm going to give it this name.

59
00:04:21,830 --> 00:04:23,510
Remove block.

60
00:04:26,310 --> 00:04:27,960
And I'm going to pass in the remedy.

61
00:04:30,530 --> 00:04:37,280
And then an underscore and then I'm going to pass in the formatted date once again, and that will be

62
00:04:37,280 --> 00:04:46,550
print F and %s %s percent D and replacing those with.

63
00:04:48,420 --> 00:04:49,660
The current year.

64
00:04:51,050 --> 00:04:52,190
The cur month.

65
00:04:53,930 --> 00:04:57,110
And add index.

66
00:05:01,000 --> 00:05:03,700
So that's its name and what's its value going to be?

67
00:05:03,730 --> 00:05:08,290
Well, its value is going to be something as simple as value equals.

68
00:05:12,790 --> 00:05:15,730
Index blocks.

69
00:05:19,700 --> 00:05:23,240
Print F again and the same string.

70
00:05:27,090 --> 00:05:37,110
And replacing those values with career per month and add index one.

71
00:05:39,480 --> 00:05:45,000
So that's going to get the value for my Bloks map and the value stored for this date, which happens

72
00:05:45,000 --> 00:05:48,240
to be a block, is the restriction ID for that block.

73
00:05:48,240 --> 00:05:52,140
So that passes in and it and that's all I have to do for there.

74
00:05:52,140 --> 00:06:01,050
Otherwise, if there is no block, I don't want to the in there.

75
00:06:01,080 --> 00:06:02,180
I want the end.

76
00:06:02,190 --> 00:06:02,650
Yeah I do.

77
00:06:02,650 --> 00:06:03,220
What the end there.

78
00:06:03,270 --> 00:06:09,480
OK, I'm going to put in the name is going to be not equal to remove block.

79
00:06:09,690 --> 00:06:13,770
It'll be equal to Adblock and I got a closing tag there.

80
00:06:13,780 --> 00:06:14,230
That's better.

81
00:06:15,180 --> 00:06:17,460
Name equals ad block.

82
00:06:17,850 --> 00:06:26,010
Underscore once again the remedy and once again an underscore and then the date which I'll just copy

83
00:06:26,010 --> 00:06:28,800
and paste because I have it up here correctly.

84
00:06:29,630 --> 00:06:30,870
I have something missing there.

85
00:06:31,680 --> 00:06:33,720
See one, two.

86
00:06:33,720 --> 00:06:35,370
I've got a missing closing parentheses.

87
00:06:35,370 --> 00:06:38,880
Their ideas are so helpful for pointing out errors.

88
00:06:39,360 --> 00:06:41,370
So let's copy this whole print statement.

89
00:06:44,270 --> 00:06:46,670
Right here to here.

90
00:06:46,730 --> 00:06:47,470
Copy that.

91
00:06:49,590 --> 00:06:54,300
Pasted here, closer quotation marks, and that should do it.

92
00:06:54,360 --> 00:06:58,020
So let's save this and let's make sure our application is running.

93
00:06:58,030 --> 00:07:01,360
I'm going to restart it just to be sure and see if this works.

94
00:07:01,620 --> 00:07:06,120
So this should, when I click on this, should show me any blocks that I have.

95
00:07:07,140 --> 00:07:09,660
And it appears to let's make sure they're right.

96
00:07:09,690 --> 00:07:12,690
So this is on the 8th of December.

97
00:07:12,690 --> 00:07:18,900
Let's inspect that element and make sure it's got the correct name and its remove block room ID and

98
00:07:18,900 --> 00:07:21,760
the date and its value is too perfect.

99
00:07:21,780 --> 00:07:22,690
Let's try a different one.

100
00:07:23,280 --> 00:07:25,260
Let's try this one on the 12th.

101
00:07:26,910 --> 00:07:31,430
And that is remove block the 12th and its value also, too.

102
00:07:31,440 --> 00:07:32,510
That doesn't seem right.

103
00:07:32,520 --> 00:07:34,460
It can't have the same values for those.

104
00:07:34,470 --> 00:07:39,870
Let's try one more, see what's going on on the seventh value, too.

105
00:07:39,870 --> 00:07:41,100
So there's something wrong with the value.

106
00:07:41,130 --> 00:07:43,410
Let's have a look at the value and see what we're doing wrong there.

107
00:07:43,920 --> 00:07:48,120
This is for existing blocks and its value is index blocks.

108
00:07:48,390 --> 00:07:50,490
Print F Kirker Month.

109
00:07:50,490 --> 00:07:51,780
Ad index one.

110
00:07:53,410 --> 00:07:58,690
Well, the only place that can come from is our handler when we actually populate that with value.

111
00:07:59,530 --> 00:08:00,610
So what am I putting in there?

112
00:08:00,610 --> 00:08:01,760
Restriction ID?

113
00:08:01,810 --> 00:08:02,910
That's not what I want.

114
00:08:03,220 --> 00:08:04,420
I want the ID.

115
00:08:05,620 --> 00:08:11,140
OK, so the restriction idea is type to block the ID is the ID of the restriction itself.

116
00:08:11,410 --> 00:08:12,370
OK, so let's stop.

117
00:08:12,370 --> 00:08:14,320
Our application started again.

118
00:08:17,250 --> 00:08:22,890
Go back to our Web browser, reload the calendar, and this time I should see the correct information.

119
00:08:22,920 --> 00:08:28,340
So this is for the eighth and the name is correct and its value is 19.

120
00:08:28,350 --> 00:08:29,250
That looks better.

121
00:08:29,310 --> 00:08:30,270
Let's try another one.

122
00:08:32,220 --> 00:08:33,630
That date is the 12th.

123
00:08:33,930 --> 00:08:35,130
The 12th is correct.

124
00:08:35,130 --> 00:08:36,900
And value of twenty, that looks much better.

125
00:08:36,930 --> 00:08:40,040
OK, so that seems to be working the way that it's supposed to.

126
00:08:41,160 --> 00:08:45,230
The next step is to display reservations if they exist.

127
00:08:45,240 --> 00:08:50,100
So back in my template, let's come up here and see what we're going to do.

128
00:08:50,490 --> 00:08:56,600
What I'm going to do is right after the opening TD tag and I'm going to give myself some room here,

129
00:08:57,330 --> 00:09:00,530
I need to determine, is there a reservation?

130
00:09:00,930 --> 00:09:05,550
If there's not, then I'm going to display either a block or an empty checkmark.

131
00:09:05,880 --> 00:09:10,410
If there's a reservation, though, I want to have something that links to the actual reservations.

132
00:09:10,410 --> 00:09:13,860
And I can do that pretty easily because I have my reservation map.

133
00:09:13,860 --> 00:09:21,390
And I know that if there's an entry for the current date that has a reservation ID that is greater than

134
00:09:21,390 --> 00:09:23,850
zero, then there is a reservation.

135
00:09:24,630 --> 00:09:33,210
So we can just say if greater than and once again, index from our reservations, which is a map and

136
00:09:33,210 --> 00:09:42,240
we're looking for once again, print F percent stasch percent X percent D and I'm substituting the values

137
00:09:42,240 --> 00:09:43,650
of the current year.

138
00:09:47,310 --> 00:09:58,740
The current month and the index with one added to it, and I have one opening parentheses to three,

139
00:09:58,740 --> 00:10:03,630
so one, two, three, and this should be zero.

140
00:10:03,630 --> 00:10:12,540
If it's greater than zero, then there is a reservation otherwise else just do what we just did because

141
00:10:12,540 --> 00:10:16,950
we know it's either a block or something that can be blocked and that should be an end, not an ELT's.

142
00:10:18,710 --> 00:10:25,460
OK, so let's just save this and reload this this calendar and what should happen is if there's a reservation

143
00:10:25,460 --> 00:10:29,730
anywhere in the month of December for either of these rooms, it should just show an empty cell.

144
00:10:30,050 --> 00:10:31,430
So let's see if that works.

145
00:10:32,300 --> 00:10:32,920
And it does.

146
00:10:32,930 --> 00:10:35,930
There's an empty cell for the second and the third there.

147
00:10:35,930 --> 00:10:38,350
And there's another one over here for the 16th and 17th.

148
00:10:38,480 --> 00:10:39,590
That seems correct.

149
00:10:39,950 --> 00:10:44,200
So let's actually just put a link in there and link that'll take us to the appropriate reservation.

150
00:10:45,260 --> 00:10:49,790
So all I'm going to put in here is an A F equals and a link to the reservations page.

151
00:10:53,160 --> 00:10:59,910
And that goes to admin reservations where you're coming from, and this time I'm going to put Carl in

152
00:10:59,910 --> 00:11:03,720
there because we're coming from the calendar, even though we're not doing any anything with it yet,

153
00:11:03,720 --> 00:11:05,010
we will in a little while.

154
00:11:05,970 --> 00:11:10,980
And then I need to get the value of the reservation, which I can get from my reservations map index

155
00:11:12,020 --> 00:11:14,100
or first dollar sign reservations.

156
00:11:15,360 --> 00:11:23,520
And again, I'll use my printer function and use the same string that I have all along and pass in the

157
00:11:23,520 --> 00:11:31,350
courier the courier month and add index one.

158
00:11:32,250 --> 00:11:38,520
OK, now let's see how many closing parentheses do I need one to.

159
00:11:39,920 --> 00:11:50,330
So that should do it and close my opening ATG and in here I'll just put a red our spin class equals

160
00:11:50,330 --> 00:11:51,560
text danger

161
00:11:54,200 --> 00:11:59,090
and that should give me a link to the appropriate reservation and show an hour for every day of the

162
00:11:59,090 --> 00:11:59,760
reservation.

163
00:11:59,780 --> 00:12:00,660
Let's see what happens.

164
00:12:01,040 --> 00:12:03,890
So let's reload this page by clicking on a reservation calendar.

165
00:12:03,890 --> 00:12:09,650
And I have the hours and this one should take me to reservation seven for generals quarters from the

166
00:12:09,650 --> 00:12:10,850
second to the third.

167
00:12:11,980 --> 00:12:13,940
Second to the third, perfect.

168
00:12:13,960 --> 00:12:18,300
OK, so that gives me the reservation and it takes me to the correct place.

169
00:12:18,670 --> 00:12:24,790
Now what I want to fix next is this this this part right here, because I didn't click on Cancel, it's

170
00:12:24,790 --> 00:12:25,690
going to take me nowhere.

171
00:12:26,050 --> 00:12:31,360
So I'm going to go back and find that reservation template and just fix that one little thing, the

172
00:12:31,360 --> 00:12:32,010
back button.

173
00:12:32,020 --> 00:12:35,260
So let's find other bookings templates.

174
00:12:35,590 --> 00:12:39,030
And we want admin show reservation right here.

175
00:12:39,580 --> 00:12:41,200
So down at the cancel per.

176
00:12:43,750 --> 00:12:46,470
Right here, where is it safe cancel?

177
00:12:47,320 --> 00:12:54,850
So what I'm going to do here is just put an if statement if equals source Karl.

178
00:12:59,090 --> 00:13:01,850
ELT's and then put an end if here.

179
00:13:06,790 --> 00:13:11,000
And all I really want to do, if you're on the calendars, I want to take you back to whatever month

180
00:13:11,000 --> 00:13:14,080
you were currently looking at and there's a really easy way to do that.

181
00:13:15,460 --> 00:13:17,680
I'll just take advantage of the browser history.

182
00:13:17,680 --> 00:13:22,930
So I'll say a traffic equals to nothing.

183
00:13:23,050 --> 00:13:29,020
Don't link and don't go anywhere when you click on this, but add an unclick handler unclick equals

184
00:13:29,350 --> 00:13:38,440
and I'm just going to say window dot history dot go and minus one which says go to the previous page

185
00:13:38,800 --> 00:13:46,500
in your browser history and we'll give this the same class of button button warning.

186
00:13:46,930 --> 00:13:47,560
Try that again.

187
00:13:51,030 --> 00:13:58,200
And cancel, so now if I've got that right window history, go one class button warning, that all looks

188
00:13:58,200 --> 00:13:58,440
good.

189
00:13:59,100 --> 00:13:59,940
Let's try that again.

190
00:13:59,970 --> 00:14:03,290
This time I will go back to my reservation or to my reservations calendar.

191
00:14:03,660 --> 00:14:10,290
I'll click on this reservation on the 16th and it's showing me the correct information and cancel.

192
00:14:10,290 --> 00:14:14,220
Should take me back one one page in my browser history.

193
00:14:14,670 --> 00:14:15,390
And it does.

194
00:14:15,390 --> 00:14:19,320
And it takes me to the correct month, which is perfect because I don't want to redirect them to the

195
00:14:19,320 --> 00:14:22,910
calendar page because I want to make sure they're looking at the correct month.

196
00:14:22,920 --> 00:14:30,870
So if I go ahead, I'm on January 20, 21, I click on the reservation, I click on cancel and it takes

197
00:14:30,870 --> 00:14:32,670
me back to January 20 one.

198
00:14:32,700 --> 00:14:33,730
That's exactly what I want.

199
00:14:34,020 --> 00:14:34,500
Perfect.

200
00:14:34,830 --> 00:14:35,400
All right.

201
00:14:35,670 --> 00:14:37,710
So the next step is a pretty simple one.

202
00:14:37,710 --> 00:14:42,360
We need to be able to check dates to block them and remove blocks.

203
00:14:42,540 --> 00:14:47,700
So we need to create a post handler for a reservation calendar and we'll take care of that in the next

204
00:14:47,700 --> 00:14:48,870
lecture or two.
