@@ -0,0 +1,1030 @@
+package com.imcode.imcms.domain.factory;%0A%0Aimport com.imcode.imcms.domain.dto.ImageDTO;%0Aimport com.imcode.imcms.domain.dto.ImageInTextDTO;%0Aimport com.imcode.imcms.persistence.repository.ImageRepository;%0Aimport org.springframework.stereotype.Component;%0A%0Aimport java.util.Optional;%0A%0A/**%0A * Created by Serhii from Ubrainians for imCode%0A * on 14.02.2018.%0A */%0A@Component%0Apublic class ImageInTextFactory %7B%0A%0A    private final ImageRepository repository;%0A%0A    ImageInTextFactory(ImageRepository imageRepository) %7B%0A        this.repository = imageRepository;%0A    %7D%0A%0A    public ImageInTextDTO createWithIndex(ImageDTO dataHolder) %7B%0A        final ImageInTextDTO emptyDTO = new ImageInTextDTO(dataHolder);%0A        emptyDTO.setIndex(getFreeIndexForImageInTextEditor(dataHolder.getDocId()));%0A        return emptyDTO;%0A    %7D%0A%0A    private Integer getFreeIndexForImageInTextEditor(Integer docId) %7B%0A        final int minIndex = Optional.ofNullable(repository.findMinIndexByVersion(docId)).orElse(0);%0A        return Math.min(minIndex, 0) - 1;%0A    %7D%0A%0A%7D%0A

Apply new UI to the admin panel and editors: - Introduced ImageInTextFactory class.