Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/6.0.0-dev' into 6.0.0-beta4
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor authored and Victor committed Mar 26, 2019
2 parents 6314bc1 + 8ec95df commit 5677314
Show file tree
Hide file tree
Showing 16 changed files with 522 additions and 523 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.imcode.imcms.api.exception;

public class CategoryTypeHasCategoryException extends RuntimeException {
public CategoryTypeHasCategoryException(String message) {
super(message, null);
}
}
12 changes: 2 additions & 10 deletions src/main/java/com/imcode/imcms/domain/dto/CategoryTypeDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@ public class CategoryTypeDTO extends CategoryType {

private boolean multiSelect;

private boolean inherited;

public CategoryTypeDTO(CategoryType from) {
super(from);
}

@Override
public boolean isInherited() {
return false;
}

@Override
public void setInherited(boolean isInherited) {
// not implemented
}

@Override
public boolean isImageArchive() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public Category update(Category updateMe) {
receivedCategory.setId(updateMe.getId());
receivedCategory.setName(updateMe.getName());
receivedCategory.setDescription(updateMe.getDescription());
receivedCategory.setImageUrl(updateMe.getImageUrl());
receivedCategory.setType(updateMe.getType());
final Category updatedCategory = categoryRepository.saveAndFlush(modelMapper.map(receivedCategory, CategoryJPA.class));
return new CategoryDTO(updatedCategory);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.imcode.imcms.domain.service.api;

import com.imcode.imcms.api.exception.CategoryAlreadyExistsException;
import com.imcode.imcms.api.exception.CategoryTypeHasCategoryException;
import com.imcode.imcms.domain.dto.CategoryTypeDTO;
import com.imcode.imcms.domain.service.CategoryTypeService;
import com.imcode.imcms.model.CategoryType;
Expand Down Expand Up @@ -65,7 +65,6 @@ public CategoryType update(CategoryType updateMe) {
final CategoryType receivedCategoryType = categoryTypeRepository.findOne(updateMe.getId());
receivedCategoryType.setId(updateMe.getId());
receivedCategoryType.setName(updateMe.getName());
receivedCategoryType.setImageArchive(updateMe.isImageArchive());
receivedCategoryType.setInherited(updateMe.isInherited());
receivedCategoryType.setMultiSelect(updateMe.isMultiSelect());
final CategoryTypeJPA updatedCategoryType = categoryTypeRepository.saveAndFlush(modelMapper.map(
Expand All @@ -80,7 +79,7 @@ public void delete(int id) {
List<CategoryJPA> categories = categoryRepository.findAll();
for (CategoryJPA category : categories) {
if (category.getType().equals(categoryTypeRepository.findOne(id))) {
throw new CategoryAlreadyExistsException("CategoryType has categories!");
throw new CategoryTypeHasCategoryException("CategoryType has categories!");
}
}
categoryTypeRepository.delete(id);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/imcode/imcms/mapping/DocGetterCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public class DocGetterCallback implements Serializable {
.map(Map.Entry::getKey)
.collect(Collectors.toCollection(ArrayList::new));

if (docLanguages.isEmpty()) {
docLanguages.add(doc.getLanguage());
}

if (!docLanguages.contains(language)) { // current language is disabled for current document
doc = shouldDocBeShownWithDefaultLang(doc, docLanguages)
? docMapper.getDefaultDocument(docId)
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/imcode/imcms/model/CategoryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ protected CategoryType(CategoryType from) {
setId(from.getId());
setName(from.getName());
setMultiSelect(from.isMultiSelect());
setInherited(from.isInherited());
}

public abstract boolean isMultiSelect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CategoryJPA extends Category {
@Column(name = "image", nullable = false)
private String imageUrl;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
@JoinColumn(name = "category_type_id", nullable = false)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private CategoryTypeJPA type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface CategoryRepository extends JpaRepository<CategoryJPA, Integer>

List<CategoryJPA> findByType(CategoryTypeJPA type);

@Query(value = "select * from categories where category_type_id = ?1", nativeQuery = true)
@Query(value = "select c.* from categories c where category_type_id = ?1", nativeQuery = true)
List<CategoryJPA> findById(int id);

CategoryJPA findByNameAndType(String name, CategoryTypeJPA type);
Expand Down
58 changes: 58 additions & 0 deletions src/main/webapp/css/admin/imcms-super-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,64 @@
background-image: url("/images_new/controls/icon_folder_controll_remove_hover.png");
}

.category-type-editor,
.category-editor {
width: 50%;
}

.categories,
.category-type {
display: flex;
width: 100%;
}

.category-type__type-drop-list {
width: 65%;
}

.categories__select-categories {
width: 65%;
}

.categories__category-create-button {
margin-top: 32px;
margin-left: 15px;
}

.category-type__type-create-button {
margin-top: 32px;
margin-left: 15px;
}

.category-create-block__row-description {
width: 65%;
}

.type-create-block__field-name {
width: 65%;
}

.category-create-block__row-name {
width: 65%;
}

.category-selection-block {
flex-basis: 50%;
}

.types-editor-block {
flex-basis: 50%;
}

.category-admin {
display: flex;
justify-content: space-between;
}

.categories-block__select-categories {
width: 55%;
}

.profile-info-row {
padding: 5px;
cursor: pointer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,216 +10,6 @@ define(
],
function (BEM, components, texts, typesRestApi, $, modal) {

texts = texts.superAdmin.categories;

let $typeNameRow;
let $inherited;
let $imageArchive;
let $singleSelect;
let $multiSelect;
let errorMsg;
let $categoryTypeSaveButtons;

function buildTypeNameRow() {
$typeNameRow = components.texts.textBox('<div>', {
text: texts.sections.createCategoryType.name
});

return $typeNameRow;
}

function buildErrorBlock() {
errorMsg = components.texts.errorText("<div>", texts.duplicateErrorName, {style: 'display: none;'});
return errorMsg;
}

function buildInheriteNewDocsCheckBox() {
return $inherited = components.checkboxes.imcmsCheckbox('<div>', {
text: texts.sections.createCategoryType.inherited,
});
}

function buildImageArchiveCheckBox() {
return $imageArchive = components.checkboxes.imcmsCheckbox('<div>', {
text: texts.sections.createCategoryType.imageArchive,
});
}

function buildSingleSelectRadioButton() {
return $singleSelect = components.radios.imcmsRadio('<div>', {
text: texts.sections.createCategoryType.singleSelect,
});
}

function buildMultiSelectRadioButton() {
return $multiSelect = components.radios.imcmsRadio('<div>', {
text: texts.sections.createCategoryType.multiSelect,
});
}

function onCancelChanges($categoryTypeElement, categoryType) {

getOnDiscardChanges(() => {
onCategoryTypeView = onCategoryTypeSimpleView;
currentCategoryType = categoryType;
$categoryTypeItem = $categoryTypeElement;
prepareCategoryTypeView();
}).call();
}

function onEditCategoryType() {
onCategoryTypeView = onCancelChanges;
$categoryTypeSaveButtons.slideDown();
}

function onDeleteCategoryType() {
modal.buildModalWindow('delete?', confirmed => {
if (!confirmed) return;

typesRestApi.remove(currentCategoryType)
.done(() => {
$categoryTypeItem.remove();
currentCategoryType = null;
onEditDelegate = onSimpleEdit;
//$container.slideUp();
})
.fail(() => modal.buildErrorWindow(texts.error.removeFailed));
});
}


function onSaveCategoryType() {
let name = $typeNameRow.getValue();
let inherited = $inherited.isChecked();
let imageArchive = $imageArchive.isChecked();

let currentCtgTypeToSave = {
id: currentCategoryType.id,
name: name,
inherited: inherited,
imageArchive: imageArchive
};

if (currentCtgTypeToSave.id) {
typesRestApi.replace(currentCtgTypeToSave)
.done(savedCategoryType => {
currentCategoryType = savedCategoryType;
$categoryTypeItem.find('type-create-block__field-name').text(currentCategoryType.name);
$inherited.find('type-create-block__inherited').setCheckedValue(currentCategoryType.inherited);
$imageArchive.find('type-create-block__imageArchive').setCheckedValue(currentCategoryType.imageArchive);
onCategoryTypeView = onCategoryTypeSimpleView;
prepareCategoryTypeView();
})
.fail(() => {
errorMsg.css('display', 'inline-block').slideDown();
});
} else {
typesRestApi.create(currentCtgTypeToSave)
.done(function (categoryType) {
$categoryTypeItem = categoryType;

onCategoryTypeView = onCategoryTypeSimpleView;
prepareCategoryTypeView();
})
.fail(() => {
errorMsg.css('display', 'inline-block').slideDown();
});
}
}

function getOnDiscardChanges(onConfirm) {
return () => {
modal.buildModalWindow(texts.warnCancelMessage, confirmed => {
if (!confirmed) return;
onConfirm.call();
});
};
}

function buildCategoryTypeSaveCancelButtons() {
return $categoryTypeSaveButtons = components.buttons.buttonsContainer('<div>', [
components.buttons.saveButton({
text: texts.saveButton,
click: onSaveCategoryType
}),
components.buttons.negativeButton({
text: texts.sections.removeCategoryType.removeButton,
click: onDeleteCategoryType
})
]);
}


function prepareCategoryTypeView() {
onEditDelegate = onSimpleEdit;

$typeNameRow.setValue(currentCategoryType.name);
$singleSelect.setChecked(currentCategoryType.singleSelect);
$multiSelect.setChecked(currentCategoryType.multiSelect);
$inherited.setChecked(currentCategoryType.inherited);
$imageArchive.setChecked(currentCategoryType.imageArchive);

$categoryTypeSaveButtons.slideDown('fast');

$container.css('display', 'inline-block');
errorMsg.css('display', 'none').slideUp();
}

function onCategoryTypeSimpleView($categoryTypeRowElement, categoryType) {
if (currentCategoryType && currentCategoryType.id === categoryType.id) return;
currentCategoryType = categoryType;
$categoryTypeItem = $categoryTypeRowElement;

prepareCategoryTypeView();
}

var $container;
var $categoryTypeItem;
var currentCategoryType;
var onCategoryTypeView = onCategoryTypeSimpleView;

function buildCreateCategoryTypeContainer() {
return $container || ($container = new BEM({
block: 'type-create-block',
elements: {
'title-row': $('<div>', {text: texts.sections.createCategoryType.title}),
'field-name': buildTypeNameRow(),
'single-select': buildSingleSelectRadioButton(),
'multi-select': buildMultiSelectRadioButton(),
'inherited': buildInheriteNewDocsCheckBox(),
'imageArchive': buildImageArchiveCheckBox(),
'error-row': buildErrorBlock(),
'ctg-type-button-save': buildCategoryTypeSaveCancelButtons()
}
}).buildBlockStructure('<div>', {style: 'display: none;'}));
}

function viewCategoryType($categoryTypeRow, categoryType) {
$container.slideDown();
onCategoryTypeView($categoryTypeRow, categoryType);
}

var onEditDelegate = onSimpleEdit;

function onSimpleEdit($categoryTypeRow, categoryType) {
viewCategoryType($categoryTypeRow, categoryType);
onEditCategoryType();
}

function editCategoryType($categoryTypeRow, categoryType) {
onEditDelegate($categoryTypeRow, categoryType);
onEditDelegate = () => {
};
}

let categoryTypeEditor = {
buildCategoryTypeCreateContainer: buildCreateCategoryTypeContainer,
editCategoryType: editCategoryType,
viewCategoryType: viewCategoryType,
onDeleteCategoryType: onDeleteCategoryType,
};

return categoryTypeEditor;
}
);

Expand Down

0 comments on commit 5677314

Please sign in to comment.