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

pkp/pkp-lib#2612 Submission filtering #428

Merged
merged 5 commits into from
Aug 21, 2017
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
61 changes: 30 additions & 31 deletions controllers/list/submissions/CatalogSubmissionsListHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @brief Instantiates and manages a UI component to list submissions.
*/
import('lib.pkp.controllers.list.submissions.SubmissionsListHandler');
import('controllers.list.submissions.SubmissionsListHandler');
import('lib.pkp.classes.db.DBResultRange');
import('classes.monograph.PublishedMonograph');

Expand Down Expand Up @@ -43,8 +43,6 @@ public function getConfig() {
$config = parent::getConfig();

$config['i18n']['add'] = __('submission.catalogEntry.new');
$config['i18n']['categories'] = __('catalog.categories');
$config['i18n']['series'] = __('catalog.manage.series');
$config['i18n']['itemCount'] = __('submission.list.countMonographs');
$config['i18n']['itemsOfTotal'] = __('submission.list.itemsOfTotalMonographs');
$config['i18n']['featured'] = __('catalog.featured');
Expand Down Expand Up @@ -82,50 +80,51 @@ public function getConfig() {
array('stageId' => WORKFLOW_STAGE_ID_PRODUCTION, 'submissionId' => '__id__')
);

$config['categories'] = array();
$config['filters'] = array();

if ($context) {

$categories = array();
$categoryDao = DAORegistry::getDAO('CategoryDAO');
$categories = $categoryDao->getByPressId($context->getId());
while (!$categories->eof()) {
$category = $categories->next();
$categoriesResult = $categoryDao->getByPressId($context->getId());
while (!$categoriesResult->eof()) {
$category = $categoriesResult->next();
list($categorySortBy, $categorySortDir) = explode('-', $category->getSortOption());
$categorySortDir = empty($categorySortDir) ? $catalogSortDir : $categorySortDir == SORT_DIRECTION_ASC ? 'ASC' : 'DESC';
$config['categories'][] = array(
'id' => (int) $category->getId(),
'parent_id' => (int) $category->getParentId(),
$categories[] = array(
'param' => 'categoryIds',
'val' => (int) $category->getId(),
'title' => $category->getLocalizedTitle(),
'description' => $category->getLocalizedDescription(),
'path' => $category->getPath(),
'image' => $category->getImage(),
'sortBy' => $categorySortBy,
'sortDir' => $categorySortDir,
'sequence' => (int) $category->getSequence(),
);
}
}
if (count($categories)) {
$config['filters']['categoryIds'] = array(
'heading' => __('catalog.categories'),
'filters' => $categories,
);
}

$config['series'] = array();
if ($context) {
$series = array();
$seriesDao = DAORegistry::getDAO('SeriesDAO');
$seriesResult = $seriesDao->getByPressId($context->getId());
while (!$seriesResult->eof()) {
$series = $seriesResult->next();
list($seriesSortBy, $seriesSortDir) = explode('-', $series->getSortOption());
$seriesObj = $seriesResult->next();
list($seriesSortBy, $seriesSortDir) = explode('-', $seriesObj->getSortOption());
$seriesSortDir = empty($seriesSortDir) ? $catalogSortDir : $seriesSortDir == SORT_DIRECTION_ASC ? 'ASC' : 'DESC';
$config['series'][] = array(
'id' => (int) $series->getId(),
'title' => $series->getLocalizedTitle(),
'prefix' => $series->getLocalizedPrefix(),
'subtitle' => $series->getLocalizedSubtitle(),
'description' => $series->getLocalizedDescription(),
'path' => $series->getPath(),
'featured' => $series->getFeatured(),
'onlineIssn' => $series->getOnlineIssn(),
'printIssn' => $series->getPrintIssn(),
'image' => $series->getImage(),
$series[] = array(
'param' => 'seriesIds',
'val' => (int) $seriesObj->getId(),
'title' => $seriesObj->getLocalizedTitle(),
);
}
if (count($series)) {
$config['filters']['seriesIds'] = array(
'heading' => __('catalog.manage.series'),
'filters' => $series,
'sortBy' => $seriesSortBy,
'sortDir' => $seriesSortDir,
'editors' => $series->getEditorsString(),
);
}
}
Expand Down
52 changes: 52 additions & 0 deletions controllers/list/submissions/SubmissionsListHandler.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* @file controllers/list/submissions/SubmissionsListHandler.inc.php
*
* Copyright (c) 2014-2017 Simon Fraser University
* Copyright (c) 2000-2017 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class SubmissionsListHandler
* @ingroup controllers_list
*
* @brief Instantiates and manages a UI component to list submissions.
*/
import('lib.pkp.controllers.list.submissions.PKPSubmissionsListHandler');
import('lib.pkp.classes.db.DBResultRange');
import('lib.pkp.classes.submission.Submission');

class SubmissionsListHandler extends PKPSubmissionsListHandler {

/**
* @copydoc PKPSubmissionsListHandler::getWorkflowStages()
*/
public function getWorkflowStages() {
return array(
array(
'param' => 'stageIds',
'val' => WORKFLOW_STAGE_ID_SUBMISSION,
'title' => __('manager.publication.submissionStage'),
),
array(
'param' => 'stageIds',
'val' => WORKFLOW_STAGE_ID_INTERNAL_REVIEW,
'title' => __('workflow.review.internalReview'),
),
array(
'param' => 'stageIds',
'val' => WORKFLOW_STAGE_ID_EXTERNAL_REVIEW,
'title' => __('workflow.review.externalReview'),
),
array(
'param' => 'stageIds',
'val' => WORKFLOW_STAGE_ID_EDITING,
'title' => __('submission.copyediting'),
),
array(
'param' => 'stageIds',
'val' => WORKFLOW_STAGE_ID_PRODUCTION,
'title' => __('manager.publication.productionStage'),
),
);
}
}
79 changes: 19 additions & 60 deletions js/controllers/list/submissions/CatalogSubmissionsListFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,26 @@
{{ i18n.filter }}
</div>
<div class="pkpListPanel__filterOptions pkpListPanel__filterOptions--catalogSubmissions">
<div v-if="categories.length > 0" class="pkpListPanel__filterSet">
<div class="pkpListPanel__filterSetLabel">
{{ i18n.categories }}
<div v-for="filter in filters" class="pkpListPanel__filterSet">
<div v-if="filter.heading" class="pkpListPanel__filterSetLabel">
{{ filter.heading }}
</div>
<ul>
<li v-for="category in categories">
<li v-for="filterItem in filter.filters">
<a href="#"
@click.prevent.stop="filterByCategory(category.id)"
@click.prevent.stop="filterBy(filterItem.param, filterItem.val)"
class="pkpListPanel__filterLabel"
:class="{'--isActive': isFilterActive('category', category.id)}"
:class="{'--isActive': isFilterActive(filterItem.param, filterItem.val)}"
:tabindex="tabIndex"
>{{ category.title }}</a>
>{{ filterItem.title }}</a>
<button
v-if="isFilterActive('category', category.id)"
v-if="isFilterActive(filterItem.param, filterItem.val)"
href="#"
class="pkpListPanel__filterRemove"
@click.prevent.stop="clearFilters()"
@click.prevent.stop="clearFilter(filterItem.param, filterItem.val)"
>
<span class="fa fa-times-circle-o"></span>
<span class="pkpListPanel__filterRemoveLabel">{{ __('filterRemove', {filterTitle: category.title}) }}</span>
</button>
</li>
</ul>
</div>
<div v-if="series.length > 0" class="pkpListPanel__filterSet">
<div class="pkpListPanel__filterSetLabel">
{{ i18n.series}}
</div>
<ul>
<li v-for="seriesItem in series">
<a href="#"
@click.prevent.stop="filterBySeries(seriesItem.id)"
class="pkpListPanel__filterLabel"
:class="{'--isActive': isFilterActive('series', seriesItem.id)}"
:tabindex="tabIndex"
>{{ seriesItem.title }}</a>
<button
v-if="isFilterActive('series', seriesItem.id)"
href="#"
class="pkpListPanel__filterRemove"
@click.prevent.stop="clearFilters()"
>
<span class="fa fa-times-circle-o"></span>
<span class="pkpListPanel__filterRemoveLabel">{{ __('filterRemove', {filterTitle: seriesItem.title}) }}</span>
<span class="pkpListPanel__filterRemoveLabel">{{ __('filterRemove', {filterTitle: filterItem.title}) }}</span>
</button>
</li>
</ul>
Expand All @@ -63,39 +39,22 @@ import ListPanelFilter from '../../../../lib/pkp/js/controllers/list/ListPanelFi
export default {
extends: ListPanelFilter,
name: 'CatalogSubmissionsListFilter',
props: ['isVisible', 'categories', 'series', 'i18n'],
props: ['isVisible', 'filters', 'i18n'],
methods: {
/**
* Check if a filter is currently active
*/
isFilterActive: function(type, id) {
return typeof _.findWhere(this.activeFilters, {type: type, id: id}) !== 'undefined';
},

/**
* Filter by a category
*/
filterByCategory: function(id) {
if (this.isFilterActive('category', id)) {
this.clearFilters();
return;
}
this.clearFilters();
this.activeFilters.push({type: 'category', id: id});
this.filterList({categoryIds: id});
},

/**
* Filter by a series
* Add a filter
*
* Only allow a single filter to be enabled at a time, so that the ordering
* features can be applied to a single category or series.
*/
filterBySeries: function(id) {
if (this.isFilterActive('series', id)) {
filterBy: function(type, val) {
if (this.isFilterActive(type, val)) {
this.clearFilters();
return;
}
this.clearFilters();
this.activeFilters.push({type: 'series', id: id});
this.filterList({seriesIds: id});
this.activeFilters.push({type: type, val: val});
this.filterList(this.compileFilterParams());
},
},
};
Expand Down
25 changes: 8 additions & 17 deletions js/controllers/list/submissions/CatalogSubmissionsListPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="pkpListPanel__header">
<div class="pkpListPanel__title">{{ i18n.title }}</div>
<ul class="pkpListPanel__actions">
<li v-if="hasFilters">
<li>
<button @click.prevent="toggleFilter" :class="{'--isActive': isFilterVisible}">
<span class="fa fa-filter"></span>
{{ i18n.filter }}
Expand Down Expand Up @@ -44,11 +44,9 @@
{{ featuredNotice }}
</div>
<catalog-submissions-list-filter
v-if="hasFilters"
@filterList="updateFilter"
:isVisible="isFilterVisible"
:categories="categories"
:series="series"
:filters="filters"
:i18n="i18n"
/>
<div class="pkpListPanel__content pkpListPanel__content--catalogSubmissions">
Expand Down Expand Up @@ -136,13 +134,6 @@ export default {
return { '--isLoading': this.isLoading, '--isOrdering': this.isOrdering };
},

/**
* Are there any filters available?
*/
hasFilters: function() {
return (this.categories.length + this.series.length) > 0;
},

/**
* Return the appropriate label for the featured column depending on
* if we're looking at a filtered view
Expand Down Expand Up @@ -175,9 +166,9 @@ export default {
*/
featuredNotice: function() {
if (this.filterAssocType === this.constants.assocTypes.category) {
return this.__('orderingFeaturesSection', {title: _.findWhere(this.categories, {id: this.filterAssocId}).title});
return this.__('orderingFeaturesSection', {title: _.findWhere(this.filters.categoryIds.filters, {val: this.filterAssocId}).title});
} else if (this.filterAssocType === this.constants.assocTypes.series) {
return this.__('orderingFeaturesSection', {title: _.findWhere(this.series, {id: this.filterAssocId}).title});
return this.__('orderingFeaturesSection', {title: _.findWhere(this.filters.seriesIds.filters, {val: this.filterAssocId}).title});
}
return this.i18n.orderingFeatures;
},
Expand Down Expand Up @@ -208,9 +199,9 @@ export default {
*/
filterAssocId: function() {
if (_.has(this.filterParams, 'categoryIds')) {
return this.filterParams.categoryIds;
return this.filterParams.categoryIds[0];
} else if (_.has(this.filterParams, 'seriesIds')) {
return this.filterParams.seriesIds;
return this.filterParams.seriesIds[0];
}
// in OMP, there's only one press context and it's always 1
return 1;
Expand Down Expand Up @@ -248,11 +239,11 @@ export default {
*/
updateSortOrder: function() {
if (typeof this.filterParams.categoryIds !== 'undefined') {
var cat = _.findWhere(this.categories, {id: this.filterParams.categoryIds});
var cat = _.findWhere(this.filters.categoryIds.filters, {val: this.filterParams.categoryIds[0]});
this.getParams.orderBy = cat.sortBy;
this.getParams.orderDirection = cat.sortDir || this.constants.catalogSortDir;
} else if (typeof this.filterParams.seriesIds !== 'undefined') {
var series = _.findWhere(this.series, {id: this.filterParams.seriesIds});
var series = _.findWhere(this.filters.seriesIds.filters, {val: this.filterParams.seriesIds[0]});
this.getParams.orderBy = series.sortBy || this.constants.catalogSortBy;
this.getParams.orderDirection = series.sortDir || this.constants.catalogSortDir;
} else {
Expand Down
2 changes: 2 additions & 0 deletions js/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ window.pkp = {
return true;
}
}

return false;
}
};