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

511: Category modification flexibility #36

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
Expand All @@ -61,6 +62,8 @@
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.inject.Singleton;
import org.sigmah.client.ui.widget.form.Forms;
import org.sigmah.client.util.ColumnProviders;

/**
* {@link CategoriesAdminPresenter}'s view implementation.
Expand All @@ -79,8 +82,11 @@ public class CategoriesAdminView extends AbstractView implements CategoriesAdmin
private Grid<CategoryElementDTO> categoryElementsGrid;
private Button addCategoryElementButton;
private Button deleteCategoryElementButton;
private Button disableCategoryElementButton;
private Button enableCategoryElementButton;
private TextField<String> name;
private ColorField colorField;
private Boolean isdisable;
private ContentPanel categoryElementsPanel;
/**
* Category Panel
Expand Down Expand Up @@ -142,9 +148,29 @@ public Object render(CategoryElementDTO model, String property, ColumnData confi
configs.add(column);

column = new ColumnConfig();


column.setId("label");
column.setWidth(400);
column.setHeaderHtml(I18N.CONSTANTS.adminCategoryElementLabel());
column.setRenderer(new GridCellRenderer<CategoryElementDTO>() {

@Override
public Object render(CategoryElementDTO model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<CategoryElementDTO> store,
Grid<CategoryElementDTO> grid) {
final String label;
label = model.getLabel();
if(model.getisDisabled()) {
return model.renderDisabled(label);
}
else {
return model.renderText(label);
}


}

});
configs.add(column);

ColumnModel cm = new ColumnModel(configs);
Expand Down Expand Up @@ -309,6 +335,14 @@ private ToolBar categoryElementToolBar() {
deleteCategoryElementButton = new Button(I18N.CONSTANTS.delete(), IconImageBundle.ICONS.delete());

toolbar.add(deleteCategoryElementButton);

disableCategoryElementButton = new Button(I18N.CONSTANTS.disable(), IconImageBundle.ICONS.disable());

toolbar.add(disableCategoryElementButton);

enableCategoryElementButton =new Button(I18N.CONSTANTS.enable(), IconImageBundle.ICONS.checked());

toolbar.add(enableCategoryElementButton);
return toolbar;
}

Expand Down Expand Up @@ -351,6 +385,16 @@ public Button getAddCategoryElementButton() {
public Button getDeleteCategoryElementButton() {
return deleteCategoryElementButton;
}

@Override
public Button getDisableCategoryElementButton() {
return disableCategoryElementButton;
}

@Override
public Button getEnableCategoryElementButton() {
return enableCategoryElementButton;
}

@Override
public Button getDeleteCategoryTypeButton() {
Expand Down Expand Up @@ -386,6 +430,11 @@ public TextField<String> getName() {
public ColorField getColorField() {
return colorField;
}

@Override
public Boolean getisdisable() {
return false;
}

@Override
public Button getImportCategoryTypeButton() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/sigmah/client/util/AdminUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public final class AdminUtil {
public static final String PROP_CATEGORY_ELEMENT = "NewCategoryElement";
public static final String PROP_CATEGORY_ELEMENT_NAME = "NewCategoryElementName";
public static final String PROP_CATEGORY_ELEMENT_COLOR = "NewCategoryElementColor";
public static final String PROP_CATEGORY_ELEMENT_ISDISABLED = "isdisabled";

public static final String PROP_PM_NAME = "ProjectModelName";
public static final String PROP_PM_USE = "ProjectModelUse";
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/org/sigmah/offline/dao/ProjectAsyncDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,23 @@ public void onRequestSuccess(OrgUnitDTO result) {

private Set<CategoryElementDTO> getCategoryElements(ValueResult valueResult, QuestionElementDTO questionElement) {
if (valueResult != null && valueResult.isValueDefined()) {
if(questionElement.getMultiple() == null || !questionElement.getMultiple()) {

if(questionElement.getMultiple() == null || !questionElement.getMultiple()) {
final String idChoice = valueResult.getValueObject();

for (final QuestionChoiceElementDTO choice : questionElement.getChoices()) {
for (final CategoryElementDTO choice : questionElement.getCategoryType().getCategoryElementsDTO()) {
if (idChoice.equals(String.valueOf(choice.getId()))) {
return Collections.<CategoryElementDTO>singleton(choice.getCategoryElement());
return Collections.<CategoryElementDTO>singleton(choice);
}
}
} else {
final Set<Integer> selectedChoicesId = new HashSet<Integer>(ValueResultUtils.splitValuesAsInteger(valueResult.getValueObject()));

final Set<CategoryElementDTO> elements = new HashSet<CategoryElementDTO>();

for (final QuestionChoiceElementDTO choice : questionElement.getChoices()) {
for (final CategoryElementDTO choice : questionElement.getCategoryType().getCategoryElementsDTO()) {
if (selectedChoicesId.contains(choice.getId())) {
elements.add(choice.getCategoryElement());
elements.add(choice);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package org.sigmah.server.domain.category;

/*
* #%L
* Sigmah
* %%
* Copyright (C) 2010 - 2016 URD
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

package org.sigmah.server.domain.category;
/*
* #%L
* Sigmah
* %%
* Copyright (C) 2010 - 2016 URD
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import java.util.Objects;
import javax.persistence.Column;
Expand Down Expand Up @@ -72,7 +72,10 @@ public class CategoryElement extends AbstractEntityId<Integer> {
@NotNull
@Size(max = EntityConstants.CATEGORY_ELEMENT_COLOR_HEX_MAX_LENGTH)
private String color;


@Column(name = EntityConstants.IS_DISABLED, nullable = false)
@NotNull
private Boolean isdisabled = false;
// --------------------------------------------------------------------------------
//
// FOREIGN KEYS.
Expand Down Expand Up @@ -194,4 +197,15 @@ public Organization getOrganization() {
public void setOrganization(Organization organization) {
this.organization = organization;
}

public boolean getisDisabled() {
if(isdisabled == null){
return false;
}
return isdisabled;
}

public void setisDisabled(boolean isdisabled) {
this.isdisabled = isdisabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ private EntityConstants() {
public static final String CATEGORY_ELEMENT_COLUMN_ID = "id_category_element";
public static final String CATEGORY_ELEMENT_COLUMN_COLOR_HEX = "color_hex";
public static final String CATEGORY_ELEMENT_COLUMN_LABEL = "label";
public static final String IS_DISABLED = "isdisabled";

public static final int CATEGORY_ELEMENT_COLOR_HEX_MAX_LENGTH = 6;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.sigmah.server.handler;

/*
* #%L
* Sigmah
* %%
* Copyright (C) 2010 - 2016 URD
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import com.google.inject.persist.Transactional;
import java.util.List;
import org.sigmah.shared.command.DisableCategoryElements;
import org.sigmah.shared.dto.category.CategoryElementDTO;
import org.sigmah.server.dispatch.impl.UserDispatch;
import org.sigmah.server.domain.category.CategoryElement;
import org.sigmah.server.handler.base.AbstractCommandHandler;
import org.sigmah.shared.command.DisableFlexibleElements;
import org.sigmah.shared.command.result.VoidResult;
import org.sigmah.shared.dispatch.CommandException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Handler for the command {@link DisableCategoryElements}.
*
* @author Nikita Jibhkate (niksj1996@@gmail.com)
*/
public class DisableCategoryElementsHandler extends AbstractCommandHandler<DisableCategoryElements, VoidResult> {

private static final Logger LOGGER = LoggerFactory.getLogger(DisableCategoryElementsHandler.class);

@Override
protected VoidResult execute(DisableCategoryElements command, UserDispatch.UserExecutionContext context) throws CommandException {
if (command.getCategoryElements() != null) {
setDisabled(command.getCategoryElements(), command.isDisable());
}
return null;
}

@Transactional
protected void setDisabled(List<CategoryElementDTO> elements, boolean disabled) {
for (CategoryElementDTO categoryElementDTO : elements) {
final CategoryElement categoryElement = em().find(CategoryElement.class, categoryElementDTO.getId());
//flexibleElement.setDisabledDate(disabled ? new Date() : null);
categoryElement.setisDisabled(disabled);
em().merge(categoryElement);

LOGGER.debug("DisableFlexibleElementsHandler flexibleElement {} name {}.", categoryElementDTO.getId(), categoryElementDTO.getLabel());
}
}
}
10 changes: 5 additions & 5 deletions src/main/java/org/sigmah/server/handler/util/ProjectMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,19 @@ public ProjectDTO map(final Project project, final boolean mapChildren) {
List<Integer> values = ValueResultUtils.splitValuesAsInteger(value.getValue());
if (!values.isEmpty()) {

final TypedQuery<QuestionChoiceElement> choicesQuery =
em().createQuery("SELECT c FROM QuestionChoiceElement c WHERE c.id IN (:ids)", QuestionChoiceElement.class);
final TypedQuery<CategoryElement> choicesQuery =
em().createQuery("SELECT c FROM CategoryElement c WHERE c.id IN (:ids)", CategoryElement.class);
choicesQuery.setParameter("ids", ValueResultUtils.splitValuesAsInteger(value.getValue()));

for (final QuestionChoiceElement choice : choicesQuery.getResultList()) {
for (final CategoryElement choice : choicesQuery.getResultList()) {

final CategoryType parent = choice.getCategoryElement().getParentType();
final CategoryType parent = choice.getParentType();
final CategoryTypeDTO parentDTO = new CategoryTypeDTO();
parentDTO.setId(parent.getId());
parentDTO.setLabel(parent.getLabel());
parentDTO.setIcon(parent.getIcon());

final CategoryElement element = choice.getCategoryElement();
final CategoryElement element = choice;
final CategoryElementDTO elementDTO = new CategoryElementDTO();
elementDTO.setId(element.getId());
elementDTO.setLabel(element.getLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected void configureHandlers() {
bindHandler(CopyLogFrame.class, CopyLogFrameHandler.class);
bindHandler(DeactivateUsers.class, DeactivateUsersHandler.class);
bindHandler(DisableFlexibleElements.class, DisableFlexibleElementsHandler.class);
bindHandler(DisableCategoryElements.class, DisableCategoryElementsHandler.class);
bindHandler(DeleteCategories.class, DeleteCategoriesHandler.class);
bindHandler(DeleteFlexibleElements.class, DeleteFlexibleElementsHandler.class);
bindHandler(Delete.class, DeleteHandler.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ final class AccessRights {
sperm(commandToken(CopyLogFrame.class), GrantType.AUTHENTICATED_ONLY, GlobalPermissionEnum.EDIT_LOGFRAME);
sperm(commandToken(DeactivateUsers.class), GrantType.AUTHENTICATED_ONLY, GlobalPermissionEnum.MANAGE_USERS);
sperm(commandToken(DisableFlexibleElements.class), GrantType.AUTHENTICATED_ONLY);
sperm(commandToken(DisableCategoryElements.class), GrantType.AUTHENTICATED_ONLY);
sperm(commandToken(DeleteCategories.class), GrantType.AUTHENTICATED_ONLY);
sperm(commandToken(DeleteFlexibleElements.class), GrantType.AUTHENTICATED_ONLY);
sperm(commandToken(Delete.class), GrantType.AUTHENTICATED_ONLY);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.sigmah.shared.command;

/*
* #%L
* Sigmah
* %%
* Copyright (C) 2010 - 2016 URD
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import java.util.List;
import org.sigmah.shared.command.base.Command;

import org.sigmah.shared.command.result.VoidResult;
import org.sigmah.shared.dto.category.CategoryElementDTO;

/**
* Enable or disable category elements.
*
* @author Nikita Jibhkate (niksj1996@gmail.com)
*/
public class DisableCategoryElements implements Command<VoidResult> {
//private static final long serialVersionUID = 3902096705358448566L;

private List<CategoryElementDTO> categoryElements;
private boolean disable;

protected DisableCategoryElements() {
// Serialization.
}

public DisableCategoryElements(List<CategoryElementDTO> categoryElements, boolean disable) {
this.categoryElements = categoryElements;
this.disable = disable;
}

public List<CategoryElementDTO> getCategoryElements() {
return categoryElements;
}

public boolean isDisable() {
return disable;
}

}
Loading