Last active
September 23, 2016 07:37
-
-
Save timohofmeijer/6ebe74c4bbd52c85203b1923d045959c to your computer and use it in GitHub Desktop.
Dashboard
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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
classNames: ['DashboardTile'], | |
classNameBindings: ['columnClass', 'emphasisClass'], | |
columnClass: 'col-2_sm-4', | |
defaultWidth: null, | |
didRender() { | |
this.adaptTileSize(); | |
}, | |
emphasisClass: Ember.computed('data.emphasis', function() { | |
return 'emphasis-' + this.get('data.emphasis').toString(); | |
}), | |
observeDefaultWidth: Ember.observer('defaultWidth', function() { | |
this.adaptTileSize(); | |
}), | |
adaptTileSize() { | |
this.set('columnClass', ''); | |
let tileWidth = this.get('defaultWidth'); | |
let valueWidth = this.$('.DashboardTile-value').width(); | |
if (this.get('data.next') || this.get('data.skip')) { | |
this.set('data.superSize', false); | |
let targetData = this.get('data.skip') ? this.get('data.skip') : this.get('data'); | |
if (valueWidth >= tileWidth) targetData.superSize = true; | |
} else if (valueWidth >= tileWidth) { | |
this.set('columnClass', 'col-4_sm-8'); | |
} else { | |
this.set('columnClass', 'col-2_sm-4'); | |
} | |
console.log(`${this.get('data.title')}: tileWidth: ${tileWidth}, valueWidth: ${valueWidth}`); | |
} | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
classNames: ['Dashboard'] | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
classNames: ['TileGroup'], | |
defaultWidth: null, | |
init() { | |
this._super(...arguments); | |
this.debounceResize = () => { | |
Ember.run.debounce(this, this.measureDefaultWidth, 200); | |
}; | |
$(window).on('resize', this.debounceResize); | |
}, | |
didRender() { | |
this.measureDefaultWidth(); | |
}, | |
didReceiveAttrs() { | |
let previous; | |
this.get('data.tiles').forEach((tile) => { | |
if (previous && previous.emphasis === 1 && tile.emphasis === 1 && !tile.skip) { | |
previous.next = tile; | |
tile.skip = previous; | |
} else { | |
delete tile.skip; | |
} | |
previous = tile; | |
}) | |
}, | |
measureDefaultWidth() { | |
let tilePadding = 8; | |
let colPadding = 8; | |
this.set('defaultWidth', this.$('#measure').width() - (2 * tilePadding) - (2 * colPadding)); | |
} | |
}); |
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
dashData: { | |
title: "Dashboard Title", | |
tileGroups: [ | |
{ | |
title: "TileGroup 1 Title", | |
tiles: [ | |
{ | |
emphasis: 2, | |
title: "Te leveren very long title demo", | |
value: 123, | |
unit: 'Artikelen' | |
}, | |
{ | |
emphasis: 2, | |
title: "Geleverd", | |
value: 4567, | |
unit: 'Artikelen' | |
}, | |
{ | |
emphasis: 1, | |
title: "Te factureren", | |
value: 12345678999, | |
unit: 'euro' | |
}, | |
{ | |
emphasis: 1, | |
title: "Gefactureerd", | |
value: 4567 | |
} | |
] | |
}, | |
{ | |
title: "TileGroup 2 Title", | |
tiles: [ | |
{ | |
emphasis: 1, | |
title: "In bestelling", | |
value: 123 | |
}, | |
{ | |
emphasis: 1, | |
title: "Voorraad", | |
value: 4567 | |
}, | |
{ | |
emphasis: 2, | |
title: "Economische voorraad", | |
value: 1234567 | |
}, | |
{ | |
emphasis: 1, | |
title: "Gereserveerd", | |
value: 4567 | |
} | |
] | |
} | |
] | |
} | |
}); |
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
* { | |
box-sizing: border-box; | |
} | |
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.Dashboard { | |
border: 1px solid silver; | |
border-radius: 2px; | |
padding: 16px; | |
} | |
.Dashboard-title { | |
color: rgb(76, 133, 255); | |
line-height: 1; | |
margin-bottom: 8px; | |
font-size: 20px; | |
} | |
.TileGroup { | |
border: 1px solid silver; | |
border-radius: 2px; | |
padding: 16px 16px 0 16px; | |
} | |
.TileGroup:not(:last-child) { | |
margin-bottom: 16px; | |
} | |
.TileGroup-title { | |
color: rgb(76, 133, 255); | |
line-height: 1; | |
font-size: 16px; | |
margin-bottom: 8px; | |
} | |
.TileGroup-tiles { | |
/*background: rgba(0,0,0,0.02);*/ | |
} | |
.DashboardTile-title { | |
color: rgb(76, 133, 255); | |
} | |
.DashboardTile-value { | |
color: black; | |
display: inline-block; | |
} | |
.DashboardTile-unit { | |
color: silver; | |
} | |
/* 1 */ | |
.DashboardTile.emphasis-1 .DashboardTile-inner { | |
height: 64px; | |
} | |
.DashboardTile.emphasis-1:not(:last-child) { | |
margin-bottom: 16px; | |
} | |
.DashboardTile.emphasis-1 .DashboardTile-title { | |
font-size: 11px; | |
} | |
.DashboardTile.emphasis-1 .DashboardTile-value { | |
font-size: 20px; | |
} | |
.DashboardTile.emphasis-1 .DashboardTile-unit { | |
font-size: 10px; | |
} | |
/* 2 */ | |
.DashboardTile.emphasis-2 { | |
height: 160px; | |
} | |
.DashboardTile.emphasis-2 .DashboardTile-title { | |
font-size: 14px; | |
} | |
.DashboardTile.emphasis-2 .DashboardTile-value { | |
font-size: 50px; | |
} | |
.DashboardTile-inner { | |
border: 1px solid silver; | |
border-radius: 2px; | |
padding: 8px; | |
height: 100%; | |
} | |
small { | |
color: silver; | |
font-size: 8px; | |
height: 0; | |
top: 8px; | |
left: -8px; | |
display: block; | |
position: relative; | |
} | |
#measure { | |
background: lime; | |
height: 0; | |
padding: 0; | |
} |
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
{ | |
"version": "0.10.5", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.8.0", | |
"ember-data": "2.8.0", | |
"ember-template-compiler": "2.8.0", | |
"ember-testing": "2.8.0" | |
}, | |
"addons": { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment