ItEr35S08CUAsignacionCalendarioLaboralRecursoItEr25S09: Removed options to create machine calendars.
This commit is contained in:
parent
2079c7d38b
commit
e83acbdccc
4 changed files with 108 additions and 100 deletions
|
|
@ -88,4 +88,11 @@ public interface IMachineModel {
|
|||
List<BaseCalendar> getBaseCalendars();
|
||||
|
||||
void removeConfigurationUnit(MachineWorkersConfigurationUnit unit);
|
||||
}
|
||||
|
||||
void setCalendar(ResourceCalendar resourceCalendar);
|
||||
|
||||
ResourceCalendar getCalendar();
|
||||
|
||||
BaseCalendar getDefaultCalendar();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ import org.zkoss.zk.ui.WrongValueException;
|
|||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Combobox;
|
||||
import org.zkoss.zul.Comboitem;
|
||||
import org.zkoss.zul.Radio;
|
||||
import org.zkoss.zul.ComboitemRenderer;
|
||||
import org.zkoss.zul.Tab;
|
||||
import org.zkoss.zul.api.Window;
|
||||
|
||||
|
|
@ -85,6 +85,8 @@ public class MachineCRUDController extends GenericForwardComposer {
|
|||
|
||||
}
|
||||
|
||||
private BaseCalendarsComboitemRenderer baseCalendarsComboitemRenderer = new BaseCalendarsComboitemRenderer();
|
||||
|
||||
public List<Machine> getMachines() {
|
||||
return machineModel.getMachines();
|
||||
}
|
||||
|
|
@ -211,6 +213,9 @@ public class MachineCRUDController extends GenericForwardComposer {
|
|||
if (baseCalendarEditionController != null) {
|
||||
baseCalendarEditionController.save();
|
||||
}
|
||||
if (machineModel.getCalendar() == null) {
|
||||
createCalendar();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveCriterions() throws ValidationException {
|
||||
|
|
@ -229,73 +234,30 @@ public class MachineCRUDController extends GenericForwardComposer {
|
|||
goToList();
|
||||
}
|
||||
|
||||
public void calendarChecked(Radio radio) {
|
||||
Combobox comboboxDerived = (Combobox) radio
|
||||
.getFellow("createDerivedCalendar");
|
||||
Combobox comboboxCopy = (Combobox) radio
|
||||
.getFellow("createCopyCalendar");
|
||||
|
||||
String selectedId = radio.getId();
|
||||
if (selectedId.equals("createFromScratch")) {
|
||||
comboboxDerived.setDisabled(true);
|
||||
comboboxCopy.setDisabled(true);
|
||||
} else if (selectedId.equals("createDerived")) {
|
||||
comboboxDerived.setDisabled(false);
|
||||
comboboxCopy.setDisabled(true);
|
||||
} else if (selectedId.equals("createCopy")) {
|
||||
comboboxDerived.setDisabled(true);
|
||||
comboboxCopy.setDisabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public List<BaseCalendar> getBaseCalendars() {
|
||||
return machineModel.getBaseCalendars();
|
||||
}
|
||||
|
||||
private IBaseCalendarModel resourceCalendarModel;
|
||||
|
||||
public void createCalendar(String optionId) {
|
||||
if (optionId.equals("createFromScratch")) {
|
||||
resourceCalendarModel.initCreate();
|
||||
} else if (optionId.equals("createDerived")) {
|
||||
Combobox combobox = (Combobox) editWindow
|
||||
.getFellow("createDerivedCalendar");
|
||||
Comboitem selectedItem = combobox.getSelectedItem();
|
||||
if (selectedItem == null) {
|
||||
throw new WrongValueException(combobox,
|
||||
_("Please, select a calendar"));
|
||||
}
|
||||
BaseCalendar parentCalendar = (BaseCalendar) combobox
|
||||
.getSelectedItem().getValue();
|
||||
resourceCalendarModel.initCreateDerived(parentCalendar);
|
||||
} else if (optionId.equals("createCopy")) {
|
||||
Combobox combobox = (Combobox) editWindow
|
||||
.getFellow("createCopyCalendar");
|
||||
Comboitem selectedItem = combobox.getSelectedItem();
|
||||
if (selectedItem == null) {
|
||||
throw new WrongValueException(combobox,
|
||||
_("Please, select a calendar"));
|
||||
}
|
||||
BaseCalendar origCalendar = (BaseCalendar) combobox
|
||||
.getSelectedItem().getValue();
|
||||
resourceCalendarModel.initCreateCopy(origCalendar);
|
||||
} else {
|
||||
throw new RuntimeException(_("Unknow option {0} to create a resource calendar", optionId));
|
||||
private void createCalendar() {
|
||||
Combobox combobox = (Combobox) editWindow
|
||||
.getFellow("createDerivedCalendar");
|
||||
Comboitem selectedItem = combobox.getSelectedItem();
|
||||
if (selectedItem == null) {
|
||||
throw new WrongValueException(combobox,
|
||||
_("Please, select a calendar"));
|
||||
}
|
||||
|
||||
updateCalendarController();
|
||||
machineModel.setCalendarOfMachine((ResourceCalendar) resourceCalendarModel
|
||||
BaseCalendar parentCalendar = (BaseCalendar) combobox.getSelectedItem()
|
||||
.getValue();
|
||||
if (parentCalendar == null) {
|
||||
parentCalendar = machineModel.getDefaultCalendar();
|
||||
}
|
||||
resourceCalendarModel.initCreateDerived(parentCalendar);
|
||||
|
||||
machineModel.setCalendar((ResourceCalendar) resourceCalendarModel
|
||||
.getBaseCalendar());
|
||||
try {
|
||||
baseCalendarEditionController.doAfterCompose(editCalendarWindow);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
baseCalendarEditionController.setSelectedDay(new Date());
|
||||
Util.reloadBindings(editCalendarWindow);
|
||||
Util.reloadBindings(createNewVersionWindow);
|
||||
reloadWindow();
|
||||
}
|
||||
|
||||
private Window editCalendarWindow;
|
||||
|
|
@ -373,4 +335,29 @@ public class MachineCRUDController extends GenericForwardComposer {
|
|||
return configurationController;
|
||||
}
|
||||
|
||||
}
|
||||
public BaseCalendarsComboitemRenderer getBaseCalendarsComboitemRenderer() {
|
||||
return baseCalendarsComboitemRenderer;
|
||||
}
|
||||
|
||||
private class BaseCalendarsComboitemRenderer implements ComboitemRenderer {
|
||||
|
||||
@Override
|
||||
public void render(Comboitem item, Object data) throws Exception {
|
||||
BaseCalendar calendar = (BaseCalendar) data;
|
||||
item.setLabel(calendar.getName());
|
||||
item.setValue(calendar);
|
||||
|
||||
if (isDefaultCalendar(calendar)) {
|
||||
Combobox combobox = (Combobox) item.getParent();
|
||||
combobox.setSelectedItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDefaultCalendar(BaseCalendar calendar) {
|
||||
BaseCalendar defaultCalendar = machineModel.getDefaultCalendar();
|
||||
return defaultCalendar.getId().equals(calendar.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -30,9 +30,12 @@ import org.apache.commons.lang.Validate;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.validator.ClassValidator;
|
||||
import org.hibernate.validator.InvalidValue;
|
||||
import org.navalplanner.business.calendars.daos.IBaseCalendarDAO;
|
||||
import org.navalplanner.business.calendars.entities.BaseCalendar;
|
||||
import org.navalplanner.business.calendars.entities.CalendarData;
|
||||
import org.navalplanner.business.calendars.entities.ResourceCalendar;
|
||||
import org.navalplanner.business.common.daos.IConfigurationDAO;
|
||||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.resources.daos.ICriterionDAO;
|
||||
|
|
@ -90,6 +93,8 @@ public class MachineModel implements IMachineModel {
|
|||
private ICriterionTypeDAO criterionTypeDAO;
|
||||
@Autowired
|
||||
private IWorkerDAO workerDAO;
|
||||
@Autowired
|
||||
private IConfigurationDAO configurationDAO;
|
||||
|
||||
private ClassValidator<Machine> validator = new ClassValidator<Machine>(
|
||||
Machine.class);
|
||||
|
|
@ -146,6 +151,13 @@ public class MachineModel implements IMachineModel {
|
|||
reattachWorkersCache();
|
||||
loadCriterionSatisfactions();
|
||||
loadConfigurationUnits();
|
||||
loadCalendar();
|
||||
}
|
||||
|
||||
private void loadCalendar() {
|
||||
if (machine.getCalendar() != null) {
|
||||
forceLoadCalendar(machine.getCalendar());
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCriterionSatisfactions() {
|
||||
|
|
@ -268,4 +280,39 @@ public class MachineModel implements IMachineModel {
|
|||
public void removeConfigurationUnit(MachineWorkersConfigurationUnit unit) {
|
||||
machine.removeMachineWorkersConfigurationUnit(unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCalendar(ResourceCalendar resourceCalendar) {
|
||||
if (machine != null) {
|
||||
machine.setCalendar(resourceCalendar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceCalendar getCalendar() {
|
||||
if (machine != null) {
|
||||
return machine.getCalendar();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public BaseCalendar getDefaultCalendar() {
|
||||
BaseCalendar defaultCalendar = configurationDAO.getConfiguration()
|
||||
.getDefaultCalendar();
|
||||
forceLoadCalendar(defaultCalendar);
|
||||
return defaultCalendar;
|
||||
}
|
||||
|
||||
private void forceLoadCalendar(BaseCalendar baseCalendar) {
|
||||
for (CalendarData calendarData : baseCalendar.getCalendarDataVersions()) {
|
||||
calendarData.getHoursPerDay().size();
|
||||
if (calendarData.getParent() != null) {
|
||||
forceLoadCalendar(calendarData.getParent());
|
||||
}
|
||||
}
|
||||
baseCalendar.getExceptions().size();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,46 +25,13 @@
|
|||
|
||||
<div visible="@{controller.isCalendarNull}">
|
||||
|
||||
<radiogroup id="createCalendarOptions"
|
||||
onCheck="controller.calendarChecked(self.selectedItem)">
|
||||
<grid fixedLayout="false">
|
||||
<columns>
|
||||
<column width="200px"/>
|
||||
<column/>
|
||||
</columns>
|
||||
<rows>
|
||||
<row>
|
||||
<!-- Brand new calendar -->
|
||||
<radio id="createFromScratch"
|
||||
label="${i18n:_('Create calendar from scratch')}"
|
||||
checked="true" />
|
||||
<label value=""/>
|
||||
</row>
|
||||
<row>
|
||||
<!-- Create derived calendar -->
|
||||
<radio id="createDerived" label="${i18n:_('Create derived calendar')}" />
|
||||
<combobox id="createDerivedCalendar" disabled="true"
|
||||
model="@{controller.baseCalendars}">
|
||||
<comboitem self="@{each='baseCalendar'}" value="@{baseCalendar}"
|
||||
label="@{baseCalendar.name}" />
|
||||
</combobox>
|
||||
</row>
|
||||
<row>
|
||||
<!-- Create calendar copy -->
|
||||
<radio id="createCopy" label="${i18n:_('Create copy of calendar')}" />
|
||||
<combobox id="createCopyCalendar" disabled="true"
|
||||
model="@{controller.baseCalendars}">
|
||||
<comboitem self="@{each='baseCalendar'}" value="@{baseCalendar}"
|
||||
label="@{baseCalendar.name}" />
|
||||
</combobox>
|
||||
</row>
|
||||
</rows>
|
||||
</grid>
|
||||
</radiogroup>
|
||||
<hbox>
|
||||
<label value="${i18n:_('Select parent calendar')}" />
|
||||
<combobox id="createDerivedCalendar"
|
||||
model="@{controller.baseCalendars}"
|
||||
itemRenderer="@{controller.baseCalendarsComboitemRenderer}" />
|
||||
</hbox>
|
||||
|
||||
<!-- Create new calendar -->
|
||||
<button label="${i18n:_('Create')}"
|
||||
onClick="controller.createCalendar(createCalendarOptions.selectedItem.id);" />
|
||||
</div>
|
||||
|
||||
<!-- Control buttons calendar -->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue