Bootcamp:Chapter 7
No edit summary
No edit summary
 
(13 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This is '''Chapter 7''' of the 1000 Steps Program.  
<message>Write the content here to display this box</message>
This is '''Chapter 7''' of the Bootcamp.  


If you want to start from the top: [[The 1000 steps program to MDriven Chapter 1]], or see [[The 1000 steps program to MDriven Chapter 6|Chapter 6 (the previous chapter)]]
If you want to start from the top: [[Training:Bootcamp:Chapter 1|Chapter 1]], or see [[Training:Bootcamp:Chapter 6|Chapter 6 (the previous chapter)]]


=== '''Video 7: Steps 215 - 238''' ===
=== '''Video 7: Derived Attributes & Editable Grid Cells in Web UI''' ===
<html>
<html>


Line 15: Line 16:
   </div>
   </div>
   <div class="video__navigation">
   <div class="video__navigation">
  <span data-video="QxXA5D4mEio" data-start="00" tabindex="0"> <strong> Derived Attributes & Editable Grid Cells in Web UI </strong> </span>
  <span data-video="QxXA5D4mEio" data-start="00" tabindex="0"> <strong> Steps 215 - 238 </strong> </span>
     <span class="navigation-item" data-video="QxXA5D4mEio" data-start="00" tabindex="0"> Introduction </span>
     <span class="navigation-item" data-video="QxXA5D4mEio" data-start="00" tabindex="0"> Introduction </span>
     <span class="navigation-item" data-video="QxXA5D4mEio" data-start="08" tabindex="0"> Renaming and notes </span>
     <span class="navigation-item" data-video="QxXA5D4mEio" data-start="08" tabindex="0"> Renaming and notes </span>
Line 28: Line 29:


== Chapter 7: First Mention of Derived Attributes; Editable Grid Cells in Web UI ==
== Chapter 7: First Mention of Derived Attributes; Editable Grid Cells in Web UI ==
215. <code>CarsIUsedToOwn</code> is actually a poor name. If we change the name to <code>CarsPersonUsedToOwn</code>, it is a better fit as it does not raise questions about whom "I" refers to.   
'''NOTE:''' Click on the step/number to access the corresponding images.    
 
'''[[Training:Chapter 7 Images#Step 215|215]]'''. '''CarsIUsedToOwn''' is actually a poor name. If we change the name to '''CarsPersonUsedToOwn''', it is a better fit as it does not raise questions about whom "I" refers to.   
* Type the new name in the Association end.   
* Type the new name in the Association end.   
* Save (that will run the error check) and see the many errors.  
* Save (that will run the error check) and see the many errors.  
216. Change it back to <code>CarsIUsedToOwn</code> temporarily and save. You will see no errors.
[[Training:Chapter 7 Images#Step 216|'''216''']]. Change it back to '''CarsIUsedToOwn''' temporarily and save. You will see no errors.


217. Instead of changing it, we will use the Rename function that will help to rename it everywhere it is used.  
'''[[Training:Chapter 7 Images#Step 217|217]]'''. Instead of changing it, we will use the Rename function that will help to rename it everywhere it is used.  
* Right-click the association end, choose rename, new name: <code>CarsPersonUsedToOwn</code> 
* Right-click the association end, choose rename, new name: '''CarsPersonUsedToOwn'''
* Check "Set former name." Whenever you use "Rename," you should check "Set former name" to guide MDriven to help you once your changes also involve the creation of change scripts to a database. Click on Toggle Selected
* Check "Set former name." Whenever you use "Rename," you should check "Set former name" to guide MDriven to help you once your changes also involve the creation of change scripts to a database. Click on Toggle Selected
* Save and verify that you are error-free.
* Save and verify that you are error-free.
218. Create a note on the diagram by right-clicking "Add note." Double-click the note box and write this in the note:  
'''[[Training:Chapter 7 Images#Step 218|218]]'''. Create a note on the diagram by right-clicking "Add note." Double-click the note box and write this in the note:  
  '''We will assume that a person always has 1 car at a time and that when they sell the first car, that person immediately gets a new car on the same day.'''  
  '''We will assume that a person always has 1 car at a time and that when they sell the first car, that person immediately gets a new car on the same day.'''  
* Close the note. Resize it and place it somewhere nice.
* Close the note. Resize it and place it somewhere nice.
219. Add a new attribute, <code>DatePurchased</code> of type DateTime?, in class HistoricOwnership.
'''[[Training:Chapter 7 Images#Step 219|219]]'''. Add a new attribute, '''DatePurchased''' of type DateTime?, in class '''HistoricOwnership'''.


220. Select <code>DatePurchased</code> and in the property inspector, change the AttributeMode from Persistent (default - means saved in the database) to Derived (means calculated somehow).
'''[[Training:Chapter 7 Images#Step 220|220]]'''. Select '''DatePurchased''' and in the property inspector, change the AttributeMode from <u>Persistent</u> (default - means saved in the database) to <u>Derived</u> (means calculated somehow).


221. Stay in the Property Inspector and find DerivationOcl. Click on the OCL Editor with the three dots.  
'''[[Training:Chapter 7 Images#Step 221|221]]'''. Stay in the Property Inspector and find DerivationOcl. Click on the OCL Editor with the three dots.  


222. We want ''this'' DatePurchased to be derived from the first car's DateSold.  
'''[[Training:Chapter 7 Images#Step 222|222]]'''. We want ''this'' '''DatePurchased''' to be derived from the first car's '''DateSold'''.  
* We want to have an expression that from HistoricOwnership (self) goes up to the person ('''self.Person'''), and from there, looks at all HistoricOwnership ('''self.Person.HistoricOwnership'''), makes sure that this list is in DateSold order ('''self.Person.HistoricOwnership->orderby(h|h.DateSold)'''), and checks where in this list '''THIS''' HistoricOwnership (self) is ('''self.Person.HistoricOwnership->orderby(h|h.DateSold)->indexof0(self)''').   
* We want to have an expression that from HistoricOwnership (self) goes up to the person ('''self.Person'''), and from there, looks at all HistoricOwnership ('''self.Person.HistoricOwnership'''), makes sure that this list is in DateSold order ('''self.Person.HistoricOwnership->orderby(h|h.DateSold)'''), and checks where in this list '''THIS''' HistoricOwnership (self) is ('''self.Person.HistoricOwnership->orderby(h|h.DateSold)->indexof0(self)''').   
* Once we have that, grab the one after '''THIS''' HistoricOwnership: '''listinorder->at0(listinorder->indexof0(self)+1)'''.  
* Once we have that, grab the one after '''THIS''' HistoricOwnership: '''listinorder->at0(listinorder->indexof0(self)+1)'''.  
* We discover that we need the same list twice; it is easier to get it once and use it in the expression twice. This is done in OCL with the "let x=someexpr in someotherexpr" operator.
* We discover that we need the same list twice; it is easier to get it once and use it in the expression twice. This is done in OCL with the "'''let x=someexpr in someotherexpr'''" operator.
We can write:
We can write:


Line 70: Line 73:
  ).DateSold
  ).DateSold


223. Go to Person ViewModel and add the date purchased in the HistoricOwnershipGrid. Save and test the web.  
'''[[Training:Chapter 7 Images#Step 223|223]]'''. Go to '''Person''' ViewModel and add the date purchased in the '''HistoricOwnershipGrid'''. Save and test the web.  


224. We notice that there is no easy way for us to edit the DateSold; thus, the DatePurchased will get a null result all the time.   
'''224'''. We notice that there is no easy way for us to edit the '''DateSold'''; thus, the '''DatePurchased''' will get a null result all the time.   
* Make the grid Editable by selecting the HistoricOwnership nesting head (blue).  
* Make the grid Editable by selecting the '''HistoricOwnership''' nesting head (blue).  
225. Here we will add a tagged value (tagged values are extra meta information we can dress up our model with on most levels, like classes, attributes, and ViewModels). Press the Tagged values button in the ViewModelEditor.
'''[[Training:Chapter 7 Images#Step 225|225]]'''. Here we will add a tagged value (tagged values are extra meta information we can dress up our model with on most levels, like classes, attributes, and ViewModels). Press the Tagged values button in the ViewModelEditor.


226. In the shown window, press the Refresh from Wiki button.   
'''[[Training:Chapter 7 Images#Step 226|226]]'''. In the shown window, press the '''Refresh from Wiki''' button.   
* Note how many predefined possible values (value store) are shown.   
* Note how many predefined possible values (value store) are shown.   
* You are not limited to these tagged values, but the predefined values have a special meaning to the Turnkey (the web front-end engine, or to the WECPOF of the WPF engine).  
* You are not limited to these tagged values, but the predefined values have a special meaning to the Turnkey (the web front-end engine, or to the WECPOF of the WPF engine).  
227. Find Editable in the top selector. Add that, set its value to True, close, and save.  
'''[[Training:Chapter 7 Images#Step 227|227]]'''. Find Editable in the top selector. Add that, set its value to True, close, and save.  


228. To make a cell in a grid editable, it must be in an editable grid - we fixed that just now - but a column must also have a ReadOnly expression that does ''not'' result in true (but rather, false or left empty). Clear the DateSold ViewModelColumn in the grid ReadOnlyExpression.  
'''[[Training:Chapter 7 Images#Step 228|228]]'''. To make a cell in a grid editable, it must be in an editable grid - we fixed that just now - but a column must also have a ReadOnly expression that does ''not'' result in true (but rather, false or left empty). Clear the '''DateSold''' ViewModelColumn in the grid ReadOnlyExpression.  


229. Save and test the web. You have an editable date-picker in DateSold.  
'''[[Training:Chapter 7 Images#Step 229|229]]'''. Save and test the web. You have an editable date-picker in '''DateSold'''.  


230. Enter some different dates in the rows. If you don't have rows, add some.   
'''[[Training:Chapter 7 Images#Step 230|230]]'''. Enter some different dates in the rows. If you don't have rows, add some.   
* Notice the instant calculation of the DatePurchase as the DateSold becomes available in the row below.  
* Notice the instant calculation of the '''DatePurchase''' as the '''DateSold''' becomes available in the row below.  
231. Click the DateSold column head in the grid to verify that you get the correct values.  
'''[[Training:Chapter 7 Images#Step 231|231]]'''. Click the '''DateSold''' column head in the grid to verify that you get the correct values.  


232. In the column DatePurchased, we want to force the ISO date because we don't trust the browser setting.   
'''[[Training:Chapter 7 Images#Step 232|232]]'''. In the column '''DatePurchased''', we want to force the ISO date because we don't trust the browser setting.   
* Change the expression to <code>self.DatePurchased.ToString('yyyy-MM-dd')</code>   
* Change the expression to <code>self.DatePurchased.ToString('yyyy-MM-dd')</code>   
* Save and test the web.  
* Save and test the web.  
233. Discover the issue with us taking <code>IndexOf0 +1</code>  when the prior car is at <code>-1</code> - fix the derivation. Save and test the web.
'''[[Training:Chapter 7 Images#Step 233|233]]'''. Discover the issue with us taking <code>IndexOf0 +1</code>  when the prior car is at <code>-1</code> - fix the derivation. Save and test the web.


234. Notice the Name column; it now looks like an edit box. This is because we made the grid editable.  
'''[[Training:Chapter 7 Images#Step 234|234]]'''. Notice the Name column; it now looks like an edit box. This is because we made the grid editable.  
* Set the column to <code>IsStatic=true</code>.  
* Set the column to <code>IsStatic=true</code>.  
* Save and verify that it now looks like a simple string.
* Save and verify that it now looks like a simple string.
235. We don't want the Name column here since it will always be our own name. Drop it.
'''[[Training:Chapter 7 Images#Step 235|235]]'''. We don't want the '''Name''' column here since it will always be our own name. Drop it.  
 
236. From class Car, drag out a new association arrow to Person. The Car-end, you name CurrentCar, and the Person-End, you name CurrentOwner.  


237. In the Person ViewModel, add a SelectBox by right-clicking in the green tree, add a Nesting ViewModelClass, go to SingleLinkWithSetter, and select CurrentCar. Save and test the web.
'''[[Training:Chapter 7 Images#Step 236|236]]'''. From class '''Car''', drag out a new association arrow to '''Person'''. The '''Car'''-end, you name '''CurrentCar''', and the '''Person'''-End, you name '''CurrentOwner'''.  


238. Clean up the view and remove any bogus columns.
'''[[Training:Chapter 7 Images#Step 237|237]]'''. In the '''Person''' ViewModel, add a SelectBox by right-clicking in the green tree, add a Nesting ViewModelClass, go to SingleLinkWithSetter, and select '''CurrentCar'''. Save and test the web.


'''Next Chapter'''
'''[[Training:Chapter 7 Images#Step 238|238]]'''. Clean up the view and remove any bogus columns. 


[[The_1000_steps_program_to_MDriven_Chapter_8]]
=== '''Next Chapter''' ===
[[Category:1000 Steps Program]]
[[Training:Bootcamp:Chapter 8|Bootcamp:Chapter 8]]
[[Category:Bootcamp]]

Latest revision as of 05:49, 16 September 2024

This is Chapter 7 of the Bootcamp.

If you want to start from the top: Chapter 1, or see Chapter 6 (the previous chapter)

Video 7: Derived Attributes & Editable Grid Cells in Web UI

To make your experience smooth, we set the main tags mentioned in the video to the right bar menu of this mini-player. Choose an interesting subtitle on the list and immediately get to the exact theme navigation item place in the video. Now you can pick any topic to be instructed on without watching the whole video.

Steps 215 - 238 Introduction Renaming and notes Derived Tagged value DateTime Selectbox

Chapter 7: First Mention of Derived Attributes; Editable Grid Cells in Web UI

NOTE: Click on the step/number to access the corresponding images.   

215. CarsIUsedToOwn is actually a poor name. If we change the name to CarsPersonUsedToOwn, it is a better fit as it does not raise questions about whom "I" refers to.

  • Type the new name in the Association end.
  • Save (that will run the error check) and see the many errors.

216. Change it back to CarsIUsedToOwn temporarily and save. You will see no errors.

217. Instead of changing it, we will use the Rename function that will help to rename it everywhere it is used.

  • Right-click the association end, choose rename, new name: CarsPersonUsedToOwn
  • Check "Set former name." Whenever you use "Rename," you should check "Set former name" to guide MDriven to help you once your changes also involve the creation of change scripts to a database. Click on Toggle Selected
  • Save and verify that you are error-free.

218. Create a note on the diagram by right-clicking "Add note." Double-click the note box and write this in the note:

We will assume that a person always has 1 car at a time and that when they sell the first car, that person immediately gets a new car on the same day. 
  • Close the note. Resize it and place it somewhere nice.

219. Add a new attribute, DatePurchased of type DateTime?, in class HistoricOwnership.

220. Select DatePurchased and in the property inspector, change the AttributeMode from Persistent (default - means saved in the database) to Derived (means calculated somehow).

221. Stay in the Property Inspector and find DerivationOcl. Click on the OCL Editor with the three dots.

222. We want this DatePurchased to be derived from the first car's DateSold.

  • We want to have an expression that from HistoricOwnership (self) goes up to the person (self.Person), and from there, looks at all HistoricOwnership (self.Person.HistoricOwnership), makes sure that this list is in DateSold order (self.Person.HistoricOwnership->orderby(h|h.DateSold)), and checks where in this list THIS HistoricOwnership (self) is (self.Person.HistoricOwnership->orderby(h|h.DateSold)->indexof0(self)).
  • Once we have that, grab the one after THIS HistoricOwnership: listinorder->at0(listinorder->indexof0(self)+1).
  • We discover that we need the same list twice; it is easier to get it once and use it in the expression twice. This is done in OCL with the "let x=someexpr in someotherexpr" operator.

We can write:

let  listinorder=self.Person.HistoricOwnership->orderby(h|h.DateSold) in

(

listinorder->at0(listinorder->indexof0(self)+1)

)

This expression will return as a HistoricOwnership object, but we want this DatePurchased to be derived from the prior cars' DateSold. We append.DateSold

let listinorder=self.Person.HistoricOwnership->orderby(h|h.DateSold) in

(

listinorder->at0(listinorder->indexof0(self)+1)

).DateSold

223. Go to Person ViewModel and add the date purchased in the HistoricOwnershipGrid. Save and test the web.

224. We notice that there is no easy way for us to edit the DateSold; thus, the DatePurchased will get a null result all the time.

  • Make the grid Editable by selecting the HistoricOwnership nesting head (blue).

225. Here we will add a tagged value (tagged values are extra meta information we can dress up our model with on most levels, like classes, attributes, and ViewModels). Press the Tagged values button in the ViewModelEditor.

226. In the shown window, press the Refresh from Wiki button.

  • Note how many predefined possible values (value store) are shown.
  • You are not limited to these tagged values, but the predefined values have a special meaning to the Turnkey (the web front-end engine, or to the WECPOF of the WPF engine).

227. Find Editable in the top selector. Add that, set its value to True, close, and save.

228. To make a cell in a grid editable, it must be in an editable grid - we fixed that just now - but a column must also have a ReadOnly expression that does not result in true (but rather, false or left empty). Clear the DateSold ViewModelColumn in the grid ReadOnlyExpression.

229. Save and test the web. You have an editable date-picker in DateSold.

230. Enter some different dates in the rows. If you don't have rows, add some.

  • Notice the instant calculation of the DatePurchase as the DateSold becomes available in the row below.

231. Click the DateSold column head in the grid to verify that you get the correct values.

232. In the column DatePurchased, we want to force the ISO date because we don't trust the browser setting.

  • Change the expression to self.DatePurchased.ToString('yyyy-MM-dd')
  • Save and test the web.

233. Discover the issue with us taking IndexOf0 +1 when the prior car is at -1 - fix the derivation. Save and test the web.

234. Notice the Name column; it now looks like an edit box. This is because we made the grid editable.

  • Set the column to IsStatic=true.
  • Save and verify that it now looks like a simple string.

235. We don't want the Name column here since it will always be our own name. Drop it.

236. From class Car, drag out a new association arrow to Person. The Car-end, you name CurrentCar, and the Person-End, you name CurrentOwner.

237. In the Person ViewModel, add a SelectBox by right-clicking in the green tree, add a Nesting ViewModelClass, go to SingleLinkWithSetter, and select CurrentCar. Save and test the web.

238. Clean up the view and remove any bogus columns.

Next Chapter

Bootcamp:Chapter 8

This page was edited 3 days ago on 09/16/2024. What links here