Let's go over what we're starting with.
- ready to go HTML template with Bootstrap 4
- ready to go Vue object with an already defined
datamethod
The best thing to work on first is your data model. Let's break down the data method's return object.
lastNamewill be bound to an input box representing a new lane's namelanesis an array oflaneobjects, each of which containnameof the lane, and thecardsthat form the lane, and some unique key- each
cardhas aname,desc, aneditingflag, and some unique key
How can you repeat (i.e. loop)? How do you bind text?
- Let's wire up the lanes to each bootstrap
.colthat forms a lane. - Each lane has a set of cards, so let's wire up each lane to have a list of cards bound to the
.card. - Finally, we need to bind text directly into the template. Add the card's name and description to the
h4+p.
How can you add events?
- Let's add a value binding for
laneNameto a text input. - Add a click event listener to a button for adding a new lane.
- Create a method for adding lanes
- the created lane should have a unique key, a name, and a empty array of cards
- the
nameshould be thelaneName - you can easily add elements to an array with
array.push(element)or[...array, element]
- Bind the
h3lane title to the name of the lane - (bonus) Give the lanes a sensible default name if no
laneNameis specified like (Lane 2, Lane 3, etc)
Code solution
addLane() {
let name = this.laneName !== '' ? this.laneName : `Lane ${this.lanes.length+1}`;
const lane = {
key: util.getKey(),
name: name,
cards: []
};
this.lanes = [...this.lanes, lane];
this.laneName = '';
},- Add a click event listener to the
+button below the lane name - Add a method that adds new cards to the lane's cards list
- the card should have a unique key, an empty
name, and emptydescand a falseeditingflag
- the card should have a unique key, an empty
- In the
h4card binding, add a default fallback to show "no name"
Code solution
addBlankCard(currentLane) {
const card = {
key: util.getKey(),
name: '',
desc: '',
editing: false
};
currentLane.cards.push(card);
},
- If you see a
style="display: none"in the edit mode section, remove that now - Add a click event listener to the
h4card name that setscard.editingto true - Bind the card name and card description inputs to
card.nameandcard.descrespectively - Add a click event listener to the Save
buttonthat setscard.editingto false
Let's work on getting cards to move through the lanes.
To move a card to another lane, you will need to know:
- the current cardIndex
- the current lane
- the current laneIndex
- the direction (left or right; represented by -1 or 1)
- the size of the lanes array (for bounds checking)
With that, you might figure you will need a method like moveCard(cardIndex, lane, laneIndex, leftOrRight).
That method might, for example, work like this:
- Find the destination lane based on
laneIndex + leftOrRight - Remove the current cardIndex from the current lane
- Add the removed card to the destination lane
- (bonus) Add bounds checking
Code solution
moveCard(cardIndex, lane, laneIndex, lr) {
const destinationIndex = laneIndex + lr;
if (destinationIndex < 0 || destinationIndex >= this.lanes.length) { return; }
const removedCard = lane.cards.splice(cardIndex, 1);
const destinationLane = this.lanes[destinationIndex];
destinationLane.cards.push(removedCard[0]);
},
Bind the two .swap-button buttons to method calls of moveCard for their direction.
This is a bonus step. Try enabling the Delete button in the card edit mode.