How to pass a data together with a router Link in HTML? - ionic4

I'm trying to a pass data together with a router Link in HTML. I have search all over google still unable to a find an answer. I even tried to store the data in a service, but it can't store the data.
Below is the HTML code, I want to pass the data outpatientRegdList?.prn together with the routherlink.
<div class="pandora-box" *ngFor="let outpatientRegdList of outpatientRegdList">
<div *ngIf="outpatientRegdList?.sexCode ==='F' || outpatientRegdList?.sexCode ==='f'">
<ion-row class="pandora-wisdom" routerLink="outpatient-settings">
<ion-col class="pandora-joy">
{{ outpatientRegdList?.prn }}<br>
<strong>{{outpatientRegdList?.title}} {{outpatientRegdList?.firstName}}
{{outpatientRegdList?.middleName}} {{outpatientRegdList?.lastName}}</strong><br>
</ion-col>
</ion-row>
<div>
</div>
Hope that some one would help me in this.

You can send data in the url via queryParams like this
<div *ngIf="outpatientRegdList?.sexCode ==='F' || outpatientRegdList?.sexCode ==='f'">
<ion-row class="pandora-wisdom" routerLink="outpatient-settings" [queryParams]="{ yourQueryFieldName: outpatientRegdList?.prn }">
<ion-col class="pandora-joy">
{{ outpatientRegdList?.prn }}<br>
<strong>{{outpatientRegdList?.title}} {{outpatientRegdList?.firstName}}
{{outpatientRegdList?.middleName}} {{outpatientRegdList?.lastName}}</strong><br>
</ion-col>
</ion-row>
<div>
After navigation you can access the queryParams in the page with the ActivatedRoute
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.route.queryParams
.filter(params => params.yourQueryFieldName)
.subscribe(params => {
console.log(params); // {yourQueryFieldName: outpatientRegdList?.prn}
});
}

Related

How to search for profiles in firestore using vue

I'm Trying to be able to search for specific profiles in a database but I don't know how to get what I put into the input field to return the profiles close to what has been typed in heres what I have so Far hopefully it will make more sense.
<script>
import { ref } from 'vue'
import getPremium from "../Composables/getPremium.js";
import getStandard from "../Composables/getStandard.js";
import getBasic from "../Composables/getBasic.js";
import { computed } from 'vue'
import getCollection from '../Composables/getCollection';
const {Premium} = getPremium();
const selectedProfile = ref(Premium)
const query = ref('')
const filteredPeople = computed(() =>
query.value === ''
? Premium
: Premium.filter((person) => {
return person.toLowerCase().includes(query.value.toLowerCase())
})
)
export default {
setup() {
const { documents: Premium } = getCollection(
'Premium',
['name', '==', selectedProfile.value]
)
return { Premium, selectedProfile }
}
}
</script>
<template>
<p>home comoonent</p>
<form>
<div class="inline-block">
<Input v-model="selectedProfile" #change="query = $event.target.value" placeholder=" Search Escort Name" class="h-7 bg-neutral-700 text-neutral-400 m-4 inline-flex rounded"/>
{{ person }}
</div>
</form>
<p>Escorts</p>
<div class="grid gap-x-4 grid-cols-2 grid-rows-fit mx-5 md:grid md:gap-2 md:grid-cols-4 md:grid-rows-fit md:mx-20 lg:grid lg:gap-4 lg:grid-cols-4 lg:grid-rows-fit lg:mx-20 xl:grid xl:gap-4 xl:grid-cols-4 xl:grid-rows-fit xl:mx-20 2xl:grid 2xl:gap-4 2xl:grid-cols-4 2xl:grid-rows-fit 2xl:mx-20">
<div v-for =" Premiums in Premium" :key="Premiums.id" >
<router-link :to="{ name: 'Samplepremium', params: { id: Premiums.id }}">
<div class= "hover:scale-105 transition ease-in-out duration-300 bg-neutral-800 hover:bg-neutral-900 active:bg-neutral-900 text-neutral-400 font-bold rounded-xl">
<br>
<p>{{ Premiums.name }}</p>
<img :src= "Premiums.Pic1" class="object-contain ml-6 w-60 h-80 transition ease-in-out duration-300">
<div class="grid grid-cols-2 grid-rows-fit text-left ml-6">
<p>name:</p>
<p>{{ Premiums.name }}</p>
</div><br>
</div>
</router-link>
</div>
So I realise that if I have the name == selectedProfile it wont get any close searchs only a specific profile names I'm just unsure how I can combine the filteredPeople into the query and how to stop the page from reloading and deleting whats in the input field every time I try and enter a search.
I hope what I've shown makes some sense and that someone might have any ideas on how to do this any help what be greatly appreciated thanks.

