mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
Support appending routes within the admin section by plugins
This commit is contained in:
parent
750b27f973
commit
f923d7e205
@ -1,5 +1,7 @@
|
||||
export default function() {
|
||||
this.resource('admin', function() {
|
||||
export default {
|
||||
resource: 'admin',
|
||||
|
||||
map: function() {
|
||||
this.route('dashboard', { path: '/' });
|
||||
this.resource('adminSiteSettings', { path: '/site_settings' }, function() {
|
||||
this.resource('adminSiteSettingsCategory', { path: 'category/:category_id'} );
|
||||
@ -60,6 +62,5 @@ export default function() {
|
||||
this.resource('adminBadges', { path: '/badges' }, function() {
|
||||
this.route('show', { path: '/:badge_id' });
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -89,23 +89,53 @@ Discourse.Route.reopenClass({
|
||||
},
|
||||
|
||||
mapRoutes: function() {
|
||||
var resources = {};
|
||||
|
||||
// If a module is defined as `route-map` in discourse or a plugin, its routes
|
||||
// will be built automatically. You can supply a `resource` property to
|
||||
// automatically put it in that resource, such as `admin`. That way plugins
|
||||
// can define admin routes.
|
||||
Ember.keys(requirejs._eak_seen).forEach(function(key) {
|
||||
if (/route-map$/.test(key)) {
|
||||
var module = require(key, null, null, true);
|
||||
if (!module || !module.default) { throw new Error(key + ' must export a route map.'); }
|
||||
|
||||
var mapObj = module.default;
|
||||
if (typeof mapObj === 'function') {
|
||||
mapObj = { resource: 'root', map: mapObj };
|
||||
}
|
||||
|
||||
if (!resources[mapObj.resource]) { resources[mapObj.resource] = []; }
|
||||
resources[mapObj.resource].push(mapObj.map);
|
||||
}
|
||||
});
|
||||
|
||||
Discourse.Router.map(function() {
|
||||
var router = this;
|
||||
|
||||
// Do the root resources first
|
||||
if (resources.root) {
|
||||
resources.root.forEach(function(m) {
|
||||
m.call(router);
|
||||
});
|
||||
delete resources.root;
|
||||
}
|
||||
|
||||
// Apply other resources next
|
||||
Object.keys(resources).forEach(function(r) {
|
||||
router.resource(r, function() {
|
||||
var res = this;
|
||||
resources[r].forEach(function(m) {
|
||||
m.call(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
if (routeBuilder) {
|
||||
Ember.warn("The Discourse `routeBuilder` is deprecated. Export a `route-map` instead");
|
||||
routeBuilder.call(router);
|
||||
}
|
||||
|
||||
// If a module is defined as `route-map` in discourse or a plugin, its routes
|
||||
// will be built automatically.
|
||||
Ember.keys(requirejs._eak_seen).forEach(function(key) {
|
||||
if (/route-map$/.test(key)) {
|
||||
var module = require(key, null, null, true);
|
||||
if (!module) { throw new Error(key + ' must export a map function.'); }
|
||||
module.default.call(router);
|
||||
}
|
||||
});
|
||||
|
||||
this.route('unknown', {path: '*path'});
|
||||
});
|
||||
|
@ -116,16 +116,15 @@ class PostDestroyer
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def make_previous_post_the_last_one
|
||||
last_post = Post.where("topic_id = ? and id <> ?", @post.topic_id, @post.id).order('created_at desc').limit(1).first
|
||||
if last_post.present?
|
||||
@post.topic.update_attributes(
|
||||
last_posted_at: last_post.created_at,
|
||||
last_post_user_id: last_post.user_id,
|
||||
highest_post_number: last_post.post_number
|
||||
last_posted_at: last_post.created_at,
|
||||
last_post_user_id: last_post.user_id,
|
||||
highest_post_number: last_post.post_number
|
||||
)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user