1
0
mirror of https://github.com/flarum/core.git synced 2025-08-01 14:10:37 +02:00

Upgrade to Ember 1.11-beta.1

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
https://github.com/emberjs/ember.js/issues/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!
This commit is contained in:
Toby Zerner
2015-02-10 18:05:40 +10:30
parent cf88fda8c8
commit c28307903b
164 changed files with 4623 additions and 4587 deletions

View File

@@ -1,116 +1,103 @@
import Ember from 'ember';
import ComposerReply from '../components/discussions/composer-reply';
import ActionButton from '../components/ui/controls/action-button';
import AlertMessage from '../components/alert-message';
import ComposerReply from 'flarum/components/composer/composer-reply';
import ActionButton from 'flarum/components/ui/action-button';
import AlertMessage from 'flarum/components/ui/alert-message';
import UseComposerMixin from 'flarum/mixins/use-composer';
export default Ember.Controller.extend(Ember.Evented, {
needs: ['application', 'alerts', 'composer'],
queryParams: ['start'],
start: '1',
searchQuery: '',
export default Ember.Controller.extend(Ember.Evented, UseComposerMixin, {
needs: ['application'],
composer: Ember.inject.controller('composer'),
alerts: Ember.inject.controller('alerts'),
loaded: false,
stream: null,
queryParams: ['start'],
start: '1',
searchQuery: '',
// Save a reply. This may be called by a composer-reply component that was
// set up on a different discussion, so we require a discussion model to
// be explicitly passed rather than using the controller's implicit one.
// @todo break this down into bite-sized functions so that extensions can
// easily override where they please.
saveReply: function(discussion, data) {
var controller = this;
var composer = this.get('controllers.composer');
var stream = this.get('stream');
loaded: false,
stream: null,
composer.set('content.loading', true);
controller.get('controllers.alerts').send('clearAlerts');
// Save a reply. This may be called by a composer-reply component that was
// set up on a different discussion, so we require a discussion model to
// be explicitly passed rather than using the controller's implicit one.
// @todo break this down into bite-sized functions so that extensions can
// easily override where they please.
saveReply: function(discussion, data) {
var post = this.store.createRecord('post', {
content: data.content,
discussion: discussion
});
var post = this.store.createRecord('post', {
content: data.content,
discussion: discussion
});
var controller = this;
var stream = this.get('stream');
return this.saveAndDismissComposer(post).then(function(post) {
discussion.setProperties({
lastTime: post.get('time'),
lastUser: post.get('user'),
lastPost: post,
lastPostNumber: post.get('number'),
commentsCount: discussion.get('commentsCount') + 1,
readTime: post.get('time'),
readNumber: post.get('number')
});
return post.save().then(function(post) {
composer.send('hide');
discussion.setProperties({
lastTime: post.get('time'),
lastUser: post.get('user'),
lastPost: post,
lastPostNumber: post.get('number'),
commentsCount: discussion.get('commentsCount') + 1,
readTime: post.get('time'),
readNumber: post.get('number')
});
// If we're currently viewing the discussion which this reply was
// made in, then we can add the post to the end of the post
// stream.
if (discussion == controller.get('model') && stream) {
stream.addPostToEnd(post);
} else {
// Otherwise, we'll create an alert message to inform the user
// that their reply has been posted, containing a button which
// will transition to their new post when clicked.
var message = AlertMessage.create({
type: 'success',
message: 'Your reply was posted.'
});
message.on('populateControls', function(controls) {
controls.pushObjectWithTag(ActionButton.create({
label: 'View',
action: function() {
controller.transitionToRoute('discussion', post.get('discussion'), {queryParams: {start: post.get('number')}});
message.send('dismiss');
}
}), 'view');
});
controller.get('controllers.alerts').send('alert', message);
// If we're currently viewing the discussion which this reply was
// made in, then we can add the post to the end of the post
// stream.
if (discussion == controller.get('model') && stream) {
stream.addPostToEnd(post);
} else {
// Otherwise, we'll create an alert message to inform the user
// that their reply has been posted, containing a button which
// will transition to their new post when clicked.
var message = AlertMessage.create({
type: 'success',
message: 'Your reply was posted.',
buttons: [{
label: 'View',
action: function() {
controller.transitionToRoute('discussion', post.get('discussion'), {queryParams: {start: post.get('number')}});
}
},
function(reason) {
var errors = reason.errors;
for (var i in reason.errors) {
var message = AlertMessage.create({
type: 'warning',
message: reason.errors[i]
});
controller.get('controllers.alerts').send('alert', message);
}
})
.finally(function() {
composer.set('content.loading', false);
}]
});
controller.get('alerts').send('alert', message);
}
});
},
// Whenever we transition to a different discussion or the logged-in user
// changes, we'll need the composer content to refresh next time the reply
// button is clicked.
clearComposerContent: Ember.observer('model', 'session.user', function() {
this.set('composerContent', undefined);
}),
actions: {
reply: function() {
var discussion = this.get('model');
var controller = this;
this.showComposer(function() {
return ComposerReply.create({
user: controller.get('session.user'),
discussion: discussion,
submit: function(data) {
controller.saveReply(discussion, data);
}
});
});
},
actions: {
reply: function() {
var controller = this;
var discussion = this.get('model');
var composer = this.get('controllers.composer');
// This action is called when the start position of the discussion
// currently being viewed changes (i.e. when the user scrolls up/down
// the post stream.)
positionChanged: function(startNumber, endNumber) {
this.set('start', startNumber);
// If the composer is already set up for this discussion, then we
// don't need to change its content - we can just show it.
if (!(composer.get('content') instanceof ComposerReply) || composer.get('content.discussion') !== discussion) {
composer.switchContent(ComposerReply.create({
user: controller.get('session.user'),
discussion: discussion,
submit: function(data) {
controller.saveReply(discussion, data);
}
}));
}
composer.send('show');
},
// This action is called when the start position of the discussion
// currently being viewed changes (i.e. when the user scrolls up/down
// the post stream.)
updateStart: function(start) {
this.set('start', start);
}
var discussion = this.get('model');
if (endNumber > discussion.get('readNumber')) {
discussion.set('readNumber', endNumber);
discussion.save();
}
}
}
});