-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Improved: user card so as to allow user jump directly to the details page (#91)
- Loading branch information
Showing
5 changed files
with
161 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<template> | ||
<img :src="imageUrl"/> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from "vue"; | ||
import { useAuthStore } from '@/store/auth'; | ||
export default defineComponent({ | ||
name: "Image", | ||
props: ['src'], | ||
components: {}, | ||
mounted() { | ||
this.setImageUrl(); | ||
}, | ||
updated() { | ||
this.setImageUrl(); | ||
}, | ||
data() { | ||
return { | ||
imageUrl: require("@/assets/images/defaultImage.png") | ||
} | ||
}, | ||
methods: { | ||
checkIfImageExists(src: string) { | ||
return new Promise((resolve, reject) => { | ||
const img = new Image(); | ||
img.onload = function () { | ||
resolve(true); | ||
} | ||
img.onerror = function (error) { | ||
Check warning on line 31 in src/components/Image.vue
|
||
reject(false); | ||
} | ||
img.src = src; | ||
}) | ||
}, | ||
setImageUrl() { | ||
if (this.src) { | ||
if (this.src.indexOf('assets/') != -1) { | ||
// Assign directly in case of assets | ||
this.imageUrl = this.src; | ||
} else if (this.src.startsWith('http')) { | ||
// If starts with http, it is web url check for existence and assign | ||
this.checkIfImageExists(this.src).then(() => { | ||
this.imageUrl = this.src; | ||
}).catch(() => { | ||
console.error("Image doesn't exist", this.src); | ||
Check warning on line 47 in src/components/Image.vue
|
||
}) | ||
} else { | ||
const authStore = useAuthStore(); | ||
const baseURL = authStore.getBaseUrl.replace("/api", "") | ||
const imageUrl = baseURL.concat(this.src) | ||
this.checkIfImageExists(imageUrl).then(() => { | ||
this.imageUrl = imageUrl; | ||
}).catch(() => { | ||
console.error("Image doesn't exist", imageUrl); | ||
Check warning on line 57 in src/components/Image.vue
|
||
}) | ||
} | ||
} | ||
} | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<template> | ||
<ion-content> | ||
<ion-list> | ||
<ion-list-header>{{ authStore.current?.partyName ? authStore.current.partyName : authStore.current.userLoginId }}</ion-list-header> | ||
|
||
<ion-item button @click="redirectToUserDetails()"> | ||
<ion-label>{{ translate("View profile") }}</ion-label> | ||
<ion-icon :icon="personCircleOutline" /> | ||
</ion-item> | ||
<ion-item button lines="none" @click="logout()"> | ||
<ion-label color="danger">{{ translate("Logout") }}</ion-label> | ||
<ion-icon :icon="exitOutline" color="danger"/> | ||
</ion-item> | ||
</ion-list> | ||
</ion-content> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { | ||
IonContent, | ||
IonIcon, | ||
IonItem, | ||
IonLabel, | ||
IonList, | ||
IonListHeader, | ||
popoverController, | ||
} from "@ionic/vue"; | ||
import { defineComponent } from "vue"; | ||
import { translate } from "@/i18n"; | ||
import { exitOutline, personCircleOutline } from 'ionicons/icons'; | ||
import { useAuthStore } from '@/store/auth'; | ||
export default defineComponent({ | ||
name: "UserActionsPopover", | ||
components: { | ||
IonContent, | ||
IonIcon, | ||
IonItem, | ||
IonLabel, | ||
IonList, | ||
IonListHeader, | ||
}, | ||
methods: { | ||
redirectToUserDetails() { | ||
window.location.href = `${process.env.VUE_APP_USERS_LOGIN_URL}?oms=${this.authStore.oms}&token=${this.authStore.token.value}&expirationTime=${this.authStore.token.expiration}&partyId=${this.authStore.current.partyId}` | ||
popoverController.dismiss() | ||
}, | ||
async logout() { | ||
await this.authStore.logout() | ||
popoverController.dismiss() | ||
} | ||
}, | ||
setup() { | ||
const authStore = useAuthStore(); | ||
return { | ||
authStore, | ||
exitOutline, | ||
personCircleOutline, | ||
translate | ||
} | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters