Commit fa280e81 by Eva Gächter
parents c7fc7856 1c0c3bd7
......@@ -19,7 +19,7 @@ package ch.insign.cms.blocks.sliderblock;
import ch.insign.cms.models.AbstractBlock;
import ch.insign.cms.models.CollectionBlock;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Predicate;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import play.twirl.api.Html;
......@@ -32,15 +32,12 @@ import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static com.google.common.collect.Collections2.filter;
import java.util.stream.Collectors;
@Entity
@Table(name = "cms_block_collection_slider")
@DiscriminatorValue("SliderCollectionBlock")
//@SecuredEntity( name = "SliderCollectionBlock", actions = { "read", "modify" })
public class SliderCollectionBlock extends CollectionBlock {
private final static Logger logger = LoggerFactory.getLogger(SliderCollectionBlock.class);
......@@ -88,17 +85,12 @@ public class SliderCollectionBlock extends CollectionBlock {
super.save();
}
public List<AbstractBlock> getSubSliderSubBlocks() {
Predicate<AbstractBlock> validSliderEntityBlock = new Predicate<AbstractBlock>() {
public boolean apply(AbstractBlock targetBlock) {
SliderEntryBlock sliderEntryBlock = (SliderEntryBlock) targetBlock;
return !sliderEntryBlock.getTitle().get().equals("");
}
};
Collection<AbstractBlock> validSubBlocks = filter(super.getSubBlocks(), validSliderEntityBlock);
return new ArrayList(validSubBlocks);
public List<SliderEntryBlock> getSubSliderSubBlocks() {
return super.getSubBlocks().stream()
.filter(entry -> SliderEntryBlock.class.isAssignableFrom(entry.getClass()))
.map(SliderEntryBlock.class::cast)
.filter(entry -> StringUtils.isNotBlank(entry.getTitle().get()))
.collect(Collectors.toList());
}
public String getSliderEntryOrder() {
......
......@@ -5,28 +5,32 @@
@import scala.collection.JavaConverters.iterableAsScalaIterableConverter
@(data: ch.insign.cms.blocks.sliderblock.SliderCollectionBlock)
@_blockBase(data = data, delete = true, edit = true, add = true, color = "green", name = Messages("collection.block.name"), sortableContainer = false) {
@if(data.getSubSliderSubBlocks != null && !data.getSubSliderSubBlocks.isEmpty) {
@Some(Template.filterPermitted(data.getSubSliderSubBlocks).asScala).filter(_.nonEmpty).map { entries =>
<div id="slider-@data.getId" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
@Template.filterPermitted(data.getSubSliderSubBlocks).asScala.zipWithIndex.map { case (slide: SliderEntryBlock, idx) =>
<li data-target="#slider-@data.getId" data-slide-to="@idx" class="@if(Template.filterPermitted(data.getSubSliderSubBlocks).asScala.head == slide){active}"></li>
}
</ol>
@if(entries.size > 1) {
<ol class="carousel-indicators">
@entries.zipWithIndex.map { case (slide, idx) =>
<li data-target="#slider-@data.getId" data-slide-to="@idx" @if(entries.head == slide){class="active"}></li>
}
</ol>
}
<div class="carousel-inner">
@Template.filterPermitted(data.getSubSliderSubBlocks).asScala.map { case slide: SliderEntryBlock =>
<div class="carousel-item @if(Template.filterPermitted(data.getSubSliderSubBlocks).asScala.head == slide){active}">
@slide.render
</div>
}
@entries.map { slide =>
<div class="carousel-item @if(entries.head == slide){active}">
@slide.render
</div>
}
</div>
<a class="carousel-control-prev" href="#slider-@data.getId" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#slider-@data.getId" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
@if(entries.size > 1) {
<a class="carousel-control-prev" href="#slider-@data.getId" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#slider-@data.getId" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
}
</div>
}
}
@(data: ch.insign.cms.blocks.sliderblock.SliderCollectionBlock, editForm: play.data.Form[ch.insign.cms.blocks.sliderblock.SliderCollectionBlock], backURL: String)
@import metronic.text
@import ch.insign.cms.views.html.admin.baseBlockEdit
@import play.api.i18n.Messages
@import ch.insign.cms.models.Template
@import ch.insign.cms.models.CMS
@import ch.insign.cms.controllers.routes.BlockController
@import ch.insign.cms.blocks.sliderblock.SliderEntryBlock
@import helper.form
@import ch.insign.cms.views.html.admin.deleteBlockModal
@import ch.insign.commons.i18n.Language
@import ch.insign.cms.blocks.sliderblock.SliderEntryBlock
@import ch.insign.cms.views.html.tags._
@import scala.collection.JavaConverters.iterableAsScalaIterableConverter
@(
data: ch.insign.cms.blocks.sliderblock.SliderCollectionBlock,
editForm: play.data.Form[ch.insign.cms.blocks.sliderblock.SliderCollectionBlock],
backURL: String
)
@pageHeader = {
<link rel="stylesheet" type="text/css" href="@_asset("backend/navigation-overview.css")" />
......@@ -23,8 +25,7 @@
<script src="@_asset("backend/js/blocks-sortable.js")"></script>
}
@baseBlockEdit(data, editForm, backURL, Messages("slider.collection.block.edit.title"), pageHeader, pageFooter){
@baseBlockEdit(data, editForm, backURL, Messages("slider.collection.block.edit.title"), pageHeader, pageFooter) {
<input type="hidden" name="sliderEntryOrder" id="slider-entry-order" value="[]">
......@@ -51,48 +52,39 @@
</label>
}
@if(Template.filterPermitted(data.getSubBlocks).size > 0) {
@Some(Template.filterPermitted(data.getSubSliderSubBlocks).asScala).filter(_.nonEmpty).map { entries =>
<div class="dd col-md-9" id="slider-entities">
<ol class="dd-list">
@for(sub <- Template.filterPermitted(data.getSubBlocks)) {
@Option(sub.asInstanceOf[SliderEntryBlock]).map { slider =>
<li class="dd-item" data-id="@sub.getId">
@entries.map { entry =>
<li class="dd-item" data-id="@entry.getId">
<div class="dd-handle">
@CMS.getConfig.frontendLanguages.filter(lang => slider.getTitle.get(lang).nonEmpty).map { lang =>
@CMS.getConfig.frontendLanguages.asScala.filter(lang => entry.getTitle.get(lang).nonEmpty).map { lang =>
<span class="badge badge-primary">@lang.toUpperCase</span>
}
@CMS.getConfig.frontendLanguages.find(lang => slider.getTitle.get(lang).nonEmpty).map { lang =>
@slider.getTitle.get(lang)
@CMS.getConfig.frontendLanguages.asScala.find(lang => entry.getTitle.get(lang).nonEmpty).map { lang =>
@entry.getTitle.get(lang)
}
</div>
<div class="nestable-list-actions" style="display: block">
<a href="@BlockController.edit(slider.getId, request.uri)" title="@Messages("btn.edit")" class="add-edit-lang">
<a href="@BlockController.edit(entry.getId, request.uri)" title="@Messages("btn.edit")" class="add-edit-lang">
<i class="fa fa-edit"></i>
</a>
<a role="button" class="deleteBlock"
data-deleted-block-name="@slider.getClass.getSimpleName" data-form-id="delete-block-form-@slider.getId"
href="@BlockController.delete(slider.getId, request.uri)" title="@Messages("btn.delete")">
<a role="button" class="deleteBlock" data-deleted-block-name="@Template.blockDisplayName(entry.getClass)" data-block-id="@entry.getId"
href="@BlockController.delete(entry.getId, request.uri)" title="@Messages("btn.delete")">
<i class="fa fa-trash"></i>
</a>
</div>
</li>
}
}
</ol>
</div>
}
</div>
}
@for(sub <- Template.filterPermitted(data.getSubBlocks)) {
@form(BlockController.delete(sub.getId, request.uri()), 'id -> ("delete-block-form-" + sub.getId), 'class -> "hide") {
<button class="deleteBlock"
data-deleted-block-name="@sub.getClass.getSimpleName">
<span class="glyphicon glyphicon-trash"></span>
</button>
@Template.filterPermitted(data.getSubSliderSubBlocks).asScala.map { entry =>
@form(BlockController.delete(entry.getId, request.uri), 'id -> ("delete-block-form-" + entry.getId), 'class -> "hide") {
@*FIXME left for the compatibility. The better approach would be to put it in the confirmation modal*@
}
}
......
......@@ -14,7 +14,8 @@
name: String = "",
color: String = "gray",
sortableContainer: Boolean = false,
CssClass: String="" )(content: Html)
CssClass: String = ""
)(content: Html)
@* adds debug info in debug mode *@
@withDebugInfo(content: Html) = {
@if(Template.isDebugMode()) {
......@@ -27,18 +28,15 @@
}
}
@responsiveCollectionClass = @{
Some(data).map{
Some(data).map {
case rc: ResponsiveCollection => rc.getResponsiveCollectionCssClass
case _ => None
}
}
@wrapIntoColumn(content: Html) = {
@if(Template.addColWidthClass(data).nonEmpty) {
<div class="@Template.addColWidthClass(data)">
@content
</div>
} else {
@content
@responsiveBlockClass = @{
Some(data).map(_.getParentBlock).map {
case rs: ResponsiveCollection => Template.addColWidthClass(data)
case _ => "container"
}
}
@wrapIntoContainer(content: Html) = {
......@@ -127,7 +125,7 @@
</div>
} else {
@wrapIntoContainer {
<div class="@Some(CssClass).filterNot(_.isEmpty).getOrElse("pcms-container") @Template.addColWidthClass(data) @responsiveCollectionClass">
<div class="@Some(CssClass).filterNot(_.isEmpty) @responsiveBlockClass @responsiveCollectionClass">
@content
</div>
}
......
@(data: ch.insign.cms.models.ContentBlock)(extension: Html=Html.apply(""))
@import ch.insign.cms.models.Template
@import ch.insign.cms.views.html._blockBase;
@import play.api.i18n.Messages;
@_blockBase(data = data, delete=true, edit=true, add=false, color="red", name=Messages("content.block.name"), CssClass="container") {
<!-- Start ContentBlock @data.getId -->
<h3>@data.getTitle</h3>
<p>@{Html(data.getContent.get)}</p>
@extension
<!-- End ContentBlock @data.getId -->
@import ch.insign.cms.views.html._blockBase
@(
data: ch.insign.cms.models.ContentBlock
)(extension: Html = Html.apply(""))
@_blockBase(data = data, color = "red") {
<h3>@data.getTitle</h3>
<p>@Html(data.getContent.get)</p>
@extension
}
......@@ -8,5 +8,7 @@
@import ch.insign.cms.blocks.horizontalcollection.HorizontalCollectionBlock
@(data: ch.insign.cms.models.PageBlock)
@main(page = data) {
@Template.addBlockToSlot(classOf[CollectionBlock], data, "main").context("mainContext").render()
<div class="content">
@Template.addBlockToSlot(classOf[CollectionBlock], data, "main").context("mainContext").render()
</div>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment