Skip to content

Commit

Permalink
#193 - updated the screen for listing tags on an individual active re…
Browse files Browse the repository at this point in the history
…cord to use templates, and updated the existing TagController unit test to cover that
  • Loading branch information
alphadevx committed Apr 2, 2018
1 parent 42c9e1e commit ada86cf
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 55 deletions.
61 changes: 17 additions & 44 deletions Alpha/Controller/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public function doGET($request)
$fields['count'] = $count;
$fields['fieldname'] = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('clearTaggedClass')) : 'clearTaggedClass');
$fields['ActiveRecordType'] = $ActiveRecordType;
$fields['adminView'] = true;

$tagsHTML .= View::loadTemplateFragment('html', 'tagsadmin.phtml', $fields);
}
Expand All @@ -155,7 +156,7 @@ public function doGET($request)
$fields['securityFields'] = View::renderSecurityFields();
$fields['tagsHTML'] = $tagsHTML;

$body .= View::loadTemplateFragment('html', 'taglist.phtml', $fields);
$body .= View::loadTemplateFragment('html', 'tagslist.phtml', $fields);
} elseif (isset($params['ActiveRecordType']) && $params['ActiveRecordType'] != 'Alpha\Model\Tag' && isset($params['ActiveRecordID'])) {

// render screen for managing individual tags on a given active record
Expand Down Expand Up @@ -183,65 +184,37 @@ public function doGET($request)

ActiveRecord::disconnect();

$body .= '<form action="'.$request->getURI().'" method="POST" accept-charset="UTF-8">';
$body .= '<h3>The following tags were found:</h3>';

foreach ($tags as $tag) {
$labels = $tag->getDataLabels();

$temp = new SmallTextBox($tag->getPropObject('content'), $labels['content'], 'content_'.$tag->getID(), '');
$body .= $temp->render(false);

$js = "if(window.jQuery) {
BootstrapDialog.show({
title: 'Confirmation',
message: 'Are you sure you wish to delete this tag?',
buttons: [
{
icon: 'glyphicon glyphicon-remove',
label: 'Cancel',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself){
dialogItself.close();
}
},
{
icon: 'glyphicon glyphicon-ok',
label: 'Okay',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself) {
$('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID')."\"]').attr('value', '".$tag->getID()."');
$('#deleteForm').submit();
dialogItself.close();
}
}
]
});
}";
$button = new Button($js, 'Delete', 'delete'.$tag->getID().'But');
$body .= $button->render();
}
$fields['contentSmallTextBox'] = $temp->render(false);
$fields['fieldname'] = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordID')) : 'ActiveRecordID');
$fields['tagID'] = $tag->getID();
$fields['adminView'] = false;

$body .= '<h3>Add a new tag:</h3>';
$tagsHTML .= View::loadTemplateFragment('html', 'tagsadmin.phtml', $fields);
}

$temp = new SmallTextBox(new SmallText(), 'New tag', 'NewTagValue', '');
$body .= $temp->render(false);
$fields['newTagValueTextBox'] = $temp->render(false);

$temp = new Button('submit', 'Save', 'saveBut');
$body .= $temp->render();
$body .= '&nbsp;&nbsp;';
$fields['saveButton'] = $temp->render();

if ($params['ActiveRecordType'] = 'Alpha\Model\Article') {
$temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ArticleController&ActiveRecordType='.$params['ActiveRecordType'].'&ActiveRecordID='.$params['ActiveRecordID'].'&view=edit')."'", 'Back to record', 'cancelBut');
} else {
$temp = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.$params['ActiveRecordType'].'&ActiveRecordID='.$params['ActiveRecordID'].'&view=edit')."'", 'Back to record', 'cancelBut');
}
$body .= $temp->render();

$body .= View::renderSecurityFields();
$fields['cancelButton'] = $temp->render();

$body .= '</form>';
$fields['securityFields'] = View::renderSecurityFields();
$fields['deleteForm'] = View::renderDeleteForm($request->getURI());
$fields['formAction'] = $request->getURI();
$fields['tagsHTML'] = $tagsHTML;