How to unshift to append under spicific div in Vue

I have comments and this comment containe likes, My propblem is when I try to push replay to the comment it is append to the wrong comment, So I used this.$el; to get the target comment bu the propblem is unshift/push just use with list and it shows error push is not a function
My qustion is how I can use unshift/push to append under spicific div not list
async addReplay(comment, e){
const element = this.$el; //this to get the target div
}
here the post replay function
async getaddReplay(id, setReplayPlace){
await axios.get('/account/api/auth/user/')
.then(response => {
this.currentUserImage = response.data.profile_image
})
const replayData = {
content: this.commentReplayContent,
video: this.$route.params.video_id,
parent: id
}
await axios.post(`/video/api/video/comment/${id}/replay/create/`, replayData)
.then(response => {
console.log(this.setReplayPlace)
// here I want append the item to spicific div
this.setReplayPlace.unshift({ content: this.commentReplayContent, author: this.$store.state.user.username, id:response.data.id, author_image:this.currentUserImage, video:this.$route.params.video_id ,likes:0, total_parents:0, check_like: false, publish:'now'})
this.commentReplayContent = ''
})
.catch(error => {
console.log(error)
})
}
Edit
Here there are comments with replies component and I pass the data to repliy component using props
<ul v-for="(comment, index) in comments" :key="index">
<li class="comment-object">
<div class="image-container">
<img class="profile-pic" :src="comment.author_image" v-on:change="currentUserImage" alt="profile picture" id="user_video_comment_profile_image" refs="user_video_comment_profile_image" />
</div>
<div class="comment-text">
<h2 class="username" style="color: #C2C3C4">{{comment.author}} <span class="muted">· {{comment.publish}}</span>
<DeleteComment :comment="comment" v-if="comments || index" :comments="comments" :index="index" />
</h2>
<p class="comment">{{comment.content}} </p>
<RepliesJustAdded #justAddedReplies="addRepliesToParent" :replaiesJustAdded="replaiesJustAdded" :setReplayPlace="setReplayPlace" :allReplies="allReplies" :replaiesData="replaiesData" v-if="replaiesJustAdded || setReplayPlace || allReplies || replaiesData" />
</div>
</li>
</ul>
The Replay component
<ul v-for="replay in replies" :key="replay.id" id="video_comments_replies" >
<li class="comment-object">
<div class="image-container">
<img class="profile-pic" :src="replay.author_image" alt="profile picture" id="user_video_comment_profile_image" refs="user_video_comment_profile_image" />
</div>
<div class="comment-text">
<h2 class="username" style="color: #C2C3C4">{{replay.author}} <span class="muted">· {{replay.publish}}</span></h2>
<p class="comment">{{replay.content}} </p>
<RepliesActionButtons :replay="replay" />
</div>
</li>
</ul>
I didn't find the line where you are trying to call push but I thing I know what's wrong: your are trying to call push but array-like collections don't have such method. You should convert your collection to array before calling push. Try something like that:
// create a `NodeList` object
const divs = document.querySelectorAll('div');
// convert `NodeList` to an array
const divsArr = Array.from(divs);
After that all methods of Array.prototype will be available.

Vue-test-utils cannot call text on empty wrapper

