Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDESK-3998] Include updates for featuremedia stats #103

Merged
merged 1 commit into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function FeaturemediaUpdatesTable(
user: _.get(scope.users, _.get(update, 'user'), {}).display_name,
operation: _.get(operations, _.get(update, 'operation')),
update: _.get(update, 'update'),
clickable: _.get(update, 'operation') !== 'remove_featuremedia',
}));

scope.itemUpdates.push({
Expand Down Expand Up @@ -147,10 +148,12 @@ export function FeaturemediaUpdatesTable(
* @description Opens the preview that will load the snapshot renditions and preview them
*/
scope.onUpdateClicked = (item, update) => {
scope.openPreview({
item: item,
update: update,
}, 'renditions-preview');
if (_.get(update, 'clickable')) {
scope.openPreview({
item: item,
update: update,
}, 'renditions-preview');
}
};

init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@
<td class="no-vert-padding">
<ul class="simple-list simple-list--dotted no-vert-padding">
<li ng-repeat="update in item.updates track by $index"
class="simple-list__item clickable"
class="simple-list__item"
ng-class="{'clickable': update.clickable}"
ng-click="onUpdateClicked(item, update)"
>
<a translate>{{update.date}} - {{update.operation}} by {{update.user}}</a>
<a translate ng-if="update.clickable">{{update.date}} - {{update.operation}} by {{update.user}}</a>
<span ng-if="!update.clickable" translate>{{update.date}} - {{update.operation}} by {{update.user}}</span>
</li>
</ul>
</td>
Expand Down
7 changes: 5 additions & 2 deletions client/views/renditions-preview.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="analytics-renditions-preview" ng-if="preview.item.update.update">
<div class="analytics-renditions-preview">
<div class="side-panel__header">
<div class="side-panel__tools">
<a class="icn-btn" ng-click="close()">
Expand All @@ -17,7 +17,10 @@
<div class="nav-tabs__pane">
<div class="main-article preview">
<div class="fieldset main-article__fieldset">
<div class="full-preview" sd-ratio-calc>
<div class="full-preview" ng-if="!preview.item.update.update._id">
<span>This version does not have any featuremedia attached!</span>
</div>
<div class="full-preview" sd-ratio-calc ng-if="preview.item.update.update._id">
<div class="media-item__item">
<div class="item-association item-association--preview">
<div class="item-association__image-container"
Expand Down
30 changes: 22 additions & 8 deletions server/analytics/base_report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,21 +506,25 @@ def _get_es_query_funcs(self):
},
}

def _es_base_query(self, query, params):
self._es_set_repos(query, params)
self._es_set_size(query, params)
self._es_set_sort(query, params)
self._es_filter_dates(query, params)
self._es_include_rewrites(query, params)

def generate_elastic_query(self, args):
params = args.get('params') or {}

query_funcs = self._get_es_query_funcs()
query = {
'must': [],
'must_not': [],
'sort': []
'sort': [],
'should': []
}

self._es_set_repos(query, params)
self._es_set_size(query, params)
self._es_set_sort(query, params)
self._es_filter_dates(query, params)
self._es_include_rewrites(query, params)
self._es_base_query(query, params)

for must in ['must', 'must_not']:
for field, filters in (params.get(must) or {}).items():
Expand Down Expand Up @@ -556,15 +560,25 @@ def generate_elastic_query(self, args):
}
}

if 'size' in query.keys():
query_keys = query.keys()

if len(query.get('should') or []) > 0:
es_query['source']['query']['filtered']['filter']['bool']['should'] = \
query['should']

if 'minimum_should_match' in query_keys:
es_query['source']['query']['filtered']['filter']['bool']['minimum_should_match'] = \
query['minimum_should_match']

if 'size' in query_keys:
es_query['source']['size'] = query['size']

page = query.get('page') or 1
es_query['source']['from'] = (page - 1) * query['size']
es_query['page'] = query.get('page') or 1
es_query['max_results'] = query['size']

if 'sort' in query.keys():
if 'sort' in query_keys:
es_query['source']['sort'] = query['sort']

if len(query['repo']) > 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ def get_request_aggregations(self, params, args):
"""Disable generating aggregations"""
return None

def get_es_stats_type(self, query, params):
# Check the rewrites filter is include|exclude|only
# then modify this query to reflect the filter
if (params.get('rewrites') or 'include') == 'include':
query['should'] += [{
'bool': {
'must': {'term': {'stats_type': 'archive'}},
'must_not': [
{'exists': {'field': 'rewritten_by'}},
{'exists': {'field': 'rewrite_of'}}
]
}
}, {
'bool': {
'must': [
{'term': {'stats_type': 'archive_family'}},
{'exists': {'field': 'rewritten_by'}}
],
}
}]

query['minimum_should_match'] = 1
else:
query['must'].append({'term': {'stats_type': 'archive'}})

def _es_set_size(self, query, params):
"""Disable setting the size"""
query['size'] = 200
Expand Down
1 change: 1 addition & 0 deletions server/analytics/stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from .archive_statistics import ArchiveStatisticsResource, ArchiveStatisticsService
from .gen_archive_statistics import GenArchiveStatistics
from .featuremedia_updates import * # noqa


def init_app(app):
Expand Down
Loading