Skip to content

Commit

Permalink
#47: Creating new export configurations now works.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfranco committed Dec 20, 2024
1 parent a5766fb commit c329e19
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 44 deletions.
21 changes: 0 additions & 21 deletions application/views/scripts/export/newconfig.phtml

This file was deleted.

5 changes: 1 addition & 4 deletions assets/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,7 @@ function saveJSON() {
if (JSONString === "}") JSONString = "{}";

$.ajax({
url:
"../exports/" +
$("#configId").attr("value") +
"/insertrevision",
url: $("#config-body").data("insert-revision-url"),
type: "POST",
dataType: "json",
data: {
Expand Down
51 changes: 33 additions & 18 deletions src/Controller/AdminExports.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,19 @@ public function latestrevisionAction(int $exportId)
$result = $stmt->executeQuery();
$latestRevision = $result->fetchAssociative();

return JsonResponse::fromJsonString($latestRevision['json_data']);
if ($latestRevision) {
return JsonResponse::fromJsonString($latestRevision['json_data']);
} else {
return new JsonResponse([
'group1' => [
'title' => 'Please fill out an h1 section to give this group a name',
'section1' => [
'type' => 'h1',
'value' => '',
],
],
]);
}
}

/**
Expand Down Expand Up @@ -153,8 +165,14 @@ public function viewjsonAction(int $revisionId)
#[Route('/admin/exports/create', name: 'admin_exports_create')]
public function newconfigAction()
{
$data['catalogs'] = [];
$lookupSession = $this->osidRuntime->getCourseManager()->getCourseCatalogLookupSession();
$data['catalogs'] = $lookupSession->getCourseCatalogs();
$catalogs = $lookupSession->getCourseCatalogs();
while ($catalogs->hasNext()) {
$data['catalogs'][] = $catalogs->getNextCourseCatalog();
}

return $this->render('admin/export/create_config.html.twig', $data);
}

/**
Expand Down Expand Up @@ -183,26 +201,23 @@ public function deleteconfigAction()

/**
* Insert a new archive configuration into the database.
*
* @return void
*
* @since 1/23/18
*/
public function insertconfigAction()
#[Route('/admin/exports/insert', name: 'admin_exports_insert_config', methods: ['POST'])]
public function insertconfigAction(Request $request)
{
if ($this->getRequest()->isPost()) {
$safeLabel = filter_input(\INPUT_POST, 'label', \FILTER_SANITIZE_SPECIAL_CHARS);
$safeCatalogId = filter_input(\INPUT_POST, 'catalog_id', \FILTER_SANITIZE_SPECIAL_CHARS);
$label = filter_var($request->get('label'), \FILTER_SANITIZE_SPECIAL_CHARS);
$catalogId = filter_var($request->get('catalog_id'), \FILTER_SANITIZE_SPECIAL_CHARS);

$db = Zend_Registry::get('db');
$query =
'INSERT INTO archive_configurations (id, label, catalog_id)
VALUES (NULL,:label,:catalogId)';
$stmt = $db->prepare($query);
$stmt->execute([':label' => $safeLabel, ':catalogId' => $safeCatalogId]);
}
$db = $this->entityManager->getConnection();
$query = 'INSERT INTO archive_configurations (id, label, catalog_id) VALUES (NULL,:label,:catalogId)';
$stmt = $db->prepare($query);
$stmt->bindValue('label', $label);
$stmt->bindValue('catalogId', $catalogId);
$stmt->execute();

$this->_helper->redirector('export', 'admin');
return $this->redirectToRoute('admin_exports_config', [
'exportId' => $db->lastInsertId(),
]);
}

/**
Expand Down
22 changes: 22 additions & 0 deletions templates/admin/export/create_config.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends 'base.html.twig' %}

{% block importmap %}
{# do NOT call parent() #}
{{ importmap(['app', 'export']) }}
{% endblock %}

{% block body %}
<h1>Create New Catalog Export Configuration</h1>
<div class='admin-menu'><a href="{{ url('admin_exports_config') }}">&laquo; Back to Archive Export Configuration</a></div>

<form class='config-create-form' action="{{ url('admin_exports_insert_config') }}" method="post">
<label for='label'>Label:</label><input name='label'></input><br>
<label for='catalog_id'>Catalog:</label>
<select name='catalog_id'>
{% for catalog in catalogs %}
<option value='{{ osidIdToString(catalog.id) }}'>{{ catalog.displayname }}</option>
{% endfor %}
</select>
<input class='submit-button' type='submit'></input>
</form>
{% endblock %}
2 changes: 1 addition & 1 deletion templates/admin/export_config.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<p class='inline-p'> - or - <a href="{{ url('admin_exports_create') }}">Create a new configuration</a></p>
</div>

<div id='config-body' data-latest-url="{{ url('admin_exports_config_latest_revision', {exportId: selected_config.id}) }}" data-courselist-url="{{ url('admin_exports_generate_course_list', {catalogId: selected_config.catalog_id}) }}">
<div id='config-body' data-latest-url="{{ selected_config ? url('admin_exports_config_latest_revision', {exportId: selected_config.id}) }}" data-courselist-url="{{ selected_config ? url('admin_exports_generate_course_list', {catalogId: selected_config.catalog_id}) }}" data-insert-revision-url="{{ selected_config ? url('admin_exports_config_insert_revision', {exportId: selected_config.id}) }}">
{% if selected_config and selected_config.id %}
<input id='catalogId' type='hidden' value='{{ selected_config.catalog_id }}'></input>
<input id='configId' type='hidden' value='{{ selected_config.id }}'></input>
Expand Down

0 comments on commit c329e19

Please sign in to comment.