1
0
mirror of https://github.com/flarum/core.git synced 2025-07-30 21:20:24 +02:00

Hello world!

This commit is contained in:
Toby Zerner
2014-12-20 16:56:46 +10:30
commit 74db323f83
279 changed files with 11954 additions and 0 deletions

View File

View File

@@ -0,0 +1,48 @@
import Ember from 'ember';
// import NotificationMessage from '../models/notification-message';
export default Ember.Controller.extend({
needs: ['discussions'],
// The title of the forum.
// TODO: Preload this value in the index.html payload from Laravel config.
forumTitle: 'Ninetech Support Forum',
// forumTitle: '<img src="tv.png" height="24" style="vertical-align: baseline; margin-right: 5px"> TV Addicts',
// forumTitle: '<img src="gametoaid.png" height="50">',
// forumTitle: '<i class="fa fa-stethoscope" style="font-size: 140%"></i>&nbsp; Med Students Forum',
pageTitle: '',
documentTitle: function() {
return this.get('pageTitle') || this.get('forumTitle');
}.property('pageTitle', 'forumTitle'),
_updateTitle: function() {
var parts = [this.get('forumTitle')];
var pageTitle = this.get('pageTitle');
if (pageTitle) parts.unshift(pageTitle);
document.title = parts.join(' - ');
}.observes('pageTitle', 'forumTitle'),
searchQuery: '',
searchActive: false,
showDiscussionStream: false,
// notificationMessage: NotificationMessage.create({text: 'Sorry, you do not have permission to do that!', class: 'message-warning'}), // currently displaying notification message object
currentUser: null,
actions: {
hideMessage: function() {
this.set('notificationMessage', null);
},
search: function(query) {
this.transitionToRoute('discussions', {queryParams: {searchQuery: query, sort: query ? 'relevance' : 'recent'}});
},
}
});

View File

@@ -0,0 +1,17 @@
import Ember from 'ember';
export default Ember.Controller.extend({
needs: ['discussions'],
showing: false,
title: 'Replying to <em>Some Discussion Title</em>',
actions: {
close: function() {
this.set('showing', false);
}
}
});

View File

@@ -0,0 +1,103 @@
import Ember from 'ember';
import PostStream from '../models/post-stream';
export default Ember.ObjectController.extend(Ember.Evented, {
needs: ['application', 'composer'],
queryParams: ['start'],
start: '1',
searchQuery: '',
loaded: false,
postStream: null,
setup: function(discussion) {
this.set('model', discussion);
// Set up the post stream object. It needs to know about the discussion
// its representing the posts for, and we also need to inject the Ember
// data store.
var postStream = PostStream.create();
postStream.set('discussion', discussion);
postStream.set('store', this.get('store'));
this.set('postStream', postStream);
// Next, we need to load a list of the discussion's post IDs into the
// post stream object. If we don't already have this information, we'll
// need to reload the discussion model.
var promise = discussion.get('posts') ? Ember.RSVP.resolve(discussion) : discussion.reload();
// When we know we have the post IDs, we can set up the post stream with
// them. Then we're ready to load some posts!
var controller = this;
promise.then(function(discussion) {
postStream.setup(discussion.get('postIds'));
controller.set('loaded', true);
controller.send('jumpToNumber', controller.get('start'));
});
},
actions: {
reply: function() {
this.set('controllers.composer.showing', true);
this.set('controllers.composer.title', 'Replying to <em>'+this.get('model.title')+'</em>');
},
jumpToNumber: function(number) {
// In some instances, we might be given a placeholder start index
// value. We need to convert this into a numerical value.
switch (number) {
case 'last':
number = this.get('model.lastPostNumber');
break;
case 'unread':
number = this.get('model.readNumber') + 1;
break;
}
number = Math.max(number, 1);
// Let's start by telling our listeners that we're going to load
// posts near this number. The discussion view will listen and
// consequently scroll down to the appropriate position in the
// discussion.
this.trigger('loadingNumber', number);
// Now we have to actually make sure the posts around this new start
// position are loaded. We will tell our listeners when they are.
// Again, the view will scroll down to the appropriate post.
var controller = this;
this.get('postStream').loadNearNumber(number).then(function() {
Ember.run.scheduleOnce('afterRender', function() {
controller.trigger('loadedNumber', number);
});
});
},
jumpToIndex: function(index) {
// Let's start by telling our listeners that we're going to load
// posts at this index. The discussion view will listen and
// consequently scroll down to the appropriate position in the
// discussion.
this.trigger('loadingIndex', index);
// Now we have to actually make sure the posts around this index are
// loaded. We will tell our listeners when they are. Again, the view
// will scroll down to the appropriate post.
var controller = this;
this.get('postStream').loadNearIndex(index).then(function() {
Ember.run.scheduleOnce('afterRender', function() {
controller.trigger('loadedIndex', index);
});
});
},
loadRange: function(start, end, backwards) {
this.get('postStream').loadRange(start, end, backwards);
}
}
});

View File

@@ -0,0 +1,175 @@
import Ember from 'ember';
import DiscussionResult from '../models/discussion-result';
import PostResult from '../models/post-result';
export default Ember.ArrayController.extend(Ember.Evented, {
needs: ['application', 'composer'],
paned: false,
paneShowing: false,
paneTimeout: null,
panePinned: false,
current: null,
index: function() {
var index = '?';
var id = this.get('current.id');
this.get('model').some(function(result, i) {
if (result.get('id') == id) {
index = i + 1;
return true;
}
});
return index;
}.property('current', 'model.@each'),
count: function() {
return this.get('model.length');
}.property('model.@each'),
previous: function() {
var result = this.get('model').objectAt(this.get('index') - 2);
return result && result.get('content');
}.property('index'),
next: function() {
var result = this.get('model').objectAt(this.get('index'));
return result && result.get('content');
}.property('index'),
queryParams: ['sort', 'show', {searchQuery: 'q'}, 'filter'],
sort: 'recent',
show: 'discussions',
filter: '',
searchQuery: '',
loadingMore: false,
sortOptions: [
{sort: 'recent', label: 'Recent'},
{sort: 'replies', label: 'Replies'},
{sort: 'newest', label: 'Newest'},
{sort: 'oldest', label: 'Oldest'},
],
displayStartUsers: function() {
return ['newest', 'oldest'].indexOf(this.get('sort')) != -1;
}.property('sort'),
discussionsCount: function() {
return this.get('model.length');
}.property('@each'),
resultsLoading: false,
start: 0,
moreResults: function() {
return !! this.get('meta.moreUrl');
}.property('meta.moreUrl'),
meta: null,
getResults: function(start) {
var sort = this.get('sort');
// var order = this.get('order');
var order;
var show = this.get('show');
var searchQuery = this.get('searchQuery');
if (sort == 'newest') sort = 'created';
else if (sort == 'oldest') {
sort = 'created';
order = 'asc';
}
else if (sort == 'recent') {
sort = '';
}
else if (sort == 'replies') {
order = 'desc';
}
var params = {
sort: (order == 'desc' ? '-' : '')+sort,
q: searchQuery,
start: start
};
if (show == 'posts') {
if (searchQuery) params.include = 'relevantPosts';
else if (sort == 'created') params.include = 'startPost,startUser';
else params.include = 'lastPost,lastUser';
}
return this.store.find('discussion', params).then(function(discussions) {
var results = Em.A();
discussions.forEach(function(discussion) {
var relevantPosts = Em.A();
discussion.get('relevantPosts.content').forEach(function(post) {
relevantPosts.pushObject(PostResult.create(post));
});
results.pushObject(DiscussionResult.create({
content: discussion,
relevantPosts: relevantPosts,
lastPost: PostResult.create(discussion.get('lastPost')),
startPost: PostResult.create(discussion.get('startPost'))
}));
results.set('meta', discussions.get('meta'));
});
return results;
});
},
actions: {
showDiscussionPane: function() {
this.set('paneShowing', true);
},
hideDiscussionPane: function() {
this.set('paneShowing', false);
},
togglePinned: function() {
this.set('panePinned', ! this.get('panePinned'));
},
loadMore: function() {
var self = this;
this.set('start', this.get('length'));
this.set('loadingMore', true);
this.getResults(this.get('start')).then(function(results) {
self.get('model').addObjects(results);
self.set('meta', results.get('meta'));
// self.set('moreResults', !! results.get('meta.moreUrl'));
self.set('loadingMore', false);
});
},
delete: function(discussion) {
alert('are you sure you want to delete discusn: '+discussion.get('title'));
}
},
queryDidChange: function(q) {
this.get('controllers.application').set('searchQuery', this.get('searchQuery'));
this.get('controllers.application').set('searchActive', !! this.get('searchQuery'));
var sortOptions = this.get('sortOptions');
if (this.get('searchQuery') && sortOptions[0].sort != 'relevance') {
sortOptions.unshiftObject({sort: 'relevance', label: 'Relevance'});
}
else if ( ! this.get('searchQuery') && sortOptions[0].sort == 'relevance') {
sortOptions.shiftObject();
}
}.observes('searchQuery'),
paramsDidChange: function(show) {
this.set('start', 0);
}.observes('show', 'sort', 'searchQuery')
});

View File

@@ -0,0 +1,5 @@
import Ember from 'ember';
export default Ember.ArrayController.extend({
needs: ['application', 'composer']
});

View File

@@ -0,0 +1,9 @@
import Ember from 'ember';
// import NotificationMessage from '../models/notification-message';
export default Ember.Controller.extend(Ember.SimpleAuth.LoginControllerMixin, Ember.Evented, {
authenticatorFactory: 'authenticator:flarum'
});