Replace index.php with a controller

This commit is contained in:
Joas Schilling 2014-12-12 10:21:54 +01:00
Родитель 4e985f11d4
Коммит dad3c403de
8 изменённых файлов: 95 добавлений и 87 удалений

Просмотреть файл

@ -21,22 +21,26 @@
*
*/
$l = OC_L10N::get('activity');
namespace OCA\Activity\AppInfo;
$app = new Application();
$c = $app->getContainer();
// add an navigation entry
OCP\App::addNavigationEntry(array(
'id' => 'activity',
$navigationEntry = array(
'id' => $c->getAppName(),
'order' => 1,
'href' => OCP\Util::linkToRoute('activity.index'),
'icon' => OCP\Util::imagePath('activity', 'activity.svg'),
'name' => $l->t('Activity'),
));
'name' => $c->query('ActivityL10N')->t('Activity'),
'href' => $c->query('URLGenerator')->linkToRoute('activity.Activities.showList'),
'icon' => $c->query('URLGenerator')->imagePath('activity', 'activity.svg'),
);
$c->query('ServerContainer')->getNavigationManager()->add($navigationEntry);
// register the hooks for filesystem operations. All other events from other apps has to be send via the public api
OCA\Activity\HooksStatic::register();
\OCA\Activity\HooksStatic::register();
// Personal settings for notifications and emails
OCP\App::registerPersonal('activity', 'personal');
\OCP\App::registerPersonal($c->getAppName(), 'personal');
// Cron job for sending Emails
OCP\Backgroundjob::registerJob('OCA\Activity\BackgroundJob\EmailNotification');
\OCP\Backgroundjob::registerJob('OCA\Activity\BackgroundJob\EmailNotification');

Просмотреть файл

