-
levels and statuses as well, and the only variance between these three is what they're applied to. For example, our difficulties are applied to the course, our access levels are applied
-
to the course and lesson, and then our statuses are applied to all three. So while we could try and go about this a very dry approach, refactoring everywhere
-
that we have difficulties to just like an organizational resource that could serve as any one of those three, I feel that would add undue complexity to what we have due to
-
some of the functionality that we have around deleting these resources. So because of that, we're going to do a lot of find and replacing here to apply what
-
we have with our difficulties to our access levels and statuses as well. It's not going to be the most fun approach, but I feel it's going to be the most practical here. So we want to take our difficulties page, copy it and paste it two times.
-
Once for our access levels and once for our statuses. Take copy number one, rename that to statuses and take copy number two and rename that
-
to access underscore levels. Within our statuses, we'll take care of this first. We want to find anywhere that we're referencing difficulty and replace that with status.
-
Now make sure that you have match case on here so that we keep the casing consistent with these replacements. Replace all of those.
-
And now we can take difficulty with a capital D, find all of those and replace it with status with a capital S just like so. That takes care of all of our singular replacements.
-
Now we have difficulties that we want to replace with statuses. Replace all of those and let's double check and see if we're missing anything.
-
So scroll through a file real quick, just scanning for anything that says difficulties right here.
-
Replace that with capital S statuses, continue scrolling and everything here looks correct. Okay. One more difficulty right down here.
-
Just replace that with status. And we need to circle back to our destroy dialogues here as well. As we want to update the text to show appropriate counts for our courses, lessons, and modules.
-
Since the statuses are applied to all three, we'll circle back later on and do that after we get all of our finding replacing done. So let's go ahead and do our access levels next. We're just going to do relatively the exact same thing here.
-
The only difference is we need to be a little bit more careful with our replacements because access levels could have a space, could be snake case, or it could be camel case.
-
So rather than just doing a straight find for difficulty, as it could be any one of those three, let's just manually replace that with access level. And then we want to search for our difficulty DTO separate as just searching for difficulty
-
could match displayed values, and it could also match our difficulty DTO. So we want to replace that with our access level DTO place.
-
All five of those replace difficulties. All of these should be camel case. So access levels, and let's just start to scroll through our file here, searching for
-
any other instances of difficulty on our page. All right. There's this one here. Difficulties that has to, we can see both of them on the find.
-
So we want to add a space in there to have access levels and replace that, and then manage access levels. There we go. Have this difficulty right here.
-
Now that we've replaced our DTO, we should be okay to go ahead and replace that one with a singular access level. And let's just continue scrolling through.
-
And we have that last dangling difficulty, replace that with access level. All right. So that should be all of them. Again, we want to circle back here to update our counts applicable to the access levels.
-
We'll do that after we do all of our final replacements and add our actual counts in. So next let's jump into our validators and let's do this one more time for our access level and status validations. So we'll paste that in twice.
-
We could just rename this one as all three are going to be very much the same to a resource validator, but to keep things consistent throughout our project, we're going to leave these named
-
as is. All right. For our access levels here, just want to rename the actual validator from difficulty validations
-
to access level like so, and do the exact same for our statuses, replacing that with status. Then we want to make sure that we update the table that we're checking whether or not a
-
replacement exists for as well. So for statuses, that's going to be our statuses table and for our access levels, that's going to be our access underscore levels table. All right.
-
We're done with our validators. Now we can move into our, let's do our actions next, since our controllers rely on the actions existence. I'm going to go ahead and right click on the entire folder, copy the entire folder and
-
paste the entire folder in two times inside of our actions folder. First one renaming to access underscore levels.
-
We also want to rename each file inside of here as well, replacing difficulty with access underscore level. And then we want to do the exact same thing for our statuses.
-
So status renaming that folder there and then jumping into it and renaming each of these files. So status. All right. There we go.
-
We'll do our access levels first, replacing everywhere that we see difficulty with access level and just scanning all of these highlights, we should be good to go with that replacement for all of those.
-
And then we need to replace the actual class name with access level there as well. Oh, this one needs to be snake cased. We'll do that there too.
-
And then we no longer want to grab the related difficulties, but rather the related access levels. And then in addition to replacing our access levels at the course level, we also want to
-
replace it at the lesson level for our access levels as well.
-
So we want to await organization related lessons and query where the access level ID is the
-
ID being passed in and then update that access level ID with the data dot replacement ID there. All right. That is our destroy.
-
Now we're onto our store. Replace difficulty for all of those. Convert this to snake case. Change the class from difficulty to access level.
-
And then we'll do a find and replace for difficulty as we have that referenced in a few spots in this file. Replace that with access level and then replace the relationship with access levels for both of these. All right.
-
That should be our store. Let's do the update. Go ahead and replace those. Do a find for difficulty and replace that with a camel case access level.
-
And then we want to convert the import for the model to snake case. And then we have this difficulties that we can replace with access levels. All right. Give that one a save.
-
And now we're onto our updates where we'll find difficulty, replace that with access level. Again, switching the import to snake case.
-
Let's update the class name to access level and the relationship to access levels. All right. That should be it for the actions for our access levels.
-
Now we're on to our statuses. So we'll jump into destroy first. Replace everything difficulty with status. Again, this one should go a little bit quicker since we don't really need to worry about
-
camel, snake or spaces. Replace difficulties with statuses and then update our class to destroy status. I'm going to give that a save to see if that's just formatting and it sure is.
-
All right. Just like with our destroy for our access levels, we also want to await organization related. And for this one, we want to destroy that both the module and lessons in addition to our courses.
-
So we'll reach for our modules relationship off of our organization query where the status
-
ID equals the ID being passed in and update that with our status ID from our data replacement ID.
-
We could just give that a copy again and replace the related call with lessons. Okay. Onto our store. Replace difficulties with statuses.
-
We can replace difficulty with a capital D with status with a capital S and then search for difficulty and replace that with status.
-
And I believe that one should be done now taking us to our update status order where we can replace difficulty with status capital D difficulty with capital S status difficulties
-
with statuses. And we should be good with that one now taking us to our update status, replace difficulties
-
with statuses there, update our class name from difficulty through status and then replace difficulty with status.
-
That now should take us to just needing to do our controllers. So let's jump into our controllers and we already have an access levels controller and statuses controller.
-
So let's just jump into our difficulties controller, give everything inside of there a copy and paste it, replacing our statuses and access level controller contents.
-
All right, let's scroll up to the top of our file here and let's replace difficulty with access level as camel case.
-
Then we can highlight difficulties and replace that with access levels as camel case as well.
-
Noting that we also want to update and fix our imports here from being camel case to instead being snake case. So we can use multi cursors to do that.
-
Command option down arrow to get multi cursors across all of these lines. Command right arrow to jump to the end. Command shift left arrow to jump to the start.
-
Option shift right arrow to deselect entire words until we get to just having the import strings and select it. Command shift P search for snake case and transform to snake case.
-
All right, our imports should now be good. Missed this one here. We also want to do access level for that one, too.
-
And let's update our controllers name to access levels controller and then replace difficulty with a capital D to access level with a capital A. Place all of those.
-
And then we can scroll through our file here to see if we got everything so far so good. We do need to jump back up to our index method to make a couple of changes here.
-
So instead of getting our difficulties, we want to get our access levels. But in addition to that, we also want to get additional counts as well, because this also applies on our lessons.
-
So we want to get both lessons and courses for those counts. Should be able to give this file a save and all of our red squiggles should go away and we can call that done now.
-
Jump into our statuses controller, scroll back up to the top, replace everything difficulty with status just like so.
-
Scroll back up to the top and let's now do lowercase difficulty with lowercase status. Replace all of those. And we have difficulties that we can replace with statuses.
-
And I believe that should just leave us now with our controller name. We can switch that to statuses too. Now, again, instead of getting our difficulties, we want to get our statuses and for our statuses,
-
this applies to all three, our courses, modules and lessons. So we want to get the count for all three of those. So modules and then with count lessons.
-
Now we're getting a red squiggly here on our modules. So let's jump into our model for our statuses. And sure enough, I missed adding that relationship in.
-
So we'll do it at has many, import our module model, make sure that you scroll down to the model and import the correct one there.
-
Modules has many type of our module model. While we're in our models, let's jump into our module to make sure that it's bound to our status, which, OK, good.
-
So we can close back our modules, jump back into our status controller. And let's give this a quick scroll through just to make sure that we got everything here. All right. That looks good.
-
That now leaves us back with the destroy confirmation dialogue for our access levels and statuses. We want to update to show the applicable counts.
-
So in addition to showing our courses count for our access levels, we want to do and amp
-
reach for our destroy that resource meta lessons count as well in adding lessons.
-
So now that reads, what difficulty would you like to assign the X amount of courses and X amount of lessons using the and then the resources name? Oh, we did miss this one, didn't we?
-
That should be access level. There we go. All right. So that should do it for our access levels. Jump into these statuses and let's do the exact same thing. So we got it there. So we don't need to replace the text for that one.
-
But we do need to now show our destroy resource meta modules count modules and then the destroy
-
resource meta lessons and add lessons to that there as well. Delimiting all of those with the and amp ampersand there as well. We're almost ready to test this out.
-
Before we do, we need to jump into our web routes so we can note that we have our difficulties here and we can copy all of those routes and paste them twice because we now also want to
-
have our statuses and our access level routes as well. So let's plop our cursor somewhere in the middle of difficulties.
-
Command option down arrow to get a cursor per route definition that we have for our statuses. Option right arrow to jump to the end of the difficulties word.
-
Option shift left arrow to jump to the start, selecting the entire word. And we can type out statuses. Command right arrow to jump to the end. And let's do the exact same thing with the routes name.
-
And then option left arrow some more to get to our controller where we now want to import our statuses controller. All right, let's go down. Should take us into our access levels controller now.
-
So we'll import that just like so. Option right arrow so that we can replace the routes names with access. And I'm gonna use a hyphen to delimit these levels for the names there.
-
Command left arrow to jump to the start. Option right arrow to jump whole words. Option shift right arrow to select the entirety of difficulties. Replacing that with access hyphen levels. Awesome.
-
At this point, we should be able to jump back into our browser. Let everything refresh there. And we should now be able to jump into our statuses to see all of our statuses as well as our access levels.
-
And it looks like that one does not want to work. Let's go ahead and right click our page. Go down to inspect. And let's check out the console to see if we can find out why. Page not found. Ah, access levels. It's trying to find it. Camel cased.
-
So we need to jump back into our text editor. And that's going to be inside of our controller. So inside of our access levels controller. Yep, sure enough right there. We gave that a snake case folder name.
-
So we'll apply that there. We should now be able to jump back into our browser and jump from statuses to access levels. And there we go. OK, cool. Can we add in a new access level? We'll call this mixed.
-
Hit enter and cannot post. So we missed the post for that one there as well. Jump down into our access levels page. Scroll up.
-
And right there, we need to switch that to hyphenated access levels. And we probably need to do that for all of the action URLs here. So scroll back down. Sure enough, hyphenate those. Hyphenate that there.
-
And that should be all three of our actions. OK, we don't need to worry about that with our statuses as that's just a single word. So we should be able to jump back into our browser now. Let's refresh our browser. There we go.
-
And let's try to add in a new access level now. So call that mixed. Hit enter. There we go. Now we have mixed. And we should now be able to drop that to the first item. And OK, that's not working either.
-
And let's make sure that we got that put updated OK. Yep. All right. So let's jump into that action. Double check that we updated everything OK in there. Update access level order. And whoops, we are getting the difficulties.
-
So that's definitely not going to work. Get access levels instead. I bet you I missed that with the statuses as well. Jump into the order for that one. Sure enough, get statuses.
-
Let's see if that now has fixed everything for us. So let's take our mixed. Try to drop it as the first. There we go. Now that's working. We can drop that back down to last. Edit, update, and delete.
-
Cool. Jump now into our statuses. And let's check all of those as well. Add new status. Say something like idea. Add that. Drag it up. See if we can update the sort. There we go. All good. Drag it back.
-
Edit. Do ED. Update. And delete. And sure enough, all is good for those. Cool. So there we go. We now have the same behavior for our difficulties applied
-
to our statuses and access levels. I am sorry. I know that wasn't the most fun process to go through. But this is the approach I would have taken. And it's the approach I did take whenever I was
-
building this application out, as I feel like it's the most future-proof approach having them all three remain separate rather than trying to do this in a dry manner.