-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented: user details header on user details page (#3)
- Loading branch information
Showing
5 changed files
with
147 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<template> | ||
<img :src="imageUrl"/> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from "vue"; | ||
export default defineComponent({ | ||
name: "Image", | ||
props: ['src'], | ||
components: {}, | ||
created() { | ||
if ( | ||
process.env.VUE_APP_RESOURCE_URL | ||
) { | ||
this.resourceUrl = process.env.VUE_APP_RESOURCE_URL; | ||
} | ||
}, | ||
mounted() { | ||
this.setImageUrl(); | ||
}, | ||
updated() { | ||
this.setImageUrl(); | ||
}, | ||
data() { | ||
return { | ||
resourceUrl: '', | ||
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 () { | ||
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(() => { | ||
this.$log.warn("Image doesn't exist", this.src); | ||
}) | ||
} else { | ||
// Image is from resource server, hence append to base resource url, check for existence and assign | ||
const imageUrl = this.resourceUrl.concat(this.src) | ||
this.checkIfImageExists(imageUrl).then(() => { | ||
this.imageUrl = imageUrl; | ||
}).catch(() => { | ||
this.$log.warn("Image doesn't exist", imageUrl); | ||
}) | ||
} | ||
} | ||
} | ||
}, | ||
}); | ||
</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,3 @@ | ||
{ | ||
"User details": "User details" | ||
} |
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
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,69 @@ | ||
<template> | ||
<ion-page> | ||
<ion-header :translucent="true"> | ||
<ion-toolbar> | ||
<ion-menu-button slot="start" /> | ||
<ion-title>{{ $t("User details") }}</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
|
||
<ion-content> | ||
<main> | ||
<ion-item lines="none"> | ||
<!-- TODO show image only if available --> | ||
<ion-avatar slot="start"> | ||
<Image /> | ||
</ion-avatar> | ||
<ion-label> | ||
<h1>First Last</h1> | ||
<p>username</p> | ||
</ion-label> | ||
</ion-item> | ||
</main> | ||
</ion-content> | ||
</ion-page> | ||
</template> | ||
<script> | ||
import { | ||
IonAvatar, | ||
IonContent, | ||
IonHeader, | ||
IonItem, | ||
IonLabel, | ||
IonMenuButton, | ||
IonPage, | ||
IonToolbar, | ||
IonTitle, | ||
} from "@ionic/vue"; | ||
import { defineComponent } from "vue"; | ||
import { useRouter } from 'vue-router'; | ||
import { useStore } from "vuex"; | ||
import { addOutline, arrowForwardOutline } from 'ionicons/icons'; | ||
import Image from '@/components/Image.vue' | ||
export default defineComponent({ | ||
name: "User Details", | ||
components: { | ||
Image, | ||
IonAvatar, | ||
IonContent, | ||
IonHeader, | ||
IonItem, | ||
IonLabel, | ||
IonMenuButton, | ||
IonPage, | ||
IonToolbar, | ||
IonTitle, | ||
}, | ||
setup() { | ||
const router = useRouter(); | ||
const store = useStore(); | ||
return { | ||
addOutline, | ||
arrowForwardOutline, | ||
router, | ||
store | ||
} | ||
} | ||
}) | ||
</script> |