@ -28,14 +28,15 @@ use OCA\Activity\Controller\Settings;
use OCA\Activity\Data;
use OCA\Activity\DataHelper;
use OCA\Activity\GroupHelper;
use OCA\Activity\Navigation;
use OCA\Activity\ParameterHelper;
use OCA\Activity\UserSettings;
use OCP\AppFramework\App;
use OCP\IContainer;
class Application extends App {
public function __construct (array $urlParams=[]) {
parent::__construct('Activity', $urlParams);
public function __construct (array $urlParams = array()) {
parent::__construct('activity', $urlParams);
$container = $this->getContainer();
$container->registerService('ActivityData', function(IContainer $c) {
@ -72,11 +73,23 @@ class Application extends App {
);
});
$container->registerService('Navigation', function(IContainer $c) {
return new Navigation(
$c->query('ActivityL10N'),
$c->query('ServerContainer')->query('ActivityManager'),
$c->query('URLGenerator')
);
});
$container->registerService('ActivityL10N', function(IContainer $c) {
return $c->query('ServerContainer')->getL10N('activity');
});
$container->registerService('ActivitySettingsController', function(IContainer $c) {
$container->registerService('URLGenerator', function(IContainer $c) {
return $c->query('ServerContainer')->getURLGenerator();
});
$container->registerService('SettingsController', function(IContainer $c) {
/** @var \OC\Server $server */
$server = $c->query('ServerContainer');
return new Settings(
@ -84,20 +97,25 @@ class Application extends App {
$c->query('Request'),
$server->getConfig(),
$server->getSecureRandom()->getMediumStrengthGenerator(),
$server->getURLGenerator(),
$c->query('URLGenerator'),
$c->query('ActivityData'),
$c->query('ActivityL10N'),
$c->query('ServerContainer')->getUserSession()->getUser()->getUID()
$server->getUserSession()->getUser()->getUID()
);
});
$container->registerService('ActivityActivitiesController', function(IContainer $c) {
$container->registerService('ActivitiesController', function(IContainer $c) {
/** @var \OC\Server $server */
$server = $c->query('ServerContainer');
return new Activities(
$c->query('AppName'),
$c->query('Request'),
$server->getConfig(),
$c->query('ActivityData'),
$c->query('GroupHelper'),
$c->query('UserSettings')
$c->query('Navigation'),
$c->query('UserSettings'),
$server->getUserSession()->getUser()->getUID()
);
});
}

Просмотреть файл

@ -24,10 +24,6 @@
namespace OCA\Activity\AppInfo;
/** @var $this \OC\Route\Router */
$this->create('activity.index', '')
->actionInclude('activity/index.php');
$this->create('activity.ajax.fetch', 'ajax/fetch.php')
->actionInclude('activity/ajax/fetch.php');
$this->create('activity.rss', 'rss.php')
->actionInclude('activity/rss.php');
@ -39,9 +35,10 @@ $this->create('activity.rss', 'rss.php')
'activity'
);
$application = new \OCA\Activity\AppInfo\Application();
$application = new Application();
$application->registerRoutes($this, ['routes' => [
['name' => 'ActivitySettings#personal', 'url' => '/settings', 'verb' => 'POST'],
['name' => 'ActivitySettings#feed', 'url' => '/settings/feed', 'verb' => 'POST'],
['name' => 'ActivityActivities#fetch', 'url' => '/activities/fetch', 'verb' => 'GET'],
['name' => 'Settings#personal', 'url' => '/settings', 'verb' => 'POST'],
['name' => 'Settings#feed', 'url' => '/settings/feed', 'verb' => 'POST'],
['name' => 'Activities#showList', 'url' => '/', 'verb' => 'GET'],
['name' => 'Activities#fetch', 'url' => '/activities/fetch', 'verb' => 'GET'],
]]);

Просмотреть файл

@ -25,47 +25,83 @@ namespace OCA\Activity\Controller;
use OCA\Activity\Data;
use OCA\Activity\GroupHelper;
use OCA\Activity\Navigation;
use OCA\Activity\UserSettings;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IRequest;
class Activities extends Controller {
const DEFAULT_PAGE_SIZE = 30;
/** @var \OCP\IConfig */
protected $config;
/** @var \OCA\Activity\Data */
protected $data;
/** @var \OCA\Activity\GroupHelper */
protected $helper;
/** @var \OCA\Activity\Navigation */
protected $navigation;
/** @var \OCA\Activity\UserSettings */
protected $settings;
/** @var string */
protected $user;
/**
* constructor of the controller
*
* @param string $appName
* @param IRequest $request
* @param IConfig $config
* @param Data $data
* @param GroupHelper $helper
* @param Navigation $navigation
* @param UserSettings $settings
* @param string $user
*/
public function __construct($appName, IRequest $request, Data $data, GroupHelper $helper, UserSettings $settings) {
public function __construct($appName, IRequest $request, IConfig $config, Data $data, GroupHelper $helper, Navigation $navigation, UserSettings $settings, $user) {
parent::__construct($appName, $request);
$this->config = $config;
$this->data = $data;
$this->helper = $helper;
$this->navigation = $navigation;
$this->settings = $settings;
$this->user = $user;
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $filter
* @return TemplateResponse
*/
public function showList($filter = 'all') {
$filter = $this->data->validateFilter($filter);
$this->navigation->setRSSToken($this->config->getUserValue($this->user, 'activity', 'rsstoken'));
return new TemplateResponse('activity', 'list', [
'appNavigation' => $this->navigation->getTemplate($filter),
'filter' => $filter,
]);
}
/**
* @NoAdminRequired
*
* @param int $page
* @param string $filter
* @param int $page
* @param string $filter
* @return TemplateResponse
*/
public function fetch($page, $filter) {
public function fetch($page, $filter = 'all') {
$pageOffset = $page - 1;
$filter = $this->data->validateFilter($filter);

Просмотреть файл

@ -77,9 +77,9 @@ class Settings extends Controller {
/**
* @NoAdminRequired
*
* @param int $notify_setting_batchtime
* @param bool $notify_setting_self
* @param bool $notify_setting_selfemail
* @param int $notify_setting_batchtime
* @param bool $notify_setting_self
* @param bool $notify_setting_selfemail
* @return DataResponse
*/
public function personal(

Просмотреть файл

@ -1,50 +0,0 @@
<?php
/**
* ownCloud - Activity App
*
* @author Frank Karlitschek
* @copyright 2013 Frank Karlitschek frank@owncloud.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
// check if the user has the right permissions to access the activities
\OCP\User::checkLoggedIn();
\OCP\App::checkAppEnabled('activity');
// activate the right navigation entry
\OCP\App::setActiveNavigationEntry('activity');
// load the needed js scripts and css
\OCP\Util::addScript('activity', 'script');
\OCP\Util::addStyle('activity', 'style');
$navigation = new \OCA\Activity\Navigation(\OCP\Util::getL10N('activity'), \OC::$server->getActivityManager(), \OC::$server->getURLGenerator());
$navigation->setRSSToken(\OCP\Config::getUserValue(\OCP\User::getUser(), 'activity', 'rsstoken'));
// get the page that is requested. Needed for endless scrolling
$data = new \OCA\Activity\Data(
\OC::$server->getActivityManager()
);
$page = $data->getPageFromParam() - 1;
$filter = $data->getFilterFromParam();
// show activity template
$tmpl = new \OCP\Template('activity', 'list', 'user');
$tmpl->assign('filter', $filter);
$tmpl->assign('appNavigation', $navigation->getTemplate($filter));
$tmpl->printPage();

Просмотреть файл

@ -111,22 +111,22 @@ class Navigation {
array(
'id' => 'all',
'name' => (string) $this->l->t('All Activities'),
'url' => Util::linkToRoute('activity.index'),
'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList'),
),
array(
'id' => 'self',
'name' => (string) $this->l->t('Activities by you'),
'url' => Util::linkToRoute('activity.index', array('filter' => 'self')),
'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'self')),
),
array(
'id' => 'by',
'name' => (string) $this->l->t('Activities by others'),
'url' => Util::linkToRoute('activity.index', array('filter' => 'by')),
'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'by')),
),
array(
'id' => 'shares',
'name' => (string) $this->l->t('Shares'),
'url' => Util::linkToRoute('activity.index', array('filter' => 'shares')),
'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'shares')),
),
);
@ -134,7 +134,7 @@ class Navigation {
array(
'id' => 'files',
'name' => (string) $this->l->t('Files'),
'url' => Util::linkToRoute('activity.index', array('filter' => 'files')),
'url' => $this->URLGenerator->linkToRoute('activity.Activities.showList', array('filter' => 'files')),
),
);

Просмотреть файл

@ -24,7 +24,10 @@
/** @var $l OC_L10N */
/** @var $theme OC_Defaults */
/** @var $_ array */
script('activity', 'script');
style('activity', 'style');
?>
<?php $_['appNavigation']->printPage(); ?>
<div id="app-content">