Skip to content

Commit

Permalink
Merge branch 'development' into fix/OP-428/reinstate-template-folder
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzondervan committed Dec 9, 2024
2 parents adf70c3 + 04204f8 commit c4bf638
Show file tree
Hide file tree
Showing 33 changed files with 2,296 additions and 21 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Create a [bug report](https://github.com/OpenCatalogi/.github/issues/new/choose)
Create a [feature request](https://github.com/OpenCatalogi/.github/issues/new/choose)
]]></description>
<version>0.6.47</version>
<version>0.6.48</version>
<licence>agpl</licence>
<author mail="[email protected]" homepage="https://www.conduction.nl/">Conduction</author>
<author mail="[email protected]" homepage="https://acato.nl/">Acato</author>
Expand Down
5 changes: 4 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'publications' => ['url' => '/api/publications'],
'organizations' => ['url' => '/api/organizations'],
'themes' => ['url' => '/api/themes'],
'pages' => ['url' => '/api/pages'],
'attachments' => ['url' => '/api/attachments'],
'catalogi' => ['url' => '/api/catalogi'],
'listings' => ['url' => '/api/listings'],
Expand Down Expand Up @@ -37,6 +38,8 @@
['name' => 'search#publication', 'url' => '/api/search/publications/{publicationId}', 'verb' => 'GET', 'requirements' => ['publicationId' => '[^/]+']],
['name' => 'search#attachments', 'url' => '/api/search/publications/{publicationId}/attachments', 'verb' => 'GET', 'requirements' => ['publicationId' => '[^/]+']],
['name' => 'search#themes', 'url' => '/api/search/themes', 'verb' => 'GET'],
['name' => 'search#theme', 'url' => '/api/search/themes/{themeId}', 'verb' => 'GET', 'requirements' => ['themeId' => '\d+']]
['name' => 'search#theme', 'url' => '/api/search/themes/{themeId}', 'verb' => 'GET', 'requirements' => ['themeId' => '\d+']],
['name' => 'search#pages', 'url' => '/api/public/pages', 'verb' => 'GET'],
['name' => 'search#page', 'url' => '/api/public/pages/{pageSlug}', 'verb' => 'GET', 'requirements' => ['pageId' => '.+']]
]
];
44 changes: 44 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,47 @@
margin-left: 16px;
color: inherit;
}

/* CodeMirror */
.codeMirrorContainer {
margin-block-start: 6px;
text-align: left;
}

.prettifyButton {
margin-block-start: 10px;
}

.codeMirrorContainer * .cm-content {
border-radius: 0 !important;
border: none !important;
}
.codeMirrorContainer * .cm-editor {
outline: none !important;
}
.codeMirrorContainer.light > .vue-codemirror {
border: 1px dotted silver;
}
.codeMirrorContainer.dark > .vue-codemirror {
border: 1px dotted grey;
}

/* value text color */
.codeMirrorContainer.light * .cm-content *::selection {
color: inherit !important;
background-color: #add6ff80 !important;
}
.codeMirrorContainer.dark * .cm-content *::selection {
color: inherit !important;
background-color: #add6ff26 !important;
}

/* value text color */
.codeMirrorContainer.dark :deep(.ͼ2 .cm-activeLine) {
background-color: #add6ff26;
}

/* text cursor */
.codeMirrorContainer :deep(.cm-content) * {
cursor: text !important;
}
145 changes: 145 additions & 0 deletions lib/Controller/PagesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php

namespace OCA\OpenCatalogi\Controller;

use GuzzleHttp\Exception\GuzzleException;
use OCA\OpenCatalogi\Db\PageMapper;
use OCA\OpenCatalogi\Service\ObjectService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IAppConfig;
use OCP\IRequest;

