Skip to content

Instantly share code, notes, and snippets.

@ASH-Michael
Last active April 14, 2020 20:16
Show Gist options
  • Save ASH-Michael/29da2e8e7af3e9ebf25169d4cefa298c to your computer and use it in GitHub Desktop.
Save ASH-Michael/29da2e8e7af3e9ebf25169d4cefa298c to your computer and use it in GitHub Desktop.
Dynamic Profile
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['profile-widget'],
classNameBindings: ['isInset:content-inset:content-full'],
isInset: true,
hasArgs: false,
didReceiveAttrs() {
this._super(...arguments);
const model = this.model;
this.isObject = typeof model === 'object' && !(model instanceof Array);
if (this.isObject) {
this._setModelProperties();
}
},
_setModelProperties() {
for (let property in this.model) {
// check for model property attributes passed in to component
if (this[property]) {
this.hasArgs = true;
}
// if model property attributes have been passed in, then use those
if (this.model.hasOwnProperty(property) && this.hasArgs) {
this.model[property] = this[property];
}
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['dynamic-profile'],
init() {
this._super(...arguments);
this.sectionLinks = [];
},
didReceiveAttrs() {
this._super(...arguments);
for (let property in this.model) {
console.log(property);
}
}
});
import Ember from 'ember';
import BaseWidget from 'app/components/base-widget';
export default BaseWidget.extend({
classNames: ['profile-banner']
});
import Ember from 'ember';
import BaseWidget from 'app/components/base-widget';
export default BaseWidget.extend({
classNames: ['profile-contact']
});
import Ember from 'ember';
import BaseWidget from 'app/components/base-widget';
export default BaseWidget.extend({
classNames: ['profile-cta']
});
import Ember from 'ember';
import BaseWidget from 'app/components/base-widget';
export default BaseWidget.extend({
classNames: ['profile-menu'],
init() {
this._super(...arguments);
this.sections = this.links.split(' ');
}
});
import Ember from 'ember';
import BaseWidget from 'app/components/base-widget';
export default BaseWidget.extend({
classNames: ['profile-photos']
});
import Ember from 'ember';
import BaseWidget from 'app/components/base-widget';
export default BaseWidget.extend({
classNames: ['profile-social']
});
import Ember from 'ember';
import BaseWidget from 'app/components/base-widget';
export default BaseWidget.extend({
classNames: ['profile-status']
});
import Ember from 'ember';
import BaseWidget from 'app/components/base-widget';
export default BaseWidget.extend({
classNames: ['profile-title']
});
import Ember from 'ember';
export default Ember.Component.extend({
classNames: ['status-message'],
classNameBindings: ['type'],
type: null
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Dynamic Profile POC'
});
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('index', { path: '/' });
this.route('pattern-2');
});
export default Router;
import Ember from 'ember';
import { set } from '@ember/object';
export default Ember.Route.extend({
profileData: null,
model() {
return {
id: 123,
banner: {
url: 'https://fakeimg.pl/350x120/?text=[ banner image ]',
alt: 'banner image'
},
title: 'My Profile',
contact: {
address: "123 Some Street",
phone: "(555) 123-4567",
email: "somebody@some-site.com",
website: "www.some-site.com"
},
photos: {
thumbs: [
'https://fakeimg.pl/375x375/?text=[ thumb 1 ]',
'https://fakeimg.pl/375x375/?text=[ thumb 2 ]'
],
originals: [
'https://fakeimg.pl/600x6005/?text=[ img 1 ]',
'https://fakeimg.pl/600x600/?text=[ img 2 ]'
]
},
social: [
{
url: ''
}
],
legal: ''
}
},
afterModel(model) {
set(this, 'profileData', [
{
component: 'banner',
inset: false,
content: model.banner
},
{
component: 'menu',
content: {
links: 'Photos Social'
}
},
{
component: 'title',
},
{
component: 'contact',
},
{
component: 'cta'
},
{
component: 'photos',
inset: false
},
{
component: 'social'
}
]);
},
setupController(controller, model) {
// Call _super for default behavior
this._super(controller, model);
// Implement your custom setup after
this.controllerFor('index')
.set('profileData', this.profileData);
}
});
import Ember from 'ember';
export default Ember.Route.extend({
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
p {
margin: 0 0 1rem;
}
h1 {
margin: 0 0 0.5rem;
}
img {
display: block;
}
button {
width: 100%;
border: none;
border-radius: 0.25rem;
padding: 1rem 0;
color: white;
font-size: 1rem;
background: dodgerblue;
}
/*
dynamic-profile
*/
.dynamic-profile {
width: 21.875em;
border: 1px solid #979797;
}
/*
profile-widget
*/
.profile-widget.content-inset {
padding: 1rem 1rem;
}
.profile-widget.content-full {
padding: 0;
}
.profile-widget:last-child:not(.content-full) {
padding-bottom: 1rem;
}
/*
profile-contact
*/
.profile-contact p {
margin: 0;
}
.profile-contact span {
display: block;
}
/*
profile-menu
*/
.profile-menu ul {
margin: 0;
padding: 0;
display: flex;
border-bottom: 1px solid #979797;
}
.profile-menu li {
padding: 0 1rem 1rem 0;
list-style: none;
}
/*
profile-photos
*/
.profile-photos {
display: flex;
justify-content: space-between;
}
.profile-photos .thumb-container {
flex-basis: 49%;
}
.profile-photos img {
max-width: 100%;
display: block;
flex-shrink: 0;
}
/*
profile-social
*/
.profile-social ul {
padding: 0;
display: flex;
justify-content: space-around;
}
.profile-social li {
list-style: none;
}
.profile-social a {
padding: 1rem;
border-radius: 100%;
display: inline-flex;
background: dodgerblue;
}
.profile-social svg {
width: 1.75rem;
height: 1.75rem;
}
/*
3rd party status-message component
*/
.status-message {
padding: 1rem;
color: #383d41;
background: #E2E3E5;
}
.status-message.info {
color: #31708f;
background: #d9edf7;
}
.status-message.success {
color: #3C763D;
background: #e2efda;
}
.status-message.warning {
color: #8A6D3B;
background: #fcf8e3;
}
.status-message.error {
color: #A94442;
background: #f2DEDE;
}
.status-message p:last-of-type {
margin: 0;
}
<h1>{{appName}}</h1>
<nav>
{{#link-to 'index'}}Default{{/link-to}}
{{#link-to 'pattern-2'}}Pattern 2{{/link-to}}
</nav>
<br>
{{outlet}}
<br>
<br>
{{yield
(hash
banner=(component 'profile-banner' model=model.banner)
menu=(component 'profile-menu')
title=(component 'profile-title' model=model.title)
status=(component 'profile-status')
contact=(component 'profile-contact' model=model.contact)
cta=(component 'profile-cta')
photos=(component 'profile-photos' model=model.photos)
social=(component 'profile-social' model=model.social)
legal=(component 'profile-legal' model=model.legal)
)
}}
{{#if (has-block)}}
{{yield}}
{{else}}
<img src={{model.url}} alt={{model.alt}}>
{{/if}}
{{#if (has-block)}}
{{yield}}
{{else}}
<p>
<span>{{model.address}}</span>
<span>{{model.phone}}</span>
<span>{{model.email}}</span>
<span>{{model.website}}</span>
</p>
{{/if}}
{{#if (has-block)}}
{{yield}}
{{else}}
<button>Select Profile</button>
{{/if}}
{{#if (has-block)}}
{{yield}}
{{else}}
<ul>
<li>Overview</li>
{{#each sections as |section|}}
<li><a href="#">{{section}}</a></li>
{{/each}}
</ul>
{{/if}}
{{#if (has-block)}}
{{yield}}
{{else}}
{{#each model.thumbs as |thumb|}}
<div class="thumb-container">
<img src={{thumb}} alt="thumb 1">
</div>
{{/each}}
{{/if}}
{{#if (has-block)}}
{{yield}}
{{else}}
<ul>
<li id="ember411" class="profile-connect__link ember-view">
<a href="#">
<svg width="16" height="31" viewBox="0 0 16 31" xmlns="http://www.w3.org/2000/svg"><path d="M15.33 11.316c-.001-.014-.012-.028-.03-.069H9.746c-.004-.118-.009-.204-.009-.29 0-1.123-.003-2.246.002-3.368 0-.263.02-.525.041-.787.015-.19.063-.376.13-.556.138-.373.392-.632.76-.779.103-.041.21-.074.318-.1.281-.064.567-.091.854-.09 1.037.005 2.073.011 3.11.015.076 0 .159.025.238-.043.008-.207.018-.421.024-.636l.044-1.767c.02-.748.04-1.496.058-2.245.001-.06-.01-.121-.018-.193-.37-.035-.726-.077-1.083-.101A50.659 50.659 0 0 0 12.78.229c-.853-.035-1.705-.042-2.555.068-.843.108-1.658.316-2.43.677-1.127.526-2.03 1.308-2.668 2.381-.553.929-.832 1.94-.9 3.014-.015.214-.014.43-.014.644-.001 1.322 0 2.644-.002 3.966 0 .085.025.175-.043.268h-.253l-3.228.001c-.085 0-.173-.014-.268.026-.002.1-.006.195-.006.289v4.467c0 .096-.003.191 0 .287.003.045.016.09.027.15.086.003.165.007.243.007h1.124l2.129.001c.085 0 .175-.021.262.038.025.098.014.201.014.303V30.41c0 .08-.002.16.002.239.002.044.014.088.024.143h2.546l2.68-.001c.084 0 .173.02.27-.032l.001-.735V18.007c0-.255-.003-.51 0-.765.004-.245-.015-.49.013-.73.09-.057.18-.037.266-.037h2.846c.654 0 1.307 0 1.961-.002.085 0 .175.019.26-.029.006-.033.015-.063.016-.094l.235-4.915c.001-.04 0-.08-.003-.119" fill="#FFF" fill-rule="evenodd"></path></svg>
</a>
</li>
<li id="ember413" class="profile-connect__link ember-view">
<a href="#">
<svg width="28" height="28" viewBox="0 0 28 28" xmlns="http://www.w3.org/2000/svg"><g fill="#FFF" fill-rule="evenodd"><path d="M24.74 19.817c-.072 1.402-.51 2.681-1.611 3.657-.796.705-1.744 1.064-2.774 1.169a35.71 35.71 0 0 1-3.208.17 246.42 246.42 0 0 1-6.556-.001c-1.162-.018-2.336-.049-3.48-.223-2.34-.357-3.795-1.92-4.052-4.288-.117-1.081-.155-2.175-.168-3.264-.025-2.13-.031-4.26.002-6.39.019-1.181.045-2.373.223-3.537.36-2.344 1.92-3.794 4.287-4.05 1.084-.118 2.18-.157 3.27-.17 2.134-.025 4.268-.03 6.402.003 1.182.018 2.377.043 3.542.221 2.352.36 3.805 1.915 4.066 4.273.116 1.051.143 2.114.17 3.172.027 1.1.006 2.202.006 3.303l.056.001c-.055 1.985-.073 3.972-.175 5.954m2.545-8.773c-.022-1.458-.035-2.934-.267-4.367-.48-2.956-2.2-4.92-5.11-5.78-1.26-.373-2.564-.4-3.861-.416-2.33-.03-4.66-.055-6.99-.02-1.46.022-2.939.033-4.373.267-3.013.493-4.988 2.25-5.82 5.22C.522 7.173.494 8.43.478 9.684c-.03 2.326-.045 4.652-.023 6.978.013 1.305.054 2.615.189 3.912.182 1.757.863 3.31 2.172 4.554 1.394 1.325 3.098 1.903 4.966 2 2.016.107 4.037.12 6.056.175l.001-.047c.939 0 1.878.03 2.815-.007 1.46-.057 2.939-.037 4.374-.267 3.041-.488 5.03-2.256 5.859-5.255.335-1.213.362-2.462.378-3.705.03-2.326.055-4.652.02-6.977"></path><path d="M20.93 4.92a1.856 1.856 0 0 0-1.835 1.889 1.848 1.848 0 0 0 1.878 1.842 1.85 1.85 0 0 0 1.852-1.868A1.857 1.857 0 0 0 20.93 4.92M14.262 18.824a4.592 4.592 0 1 1 0-9.184 4.592 4.592 0 0 1 0 9.184m-.007-11.665a7.084 7.084 0 0 0-7.096 7.086 7.084 7.084 0 0 0 7.094 7.088 7.085 7.085 0 0 0 7.08-7.07 7.084 7.084 0 0 0-7.078-7.104"></path></g></svg>
</a>
</li>
<li id="ember415" class="profile-connect__link ember-view">
<a href="#">
<svg width="27" height="23" viewBox="0 0 27 23" xmlns="http://www.w3.org/2000/svg"><path d="M.47 19.886c2.925.269 5.565-.455 7.903-2.255-1.144-.078-2.18-.433-3.094-1.117a5.41 5.41 0 0 1-1.903-2.616c.4 0 .79.017 1.179-.005a7.84 7.84 0 0 0 1.143-.16C4.13 13.3 2.92 12.426 2.125 11.01c-.482-.856-.75-1.947-.672-2.67.382.143.754.312 1.143.42.392.108.8.156 1.204.207C1.404 6.948.88 4.538 2.182 1.66c2.984 3.503 6.712 5.42 11.276 5.733-.035-.348-.081-.661-.096-.976-.08-1.695.501-3.134 1.743-4.282C16.47.873 18.101.457 19.912.795c1.046.197 1.96.69 2.713 1.454.11.113.21.147.373.109 1.02-.236 1.999-.58 2.913-1.096.091-.051.188-.092.333-.162-.424 1.273-1.193 2.212-2.25 2.944 1.026-.08 1.99-.384 2.98-.79a10.402 10.402 0 0 1-1.68 1.963c-.267.243-.547.472-.832.691a.442.442 0 0 0-.193.412c.064 1.565-.142 3.102-.564 4.605a16.31 16.31 0 0 1-1.538 3.676 15.763 15.763 0 0 1-2.607 3.418 14.483 14.483 0 0 1-4.811 3.173 15.56 15.56 0 0 1-5.34 1.114c-1.296.044-2.582-.038-3.85-.31-1.278-.275-2.516-.679-3.68-1.285-.481-.25-.957-.512-1.435-.768l.025-.057" fill="#FFF" fill-rule="evenodd"></path></svg>
</a>
</li>
</ul>
{{/if}}
{{#if (has-block)}}
{{yield}}
{{else}}
profile status
{{/if}}
{{#if (has-block)}}
{{yield}}
{{else}}
<h1>{{title}}</h1>
{{/if}}
{{#if (has-block)}}
{{yield}}
{{else}}
<p><strong>{{title}}</strong></p>
<p>{{message}}</p>
{{/if}}
{{#dynamic-profile model=model as |profile|}}
{{log profileData}}
{{#each profileData as |data|}}
{{component (get profile data.component)
isInset=data.inset
}}
{{/each}}
{{profile.banner
isInset=false
}}
{{profile.menu
links='Photos Social'
}}
{{profile.title
title="My Profile"
}}
{{#profile.status
isInset=false
}}
{{status-message
type="warning"
title="Some Warning"
message="A message that you should pay attention to, but nothing you should worry about."
}}
{{/profile.status}}
{{profile.contact}}
{{profile.cta}}
{{profile.photos
isInset=false
}}
{{profile.social}}
{{#profile.status
isInset=false
}}
{{#status-message}}
<p>Information may be self-reported.</p>
<p>Additional fees may apply. Please contact the center for details.</p>
{{/status-message}}
{{/profile.status}}
{{/dynamic-profile}}
{
"version": "0.15.1",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js",
"ember": "3.4.3",
"ember-template-compiler": "3.4.3",
"ember-testing": "3.4.3"
},
"addons": {
"ember-data": "3.4.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment