Skip to content

Instantly share code, notes, and snippets.

@rossjha
Last active April 4, 2018 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rossjha/080295dbb2d31f3b69ff46ad2a22ae70 to your computer and use it in GitHub Desktop.
Save rossjha/080295dbb2d31f3b69ff46ad2a22ae70 to your computer and use it in GitHub Desktop.
Notifications
import Ember from 'ember';
const { Route: EmberRoute } = Ember;
export default EmberRoute.extend({
// Defaults
// Single line CP
// Multiline CP
// Private
// Lifecycle hooks
afterModel() {
this.replaceWith('notifications');
}
});
<div class="wrapper">
{{layout-header}}
<main class="container">
{{outlet}}
</main>
</div>
import Ember from 'ember';
const { Helper: EmberHelper } = Ember;
export function sortable(params, namedArgs) {
let { attr } = namedArgs;
let sortBy = namedArgs.sortBy[0].split(':');
if (attr === sortBy[0]) {
return sortBy[1];
}
}
export default EmberHelper.helper(sortable);
import Ember from 'ember';
const { Component: EmberComponent } = Ember;
export default EmberComponent.extend({
// Defaults
// Single line CP
// Multiline CP
// Private
// Lifecycle hooks
});
<header class="top">
<div class="container">
<nav>
<ul>
<li>{{link-to "Notifications" "notifications"}}</li>
</ul>
</nav>
</div>
</header>
export default function() {
this.get('notifications');
this.get('notifications/:id');
};
import { Factory, faker } from 'ember-cli-mirage';
export default Factory.extend({
approvedAt: faker.date.past(4),
approvedBy: 'samantha.carter@outplay.com',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit',
content: {
title: 'Mystery Match',
body: 'Welcome! We hope you have a great time playing Mystery Match!'
},
completedAt: faker.date.past(8),
completedBy: 'samantha.carter@outplay.com',
createdAt: faker.date.past(10),
createdBy: 'samantha.carter@outplay.com',
name: 'Welcome New Users',
tags: [{
name: 'tag one'
}],
type: 'onboarding',
updatedAt: faker.date.past(9),
updatedBy: 'samantha.carter@outplay.com'
})
import { Model } from 'ember-cli-mirage';
export default Model.extend({
});
export default function(server) {
// added this line because global wasn't created otherwise.
let notification = server.createList('notification', 10);
}
import { JSONAPISerializer } from 'ember-cli-mirage';
export default JSONAPISerializer.extend({
});
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
const { computed, get } = Ember;
export const schema = {
// Attributes
approvedAt: attr('date'),
approvedBy: attr('string'),
description: attr('string'),
content: attr(),
completedAt: attr('date'),
completedBy: attr('string'),
createdAt: attr('date'),
createdBy: attr('string'),
name: attr('string'),
tags: attr(),
type: attr('string'),
updatedAt: attr('date'),
updatedBy: attr('string'),
// Associations
// Computed Properties
};
export default Model.extend(schema);
import Ember from 'ember';
const { Route: EmberRoute } = Ember;
export default EmberRoute.extend({
// Defaults
// Single line CP
// Multiline CP
// Private
// Lifecycle hooks
model() {
return this.store.findAll('notification');
}
});
<section class="notifications">
<header>
<h1>Notifications</h1>
</header>
<div class="content">
{{#each model as |notification|}}
<div class="c-notification">
<div class="c-notification__title">{{notification.content.title}}</div>
<div class="c-notification__body">{{notification.content.body}}</div>
</div>
{{/each}}
</div>
</section>
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('notifications');
});
export default Router;
/* Layout */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
color: #444;
font-family: 'Roboto', sans-serif;
font-size: 100%;
}
.container{
max-width: 960px;
margin: 0 auto;
}
/* Type */
h1{
margin-bottom: 30px;
padding-bottom: 15px;
border-bottom: 1px solid #eee;
}
/* Lists */
main ul{
margin-left: 17px;
}
/* Table */
table{
border-collapse: collapse;
}
th, td{
padding: 10px;
text-align: left;
border: 1px solid #eee;
}
/* Actions */
[data-ember-action] {
cursor: pointer;
}
/* Nav */
nav{
margin-bottom: 30px;
padding: 15px;
background: #efefef;
}
nav a{
text-decoration: none;
color: #333;
}
nav a.active{
color: #000;
font-weight: 500;
}
nav ul li{
display: inline-block;
text-transform: uppercase;
}
nav ul li:not(:first-child) {
margin-left: 20px;
}
/* sortable-by */
[data-sortable-by] {
cursor: pointer;
}
[data-sortable-order]::before {
color: #ccc;
font-weight: 300;
}
[data-sortable-order="asc"]::before {
content: '\02191\00a0';
}
[data-sortable-order="desc"]::before {
content: '\02193\00a0';
}
.sortable th {
text-transform: capitalize;
}
/* Notifications */
.c-notification{
padding: 15px;
border: 1px solid #ccc;
border-radius: 5px;
margin-bottom: 15px;
}
import Ember from 'ember';
export default function destroyApp(application) {
Ember.run(application, 'destroy');
}
import { module } from 'qunit';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
export default function(name, options = {}) {
module(name, {
beforeEach() {
this.application = startApp();
if (options.beforeEach) {
options.beforeEach.apply(this, arguments);
}
},
afterEach() {
if (options.afterEach) {
options.afterEach.apply(this, arguments);
}
destroyApp(this.application);
}
});
}
import Resolver from '../../resolver';
import config from '../../config/environment';
const resolver = Resolver.create();
resolver.namespace = {
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix
};
export default resolver;
import Ember from 'ember';
import Application from '../../app';
import config from '../../config/environment';
export default function startApp(attrs) {
let application;
let attributes = Ember.merge({rootElement: "#test-root"}, config.APP);
attributes = Ember.merge(attributes, attrs); // use defaults, but you can override;
Ember.run(() => {
application = Application.create(attributes);
application.setupForTesting();
application.injectTestHelpers();
});
return application;
}
import resolver from './helpers/resolver';
import {
setResolver
} from 'ember-qunit';
setResolver(resolver);
{
"version": "0.10.4",
"ENV": {
"ember-cli-mirage": {
"enabled": true
}
},
"EmberENV": {
"FEATURES": {
"ds-finder-include": true
}
},
"options": {
"use_pods": true
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2"
},
"addons": {
"ember-cli-mirage": "0.2.4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment