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

Inactive templates #5628

Merged
merged 6 commits into from
May 5, 2023
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 @@ -75,7 +75,7 @@ public Template() {
}

/**
* Check if workflow is active.
* Check if template is active.
*
* @return true or false
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* Project DTO object.
Expand Down Expand Up @@ -223,9 +224,9 @@ public void setClient(ClientDTO client) {
}

/**
* Get list of templates.
* Get list of active templates.
*
* @return list of templates as TemplateDTO
* @return list of active templates as TemplateDTO
*/
public List<TemplateDTO> getTemplates() {
return templates;
Expand Down
58 changes: 58 additions & 0 deletions Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

Expand Down Expand Up @@ -54,6 +56,9 @@ public class TemplateForm extends TemplateBaseForm {
private static final String TITLE_USED = "templateTitleAlreadyInUse";
private final String templateListPath = MessageFormat.format(REDIRECT_PATH, "projects");
private final String templateEditPath = MessageFormat.format(REDIRECT_PATH, "templateEdit");
private List<String> templateFilters;
private List<String> selectedTemplateFilters;
private static final String DEACTIVATED_TEMPLATES_FILTER = "deactivatedTemplates";

/**
* Constructor.
Expand All @@ -62,6 +67,16 @@ public TemplateForm() {
super.setLazyDTOModel(new LazyDTOModel(ServiceManager.getTemplateService()));
}

/**
* Initialize list of template filters (currently only 'deactivated templates').
*/
@PostConstruct
public void init() {
templateFilters = new LinkedList<>();
templateFilters.add(DEACTIVATED_TEMPLATES_FILTER);
selectedTemplateFilters = new LinkedList<>();
}

/**
* Check if inactive templates should be shown.
*
Expand Down Expand Up @@ -430,4 +445,47 @@ public boolean isCurrentTemplateInUse() {
return false;
}
}

/**
* Get templateFilters.
*
* @return value of templateFilters
*/
public List<String> getTemplateFilters() {
return templateFilters;
}

/**
* Set templateFilters.
*
* @param templateFilters as list of Strings
*/
public void setTemplateFilters(List<String> templateFilters) {
this.templateFilters = templateFilters;
}

/**
* Get selectedTemplateFilters.
*
* @return value of selectedTemplateFilters
*/
public List<String> getSelectedTemplateFilters() {
return selectedTemplateFilters;
}

/**
* Set selectedTemplateFilters.
*
* @param selectedTemplateFilters as list of Strings
*/
public void setSelectedTemplateFilters(List<String> selectedTemplateFilters) {
this.selectedTemplateFilters = selectedTemplateFilters;
}

/**
* Event listener for template filter changed event.
*/
public void templateFiltersChanged() {
setShowInactiveTemplates(selectedTemplateFilters.contains(DEACTIVATED_TEMPLATES_FILTER));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public Long countDatabaseRows() throws DAOException {
public Long countNotIndexedDatabaseRows() throws DAOException {
return countDatabaseRows("SELECT COUNT(*) FROM Project WHERE indexAction = 'INDEX' OR indexAction IS NULL");
}

@Override
public Long countResults(Map filters) throws DataException {
return countDocuments(getProjectsForCurrentUserQuery());
Expand Down Expand Up @@ -224,14 +224,14 @@ private List<TemplateDTO> getTemplatesForProjectDTO(Map<String, Object> jsonObje
templateDTO.setTitle(TemplateTypeField.TITLE.getStringValue(singleObject));
templateDTOS.add(templateDTO);
}
return templateDTOS;
return templateDTOS.stream().filter(TemplateDTO::isActive).collect(Collectors.toList());
}

private void convertRelatedJSONObjects(Map<String, Object> jsonObject, ProjectDTO projectDTO) throws DataException {
// TODO: not clear if project lists will need it
projectDTO.setUsers(new ArrayList<>());
projectDTO.setTemplates(convertRelatedJSONObjectToDTO(jsonObject, ProjectTypeField.TEMPLATES.getKey(),
ServiceManager.getTemplateService()));
ServiceManager.getTemplateService()).stream().filter(TemplateDTO::isActive).collect(Collectors.toList()));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Kitodo/src/main/resources/messages/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ dataPrivacyDefaultText=Datenschutzinformationen f\u00FCr dieses System wurden no
databaseStatistic=Datenbankstatistik
day=Tag
days=Tage
deactivatedTemplates=Deaktivierte Produktionsvorlagen
defaults=Vorgaben
delete=L\u00F6schen
deleteAfterMove=Nach dem Export l\u00F6schen
Expand Down Expand Up @@ -827,7 +828,7 @@ none=Keine
normDataRecord=URI
noImageFolderConfiguredInProject=Im Projekt ist kein Zielordner f\u00fcr die Bildgenerierung konfiguriert.
noSourceFolderConfiguredInProject=Im Projekt ist kein Quellordner f\u00fcr die Bildgenerierung konfiguriert.
noProjectsConfigured=Diese Produktionsvorlage wird von keinem Projekt verwendet!
noProjectsConfigured=Diese Produktionsvorlage wurde deaktiviert oder wird von keinem Projekt verwendet!
noTemplatesConfigured=F\u00fcr dieses Projekt wurden keine Produktionsvorlagen konfiguriert!
notSelected=Keine Auswahl
nr=Nr.
Expand Down
3 changes: 2 additions & 1 deletion Kitodo/src/main/resources/messages/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ dataPrivacyDefaultText=Data privacy information have not been configured for thi
databaseStatistic=Database statistics
day=day
days=days
deactivatedTemplates=Deactivated templates
defaults=Defaults
delete=Delete
deleteAfterMove=Delete after export
Expand Down Expand Up @@ -827,7 +828,7 @@ none=None
normDataRecord=URI
noImageFolderConfiguredInProject=No target folder for imagegeneration configured in project.
noSourceFolderConfiguredInProject=No source folder for imagegeneration configured in project.
noProjectsConfigured=This template is not used by any project!
noProjectsConfigured=This template has been deactivated or is not used by any project!
noTemplatesConfigured=No template configured for this project!
notSelected=No selection
nr=Number
Expand Down
4 changes: 2 additions & 2 deletions Kitodo/src/main/webapp/WEB-INF/resources/css/kitodo.css
Original file line number Diff line number Diff line change
Expand Up @@ -1785,15 +1785,15 @@ Mass import
color: var(--medium-gray);
}

.task-filter-panel.ui-selectcheckboxmenu-panel .ui-selectcheckboxmenu-items-wrapper {
.filter-panel.ui-selectcheckboxmenu-panel .ui-selectcheckboxmenu-items-wrapper {
overflow-y: hidden;
}

#tasksTabView\:filterForm {
margin-right: var(--default-full-size);
}

#tasksTabView\:filterForm .ui-selectcheckboxmenu-label,
.filter-form .ui-selectcheckboxmenu .ui-selectcheckboxmenu-label,
#tasksTabView\:statusForm .ui-selectcheckboxmenu-label {
padding-right: var(--input-height);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
xmlns:p="http://primefaces.org/ui">
<!--@elvariable id="item" type="org.kitodo.production.dto.TemplateDTO"-->
<p:dataTable id="templateTable"
widgetVar="templateTable"
styleClass="default-layout"
var="item"
value="#{TemplateForm.lazyDTOModel}"
Expand Down Expand Up @@ -59,6 +60,19 @@
title="#{item.ruleset.title}"/>
</p:column>

<p:column headerText="#{msgs.active}"
styleClass="checkboxColumn"
sortBy="#{item.active}">
<h:outputText>
<ui:fragment rendered="#{item.isActive()}">
<i class="fa fa-check-square-o fa-lg checkbox-checked"/>
</ui:fragment>
<ui:fragment rendered="#{not item.isActive()}">
<i class="fa fa-minus-square-o fa-lg checkbox-unchecked"/>
</ui:fragment>
</h:outputText>
</p:column>

<p:column headerText="#{msgs.actions}"
resizable="false"
width="115"
Expand All @@ -67,11 +81,11 @@
<h:form id="templateActionForm">

<h:panelGroup styleClass="action"
title="#{item.projects.size() gt 0 ? msgs['createNewProcess'] : msgs['noProjectsConfigured']}">
title="#{item.isActive() and item.projects.size() gt 0 ? msgs['createNewProcess'] : msgs['noProjectsConfigured']}">
<p:commandLink id="createProcessFromTemplate"
actionListener="#{SelectProjectDialogView.setTemplateDTO(item)}"
action="#{SelectProjectDialogView.createProcessFromTemplate()}"
disabled="#{item.projects.size() lt 1}"
disabled="#{item.projects.size() lt 1 or not item.active}"
rendered="#{SecurityAccessController.hasAuthorityToAddProcess()}">
<f:setPropertyActionListener value="0" target="#{SelectProjectDialogView.selectedProjectId}"/>
<h:outputText><i class="fa fa-plus-square fa-lg"/></h:outputText>
Expand Down Expand Up @@ -161,7 +175,7 @@
title="#{project.title}"
styleClass="expansion-list-item-title"/>
<h:panelGroup class="expansion-list-item-actions">
<h:outputText rendered="#{SecurityAccessController.hasAuthorityToAddProcess()}">
<h:outputText rendered="#{SecurityAccessController.hasAuthorityToAddProcess() and item.isActive()}">
<h:link id="createProcess"
outcome="/pages/processFromTemplate?faces-redirect=true"
styleClass="action"
Expand Down Expand Up @@ -189,5 +203,26 @@
</p:rowExpansion>

</p:dataTable>

<div id="dropDownMenus">
<h:form id="filterForm"
styleClass="filter-form"
style="display: inline-block;">
<p:selectCheckboxMenu id="templateFilters"
panelStyleClass="filter-panel"
value="#{TemplateForm.selectedTemplateFilters}"
styleClass="secondary"
label="#{msgs.filter}">
<f:selectItems value="#{TemplateForm.templateFilters}"
var="templateFilter"
itemLabel="#{msgs[templateFilter]}"/>
<p:ajax event="change"
onstart="PF('templateTable').getPaginator().setPage(0);"
listener="#{TemplateForm.templateFiltersChanged}"
update="templateTable"/>
</p:selectCheckboxMenu>
</h:form>
</div>

<ui:include src="/WEB-INF/templates/includes/processFromTemplate/dialogs/selectProject.xhtml"/>
</ui:composition>
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,40 @@
</p:rowExpansion>
</p:dataTable>
</h:form>

<div id="dropDownMenus">
<h:form id="filterForm"
styleClass="filter-form"
style="display: inline-block;">
<p:selectCheckboxMenu id="taskFilters"
panelStyleClass="filter-panel"
value="#{CurrentTaskForm.selectedTaskFilters}"
styleClass="secondary"
label="#{msgs.filter}">
<f:selectItems value="#{CurrentTaskForm.taskFilters}"
var="taskFilter"
itemLabel="#{msgs[taskFilter]}"/>
<p:ajax event="change"
onstart="PF('taskTable').getPaginator().setPage(0);"
listener="#{CurrentTaskForm.taskFiltersChanged}"
update="tasksTabView:tasksForm:taskTable"/>
</p:selectCheckboxMenu>
</h:form>
<h:form id="statusForm"
style="display: inline-block;">
<p:selectCheckboxMenu id="taskStatus"
panelStyleClass="filter-panel"
value="#{CurrentTaskForm.selectedTaskStatus}"
styleClass="secondary"
label="#{msgs.processingStatus}">
<f:selectItems value="#{CurrentTaskForm.taskStatus}"
var="taskStatus"
itemLabel="#{msgs[taskStatus.title]}"/>
<p:ajax event="change"
onstart="PF('taskTable').getPaginator().setPage(0);"
listener="#{CurrentTaskForm.taskStatusChanged}"
update="tasksTabView:tasksForm:taskTable"/>
</p:selectCheckboxMenu>
</h:form>
</div>
</ui:composition>
23 changes: 23 additions & 0 deletions Kitodo/src/test/java/org/kitodo/selenium/ListingST.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.kitodo.selenium.testframework.pages.ProcessesPage;
import org.kitodo.selenium.testframework.pages.ProjectsPage;
import org.kitodo.selenium.testframework.pages.TasksPage;
import org.kitodo.selenium.testframework.pages.TemplateEditPage;
import org.kitodo.selenium.testframework.pages.UsersPage;

public class ListingST extends BaseTestSelenium {
Expand Down Expand Up @@ -234,4 +235,26 @@ public void listUsersTest() throws Exception {
int ldapGroupsDisplayed = usersPage.countListedLdapGroups();
assertEquals("Displayed wrong number of ldap groups!", ldapGroupsInDatabase, ldapGroupsDisplayed);
}

/**
* Test number of displayed templates. Assert deactivated templates are hidden by default and only visible
* when activating the corresponding switch on the projects/templates page.
*
* @throws Exception when thread is interrupted or templates cannot be loaded.
*/
@Test
public void listTemplatesTest() throws Exception {
projectsPage.goToTemplateTab();
assertEquals("Wrong number of templates before hiding first template", 2,
projectsPage.getTemplateTitles().size());
TemplateEditPage editTemplatePage = projectsPage.editTemplate();
editTemplatePage.hideTemplate();
editTemplatePage.save();
assertEquals("Wrong number of templates after hiding first template", 1,
projectsPage.getTemplateTitles().size());
projectsPage.goToTemplateTab();
projectsPage.toggleHiddenTemplates();
assertEquals("Wrong number of templates after toggling hidden templates", 2,
projectsPage.getTemplateTitles().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public abstract class Page<T> {
private static final Logger logger = LogManager.getLogger(Page.class);
static final String DATA = "_data";
static final String CSS_SELECTOR_DROPDOWN_TRIGGER = ".ui-selectonemenu-trigger";
static final String WAIT_FOR_FILTER_FORM_MENU = "Wait for filter form menu to open";

@SuppressWarnings("unused")
@FindBy(id = "user-menu")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ public class ProjectsPage extends Page<ProjectsPage> {
@FindBy(id = RULESET_TABLE + ":0:actionForm:deleteRuleset")
private WebElement deleteFirstRulesetButton;

@FindBy(id = "filterForm:templateFilters")
private WebElement filterMenu;

@FindBy(id = "filterForm:templateFilters_panel")
private WebElement checkBoxPanel;

@FindBy(css = ".filter-panel li:last-child .ui-chkbox")
private WebElement toggleHiddenTemplatesWrapper;

public ProjectsPage() {
super("pages/projects.jsf");
}
Expand Down Expand Up @@ -630,4 +639,19 @@ public Long getNumberOfImportConfigurations() {
public Long getNumberOfMappingFiles() {
return (long) Browser.getRowsOfTable(Browser.getDriver().findElementById(MAPPING_FILE_TABLE)).size();
}

/**
* Toggle switch to hide/show inactive templates.
*/
public void toggleHiddenTemplates() {
filterMenu.click();
await(WAIT_FOR_FILTER_FORM_MENU).pollDelay(700, TimeUnit.MILLISECONDS)
.atMost(3, TimeUnit.SECONDS)
.until(() -> checkBoxPanel.isDisplayed());
toggleHiddenTemplatesWrapper.click();

await("Wait for template filter list to be updated").pollDelay(700, TimeUnit.MILLISECONDS)
.atMost(3, TimeUnit.SECONDS)
.until(() -> filterMenu.isEnabled());
}
}
Loading