Skip to content

Commit 373f61a

Browse files
committed
feat: Add User By Name Web component
This change will allow to display the user full name with its avatar by using a simple Web Component tag 'user-by-name'.
1 parent b0f2295 commit 373f61a

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

webapp/src/main/webapp/js/ExtendedDomPurify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
SAFE_FOR_TEMPLATES: true,
4646
svg: true
4747
},
48-
ADD_TAGS: ["iframe", "content-link"],
48+
ADD_TAGS: ["iframe", "content-link", "user-by-name"],
4949
ADD_ATTR: ['is', 'target', 'allow', 'allowfullscreen', 'frameborder', 'scrolling', 'v-identity-popover'],
5050
});
5151
DOMPurify.addHook('afterSanitizeAttributes', function(node) {

webapp/src/main/webapp/vue-apps/common/initWebComponents.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919
import './web-components/ContentLinkWebComponent.js';
20+
import './web-components/UserByNameWebComponent.js';
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class UserByName extends HTMLElement {
2+
3+
constructor(params) {
4+
super(params);
5+
}
6+
7+
connectedCallback() {
8+
const username = this.textContent?.replace?.(/^@/, '')?.trim?.();
9+
if (username?.length) {
10+
fetch(`/portal/rest/v1/social/identities/organization/${username}`, {
11+
method: 'GET',
12+
credentials: 'include',
13+
}).then(resp => resp?.ok && resp.json()).then(identity => {
14+
if (identity) {
15+
const template = document.createElement('template');
16+
let htmlContent = `<a href="/portal/profile/${username}" target="_blank" class="d-inline-flex position-relative">`;
17+
htmlContent += ' <div class="v-avatar ma-0 absolute-vertical-center z-index-one" style="height: 1.5em;min-width: 1.5em;width: 1.5em;">';
18+
htmlContent += ` <img src="${identity.profile.avatar}" class="object-fit-cover">`;
19+
htmlContent += ' </div>';
20+
htmlContent += ` <div class="overflow-hidden" style="margin-left: calc(1.6em + 4px);">${identity.profile.fullname}</div>`;
21+
htmlContent += '</a>';
22+
template.innerHTML = htmlContent;
23+
const node = template.content.firstElementChild;
24+
this.replaceWith(node);
25+
} else {
26+
throw new Error();
27+
}
28+
}).catch(e => {
29+
console.debug(e); // eslint-disable-line no-console
30+
const template = document.createElement('template');
31+
template.innerHTML = `<div>${username}</div>`;
32+
const node = template.content.firstElementChild;
33+
this.replaceWith(node);
34+
});
35+
}
36+
}
37+
38+
}
39+
40+
window.customElements.define('user-by-name', UserByName);

0 commit comments

Comments
 (0)