Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add avatar component with contacts menu
Signed-off-by: Julius Härtl <jus@bitgrid.net>
- Loading branch information
1 parent
190d781
commit a1fcca5
Showing
4 changed files
with
214 additions
and
2 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,172 @@ | ||
<!-- | ||
- @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net> | ||
- | ||
- @author Julius Härtl <jus@bitgrid.net> | ||
- | ||
- @license GNU AGPL version 3 or any later version | ||
- | ||
- This program is free software: you can redistribute it and/or modify | ||
- it under the terms of the GNU Affero General Public License as | ||
- published by the Free Software Foundation, either version 3 of the | ||
- License, or (at your option) any later version. | ||
- | ||
- This program is distributed in the hope that it will be useful, | ||
- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
- GNU Affero General Public License for more details. | ||
- | ||
- You should have received a copy of the GNU Affero General Public License | ||
- along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
- | ||
--> | ||
|
||
<template> | ||
<!-- TODO: Get rid of the inline css --> | ||
<div v-tooltip="displayName" :class="{ 'icon-loading': loading, 'unknown': unknown }" :style="{width: size + 'px', height: size + 'px'}" | ||
class="avatardiv popovermenu-wrapper" @click="openMenu"> | ||
<img v-if="!loading && !unknown" :src="avatarUrlLoaded"> | ||
<span v-if="unknown">?</span> | ||
<div v-show="openedMenu" class="popovermenu"> | ||
<popover-menu :is-open="openedMenu" :menu="menu()" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
/* global oc_userconfig */ | ||
// contactsmenu: http://localhost:8000/index.php/contactsmenu/findOne | ||
import { VTooltip } from 'v-tooltip' | ||
import { PopoverMenu } from '../PopoverMenu' | ||
export default { | ||
name: 'Avatar', | ||
directives: { | ||
tooltip: VTooltip | ||
}, | ||
components: { | ||
PopoverMenu | ||
}, | ||
props: { | ||
url: { | ||
type: String, | ||
default: undefined | ||
}, | ||
user: { | ||
type: String, | ||
default: undefined | ||
}, | ||
displayName: { | ||
type: String, | ||
default: undefined | ||
}, | ||
size: { | ||
type: Number, | ||
default: 32 | ||
} | ||
}, | ||
data: function() { | ||
return { | ||
actions: [], | ||
avatarUrlLoaded: null, | ||
unknown: false, | ||
loading: true, | ||
openedMenu: false, | ||
} | ||
}, | ||
mounted: function() { | ||
let avatarUrl = OC.generateUrl( | ||
'/avatar/{user}/{size}', | ||
{ | ||
user: this.user, | ||
size: Math.ceil(this.size * window.devicePixelRatio) | ||
}) | ||
if (this.user === OC.getCurrentUser().uid) { | ||
avatarUrl += '?v=' + oc_userconfig.avatar.version | ||
} | ||
if (typeof this.url !== 'undefined') { | ||
avatarUrl = this.url | ||
} | ||
let img = new Image() | ||
const self = this | ||
img.onload = function() { | ||
self.avatarUrlLoaded = avatarUrl | ||
self.loading = false | ||
} | ||
img.onerror = function() { | ||
self.unknown = true | ||
self.loading = false | ||
} | ||
img.src = avatarUrl | ||
}, | ||
methods: { | ||
openMenu: function() { | ||
this.openedMenu = !this.openedMenu | ||
this.fetchContactsMenu() | ||
}, | ||
menu: function() { | ||
return this.actions.map((item) => { | ||
return { | ||
href: item.hyperlink, | ||
icon: item.icon, | ||
text: item.title | ||
} | ||
}); | ||
}, | ||
fetchContactsMenu: function() { | ||
fetch('http://localhost:8000/index.php/contactsmenu/findOne', { | ||
method: "POST", | ||
body: 'shareType=0&shareWith=abc3', | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
requesttoken: OC.requestToken, | ||
'OCS-Apirequest': true, | ||
} | ||
}).then((response) => { | ||
return response.json().then((json) => { | ||
this.actions = [json.topAction].concat(json.actions) | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.avatardiv { | ||
display: inline-block; | ||
} | ||
.avatardiv.unknown { | ||
background-color: #b9b9b9; | ||
position: relative; | ||
} | ||
.avatardiv span { | ||
position: absolute; | ||
color: var(--color-background); | ||
width: 100%; | ||
text-align: center; | ||
height: 100%; | ||
font-size: 12pt; | ||
/* TODO: proper centering */ | ||
padding-top: 25%; | ||
} | ||
.avatardiv img { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
.popovermenu-wrapper { | ||
position: relative; | ||
display: inline-block; | ||
} | ||
.popovermenu { | ||
display: block; | ||
} | ||
</style> |
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,26 @@ | ||
/** | ||
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net> | ||
* | ||
* @author Julius Härtl <jus@bitgrid.net> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
import Avatar from './Avatar' | ||
|
||
export default Avatar | ||
export { Avatar } |
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