Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhiltri committed Feb 24, 2022
2 parents d5c27d7 + 22c1adf commit b7b5ebd
Show file tree
Hide file tree
Showing 33 changed files with 439 additions and 88 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.33
6.34
31 changes: 31 additions & 0 deletions app/Helpers/FrontendHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,35 @@ public static function revAsset($file)

return (rtrim(config('twill.frontend.dev_assets_path'), '/') . '/') . $file;
}

/**
* @param string $file
* @return string
*/
public static function embedAsset($file)
{

if (config('aic.use_compiled_revassets')) {
try {
$manifest = json_decode(file_get_contents(config('twill.frontend.rev_manifest_path')), true);

if (isset($manifest[$file])) {
return file_get_contents(FrontendHelpers::dist_path($manifest[$file]));
}
} catch (\Exception $e) {
return '/' . $file;
}
}

return file_get_contents(FrontendHelpers::dist_path($file));
}

/**
* Returns the fully qualified path to the application's `frontend` directory.
* You may generate a fully qualified path to a file relative to the frontend directory.
*/
public static function dist_path($file = null)
{
return base_path() . '/public' . config('twill.frontend.dist_assets_path') . (!empty($file) ? '/' . $file : '');
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/BaseScopedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class BaseScopedController extends FrontController
'subject_ids' => 'bySubjects',
'material_ids' => 'byMaterials',
'place_ids' => 'byPlaces',
'artwork_type_id' => 'byArtworkType',
'color' => 'byColor',
'sort_by' => 'sortBy',
'date-start' => 'yearMin',
Expand Down
46 changes: 39 additions & 7 deletions app/Libraries/Search/CollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use App\Libraries\Search\Filters\ColorFilter;
use App\Models\Api\Search;

use Illuminate\Support\Str;

class CollectionService
{
const API_SEARCH_CACHE_TTL = 3600;
Expand All @@ -25,11 +27,11 @@ class CollectionService
* Options for BooleanFilter class. [ parameter => label, ... ]
*/
protected $booleanOptions = [
'is_on_view' => 'On view',
'is_public_domain' => 'Public domain',
'is_recent_acquisition' => 'Recent acquisition',
'has_multimedia' => 'Has multimedia',
'has_educational_resources' => 'Has educational resources',
'is_on_view' => 'On view',
];

/**
Expand Down Expand Up @@ -82,13 +84,22 @@ public function generateFilters()
$results = $this->results();

// Generate listing filters
$filters = $this->buildListFilters($results->getMetadata('aggregations'));
$filters = collect([]);
$filters->push($this->buildListFilter($results->getMetadata('aggregations'), 'artists'));
$filters->push($this->buildListFilter($results->getMetadata('aggregations'), 'places'));
$filters->push($this->buildListFilter($results->getMetadata('aggregations'), 'artwork_type'));

// Date Filter
$filters->push($this->buildDateFilters());

// Color Filter
$filters->prepend($this->buildColorFilters());
$filters->push($this->buildColorFilters());

// Date Filter
$filters->prepend($this->buildDateFilters());
$filters->push($this->buildListFilter($results->getMetadata('aggregations'), 'styles'));
$filters->push($this->buildListFilter($results->getMetadata('aggregations'), 'subjects'));
$filters->push($this->buildListFilter($results->getMetadata('aggregations'), 'classifications'));
$filters->push($this->buildListFilter($results->getMetadata('aggregations'), 'materials'));
$filters->push($this->buildListFilter($results->getMetadata('aggregations'), 'departments'));

// Prepend sorting filters at the beginning
if (!request('is_deaccessioned')) {
Expand All @@ -98,7 +109,7 @@ public function generateFilters()
// Appends boolean filters
$filters->push($this->buildBooleanFilters());

return $filters;
return $filters->filter();
}

/**
Expand Down Expand Up @@ -175,7 +186,7 @@ protected function buildListFilters($aggregations)

if ($aggregations) {
foreach ($aggregations as $name => $data) {
$filterClass = __NAMESPACE__ . '\\Filters\\' . ucfirst($name);
$filterClass = __NAMESPACE__ . '\\Filters\\' . ucfirst(Str::camel($name));
if (class_exists($filterClass)) {
$filter = new $filterClass($data->buckets, $name);
$filters->push($filter->generate());
Expand All @@ -186,6 +197,27 @@ protected function buildListFilters($aggregations)
return $filters->filter();
}

/**
* Go through all aggregations and process a the given bucket with the proper
* filter class.
*/
protected function buildListFilter($aggregations, $name)
{
if ($aggregations) {
if (isset($aggregations->$name)) {
$data = $aggregations->$name;
$filterClass = __NAMESPACE__ . '\\Filters\\' . ucfirst(Str::camel($name));
if (class_exists($filterClass)) {
$filter = new $filterClass($data->buckets, $name);
return $filter->generate();
}
}
}

return null;
}


/**
* Sort filters receive all possible sorting values and create
* the proper dropdown options.
Expand Down
32 changes: 32 additions & 0 deletions app/Libraries/Search/Filters/ArtworkType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Libraries\Search\Filters;

class ArtworkType extends BaseFilteredList
{
protected $parameter = 'artwork_type_id';
protected $entity = \App\Models\Api\ArtworkType::class;

public function generate()
{
$list = $this->generateFilteredCategory();

if (!$list->isEmpty()) {
return [
'placeholder' => 'Find Artwork Types',
'title' => 'Artwork Type',
'active' => $this->activeList,
'list' => $list,
'listSearch' => true,
'type' => 'list',
'aggregation' => $this->aggregationName,
'listSearchUrl' => route('collection.categorySearch', request()->except(['categoryQuery']) + ['categoryName' => 'artwork_type'])
];
}
}

public function findLabel($key)
{
return ucfirst($key);
}
}
36 changes: 36 additions & 0 deletions app/Models/Api/Artwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,19 @@ public function scopeAggregationClassification($query)
return $query->aggregations($aggs);
}

public function scopeAggregationArtworkType($query)
{
$aggs = [
'types' => [
'terms' => [
'field' => 'artwork_type_id',
],
],
];

return $query->aggregations($aggs);
}

public function scopeByClassifications($query, $ids)
{
if (empty($ids)) {
Expand All @@ -381,6 +394,29 @@ public function scopeByClassifications($query, $ids)
return $query->rawSearch($params);
}

public function scopeByArtworkType($query, $id)
{
if (empty($id)) {
return $query;
}

$id = is_array($id) ? $id[0] : $id;

$params = [
'bool' => [
'must' => [
[
'terms' => [
'artwork_type_id' => $id,
],
],
],
],
];

return $query->rawSearch($params);
}

public function scopeByArtists($query, $ids)
{
if (empty($ids)) {
Expand Down
22 changes: 22 additions & 0 deletions app/Models/Api/ArtworkType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Models\Api;

use App\Libraries\Api\Models\BaseApiModel;

class ArtworkType extends BaseApiModel
{
protected $endpoints = [
'collection' => '/api/v1/artwork-types',
'resource' => '/api/v1/artwork-types/{id}',
'search' => '/api/v1/artwork-types/search',
];

protected $presenter = 'App\Presenters\Admin\ArtworkTypePresenter';
protected $presenterAdmin = 'App\Presenters\Admin\ArtworkTypePresenter';

public function getParameterName()
{
return 'artwork_type_id';
}
}
20 changes: 20 additions & 0 deletions app/Models/Api/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function scopeAllAggregations($query, $categoryFilter = null, $queryFilte
'materials' => 'material_titles.keyword',
'subjects' => 'subject_titles.keyword',
'places' => 'place_of_origin.keyword',
'artwork_type' => 'artwork_type_title.keyword',
'departments' => [
'field' => 'department_title.keyword',
'size' => 20,
Expand Down Expand Up @@ -154,6 +155,20 @@ public function scopeAggregationClassifications($query, $max = 3)
return $query->aggregations($aggs);
}

public function scopeAggregationArtworkType($query, $max = 3)
{
$aggs = [
'artworkTypes' => [
'terms' => [
'field' => 'artwork_type_title.keyword',
'size' => $max
]
]
];

return $query->aggregations($aggs);
}

public function scopeAggregationStyles($query, $max = 3)
{
$aggs = [
Expand Down Expand Up @@ -247,6 +262,11 @@ public function scopeByThemes($query, $ids)
return $this->scopeByListType($query, $ids, 'category_ids');
}

public function scopeByArtworkType($query, $ids)
{
return $this->scopeByListType($query, $ids, 'artwork_type_title.keyword');
}

public function scopeByArtworkIds($query, $ids)
{
if (empty($ids)) {
Expand Down
5 changes: 2 additions & 3 deletions app/Models/ExactTargetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ public static function getList()
return collect([
'OptEnews' => 'News and Exhibitions',
'OptHumanResources' => 'Career Opportunities',
'OptEveningAssociates' => 'Young Professionals',
'OptFamilyPrograms' => 'Families',
'OptEvents' => 'Public Programs',
'OptStudentTeacherPrograms' => 'Students and Teachers',
'OptTeenPrograms' => 'Teens',
'OptStudentTeacherPrograms' => 'K-12 Educator Resources',
'OptTeenPrograms' => 'Teen Opportunities',
'OptAcademicEngagement' => 'Research, Publishing, and Conservation',
]);
}
Expand Down
15 changes: 15 additions & 0 deletions app/Presenters/Admin/ArtworkTypePresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Presenters\Admin;

use App\Presenters\BasePresenter;

class ArtworkTypePresenter extends BasePresenter
{
protected function collectionUrl()
{
$value = $this->entity->id;

return route('collection', [$this->entity->getParameterName() => $value]);
}
}
17 changes: 16 additions & 1 deletion config/twill.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,20 @@
],
],

'imgix_source_host' => env('IMGIX_SOURCE_HOST', 'artic-web.imgix.net')
'imgix_source_host' => env('IMGIX_SOURCE_HOST', 'artic-web.imgix.net'),

'media_library' => [
'disk' => 'twill_media_library',
'endpoint_type' => env('MEDIA_LIBRARY_ENDPOINT_TYPE', 's3'),
'cascade_delete' => env('MEDIA_LIBRARY_CASCADE_DELETE', false),
'local_path' => env('MEDIA_LIBRARY_LOCAL_PATH', 'uploads'),
'image_service' => env('MEDIA_LIBRARY_IMAGE_SERVICE', 'A17\Twill\Services\MediaLibrary\Imgix'),
'acl' => env('MEDIA_LIBRARY_ACL', 'private'),
'filesize_limit' => env('MEDIA_LIBRARY_FILESIZE_LIMIT', 50),
'allowed_extensions' => ['svg', 'jpg', 'gif', 'png', 'jpeg', 'mp4'],
'init_alt_text_from_filename' => true,
'prefix_uuid_with_local_path' => config('twill.file_library.prefix_uuid_with_local_path', false),
'translated_form_fields' => false,
'show_file_name' => false,
]
];
21 changes: 21 additions & 0 deletions frontend/js/functions/core/ajaxPageLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,27 @@ const ajaxPageLoad = function() {
// WEB-1323
&& link.href.indexOf('interactive-features') < 0
&& window.location.href.indexOf('interactive-features') < 0
// ART-52
&& link.href.indexOf('articles') < 0
&& link.href.indexOf('artworks') < 0
&& link.href.indexOf('digital-publications') < 0
&& link.href.indexOf('exhibitions') < 0
&& link.href.indexOf('highlights') < 0
&& link.href.indexOf('artinstitutereview') < 0
&& link.href.indexOf('videos') < 0
&& link.href.indexOf('virtual-tours') < 0
&& link.href.indexOf('collection') < 0
&& link.href.indexOf('events') < 0
&& window.location.href.indexOf('articles') < 0
&& window.location.href.indexOf('artworks') < 0
&& window.location.href.indexOf('digital-publications') < 0
&& window.location.href.indexOf('exhibitions') < 0
&& window.location.href.indexOf('highlights') < 0
&& window.location.href.indexOf('artinstitutereview') < 0
&& window.location.href.indexOf('videos') < 0
&& window.location.href.indexOf('virtual-tours') < 0
&& window.location.href.indexOf('collection') < 0
&& window.location.href.indexOf('events') < 0
) {
event.preventDefault();
var win = window.open(link.href, '_blank');
Expand Down
Loading

0 comments on commit b7b5ebd

Please sign in to comment.