Skip to content

Commit

Permalink
DIS-336 : Updates to Aspen Web Resources Part V
Browse files Browse the repository at this point in the history
Add option to generate a placard when adding or editing a web resource
  • Loading branch information
K-Alette committed Feb 28, 2025
1 parent e7120ef commit 034b69c
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 0 deletions.
28 changes: 28 additions & 0 deletions code/web/interface/themes/responsive/js/aspen.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions code/web/interface/themes/responsive/js/aspen/web-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,35 @@ AspenDiscovery.WebBuilder = function () {
}
});
}
},

getSourceValuesForPlacard: function () {
var placardId = $("#id").val();
var sourceType = $("#sourceTypeSelect").val();

if (sourceType === 'none') {
$("#propertyRowsourceId").hide();
} else {
$("#propertyRowsourceId").show();
}

var url = Globals.path + '/WebBuilder/AJAX?method=getSourceValuesForPlacard&placardId=' + placardId + '&sourceType=' + sourceType;
$.getJSON(url, function(data){
if (data.success === true){
var sourceIdSelect = $("#sourceIdSelect" );
sourceIdSelect.find('option').remove();
var optionValues = data.values;
for (var key in optionValues) {
if (data.selected === key){
sourceIdSelect.append('<option value="' + key + '" selected>' + optionValues[key] + '</option>')
}else{
sourceIdSelect.append('<option value="' + key + '">' + optionValues[key] + '</option>')
}
}
}else{
AspenDiscovery.showMessage('Sorry', data.message);
}
});
},

getImageActionFields: function() {
Expand Down
4 changes: 4 additions & 0 deletions code/web/services/Admin/Placards.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ function getActiveAdminSection(): string {
return 'local_enrichment';
}

function getInitializationJs(): string {
return 'AspenDiscovery.WebBuilder.getSourceValuesForPlacard()';
}

function canView(): bool {
return UserAccount::userHasPermission([
'Administer All Placards',
Expand Down
51 changes: 51 additions & 0 deletions code/web/services/WebBuilder/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,57 @@ function getPortalCellValuesForSource() {
return $result;
}

function getSourceValuesForPlacard() {
$result = [
'success' => false,
'message' => translate([
'text' => 'Unknown Error',
'isPublicFacing' => true,
]),
];

$sourceType = $_REQUEST['sourceType'];
switch ($sourceType) {
case 'none':
$result = [
'success' => true,
];
break;
case 'web_resource':
require_once ROOT_DIR . '/sys/WebBuilder/WebResource.php';
$list = [];
$list['-1'] = 'Select a web resource';
$object = new WebResource();
$object->orderBy('name');
$object->find();
while ($object->fetch()) {
$list[$object->id] = $object->name;
}
$result = [
'success' => true,
'values' => $list,
];
break;
default:
$result['message'] = 'Unhandled Source Type ' . $sourceType;
}

$placardId = $_REQUEST['placardId'];
$result['selected'] = '-1';
if (!empty($placardId)) {
require_once ROOT_DIR . '/sys/LocalEnrichment/Placard.php';
$placard = new Placard();
$placard->id = $placardId;
if ($placard->find(true)) {
if ($placard->sourceType == $sourceType) {
$result['selected'] = $placard->sourceId;
}
}
}

return $result;
}

/** @noinspection PhpUnused */
function uploadImage() {
$result = [
Expand Down
17 changes: 17 additions & 0 deletions code/web/sys/DBMaintenance/version_updates/25.03.00.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,23 @@ function getUpdates25_03_00(): array {
"ALTER TABLE library ADD COLUMN webResourcesSettingId INT(11) DEFAULT -1",
],
], //add_web_resources_setting_id_to_library_table
'placard_source_type' => [
'title' => 'Placard Source Type',
'description' => 'Add sourceType and sourceId columns to placards table.',
'sql' => [
"ALTER TABLE placards ADD COLUMN sourceType VARCHAR(30) DEFAULT NULL",
"ALTER TABLE placards ADD COLUMN sourceId VARCHAR(30) DEFAULT NULL",
"ALTER TABLE placards ADD COLUMN generatedFromSource VARCHAR(30) DEFAULT NULL",
"ALTER TABLE placards ADD COLUMN isCustomized TINYINT(1) DEFAULT 0",
],
], //placard_source_type
'web_resource_generate_placard' => [
'title' => 'Web Resource: Generate Placard',
'description' => 'Add option to generate a placard for a web resource.',
'sql' => [
"ALTER TABLE web_builder_resource ADD COLUMN generatePlacard TINYINT(1) DEFAULT 0",
],
], //web_resource_generate_placard

// Leo Stoyanov - BWS

Expand Down
45 changes: 45 additions & 0 deletions code/web/sys/LocalEnrichment/Placard.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class Placard extends DB_LibraryLocationLinkedObject {
$dismissable;
public $startDate;
public $endDate;
public $sourceType;
public $sourceId;
public $generatedFromSource;
public $isCustomized;

/** @var PlacardTrigger[] */
protected $_triggers;
Expand All @@ -41,6 +45,11 @@ static function getObjectStructure($context = ''): array {
$locationList = Location::getLocationList(!UserAccount::userHasPermission('Administer All Placards'));
$languageList = Language::getLanguageList();

$sourceOptions = [
'none' => 'None',
'web_resource' => 'Web Resource',
];

return [
'id' => [
'property' => 'id',
Expand Down Expand Up @@ -130,6 +139,21 @@ static function getObjectStructure($context = ''): array {
'canAddNew' => true,
'canDelete' => true,
],
'sourceType' => [
'property' => 'sourceType',
'type' => 'enum',
'values' => $sourceOptions,
'label' => 'Source Type',
'description' => 'Source type for the content of cell',
'onchange' => 'return AspenDiscovery.WebBuilder.getSourceValuesForPlacard();',
],
'sourceId' => [
'property' => 'sourceId',
'type' => 'enum',
'values' => [],
'label' => 'Source Id',
'description' => 'Source for the content of placard',
],
'languages' => [
'property' => 'languages',
'type' => 'multiSelect',
Expand Down Expand Up @@ -228,6 +252,12 @@ public function __set($name, $value) {
* @see DB/DB_DataObject::update()
*/
public function update($context = '') {
if ($this->sourceType != 'none') {
$this->compareLinkedObject();
}
if ($this->sourceType == 'none') {
$this->__set('isCustomized', 0);
}
$ret = parent::update();
if ($ret !== FALSE) {
$this->saveLibraries();
Expand Down Expand Up @@ -517,4 +547,19 @@ public function loadCopyableSubObjects() {
}
$this->getLanguages();
}

private function compareLinkedObject() {
if ($this->sourceType == 'web_resource') {
require_once ROOT_DIR . '/sys/WebBuilder/WebResource.php';
$webResource = new WebResource();
$webResource->id = $this->sourceId;
if ($webResource->find(true)) {
if ($webResource->name != $this->title || $webResource->url != $this->link || $webResource->teaser != $this->body) {
$this->__set('isCustomized', 1);
} else {
$this->__set('isCustomized', 0);
}
}
}
}
}
38 changes: 38 additions & 0 deletions code/web/sys/WebBuilder/WebResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class WebResource extends DB_LibraryLinkedObject {
$teaser;
public $description;
public $lastUpdate;
public $generatePlacard;

private $_allowAccessByLibrary;

Expand Down Expand Up @@ -94,6 +95,13 @@ static function getObjectStructure($context = ''): array {
'description' => 'Whether or not the resource is a featured resource',
'default' => 0,
],
'generatePlacard' => [
'property' => 'generatePlacard',
'type' => 'checkbox',
'label' => 'Generate Placard?',
'description' => 'Whether or not the resource has an automatically generated placard which can be edited in Local Catalog Enrichment > Placards.',
'default' => 0,
],
'teaser' => [
'property' => 'teaser',
'type' => 'markdown',
Expand Down Expand Up @@ -197,6 +205,9 @@ public function insert($context = '') {
$this->saveAudiences();
$this->saveCategories();
$this->saveAllowableLibraries();
if ($this->generatePlacard) {
$this->generatePlacard();
}
}
return $ret;
}
Expand All @@ -209,6 +220,9 @@ public function update($context = '') {
$this->saveAudiences();
$this->saveCategories();
$this->saveAllowableLibraries();
if ($this->generatePlacard) {
$this->generatePlacard();
}
}
return $ret;
}
Expand Down Expand Up @@ -502,4 +516,28 @@ public function saveAllowableLibraries() {
unset($this->_allowAccessByLibrary);
}
}

public function generatePlacard() {
require_once ROOT_DIR . '/sys/LocalEnrichment/Placard.php';
//create or update existing placard linked to this resource
$placard = new Placard();
$placard->sourceType = 'web_resource';
$placard->sourceId = $this->id;
if ($placard->find(true)){
$placard->title = $this->name;
$placard->image = $this->logo;
$placard->link = $this->url;
$placard->body = $this->teaser;
$placard->update();
} else {
$placard->sourceType = 'web_resource';
$placard->sourceId = $this->id;
$placard->title = $this->name;
$placard->image = $this->logo;
$placard->link = $this->url;
$placard->body = $this->teaser;
$placard->insert();
}

}
}

0 comments on commit 034b69c

Please sign in to comment.