Skip to content

Commit

Permalink
Upgrade to Ember 1.11-beta.1
Browse files Browse the repository at this point in the history
HTMLBars goodness! Since there was some breakage and a lot of fiddling
around to get some things working, I took this opportunity to do a big
cleanup of the whole Ember app. I accidentally worked on some new
features too :3

Note that the app is still broken right now, pending on
emberjs/ember.js#10401

Cleanup:
- Restructuring of components
- Consolidation of some stuff into mixins, cleanup of some APIs that
will be public
- Change all instances of .property() / .observes() / .on() to
Ember.computed() / Ember.observer() / Ember.on() respectively (I think
it is more readable)
- More comments
- Start conforming to a code style (2 spaces for indentation)

New features:
- Post hiding/restoring
- Mark individual discussions as read by clicking
- Clicking on a read discussion jumps to the end
- Mark all discussions as read
- Progressively mark the discussion as read as the page is scrolled
- Unordered list post formatting
- Post permalink popup

Demo once that Ember regression is fixed!
  • Loading branch information
tobyzerner committed Feb 10, 2015
1 parent cf88fda commit c283079
Show file tree
Hide file tree
Showing 164 changed files with 4,708 additions and 4,672 deletions.
8 changes: 7 additions & 1 deletion ember/Brocfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

var EmberApp = require('ember-cli/lib/broccoli/ember-app');

var app = new EmberApp();
var app = new EmberApp({
vendorFiles: {
'handlebars.js': null
}
});

app.import('bower_components/ember/ember-template-compiler.js');

app.import('bower_components/bootstrap/dist/js/bootstrap.js');
app.import('bower_components/spin.js/spin.js');
Expand Down
53 changes: 53 additions & 0 deletions ember/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Flarum

This README outlines the details of collaborating on this Ember application.
A short introduction of this app could easily go here.

## Prerequisites

You will need the following things properly installed on your computer.