$body .= View::renderDeleteForm($request->getURI());
$body .= View::loadTemplateFragment('html', 'tagsonrecord.phtml', $fields);
} catch (RecordNotFoundException $e) {
$msg = 'Unable to load the ActiveRecord of id ['.$params['ActiveRecordID'].'], error was ['.$e->getMessage().']';
self::$logger->error($msg);
Expand Down
53 changes: 43 additions & 10 deletions Alpha/View/Renderer/Html/Fragments/tagsadmin.phtml
Original file line number Diff line number Diff line change
@@ -1,11 +1,45 @@
<h4><?= $friendlyClassName ?> record type is tagged (<?= $count ?> tags found)</h4>

<?php

$js = "if(window.jQuery) {
if ($adminView) {
echo "<h4>$friendlyClassName record type is tagged ($count tags found)</h4>";

$js = "if(window.jQuery) {
BootstrapDialog.show({
title: 'Confirmation',
message: 'Are you sure you want to delete all tags attached to the ".$friendlyClassName." class, and have them re-created?',
buttons: [
{
icon: 'glyphicon glyphicon-remove',
label: 'Cancel',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself){
dialogItself.close();
}
},
{
icon: 'glyphicon glyphicon-ok',
label: 'Okay',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself) {
$('[id=\"".$fieldname."\"]').attr('value', '".addslashes($ActiveRecordType)."');
$('#clearForm').submit();
dialogItself.close();
}
}
]
});
}";

$button = new \Alpha\View\Widget\Button($js, 'Re-create tags', 'clearBut'.stripslashes($ActiveRecordType));
echo $button->render();
} else {

echo $contentSmallTextBox;

$js = "if(window.jQuery) {
BootstrapDialog.show({
title: 'Confirmation',
message: 'Are you sure you want to delete all tags attached to the ".$friendlyClassName." class, and have them re-created?',
message: 'Are you sure you wish to delete this tag?',
buttons: [
{
icon: 'glyphicon glyphicon-remove',
Expand All @@ -20,16 +54,15 @@ $js = "if(window.jQuery) {
label: 'Okay',
cssClass: 'btn btn-default btn-xs',
action: function(dialogItself) {
$('[id=\"".$fieldname."\"]').attr('value', '".addslashes($ActiveRecordType)."');
$('#clearForm').submit();
$('[id=\"".$fieldname."\"]').attr('value', '".$tagID."');
$('#deleteForm').submit();
dialogItself.close();
}
}
]
});
}";

$button = new Button($js, 'Re-create tags', 'clearBut'.stripslashes($ActiveRecordType));
echo $button->render();

?>
$button = new \Alpha\View\Widget\Button($js, 'Delete', 'delete'.$tagID.'But');
echo $button->render();
}
15 changes: 15 additions & 0 deletions Alpha/View/Renderer/Html/Fragments/tagsonrecord.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<form action="<?= $formAction ?>" method="POST" accept-charset="UTF-8">
<h3>The following tags were found:</h3>

<?= $tagsHTML ?>

<h3>Add a new tag:</h3>

<?= $newTagValueTextBox ?>

<?= $saveButton ?>&nbsp;&nbsp;<?= $cancelButton ?>

<?= $securityFields ?>
</form>

<?= $deleteForm ?>
10 changes: 9 additions & 1 deletion test/Alpha/Test/Controller/TagControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,16 @@ public function testDoGET()
$request = new Request(array('method' => 'GET', 'URI' => '/tag/'.urlencode('Alpha\Model\Article').'/'.$article->getID()));
$response = $front->process($request);

$this->assertEquals(200, $response->getStatus(), 'Testing the doGET method');
$this->assertEquals(200, $response->getStatus(), 'Testing the doGET method for rendering tags on an existing ActiveRecord');
$this->assertEquals('text/html', $response->getHeader('Content-Type'), 'Testing the doGET method');
$this->assertTrue(strpos($response->getBody(), 'blah') !== false, 'Testing the created tag is listed');

$request = new Request(array('method' => 'GET', 'URI' => '/tag'));
$response = $front->process($request);

$this->assertEquals(200, $response->getStatus(), 'Testing the doGET method for rendering a summary of all tagged classes');
$this->assertEquals('text/html', $response->getHeader('Content-Type'), 'Testing the doGET method');
$this->assertTrue(strpos($response->getBody(), '<h4>Article record type is tagged (2 tags found)</h4>') !== false, 'Testing the ArticleRecord class is listed as having tags');
}

/**
Expand Down

0 comments on commit ada86cf

Please sign in to comment.