From c5da4e56a690d9e9caf8ca4bad4349684b4d39c5 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Thu, 14 Jan 2021 18:14:53 -0500 Subject: Add a query configuration page (#3366) * Add a query configuration page Before, there was no way to modify a user query. Thus you need to create a new one and delete the old one afterward. Now, every user query can be modified if needed. They have their own configuration page on which it can be modified or deleted. * Change drag and drop action on queries Before, the drag and drop action needed to be validated by submitting the form to be persisted. Now, it's done automatically after the query is dropped to its final location. --- app/Controllers/configureController.php | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'app/Controllers/configureController.php') diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 917879810..b37d2cefa 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -280,6 +280,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $category_dao = FreshRSS_Factory::createCategoryDao(); $feed_dao = FreshRSS_Factory::createFeedDao(); $tag_dao = FreshRSS_Factory::createTagDao(); + if (Minz_Request::isPost()) { $params = Minz_Request::param('queries', array()); @@ -304,9 +305,92 @@ class FreshRSS_configure_Controller extends Minz_ActionController { } } + $this->view->categories = $category_dao->listCategories(false); + $this->view->feeds = $feed_dao->listFeeds(); + $this->view->tags = $tag_dao->listTags(); + + $id = Minz_Request::param('id'); + $this->view->displaySlider = false; + if (false !== $id) { + $this->view->displaySlider = true; + $this->view->query = $this->view->queries[$id]; + $this->view->queryId = $id; + } + Minz_View::prependTitle(_t('conf.query.title') . ' · '); } + /** + * Handles query configuration. + * It displays the query configuration page and handles modifications + * applied to the selected query. + */ + public function queryAction() { + $this->view->_layout(false); + + $id = Minz_Request::param('id'); + if (false === $id || !isset(FreshRSS_Context::$user_conf->queries[$id])) { + Minz_Error::error(404); + return; + } + + $category_dao = FreshRSS_Factory::createCategoryDao(); + $feed_dao = FreshRSS_Factory::createFeedDao(); + $tag_dao = FreshRSS_Factory::createTagDao(); + + $query = new FreshRSS_UserQuery(FreshRSS_Context::$user_conf->queries[$id], $feed_dao, $category_dao, $tag_dao); + $this->view->query = $query; + $this->view->queryId = $id; + $this->view->categories = $category_dao->listCategories(false); + $this->view->feeds = $feed_dao->listFeeds(); + $this->view->tags = $tag_dao->listTags(); + + if (Minz_Request::isPost()) { + $params = array_filter(Minz_Request::param('query', [])); + if (!empty($params['search'])) { + $params['search'] = urldecode($params['search']); + } + if (!empty($params['state'])) { + $params['state'] = array_sum($params['state']); + } + $params['url'] = Minz_Url::display(['params' => $params]); + $name = Minz_Request::param('name', _t('conf.query.number', $id + 1)); + if ('' === $name) { + $name = _t('conf.query.number', $id + 1); + } + $params['name'] = $name; + + $queries = FreshRSS_Context::$user_conf->queries; + $queries[$id] = new FreshRSS_UserQuery($params, $feed_dao, $category_dao, $tag_dao); + FreshRSS_Context::$user_conf->queries = $queries; + FreshRSS_Context::$user_conf->save(); + + Minz_Request::good(_t('feedback.conf.updated'), + array('c' => 'configure', 'a' => 'queries', 'params' => ['id' => $id])); + } + + Minz_View::prependTitle(_t('conf.query.title') . ' · ' . $query->getName() . ' · '); + } + + /** + * Handles query deletion + */ + public function deleteQueryAction() { + $id = Minz_Request::param('id'); + if (false === $id || !isset(FreshRSS_Context::$user_conf->queries[$id])) { + Minz_Error::error(404); + return; + } + + $queries = FreshRSS_Context::$user_conf->queries; + unset($queries[$id]); + FreshRSS_Context::$user_conf->queries = $queries; + FreshRSS_Context::$user_conf->save(); + + Minz_Request::good(_t('feedback.conf.updated'), + array('c' => 'configure', 'a' => 'queries')); + } + /** * This action handles the creation of a user query. * -- cgit v1.2.3