* [Git](http://git-scm.com/)
* [Node.js](http://nodejs.org/) (with NPM)
* [Bower](http://bower.io/)
* [Ember CLI](http://www.ember-cli.com/)
* [PhantomJS](http://phantomjs.org/)

## Installation

* `git clone <repository-url>` this repository
* change into the new directory
* `npm install`
* `bower install`

## Running / Development

* `ember server`
* Visit your app at [http://localhost:4200](http://localhost:4200).

### Code Generators

Make use of the many generators for code, try `ember help generate` for more details

### Running Tests

* `ember test`
* `ember test --server`

### Building

* `ember build` (development)
* `ember build --environment production` (production)

### Deploying

Specify what it takes to deploy your app.

## Further Reading / Useful Links

* [ember.js](http://emberjs.com/)
* [ember-cli](http://www.ember-cli.com/)
* Development Browser Extensions
* [ember inspector for chrome](https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi)
* [ember inspector for firefox](https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/)

26 changes: 20 additions & 6 deletions ember/app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,38 @@
import DS from 'ember-data';
import JsonApiAdapter from 'ember-json-api/json-api-adapter';
import config from '../config/environment';

import config from 'flarum/config/environment';
import AlertMessage from 'flarum/components/ui/alert-message';

export default JsonApiAdapter.extend({
host: config.apiURL,

ajaxError: function(jqXHR) {
var errors = this._super(jqXHR);

// Reparse the errors in accordance with the JSON-API spec to fit with
// Ember Data style. Hopefully something like this will eventually be a
// part of the JsonApiAdapter.
if (errors instanceof DS.InvalidError) {
var newErrors = {};
for (var i in errors.errors) {
var error = errors.errors[i];
newErrors[error.path] = error.detail;
}
errors = new DS.InvalidError(newErrors);
} else if (errors instanceof JsonApiAdapter.ServerError) {
// @todo show an alert message
console.log(errors);
return new DS.InvalidError(newErrors);
}

// If it's a server error, show an alert message. The alerts controller
// has been injected into this adapter.
if (errors instanceof JsonApiAdapter.ServerError) {
var message = AlertMessage.create({
type: 'warning',
message: errors.message
});
this.get('alerts').send('alert', message);
return;
}

return errors;
}

});
Empty file removed ember/app/components/.gitkeep
Empty file.
44 changes: 0 additions & 44 deletions ember/app/components/alert-message.js

This file was deleted.

30 changes: 30 additions & 0 deletions ember/app/components/application/back-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Ember from 'ember';

/**
The back/pin button group in the top-left corner of Flarum's interface.
*/
export default Ember.Component.extend({
classNames: ['back-button'],
classNameBindings: ['active'],

active: Ember.computed.or('target.paneIsShowing', 'target.paneIsPinned'),

mouseEnter: function() {
this.get('target').send('showPane');
},

mouseLeave: function() {
this.get('target').send('hidePane');
},

actions: {
back: function() {
this.get('target').send('transitionFromBackButton');
this.set('target', null);
},

togglePinned: function() {
this.get('target').send('togglePinned');
}
}
});
7 changes: 7 additions & 0 deletions ember/app/components/application/forum-statistic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';

var precompileTemplate = Ember.Handlebars.compile;

export default Ember.Component.extend({
layout: precompileTemplate('{{number}} {{label}}')
});
12 changes: 12 additions & 0 deletions ember/app/components/application/go-to-top.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';

import ActionButton from 'flarum/components/ui/action-button';

export default ActionButton.extend({
title: 'Go to Top',
icon: 'arrow-up',
className: 'control-top',
action: function() {
$('html, body').stop(true).animate({scrollTop: 0});
}
})
7 changes: 7 additions & 0 deletions ember/app/components/application/powered-by.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';

var precompileTemplate = Ember.Handlebars.compile;

export default Ember.Component.extend({
layout: precompileTemplate('<a href="http://flarum.org" target="_blank">Powered by Flarum</a>')
});
27 changes: 27 additions & 0 deletions ember/app/components/application/user-dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Ember from 'ember';

import HasItemLists from 'flarum/mixins/has-item-lists';
import DropdownButton from 'flarum/components/ui/dropdown-button';
import SeparatorItem from 'flarum/components/ui/separator-item';

export default DropdownButton.extend(HasItemLists, {
layoutName: 'components/application/user-dropdown',
itemLists: ['items'],

buttonClass: 'btn btn-default btn-naked btn-rounded btn-user',
menuClass: 'pull-right',
label: Ember.computed.alias('user.username'),

populateItems: function(items) {
this.addActionItem(items, 'profile', 'Profile', 'user');
this.addActionItem(items, 'settings', 'Settings', 'cog');
items.pushObject(SeparatorItem.create());
this.addActionItem(items, 'logout', 'Log Out', 'sign-out', null, null, this);
},

actions: {
logout: function() {
this.logout();
}
}
})
27 changes: 0 additions & 27 deletions ember/app/components/back-button.js

This file was deleted.

40 changes: 40 additions & 0 deletions ember/app/components/composer/composer-body.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Ember from 'ember';

import HasItemLists from 'flarum/mixins/has-item-lists';

/**
This component is a base class for a composer body. It provides a template
with a list of controls, a text editor, and some default behaviour.
*/
export default Ember.Component.extend(HasItemLists, {
layoutName: 'components/composer/composer-body',

itemLists: ['controls'],

submitLabel: '',
placeholder: '',
content: '',
originalContent: '',
user: null,
submit: null,
loading: false,
confirmExit: '',

disabled: Ember.computed.alias('composer.minimized'),

actions: {
submit: function(content) {
this.get('submit')({
content: content
});
},

willExit: function(abort) {
// If the user has typed something, prompt them before exiting
// this composer state.
if (this.get('content') !== this.get('originalContent') && !confirm(this.get('confirmExit'))) {
abort();
}
}
}
});
41 changes: 41 additions & 0 deletions ember/app/components/composer/composer-discussion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import Ember from 'ember';

import ComposerBody from 'flarum/components/composer/composer-body';

var precompileTemplate = Ember.Handlebars.compile;

/**
The composer body for starting a new discussion. Adds a text field as a
control so the user can enter the title of their discussion. Also overrides
the `submit` and `willExit` actions to account for the title.
*/
export default ComposerBody.extend({
submitLabel: 'Post Discussion',
confirmExit: 'You have not posted your discussion. Do you wish to discard it?',
titlePlaceholder: 'Discussion Title',
title: '',

populateControls: function(items) {
var title = Ember.Component.create({
tagName: 'h3',
layout: precompileTemplate('{{ui/text-input value=component.title class="form-control" placeholder=component.titlePlaceholder disabled=component.disabled autoGrow=true}}'),
component: this
});
items.pushObjectWithTag(title, 'title');
},

actions: {
submit: function(content) {
this.get('submit')({
title: this.get('title'),
content: content
});
},

willExit: function(abort) {
if ((this.get('title') || this.get('content')) && !confirm(this.get('confirmExit'))) {
abort();
}
}
}
});
26 changes: 26 additions & 0 deletions ember/app/components/composer/composer-edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Ember from 'ember';

import ComposerBody from 'flarum/components/composer/composer-body';

var precompileTemplate = Ember.Handlebars.compile;

/**
The composer body for editing a post. Sets the initial content to the
content of the post that is being edited, and adds a title control to
indicate which post is being edited.
*/
export default ComposerBody.extend({
submitLabel: 'Save Changes',
content: Ember.computed.oneWay('post.content'),
originalContent: Ember.computed.oneWay('post.content'),

populateControls: function(controls) {
var title = Ember.Component.create({
tagName: 'h3',
layout: precompileTemplate('Editing Post #{{component.post.number}} in <em>{{discussion.title}}</em>'),
discussion: this.get('post.discussion'),
component: this
});
controls.pushObjectWithTag(title, 'title');
}
});
Loading

0 comments on commit c283079

Please sign in to comment.