/**
* Class PagesController
*
* This controller handles CRUD operations for pages in the OpenCatalogi app.
*/
class PagesController extends Controller
{
/**
* Constructor for PagesController
*
* @param string $appName The name of the app
* @param IRequest $request The request object
* @param PageMapper $pageMapper The page mapper for database operations
* @param IAppConfig $config The app configuration
* @param ObjectService $objectService The service for handling object operations
*/
public function __construct
(
$appName,
IRequest $request,
private readonly PageMapper $pageMapper,
private readonly IAppConfig $config,
private readonly ObjectService $objectService
)
{
parent::__construct($appName, $request);
}

/**
* Retrieve a list of pages based on provided filters and parameters.
*
* @return JSONResponse JSON response containing the list of pages and total count
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index(): JSONResponse
{
// Retrieve all request parameters
$requestParams = $this->request->getParams();

// Fetch page objects based on filters and order
$data = $this->objectService->getResultArrayForRequest('page', $requestParams);

// Return JSON response
return new JSONResponse($data);
}

/**
* Retrieve a specific page by its ID.
*
* @param string|int $id The ID of the page to retrieve
* @return JSONResponse JSON response containing the requested page
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function show(string|int $id): JSONResponse
{
// Fetch the page object by its ID
$object = $this->objectService->getObject('page', $id);

// Return the page as a JSON response
return new JSONResponse($object);
}

/**
* Create a new page.
*
* @return JSONResponse The response containing the created page object.
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function create(): JSONResponse
{
// Get all parameters from the request
$data = $this->request->getParams();

// Remove the 'id' field if it exists, as we're creating a new object
unset($data['id']);

// Save the new page object
$object = $this->objectService->saveObject('page', $data);

// Return the created object as a JSON response
return new JSONResponse($object);
}

/**
* Update an existing page.
*
* @param string|int $id The ID of the page to update.
* @return JSONResponse The response containing the updated page object.
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function update(string|int $id): JSONResponse
{
// Get all parameters from the request
$data = $this->request->getParams();

// Ensure the ID in the data matches the ID in the URL
$data['id'] = $id;

// Save the updated page object
$object = $this->objectService->saveObject('page', $data);

// Return the updated object as a JSON response
return new JSONResponse($object);
}

/**
* Delete a page.
*
* @param string|int $id The ID of the page to delete.
* @return JSONResponse The response indicating the result of the deletion.
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function destroy(string|int $id): JSONResponse
{
// Delete the page object
$result = $this->objectService->deleteObject('page', $id);

// Return the result as a JSON response
return new JSONResponse(['success' => $result], $result === true ? '200' : '404');
}
}
69 changes: 69 additions & 0 deletions lib/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,73 @@ public function theme(string|int $themeId): JSONResponse
return new JSONResponse($object);
}

/**
* Return all pages.
*
* @CORS
* @PublicPage
* @NoAdminRequired
* @NoCSRFRequired
*
* @return JSONResponse The Response containing all pages.
*/
public function pages(): JSONResponse
{
// Get all page objects with request parameters
$objects = $this->objectService->getResultArrayForRequest(objectType: 'page', requestParams: $this->request->getParams());

// Format dates for each result
$formattedResults = array_map(function($object) {
// Format created_at if it exists
if (isset($object['created_at'])) {
$created = new \DateTime($object['created_at']);
$object['created_at'] = $created->format('Y-m-d\TH:i:s.u\Z');
}
// Format updated_at if it exists
if (isset($object['updated_at'])) {
$updated = new \DateTime($object['updated_at']);
$object['updated_at'] = $updated->format('Y-m-d\TH:i:s.u\Z');
}
return $object;
}, $objects['results']);

// Prepare the response data with formatted dates
$data = [
'data' => $formattedResults
];

return new JSONResponse($data);
}

/**
* Return a specific page by slug.
*
* @CORS
* @PublicPage
* @NoAdminRequired
* @NoCSRFRequired
*
* @param string $pageSlug The slug of the page
* @return JSONResponse The Response containing the requested page
* @throws GuzzleException
*/
public function page(string $pageSlug): JSONResponse
{
// Get the page object by slug
$object = $this->objectService->getObject('page', $pageSlug);

// Format the date fields to match required format
if (isset($object['created_at'])) {
$created = new \DateTime($object['created_at']);
$object['created_at'] = $created->format('Y-m-d\TH:i:s.u\Z');
}
if (isset($object['updated_at'])) {
$updated = new \DateTime($object['updated_at']);
$object['updated_at'] = $updated->format('Y-m-d\TH:i:s.u\Z');
}

return new JSONResponse($object);
}


}
7 changes: 5 additions & 2 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function index(): JSONResponse
{
// Initialize the data array
$data = [];
$data['objectTypes'] = ['attachment', 'catalog', 'listing', 'publicationtype', 'organization', 'publication', 'theme'];
$data['objectTypes'] = ['attachment', 'catalog', 'listing', 'publicationtype', 'organization', 'publication', 'theme', 'page'];
$data['openRegisters'] = false;
$data['availableRegisters'] = [];

Expand Down Expand Up @@ -78,7 +78,10 @@ public function index(): JSONResponse
'publication_register' => '',
'theme_source' => 'internal',
'theme_schema' => '',
'theme_register' => ''
'theme_register' => '',
'page_source' => 'internal',
'page_schema' => '',
'page_register' => '',
];

// Get the current values for the object types from the configuration
Expand Down
Loading

0 comments on commit c4bf638

Please sign in to comment.