I have the following html template
<div>
<li class="posted-comment" v-for="commentDetail in commentDetail" :key="commentDetail.id"
#mouseover="hoverIn()" #mouseout="hoverOut()">
<div class="comment-user-avatar"><img :src="commentDetail.img_url"></div>
<div class="comment-user-details">
<span class="distinct-user-name">{{ commentDetail.name}}</span>
<span class="distinct-user-title">{{ commentDetail.user }}</span>
<span class="full-stop">.</span>
<span class="distinct-time-stamp">{{ commentDetail.time}}</span>
</div>
<div class="comment-info-block-wrapper">
<div id="distinct-user-comment">
{{ commentDetail.text}}
</div>
</div>
</li>
Calling wrapper.find('li.posted-comment .comment-info-block-wrapper #distinct-user-comment') says cannot call text on empty wrapper, looks like the "distinct-user-comment" id cant be found
describe('Comment.vue', () => {
it('renders distinct user comment class', () => {
const string = 'So what the German automaker is likely to focus on today is the bigger picture. This will be the first time we see the Taycan free from any prototype bodywork.';
const wrapper = shallowMount(Comment)
expect(wrapper.find("li.posted-comment .comment-info-block-wrapper #distinct-user-comment").text()).equal(string)
})
})

Ionic 4 vue - Get slide index

In ionic/vue I cant figure out how to get slide index. getActiveIndex is not even firing, it is on the documentation but its not clear how to use it. ionSlideDidChange fires but I cant see anything related to index of an active slide. What is the best way to know which slider is active?
<ion-slides pager="true" #ionSlideDidChange="ionSlideDidChange" #getActiveIndex="getActiveIndex($event)" :options="slideOptions">
<ion-slide v-for="item in paymentAccounts" :key="item.code">
<div class="account-info">
<div class="account-name">
{{ item.label }}
<br />
R {{ item.balance }}
</div>
<div class="account-footer">
<ion-grid>
<ion-row>
<ion-col class="moneyInOut-label">Money-In</ion-col>
<ion-col class="moneyInOut-label">Money-Out</ion-col>
</ion-row>
<ion-row>
<ion-col class="moneyInOut-amount">{{ item.moneyIn }}</ion-col>
<ion-col class="moneyInOut-amount">{{ item.moneyOut }}</ion-col>
</ion-row>
</ion-grid>
</div>
</div>
</ion-slide>
</ion-slides>
JS:
methods: {
getActiveIndex(r) {
console.log("r", r)
},
ionSlideDidChange(e) {
console.log("e",e)
},
}
I think you can do something like this (at least, it works for me):
ionSlideDidChange(e) {
e.target.getActiveIndex().then(i => {
this.activeIndex = i;
});
}
Hope it helps,

Data Reactivity On Post Request Vue

