Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move settings to a seperate page in the admin settings #13

Merged
merged 2 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions admin.php

This file was deleted.

2 changes: 0 additions & 2 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*
*/

\OCP\App::registerAdmin('survey_client', 'admin');

$l = \OC::$server->getL10N('survey_client');

$notificationManager = \OC::$server->getNotificationManager();
Expand Down
4 changes: 4 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
<owncloud min-version="9.1" max-version="9.2" />
</dependencies>
<default_enable/>
<settings>
<admin>\OCA\Survey_Client\Settings\AdminSettings</admin>
<admin-section>\OCA\Survey_Client\Settings\AdminSection</admin-section>
</settings>
</info>
4 changes: 3 additions & 1 deletion lib/BackgroundJobs/AdminNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ protected function run($argument) {
$urlGenerator = \OC::$server->getURLGenerator();

$notification = $manager->createNotification();
$url = $urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'survey_client']);

$notification->setApp('survey_client')
->setDateTime(new \DateTime())
->setSubject('updated')
->setObject('dummy', 23)
->setLink($urlGenerator->getAbsoluteURL('index.php/settings/admin#usage-report'));
->setLink($url);

$enableAction = $notification->createAction();
$enableAction->setLabel('enable')
Expand Down
66 changes: 66 additions & 0 deletions lib/Settings/AdminSection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/


namespace OCA\Survey_Client\Settings;


use OCP\IL10N;
use OCP\Settings\ISection;

class AdminSection implements ISection {

/** @var IL10N */
private $l;

public function __construct(IL10N $l) {
$this->l = $l;
}

/**
* returns the ID of the section. It is supposed to be a lower case string
*
* @returns string
*/
public function getID() {
return 'survey_client';
}

/**
* returns the translated name as it should be displayed, e.g. 'LDAP / AD
* integration'. Use the L10N service to translate it.
*
* @return string
*/
public function getName() {
return $this->l->t('Usage report');
}

/**
* @return int whether the form should be rather on the top or bottom of
* the settings navigation. The sections are arranged in ascending order of
* the priority values. It is required to return a value between 0 and 99.
*/
public function getPriority() {
return 80;
}

}
116 changes: 116 additions & 0 deletions lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
/**
* @copyright Copyright (c) 2016 Bjoern Schiessle <bjoern@schiessle.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/


namespace OCA\Survey_Client\Settings;


use OCA\Survey_Client\Collector;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\BackgroundJob\IJobList;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IL10N;
use OCP\Settings\ISettings;

class AdminSettings implements ISettings {

/** @var Collector */
private $collector;

/** @var IConfig */
private $config;

/** @var IL10N */
private $l;

/** @var IDateTimeFormatter */
private $dateTimeFormatter;

/** @var IJobList */
private $jobList;

/**
* Admin constructor.
*
* @param Collector $collector
* @param IConfig $config
* @param IL10N $l
* @param IDateTimeFormatter $dateTimeFormatter
* @param IJobList $jobList
*/
public function __construct(Collector $collector,
IConfig $config,
IL10N $l,
IDateTimeFormatter $dateTimeFormatter,
IJobList $jobList
) {
$this->collector = $collector;
$this->config = $config;
$this->l = $l;
$this->dateTimeFormatter = $dateTimeFormatter;
$this->jobList = $jobList;
}

/**
* @return TemplateResponse
*/
public function getForm() {

$lastSentReportTime = (int) $this->config->getAppValue('survey_client', 'last_sent', 0);
if ($lastSentReportTime === 0) {
$lastSentReportDate = $this->l->t('Never');
} else {
$lastSentReportDate = $this->dateTimeFormatter->formatDate($lastSentReportTime);
}

$lastReport = $this->config->getAppValue('survey_client', 'last_report', '');
if ($lastReport !== '') {
$lastReport = json_encode(json_decode($lastReport, true), JSON_PRETTY_PRINT);
}

$parameters = [
'is_enabled' => $this->jobList->has('OCA\Survey_Client\BackgroundJobs\MonthlyReport', null),
'last_sent' => $lastSentReportDate,
'last_report' => $lastReport,
'categories' => $this->collector->getCategories()
];

return new TemplateResponse('survey_client', 'admin', $parameters);
}

/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection() {
return 'survey_client';
}

/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*/
public function getPriority() {
return 50;
}

}
4 changes: 4 additions & 0 deletions templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@

/** @var $l \OCP\IL10N */
/** @var $_ array */

script('survey_client', 'admin');
style('survey_client', 'admin');
?>

<div id="survey_client" class="section">
<h2><?php p($l->t('Usage report')); ?></h2>

Expand Down