diff --git a/class.paperless.php b/class.paperless.php index e9735c5..a24e099 100644 --- a/class.paperless.php +++ b/class.paperless.php @@ -1473,6 +1473,32 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ return $this->renderer->json($response, array('count'=>count($paths), 'next'=>null, 'previous'=>null, 'results'=>$paths))->withStatus(200); } /* }}} */ + function storage_path($request, $response, $args) { /* {{{ */ + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $logger = $this->container->get('logger'); + + if (!isset($args['id']) || !$args['id']) + return $response->withStatus(404); + + if(!empty($settings->_extensions['paperless']['usehomefolder'])) { + if(!($rootfolder = $dms->getFolder((int) $userobj->getHomeFolder()))) + $rootfolder = $dms->getFolder($settings->_rootFolderID); + } elseif(!isset($settings->_extensions['paperless']['rootfolder']) || !($rootfolder = $dms->getFolder($settings->_extensions['paperless']['rootfolder']))) + $rootfolder = $dms->getFolder($settings->_rootFolderID); + + if ($folder = $dms->getFolder((int) $args['id'])) { + $c = $folder->hasDocuments(); + if($c > 0) + $p = $folder->getFolderPathPlain(true, '/'); + $path = array('id'=>$folder->getId(), 'name'=>$p, 'slug'=>$p, 'path'=>$p, 'match'=>'', 'matching_algorithm'=>6, 'is_insensitive'=>true, 'document_count'=>$c); + return $this->renderer->json($response, $path)->withStatus(200); + } + + return $this->renderer->json($response, array('detail'=>'No storage path matches the given query.'))->withStatus(404); + } /* }}} */ + function documents($request, $response) { /* {{{ */ $dms = $this->container->get('dms'); $userobj = $this->container->get('userobj'); @@ -1872,6 +1898,62 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */ return $this->renderer->json($response, $list)->withStatus(200); } /* }}} */ + function search($request, $response) { /* {{{ */ + $dms = $this->container->get('dms'); + $userobj = $this->container->get('userobj'); + $settings = $this->container->get('config'); + $fulltextservice = $this->container->get('fulltextservice'); + $logger = $this->container->get('logger'); + + $params = $request->getQueryParams(); +// $params['query']; +// $params['db_only']; + $list = []; + $list["total"] = 0; + $list["documents"] = []; + $list["saved_views"] = []; + $list["tags"] = []; + $list["correspondents"] = []; + $list["document_types"] = []; + $list["storage_paths"] = []; + $list["users"] = []; + $list["groups"] = []; + $list["mail_rules"] = []; + $list["mail_accounts"] = []; + $list["workflows"] = []; + $list["custom_fields"] = []; + + $total = 0; + + /* Search for saved views */ + + /* Search for saved tags */ + if($categories = $dms->getDocumentCategories()) { + $inboxtags = []; + if(!empty($settings->_extensions['paperless']['inboxtags'])) + $inboxtags = explode(',', $settings->_extensions['paperless']['inboxtags']); + foreach ($categories as $category) { + if (false !== stristr($category->getName(), $params['query'])) { + $list["tags"][] = $this->__getCategoryData($category, $inboxtags); + $total++; + } + } + } + + /* Search for users */ + if($allusers = $dms->getAllUsers()) { + foreach ($allusers as $u) { + if (false !== stristr($u->getFullName().' '.$u->getLogin(), $params['query'])) { + $list["users"][] = $this->__getUserData($u); + $total++; + } + } + } + + $list["total"] = $total; + return $this->renderer->json($response, $list)->withStatus(200); + } /* }}} */ + function ui_settings($request, $response) { /* {{{ */ $dms = $this->container->get('dms'); $userobj = $this->container->get('userobj'); @@ -3159,6 +3241,7 @@ class SeedDMS_ExtPaperless_RestAPI { /* {{{ */ $app->delete('/api/saved_views/{id}/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':delete_saved_views'); $app->patch('/api/saved_views/{id}/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':patch_saved_views'); $app->get('/api/storage_paths/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':storage_paths'); + $app->get('/api/storage_paths/{id}/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':storage_path'); $app->post('/api/documents/post_document/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':post_document'); $app->get('/api/documents/{id}/preview/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':documents_preview'); $app->get('/api/documents/{id}/thumb/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':documents_thumb'); @@ -3173,6 +3256,7 @@ class SeedDMS_ExtPaperless_RestAPI { /* {{{ */ $app->put('/api/documents/{id}/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':put_documents'); $app->delete('/api/documents/{id}/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':delete_documents'); $app->get('/api/search/autocomplete/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':autocomplete'); + $app->get('/api/search/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':search'); $app->get('/api/ui_settings/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':ui_settings'); $app->get('/api/statstotal/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':statstotal'); $app->get('/api/statistics/', \SeedDMS_ExtPaperless_RestAPI_Controller::class.':statstotal');