Im having issues with my data not reacting correctly when a new object is added to the array of data. I am currently looping through an array of engagements that belong to a client like this
<div class="row mx-2 px-2 justify-content-between" v-if="!engagementLoaded">
<div class="card mb-3 shadow-sm col-lg-5 col-md-3 p-0" v-for="(engagement, index) in engagement" :key="index">
<div class="d-flex justify-content-between card-header">
<h3 class="m-0 text-muted">{{ index + 1 }}</h3>
<h5 class="align-self-center m-0"><span>Return Type: </span> {{ engagement.return_type }} </h5>
</div>
<div class="card-body text-left p-0 my-1">
<h5 class="p-4"><span>Year: </span> {{ engagement.year }} </h5>
<hr class="my-1">
<h5 class="p-4"><span>Assigned To: </span> {{ engagement.assigned_to }} </h5>
<hr class="my-1">
<h5 class="p-4"><span>Status: </span> {{ engagement.status}} </h5>
</div>
<div class="card-footer d-flex justify-content-between">
<router-link to="#" class="btn">View</router-link>
<router-link to="#" class="btn">Edit</router-link>
</div>
</div>
</div>
Everything works fine until I add a new engagement to the array. My AddEngagement Component is seperate but this is the form and script for it.
<form #submit.prevent="addEngagement" class="d-flex-column justify-content-center">
<div class="form-group">
<select class="form-control mb-3" id="type" v-model="engagement.return_type">
<option v-for="type in types" :key="type.id" :value="type">{{ type }}</option>
</select>
<input type="text" class="form-control mb-3" placeholder="Year" v-model="engagement.year">
<input type="text" class="form-control mb-3" placeholder="Assign To" v-model="engagement.assigned_to">
<input type="text" class="form-control mb-3" placeholder="Status" v-model="engagement.status">
<div class="d-flex justify-content-between">
<button type="submit" class="btn btn-primary d-flex justify-content-start">Create</button>
<router-link v-bind:to="'/client/' +client.id+ '/engagements'" class="btn btn-secondary float-right">Dismiss</router-link>
</div>
</div>
</form>
This is the addEngagement Method for the form
methods: {
addEngagement(e) {
if(!this.engagement.return_type || !this.engagement.year ){
return
} else {
this.$store.dispatch('addEngagement', {
id: this.idForEngagement,
client_id: this.client.id,
return_type: this.engagement.return_type,
year: this.engagement.year,
assigned_to: this.engagement.assigned_to,
status: this.engagement.status,
})
e.preventDefault();
}
e.preventDefault();
this.engagement = ""
this.idForEngagement++
this.$router.go(-1);
},
},
I think the issue is happening here but im not sure
this.$router.go(-1);
Ive tried this as well
this.$router.push({path: 'whatever route'})
and it did not change either
Somehow I need the parent component EngagementsList to react correctly to my newly added engagement that is submitted from the AddEngagement componenet if that makes sense..
here is the code for the addEngagement in the Vuex
addEngagement(context, engagement) {
axios.post(('/engagements'), {
client_id: engagement.client_id,
return_type: engagement.return_type,
year: engagement.year,
assigned_to: engagement.assigned_to,
status: engagement.status,
done: false
})
.then(response => {
context.commit('getClientEngagement', response.data)
})
.catch(error => {
console.log(error)
})
},
Although I can't see your code, I'm pretty certain I know the problem. You have an array but it's not reactive to the objects within. This is because Vue doesn't know to observe this array.
If you want your array to be reactive, use Vue.set from within your store model.
Vue.set(this/state, 'array_name', Array<Of objects>)
This will make sure vue watches for changes within the Array.
For your use case, you will need to append the engagement object to the existing array and then use that array:
const engagements = state.engagements
engagements.push(engagement)
Vue.set(state, 'engagements', engagements)
So i've tried different configurations of this. I changed my state description that the v-for is iterating to clientengagements
engagement now equals clientengagements
here is the mutation currently
getClientEngagements(state, engagement, clientengagements) {
state.clientengagements = clientengagements
clientengagements.push(engagement)
Vue.set(state, 'clientengagements', clientengagements)
},
Which is not working. Ive also tried
getClientEngagements(state, clientengagements) {
state.clientengagements = clientengagements
clientengagements.push(engagement)
Vue.set(state, 'clientengagements', clientengagements)
},
Which will tell me that "engagement" is not defined
If anyone is still able to help this is the Action
addEngagement(context, engagement) {
axios.post(('/engagements'), {
client_id: engagement.client_id,
return_type: engagement.return_type,
year: engagement.year,
assigned_to: engagement.assigned_to,
status: engagement.status,
done: false
})
.then(response => {
context.commit('getClientEngagements', response.data)
})
.catch(error => {
console.log(error)
})
},
The response.data is mutating my clientengagements array to just a single object of the newly added engagement..
context.commit('getClientEngagements`, response.data)
Is commiting to this mutation
getClientEngagements(state, engagement, clientengagements) {
state.clientengagements = clientengagements
clientengagements.push(engagement)
Vue.set(state, 'clientengagements', clientengagements)
},