Commit 6ca0ade3 authored by Pat Kira's avatar Pat Kira Committed by Robert Lyon
Browse files

Style elasticsearch (bug: 1465107)

behatnotneeded

Change-Id: Id1c17fd3c926a09e24080e454aba672dc9a62549
parent 550d72fe
...@@ -3848,14 +3848,14 @@ function build_portfolio_search_html(&$data) { ...@@ -3848,14 +3848,14 @@ function build_portfolio_search_html(&$data) {
foreach ($data->data as &$item) { foreach ($data->data as &$item) {
$item->ctime = format_date($item->ctime); $item->ctime = format_date($item->ctime);
if ($item->type == 'view') { if ($item->type == 'view') {
$item->typestr = 'file'; $item->typestr = $item->type;
$item->typelabel = get_string('view'); $item->typelabel = get_string('view');
$v = new View(0, (array)$item); $v = new View(0, (array)$item);
$v->set('dirty', false); $v->set('dirty', false);
$item->url = $v->get_url(); $item->url = $v->get_url();
} }
else if ($item->type == 'collection') { else if ($item->type == 'collection') {
$item->typestr = 'folder-open'; $item->typestr = $item->type;
$item->typelabel = get_string('Collection', 'collection'); $item->typelabel = get_string('Collection', 'collection');
$c = new Collection(0, (array)$item); $c = new Collection(0, (array)$item);
$item->url = $c->get_url(); $item->url = $c->get_url();
...@@ -3866,13 +3866,9 @@ function build_portfolio_search_html(&$data) { ...@@ -3866,13 +3866,9 @@ function build_portfolio_search_html(&$data) {
$item->url = $links['_default']; $item->url = $links['_default'];
$item->typestr = $item->artefacttype; $item->typestr = $item->artefacttype;
if ($item->artefacttype == 'task') { if ($item->artefacttype == 'task') {
$item->typestr = 'tasks';
$item->typelabel = get_string('Task', 'artefact.plans'); $item->typelabel = get_string('Task', 'artefact.plans');
} }
else { else {
if ($item->artefacttype == 'plan') {
$item->typestr = 'plans';
}
$item->typelabel = get_string($item->artefacttype, 'artefact.' . $artefacttypes[$item->artefacttype]->plugin); $item->typelabel = get_string($item->artefacttype, 'artefact.' . $artefacttypes[$item->artefacttype]->plugin);
} }
} }
......
...@@ -70,27 +70,49 @@ if (get_config('licensemetadata')) { ...@@ -70,27 +70,49 @@ if (get_config('licensemetadata')) {
PluginSearchElasticsearch::build_results_html($data); PluginSearchElasticsearch::build_results_html($data);
$searchoptions = array(
'all' => get_string('All'),
'tagsonly' => get_string('tagsonly', 'view'),
);
if (isset($options['tagsonly']) && $options['tagsonly'] == true) {
$selectvalue = 'tagsonly';
}
else {
$selectvalue = 'all';
}
$searchform = array( $searchform = array(
'name' => 'search', 'name' => 'search',
'renderer' => 'oneline', 'renderer' => 'div',
'checkdirtychange' => false, 'checkdirtychange' => false,
'elements' => array(), 'class' => 'form-inline with-heading elasticsearch-form',
); 'elements' => array(
'searchwithin' => array (
$searchform['elements']['query'] = array( 'type' => 'fieldset',
'type' => 'text', 'class' => 'dropdown-group js-dropdown-group',
'defaultvalue' => $query, 'elements' => array(
'title' => get_string('pagetitle', 'search.elasticsearch'), 'query' => array(
'hiddenlabel' => true, 'type' => 'text',
); 'title' => get_string('pagetitle', 'search.elasticsearch') . ': ',
$searchform['elements']['submit'] = array( 'class' => 'with-dropdown js-with-dropdown',
'type' => 'submit', 'defaultvalue' => $query,
'value' => get_string('search'), ),
); 'tagsonly' => array(
$searchform['elements']['tagsonly'] = array( 'title' => get_string('searchwithin'). ': ',
'type' => 'switchbox', 'class' => 'dropdown-connect js-dropdown-connect searchviews-type',
'value' => (isset($options['tagsonly']) && $options['tagsonly'] == true) ? true : false, 'type' => 'select',
'title' => get_string('tagsonly', 'search.elasticsearch'), 'options' => $searchoptions,
'value' => $selectvalue,
),
'submit' => array(
'type' => 'submit',
'class' => 'btn-primary no-label input-group',
'value' => get_string('search'),
)
)
),
),
); );
$searchform = pieform($searchform); $searchform = pieform($searchform);
...@@ -120,7 +142,15 @@ addLoadEvent(function () { ...@@ -120,7 +142,15 @@ addLoadEvent(function () {
connect('search_submit', 'onclick', function (event) { connect('search_submit', 'onclick', function (event) {
firstpage = true; firstpage = true;
replaceChildNodes('messages'); replaceChildNodes('messages');
var params = {'query': $('search_query').value, 'tagsonly': $('search_tagsonly').checked, 'limit': $('setlimitselect').value, 'extradata':serializeJSON({'page':'index'})};
if ($('search_tagsonly').value === 'tagsonly') {
var tagsonly = true;
}
else {
var tagsonly = false;
}
var params = {'query': $('search_query').value, 'tagsonly': tagsonly, 'mainfacetterm': null,'limit': $('setlimitselect').value, 'extradata':serializeJSON({'page':'index'})};
p.sendQuery(params); p.sendQuery(params);
event.stop(); event.stop();
}); });
......
...@@ -258,7 +258,6 @@ class ElasticsearchType_artefact extends ElasticsearchType ...@@ -258,7 +258,6 @@ class ElasticsearchType_artefact extends ElasticsearchType
$record->title = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->title)); $record->title = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->title));
$record->description = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->description)); $record->description = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->description));
// If user is owner // If user is owner
if ($USER->get('id') == $record->owner) { if ($USER->get('id') == $record->owner) {
switch ($record->artefacttype) { switch ($record->artefacttype) {
...@@ -316,6 +315,7 @@ class ElasticsearchType_artefact extends ElasticsearchType ...@@ -316,6 +315,7 @@ class ElasticsearchType_artefact extends ElasticsearchType
} }
break; break;
case 'socialprofile': case 'socialprofile':
safe_require('artefact', 'internal');
$record->note = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->note)); $record->note = str_replace(array("\r\n", "\n", "\r"), ' ', strip_tags($record->note));
$socialprofile = new ArtefactTypeSocialprofile($record->id); $socialprofile = new ArtefactTypeSocialprofile($record->id);
$icons = $socialprofile->get_profile_icons(array($record)); $icons = $socialprofile->get_profile_icons(array($record));
...@@ -386,7 +386,7 @@ class ElasticsearchType_artefact extends ElasticsearchType ...@@ -386,7 +386,7 @@ class ElasticsearchType_artefact extends ElasticsearchType
} }
// Thumb // Thumb
if ($record->artefacttype == 'image') { if ($record->artefacttype == 'image' || $record->artefacttype == 'profileicon') {
if (isset($record->width) && isset($record->height) && intval($record->width) > 0 && intval($record->height) > 0) { if (isset($record->width) && isset($record->height) && intval($record->width) > 0 && intval($record->height) > 0) {
if ($record->width > $record->height) { if ($record->width > $record->height) {
$size = '80x' . intval($record->height * 80 / $record->width); $size = '80x' . intval($record->height * 80 / $record->width);
......
<div class="row">
{if $selected == "Media"} <div class="col-md-8">
<div class="thumbnail-right"> {if ($secfacetterm == "Image" || $record->artefacttype == 'profileicon') && $record->thumb}
{if $secfacetterm == "Image" && $record->thumb} <img src="{$record->thumb}" alt="" class="mrm">
<div class="thumbnail-image"><img src="{$record->thumb}" alt=""></div> <h3 class="title list-group-item-heading text-inline">
{else} {if $record->link}
<div class="thumbnail-image"><img src="{$WWWROOT}search/elasticsearch/theme/raw/images/thumbnail-{$secfacetterm|lower}.png" alt=""></div> <a href="{$WWWROOT}{$record->link}">
{/if} {$record->title|str_shorten_html:50:true|safe}
{/if} </a>
{if $record->link} {else}
<h3 class="title"> {$record->title|str_shorten_html:50:true|safe}
{if $record->artefacttype == 'socialprofile'} {/if}
</h3>
{elseif $record->artefacttype == 'socialprofile'}
<img src="{$record->icon}" alt="{$record->note}"> <img src="{$record->icon}" alt="{$record->note}">
{$record->note|str_shorten_html:50:true|safe} <h3 class="title list-group-item-heading text-inline">
<a href="{$record->link}" title="{$record->link}" target="_blank" class="socialprofile">{$record->title|str_shorten_html:50:true|safe}</a> {if $record->link}
{else} <a href="{$WWWROOT}{$record->link}">
<a href="{$WWWROOT}{$record->link}">{$record->title|str_shorten_html:50:true|safe}</a> {$record->title|str_shorten_html:50:true|safe}
{/if}
{else}
<h3 class="title">{$record->title|str_shorten_html:50:true|safe}
{/if}
<span class="artefacttype">
{if $secfacetterm == "Journalentry"}
({str tag=blogpost section=search.elasticsearch})
{elseif $secfacetterm == "Forumpost"}
({str tag=forumpost section=search.elasticsearch})
{elseif $secfacetterm == "Resume"}
({str tag=resume section=search.elasticsearch})
{elseif $secfacetterm == "Wallpost"}
({str tag=wallpost section=search.elasticsearch})
{else}
({$secfacetterm})
{/if}
{if $record->deleted}
({str tag=deleted section=search.elasticsearch})
{/if}
</span></h3>
{if $record->createdbyname}
<div class="createdby">{str tag=createdby section=search.elasticsearch arg1='<a href="`$record->createdby|profile_url`">`$record->createdbyname|safe`</a>'}</div>
{/if}
<div class="detail">{$record->description|str_shorten_html:100:true|safe}</div>
<!-- RESUMEITEMS -->
{if $record->resumeitems|count gt 0}
<strong>{str tag=contains section=search.elasticsearch}:</strong>
<ul>
{foreach from=$record->resumeitems key=rid item=resume}
{if $resume->title}<li>{$resume->title}</li>{/if}
{if $resume->jobtitle}<li>{$resume->jobtitle}</li>{/if}
{if $resume->qualname}<li>{$resume->qualname}</li>{/if}
{/foreach}
</ul>
{/if}
<!-- end RESUMEITEMS -->
<!-- VIEWS -->
{if $record->views|count gt 0}
<div class="usedon">
{if $record->views|count gt 1}
<strong>{str tag=usedonpages section=search.elasticsearch}:</strong>
<ul>
{foreach from=$record->views key=id item=view}
<li><a href="{$WWWROOT}view/view.php?id={$id}">{$view|str_shorten_html:50:true|safe}</a>
<!-- Profile artefact can only be displayed in views -->
{if $secfacetterm != "Profile"}
|
<span class="viewartefact">
<a href="{$WWWROOT}artefact/artefact.php?artefact={$record->id}&view={$id}">view
{if $secfacetterm == "Journalentry"}
{str tag=blogpost section=search.elasticsearch}
{elseif $secfacetterm == "Forumpost"}
{str tag=forumpost section=search.elasticsearch}
{elseif $secfacetterm == "Resume"}
{str tag=resume section=search.elasticsearch}
{elseif $secfacetterm == "Wallpost"}
{str tag=wallpost section=search.elasticsearch}
{else}
{$secfacetterm|lower}
{/if}
</a> </a>
</span> {else}
{$record->title|str_shorten_html:50:true|safe}
{/if} {/if}
</li> </h3>
{/foreach} {else}
</ul> <h3 class="title list-group-item-heading text-inline">
{else} <span class="icon icon-{$record->artefacttype} left {if $record->deleted}text-lighttone{/if}"></span>
<strong>{str tag=usedonpage section=search.elasticsearch}:</strong> {if $record->link}
<ul> <a href="{$WWWROOT}{$record->link}">
{foreach from=$record->views key=id item=view} {$record->title|str_shorten_html:50:true|safe}
<li><a href="{$WWWROOT}view/view.php?id={$id}">{$view|str_shorten_html:50:true|safe}</a>
<!-- Profile artefact can only be displayed in views -->
{if $secfacetterm != "Profile"}
|
<span class="viewartefact">
<a href="{$WWWROOT}artefact/artefact.php?artefact={$record->id}&view={$id}">view
{if $secfacetterm == "Journalentry"}
{str tag=blogpost section=search.elasticsearch}
{elseif $secfacetterm == "Forumpost"}
{str tag=forumpost section=search.elasticsearch}
{elseif $secfacetterm == "Resume"}
{str tag=resume section=search.elasticsearch}
{elseif $secfacetterm == "Wallpost"}
{str tag=wallpost section=search.elasticsearch}
{else}
{$secfacetterm|lower}
{/if}
</a> </a>
</span> {else}
{$record->title|str_shorten_html:50:true|safe}
{/if} {/if}
</li> </h3>
{/if}
<span class="artefacttype text-lighttone">
{if $secfacetterm == "Journalentry"}
({str tag=blogpost section=search.elasticsearch})
{elseif $secfacetterm == "Forumpost"}
({str tag=forumpost section=search.elasticsearch})
{elseif $secfacetterm == "Resume"}
({str tag=resume section=search.elasticsearch})
{elseif $secfacetterm == "Wallpost"}
({str tag=wallpost section=search.elasticsearch})
{else}
({$secfacetterm})
{/if}
{if $record->deleted}
({str tag=deleted section=search.elasticsearch})
{/if}
</span>
{if $record->createdbyname}
<div class="createdby">
{str tag=createdby section=search.elasticsearch arg1='<a href="`$record->createdby|profile_url`">`$record->createdbyname|safe`</a>'}
</div>
{/if}
<div class="detail">
{$record->description|str_shorten_html:100:true|safe}
</div>
<!-- TAGS -->
{if $record->tags|count gt 0}
<div class="tags"><strong>{str tag=tags section=search.elasticsearch}:</strong>
{foreach from=$record->tags item=tag name=tags}
<a href="{$WWWROOT}search/elasticsearch/index.php?query={$tag}&tagsonly=true">{$tag}</a>{if !$.foreach.tags.last}, {/if}
{/foreach} {/foreach}
</ul> </div>
{/if}
</div>
<!-- RESUMEITEMS -->
<div class="col-md-4">
{if $record->resumeitems|count gt 0}
<strong>{str tag=contains section=search.elasticsearch}:</strong>
<ul>
{foreach from=$record->resumeitems key=rid item=resume}
{if $resume->title}<li>{$resume->title}</li>{/if}
{if $resume->jobtitle}<li>{$resume->jobtitle}</li>{/if}
{if $resume->qualname}<li>{$resume->qualname}</li>{/if}
{/foreach}
</ul>
{/if}
<!-- VIEWS -->
{if $record->views|count gt 0}
<div class="usedon">
{if $record->views|count gt 1}
<strong>{str tag=usedonpages section=search.elasticsearch}:</strong>
<ul class="list-group list-unstyled">
{foreach from=$record->views key=id item=view}
<li>
<a href="{$WWWROOT}view/view.php?id={$id}">{$view|str_shorten_html:50:true|safe}</a>
<!-- Profile artefact can only be displayed in views -->
{if $secfacetterm != "Profile"} |
<span class="viewartefact">
<a href="{$WWWROOT}artefact/artefact.php?artefact={$record->id}&view={$id}">
view
{if $secfacetterm == "Journalentry"}
{str tag=blogpost section=search.elasticsearch}
{elseif $secfacetterm == "Forumpost"}
{str tag=forumpost section=search.elasticsearch}
{elseif $secfacetterm == "Resume"}
{str tag=resume section=search.elasticsearch}
{elseif $secfacetterm == "Wallpost"}
{str tag=wallpost section=search.elasticsearch}
{else}
{$secfacetterm|lower}
{/if}
</a>
</span>
{/if}
</li>
{/foreach}
</ul>
{else}
<strong>{str tag=usedonpage section=search.elasticsearch}:</strong>
<ul class="list-group list-unstyled">
{foreach from=$record->views key=id item=view}
<li>
<a href="{$WWWROOT}view/view.php?id={$id}">{$view|str_shorten_html:50:true|safe}</a>
<!-- Profile artefact can only be displayed in views -->
{if $secfacetterm != "Profile"} |
<span class="viewartefact">
<a href="{$WWWROOT}artefact/artefact.php?artefact={$record->id}&view={$id}">
view
{if $secfacetterm == "Journalentry"}
{str tag=blogpost section=search.elasticsearch}
{elseif $secfacetterm == "Forumpost"}
{str tag=forumpost section=search.elasticsearch}
{elseif $secfacetterm == "Resume"}
{str tag=resume section=search.elasticsearch}
{elseif $secfacetterm == "Wallpost"}
{str tag=wallpost section=search.elasticsearch}
{else}
{$secfacetterm|lower}
{/if}
</a>
</span>
{/if}
</li>
{/foreach}
</ul>
{/if}
</div>
{/if} {/if}
</div> </div>
{/if}
<!-- end VIEWS -->
<!-- TAGS -->
{if $record->tags|count gt 0}
<div class="tags"><strong>{str tag=tags section=search.elasticsearch}:</strong>
{foreach from=$record->tags item=tag name=tags}
<a href="{$WWWROOT}search/elasticsearch/index.php?query={$tag}&tagsonly=true">{$tag}</a>{if !$.foreach.tags.last}, {/if}
{/foreach}
</div>
{/if}
{if $selected == "Media"}
</div> </div>
{/if}
<!-- end TAGS -->
<div class="row">
{if $record->link} <div class="col-md-8">
<h3 class="title"> {if $record->link}
<a href="{$WWWROOT}{$record->link}">{$record->title|str_shorten_html:50:true|safe}</a> <h3 class="title list-group-item-heading text-inline">
{else} <span class="icon icon-file left"></span>
<h3 class="title">{$record->title|str_shorten_html:50:true|safe} <a href="{$WWWROOT}{$record->link}">{$record->title|str_shorten_html:50:true|safe}</a>
{/if} </h3>
<span class="artefacttype"> {else}
({str tag=document section=search.elasticsearch}) <h3 class="title list-group-item-heading text-inline">
{if $record->deleted} <span class="icon icon-file left"></span>
({str tag=deleted section=search.elasticsearch}) {$record->title|str_shorten_html:50:true|safe}
{/if} </h3>
</span></h3> {/if}
{if $record->createdbyname} <span class="artefacttype text-lighttone">
<div class="createdby">{str tag=createdby section=search.elasticsearch arg1='<a href="`$record->createdby|profile_url`">`$record->createdbyname|safe`</a>'}</div> ({str tag=document section=search.elasticsearch})
{/if} {if $record->deleted}
<div class="detail">{$record->description|str_shorten_html:100:true|safe}</div> ({str tag=deleted section=search.elasticsearch})
<!-- VIEWS --> {/if}
{if $record->views|count gt 0} </span>
<div class="usedon"> {if $record->createdbyname}
{if $record->views} <div class="createdby">{str tag=createdby section=search.elasticsearch arg1='<a href="`$record->createdby|profile_url`">`$record->createdbyname|safe`</a>'}</div>
<strong>{str tag=usedonpage section=search.elasticsearch}:</strong> {/if}
<ul> <div class="detail">{$record->description|str_shorten_html:100:true|safe}</div>
{foreach from=$record->views key=id item=view} <!-- TAGS -->
<li><a href="{$WWWROOT}view/view.php?id={$id}">{$view|str_shorten_html:50:true|safe}</a> {if $record->tags|count gt 0}
</li> <div class="tags"><strong>{str tag=tags section=search.elasticsearch}:</strong>
{foreach from=$record->tags item=tag name=tags}
<a href="{$WWWROOT}search/elasticsearch/index.php?query={$tag}&tagsonly=true">{$tag}</a>{if !$.foreach.tags.last}, {/if}
{/foreach} {/foreach}
</ul> </div>
{/if} {/if}
</div> </div>
{/if} <!-- VIEWS -->
<!-- end VIEWS --> {if $record->views|count gt 0}
<!-- TAGS --> <div class="col-md-4">
{if $record->tags|count gt 0} <div class="usedon">
<div class="tags"><strong>{str tag=tags section=search.elasticsearch}:</strong> {if $record->views}
{foreach from=$record->tags item=tag name=tags} <strong>{str tag=usedonpage section=search.elasticsearch}:</strong>
<a href="{$WWWROOT}search/elasticsearch/index.php?query={$tag}&tagsonly=true">{$tag}</a>{if !$.foreach.tags.last}, {/if} <ul class="list-group list-unstyled">
{/foreach} {foreach from=$record->views key=id item=view}
<li><a href="{$WWWROOT}view/view.php?id={$id}">{$view|str_shorten_html:50:true|safe}</a>
</li>
{/foreach}
</ul>
{/if}
</div>
</div>
{/if}
</div> </div>
{/if}
<!-- end TAGS -->
{if $record->deleted} {if $record->deleted}
<h3 class="title">{$record->name} <span class="artefacttype">({str tag=deleted section=search.elasticsearch})</span></h3> <h3 class="title list-group-item-heading text-inline">
<span class="icon icon-folder-open left"></span>
{$record->name}
</h3>
<span class="artefacttype text-lighttone">({str tag=deleted section=search.elasticsearch})</span>
{else} {else}
<h3 class="title"><a href="{$WWWROOT}view/view.php?id={$record->viewid}">{$record->name}</a> <span class="artefacttype">({str tag=collection section=search.elasticsearch})</span></h3> <h3 class="title">
<span class="icon icon-folder-open left"></span>
<a href="{$WWWROOT}view/view.php?id={$record->viewid}">
{$record->name}
</a>
</h3>
<span class="artefacttype">({str tag=collection section=search.elasticsearch})</span>
{if $record->createdbyname} {if $record->createdbyname}
<div class="createdby">{str tag=createdby section=search.elasticsearch arg1='<a href="`$record->createdby|profile_url}">`$record->createdbyname|safe`</a>'}</div>